Hi,
my intention is to save annotations into my custom DB while prodigy annotations are being saved.
I copy-pasted the "textcat" recipe from /prodigy/recipes/textcat.py and created a new custom one. I added two print instructions (to console and log) in "update()" function but do not see the output when I hit save button.
My update function:
def update(answers):
print("yuri_answers:", answers)
log("yuri_answers:", answers)
Does it mean that the "update()" function is not called?
Entire recipe:
# coding: utf8
from __future__ import unicode_literals, print_function
import spacy
# import random
# import tqdm
# import copy
# from spacy.util import minibatch, fix_random_seed
#
# from ..models.matcher import PatternMatcher
# from ..models.textcat import TextClassifier
# from ..components import printers
from prodigy.components.loaders import get_stream
from prodigy.components.preprocess import split_sentences, add_label_options
from prodigy.components.preprocess import add_labels_to_stream
# from ..components.preprocess import convert_options_to_cats
# from ..components.db import connect
# from ..components.sorters import prefer_uncertain
from prodigy.core import recipe, recipe_args
# from ..util import export_model_data, split_evals, get_print
from prodigy.util import combine_models, prints, log, set_hashes
@recipe(
"textcat_manual_custom",
dataset=recipe_args["dataset"],
spacy_model=recipe_args["spacy_model"],
source=recipe_args["source"],
api=recipe_args["api"],
loader=recipe_args["loader"],
label=recipe_args["label_set"],
exclusive=recipe_args["exclusive"],
exclude=recipe_args["exclude"],
)
def manual(
dataset,
spacy_model,
source=None,
api=None,
loader=None,
label=None,
exclusive=False,
exclude=None,
):
print("textcat_manual_custom()")
"""
Manually annotate categories that apply to a text. If more than one label
is specified, categories are added as multiple choice options. If the
--exclusive flag is set, categories become mutually exclusive, meaning that
only one can be selected during annotation.
"""
log("RECIPE: Starting recipe textcat_manual_custom", locals())
nlp = spacy.load(spacy_model)
log("RECIPE: Loaded model {}".format(spacy_model))
labels = label
has_options = len(labels) > 1
log("RECIPE: Annotating with {} labels".format(len(labels)), labels)
stream = get_stream(
source, api=api, loader=loader, rehash=True, dedup=True, input_key="text"
)
if has_options:
stream = add_label_options(stream, label)
else:
stream = add_labels_to_stream(stream, label)
def update(answers):
print("yuri_answers:", answers)
log("yuri_answers:", answers)
return {
"view_id": "choice" if has_options else "classification",
"dataset": dataset,
"stream": stream,
"exclude": exclude,
"config": {
"lang": nlp.lang,
"labels": labels,
"choice_style": "single" if exclusive else "multiple",
},
}
Here is how I initiate Prodigy server:
prodigy textcat_manual_custom dataset_1 en_core_web_sm input.jsonl --label "L1","L2" -F "/full/path/to/textcat_manual_custom.py"
Thank you!