Hi,
I was going through the custom recipe tutorial on Custom Recipes · Prodigy · An annotation tool for AI, Machine Learning & NLP, but it is not working. Specifically, I'm trying to run the cat facts example (code copy/pasted from the webpage below). It seems like the cat facts API has changed, but even accounting for that I'm still getting the error:
...
stream.apply(add_tokens, nlp=nlp, stream=stream) # tokenize the stream for ner_manual
AttributeError: 'generator' object has no attribute 'apply'
Code (from webpage):
import prodigy
from prodigy.components.preprocess import add_tokens
import requests
import spacy
@prodigy.recipe("cat-facts")
def cat_facts_ner(dataset, lang="en"):
# We can use the blocks to override certain config and content, and set
# "text": None for the choice interface so it doesn't also render the text
blocks = [
{"view_id": "ner_manual"},
{"view_id": "choice", "text": None},
{"view_id": "text_input", "field_rows": 3, "field_label": "Explain your decision"}
]
options = [
{"id": 3, "text": "😺 Fully correct"},
{"id": 2, "text": "😼 Partially correct"},
{"id": 1, "text": "😾 Wrong"},
{"id": 0, "text": "🙀 Don't know"}
]
def get_stream():
res = requests.get("https://cat-fact.herokuapp.com/facts").json()
for fact in res["all"]:
yield {"text": fact["text"], "options": options}
nlp = spacy.blank(lang) # blank spaCy pipeline for tokenization
stream = get_stream() # set up the stream
stream.apply(add_tokens, nlp=nlp, stream=stream) # tokenize the stream for ner_manual
return {
"dataset": dataset, # the dataset to save annotations to
"view_id": "blocks", # set the view_id to "blocks"
"stream": stream, # the stream of incoming examples
"config": {
"labels": ["RELEVANT"], # the labels for the manual NER interface
"blocks": blocks # add the blocks to the config
}
}
How can I fix these issues? Also, is there a more in-depth guide for custom recipes?
Thanks