Hi!
I'm making a custom recipe that uses textcat.teach
. It is based on the source code of textcat_teach.py obtained from GitHub.It contains an interface that combines diff-view
and classification-view
with blocks
.
When annotating, I only want to see the contents of the diff-view.
So is there a way to hide the value of the "text"
key on the interface?
I tried removing the "text"
key in the json task format, and only "added"
and "removed"
suitable for diff-view
, but it caused a KeyError:'text'.
Here is my custom recipe.
@prodigy.recipe(
"custom_tt_diff",
dataset=("The dataset to use", "positional", None, str),
spacy_model=("The base model", "positional", None, str),
source=("The source data as a JSONL file", "positional", None, str),
label=("One or more comma-separated labels", "option", "l", split_string),
patterns=("Optional match patterns", "option", "p", str),
exclude=("Names of datasets to exclude", "option", "e", split_string)
)
def textcat_teach(
dataset: str,
spacy_model: str,
source: str,
label: Optional[List[str]] = None,
patterns: Optional[str] = None,
exclude: Optional[List[str]] = None
):
blocks = [{"view_id": "classification"},{"view_id": "diff"}]
stream = JSONL(source)
# Load the spaCy model
nlp = spacy.load(spacy_model)
model = TextClassifier(nlp, label)
if patterns is None:
predict = model
update = model.update
else:
matcher = PatternMatcher(
nlp,
prior_correct=5.0,
prior_incorrect=5.0,
label_span=False,
label_task=True,
)
matcher = matcher.from_disk(patterns)
predict, update = combine_models(model, matcher)
stream = prefer_uncertain(predict(stream))
return {
"dataset": dataset, # Name of dataset to save annotations
"stream": stream, # Incoming stream of examples
"update": update, # Update callback, called with batch of answers
"exclude": exclude, # List of dataset names to exclude
"view_id": "blocks",
"config": {"lang": nlp.lang, "blocks":blocks}
}
Here is json task format.
{
"text": "This is a sample text. \n\n This is an sample text.",
"added": "This is a sample text.",
"removed": "This is an sample text."
}