This introductory lecture covers the fundamentals of natural language processing, from task classification and tokenization to word embeddings and recurrent models, culminating in a high-level overview of the revolutionary transformer architecture.
Classification: Takes a single text input and predicts a single output label. Examples include sentiment analysis (positive/negative/neutral), intent detection, language identification, and topic modeling. Evaluation uses standard classification metrics: accuracy, precision, recall, and F1-score, which are critical for imbalanced datasets.
Multi-classification: Takes a single text input and predicts multiple outputs, typically at the token level. The most common example is Named Entity Recognition (NER), which labels words as locations, people, times, or organizations. Other tasks include part-of-speech tagging and dependency parsing.
Generation: Takes text input and produces variable-length text output. This is the most popular category today and includes machine translation, question answering, summarization, code generation, and creative writing. Traditional evaluation metrics include BLEU and ROUGE (which require reference texts), while modern approaches use reference-free LLM-based metrics. Perplexity, which measures how surprised the model is by its output, is also commonly used (lower is better).
Word-level tokenization: Splits text into individual words. Simple to implement but suffers from high out-of-vocabulary (OOV) rates and cannot leverage shared word roots (e.g., "bear" and "bears" are treated as completely separate tokens).
Subword tokenization: Splits text into meaningful subword units (e.g., "unhappiness" becomes "un", "happy", "ness"). This is the standard approach used in all modern LLMs. It balances low OOV rates with reasonable sequence lengths and leverages shared morphological roots.
Character-level tokenization: Splits text into individual characters. Robust to misspellings and has zero OOV rate but produces extremely long sequences, making computation prohibitively expensive for most tasks.
Continuous Bag of Words (CBOW): Predicts a target word from its surrounding context words.
Skip-gram: Predicts the surrounding context words from a single target word.
Query: What the current token is looking for
Key: What each token in the sequence offers
Value: The actual content of each token
Encoder: Processes the input sequence and produces context-aware embeddings. Each encoder layer contains a multi-head self-attention layer and a feed-forward neural network, with residual connections and layer normalization around each component. Multi-head attention runs multiple self-attention computations in parallel with different projection matrices, allowing the model to learn different types of relationships between tokens.
Decoder: Generates the output sequence one token at a time. Each decoder layer contains three components: a masked multi-head self-attention layer (which only attends to previously generated tokens), a cross-attention layer (which attends to the encoder’s output), and a feed-forward neural network.
The input English sentence is tokenized, and each token is converted to an embedding.
Positional encodings are added to the embeddings to preserve sequence order.
The embeddings pass through multiple stacked encoder layers, producing context-aware encoder outputs.
Decoding starts with a special beginning-of-sequence (BOS) token.
The decoder processes the BOS token, using masked self-attention to attend to itself and cross-attention to attend to the encoder outputs.
The final decoder output is projected to the vocabulary size and passed through a softmax layer to produce a probability distribution over the next token.
The most probable token is selected and added to the output sequence.

