Is there a way to hide the value of the "text" key on the interface?


I'm making a custom recipe that uses textcat.teach. It is based on the source code of 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.

    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
        matcher = PatternMatcher(
        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."

Hi! The "text" key should definitely be present in the underlying JSON data, because it's what the text classifier will use under the hood and what it will be updated with.

But the blocks let you override existing task properties for display in the UI, so you could do:

blocks = [{"view_id": "classification", "text": None},{"view_id": "diff"}]

This will prevent the classification UI from showing the "text" (which it otherwise would, by default).

Thanks for the quick answer :smiley:
I tried adding "text": Noneto the blocks in my custom recipe.
However, the following message was returned.

What could be the cause of this?

Ah, sorry, could you try an empty string "" instead?

Yes, I rewrote "blocks" like this.

blocks = [{"view_id":"classification","text": ""},{"view_id":"diff"}]

However, the content of the "text" remains visible, just with the addition of an empty line. :cry:

Ahh, I think what might be happening here is that the diff UI can also render the text, if you provide it. That lets you stream in input text plus two diffed versions (e.g. for evaluating machine translation). What happens if you do {"view_id":"diff", "text": ""}?

Alternatively, if you just want the classification block for the label at the top and you don't care so much about the exact styling, you could also use a regular html block with an html_template and put the label in there.

Wow! I solved it with your suggestion.
I should have added "text": "" to both classification and diff, like this:

blocks = [{"view_id":"classification","text": ""},{"view_id":"diff","text": ""}]

As you pointed out, I noticed that not only classification but also diff is rendering "text".
This will speed up the annotation. :smile:Thank you for your support!

1 Like

Yay, glad it worked! :tada:

I'll add a fix for the error that came up with "text": None – there's no reason this shouldn't work and Prodigy should be able to handle it out-of-the-box.

1 Like

It would be nice to have a fix for "text": None, thank you :blush:

1 Like

Just released v1.10.1, which includes a fallback for None text values in the classification UI :slightly_smiling_face:

1 Like