What is Text Generation?
Text generation is the task of producing text automatically, word by word, with a language model. It is the mechanism behind chat assistants, autocomplete, summarisers and AI text generators. This entry explains how it works; for its uses and rules in writing, see content generation.
How Text Generation Works
- The input, or prompt, is split into tokens (pieces of words).
- The model scores every possible next token by how likely it is to follow.
- One token is chosen, added to the text, and the process repeats until the answer is complete.
Today this is usually done by large language models built on the transformer architecture.
Choosing the Next Word: Decoding
- Greedy decoding: always take the most likely token. Predictable, but often repetitive.
- Sampling: pick randomly in proportion to the probabilities, which gives more varied text.
- Temperature: a setting that controls how adventurous the sampling is. Low values give focused, consistent answers; high values give more creative and more error-prone ones.
This is why the same prompt can produce a different answer each time.
Types of Text Generation
- Open-ended: stories, essays and chat replies.
- Text-to-text: summaries, translations, paraphrases and answers based on a given document.
- Completion: continuing a sentence you have started, as in autocomplete.
Terms such as "text-to-image" and "text-to-speech" describe generating images or audio from a text prompt, a different task in the wider family of generative AI.
Why Generated Text Can Be Wrong
The model chooses words that are likely, not words that are true. Fluent text can therefore contain errors or invented references (see AI hallucination). Clear instructions help (see prompt engineering), but they do not replace checking.
Best Practices
- Use generated text as a starting point, not a final draft.
- Verify every fact and source.
- Follow your institution's rules on AI use, and keep your own voice.