ComeçarComece de graça

Compatible training data

Recall that you cannot feed the raw text directly to spaCy. Instead, you need to create an Example object for each training example. In this exercise, you will practice converting a training_data with a single annotated sentence into a list of Example objects.

en_core_web_sm model is already imported and ready for use as nlp. The Example class is also imported for your use.

Este exercício faz parte do curso

Natural Language Processing with spaCy

Ver curso

Instruções do exercício

  • Iterate through the text and annotations in the training_data, convert the text to a Doc container and store it at doc.
  • Create an Example object using the doc object and the annotations of each training data point, and store it at example_sentence.
  • Append example_sentence to a list of all_examples.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

example_text = 'A patient with chest pain had hyperthyroidism.'
training_data = [(example_text, {'entities': [(15, 25, 'SYMPTOM'), (30, 45, 'DISEASE')]})]

all_examples = []
# Iterate through text and annotations and convert text to a Doc container
for text, annotations in training_data:
  doc = nlp(____)
  
  # Create an Example object from the doc contianer and annotations
  example_sentence = ____.____(doc, ____)
  print(example_sentence.to_dict(), "\n")
  
  # Append the Example object to the list of all examples
  all_examples.append(____)
  
print("Number of formatted training data: ", len(____))
Editar e executar o código