Natural Language Processing
Related: 16. Recurrent Neural Networks | 15. Regression and Text Classification with FCNs | 2. Supervised Learning | Artificial Intelligence
NLP vs LLMs
- NLP — the broader field of techniques for analysing human language (includes statistical models like N-gram, TF-IDF, BoW)
- LLMs — a specific type of deep learning model within NLP, trained on massive datasets (e.g., GPT, BERT)
Levels of Linguistic Analysis
- Syntax — what is grammatically correct
- Semantics — what is the meaning
Ambiguity Types
| Type | Description | Example |
|---|---|---|
| Lexical | Words with multiple meanings | ”bank” (financial vs river) |
| Semantic | Sentences with multiple meanings | ”I saw him with a telescope” |
| Anaphoric | Pronouns referring to earlier mentions | ”He told his dog to sit, and it did” |
NLP Pipeline
- Sentence segmentation — split text into sentences
- Tokenisation — split sentences into words/tokens
- Stemming — crude chopping of word endings (e.g., “eating” → “eat”)
- Lemmatisation — proper reduction using vocabulary (e.g., “better” → “good”, “drove” → “drive”)
- Stop word removal — remove common words (“the”, “a”, “is”)
- POS tagging — assign part of speech (noun, verb, adjective, etc.)
- Named Entity Recognition — identify persons, locations, times
Bag of Words (BoW)
Represents a document as a vector of word frequencies. Ignores word order entirely.
Process:
- Build a vocabulary of known words
- For each document, count occurrences of each vocabulary word
- Resulting vector represents the document
TF-IDF (Term Frequency — Inverse Document Frequency)
Measures importance of a word to a document within a corpus.
Words that appear frequently in one document but rarely across the corpus get high TF-IDF scores.
Cosine Similarity
Measures similarity between two document vectors:
N-gram Language Models
Uses the probabilities of word sequences to predict the next word.
Markov assumption: the probability of a word depends only on the previous words:
MLE for conditional probabilities:
Types:
- Unigram:
- Bigram:
- Trigram:
Limitations: Computationally expensive for large ; gives zero probability to unseen sequences (sparsity). 16. Recurrent Neural Networks address these limitations by learning sequential patterns without fixed context windows.