Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble running code for Exercise 5 in Chapter 4 #99

Open
ruruu127 opened this issue May 16, 2021 · 1 comment
Open

Trouble running code for Exercise 5 in Chapter 4 #99

ruruu127 opened this issue May 16, 2021 · 1 comment

Comments

@ruruu127
Copy link

Hi! I recently took this course on DataCamp and did manage to run the code in the exercise. For future references, I copied the exercise and the answer to my own notebook using Jupyter. However, when I tried to run the code, I encountered an error.

This is the original code:

import random

# Start the training
nlp.begin_training()

# Loop for 10 iterations
for itn in range(10):
    # Shuffle the training data
    random.shuffle(TRAINING_DATA)
    losses = {}
    
    # Batch the examples and iterate over them
    for batch in spacy.util.minibatch(TRAINING_DATA, size=2):
        texts = [text for text, entities in batch]
        annotations = [entities for text, entities in batch]
        
        # Update the model
        nlp.update(texts, annotations, losses=losses)
        print(losses)

And this is the error I got:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-aa733910c3ca> in <module>
     18 
     19         # Update the model
---> 20         nlp.update(texts, annotations, losses=losses)
     21         #example = Example.from_dict(nlp.make_doc(texts), annotations)
     22         #nlp.update([example])

~\anaconda3\lib\site-packages\spacy\language.py in update(self, examples, _, drop, sgd, losses, component_cfg, exclude)
   1086         """
   1087         if _ is not None:
-> 1088             raise ValueError(Errors.E989)
   1089         if losses is None:
   1090             losses = {}

ValueError: [E989] `nlp.update()` was called with two positional arguments. This may be due to a backwards-incompatible change to the format of the training data in spaCy 3.0 onwards. The 'update' function should now be called with a batch of Example objects, instead of `(text, annotation)` tuples. 

I'm sorry if it looks a bit confusing, but this error has been bugging me for weeks now, and I tried to find the solution through stackoverflow and applied them here, but nothing seems to work out. Really appreciate it if the author herself or anyone here can explain what happened.

Thank you.

@adrianeboyd
Copy link
Collaborator

Hi, this code looks like it was written for spaCy v2.x.

The version of the course at https://course.spacy.io should be compatible with spacy==2.3.5. It's possible this is a slightly older version and you might need spacy==2.2.4 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants