Concepts / Coding a Text-Generating LLM

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.

  • Programming

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

Definition

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.

Input textwhat the user providesText generatorthe foundation layerNew written outputtext that did not existbeforepassed inproduces
What does the generator do with the input it receives? It produces new written output rather than just labeling the text it was given.

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.

Text generatorbottom layer: learn firstQuery techniquesdirect the generator to ajobLLM assistanttasks combined into onesystemdirected bycombine into
Which piece depends on which? The query techniques rest on the generator, and the assistant is what those tasks combine into.

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.

Answering questionsa question in, a responseoutSummarizing texta long passage in, ashorter version outTranslating texta passage in, the samemeaning in another languageout
How do the three tasks differ? Each one takes a text or question as input and produces a different kind of output.
Worked example

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?

  1. 1
    Identify the input

    The input is a paragraph of existing text, so the request is about text that already exists.

  2. 2
    Identify the requested output

    The user wants a shorter version that keeps the main points, which is the output of summarizing text.

  3. 3
    Check 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.

Result

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?

  • Answering questions

  • Summarizing text

  • Translating text

Reveal answer
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.

EASY

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 fails

    The course approach is to build it one layer at a time, starting from the generator, so the parts can be understood separately.

    Do this instead

    Describe 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 like

    A 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 fails

    The technique is chosen by the kind of output the user wants, not by the surface wording alone.

    Do this instead

    Look 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

  1. 1
    An LLM that can generate text is the foundation of an assistant, and it can be coded to do so.
  2. 2
    Query techniques direct the generator toward specific jobs: answering questions, summarizing text, and translating text.
  3. 3
    A complex assistant such as ChatGPT can be understood by building it one layer at a time, from generator to query techniques.
  4. 4
    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.

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.

More concepts starting with C