本文主要是介绍句子相似 BM25 python 实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
# -*- coding: utf-8 -*-import mathclass BM25(object):def __init__(self, docs):""":param docs: 分好词的list"""self.D = len(docs)self.avgdl = sum([len(doc)+0.0 for doc in docs]) / self.Dself.docs = docsself.f = []self.df = {}self.idf = {}self.k1 = 1.5self.b = 0.75self.init()def init(self):for doc in self.docs:tmp = {}for word in doc:if not word in tmp:tmp[word] = 0tmp[word] += 1self.f.append(tmp)for k
这篇关于句子相似 BM25 python 实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!