similarity method for italian language in spacy not working

Viewed 198

how can I get the similarity method of spacy for the Italian language?

Italian Code:

import it_core_news_lg
nlp = it_core_news_lg.load()

doc1 = nlp("vuole AUX aux")
doc2 = nlp("Apple PROPN ROOT")

# Similarity of two documents
print(doc1, "<->", doc2, doc1.similarity(doc2))

return --->

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-35-db17c0966749> in <module>()
      1 import it_core_news_lg
----> 2 nlp = it_core_news_lg.load()
      3 
      4 doc1 = nlp("vuole AUX aux")
      5 doc2 = nlp("Apple PROPN ROOT")

3 frames
/usr/local/lib/python3.7/dist-packages/spacy/language.py in create_pipe(self, name, config)
    298         return SimpleFrozenList(
    299             self._components, error=Errors.E926.format(attr="components")
--> 300         )
    301 
    302     @property

KeyError: "[E002] Can't find factory for 'tok2vec'. This usually happens when spaCy calls `nlp.create_pipe` with a component name that's not built in - for example, when constructing the pipeline from a model's meta.json. If you're using a custom component, you can write to `Language.factories['tok2vec']` or remove it from the model meta and add it via `nlp.add_pipe` instead."

English Code:

import spacy
import en_core_web_lg
nlp = en_core_web_lg.load()
doc1 = nlp("I like salty fries and hamburgers.")
doc2 = nlp("Fast food tastes very good.")

# Similarity of two documents
print(doc1, "<->", doc2, doc1.similarity(doc2))

Returns--->

I like salty fries and hamburgers. <-> Fast food tastes very good. 0.7687607012190486
0 Answers
Related