Can you help create a custom recipe with hierarchical labels?
Specifically my hierarchy would look like the following with 3 levels in each category:
Politics
- Asia
-- elections
-- foreign
- Europe
-- local
-- election
-- finance
- America
-- business
-- finance
Sports
- Team
-- football
-- baseball
- Individual
-- golf
-- tennis
This is sample example.jsonl has the following two records to annotate:
{ "text": "Cyber researchers have linked the vulnerability exploited by the latest ransomware to “WannaCry”. Both versions of malicious software rely on weaknesses discovered by the National Security Agency years ago, Kaspersky said." }
{ "text": "Java J****EE Developer ****k k Music, Film & TV London Java JEE Developers required for software house with client sectors of music, film and TV. Salary: Maximum ****: Discretionary bonus and benefits package. Location: Near Euston and King's Cross, London THE COMPANY: Consistent new business wins for the world leader in the provision of software solutions to the Music and Entertainment industry has given rise to the need for an experienced Java Developer. The working environment here is very pleasant with a casual dress code, laid back and friendly atmosphere"}
My recipe file looks as follows:
import prodigy
LABEL_HIERARCHY = {
"CATEGORY": {
"Politics": {
"Asia": {
"elections":{},
"foreign":{}
},
"Elections": {
"A":{},
"B":{}
}
}
}
}
def add_label_hierarchy(examples):
for eg in examples:
eg["hierarchy"] = LABEL_HIERARCHY
return examples
@prodigy.recipe('hierarchy_recipe')
def hierarchy_recipe(dataset, source):
stream = prodigy.get_stream(source)
stream = add_label_hierarchy(stream)
return {
'dataset': dataset,
'stream': stream,
'view_id': 'hierarchy_recipe',
'config': {
'labels': None
}
}
@prodigy.serve('hierarchy_recipe')
def hierarchy_recipe():
html_template = """
<div style="font-size: 16px">
<p>Text: <strong>{{text}}</strong></p>
<p>Labels:</p>
<ul>
{% for level1 in hierarchy %}
<li>{{ level1 }}
{% if hierarchy[level1] %}
<ul>
{% for level2 in hierarchy[level1] %}
<li>{{ level2 }}
{% if hierarchy[level1][level2] %}
<ul>
{% for level3 in hierarchy[level1][level2] %}
<li><input type="checkbox" name="{{ level1 }}|{{ level2 }}|{{ level3 }}" value="accept">{{ level3 }}</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</div>
"""
return {'html_template': html_template}
I am running this command: prodigy hierarchy_recipe -F hierarchy_recipe.py test_dataset example.jsonl
Getting this error: usage: prodigy hierarchy_recipe [-h] dataset source
prodigy hierarchy_recipe: error: the following arguments are required: dataset, source