The "label"
in this case would be a string โ for example, "sympathetic"
.
Here's a simple standalone example you can run in your terminal to see the idea in action:
emotions = ["sympathetic", "moved", "compassionate", "tender"]
options = [
{"id": "1", "text": "Gar nicht"},
{"id": "2", "text": "Kaum"},
{"id": "3", "text": "Meist nicht"},
{"id": "4", "text": "Neutral"},
]
# Those would later be loaded from your file
stream = [{"text": "hello world"}, {"this is a text"}]
for emotion in emotions:
for eg in stream:
eg["label"] = emotion
eg["options"] = options
print(eg)
The result should look something like this:
{'text': 'hello world', 'label': 'sympathetic', 'options': [{'id': '1', 'text': 'Gar nicht'}, {'id': '2', 'text': 'Kaum'}, {'id': '3', 'text': 'Meist nicht'}, {'id': '4', 'text': 'Neutral'}]}
{'text': 'this is a text', 'label': 'sympathetic', 'options': [{'id': '1', 'text': 'Gar nicht'}, {'id': '2', 'text': 'Kaum'}, {'id': '3', 'text': 'Meist nicht'}, {'id': '4', 'text': 'Neutral'}]}
{'text': 'hello world', 'label': 'moved', 'options': [{'id': '1', 'text': 'Gar nicht'}, {'id': '2', 'text': 'Kaum'}, {'id': '3', 'text': 'Meist nicht'}, {'id': '4', 'text': 'Neutral'}]}
...
That's the format you want, because it allows Prodigy to render the text with a label on top (the emotion) and a number of multiple-choice options. So your recipe could look something like this:
import prodigy
from prodigy.components.loaders import JSONL
@prodigy.recipe(
"empathy_classification",
dataset=("Name of dataset to annotate to", "positional", None, str),
source=("Input data file", "positional", None, str),
)
def empathy_classification(dataset, source):
stream = JSONL(source)
stream = add_options(stream)
return {
"dataset": dataset,
"view_id": "choice",
"stream": stream,
}
def add_options(stream):
emotions = ["sympathetic", "moved", "compassionate", "tender"]
options = [
{"id": "1", "text": "Gar nicht"},
{"id": "2", "text": "Kaum"},
{"id": "3", "text": "Meist nicht"},
{"id": "4", "text": "Neutral"},
]
for emotion in emotions:
for eg in stream:
eg["label"] = emotion
eg["options"] = options
yield eg
And the result in your browser would then look like this: