Hi there,
I am trying to set up a custom interface, together with a custom csv loader. I am following quite closely the example recipe for the custom UI, as it is quite close to what I am trying to achieve: I want my reviewers to tell me if a piece of text is relevant for them, and have some possibly interesting entities highlighted to help them review (for which I think I'll need to use ner.correct instead of ner.manual, but not there yet).
I am pasting the code I am using below
import prodigy
import csv
from prodigy.components.preprocess import add_tokens
import spacy
@prodigy.recipe("retrieval-validation")
def retrieval(dataset, source):
# 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": "If ambiguous, why?"}
]
options = [
{"id": 2, "text": "😺 Relevant"},
{"id": 1, "text": "🙀 Ambiguous"},
{"id": 0, "text": "😾 Not relevant"}
]
def custom_csv_loader(source):
with open(source) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
r_score = row.get('r_score')
text = row.get('query') + '\n\n' + row.get('text')
s_score = row.get('s_score')
pdf = row.get('pdf')
yield {'text': text, "options": options,'r_score':r_score,'s_score':s_score, 'meta': {'pdf':pdf}}
stream = custom_csv_loader(source) #load stream with custom loader
nlp = spacy.load("en_ner_jnlpba_md")#load model
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": ["DNA", "PROTEIN"],
"blocks": blocks # add the blocks to the config
}
}
When running this with my csv file I get:
AttributeError: 'generator' object has no attribute 'apply'
When I remove the ner.manual view_id and just load the stream with my custom loader, I have no issue, but as soon as I need to modify the tasks I have a problem.
The prodigy version I am using is 1.15.
Is there something I am missing to make this work?