shon-otmazgin / fastcoref

MIT License
142 stars 25 forks source link

resolve_text appears to fail for that particular sentence in batch #52

Open ScienceWithConscience opened 7 months ago

ScienceWithConscience commented 7 months ago

Hi,

code is

from fastcoref import spacy_component
import spacy
nlp = spacy.load("fr_core_news_lg",exclude=["parser", "lemmatizer", "ner", "textcat"])
nlp.add_pipe("fastcoref")
text=nlp("Lénie en pleurs. Mais qu'elle arrête un peu avec son cinéma !! Un peu de pudeur", component_cfg={"fastcoref": {'resolve_text': True}})

I am using spacy 3.7.2

Error message is

TypeError                                 Traceback (most recent call last)
Cell In[34], line 6
      4 nlp = spacy.load("fr_core_news_lg",exclude=["parser", "lemmatizer", "ner", "textcat"])
      5 nlp.add_pipe("fastcoref")
----> 6 text=nlp("Lénie en pleurs. Mais qu'elle arrête un peu avec son cinéma !! Un peu de pudeur", component_cfg={"fastcoref": {'resolve_text': True}})

File /opt/bitnami/miniconda/lib/python3.8/site-packages/spacy/language.py:1054, in Language.__call__(self, text, disable, component_cfg)
   1052     raise ValueError(Errors.E109.format(name=name)) from e
   1053 except Exception as e:
-> 1054     error_handler(name, proc, [doc], e)
   1055 if not isinstance(doc, Doc):
   1056     raise ValueError(Errors.E005.format(name=name, returned_type=type(doc)))

File /opt/bitnami/miniconda/lib/python3.8/site-packages/spacy/util.py:1704, in raise_error(proc_name, proc, docs, e)
   1703 def raise_error(proc_name, proc, docs, e):
-> 1704     raise e

File /opt/bitnami/miniconda/lib/python3.8/site-packages/spacy/language.py:1049, in Language.__call__(self, text, disable, component_cfg)
   1047     error_handler = proc.get_error_handler()
   1048 try:
-> 1049     doc = proc(doc, **component_cfg.get(name, {}))  # type: ignore[call-arg]
   1050 except KeyError as e:
   1051     # This typically happens if a component is not initialized
   1052     raise ValueError(Errors.E109.format(name=name)) from e

File /opt/bitnami/miniconda/lib/python3.8/site-packages/fastcoref/spacy_component/spacy_component.py:129, in FastCorefResolver.__call__(self, doc, resolve_text)
    127         mention_span, mention = self._get_cluster_head(doc, cluster, indices)
    128         for coref in cluster:
--> 129             if coref != mention and not self._is_containing_other_spans(coref, all_spans):
    130                 self._core_logic_part(doc, coref, resolved, mention_span)
    131 doc._.resolved_text = "".join(resolved)

File /opt/bitnami/miniconda/lib/python3.8/site-packages/fastcoref/spacy_component/spacy_component.py:83, in FastCorefResolver._is_containing_other_spans(self, span, all_spans)
     74 def _is_containing_other_spans(self,span: List[int], all_spans: List[List[int]]):
     75     """
     76     It returns True if there is any span in all_spans that is contained within span and is not equal to span
     77     :param span: the span we're checking to see if it contains other spans
   (...)
     81     :return: A list of all spans that are not contained in any other span.
     82     """
---> 83     return any([s[0] >= span[0] and s[1] <= span[1] and s != span for s in all_spans])

File /opt/bitnami/miniconda/lib/python3.8/site-packages/fastcoref/spacy_component/spacy_component.py:83, in <listcomp>(.0)
     74 def _is_containing_other_spans(self,span: List[int], all_spans: List[List[int]]):
     75     """
     76     It returns True if there is any span in all_spans that is contained within span and is not equal to span
     77     :param span: the span we're checking to see if it contains other spans
   (...)
     81     :return: A list of all spans that are not contained in any other span.
     82     """
---> 83     return any([s[0] >= span[0] and s[1] <= span[1] and s != span for s in all_spans])

TypeError: 'NoneType' object is not subscriptable