赞
踩
安装
pip install rank-bm25
from rank_bm25 import BM25Okapi corpus = [ "Hello there good man!", "It is quite windy in London", "How is the weather today?" ] tokenized_corpus = [doc.split(" ") for doc in corpus] bm25 = BM25Okapi(tokenized_corpus) query = "windy London" tokenized_query = query.split(" ") print(bm25.get_scores(tokenized_query)) print(bm25.get_top_n(tokenized_query, corpus, n=1)) # ['It is quite windy in London']
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。