Hi all,
I am not able to apply custom HTML template to my recipe. It doesn't show anything apart from metadata.
Please help
from typing import List, Optional
import prodigy
from prodigy.components.loaders import JSONL
from prodigy.util import split_string
# Helper functions for adding user provided labels to annotation tasks.
def add_label_options_to_stream(stream, labels):
options = [{"id": label, "text": label} for label in labels]
for task in stream:
task["options"] = options
yield task
# Recipe decorator with argument annotations: (description, argument type,
# shortcut, type / converter function called on value before it's passed to
# the function). Descriptions are also shown when typing --help.
@prodigy.recipe(
"memt.manual",
dataset=("The dataset to use", "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),
exclusive=("Treat classes as mutually exclusive", "flag", "E", bool),
exclude=("Names of datasets to exclude", "option", "e", split_string),
)
def memt_manual(
dataset: str,
source: str,
label: Optional[List[str]] = None,
exclusive: bool = False,
exclude: Optional[List[str]] = None,
):
"""
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.
"""
# Load the stream from a JSONL file and return a generator that yields a
# dictionary for each example in the data.
stream = JSONL(source)
#Add labels to each task in stream
stream = add_label_options_to_stream(stream, label)
return {
"view_id": "html", # Annotation interface to use
"dataset": dataset, # Name of dataset to save annotations
"stream": stream, # Incoming stream of examples
"config": { # Additional config settings, mostly for app UI
"exclude_by": "task", # Hash value used to filter out already seen examples
"choice_style": "single",
"force_stream_order": True,
"validate": False,
"batch_size": 10,
"html_template": "<h2>{{ text }}</h2><strong>{{ meta.source }}</strong>"
},
}
data.jsonl:
{"text": "target 1, s1", "meta": {"source": "source 1"}}
prodigy memt.manual eval_user data.jsonl --label FPE+LPE,"LPE only",None -F memt_recipe.py
What I get: