# Sentence to word similarity

Is there a way to know how much a sentence is related to a word/topic?

For instance the following dataframe and the topics/attributes 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
...


As a start I thought about doing a jaccard_similarity distance ...

>>>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})


But is there a better way to see how much a sentence relate to a targeted word?

# Update

My main goal is to compare the proportion of people who used some topics in their comments of a product with the presence or absence of these topics in the description of the product. I used a model which use the synonyms:

d = {}
for product in collection.find():
d_product = {}
name = product['q0']['Results'][0]['Name']
description = product['q0']['Results'][0]['Description']
#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
# 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)


It produces the following graph:

It's weird because it shows that for most products the difference between the presence/absence of any topic compared to its presence/absence in the description is the same for most topics, but different from 0! Everything that is above zero means that at least the description has it and none of the comments, but everything below zero means that the comments have it but not the description. What strikes me is these straight lines below zero. It means that the presence/absence of a given attribute in absciss is the same for every comment...

• Where do the topics come from? if it's from a topic model, you could re-apply the model on the sentences. Dec 10, 2020 at 17:46
• @Erwan thanks for tour comment. The topics come from a list my of topics in a csv Dec 11, 2020 at 8:50