No history yet

LLM Input Processing

From Words to Numbers

Large Language Models work with numbers, not words. Before an LLM can understand your prompt, it has to translate your text into a format it can process. This all starts with a process called tokenisation which breaks your input down into manageable pieces.

Think of tokens as the individual Lego bricks the model uses to build its understanding and its response. They can be whole words, like "apple," parts of words, like "-ing," or even just punctuation.

For example, the sentence "Prompt engineering is powerful" might be broken down into these tokens: ["Prompt", "_engineering", "_is", "_powerful"]. Notice how spaces are sometimes included in the token itself. Different models use different tokenisers, which can affect how they interpret the exact same prompt.

Once the text is tokenised, each token is converted into a list of numbers called a word embedding. This isn't just a random ID number; it's a high-dimensional vector that represents the token's meaning and its relationships to other tokens. Words with similar meanings will have similar numerical representations.

Paying Attention

Now that the prompt is a sequence of numerical vectors, the model needs to figure out which parts are most important. It does this using a mechanism that mimics human focus: the attention mechanism . When you read "The cat sat on the mat, and it was fluffy," you instantly know "it" refers to the cat, not the mat. The attention mechanism allows an LLM to make similar connections by calculating relevance scores between all the tokens in the input.

For each token it processes, the model looks at all the other tokens and assigns a weight, or "attention score," to them. A higher score means a stronger relationship. This allows the model to understand that in "summarise the following article about space exploration," the token "summarise" is critically important and should influence how it processes "article" and "space exploration." This dynamic weighting is what allows LLMs to handle complex grammar, context, and nuance.

Lesson image

Working Memory

An LLM can't pay attention to an infinite amount of text. Every model has a limit on how much information it can process at once, known as its context window. This includes your prompt and the model's own response, all measured in tokens. If a conversation exceeds this limit, the model starts to forget what was said at the beginning.

Think of the context window as the LLM's short-term memory. It's the only information the model has to work with when generating the next token.

This has direct implications for prompt engineering. If you're working with a long document, you can't just paste the whole thing in and ask a question. The model might forget the start of the document before it even sees your question. You need to structure your prompts to fit the most relevant information within this window.

This is also why providing clear instructions and good examples is so effective. By placing them inside the context window, you are directly shaping the model's immediate working memory. The LLM uses these instructions and examples as a primary guide for its behaviour, helping it focus on the right patterns to generate the output you want.

Now that you understand how a model processes your input, let's test your knowledge.

Quiz Questions 1/5

What is the primary function of tokenisation in an LLM?

Quiz Questions 2/5

In the sentence, "The rocket launched, and it soared into the sky," the attention mechanism helps the model understand that "it" most likely refers to...

Understanding these core mechanics—tokenisation, embeddings, attention, and the context window—is the key to moving beyond simply talking to an LLM and starting to engineer prompts that deliver precise and reliable results.