Math Foundations — Lecture 5
Embedding objectives (CBOW, skip-gram, GloVe), seq2seq conditioning, F-beta, BLEU, BPE algorithm.
Dot product & similarity
Dot product mixes magnitude and direction. Cosine similarity (\(\cos\theta\)) isolates direction. Both appear throughout embedding and attention math.
word2vec CBOW objective
Predict centre word \(w_c\) from averaged context embeddings:
Maximise \(\sum\log p(w_c\mid\text{ctx})\) over the corpus. Full softmax over \(|V|\) is expensive → negative sampling approximation.
Skip-gram objective
Reverse direction: predict each context word from the centre word:
Maximise \(\sum_{c}\sum_{j\in\text{ctx}(c)}\log p(w_j\mid w_c)\). Often stronger for rare words than CBOW.
Negative sampling
\(K\) negative samples drawn from noise distribution \(P_n\propto f(w)^{3/4}\).
GloVe objective
Learns vectors so that dot product approximates log co-occurrence.
Seq2seq conditioning
Encoder produces context \(\mathbf{c}\) (e.g. last hidden state). Decoder generates:
Teacher forcing: at training, condition on gold \(y_{
\(F_\beta\) score (chrF)
\(\beta=1\) → equal weight (standard F1). \(\beta>1\) → recall-weighted. \(\beta<1\) → precision-weighted. chrF uses character n-gram P/R in this formula.
BLEU score
Geometric mean of n-gram precisions with a brevity penalty:
Brevity penalty discourages very short translations that trivially achieve high precision.
Byte-Pair Encoding (BPE)
- Start: vocabulary = all individual characters (+ end-of-word marker).
- Count all adjacent symbol pairs in the training corpus.
- Merge the most frequent pair into a new symbol.
- Repeat 2–3 until vocabulary reaches target size \(K\).
At inference: apply merges in learned order. Rare words decompose into known subwords; frequent words stay whole.