Instance Usage of similarity Function in python

  • 2021-12-11 07:43:11
  • OfStack

1. The similarity function takes two lists and returns a list consisting of the same elements in both lists.

2. The function uses list derivation to traverse all elements in the a list, and uses in keywords to determine whether these elements exist in the b list.

Instances


def similarity(a, b):
  return [item for item in a if item in b]
 
# EXAMPLES
similarity([1, 2, 3], [1, 2, 4]) # [1, 2]

Expansion of knowledge points:

python Semantics similarity_Python: Semantic Similarity Score of string

Semantic similarity score of Python: string

Is there a library for calculating the semantic similarity score of a pair of sentences?

I know the semantic database of WordNet and how to generate scores for two words, but I am looking for a library that can perform all preprocessing tasks (such as port stems, stop word deletion, etc.) in the whole sentence and output.

I found a job written using the. NET framework, which uses a series of preprocessing steps to calculate scores. Are there any projects in Python that do this 1?

I'm not looking for a sequence of operations that will help me with my find score (as required here)

I like to implement each stage myself, or paste functions from different libraries so that it can be used for sentence pairs, but I mainly need this tool to deduce testing data.

Editor: I'm thinking about using NLTK and calculating the score of every two words iteration on these two sentences, and then drawing inferences from the standard deviation of the results, but I don't know if this is a reasonable similarity estimate. In addition, it will take a long time.

Thirdly, I am looking for projects/libraries that have already implemented this intelligence. Things, let me do this:

import amazing_semsim_package str1='Birthday party ruined as cake explodes' str2='Grandma mistakenly bakes cake using gunpowder' > > similarity(str1,str2) > > 0.889

The best wrapper I've ever seen is Gensim on the Gensim home page find. I've used it many times, and overall I'm very satisfied with its ease of use, it's written in Python, and there's a simple follow-up tutorial to start with, which compares nine string. It can be installed by point, so you won't have much trouble getting it installed, I hope.

Which rating you use for algorithm depends to a large extent on the context of your question, but if you want something basic, I will start using function for LSI for build. This is a tutorial to guide you through. )

If you read the gensim tutorial, it will guide you to use Similaritiesfunction by comparing two string. This allows you to see how your bites compare to each other according to the text they contain, or some other stabbing pain.


Related articles: