· Xiaojing Yang · NLP and LLMs · 2 min read

中文

Transformers for NLP

How Transformers combine self-attention, feed-forward layers, residuals, and positional information.

Core idea

A Transformer is a stack of attention-based representation updates.

1. The architecture idea

Transformers replaced recurrence with self-attention and parallel computation. Each layer updates token representations using information from the sequence.

Transformer block
Token embeddings
input vectors
Self-attention
mix contextual information
Residual + norm
stabilize updates
Feed-forward
transform each position
Next layer
repeat

2. Encoder, decoder, encoder-decoder

FamilyTypical use
Encoder-onlyclassification, NER, sentence representation
Decoder-onlylanguage modeling, chat, generation
Encoder-decodertranslation, summarization, text-to-text tasks

3. Hugging Face practice

from transformers import AutoTokenizer, AutoModelForSequenceClassification

name = "distilbert-base-uncased"
tokenizer = AutoTokenizer.from_pretrained(name)
model = AutoModelForSequenceClassification.from_pretrained(name, num_labels=2)

4. My research connection

Transformers are the common backbone behind multilingual encoders, MT systems, COMET-like metrics, and LoRA fine-tuning. Understanding the block helps explain where adapters can be inserted and why tokenization affects everything downstream.

Engineering view

Use pretrained checkpoints and task heads.

Research view

Ask what representation, language coverage, and adaptation mechanism the architecture supports.

Takeaway

Transformers are not one model. They are a reusable architecture pattern for contextual representation and generation.

Interview pattern

My interview answer would usually be:

  1. define the concept in one sentence;
  2. explain the data flow;
  3. name the main failure mode;
  4. connect it to evaluation, multilinguality, or fine-tuning.

References

Share:
Back to Blog

Related Posts

View All Posts »
FoundationsNLP and LLMsEN

Attention Mechanism

Attention as a learned way to decide what context matters for each token.

FoundationsNLP and LLMsEN

Fine-Tuning Transformers

How pretrained language models are adapted to a task or domain with supervised data.

FoundationsNLP and LLMsEN

LLM Evaluation and Failure Modes

A practical map of LLM evaluation risks: hallucination, prompt sensitivity, bias, contamination, and brittle benchmarks.

FoundationsNLP and LLMsEN

NLP Evaluation

Why NLP evaluation needs metrics, uncertainty, human judgment, and task-specific error analysis.