NLP Foundations at a Glance #
Consider “Book a room near the river bank.” You can use the same sentence to see what different NLP components contribute.
| Question | Technique | What you get |
|---|---|---|
| What does the person want? | Intent and entity extraction | A booking request for a room near a location |
| Which notes are related to the request? | TF-IDF or embeddings | A ranked list of passages |
| What might come next after “book a”? | A language model | A distribution over possible next tokens |
| What grammatical role does “book” play? | Part-of-speech tagging | A verb tag supported by the context |
| How could the system respond? | Prompted generation | A reply that can ask for dates or other missing details |
1. Representing text #
Bag-of-words vectors record which terms occur. TF-IDF gives more weight to terms that are frequent in a document and uncommon across the collection. Word2Vec learns dense vectors from the contexts in which words appear. A static vector for bank serves all its uses, while a contextual model can produce different vectors for river bank and bank account.
2. Predicting text #
An n-gram model predicts from recent token counts. Smoothing helps when a sequence was absent from training. A feed-forward neural language model also uses a fixed window, but learns embeddings and combines them through hidden layers. Perplexity compares how well probabilistic models predict held-out tokens when evaluation data and tokenisation are comparable.
3. Assigning tags #
In an HMM tagger, transitions describe which tags tend to follow each other and emissions describe which words each tag tends to produce. The forward algorithm sums the probabilities of all tag paths for a sentence. Viterbi finds the highest-scoring tag path. MEMMs and neural taggers can use richer evidence such as spelling and the words on either side of a token.
4. Giving a language model a task #
A prompt can specify the task, expected format and examples. For a booking assistant, ask the model to extract the request and flag missing dates. If it needs to quote current prices or availability, supply information from the booking system and evaluate whether the reply follows that evidence.
Try it #
Compare “Book a room near the river bank” with “The book was left in the bank.” Mark the part of speech of book and the likely sense of bank in each. Then decide what information you would need before a booking assistant could act.