Artificial Intelligence · Explainer
Generative AI: how models create text, images and code
Writing a paragraph, painting a landscape and continuing a voice recording seem like different tasks. Underneath, generative AI does the same thing: it learns what data usually looks like and produces new samples similar to it.
- Author:
- Redação Token & Tech
- Responsible editor:
- Daniel Ferreira
- Translation:
- Redação Token & Tech
Published · 7 min read
Originally published in Brazilian Portuguese.
Translated from the Portuguese original with AI assistance.
Also available in: Português
Key points
- Generative models learn the structure of large volumes of data and produce new content with similar characteristics.
- Text, audio and code are usually generated piece by piece; images are usually born from noise that is removed little by little.
- Generated content can be fluent and wrong, biased or unsafe, so it requires checking in proportion to how it will be used.
You describe a scene and get an image that never existed. You ask for an email and it appears ready-made. You paste a piece of broken code and get a fix. All of this is generative AI, the part of artificial intelligence that creates content instead of just classifying or predicting.
Adoption has been fast. According to Stanford University’s AI Index 2026, generative AI reached 53% population adoption in three years, a faster pace than the personal computer or the internet, with wide variation between countries (Stanford HAI, AI Index 2026).
This article explains what these systems do under the hood, why the same question can produce different answers and where the risks lie. If you have not yet read the basics of how a model learns, start with What is artificial intelligence.
What makes an AI “generative”
Most traditional AI systems answer closed questions. A spam filter says “yes” or “no”. A credit model returns a score. The output is a choice among known options.
A generative model returns something new: a text, an image, a sound. Google’s documentation describes generative AI as a class of models that creates content from user input (Google for Developers).
The generative AI profile published by NIST in July 2024 uses a more technical definition, taken from a 2023 US executive order: the class of models that emulate the structure and characteristics of input data to generate derived synthetic content, such as images, videos, audio and text (NIST AI 600-1).
The key words are “emulate the structure”. The model does not keep a folder of ready-made answers to copy. It learns what data usually looks like and generates new examples that follow that pattern.
The central idea: learning what data usually looks like
Think of all the face photos ever taken. They vary a lot, but not at random: eyes sit above the nose, skin has texture, light creates consistent shadows. This set of regularities is what researchers call the data distribution: the description of which combinations are common, rare or impossible.
The paper that introduced generative adversarial networks, in 2014, sums up the goal this way: to train a model that captures “the data distribution” (Goodfellow et al., 2014). Generating, then, means drawing a new sample from that learned distribution. A face that no one has, but that looks plausible.
Each type of content has its own techniques for drawing that sample. The two most important families today are piece-by-piece generation, used for text, audio and code, and gradual noise removal, common for images.
Text: predicting the next piece
Language models work with tokens, pieces of text that can be a word, part of a word or a punctuation mark. The subject is covered in detail in Tokens in AI models.
Generation is autoregressive: the model looks at the text so far, calculates the probability of each possible token coming next, picks one, adds it to the text and repeats. A whole paragraph is the result of hundreds of these choices in sequence.
Two works explain why this started working so well:
- The Transformer architecture, from 2017, uses an attention mechanism to relate each part of the text to all the others, without having to read word by word in order (Vaswani et al., 2017).
- GPT-3, from 2020, showed that an autoregressive model with 175 billion parameters could perform new tasks with just instructions and a few examples written in the request itself, without new training (Brown et al., 2020). This is where much of the practice of prompt engineering comes from.
To understand these models in detail, see What are LLMs.
Why the same question produces different answers
If the model always picked the most likely token, the text would be predictable. In practice, it also makes the text worse. A 2019 study showed that always choosing the highest-probability option produces text that is “bland and strangely repetitive” and proposed sampling only from the options that hold most of the probability, discarding the tail of unlikely choices (Holtzman et al., 2019).
The same study shows that the selection strategy, called decoding, greatly changes the quality of the result, even with the same model. That is why you can ask the same question twice and get different answers. There is a controlled random draw at each step.
Images: from a forger’s game to controlled noise
Generative adversarial networks (GANs) were proposed in 2014. They train two models at the same time: a generator, which creates images, and a discriminator, which tries to tell real images from fake ones. The authors describe the process as a two-player game (Goodfellow et al., 2014). The generator improves because it has to fool an opponent that is also improving.
Another family, diffusion models, takes a different path. The idea is counterintuitive:
- In training, you take real images and add noise little by little until they turn into static.
- The model learns to go the other way: given some noise, predict how to remove part of it.
- In generation, it starts from pure noise and removes it step by step until an image emerges.
A 2020 paper showed that this approach generated high-quality images (Ho, Jain and Abbeel, 2020). Next, another group proposed running diffusion in a compressed space, called latent space, instead of pixel by pixel. According to the authors, this greatly reduces computational cost. The same work uses attention layers so that generation follows a condition, such as a descriptive text (Rombach et al., 2021). It is this combination that lets you ask for “a lighthouse on the beach at sunset” and get the scene.
Audio: sound also becomes tokens
Audio can be treated much like text. In AudioLM, researchers converted recordings into discrete tokens and treated sound generation as a language modeling problem: predicting the next audio token (Borsos et al., 2022).
According to the paper, the model, given a short speech clip, generated plausible continuations that kept the speaker’s identity and rhythm, even without a transcript. It also continued piano passages coherently. The ability to imitate a voice from a few seconds is useful for accessibility and dubbing, but it also makes fake-voice scams easier.
Code: a special kind of text
For a language model, source code is text with strict rules. In 2021, researchers presented Codex, a GPT model fine-tuned on public GitHub code, and the HumanEval test, which checks whether the generated program actually works (Chen et al., 2021).
The numbers show how much the sampling technique matters. On HumanEval, Codex solved 28.8% of problems with one attempt. With 100 attempts per problem, the rate rose to 70.2%. GPT-3, with no specific training on code, solved 0%. These are 2021 figures: later models have advanced a great deal, and the AI Index 2026 records that performance on another programming test, SWE-bench Verified, went from 60% to close to 100% in one year (Stanford HAI, AI Index 2026).
The Codex paper itself discusses safety issues and economic impacts of code generation. Generated code can compile, pass simple tests and still contain flaws. Human review remains part of the job.
What changes when the machine creates
A classifier that gets it wrong returns the wrong category. A generator that gets it wrong returns a convincing but wrong text, image or voice. That is why NIST lists risks that are new or amplified by generative AI (NIST AI 600-1). Some of the most relevant for people who use these tools:
- Confabulation: false content presented with confidence, commonly called hallucination. See AI hallucinations.
- Information integrity: it becomes cheaper to produce content that does not distinguish fact from opinion or fiction, including in disinformation campaigns.
- Data privacy: risk of leakage or misuse of personal information.
- Intellectual property: ease of reproducing protected content without authorization.
- Bias and homogenization: amplification of biases present in the data and answers that are too similar to one another.
- Human-AI configuration: excessive trust in the system or treating it as if it were a person.
- Environmental impact: high consumption of computing resources in training and use.
How to use it with judgment
The recommendations below are the editorial team’s, based on the risks described above:
- Check facts, figures and quotes against a primary source before repeating them. The method is in How to evaluate AI responses.
- Provide reliable context when accuracy matters. Giving the model documents reduces its reliance on its own memory; see how RAG works.
- Do not paste sensitive data about customers, health or finances into tools whose usage policy you do not know.
- Review generated code as you would a new colleague’s: test it, read it and check dependencies.
- Be suspicious of unexpected audio and video asking for money or data, even with a familiar voice.
Key takeaways
- Generating means sampling from a learned pattern. The model learns what data usually looks like and produces new examples similar to it.
- Text, audio and code are usually generated token by token; images usually emerge from noise removed little by little, guided by a text.
- Variation is intentional. The controlled random draw at each step improves quality and explains why answers change.
- Fluency is not truth. Generated content needs checking in proportion to what is at stake.
Sources
- Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile: NIST AI 600-1, National Institute of Standards and Technology (NIST). Published July 26, 2024 · Accessed October 8, 2026
- What is Machine Learning?, Google for Developers. Accessed October 8, 2026
- Generative Adversarial Networks, arXiv (Goodfellow et al.). Published June 10, 2014 · Accessed October 8, 2026
- Attention Is All You Need, arXiv (Vaswani et al.). Published June 12, 2017 · Accessed October 8, 2026
- Language Models are Few-Shot Learners, arXiv (Brown et al.). Published May 28, 2020 · Accessed October 8, 2026
- The Curious Case of Neural Text Degeneration, arXiv (Holtzman et al.). Published April 22, 2019 · Accessed October 8, 2026
- Denoising Diffusion Probabilistic Models, arXiv (Ho, Jain, Abbeel). Published June 19, 2020 · Accessed October 8, 2026
- High-Resolution Image Synthesis with Latent Diffusion Models, arXiv (Rombach et al.). Published December 20, 2021 · Accessed October 8, 2026
- AudioLM: a Language Modeling Approach to Audio Generation, arXiv (Borsos et al.). Published September 7, 2022 · Accessed October 8, 2026
- Evaluating Large Language Models Trained on Code, arXiv (Chen et al.). Published July 7, 2021 · Accessed October 8, 2026
- The 2026 AI Index Report, Stanford Institute for Human-Centered AI (HAI). Accessed October 8, 2026