Skip to content

Trouble running code for Exercise 5 in Chapter 4Β #99

Description

@ruruu127

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions