combination.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:vec4ir 作者: lgalke 项目源码 文件源码
def query(self, query, k=1, sort=True):
        models = self.retrieval_models
        weights = maxabs_scale(self.weights)  # max 1 does not crash [0,1]
        agg_fn = self.aggregation_fn
        # we only need to sort in the final run
        combined = [m.query(query, k=k, sort=False) for m in models]

        if weights is not None:
            combined = [{k: v * w for k, v in r.items()} for r, w in
                        zip(combined, weights)]

        combined = aggregate_dicts(combined, agg_fn=agg_fn, sort=True)

        if sort:
            # only cut-off at k if this is the final (sorted) output
            combined = OrderedDict(sorted(combined.items(), key=itemgetter(1),
                                          reverse=True)[:k])
        return combined
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号