Inside ChatGPT: How Language Models Work, Learn and Respond

Ask ChatGPT a question and an answer can appear almost instantly. But what shapes that answer happens at several different stages — from how the model learned during training, to how it interprets the words in a prompt, to the choices it makes as it generates a response. Understanding those stages can make large language models less mysterious. It can also help us use them more effectively: by giving clearer instructions, supplying relevant evidence and knowing what to look for when evaluating the results.

Those connections were the focus of the Ottawa Medical AI Research Institute’s inaugural seminar, Inside ChatGPT: How Large Language Models Work, Learn and Respond, held in person on October 14, 2026. Dr. Fida Dankar introduced the architecture and training behind models such as GPT, then connected those foundations to reasoning models and effective prompting. 

Computer chip surrounded by glowing blue and purple circuits

From words to numbers and back again

Large language models, or LLMs, are part of a broader shift in artificial intelligence. Rule-based AI follows instructions that people program explicitly. Machine-learning systems learn patterns from data and apply them to new cases. Generative AI also learns patterns from data, but uses them to create new content, including text, images, audio or video.

These approaches coexist, and each has different capabilities and limits. LLMs are generative models that learn patterns in language. Models such as GPT use a type of architecture called a transformer.

To process text, a transformer first breaks it into units called tokens. Tokens are represented numerically through embeddings, a set of numbers that captures relationships the model learned during training. Terms that are used in similar ways can develop related representations.

But an initial embedding does not tell the whole story, because the same word can mean very different things depending on its context.

Consider the word bank.

“I deposited my cheque at the bank.”

“We reached the opposite bank of the river.”

The word is the same, but its meaning changes completely.

This is where attention becomes important. Attention allows relationships among the tokens in the current text to influence their representations. In a sentence about cheques and deposits, the context points toward the financial meaning of bank. In a sentence about a river or boat, it points elsewhere.

Transformers use multiple attention heads in parallel, allowing the model to capture different kinds of relationships within the text. They also incorporate information about position, because the order of words matters. Further artificial neural-network processing then transforms these context-enriched representations.

The result is not simply a numerical representation of a word, but one that reflects how that word is being used in the particular context.

How GPT generates a response

GPT uses a decoder-only transformer architecture. Its basic task is to predict the next token using the tokens that came before it.

Suppose a sentence begins: “The patient was treated with…”

The model calculates probabilities for possible next tokens. Some possibilities will be more likely than others. Depending on how generation is configured, it may choose the most likely continuation or sample from the available possibilities.

Once the next token is generated, it becomes part of the context used to predict the one after that. Then the process repeats.

This has an important consequence: an early choice can influence everything that follows. The model is not composing a finished paragraph and then revealing it. It is generating the response step by step, with each new token becoming part of the context for the next prediction. That helps explain why the wording of a prompt is important, but also why prompting is only one part of what shapes a response.

Different kinds of training do different jobs

The calculations inside a language model depend on its parameters: numbers that are adjusted through training. Several stages of training can shape how a conversational model behaves.

Pretraining establishes the foundation. The model trains on very large amounts of text, which can include sources such as web material, books, code and dialogue. For a model such as GPT, training improves its ability to predict the next token.

Through that process, the model learns patterns in language and information contained in its training data. The result is a foundation model. But a foundation model has not necessarily been trained to follow a person’s instructions.

Instruction tuning builds on that foundation. The model is trained on curated examples that pair instructions with appropriate responses. This helps it learn to interpret requests and produce answers suited to the task.

Reinforcement learning with human feedback, or RLHF, adds another step. People assess model responses, and that feedback is used to train a separate reward model that scores outputs. The language model can then be further adjusted to produce responses that receive higher scores.

These stages are related, but they are not doing the same thing. Learning patterns in language, following an instruction and producing an answer people prefer are distinct training goals.

What prompting can and cannot change

Prompting acts at a different point in the process. Instructions, background information and examples all become part of the context available when the model responds. They can influence the answer without changing the model’s underlying parameters. That distinction helps explain why some prompting practices are useful.

Clear and complete instructions give the model more information about the task and the desired output. Separating instructions from the source material (for example, with headings, quotation marks or other delimiters) makes the structure of the request clearer. Examples can show the style, format or type of response required. More complicated tasks can be divided into smaller steps rather than leaving the model to infer every requirement at once.

These approaches do not guarantee a correct answer. Even well-written prompts cannot completely prevent inaccurate or fabricated responses. But they can make the task and expectations more explicit.

Newer reasoning models add another consideration: how much computation happens while the model is answering.

Additional processing can involve working through intermediate reasoning steps, exploring different possible paths or generating several possible solutions and comparing the results. This takes place during inference (when the model is generating an answer) rather than during its earlier training.

Where different reasoning levels are available, the amount of processing can be matched to the task. Rewriting a short patient-information paragraph in simpler language may require less reasoning than comparing conflicting studies and assessing possible explanations for their different findings.

More reasoning is not necessarily required for every task. A practical approach is to begin with the default and increase the reasoning level when the task involves several steps or careful comparison.

Understanding what shapes the answer

A response from a large language model is shaped at multiple points. Training determines the parameters the model begins with. Prompting changes the instructions and information available for a particular interaction. Reasoning settings can change how much processing happens while answering. 

Knowing those distinctions does not require understanding every calculation inside a transformer. But it can make conversations about large language models more precise, and help people make better decisions about how to instruct, adapt and evaluate them.

The October 14 seminar opened OMARI’s four-session, in-person pilot for researchers, clinicians, medical students, faculty and others interested in AI in medicine. The series covers methods and applications ranging from traditional machine learning to large language models, and from model development to clinical evaluation and implementation.

Watch the recording of the seminar here. 

For information about upcoming seminars, visit the OMARI events page.