我正在尝试寻找与两个不同的单词相似的单词。我知道我可以用FastText找到最相似的单词,但我想知道是否有一种方法可以找到与两个关键词相似的关键词。例如,"apple“类似于"orange”,也类似于"kiwi“。所以,我想要做的是,如果我有两个词,“器官”和“奇异果”,那么我希望得到一个关键字“苹果”或任何其他水果的建议。有没有办法做到这一点?
发布于 2021-02-08 22:26:52
我认为这个功能没有开箱即用的功能。
在任何情况下,您都可以考虑使用这种简单的方法
注意:这是一种粗糙的方法。如果需要,甚至可以使用相似度余弦执行更复杂的操作。
代码示例:
import fasttext
# load the pretrained model
# (in the example I use the Italian model)
model=fasttext.load_model('./ml_models/cc.it.300.bin')
# get nearest neighbors for the interested words (100 neighbors)
arancia_nn=model.get_nearest_neighbors('arancia', k=100)
kiwi_nn=model.get_nearest_neighbors('kiwi', k=100)
# get only words sets (discard the similarity cosine)
arancia_nn_words=set([el[1] for el in arancia_nn])
kiwi_nn_words=set([el[1] for el in kiwi_nn])
# compute the intersection
common_similar_words=arancia_nn_words.intersection(kiwi_nn_words)输出示例(意大利语):
{'agrume',
'agrumi',
'ananas',
'arance',
'arancie',
'arancio',
'avocado',
'banana',
'ciliegia',
'fragola',
'frutta',
'lime',
'limone',
'limoni',
'mandarino',
'mela',
'mele',
'melograno',
'melone',
'papaia',
'papaya',
'pera',
'pompelmi',
'pompelmo',
'renetta',
'succo'}发布于 2021-02-09 16:11:57
多年来,我一直使用Gensim的W2V实现进行这样的计算,但Gensim也有FastText实现:https://radimrehurek.com/gensim/models/fasttext.html
https://stackoverflow.com/questions/66097756
复制相似问题