【发布时间】:2021-02-14 02:00:39
【问题描述】:
我有一个数据集
Title Year
0 Sport, there will be a match between United and Tottenham ... 2020
1 Forecasting says that it will be cold next week 2019
2 Sport, Mourinho is approaching the anniversary at Tottenham 2020
3 Sport, Tottenham are sixth favourites for the title behind Arsenal. 2020
4 Pochettino says clear-out of fringe players at Tottenham is inevitable. 2018
... ... ...
我想研究同一年内的文本相似度,而不是在整个数据集中。为了找到最相似的文本,我使用了 WM 距离相似度。 对于两个文本将是:
word2vec_model = gensim.models.KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin', binary=True)
distance = word2vec_model.wmdistance("string 1".split(), "string 2".split())
但是,我需要在同一年遍历句子的距离,以获得每个文本与其他文本的相似性,从而在数据框中的每行创建一个相似文本列表。 能否请您告诉我如何在同一年发表的文本中迭代 wmdistance 函数,以便为每个文本获取同一时期内最相似的文本?
【问题讨论】:
标签: python pandas gensim word2vec similarity