Search for AI Courses, Tech News and, Blogs

How Does Generative AI Actually Work?

by Greg Rubino | 2 weeks ago | 11 min read

The first time a chatbot drafted an email that sounded almost exactly like me, I shut the laptop and sat there for a second. I had been using these tools every day for months by then. Writing first drafts. Cleaning up code. Turning three paragraphs of rambling into one tight sentence. And I still could not answer the obvious question when a friend asked me at dinner: what is actually happening inside the thing?

Not the marketing version. The real one. So I spent a few weeks reading the papers, poking at the settings most people never touch, and watching the same model hand me three different answers to one identical prompt. What follows is the explanation I wish someone had given me on day one, before I started trusting these tools with real work.

THE SHORT ANSWER

Generative AI does not look anything up and it does not think the way you do. It has studied an enormous amount of human-made text, images, and sound, learned the statistical patterns inside that material, and now predicts the next most likely piece, one small step at a time, until a full response exists. Everything below is a slower walk through that one idea.

What "generative" really means

Most AI you used before 2022 was built to sort things. It looked at a photo and said "cat." It read an email and said "spam" or "not spam." That kind of model draws lines between categories. It recognizes.

Generative AI does the opposite. Instead of labeling what already exists, it produces something new that did not exist a second ago. Ask for a cat and it paints one, pixel by pixel. The shift sounds small on paper. In practice it changed what a computer can be asked to do, because creating a plausible answer is a far harder problem than filing an answer into a bucket.

Older AI (discriminative)

Sorts and recognizes

Given a thing, it picks a label. Fraud or safe. Dog or wolf. The answer already exists; the model just chooses it.

Generative AI

Builds something new

Given a prompt, it generates fresh text, an image, or audio that fits the request. The answer is assembled on the spot.

The engine underneath: prediction

Here is the part that surprised me most. A large language model, the kind behind a chat assistant, is at heart a very advanced autocomplete. Give it the start of a sentence and its entire job is to guess what comes next. Then it adds that guess to the sentence and guesses again. And again. A long, fluent answer is just thousands of these next-piece predictions stacked one after another.

That is why the same question can give you different wording twice in a row. At each step the model is not reading off a single correct answer. It holds a ranked list of likely next pieces and picks from it, with a touch of controlled randomness. Change that randomness and you change the personality of the output, which I will come back to.

How words become numbers

A model cannot do math on the letters t, h, e. Everything has to become numbers first, and this happens in two moves.

First, your text is chopped into tokens. A token is usually a short chunk of a word rather than a whole word. In English, one token lands around three-quarters of a word on average, so "generating" might split into "gener" and "ating." This is why models sometimes count letters strangely: they never see clean words, only these fragments.

Second, each token is turned into an embedding, a long list of numbers that acts like coordinates in a vast space of meaning. Tokens with similar meaning sit close together in that space. This is the trick that lets a model sense that "king" relates to "queen" the way "man" relates to "woman," without anyone ever writing that rule down.

StageWhat you give itWhat the model sees
Your textI love coffeePlain English
Tokens[I] [love] [cof] [fee]Fragments, not words
Embeddings[0.21, -0.88, 0.04 ...]Coordinates in meaning-space

A simplified view. Real tokenizers and embeddings are larger, but the flow is exactly this.

The transformer and the attention trick

The architecture that made all of this work is the transformer, introduced by a group of Google researchers in a 2017 paper with the memorable title "Attention Is All You Need." Nearly every well-known model today is a descendant of that design.

Its key idea is self-attention. When the model processes a word, it looks at every other word in your prompt and decides how much each one should influence the current step. In the sentence "the trophy did not fit in the case because it was too big," attention is what helps the model connect "it" to "trophy" rather than "case." Each word gets to weigh the relevance of all the others at once, which is why these models handle context so much better than anything that came before.

A useful way to picture it: attention is the model constantly asking, "given everything in front of me, which parts matter most for the very next word?" Scale that question across billions of adjustable settings and you get fluent language.

Where the knowledge comes from: training

A model is not born knowing anything. Its abilities come from training, and it happens in distinct stages. The billions of internal settings, called parameters, start as near-random numbers and get nudged millions of times until the predictions stop being nonsense.

STAGE 1

Pretraining

The model reads a huge slice of the internet, books, and code, and learns language by endlessly predicting the next token. This is the expensive part, run across thousands of chips for weeks.

STAGE 2

Fine-tuning

People feed it curated examples of good questions and good answers, teaching the raw model to actually follow instructions instead of just continuing text.

STAGE 3

Human feedback

Humans rank competing answers, and the model learns to prefer the ones people rate highly. This is what makes a model feel helpful and polite rather than blunt or odd.

One thing worth sitting with: once training ends, the model is frozen. Its knowledge stops at a cutoff date. It does not quietly learn from your chats, and it has no live view of the world unless it is paired with a search tool. When a plain model tells you today's news, it is guessing from old patterns, not reporting.

What happens the moment you hit send

Put the pieces together and the loop that runs behind a single reply is simple to follow:

  1. Your prompt is split into tokens and turned into embeddings.
  2. Those run through the transformer, where attention weighs how every token relates to the rest.
  3. The model outputs a ranked list of likely next tokens.
  4. It picks one, adds it to the response, and feeds the whole thing back in to predict the token after that.
  5. This repeats until the model produces a natural stopping point.

The setting that controls step four is worth knowing, because it is the one that changed my results the most once I found it. It is usually called temperature.

TemperatureBehaviourGood for
LowPicks the safest next token, stays predictableCode, facts, structured answers
HighTakes more chances, more variety and surpriseBrainstorming, fiction, fresh phrasing

Beyond text: images and sound

Text models predict the next token. Image models work on a stranger and rather beautiful idea called diffusion. During training, the model is shown millions of real images with noise gradually added until each one is pure static. It learns to run that process in reverse, removing noise step by step. To create a new picture, it starts from a field of random static and cleans it up over many passes, steered by your text prompt, until a coherent image emerges. Tools that turn a short line of text into finished artwork, like the ones I walk through in this look at how Freepik AI turns simple prompts into visuals, sit on exactly this denoising machinery.

Audio follows a similar spirit. Modern text-to-speech models generate sound in small slices, predicting the shape of the waveform that matches the words and the chosen voice. The leap in quality over the last few years is why synthetic narration no longer sounds robotic. If you want a concrete example of generated speech in action, this breakdown of how OpenAI.fm turns plain text into lifelike speech shows the same prediction idea applied to sound rather than sentences.

TypeCore methodIt predicts
TextTransformer, next-tokenThe next chunk of a word
ImagesDiffusion, denoisingHow to remove the next layer of noise
AudioNeural waveform generationThe next slice of sound

Why it sounds sure of itself and is sometimes wrong

This is the part I most want people to understand before they lean on these tools. A model has no internal fact-checker. It is optimized to produce text that reads as correct, not text that is verified as correct. Most of the time those overlap, which is exactly what makes the gap dangerous. When the training data thins out on a topic, the model keeps predicting fluent, confident sentences anyway, and some of them are invented. The industry calls these hallucinations.

Why it happens

The model fills gaps with the most statistically plausible words, not with checked facts. A confident tone is baked in, whether the content is solid or not.

What helps

Verify anything factual, especially names, numbers, dates, and quotes. Treat the output as a fast first draft from a very well-read assistant who occasionally bluffs.

Where it shines and where it stumbles

Strong at

  • Drafting, summarizing, and rewording
  • Explaining dense topics in plain language
  • Writing and debugging routine code
  • Turning a blank page into a usable starting point

Weak at

  • Reliable facts without a verification step
  • Fresh events after its training cutoff
  • Exact counting and some multi-step math
  • Knowing the limits of its own knowledge

My verdict after living with it

After months of daily use and a few weeks of reading how the pieces fit, the mystery mostly dissolved, and I ended up trusting the tools more, not less, because I finally knew what they were. Generative AI is not a mind and it is not a search engine. It is a staggeringly good pattern machine that has absorbed a huge amount of human output and replays it in new combinations on demand. Once that clicked for me, my prompts got sharper and my disappointment disappeared, because I stopped asking it to be something it is not.

The practical takeaway I keep coming back to is this. Use it for the first 70 percent of almost any writing, thinking, or building task, where speed matters more than perfection. Then bring your own judgment to the last 30 percent, where accuracy and taste live. That split is where the tool earns its place on my desk, and understanding the machinery is what taught me where to draw the line.

If you remember one sentence from all of this, make it this one: it predicts, it does not know. Everything clever and everything frustrating about generative AI flows straight from that.