【发布时间】:2020-10-31 13:21:34
【问题描述】:
我有一张如下表:
data = {'text': ['The scent is nice','I like the smell', 'The smell is awesome', 'I find the scent amazing', 'I love the smell']}
df = pd.DataFrame (data, columns = ['text'])
我想列出所有包含“气味”这个词的句子
word = 'smell'
selected_list = []
for i in range(0, len(df)):
if word in df.iloc[i,0]:
selected_list.append(df.iloc[i,0])
selected_list
我得到的输出是:
['I like the smell', 'The smell is awesome', 'I love the smell']
但是,我还想列出包含与“气味”相似的单词的句子,例如“气味”,并且我想使用谷歌的预训练 word2vec 并设置一个条件,如果相似度高于 0.5 到也列出句子。因此,期望的输出是:
['The scent is nice', 'I like the smell', 'The smell is awesome', 'I find the scent amazing','I love the smell']
如何将 word2vec 添加到上述代码中,以便它不仅可以扫描"smell",还可以扫描所有相似的单词?
【问题讨论】:
-
你可以创建可能的令牌,
df.loc[df.text.str.contains("smell|scent"), "text"].tolist() -
您是否已经训练了 word2vec 模型,或者决定重用其他地方的词向量?
-
@gojomo 我正在使用 Google 的预训练 word2vec 模型
标签: python pandas nlp word2vec