Hugging Face LLM Course: Practical Transformers · Урок 1
Pipeline API: Run Models in Three Lines
Hugging Face pipeline() lets you run NLP tasks without knowing the model's architecture, and with a chat model it handles generation, summarization and translation in messages format (transformers 5).
ENМатеріали курсів поки англійською. Інтерфейс, ШІ-наставник і перевірка завдань — українською.
What is pipeline
pipeline() handles model selection, tokenization, and post-processing automatically. The examples below target transformers 5 (5.24.0 is current as of November 21, 2026). Version 5 is PyTorch-only and needs Python 3.11 or newer: pip install -U transformers torch.
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
import torch
clf = pipeline("sentiment-analysis")
print(clf("This library is amazing!")) # [{'label': 'POSITIVE', 'score': 0.9998}]
print(clf("This library is amazing!", top_k=None)) # probabilities for every class
model_name = "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
inputs = tokenizer("I love transformers!", return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
print(model.config.id2label[logits.argmax(-1).item()])
zs = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
print(zs("Python is a language", candidate_labels=["tech", "sport", "food"]))
Далі урок відкривається після безкоштовної реєстрації
Реєстрація через email або Google відкриває перші два уроки кожного курсу назавжди і 7 днів повного доступу до всього каталогу. Картка не потрібна.


