Default 'textcat' pipe not working #10635
Answered
by
thomashacker
riZZZhik
asked this question in
Help: Coding & Implementations
-
Hi, got an issue with using 'textcat' pipe Initialization:import spacy
doc = "Apple is looking at buying U.K. startup for $1 billion in 10 days"
nlp = spacy.load('en_core_web_sm')
textcat = nlp.add_pipe('textcat') Codetokens = nlp(doc) # Crashes already on this line
category = textcat(tokens)
print(category) ErrorTraceback (most recent call last):
File "/Users/rizhik/Desktop/dev/belinsky/test.py", line 7, in <module>
tokens = nlp(doc)
File "/opt/homebrew/lib/python3.10/site-packages/spacy/language.py", line 1022, in __call__
error_handler(name, proc, [doc], e)
File "/opt/homebrew/lib/python3.10/site-packages/spacy/util.py", line 1617, in raise_error
raise e
File "/opt/homebrew/lib/python3.10/site-packages/spacy/language.py", line 1017, in __call__
doc = proc(doc, **component_cfg.get(name, {})) # type: ignore[call-arg]
File "spacy/pipeline/trainable_pipe.pyx", line 56, in spacy.pipeline.trainable_pipe.TrainablePipe.__call__
File "/opt/homebrew/lib/python3.10/site-packages/spacy/util.py", line 1617, in raise_error
raise e
File "spacy/pipeline/trainable_pipe.pyx", line 52, in spacy.pipeline.trainable_pipe.TrainablePipe.__call__
File "/opt/homebrew/lib/python3.10/site-packages/spacy/pipeline/textcat.py", line 191, in predict
scores = self.model.predict(docs)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/model.py", line 315, in predict
return self._func(self, X, is_train=False)[0]
File "/opt/homebrew/lib/python3.10/site-packages/thinc/layers/chain.py", line 54, in forward
Y, inc_layer_grad = layer(X, is_train=is_train)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/model.py", line 291, in __call__
return self._func(self, X, is_train=is_train)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/layers/concatenate.py", line 44, in forward
Ys, callbacks = zip(*[layer(X, is_train=is_train) for layer in model.layers])
File "/opt/homebrew/lib/python3.10/site-packages/thinc/layers/concatenate.py", line 44, in <listcomp>
Ys, callbacks = zip(*[layer(X, is_train=is_train) for layer in model.layers])
File "/opt/homebrew/lib/python3.10/site-packages/thinc/model.py", line 291, in __call__
return self._func(self, X, is_train=is_train)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/layers/chain.py", line 54, in forward
Y, inc_layer_grad = layer(X, is_train=is_train)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/model.py", line 291, in __call__
return self._func(self, X, is_train=is_train)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/layers/with_cpu.py", line 24, in forward
cpu_outputs, backprop = model.layers[0].begin_update(_to_cpu(X))
File "/opt/homebrew/lib/python3.10/site-packages/thinc/model.py", line 309, in begin_update
return self._func(self, X, is_train=True)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/layers/chain.py", line 54, in forward
Y, inc_layer_grad = layer(X, is_train=is_train)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/model.py", line 291, in __call__
return self._func(self, X, is_train=is_train)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/layers/resizable.py", line 27, in forward
Y, callback = layer(X, is_train=is_train)
File "/opt/homebrew/lib/python3.10/site-packages/thinc/model.py", line 291, in __call__
return self._func(self, X, is_train=is_train)
File "thinc/layers/sparselinear.pyx", line 43, in thinc.layers.sparselinear.forward
File "thinc/layers/sparselinear.pyx", line 68, in thinc.layers.sparselinear._begin_cpu_update
File "/opt/homebrew/lib/python3.10/site-packages/thinc/model.py", line 175, in get_dim
raise ValueError(err)
ValueError: Cannot get dimension 'nO' for model 'sparse_linear': value unset Info about spaCy
|
Beta Was this translation helpful? Give feedback.
Answered by
thomashacker
Apr 12, 2022
Replies: 1 comment
-
Hello, If you're new to spaCy, I'd recommend the free spaCy online course which covers all the fundamentals of using spaCy and training your own ML components. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
riZZZhik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
the error is thrown because the added
textcat
component is not initialized (https://spacy.io/api/textcategorizer#initialize). However, to be able to use thetextcat
component you need to train it first (https://spacy.io/usage/training).If you're new to spaCy, I'd recommend the free spaCy online course which covers all the fundamentals of using spaCy and training your own ML components.