Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default coreference usage runs into: "Did you forget to call initialize()? " #13062

Closed
mazieres opened this issue Oct 12, 2023 Discussed in #13060 · 3 comments
Closed

Default coreference usage runs into: "Did you forget to call initialize()? " #13062

mazieres opened this issue Oct 12, 2023 Discussed in #13060 · 3 comments
Labels
feat / coref Feature: Coreference resolution usage General spaCy usage

Comments

@mazieres
Copy link

Discussed in #13060

Originally posted by mazieres October 11, 2023
I'm trying to use the default experimental coreference feature.

On a fresh python3 venv with spacy==3.6.0 and spacy-experimental, I followed the coref tutorial, as such:

nlp = spacy.load("en_core_web_sm")
coref = nlp.add_pipe("experimental_coref")
doc = nlp("This is a sentence.")

And ran into this error (full log below):

ValueError: [E109] Component 'experimental_coref' could not be run. Did you forget to call `initialize()`?

I've encountered many posts on the web with comparable errors but none of the solution fixed my problem. Any idea where/what I could look for ?

Thanks in advance for your help.

Full error log

File ~/.tmp/lib/python3.11/site-packages/spacy/language.py:1042, in Language.__call__(self, text, disable, component_cfg)
   1041 try:
-> 1042     doc = proc(doc, **component_cfg.get(name, {}))  # type: ignore[call-arg]
   1043 except KeyError as e:
   1044     # This typically happens if a component is not initialized

File ~/.tmp/lib/python3.11/site-packages/spacy/pipeline/trainable_pipe.pyx:56, in spacy.pipeline.trainable_pipe.TrainablePipe.__call__()

File ~/.tmp/lib/python3.11/site-packages/spacy/util.py:1724, in raise_error(proc_name, proc, docs, e)
   1723 def raise_error(proc_name, proc, docs, e):
-> 1724     raise e

File ~/.tmp/lib/python3.11/site-packages/spacy/pipeline/trainable_pipe.pyx:52, in spacy.pipeline.trainable_pipe.TrainablePipe.__call__()

File ~/.tmp/lib/python3.11/site-packages/spacy_experimental/coref/coref_component.py:153, in CoreferenceResolver.predict(self, docs)
    151     continue
--> 153 scores, idxs = self.model.predict([doc])
    154 # idxs is a list of mentions (start / end idxs)
    155 # each item in scores includes scores and a mapping from scores to mentions

File ~/.tmp/lib/python3.11/site-packages/thinc/model.py:334, in Model.predict(self, X)
    331 """Call the model's `forward` function with `is_train=False`, and return
    332 only the output, instead of the `(output, callback)` tuple.
    333 """
--> 334 return self._func(self, X, is_train=False)[0]

File ~/.tmp/lib/python3.11/site-packages/thinc/layers/chain.py:54, in forward(model, X, is_train)
     53 for layer in model.layers:
---> 54     Y, inc_layer_grad = layer(X, is_train=is_train)
     55     callbacks.append(inc_layer_grad)

File ~/.tmp/lib/python3.11/site-packages/thinc/model.py:310, in Model.__call__(self, X, is_train)
    308 """Call the model's `forward` function, returning the output and a
    309 callback to compute the gradients via backpropagation."""
--> 310 return self._func(self, X, is_train=is_train)

File ~/.tmp/lib/python3.11/site-packages/thinc/layers/chain.py:54, in forward(model, X, is_train)
     53 for layer in model.layers:
---> 54     Y, inc_layer_grad = layer(X, is_train=is_train)
     55     callbacks.append(inc_layer_grad)

File ~/.tmp/lib/python3.11/site-packages/thinc/model.py:310, in Model.__call__(self, X, is_train)
    308 """Call the model's `forward` function, returning the output and a
    309 callback to compute the gradients via backpropagation."""
--> 310 return self._func(self, X, is_train=is_train)

File ~/.tmp/lib/python3.11/site-packages/thinc/layers/chain.py:54, in forward(model, X, is_train)
     53 for layer in model.layers:
---> 54     Y, inc_layer_grad = layer(X, is_train=is_train)
     55     callbacks.append(inc_layer_grad)

File ~/.tmp/lib/python3.11/site-packages/thinc/model.py:310, in Model.__call__(self, X, is_train)
    308 """Call the model's `forward` function, returning the output and a
    309 callback to compute the gradients via backpropagation."""
--> 310 return self._func(self, X, is_train=is_train)

File ~/.tmp/lib/python3.11/site-packages/thinc/layers/with_array.py:36, in forward(model, Xseq, is_train)
     35 if isinstance(Xseq, Ragged):
---> 36     return cast(Tuple[SeqT, Callable], _ragged_forward(model, Xseq, is_train))
     37 elif isinstance(Xseq, Padded):

File ~/.tmp/lib/python3.11/site-packages/thinc/layers/with_array.py:91, in _ragged_forward(model, Xr, is_train)
     90 layer: Model[ArrayXd, ArrayXd] = model.layers[0]
---> 91 Y, get_dX = layer(Xr.dataXd, is_train)
     93 def backprop(dYr: Ragged) -> Ragged:

File ~/.tmp/lib/python3.11/site-packages/thinc/model.py:310, in Model.__call__(self, X, is_train)
    308 """Call the model's `forward` function, returning the output and a
    309 callback to compute the gradients via backpropagation."""
--> 310 return self._func(self, X, is_train=is_train)

File ~/.tmp/lib/python3.11/site-packages/thinc/layers/concatenate.py:57, in forward(model, X, is_train)
     56 def forward(model: Model[InT, OutT], X: InT, is_train: bool) -> Tuple[OutT, Callable]:
---> 57     Ys, callbacks = zip(*[layer(X, is_train=is_train) for layer in model.layers])
     58     if isinstance(Ys[0], list):

File ~/.tmp/lib/python3.11/site-packages/thinc/layers/concatenate.py:57, in <listcomp>(.0)
     56 def forward(model: Model[InT, OutT], X: InT, is_train: bool) -> Tuple[OutT, Callable]:
---> 57     Ys, callbacks = zip(*[layer(X, is_train=is_train) for layer in model.layers])
     58     if isinstance(Ys[0], list):

File ~/.tmp/lib/python3.11/site-packages/thinc/model.py:310, in Model.__call__(self, X, is_train)
    308 """Call the model's `forward` function, returning the output and a
    309 callback to compute the gradients via backpropagation."""
--> 310 return self._func(self, X, is_train=is_train)

File ~/.tmp/lib/python3.11/site-packages/thinc/layers/chain.py:54, in forward(model, X, is_train)
     53 for layer in model.layers:
---> 54     Y, inc_layer_grad = layer(X, is_train=is_train)
     55     callbacks.append(inc_layer_grad)

File ~/.tmp/lib/python3.11/site-packages/thinc/model.py:310, in Model.__call__(self, X, is_train)
    308 """Call the model's `forward` function, returning the output and a
    309 callback to compute the gradients via backpropagation."""
--> 310 return self._func(self, X, is_train=is_train)

File ~/.tmp/lib/python3.11/site-packages/thinc/layers/hashembed.py:62, in forward(model, ids, is_train)
     59 def forward(
     60     model: Model[Ints1d, OutT], ids: Ints1d, is_train: bool
     61 ) -> Tuple[OutT, Callable]:
---> 62     vectors = cast(Floats2d, model.get_param("E"))
     63     nV = vectors.shape[0]

File ~/.tmp/lib/python3.11/site-packages/thinc/model.py:235, in Model.get_param(self, name)
    234 if not self._params.has_param(self.id, name):
--> 235     raise KeyError(
    236         f"Parameter '{name}' for model '{self.name}' has not been allocated yet."
    237     )
    238 return self._params.get_param(self.id, name)

KeyError: "Parameter 'E' for model 'hashembed' has not been allocated yet."

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
Cell In[6], line 1
----> 1 doc = nlp("This is a sentence.")

File ~/.tmp/lib/python3.11/site-packages/spacy/language.py:1045, in Language.__call__(self, text, disable, component_cfg)
   1042     doc = proc(doc, **component_cfg.get(name, {}))  # type: ignore[call-arg]
   1043 except KeyError as e:
   1044     # This typically happens if a component is not initialized
-> 1045     raise ValueError(Errors.E109.format(name=name)) from e
   1046 except Exception as e:
   1047     error_handler(name, proc, [doc], e)

ValueError: [E109] Component 'experimental_coref' could not be run. Did you forget to call `initialize()`?

Info about spaCy

  • spaCy version: 3.6.0
  • Platform: Linux-6.1.0-13-amd64-x86_64-with-glibc2.36
  • Python version: 3.11.2
  • Pipelines: en_core_web_sm (3.6.0), en_core_web_trf (3.6.1)
@rmitsch rmitsch added usage General spaCy usage feat / coref Feature: Coreference resolution labels Oct 13, 2023
@rmitsch
Copy link
Contributor

rmitsch commented Oct 13, 2023

Hi @mazieres, please provide your code and config so we can look into this. Thanks!

@mazieres
Copy link
Author

mazieres commented Oct 14, 2023

Hi @rmitsch, my post includes the packages installed, the code and its output together with the requested Info about SpaCy section. What else can I provide ?

@adrianeboyd
Copy link
Contributor

Hi, you're trying to run an uninitialized/untrained new coreference component rather than loading an existing trained model. You can install our experimental demo English model following the directions here:

https://github.com/explosion/spacy-experimental/releases/tag/v0.6.1

@explosion explosion locked and limited conversation to collaborators Oct 20, 2023
@adrianeboyd adrianeboyd converted this issue into discussion #13075 Oct 20, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
feat / coref Feature: Coreference resolution usage General spaCy usage
Projects
None yet
Development

No branches or pull requests

3 participants