pythonbeginner
Hugging Face Transformers Pipeline
Run text classification, NER, summarisation, and translation tasks with the HF Pipelines API.
pythonPress ⌘/Ctrl + Shift + C to copy
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.
pythonintermediate
Text Classification with Hugging Face
Fine-tune or use pre-trained Hugging Face models for text classification.
Best for: Sentiment analysis
#ai#huggingface
pythonintermediate
Hugging Face Inference API
Run ML models via the Hugging Face Inference API for text generation, classification, and embeddings.
Best for: Text classification
#huggingface#inference
pythonbeginner
Zero-Shot Text Classification
Classify text into custom categories using zero-shot NLI models without training data.
Best for: content categorization
#huggingface#zero-shot
typescriptadvanced
AI Prompt Chaining Pattern
Chain multiple LLM calls sequentially where each step's output feeds into the next for complex tasks.
Best for: Complex multi-step AI workflows
#prompt-engineering#chaining