shon-otmazgin / fastcoref

MIT License
147 stars 26 forks source link

Generator Object is not subscriptable - Unable to use resolve text #18

Closed SaadAhmed433 closed 1 year ago

SaadAhmed433 commented 1 year ago

Hello

I am trying to use the spacy pipeline feature with resolve text. I am using the quick start example like this

from fastcoref import spacy_component
import spacy

text = ["Alice goes down the rabbit hole. Where she would discover a new reality beyond her expectations.",
        "Alice goes down the rabbit hole. Where she would discover a new reality beyond her expectations."]

nlp = spacy.load("en_core_web_sm")
nlp.add_pipe("fastcoref")

docs = nlp.pipe(text, component_cfg={"fastcoref": {"resolve_text": True}})

docs[0]._.resolved_text

I get the following error

TypeError: 'generator' object is not subscriptable

Is there any work around for this!

shon-otmazgin commented 1 year ago

Hello @SaadAhmed433,

since nlp.pipe returns a generator, can you do:

for doc in docs:
    print(doc._.resolved_text)

I will update the docs accordingly

SaadAhmed433 commented 1 year ago

Yes thanks it works!

RohitRanga12 commented 10 months ago

@shon-otmazgin Hi, thanks for this great library. I see that resolve text works with spacy, but the fastcoref package itself does not have this feature. It would be very helpful to have this feature because using spacy is much slower when inferencing one text at a time.