☰ Learn Artificial Intelligence Tutorial Menu
Natural Language Processing and Large Language Models
Written by CSA mentors · Updated 26 Sept 2026 · 6 min read
Why can a chat assistant write a decent SQL query and, on a bad day, invent a court case that never happened? Both come from the same mechanism, and once you've seen it you'll never trust or distrust these tools blindly again. Natural language processing (NLP) is the branch of AI that reads, translates, summarises and writes human language. For decades it was a shelf of separate tools. Since 2018 the large language model (LLM) has swallowed nearly all of them.
The classic NLP jobs
| Task | Example | Business use |
|---|---|---|
| Classification | Is this review positive or negative? | Sentiment on Daraz product reviews |
| Named entity recognition | Find people, places, amounts in text | Pull invoice numbers and totals from emails |
| Translation | Urdu to English | Customer support across languages |
| Summarisation | Ten pages to ten lines | Board-pack summaries |
| Question answering | "What is the refund window?" | Policy chatbots |
| Generation | Write a reply | Drafting emails and reports |
What an LLM actually does
It predicts the next token. Text is split into tokens, chunks of roughly three to four characters (a common English word is one token, while a rare word or Urdu script is often several, which is why Urdu prompts cost more and sometimes come out worse). The model reads the tokens so far and outputs a probability for every possible next one. One gets picked, appended, and the loop runs again. That's the entire mechanism behind writing an essay or a SQL query. There is no second mechanism.
The temperature setting decides whether the model always takes the most likely token (temperature 0, more predictable and factual) or sometimes gambles on a less likely one (higher, more varied). For data work we keep it low. For brainstorming course names we turn it up.
How an LLM is made
- Pre-training. A transformer with billions of weights is trained to predict the next token across trillions of tokens of text and code. This takes months on thousands of GPUs and produces a "base model" that knows language and a great deal about the world, but just continues text; it does not answer questions helpfully.
- Instruction tuning. The base model is fine-tuned on examples of instructions and good responses, so it learns to behave like an assistant.
- Alignment. Human raters (and increasingly AI raters) compare responses; reinforcement learning from that feedback (RLHF) makes the model more helpful, honest and safe. The 2025–26 reasoning models add training that rewards correct step-by-step solutions on maths, code and logic problems, so the model learns to "think before answering".
- Deployment. The model is served through a chat app or API, wrapped with tools, memory, safety filters and, often, retrieval from your own documents.
Two limits that shape every conversation
- Context window. The most tokens the model can hold at once, prompt plus reply. Frontier models now take very long documents, but anything you want the model to use has to fit in that window or be fetched into it.
- Knowledge cut-off. The model only knows what was in its pre-training data up to a certain date. It doesn't know today's dollar rate or your company's leave policy unless you paste that in, connect a search tool, or use retrieval (RAG, which we cover in the agents lesson).
The most common question we get from students is some version of "why did it get last month's tax slab wrong?" Both limits above are the answer, and the fix is always to give the model the document.
Embeddings: meaning as numbers
Inside the model every token becomes a list of numbers, an embedding, arranged so similar meanings sit close together. Embedding models are also sold on their own. Turn any sentence into a vector and you can search by meaning instead of keyword, so "late delivery complaint" matches "my parcel still has not arrived" with no words in common. That's the basis of semantic search, clustering support tickets, and retrieval-augmented generation.
A language model in twenty lines
To feel what "predict the next token" means, build a bigram model. It learns which word tends to follow which from a few sentences, then generates text of its own.
import random
from collections import defaultdict, Counter
corpus = """the parcel from lahore was late .
the parcel from karachi was on time .
the order from lahore was delivered .
the order from multan was late ."""
nxt = defaultdict(Counter)
for line in corpus.splitlines():
words = ["<s>"] + line.split()
for a, b in zip(words, words[1:]):
nxt[a][b] += 1
random.seed(3)
word, out = "<s>", []
while word != "." and len(out) < 12:
choices = nxt[word]
word = random.choices(list(choices), weights=choices.values())[0]
out.append(word)
print(" ".join(out))
print("after 'from':", dict(nxt["from"]))
The model "learns" that city names follow from, and it generates sentences that sound right and are sometimes false ("the order from karachi was late"), because it knows statistics, not facts. A real LLM is this idea scaled up billions of times, with attention in place of a lookup table. That answers the question at the top of the page. Fluent and wrong come from the same place.
Inside a Karachi bank's complaints unit. Thousands of messages a week arrive in English, Urdu and Roman Urdu. An LLM sorts each one by product and severity, pulls out the account reference and drafts a first reply for an agent to approve. Because the model's cut-off predates the bank's current fee schedule, the fee document is fetched into the prompt for every fee-related query. Agents now spend their day on judgement instead of typing, and the audit team keeps every AI draft and human edit on file, which is the part we'd insist on.
Quick recap
- An LLM predicts the next token, over and over. Fluency is not truth.
- Models are pre-trained on huge text, then instruction-tuned and aligned. Reasoning models add step-by-step training on top.
- Context window and knowledge cut-off limit what a model can use, so give it fresh facts in the prompt or through retrieval.
- Embeddings turn meaning into vectors, which is what makes semantic search and RAG work.
Three things to try
- Add four more sentences to the bigram corpus and generate ten outputs. Which ones are false, and why did the model produce them?
- Ask any chat assistant a question about an event from last week. Note how it handles its knowledge cut-off.
- List three questions from your workplace that an LLM could answer only if you gave it a document in the prompt.
Lesson 9 of 18
Sign in to track your progress and earn learning points for every lesson you finish.
