TExcelTAD
Home › Generative AI & LLMs › AI Intro

AI Intro

Artificial intelligence (AI) is the field of building computer systems that perform tasks we usually associate with human thinking: understanding language, recognising images, making plans, answering questions. Generative AI is the part of AI that creates new content — text, code, images, audio — instead of only labelling or sorting existing data. Large language models (LLMs) are the generative models behind chat assistants and coding tools.

This course explains how LLMs work and how to build useful, safe applications with them. You do not need a GPU, an API key or a paid account: every runnable example on this site is a small, transparent toy written in plain Python (sometimes with NumPy) that shows one idea at a time. Real models apply the same ideas at a vastly larger scale.

What you will learn

Part Topics
Fundamentals tokens, embeddings, neural networks, attention, transformers, sampling, context windows, training
Prompt engineering clear instructions, system prompts, few-shot examples, reasoning, JSON output, templates, pitfalls
Building with LLMs APIs, conversations, streaming, tool use, RAG, vector search, agents, evaluation, cost
Responsible AI hallucinations, bias, prompt injection and privacy, copyright and disclosure

To build, train and fine-tune the models yourself, continue with the Machine Learning track: Deep Learning writes attention and a transformer from scratch, and NLP, Transformers & LLM Fine-Tuning covers tokenizers, pretraining, fine-tuning and RAG in depth.

The core idea in one program

At heart, a language model answers one question over and over: "given the text so far, what comes next?" Here is the smallest possible version of that idea. It counts which word follows which in a tiny text and then predicts the most common follower:

python · try it yourself
text = "the cat sat on the mat the cat ate the fish"
words = text.split()

follows = {}
for current, nxt in zip(words, words[1:]):
    follows.setdefault(current, {})
    follows[current][nxt] = follows[current].get(nxt, 0) + 1

print("after 'the':", follows["the"])
best = max(follows["the"], key=follows["the"].get)
print("most likely next word:", best)
after 'the': {'cat': 2, 'mat': 1, 'fish': 1}
most likely next word: cat

The program has "learned" that cat usually follows the — purely from counting. An LLM does something conceptually similar, but instead of a table of counts it uses a neural network with billions of parameters, it looks at thousands of previous tokens rather than one word, and it was trained on a huge amount of text. That difference in scale is what lets it write essays, explain code and follow instructions.

Generating text, one step at a time

Prediction becomes generation when you feed each prediction back in as input. Starting from one word, the toy model below keeps choosing the most frequent next word:

python · try it yourself
text = "the cat sat on the mat the cat ate the fish"
words = text.split()
follows = {}
for current, nxt in zip(words, words[1:]):
    follows.setdefault(current, {})
    follows[current][nxt] = follows[current].get(nxt, 0) + 1

word = "on"
sentence = [word]
for _ in range(5):
    options = follows.get(word)
    if not options:
        break
    word = max(options, key=options.get)
    sentence.append(word)
print(" ".join(sentence))
on the cat sat on the

Notice that the output quickly repeats itself. Always picking the single most likely word is called greedy decoding, and it tends to loop. Real systems add controlled randomness (sampling), which you will explore in the Sampling lesson.

What LLMs are good at — and not

Usually strong Needs care
Drafting, rewriting and summarising text Exact facts, figures and citations (they can hallucinate)
Explaining and writing code Precise arithmetic on long numbers without a tool
Translating and changing tone Knowing about events after their training data
Extracting fields from messy text Following secret rules when users try to override them
Brainstorming options Decisions that need accountability (medical, legal, financial)

Note: An LLM produces plausible text. Plausible is often correct, but not always. A large part of this course is about techniques that make LLM output more reliable: clear prompts, retrieval of trusted documents, tool use, validation and evaluation.

How this course runs code

Runnable examples use the python run playground (Python in your browser via Pyodide, with NumPy, pandas, Matplotlib and scikit-learn available). Examples that call a real model API are shown in ordinary code blocks without a Run button, followed by a description of what a typical response looks like — the site has no server and no API key, so it never contacts a model.

python · try it yourself
course = {
    "runnable": "toy models in Python and NumPy",
    "not runnable": "real API calls (shown as reference code)",
    "goal": "understand the ideas, then build with real tools",
}
for key, value in course.items():
    print(f"{key:>12}: {value}")
    runnable: toy models in Python and NumPy
not runnable: real API calls (shown as reference code)
        goal: understand the ideas, then build with real tools

Test yourself

What makes a model *generative*?

  1. It only sorts data into categories
  2. It creates new content such as text or images
  3. It runs without electricity
  4. It is always larger than 1 billion parameters

Which question does a language model answer repeatedly while generating text?

  1. Is this text spam?
  2. What comes next, given the text so far?
  3. Which database row matches?
  4. How many words are in the text?

Always choosing the single most likely next word is called…

  1. greedy decoding
  2. fine-tuning
  3. tokenization
  4. retrieval