有没有办法知道一个句子与一个单词/主题有多大关系?
例如以下数据框和主题/属性Romantique,,Feminine...:
comments
0 Très contente de mon achat. Je cherchais ce parfum depuis un temps en magasin et je suis heureuse qu’il soit disponible en ligne il sent tellement bon !! En plus en promo, génial ! \r\nLivraison très rapide !
1 J’adore les parfums de cette marque car je trouve qu’ils sont captivant et surtout ils tiennent toute la journée ! Ils ont des odeurs originales et que l’on ne retrouve pas partout ! Je conseil fortement
2 Le parfum ideal pour porter pendant toutes les saisons du matin à nuit !!!
3 Très bon parfum floral, envoûtant au note de Jasmin qui reste toute la journée\r\nCorresponds aux personnes qui aiment les parfums florales assez imposante
...
作为开始,我想过做一个 jaccard_similarity 距离......
>>>from collections import Counter
>>>Counter(df['comments'].apply(lambda x: x.split(' ')).apply(lambda x: jaccard_similarity(x,['féminin'])))
Counter({0.0: 1344, 0.025: 21, 0.05: 21, 0.0625: 21})
但是有没有更好的方法来查看一个句子与目标词的相关程度?
更新
我的主要目标是比较在产品评论中使用某些主题的人的比例与产品描述中是否存在这些主题。我使用了一个使用同义词的模型:
d = {}
for product in collection.find():
d_product = {}
name = product['q0']['Results'][0]['Name']
description = product['q0']['Results'][0]['Description']
comments = short_comments_df(product['q2'])['comments']
#for every attributes
for attribut in attributs:
consumers_approved = 0
# Is the attribut, or its synonyms, in the comments?
try:
# if the attribute or it synonyms are in the description then the product has the attribut
product_approved = presence(synonymes[unidecode.unidecode(attribut)], description)
# we test every comment to see if they talked about the attribute
for comment in comments:
# We only take the nouns and the verbs
lemmatized_comment = lemmatize_pos_filtering(comment)
# if the attributes are in the comments then we increment the consumer approved counter
consumers_approved += presence(synonymes[unidecode.unidecode(attribut)],lemmatized_comment)
# we take the proportion of people who used the attribute, but shouldn't we normalize it?
proportion_approved = consumers_approved/len(record['q2']['Results'])
except IndexError:
print("IndexError: ",attribut)
# we use the difference between if we found it in the description and the % of people who found it as well
d_product[attribut] = product_approved - proportion_approved
d[name] = d_product
df = pd.DataFrame(d)
它产生以下图表:
这很奇怪,因为它表明对于大多数产品,任何主题的存在/不存在与描述中的存在/不存在之间的差异对于大多数主题来说都是相同的,但不同于 0!高于零的所有内容都意味着至少描述有它并且没有评论,但低于零的所有内容都意味着评论有它但没有描述。令我印象深刻的是这些低于零的直线。这意味着对于每条评论,横坐标中给定属性的存在/不存在都是相同的......
