# Text Similarities: which nlp methods to use?

I have data where there is text for each user A visiting a business B. I want to find similarity between each user using their text.

I have tried cosine similarity, I know its a great method but it's very slow in computing similarities.

I have thought about extracting important information from text (for example: Term Extraction, I don't want to use LDA) and computing similarities between that information.

Question 2: Any suggestions?

• Hi, can you show some example of how these texts look like? Jul 31, 2018 at 8:18
• @BrunoGL I have edited my post. You can see how text data looks now. Aug 1, 2018 at 16:23
• Try sentence to vectors and get similarity measure. Look word2vec and Doc2vec Aug 2, 2018 at 5:18
• cosine similarity is basically a two vector dot product, why do you think it is slow? Jun 5, 2019 at 13:16

There are many ways to see how texts are similar, but this will depend on your use case.

# Semantics

Nowadays, word embeddings are getting popular. Like it was suggested in the comments, you could use Doc2Vec to transform your sentence into a vector and calculate the cosine distance from each sentence.

The idea with these learned embeddings is that you kind of encode the meaning of the sentence by looking how words are used in context. So, to sentences would be similar if words are used in the same manner in a context.

However, this could potentially be difficult to interpret.

For example:

Good tattoo shop. Clean space.
Good pizza restaurant. Large space.
Terrible tattoo shop. Dirty space.


Which of these are semantically close? It will depend a lot on your training and your own judgment to tell if the results are useful to you.

# Sentiment

Maybe you are interested in saying that sentences are similar if their sentiment is positive or negative (or on some other scale).

For example:

Suppose you can have sentiment on a scale $[-1,1]$, where $-1$ is negative, $0$ is neutral and $1$ is positive.

Good tattoo shop. Clean space.
Sentiment = 0.7

Good pizza restaurant. Large space.
Sentiment = 0.75

Terrible tattoo shop. Dirty space.
Sentiment = -0.9


There are many resources online on how to do this. Here is an answer with some links.

# BoW

The bag-of-words is a very simple approach, but depending on what you are doing, it could do the trick. Suppose you want to say that sentences are similar if they are about a business in the same industry.

You can make a simple dictionary for every industry:

word_per_industry = {
'restaurants' = ['restaurant', 'food', 'chef', 'dish', 'salad', 'lunch'],
'tatto_shop' = ['clean', 'dirty', 'art', 'sterlized']
.
.
.
}


Then, per sentences, you can count which business has more words in the sentence, and if sentences are from the same industry they are similar. Of course, you could also make lists based on another characteristic, not necessarily on industries.