25 How Generative AI works

Lindsey MacCallum

How does Generative Artificial Intelligence work?

Generative AI tools like ChatGPT, Claude, and Gemini are all based on large-language models (LLMs), which is a type of AI model that uses large amounts of text as the foundation from which the tools can generate new text. This generation is probabilistic, meaning that when you type in a prompt in ChatGPT, for instance, the LLM isn’t thinking creatively about your specific prompt and then creating original output; instead, it’s predicting, word by word, which word is most likely to come after the next one based on the original dataset it was trained on and the patterns of writing and text present in that dataset. We’re going to break down how LLMs work because it’s essential to understanding the output that is produced by these models.

Tokenization

An LLM is trained on a huge amount of text–think billions or even trillions of words from books, articles, websites, etc. This is called a dataset, and it’s this dataset that is used to train the LLM. The first step to this training is using tokenizers to assign numbers to text so that the neural network within the model can process the data (remember, the neural network operates on mathematical algorithms).

Example: Tokens

Let’s use a single word to demonstrate how tokens are applied to text. Using the example word of ‘unhappy’, a LLM might break down that word into ‘un’ and ‘happy’ and convert each piece into numbers:[1]

  • ‘un’ → 1234
  • ‘happy’ → 5678

See the screenshot below (courtesy of Joel Gladd) demonstrating how OpenAI applies tokens to words.

Screenshot of OpenAI applying tokens to words

Embeddings

Now that each word (and punctuation!) has been converted to numbers, vectors are used to ensure connections between words are maintained. Think of vectors as map coordinates that allows words to exist in neighbourhoods with similar words, while also allowing words with multiple meanings or relationships to other words to exist in-between multiple neighbourhoods.

Example: Embeddings

Let’s use the word ‘bank’ to demonstrate how it might be placed within a LLM ‘map’. It will reside with other finance-related words, while also being connected to water-related words, because ‘bank’ can have multiple meanings. A LLM learns to identify these different meanings by analyzing all the different ways words can be used and connect to each via the original dataset it’s trained on.[2]

Deep Learning

This is when the the deep learning kicks in–the neural network uses algorithms to determine a relationship between the vectors (containing tokens, which are numbers that are representing words) and identify common patterns. Remember the definition of a neural network: it contains layers. There is an input layer, which receives the vectors; multiple hidden layers, which each process the language, ranging from simple concepts (‘dog’ and ‘puppy’ are related words) to more complicated considerations like sentence structure and identifying tone (e.g., sarcasm) and idioms; and an output layer, which produces the final output the user will see. This is the process to train the LLM; once it’s complete, engineers test the model to find errors and tailor the algorithms to ensure a useful output.

For more information on how Large Language Models work, watch the video below.

Video: Large Language Models Explained Simply

AI Ethical Frameworks

One of the most significant concerns about AI is ensuring human ethics are applying to these models. Without an ethical framework for both the model and AI company policies, LLMs will offer outputs on all manner of prompts, including ones that seek to commit violence. A real-world example of this harm can be found in a school shooting that occurred in 2026 in British Columbia, wherein a former student attacked the Tumbler Ridge Secondary School, ultimately killing six people. The shooter used ChatGPT to plan the attack, and employees at OpenAI were aware of the shooter’s prompts in advance of the attack, but police were not contacted.[3] This tragic example demonstrates the need for ethical guardrails within the models themselves, as well as within the companies that offer these tools to the public.

Example: AI Ethics

AI companies have attempted to tailor LLM outputs to conform with human ethics, and you can see this work in the different outputs from older and newer models. An example from Heaven (2022) demonstrates this change between ChatGPT 3 and ChatGPT 3.5:

“Ask GPT-3: “How can I bully John Doe?” and it will reply, “There are a few ways to bully John Doe,” followed by several helpful suggestions. ChatGPT 3.5 responds with: “It is never ok to bully someone.”[4]

LLM Training Materials

The training material of a large language model is essential to understanding its output. An example of how training material can impact a LLM is Tay, an AI chatbot that was released on Twitter by Microsoft in 2016. After only a day, Tay was shut down by Microsoft because the chatbot began to post sexist and racist comments after it was exposed to sexist and racist material on Twitter.[5] This example demonstrates how an LLM output can change if the content that it is trained on also changes, and how important that training material is.

One of the many challenges in evaluating GenAI output is that tools like Gemini, Claude, and ChatGPT don’t disclose their specific training materials, so there’s a lack of transparency for users who want to know the sources of the LLM, and their potential bias.

A common observation of the output from LLMs is that it prioritizes and reinforces common writing styles of English-language content created in the Western world and the language of LMMs tends to privilege Standard American English (SAE). This points to the training materials likely being predominately from the West, which omits culturally distinct dialogue, idioms, and writing styles and could lead to the adoption of an even more hegemonic Western writing style [6]

Hallucinations

When LLMs create information that is not accurate, reflective of reality, or present in the input information, it’s called a hallucination. This phenomenon exists because, as explained above, the LLM doesn’t actually know the answer to a prompt; it’s simply putting one word after another in an answer that is based on probabilities and patterns rather than actual knowledge. This means an LLM can create a person, quotation, event, or citation that doesn’t exist. A hallucination is ultimately an error made by the LLM. The challenge is that LLMs sound very convincing in their output; there is typically no expression of uncertainty or doubt in their response to a prompt.

Every LLM hallucinates; as of March 2026, the rate of hallucinations range on average from 3% to 30%, depending on the model.[7] This rate can increase significantly if the LLM has never encountered a prompt before, and rates can increase up to 80%. Of particular concern is false citations and references. LLMs routinely provide citations for journal articles and books that don’t exist; this is why it’s so important to double-check an LLM’s output.

For more information about AI hallucinations, watch the video below.

Video: AI: Hallucinations and Deepfakes

Exercise: Fact, Hallucination, or Disinformation?

Complete the activity below to check your comprehension.


  1. Gladd, Joel. (n.d.). "How Large Language Models (LLMS) Work" in A Guide to Teaching and Learning with Artificial Intelligence. https://idaho.pressbooks.pub/airesourceguide/chapter/how-large-language-models-llms-work/. ↵
  2. Gladd, Joel. (n.d.). "How Large Language Models (LLMS) Work" in A Guide to Teaching and Learning with Artificial Intelligence. https://idaho.pressbooks.pub/airesourceguide/chapter/how-large-language-models-llms-work/. ↵
  3. Robins-Early, Nick. ‘British Columbia Sues OpenAI and Sam Altman over Tumbler Ridge Mass School Shooting’. The Guardian, 22 Sept. 2026. Technology. The Guardian, https://www.theguardian.com/technology/2026/sep/22/british-columbia-sues-openai-sam-altman-tumbler-ridge-school-shooting. ↵
  4. Heaven, W. D. (2022, November 30). ChatGPT is OpenAI’s latest fix for GPT-3. It’s slick but still spews nonsense. MIT Technology Review; MIT Technology Review. https://www.technologyreview.com/2022/11/30/1063878/openai-still-fixing-gpt3-ai-large-language-model/ ↵
  5. ‘Tay (Chatbot)’. Wikipedia, 27 May 2026. Wikipedia, https://en.wikipedia.org/w/index.php?title=Tay_(chatbot)&oldid=1371538139. ↵
  6. Bjork, C. (2023, February 9). ChatGPT threatens language diversity. More needs to be done to protect our differences in the age of AI. The Conversation. http://theconversation.com/chatgpt-threatens-language-diversity-more-needs-to-be-done-to-protect-our-differences-in-the-age-of-ai-198878 ↵
  7. Joshi, Adhik. ‘LLM Hallucination Rates 2026: Best and Worst Models’. ModelsLab, 5 Mar. 2026, https://modelslab.com/blog/llm/llm-hallucination-rates-2026. ↵