spaCy - Span.similarity Method
This method is used to make a semantic similarity estimate. The default is cosine similarity using an average of word vectors.
Argument
The table below explains its argument −
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| other | - | It is the object with which the comparison will be done. By default, it will accept Doc, Span, Token, and Lexeme objects. |
Example
An example of Span.similarity method is as follows −
import spacy
nlp_model = spacy.load("en_core_web_sm")
doc = nlp_model("red car and black bike")
red_car = doc[:2]
black_bike = doc[3:]
car_bike = red_car.similarity(black_bike)
bike_car = black_bike.similarity(red_car)
car_bike == bike_car
Output
When you run the code, you will see the following output −
True
spacy_container_span_class.htm
Advertisements