IBM / zshot

Zero and Few shot named entity & relationships recognition
https://ibm.github.io/zshot
MIT License
350 stars 20 forks source link

[Bug] Error while visualizing results without entities extracted #64

Closed marmg closed 1 year ago

marmg commented 1 year ago

Summary

Describe the bug IndexError while visualizing results without entities extracted in the "rel" mode:

File ~/zshot/utils/displacy/relations_render.py:27, in parse_rels(doc)
     25         tokens_span.append((filtered_spans[idx - 1].end, span.start, None))
     26     tokens_span.append((span.start, span.end, span))
---> 27 if filtered_spans[-1].end < len(doc.text):
     28     tokens_span.append((filtered_spans[-1].end, len(doc.text), None))
     30 words = []

IndexError: list index out of range

To Reproduce

import spacy

from zshot import PipelineConfig, displacy
from zshot.relation_extractor import RelationsExtractorZSRC
from zshot.utils.data_models import Relation

nlp = spacy.load("en_core_web_sm")
nlp_config = PipelineConfig(
    relations_extractor=RelationsExtractorZSRC(thr=0.1),
    relations=[
        Relation(name='located in', description="If something like a person, a building, or a company is located in a particular place, like a city, country of any other physical location, it is present or has been built there")
    ]
)
nlp.add_pipe("zshot", config=nlp_config, last=True)

text = "IBM headquarters are located in Armonk."
doc = nlp(text)
displacy.render(doc, style='rel')

Expected behavior Show sentence without entities and relations