LLM Basics
By the Syncfusion DevTutorials team · Last updated
What a large language model is, the one job it does (guess the next word), what it is good at, what it cannot do, and how it learned from text.
LLM Basics
You may have used a chat assistant like ChatGPT, Claude, or Gemini. You type a question, and a few seconds later, a complete answer appears, word by word.
The program that creates that answer is called a large language model, or LLM. This lesson explains what it is in simple terms, without any complicated math.
The main idea: an LLM is a program that guesses the next word. It does this one small task repeatedly until the response is complete.
A Real-World Example
Think about the keyboard on your phone. When you type "Have a", three words appear above the keys: "good", "great", "nice".
Your phone is trying to guess what you will type next. It learned this from many messages that people have typed before. "Have a good" is a common phrase, so "good" appears first.
An LLM works in a similar way. It is a much larger and smarter version of that phone keyboard.
Your phone guesses one word from a few words. An LLM guesses the next word from the entire text, again and again.
- Your phone guesses one next word based on a short message.
- An LLM guesses the next word based on a longer text, like a full question.
- Then it adds that word and makes another guess, many times in a row.
In simple words: an LLM is autocomplete that keeps going until it has written a complete answer.
What You Will Learn
In this lesson, you will learn:
- What the words "large", "language", and "model" mean.
- How an LLM creates a response by guessing one word at a time.
- How it learned to make good guesses.
- What an LLM is good at.
- What an LLM cannot do, and why it can be wrong.
The code boxes on this page use plain JavaScript. They create a small "next word guesser" so you can see the concept in action. A real LLM is much larger, but the basic idea is the same. Press Run on each box and change the values to see what happens.
What Is an LLM?
An LLM is a computer program that reads text and writes text. Let us look at its name one word at a time.
Large
"Large" has two meanings.
- It learned from a huge amount of text. This includes books, websites, articles, and code. It is much more than one person could read in many lifetimes.
- It has a huge number of settings inside. These settings are called parameters. Smaller LLMs have hundreds of millions, while larger ones have hundreds of billions.
A parameter is a number that the model adjusts as it learns. Together, the parameters store what the model has learned about language.
Language
"Language" means that the model works with text.
- It reads your words as input.
- It writes words as output.
- The text can be in English, another human language, or code. To the model, all of it is text.
Model
A model is a program that copies a pattern it has learned. A weather model learns patterns from past weather to predict tomorrow's weather. A language model learns patterns from text to predict the next word.
In simple words: a large language model is a program that learned the patterns of text from a huge amount of reading.
How an LLM Writes a Reply
This is the most important section in the entire course. Everything that follows builds on this.
The One Job: Guess the Next Word
An LLM has one job. It looks at all the text so far and guesses the word that should come next.
Here is the phone keyboard idea represented in code. For the text "Have a", the box keeps track of how often each next word appeared in previous messages. The code selects the most common one.
Pick the most likely next word
const nextWords = { "good": 50, "great": 30, "happy": 20 };
let best = "";
let bestCount = 0;
for (const word in nextWords) {
if (nextWords[word] > bestCount) {
best = word;
bestCount = nextWords[word];
}
}
console.log("Have a ... ->", best);
Expected output:
Have a ... -> good
"good" appeared 50 times, more than the others. So it is chosen. Try changing "great": 30 to "great": 80 and run it again.
Learning the Patterns From Text
Where do those counts come from? The model learns them by reading text. The next box reads one short sentence. For each word, it counts which word came right after it.
Learn which word follows which
const text = "the cat sat on the mat the cat ate the fish";
const words = text.split(" ");
const after = {};
for (let i = 0; i < words.length - 1; i++) {
const word = words[i];
const next = words[i + 1];
after[word] = after[word] || {};
after[word][next] = (after[word][next] || 0) + 1;
}
console.log("After 'the':", JSON.stringify(after["the"]));
console.log("After 'cat':", JSON.stringify(after["cat"]));
Expected output:
After 'the': {"cat":2,"mat":1,"fish":1}
After 'cat': {"sat":1,"ate":1}
After "the", the word "cat" appeared twice. "mat" and "fish" appeared once each. This table is what our small model "knows".
A real LLM does not maintain a simple table like this. It learns much richer patterns and considers many words before, not just one. But the goal remains the same: learn what usually comes next.
Turning Counts Into Chances
An LLM does not just select one word. It assigns every possible next word a probability. A probability is a chance from 0% to 100%.
Every possible next word gets a chance. All the chances add up to 100%.
The next box calculates these chances based on the counts.
Turn counts into chances
const counts = { cat: 2, mat: 1, fish: 1 };
const total = 2 + 1 + 1;
for (const word in counts) {
const percent = Math.round((counts[word] / total) * 100);
console.log(word, percent + "%");
}
Expected output:
cat 50%
mat 25%
fish 25%
After "the", there is a 50% chance of "cat". All the chances add up to 100%. You will see real probabilities from a real model later in this course.
One Word at a Time
A complete reply is created by repeating the guessing process. The model guesses a word, adds it to the text, and guesses again.
The loop behind every reply: read the text, guess one word, add it, and repeat.
The next box executes this loop five times.
Write a sentence, one guess at a time
const after = {
the: { cat: 2, mat: 1 },
cat: { sat: 1, ate: 1 },
sat: { on: 1 },
on: { the: 1 },
ate: { the: 1 },
mat: { the: 1 },
};
function mostLikely(word) {
let best = null;
let bestCount = 0;
for (const next in after[word]) {
if (after[word][next] > bestCount) {
best = next;
bestCount = after[word][next];
}
}
return best;
}
let word = "the";
const sentence = [word];
for (let step = 0; step < 5; step++) {
word = mostLikely(word);
sentence.push(word);
}
console.log(sentence.join(" "));
Expected output:
the cat sat on the cat
The model generated a sentence that was never in its training text. It combined patterns it had learned. This is how an LLM can create new answers.
Notice the ending: "on the cat". It sounds a little strange, but every step followed a real pattern. Our small model only looks one word back. A real LLM can look thousands of words back, so its sentences make much more sense.
In simple words: the whole reply is just "guess the next word" repeated many times.
Easy Way to Remember: an LLM is autocomplete on repeat. Guess one word, add it, guess again.
How an LLM Learned
An LLM learns in two major steps. A later lesson, Model Training, explains them in detail.
Step 1 teaches the patterns of text. Step 2 teaches the model to respond like an assistant.
- Reading a lot. The model reads a huge amount of text. It repeatedly hides the next word, guesses it, and checks the answer. Each incorrect guess slightly changes its parameters. This process is called pretraining.
- Learning to be helpful. People then provide good examples of questions and answers. This teaches it to respond like an assistant, not just continue any text.
After these steps, learning stops. The model does not continue learning from your conversations while you use it.
What LLMs Are Good At
LLMs are good at tasks where the answer consists of words and patterns.
- Writing. Emails, summaries, stories, and product descriptions.
- Explaining. Turning difficult topics into simple steps.
- Changing text. Translating, shortening, or changing the tone.
- Code. Writing small functions, explaining code, and identifying simple bugs.
- Extracting facts from text you provide. For example, finding names and dates in an email.
What LLMs Cannot Do
LLMs have real limitations. Understanding them will help you avoid many mistakes.
It Can Sound Right and Still Be Wrong
The model chooses words that sound likely. It does not check whether they are true. Because of this, it can give a wrong answer with a very confident tone.
This is called a hallucination. You will learn more about it in the Using LLMs chapter.
It Does Not Look Things Up
A plain LLM does not search the web while answering. It only relies on patterns it learned during training. If a word or fact was never included in its training text, it has no pattern for it.
No pattern, no guess
const after = {
the: { cat: 2, mat: 1 },
cat: { sat: 1, ate: 1 },
};
console.log("After 'cat':", JSON.stringify(after["cat"]));
console.log("After 'dog':", JSON.stringify(after["dog"]));
Expected output:
After 'cat': {"sat":1,"ate":1}
After 'dog': undefined
Our small model never encountered "dog", so it knows nothing about it. A real LLM is not this strict. It will still make a guess, and that guess can be wrong.
Its Knowledge Has an End Date
Training ends on a specific date. This date is called the knowledge cutoff. The model does not know about anything that happened after it.
The model has patterns only for things in its training text. Anything after the cutoff is unknown to it.
It Is Weak at Exact Work
LLMs are not calculators. They can make mistakes in long calculations, counting letters, or working out exact dates. For precise answers, use real code or a real tool.
Always verify important answers. Never copy facts, numbers, legal text, or medical advice from an LLM without checking a trusted source.
Common Mistakes
| Mistake | Wrong idea | Correct idea | What goes wrong |
|---|---|---|---|
| Treating it like a search engine | "It found this answer on the internet." | A plain LLM generates the answer from patterns it learned. It does not look anything up. | You trust facts that were never checked against a source. |
| Trusting a confident answer | "It sounds sure, so it must be right." | The model always sounds confident. It picks likely words, not true facts. | Wrong facts, numbers, or code end up in your work. |
| Thinking it learns from your chat | "I corrected it yesterday, so now it knows." | Learning stopped when training ended. A new chat starts fresh. | The same mistake comes back in the next chat. |
| Expecting recent news | "It will know what happened last week." | It knows nothing after its knowledge cutoff. | You get an old or made-up answer about recent events. |
| Using it as a calculator | "It can add these 20 prices for me." | It guesses digits like words. Use real code for exact math. | Totals and counts can be slightly wrong. |
| Thinking it understands like a person | "It knows what I mean, like a friend would." | It follows patterns in text. Give it clear, complete instructions. | Vague questions lead to vague or off-target answers. |
Exercises
Each exercise ends with a value on the last line. Press Check to compare it with the expected answer.
What to Remember
- An LLM is a program that reads text and writes text.
- Its one job is to guess the next word. A reply is that guess, repeated.
- It learned the patterns of text by reading a huge amount of it.
- Parameters are the numbers inside the model that store what it learned.
- It is good at writing, explaining, changing text, and simple code.
- It can sound right and still be wrong, so check important answers.
- It does not look things up, and it does not know events after its knowledge cutoff.
Next: Generation Flow, the full path from the prompt you type to the reply you read.