🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Generative AI Foundations: From ELIZA to GPT

đŸŸĸ Free Lesson

Generative AI Foundations: From ELIZA to GPT

Ask a machine to finish a sentence, paint a logo, or draft a pull request and you are using generative AI: software that produces new artifacts instead of sorting existing ones. That single distinction drives everything else in this course, from how models are trained to what breaks in production. Spend ten minutes with the idea and it becomes obvious why the field exploded, but the boundary between generating and judging is sharper than it first appears, and knowing exactly where it sits saves you from choosing the wrong tool for the job.

Where Generation Stops and Prediction Begins

Every machine learning system takes an input and returns an output, so the split is not about having a model at all. It is about what probability distribution the model learns. A discriminative model estimates the probability of a label given an observation, written as P(y given x). A spam filter looks at an email and answers yes or no. A generative model estimates P(x) itself, or the joint P(x, y), which means it can sample brand-new emails that never existed in the training set.

The practical consequences of that difference show up immediately. Discriminative systems are judged by accuracy, precision, and recall on a fixed label set, and they degrade quietly when the world shifts. Generative systems are judged by quality, diversity, and faithfulness, and they fail loudly by inventing facts. You cannot fully unit-test a generative model the way you unit-test a classifier, because the output space is unbounded. That is why this course spends so much time on evaluation, grounding, and guardrails later on.

PropertyDiscriminative modelGenerative model
LearnsP(label given input)P(input) or P(next token)
OutputFixed classes or scoreNew text, image, audio, code
Typical lossCross-entropy on labelsCross-entropy on tokens, denoising loss
Failure modeWrong class, silent driftConfident invention, repetition
EvaluationAccuracy, F1, AUCPerplexity, human preference, faithfulness

Six Decades of Machines That Write

The current wave feels sudden only if you ignore the lineage. Joseph Weizenbaum's ELIZA in 1967 pattern-matched user phrases into canned therapist replies and still fooled people. Recurrent networks brought statistical language modeling into the mainstream, and LSTMs in the late 1990s finally let models remember context across longer spans. Generative Adversarial Networks in 2014 gave images a training recipe: one network fabricates, one network judges, and both improve. The 2017 Transformer replaced recurrence with attention, making training massively parallel. Scale then did the rest — GPT-3 in 2020 demonstrated that a model trained only to predict tokens could follow instructions it was never explicitly taught.

Each step removed a different bottleneck. Recurrence removed the need for hand-built grammars. GANs removed the need for pixel-level supervision. Attention removed the sequential bottleneck. Scaling removed the need for task-specific labels. Understanding which bottleneck a new technique attacks tells you whether it matters for your use case or is mostly a research curiosity.

The Modalities and Their Model Families

Text was first to industrialize because text is abundant and tokenization is simple, but the same recipe now covers images, audio, code, and video. Diffusion models learn to reverse progressive noise, which makes them stable to train and easy to steer with prompts. Autoregressive models treat any sequence — tokens, pixels in raster order, patches of audio — as a chain of conditional predictions. Normalizing flows and variational autoencoders map data to a latent space where interpolation and sampling become tractable.

What differs across modalities is mostly the tokenizer and the loss, not the architecture underneath. A text model splits characters into subword tokens and minimizes cross-entropy. An image diffusion model corrupts tensors and predicts noise. A speech model works on mel-spectrogram frames. When you evaluate a new generative product, ask two questions: what unit does it predict, and what keeps it from drifting off the distribution. Those answers predict most of its failure modes.

From Prompt to Token: The Generation Loop

Under the hood, generation is a loop you can read in twenty lines. Text is tokenized, tokens become dense vectors, the network produces a probability distribution over the vocabulary, a decoding rule picks one token, and the cycle repeats until a stop condition fires. Nothing in that loop searches a database for facts; every token comes from the model's learned distribution.

python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

name = "gpt2"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name)

def continue_text(prompt, steps=25, temperature=0.8, top_k=40):
    ids = tok.encode(prompt, return_tensors="pt")
    with torch.no_grad():
        for _ in range(steps):
            logits = model(ids).logits[:, -1, :] / temperature
            if top_k:
                kth = torch.topk(logits, top_k)[0][:, -1, None]
                logits = logits.masked_fill(logits < kth, float("-inf"))
            probs = torch.softmax(logits, dim=-1)
            nxt = torch.multinomial(probs, num_samples=1)
            ids = torch.cat([ids, nxt], dim=1)
            if nxt.item() == tok.eos_token_id:
                break
    return tok.decode(ids[0], skip_special_tokens=True)

print(continue_text("The quiet laboratory filled with"))

The Four Knobs You Will Touch Daily

Once a model is trained, behavior is controlled almost entirely at decode time, which is why prompt configuration is a real engineering skill rather than a party trick. Temperature rescales logits before softmax: near zero the model becomes deterministic and repetitive, above one it grows surprising and less reliable. Top-k truncates the candidate set to the k most likely tokens, while top-p (nucleus) sampling keeps the smallest set whose cumulative probability exceeds p, so the candidate count adapts to how confident the model is. Max length caps runaway generations.

ControlLow settingHigh settingTypical use
TemperatureDeterministic, repetitiveDiverse, riskierFacts low, brainstorming high
Top-kConservative picksWide candidate poolStable output vs variety
Top-pTight nucleusNearly full vocabularyDomain answers vs creative copy
Max tokensTruncated answersCost and latency creepClassify short, summarize long

Where This Technology Actually Earns Money

The credible applications share a shape: a task where drafting is expensive and reviewing is cheap. Code assistants pass because a developer reviews every line. Support-ticket triage passes because a human routes the final decision. Contract summarization passes because lawyers verify the clauses. Medical diagnosis written straight into a chart fails that test, and so does any pipeline that emits text nobody reads.

Two secondary benefits matter as much as the headline one. First, generative interfaces lower the cost of interaction: a user can ask for what they want in plain language instead of learning a query language. Second, models compress conventions — formatting, tone, boilerplate — so teams spend time on judgment rather than scaffolding. When you scope a project, write down which of those two levers you are pulling; it keeps the roadmap honest when demos look equally magical.

Setting Up Your First Script

Everything in this lesson is reproducible locally with two packages. Install them, load a small open model, and run the loop above before moving on — watching tokens appear one at a time makes the rest of the course far less abstract. Keep the model small on a laptop; a 125M-parameter checkpoint generates quickly on CPU and is more than enough to study decoding behavior.

pip install torch transformers
python -c "from transformers import pipeline; \
print(pipeline('text-generation', model='gpt2')('AI will', max_length=20)[0]['generated_text'])"

The output will be mediocre, and that is the point: capability comes from scale, data quality, and alignment, not from the loop itself. Those three ingredients are exactly what the next lessons unpack.

💡Mental model to keep

Treat a generative model as a very well-read collaborator who never looks anything up. It reproduces patterns with confidence, so your job is to supply facts, constraints, and a review step.

Best Practices

  • Match the tool to the review loop: generate only where a human or test suite can check the result
  • Fix the random seed and decoding settings when you compare prompts, or you will measure noise
  • Log the prompt, model version, and decoding parameters alongside every stored output
  • Start with the smallest model that demonstrates the workflow, then scale only what fails

Key Takeaways

  • Generative models learn the distribution of the data itself, so they can sample artifacts that never existed
  • Discriminative models answer what label fits; generative models answer what comes next
  • Sixty years of progress removed grammars, pixel labels, sequential training, and hand-built task data in turn
  • Temperature, top-k, top-p, and max tokens govern nearly all runtime behavior after training
  • Deploy generation where drafting is costly and review is cheap, and always log the settings that produced an output
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-12

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Generative AI Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement