Coding a Text-Generating LLM
An LLM can generate text, and the source material notes that it can be coded to do so, making generation the foundation of an assistant.
A Single Conversation, Many Abilities
Most people have used a chat-based AI assistant that can answer a question, rewrite a paragraph, and render a passage into another language, all within one conversation. It is natural to assume that such a system must be enormously complicated, and that the only way to understand it is to study a finished product from the outside. This article takes a different route. Instead of treating the assistant as a sealed box, it asks what the smallest useful piece is and how the larger behavior is put together from it.
The course section this article belongs to proposes that you can understand a complex assistant by constructing one yourself, one layer at a time. The layers are a text generator at the bottom and a set of query techniques on top of it. Keep that two-layer picture in mind, because the rest of the article fills it in.
What Text Generation Means
Text generation means producing new written output in response to input, rather than only classifying or labeling text that already exists.
The foundation of everything in this part of the course is an LLM that can generate text. The source material emphasizes two points. First, an LLM can generate texts. Second, an LLM can be coded to generate texts. The second point matters because it turns an abstract capability into something you can build and run yourself. Generation is therefore not just a property you observe in a finished product; it is the first thing you construct.
This article does not explain the internal mechanics of how the generator produces each piece of its output. Its goal is to show where generation sits in the overall design, and why every later task is built on top of it.
Two Layers: Generator and Query Techniques
A query technique is a way of getting an LLM to carry out a particular job. The generator provides the general ability to produce text, and a query technique points that generator at a specific task. Query techniques direct the generator toward specific jobs, and this part of the course covers three of them.
The diagram can be read in two directions, and each direction is useful. Reading it from the bottom up gives the order of study: first you learn how a generator produces text, then how to point that generator at specific tasks, and finally how those tasks combine into an assistant. Reading it from the top down gives a debugging habit. When an assistant behaves unexpectedly, ask whether the problem lies in the generator underneath or in the technique that is directing it.
Three Query Techniques at a Glance
The source names three jobs that this part of the course focuses on: answering questions, summarizing text, and translating text. Each one asks the generator for a different kind of output from the same kind of input. The comparison below gives a short description of each, along with the kind of request it fits.
Reading One Request Against the Three Tasks
A user pastes a paragraph and writes: Give me the three main points of this in two sentences. Which query technique does this request call for?
- 1Identify the input
The input is a paragraph of existing text, so the request is about text that already exists.
- 2Identify the requested output
The user wants a shorter version that keeps the main points, which is the output of summarizing text.
- 3Check the other two tasks
The request is not a question to answer and does not ask for another language, so answering questions and translating text do not fit.
The request calls for summarizing text.
Matching a Request to a Technique
Matching a request to its technique is a practical habit that follows from the layered view. The habit has two steps: look at what goes in, then look at what should come out. Before you read the answer, try the prediction below.
What do you think happens?
A user writes: Please render this paragraph into Spanish. Which query technique does this call for?
Reveal answer
Translating text
The paragraph is passed in unchanged in meaning and the requested output is the same passage in another language. Summarizing would shorten it, and answering questions would respond to a question, which this request does not contain.
Classify this request: What year did the first version of the course module appear in the material? Decide whether it calls for answering questions, summarizing text, or translating text, and explain which part of the request tells you.
Hints
- Look for whether the request contains a question.
- Ask what kind of output the user expects back.
Debugging by Layer
The layered view also tells you where to look when something goes wrong. Locating a problem in either the generator or the technique is itself a practical habit. A useful question to ask is whether the assistant is failing at producing text at all, or whether it is producing text that is aimed at the wrong job.
Common Mistakes When Reading the Layers
Common mistake Treating the assistant as a single indivisible system
Why it failsThe course approach is to build it one layer at a time, starting from the generator, so the parts can be understood separately.
Do this insteadDescribe the assistant as a generator with query techniques on top, and study each layer in turn.
Common mistake Assuming a question always needs answering questions
What it looks likeA user pastes a long article and asks for a shorter version. The request has a question-like phrase but the output requested is a condensed text.
Why it failsThe technique is chosen by the kind of output the user wants, not by the surface wording alone.
Do this insteadLook at what goes in and what should come out before choosing a technique.
Common mistake Confusing the generator with the query technique when a result looks wrong
Key Takeaways
- 1An LLM that can generate text is the foundation of an assistant, and it can be coded to do so.
- 2Query techniques direct the generator toward specific jobs: answering questions, summarizing text, and translating text.
- 3A complex assistant such as ChatGPT can be understood by building it one layer at a time, from generator to query techniques.
- 4Matching a request to its technique, and locating a problem in the generator or the technique, are practical habits that follow from this layered view.
At a glance
- An LLM that can generate text is the foundation of an assistant, and it can be coded to do so.
- Query techniques direct the generator toward specific jobs: answering questions, summarizing text, and translating text.
- A complex assistant such as ChatGPT can be understood by building it one layer at a time, from generator to query techniques.
- Matching a request to its technique, and locating a problem in the generator or the technique, are practical habits that follow from this layered view.