I basically just want to use the transformers pipeline() to classify data, but independent of which model I try to use, it returns the same error, stating Numpy is not available
Code I’m running:
pipe = pipeline("text-classification", model="AdamLucek/roberta-llama3.1405B-twitter-sentiment")
sentiment_pipeline('Today is a great day!')
# other model i've tried:
sentiment_pipeline = pipeline(model="cardiffnlp/twitter-roberta-base-sentiment-latest", tokenizer="cardiffnlp/twitter-roberta-base-sentiment-latest")
sentiment_pipeline('Today is a great day!')
Error I receive:
RuntimeError Traceback (most recent call last)
Cell In[49], line 1
----> 1 sentiment_pipeline('Today is a great day!')
File ~AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagestransformerspipelinestext_classification.py:156, in TextClassificationPipeline.__call__(self, inputs, **kwargs)
122 """
123 Classify the text(s) given as inputs.
124
(...)
153 If `top_k` is used, one such dictionary is returned per label.
154 """
155 inputs = (inputs,)
--> 156 result = super().__call__(*inputs, **kwargs)
157 # TODO try and retrieve it in a nicer way from _sanitize_parameters.
158 _legacy = "top_k" not in kwargs
File ~AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagestransformerspipelinesbase.py:1257, in Pipeline.__call__(self, inputs, num_workers, batch_size, *args, **kwargs)
1249 return next(
1250 iter(
1251 self.get_iterator(
(...)
1254 )
1255 )
1256 else:
-> 1257 return self.run_single(inputs, preprocess_params, forward_params, postprocess_params)
File ~AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagestransformerspipelinesbase.py:1265, in Pipeline.run_single(self, inputs, preprocess_params, forward_params, postprocess_params)
1263 model_inputs = self.preprocess(inputs, **preprocess_params)
1264 model_outputs = self.forward(model_inputs, **forward_params)
-> 1265 outputs = self.postprocess(model_outputs, **postprocess_params)
1266 return outputs
File ~AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagestransformerspipelinestext_classification.py:208, in TextClassificationPipeline.postprocess(self, model_outputs, function_to_apply, top_k, _legacy)
204 outputs = model_outputs["logits"][0]
206 if self.framework == "pt":
207 # To enable using fp16 and bf16
--> 208 outputs = outputs.float().numpy()
209 else:
210 outputs = outputs.numpy()
RuntimeError: Numpy is not available
I already tried simply un- and reinstalling transformers and numpy and for both the most recent versions are installed (and should be compatible).
Anyone has an idea on how to solve this?
1
Try:
pip install "numpy<2"
then restart the kernel.
2