PacktPublishing / Mastering-spaCy

Mastering spaCy, published by Packt
MIT License
125 stars 73 forks source link

Lemmatization in NLU example doesn't work with spaCy 3.0 #3

Closed educatorsRlearners closed 3 years ago

educatorsRlearners commented 3 years ago

Like the title says, the example on pages 46 and 47 throws an error if you are using spaCy 3.0 as described here.

To that end, I changed the code using the template provided here like this:

import spacy   
nlp = spacy.load('en_core_web_md')   
nlp.get_pipe("attribute_ruler").add([[{"TEXT": "Angeltown"}]], {"LEMMA": "Los Angeles"})
doc = nlp("I am flying to Angeltown.")
for token in doc: 
    print(token.text, token.lemma_)

and got the desired output.

DuyguA commented 3 years ago

I wrote some chapters before v3. I made a second pass to the code after v3 came out, some of the code might have escaped from my attention. Thanks for reporting!