← All mindmapsMAIN TOPIC · 06 / 14

Natural Language Processing

Text representation, sequence tasks and evaluation

Explore full topic ↗
100%
Natural Language Processing overview revision sheet; full text available below

Use + to enlarge the vector sheet up to 400%, then pan horizontally or vertically. A readable text version is below.

Readable revision notes (18 concepts)

The same content as the visual sheet, optimized for mobile and assistive technology.

01 · Text preparation

  • Normalize where appropriate; preserve task signals
  • Tokenization splits text; subwords handle rare forms
  • Stemming heuristics; lemmatization uses linguistic forms

02 · Sparse features

  • BoW counts terms; n-grams capture local order
  • TF-IDF weights frequency by document rarity
  • Sparse features + linear classifier make strong baseline

03 · Embeddings

  • Dense vectors encode learned relationships
  • Static: word vectors; contextual: token depends on context
  • Cosine = (a·b)/(‖a‖‖b‖) for nonzero vectors

04 · Sequence handling

  • Vocabulary → token IDs → embeddings
  • Padding aligns lengths; mask padding in attention/loss
  • Truncation may lose relevant context

05 · NLP tasks

  • Classification / sentiment: document label
  • NER: entity spans; QA: extract or generate answer
  • Summarization, translation, semantic search

06 · Model families

  • Naive Bayes/linear models for sparse features
  • RNN/LSTM for recurrence; Transformer for attention
  • Encoder for understanding; decoder for generation

07 · Evaluation

  • Classification: precision, recall, macro/micro F1
  • QA: exact match + token F1; NER: span-level F1
  • BLEU/ROUGE overlap; complement with human checks

08 · Training & transfer

  • Pretrained tokenizer + model must be compatible
  • Fine-tune on task data; avoid split contamination
  • Domain shift and label imbalance affect quality

09 · Reliability

  • Negation, ambiguity, sarcasm, multilingual text
  • Check fairness, privacy, annotation consistency
  • Inspect error slices; evaluate on held-out real examples

10 · Tokenization algorithms

  • BPE merges frequent symbol pairs; WordPiece uses vocabulary training criterion; Unigram prunes probabilistic pieces.
  • Subwords reduce unknown words but can split meaning; use model tokenizer.
  • Special tokens, padding/truncation and attention masks must match model.

11 · Language models & n-grams

  • n-gram approximates next token using last n−1 tokens; sparsity needs smoothing.
  • P(sequence)=ΠP(tokenₜ|history); perplexity=exp(mean negative log-likelihood).
  • Compare perplexity only with compatible tokenization/data.

12 · TF-IDF & similarity

  • tf-idf=term frequency × inverse document frequency; definitions vary.
  • Cosine normalizes dot product; sparse baseline for search and classification.
  • Fit vocabulary/IDF on training documents only.

13 · Word2Vec / GloVe / FastText

  • CBOW predicts center from context; skip-gram predicts context from center.
  • GloVe factorizes co-occurrence statistics; FastText uses character subwords.
  • Static word vectors cannot directly disambiguate contextual senses.

14 · Text classification & NER

  • Logistic regression/SVM + TF-IDF; neural encoder for contextual features.
  • NER BIO tags: B begins, I continues, O outside; decode valid spans.
  • Macro F1 weights classes equally; micro pools decisions; entity-level F1.

15 · Sequence-to-sequence & QA

  • Encoder-decoder for translation/summarization; teacher forcing during training.
  • Extractive QA predicts answer span; generative QA emits tokens.
  • Beam search can favor short outputs; length penalty and task metrics.

16 · BERT vs GPT

  • BERT-style bidirectional encoder with masked LM; classify/token-label.
  • GPT-style causal decoder trained next token; generates autoregressively.
  • T5-style text-to-text encoder-decoder; select based on task.

17 · Text evaluation & errors

  • BLEU n-gram precision + brevity penalty; ROUGE overlap/recall variants.
  • Exact match and token F1 for QA; semantic and human evaluation supplement.
  • Test negation, entities, rare words, domain shifts, multilingual and harmful bias.

18 · Information retrieval

  • BM25 sparse lexical ranking; dense embeddings enable semantic search.
  • Cross-encoder reranks query-document pairs; higher cost than bi-encoder.
  • Recall@k, MRR, nDCG; separate retrieval vs generation evaluation.

References & further study

Original schematics illustrate concepts, not measured data. Review these references for full derivations and implementation details.

Last 30 min revisionHigh-yield interview Q&As