Marco Meyer
Marco Meyer

Reputation: 373

Huggingface: NameError: name 'pipeline' is not defined

I try to execute the standard intro example from the HuggingFace documentation in a Jupiter notebook:

from transformers import pipeline
classifier = pipeline("sentiment-analysis")
classifier("I've been waiting for a HuggingFace course my whole life.")

Importing the pipeline method apparently works -- no error message. If I declare the classifier in the next line, I get the following error:

NameError Traceback (most recent call last) /var/folders/m_/sn4z8b8s6676slgsrc3smg7w0000gn/T/ipykernel_7310/39715268.py in ----> 1 classifier = pipeline("sentiment-analysis") 2 classifier("I've been waiting for a HuggingFace course my whole life.")

NameError: name 'pipeline' is not defined

The transformers library is installed. The error also occurs after creating a clean environment and only installing transformers, tensor flow, and dependencies.

Importing other libraries and using their methods works.

I have previously worked with HuggingFace. I encounter this error since moving my files to a new MacBook.

Does anyone know what could cause this weird behavior?

Importing transformers does not produce an error either, yet calling

transformers.__version__

Produces a Name Error also.

Edit: The transformers library is installed in the environment I use to run the notebook -- pip show transformers yields:

    (py-spacy-new) (base) MacBook-Pro-von-Marco:huggingface marco$  pip show transformers
Name: transformers
Version: 4.12.5
Summary: State-of-the-art Natural Language Processing for TensorFlow 2.0 and PyTorch
Home-page: https://github.com/huggingface/transformers
Author: Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Sam Shleifer, Patrick von Platen, Sylvain Gugger, Suraj Patil, Stas Bekman, Google AI Language Team Authors, Open AI team Authors, Facebook AI Authors, Carnegie Mellon University Authors
Author-email: [email protected]
License: Apache
Location: /Users/marco/Documents/programming/spacy tests/Spacy tests/py-spacy-new/lib/python3.7/site-packages
Requires: importlib-metadata, tqdm, requests, pyyaml, tokenizers, filelock, huggingface-hub, numpy, regex, packaging, sacremoses
Required-by: 

Upvotes: 1

Views: 18140

Answers (2)

Gnani
Gnani

Reputation: 1

This should solve the problem, I would guess.

pipeline = keras_ocr.pipeline.Pipeline()

Upvotes: 0

Carlos
Carlos

Reputation: 300

this seems like you haven´t installed the transformers library you should read this documentation: https://huggingface.co/transformers/quicktour.html

TLDR: you should run this command on your terminal

>>> pip install transformers

or if you use anaconda

>>> conda install transformers

Upvotes: 2

Related Questions