Skip to main content

El Blog de IA

December 2, 2026

Artificial intelligence, explained without the jargon.

December 2, 2026

What Is Generative AI and How Does It Work Under the Hood?

Tokens, transformers, inference, context window. Understanding these four ideas completely changes how you use these tools and how you read an API bill.
¿Qué es la IA generativa y cómo funciona por dentro?

Generative AI is the part of artificial intelligence that produces new content —text, images, audio, video or code— instead of just classifying, predicting or scoring. It is the branch that has reached the general public, and the one that gets misunderstood the most.

Let’s look inside, without the math.

1. It all starts with chopping

A language model doesn’t see words: it sees tokens. A token is a piece of text, usually between two and five characters. The word intelligence can become three or four tokens; house, just one.

Rule of thumb

In Spanish, 1,000 words ≈ 1,300-1,500 tokens. It’s the conversion you need to estimate how much space a document takes up and how much it will cost to process.

Each token is turned into a list of numbers —a vector— that encodes its meaning in relation to all the others. Words with similar uses end up with similar vectors. That geometry is what lets the model relate concepts that never appeared together in the same sentence.

2. The transformer and attention

In 2017, a Google team published an architecture called the transformer, which solved the problem that was holding back earlier models: they processed text word by word, in order, and lost the thread as soon as a sentence got long.

The transformer processes the whole sequence at once through an attention mechanism: for each token, it calculates how much it should focus on each of the others. When reading “the architect who designed the bridge presented it yesterday”, the model learns to connect “it” with “bridge” and not with “architect”.

That mechanism, repeated across dozens of layers, underpins all of today’s generative text AI.

3. Training: two very different phases

Pretraining

The model reads enormous amounts of text with a single task: predicting the next token. A word is hidden, it tries to guess it, the guess is compared with the real one, and the parameters are slightly adjusted. Repeated trillions of times.

At first it produces noise. Then, spelling. Then, grammar. Later, facts, styles and reasoning patterns. Nobody teaches it grammar: it’s what you need to know to get the next word right.

This phase lasts months, costs tens or hundreds of millions of euros and happens once.

Fine-tuning

A pretrained model is not an assistant: it’s a text continuer. To make it answer instead of continuing, it is fine-tuned with examples of well-resolved conversations and with human feedback: it is shown several answers, people indicate which one is better, and a system is trained to learn to prefer those.

This phase is where the tone, the willingness to refuse requests and much of what we perceive as the assistant’s “personality” come from.

This is where flattery comes from

If a model learns to prefer the answers that evaluators like, it also learns to agree with you. That’s why assistants tend to validate what you say. When you want a critical review, ask for it explicitly: “point out the three weakest points of this text” works much better than “what do you think?”.

4. Inference: what happens when you hit Enter

Training happens once. Inference happens every time you use it.

The model receives your text, chops it up and calculates a probability for every possible next token. Then it picks one, adds it and repeats the process with the extended sequence. Word by word, until it’s done.

That “picks one” is not always the most probable one. A parameter called temperature controls how far it is allowed to stray from the most predictable choice: low for precise, repeatable answers, high for creative variety.

Two practical consequences follow from this:

  • The model doesn’t query a database. It doesn’t look up the answer: it generates it. That’s why it can produce a perfect quote from a book that doesn’t exist.
  • Every response is paid for by tokens, both input and output. A long context costs money on every call, not just the first.

5. The context window

It is the limit of tokens the model can hold in mind at once: your instruction, the conversation history, the attached documents and the response it is generating. All together.

When it fills up, the oldest material ceases to exist. It’s not that the model forgets it: it’s that it is no longer there.

What it means in practice

A window of 128,000 tokens equals about 90,000 words: a short novel. It sounds like a lot until you drop in three reports and a two-hour conversation. And be careful: a big context is not memory. When you open a new chat, the model remembers nothing unless the product has an explicit memory feature.

6. Beyond text

Image. Diffusion models start from random noise and clean it up step by step, guided by your description, until a coherent image appears. It’s what is behind the tools we analyze in how to create images with AI.

Video. The same idea with an added difficulty: temporal coherence. Keeping the character the same by frame forty is the hard problem, and the reason clip lengths remain short. We go over it in the best AI tools for creating videos.

Audio. Voice and music work with related architectures, on representations of sound instead of pixels.

Multimodal. A single model that accepts text, images and sound at the same time. It’s where the whole industry is heading.

RAG: the technique that solves most real-world cases

If you’re only going to keep one technical concept from this article, make it this one.

RAG (retrieval-augmented generation) means not trusting what the model remembers, but searching your documents first and giving it the relevant fragments so it answers based on them.

The process has four steps:

  1. Your documents are chopped into fragments.
  2. Each fragment is turned into a vector that encodes its meaning.
  3. When someone asks a question, the fragments closest to that question are retrieved.
  4. Those fragments are passed to the model along with the question.

Why it matters so much

It changes the model’s task: from remembering to reading. And it is far better at reading. It’s the reason why uploading a PDF and asking about it gives much more reliable results than asking from memory, and it’s the basis of almost all the internal assistants that work in companies.

It’s worth knowing its limits too: if the chopping splits an idea in half, if the question uses words very different from those in the document, or if the document is out of date, the result will be bad with complete certainty and complete aplomb.

How to read an API bill

When you move from the monthly subscription to usage through programming, the cost is measured in tokens and there are three line items:

Line item What it is How to control it
Input tokens Everything you send: instruction, history, documents Trim context, summarize the history
Output tokens What it generates. Usually costs 3 to 5 times more Ask for short, structured answers
Context cache Reusing a fixed part that has already been processed Put the stable material at the start of the prompt

Two practical consequences. The first: a long context is paid for on every call, not just the first; a two-hour conversation costs more and more as it goes on. The second: asking “answer in under 150 words” is not just a matter of style, it’s a cost decision.

How to measure whether a model is good

Public rankings help very little when it comes to deciding. What works is setting up your own evaluation, and you don’t need to be a lab to do it:

  1. Gather twenty real tasks from your work, along with the answer you would consider good.
  2. Give them to the candidate models, with the same prompt.
  3. Score each result with binary criteria: is it correct? Is it complete? Does it need rewriting?
  4. Count. The one that wins on your tasks is the good one for you, regardless of what any table says.

It’s exactly the method we apply in our comparisons and that we explain in how we test tools.

What this explains about your day-to-day

Once you understand the above, several things stop being mysterious:

  • Why it improves so much if you give it the document: it doesn’t have to remember, it has to read. The difference in reliability is huge.
  • Why it gets lost in very long conversations: the window fills up and the first part disappears.
  • Why it makes up sources: it generates plausible text; a well-formed bibliographic reference is very plausible.
  • Why the prompt changes the result: you are shifting the probabilities. It’s exactly what we explain in what a prompt is and how to write better prompts.
  • Why some models cost ten times more: parameters, compute per token and margin. The cost implications are in open models versus closed models.

If you want the complete map of the field, go back to what artificial intelligence is.

Everything about artificial intelligence

Frequently asked questions

What is a token?

The smallest unit into which a model chops text. It’s roughly equivalent to a long syllable or a short word. In Spanish, a thousand words are approximately 1,300 to 1,500 tokens.

What is the context window?

The maximum number of tokens the model can take into account at once: your request, the documents you’ve given it and its own response. Whatever falls outside that ceases to exist for the model.

Why does it make up facts?

Because its training objective is to produce plausible text, not true text. When it doesn’t have the information, it generates the most probable continuation, and that continuation can be false and sound perfect.

What is the difference between training and inference?

Training is the very long and very expensive process of adjusting the model’s parameters. Inference is every later use: taking an already trained model and generating a response.

Sources

  1. Vaswani et al.: Attention Is All You Need
  2. Nature: Deep learning (LeCun, Bengio, Hinton)

You may also like

Tecla Copilot en el teclado de un portátil con Windows 11

Free Copilot: what Microsoft Copilot is and how to use it in Spanish

Microsoft Copilot is still free, but since August 2026 it requires an account. How to use it in Spanish on the web, Windows, mobile
Rascacielos de Hangzhou, la ciudad china donde tiene su sede DeepSeek, vistos desde el Lago del Oeste

DeepSeek: what it is, how to use it for free in Spanish, and whether it’s safe

DeepSeek is the Chinese chatbot you can use for free and in Spanish. We explain how to get started, which model it runs now,
Paleta de pintor y pinceles, Leonardo AI para crear imágenes con IA

Leonardo AI: What It Is, How to Use It for Free and How Much It Costs (2026)

What Leonardo AI is, what it is for, what the free plan includes, the price of each plan and how to create AI images

Most read

El Blog de IA
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.