pythonbeginner

Hugging Face Transformers Pipeline

Run text classification, NER, summarisation, and translation tasks with the HF Pipelines API.

python
from transformers import pipeline

# Sentiment analysis
sentiment = pipeline('sentiment-analysis')
print(sentiment(['I love building AI systems!', 'This is terrible.']))

# Summarisation
summariser = pipeline('summarization', model='facebook/bart-large-cnn')
text = '''Artificial intelligence is transforming every industry. From healthcare diagnostics to financial forecasting, AI systems now perform tasks that previously required human expertise.'''
print(summariser(text, max_length=60, min_length=20))

# Named entity recognition
ner = pipeline('ner', grouped_entities=True)
print(ner('Elon Musk founded SpaceX and Tesla in California.'))

Use Cases

  • NLP tasks
  • text classification
  • entity extraction

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.