poltextlab commited on
Commit
aa9d9e1
1 Parent(s): 1f52b61

list labels used

Browse files
Files changed (1) hide show
  1. interfaces/ner.py +2 -1
interfaces/ner.py CHANGED
@@ -34,7 +34,8 @@ def named_entity_recognition(text, language):
34
  pipeline = huspacy.load() if model_id.startswith("hu") else spacy.load(model_id)
35
  doc = pipeline(text)
36
  entities = [{"entity":ent.label_, "start":ent.start_char, "end":ent.end_char} for ent in doc.ents]
37
- legend = "<ul>"+"".join([f"<li> <b>{ent.label_}</b> = <i>{spacy.glossary.GLOSSARY[ent.label_]}</i> </li>" for ent in set(doc.ents)])+"</ul>"
 
38
  output = {"text":text, "entities":entities}
39
  model_id_hf = f"huspacy/{model_id}" if model_id.startswith("hu") else f"spacy/{model_id}"
40
  output_info = legend + f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id_hf}">{model_id_hf}</a> model.</p> <ul> {" ".join(legend)} </ul>'
 
34
  pipeline = huspacy.load() if model_id.startswith("hu") else spacy.load(model_id)
35
  doc = pipeline(text)
36
  entities = [{"entity":ent.label_, "start":ent.start_char, "end":ent.end_char} for ent in doc.ents]
37
+ labels_used = [ent.label_ for ent in doc.ents]
38
+ legend = "<ul>"+"".join([f"<li> <b>{label}</b> = <i>{spacy.glossary.GLOSSARY[label]}</i> </li>" for label in set(labels_used)])+"</ul>"
39
  output = {"text":text, "entities":entities}
40
  model_id_hf = f"huspacy/{model_id}" if model_id.startswith("hu") else f"spacy/{model_id}"
41
  output_info = legend + f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id_hf}">{model_id_hf}</a> model.</p> <ul> {" ".join(legend)} </ul>'