The Transformer architecture processes sequences with self-attention, allowing models to compare tokens in parallel and capture relationships across long distances. Its encoder builds input representations, while its decoder generates target sequences; either component can also operate alone. section 3.1
from transformers import pipeline
classifier = pipeline('text-classification',
model = 'distilbert-base-uncased-finetuned-sst-2-english',
revision = 'af0f99b')
Run a sentiment-classification workflow with Hugging Face’s high-level pipeline API and a pinned pretrained DistilBERT model. section 1.1
The architecture relies on several interacting ideas:
- Self-attention weighs the importance of different words while encoding each word, capturing dependencies regardless of their distance. section 3.1
- Token embeddings convert tokens into dense numerical vectors representing semantic and syntactic information. section 3.4
- Positional encodings preserve word order because parallel processing does not inherently provide token positions. section 3.1
- Encoder-only models suit sentence classification and named entity recognition; decoder-only models suit text generation; encoder-decoder models suit translation and summarization. section 3.1
Sentiment analysis with a pretrained model
Pass an IMDb review paragraph to the pipeline created with the DistilBERT sentiment model. The returned result identifies the review as positive, without requiring model training or detailed knowledge of text-classification internals. section 1.1
Hugging Face Transformers packages open-source Transformer implementations for text, image, and audio tasks. Its pipeline function wraps complex NLP workflows such as classification, named entity recognition, translation, and summarization behind a small high-level API. section 1.5



























