ir_baseline.py 文件源码

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

项目:ParlAI 作者: facebookresearch 项目源码 文件源码
def score_match(query_rep, text, length_penalty, dictionary=None, debug=False):
    if text == "":
        return 0
    if not dictionary:
       words = text.lower().split(' ')
    else:
       words = [w for w in dictionary.tokenize(text.lower())]
    score = 0
    rw = query_rep['words']
    used = {}
    for w in words:
        if w in rw and w not in used:
            score += rw[w]
            if debug:
                print("match: " + w)
        used[w] = True
    norm = math.sqrt(len(used))
    score = score / math.pow(norm * query_rep['norm'], length_penalty)
    return score
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号