What AI actually is beneath the headlines — rule-based systems, machine learning, training data, models, neural networks, generative AI, evaluation, bias, and responsible use
This chapter introduces artificial intelligence and machine learning as areas of computer science concerned with systems that perceive, predict, reason, generate, and support decisions. Students will learn what AI actually is beneath the headlines, how machine learning differs from traditional programming, where training data comes from and why it matters, what models are and how they are evaluated, and how generative AI systems produce text and images.
The chapter is honest about what AI systems can and cannot do, clear about where human choices shape AI behavior, and careful about bias, limits, and responsible use. By the end of this chapter, students should be able to describe an AI system's inputs, model, outputs, and limitations — and ask thoughtful questions about any AI system they encounter.
When you type a message to a chatbot and it responds with a well-organized paragraph, what is actually happening? When a streaming service recommends a show you end up loving, how did it know? When a photo app recognizes your friend's face, what is it doing? These are not tricks or magic. They are the outputs of systems built from data, mathematics, and deliberate human choices — and by the end of this chapter, you will be able to describe exactly what is going on inside them.
Artificial intelligence is one of the most talked-about and most misunderstood phrases in modern technology. To some people it suggests human-like robots from science fiction. To others it means a chatbot, a spam filter, or a recommendation algorithm. To computer scientists, AI refers to a broad family of techniques for building systems that perform tasks that would typically require some form of perception, reasoning, or decision-making when performed by humans.
That definition is intentionally wide. AI is not a single algorithm or a single technology. It is a field — a collection of methods, problems, and approaches — that has expanded dramatically over the past several decades and especially over the past ten years.
Artificial intelligence systems are built to perform tasks such as recognizing patterns in images, audio, text, or sensor data; classifying inputs into categories; predicting future values or outcomes from past data; recommending items or actions based on past behavior; translating text between languages; generating new text, images, audio, or video; playing complex games; and controlling robots or vehicles through perception and response.
Notice that this list does not include: "understand the world the way humans do," "reason about ethics spontaneously," or "have goals of their own." These distinctions matter. AI systems can perform remarkable tasks within their training domain while remaining brittle, narrow, and unaware of the broader world.
| Period | Approach | Key Development |
|---|---|---|
| 1950s–1980s | Symbolic AI and Rule-Based Systems | Explicit logical rules written by experts; worked on narrow problems, failed on messier ones |
| 1980s–2000s | Machine Learning Emerges | Systems that learn patterns from data; progress limited by data volume and computing power |
| 2000s–2010s | Data and Scale | The internet produced vast data; search engines, recommendation systems, and spam filters became AI systems |
| 2010s–present | Deep Learning and Generative AI | Neural networks with many layers; large language models; image generation from text |
AI systems are not conscious. They do not experience the world, have desires, or feel emotions. An AI that writes a paragraph about loneliness is not lonely — it is performing a statistical operation over a learned pattern space.
Every AI system is built from mathematics, data, software, and hardware. Every output can, in principle, be traced back to specific design choices, training data, and model architecture.
The choices about what data to collect, what problem to solve, what to optimize for, and how to deploy a system are human choices. Those choices reflect values, priorities, and sometimes biases that get embedded in the system.
Before machine learning dominated the field, most AI systems were rule-based systems — programs that used explicit if-then rules written by human experts to make decisions. A rule-based system has two main components: a knowledge base (a collection of facts and rules from experts) and an inference engine (a program that applies the rules to inputs and produces conclusions).
RULE 1: IF lesion is red AND raised AND itchy THEN consider eczema
RULE 2: IF lesion has irregular border AND multiple colors THEN consider melanoma screening
RULE 3: IF rash is ring-shaped AND expanding AND patient was outdoors THEN consider Lyme disease
| Dimension | Rule-Based Strength | Rule-Based Limitation |
|---|---|---|
| Knowledge source | Written directly by human experts | Capturing full expert knowledge in rules is extremely difficult |
| Transparency | Every decision traces to a rule | As rules multiply, they conflict and leave gaps |
| Variation handling | Reliable when the case matches a rule | Brittle on unusual or unanticipated cases |
| Updating | Predictable behavior | A human must manually update every affected rule when the world changes |
Consider trying to write rules for recognizing cats in photographs. Pointy ears? Four legs? Fur? A tail? Every rule immediately admits exceptions. Rule-based systems struggled with perception tasks because human visual knowledge is too rich and contextual to capture in explicit rules — and this motivated machine learning.
TRADITIONAL PROGRAMMING: Input + Rules → Output
MACHINE LEARNING (Training): Input + Output → Learned Model
MACHINE LEARNING (Prediction): Input + Learned Model → Output
In traditional programming, a human writes the rules. In machine learning, a human provides examples of input-output pairs and the learning algorithm discovers the rules automatically.
| Type | What the System Receives | What It Learns | Example Task |
|---|---|---|---|
| Supervised Learning | Inputs paired with correct labels | To map inputs to correct outputs | Spam detection, medical image classification, language translation |
| Unsupervised Learning | Inputs only — no labels | Structure, groupings, or patterns in the data | Customer segmentation, anomaly detection, data compression |
| Reinforcement Learning | Actions and feedback (rewards) | Strategies that maximize cumulative reward | Chess-playing AI, robot locomotion, game agents |
A training dataset is the collection of examples used to teach a machine learning model. Its quality, size, diversity, and accuracy directly determines what the model can and cannot do. Early machine learning systems were trained on thousands of examples. Modern systems are trained on billions. A large language model may be trained on trillions of words of text.
A model is the mathematical structure that captures the patterns the algorithm found. Think of it as a complex function: Model(input) → output. The model is stored as a large collection of numbers called parameters or weights — adjusted during training to minimize prediction errors. A small model may have thousands of parameters; a large language model may have hundreds of billions.
| Data Split | Purpose | Used When |
|---|---|---|
| Training data | The model adjusts its parameters based on these examples | During the training process |
| Validation data | Check generalization; guide decisions about architecture and settings | During training (held out from parameter updates) |
| Testing data | Final honest estimate of real-world performance | Once, after training is complete |
A model that memorizes its training data perfectly but fails on new examples has not learned anything useful — it has only learned to recognize what it has already seen. This failure mode is called overfitting, and it is one of the most important concepts in machine learning. Honest evaluation always uses a test set the model has never seen during training.
A feature is any measurable property of the input that might be useful for the prediction task. Choosing which features to include — feature engineering — is one of the most important skills in machine learning.
| Prediction Task | Example Features |
|---|---|
| Loan approval | Annual income, credit score, debt-to-income ratio, employment years, past defaults |
| Tumor classification | Cell radius (mean), cell texture, smoothness, symmetry, concave points |
| Spam detection | Word count, presence of "WINNER," number of links, sender known, uppercase word ratio |
| Movie review sentiment | Word frequencies, presence of positive/negative words, punctuation patterns, sentence length |
In supervised learning, each training example also includes a label — the correct output that the model should learn to predict. For a spam filter: spam or not spam. For a tumor classifier: benign or malignant. Labels are typically provided by humans or extracted from historical records.
Once trained, the model is applied to new inputs it has never seen — called inference. It does not look up the input in a table; it applies the mathematical function it learned. Machine learning prediction tasks fall into two main types:
| Task Type | Output | Examples |
|---|---|---|
| Classification | One of a fixed set of categories | Spam/not spam; cat/dog/bird; digit recognition |
| Regression | A continuous number | House price; sales forecast; tomorrow's temperature |
A classifier assigns an input to one of a set of predefined categories. Classification is one of the most common and practical machine learning tasks. Spam filters, medical diagnostic aids, image recognition systems, fraud detectors, content moderation tools, and voice recognition systems are all classifiers.
A classifier learns a decision boundary — a line, curve, or surface in feature space that separates one class from another. Any new input that falls to one side of the boundary is classified as one category; inputs on the other side are classified differently.
Iris setosa → 97%
Iris versicolor → 2%
Iris virginica → 1%
Final: Iris setosa (confidence: 97%)A confusion matrix organizes predictions by actual versus predicted class. It reveals more than simple accuracy by showing exactly which errors the classifier makes.
| Predicted: Not Spam | Predicted: Spam | |
|---|---|---|
| Actual: Not Spam | 940 — True Negatives (TN) | 20 — False Positives (FP) |
| Actual: Spam | 15 — False Negatives (FN) | 25 — True Positives (TP) |
Precision = TP / (TP + FP) — Of all predictions of "spam," how many were actually spam?
Recall = TP / (TP + FN) — Of all actual spam messages, how many did the model catch?
A model that predicts "not spam" for every email would achieve high accuracy in a world where most email is legitimate — but would catch zero spam. The confusion matrix reveals this failure where overall accuracy conceals it.
A neural network is built from many simple processing units called neurons (or nodes), loosely inspired by biological neurons. Each artificial neuron does something simple:
Inputs: x1, x2, x3
Weights: w1, w2, w3
Weighted sum: (x1 × w1) + (x2 × w2) + (x3 × w3) + bias
Activation: output = activation_function(weighted sum)
The activation function introduces nonlinearity — the ability to learn complex, curved decision boundaries rather than just straight lines.
INPUT LAYER HIDDEN LAYER 1 HIDDEN LAYER 2 OUTPUT LAYER
[x1] ───────► [N] [N] [N] [O1] → Cat
↓ ↓ ↓ [O2] → Dog
[x2] ───────► [N] [N] [N] ──────► [N] [N] [N] ──────► [O3] → Bird
↓ ↓ ↓
[x3] ───────► [N] [N] [N]
features patterns higher-level prediction
(edges, patterns probabilities
textures) (shapes, parts)
Diagram Questions
A deep neural network has many hidden layers — sometimes dozens or hundreds. Each layer learns to recognize patterns at a higher level of abstraction than the layer before it. For an image recognition network: early layers detect edges and textures; middle layers detect shapes and parts (eyes, wheels, corners); later layers recognize complex objects (faces, cars, cats). The word "deep" in deep learning simply means many layers.
Weights begin as random numbers. Training adjusts them through backpropagation combined with an optimization algorithm called gradient descent:
| Neural Network Strengths | Neural Network Weaknesses |
|---|---|
| Learn from raw inputs without hand-engineered features | Require very large amounts of training data |
| Represent extremely complex, nonlinear patterns | Require substantial computing power to train |
| Scale well: more data and compute tends to improve results | Internal representations are difficult for humans to interpret |
| Same basic architecture applies to many problem types | Can be brittle on unusual inputs; can amplify training data bias |
All the AI systems discussed so far take an input and produce a prediction or classification. Generative AI systems do something different: they take an input — often called a prompt — and produce new content (text, images, audio, video, or code) that was not explicitly in the training data.
| System Type | What It Produces | Example |
|---|---|---|
| Large language models (LLMs) | Coherent text from a text prompt | Explanations, essays, summaries, code, dialogue |
| Image generation models | Images from a text description | "A lighthouse at sunset, oil painting style" |
| Code generation models | Functional code from natural language | "Write a function that sorts a list by length" |
| Audio generation models | Speech, music, or sound effects | Text-to-speech, music composition, sound design |
A large language model is a type of neural network trained on enormous amounts of text — web pages, books, articles, code, conversations — with a simple but powerful training objective: predict what word (or part of a word) comes next. Through this process, the model learns which words follow which, how topics are structured, facts and relationships embedded in the text, and patterns of reasoning and explanation.
| LLMs Can | LLMs Cannot |
|---|---|
| Generate fluent, detailed text on topics well-represented in training data | Look things up in real time — they generate from learned patterns |
| Explain, summarize, translate, and reason about language | Know what happened after their training cutoff without being told |
| Produce code, outlines, arguments, and creative writing | Guarantee factual accuracy — fluency and accuracy are separate |
| Follow instructions and adjust tone or style | Reason about consequences the way humans reason about ethics |
The tendency of language models to generate confident-sounding but factually incorrect information is called hallucination. Models can invent citations, misstate statistics, or confidently describe events that never happened. This is one of the most important practical limitations of large language models — and a reason why LLM output should always be verified for factual claims.
The simplest evaluation metric is accuracy: the percentage of predictions the model gets correct. But accuracy can be deeply misleading, especially with imbalanced datasets.
An overall accuracy score can hide serious failures in specific subgroups. Consider a face recognition system with 94% overall accuracy. That number might mask 98% accuracy on light-skinned male faces alongside 79% accuracy on dark-skinned female faces. The system performs well on average, but very differently across demographic groups. Evaluation should always examine performance broken down by relevant subgroups.
| Evaluation Principle | Why It Matters |
|---|---|
| Use a held-out test set | Honest estimate of real-world performance; prevents overfitting from going undetected |
| Examine performance across subgroups | Overall accuracy can hide systematic failures for specific populations |
| Test edge cases and robustness | Real deployment exposes inputs very different from training data |
| Compare to a baseline | Confirms the model adds value over a trivial alternative |
| Monitor after deployment | Model drift: the world changes; performance can degrade over time |
AI systems should be monitored after deployment. Real-world data changes over time — what worked well in one year may perform poorly two years later as language, fraud patterns, medical knowledge, or user behavior evolves. Ongoing evaluation and retraining are not optional extras; they are requirements for responsible deployment.
| Source | Description | Example |
|---|---|---|
| Biased training data | If training data over- or under-represents certain groups, the model learns those imbalances | Face recognition trained mostly on light-skinned men performs worse on dark-skinned women |
| Measurement bias | Features used to train may be proxies for protected characteristics | Zip codes often correlate with race due to historical housing discrimination |
| Label bias | Labels reflect human judgment, which can be inconsistent or systematically unfair | Medical diagnosis labels may reflect historical underdiagnosis in certain populations |
| Feedback loops | A deployed system changes the data it later trains on, reinforcing initial patterns | Predictive policing: more police → more arrests → more training data → same prediction |
| Limitation | What It Means in Practice |
|---|---|
| Brittleness | AI systems can fail dramatically on inputs that differ from their training distribution, even when the change is invisible to humans (adversarial examples) |
| Narrow expertise | A model trained to diagnose skin conditions does not have general medical knowledge; applying it outside its training domain can be dangerous |
| Hallucination | Language models generate confident-sounding but factually wrong information; fluency and accuracy are separate properties |
| Opaqueness | Deep neural networks are difficult to interpret; a model may produce the right output for the wrong reasons |
| No common sense | AI systems do not understand physical reality, social context, or the consequences of their outputs the way humans do |
Users should know when they are interacting with or affected by an AI system. Presenting AI-generated content as human-created, or AI-assisted decisions as purely human decisions, is a form of deception.
High-stakes decisions — medical diagnosis, criminal justice, hiring, credit, housing — should not be made by AI systems without meaningful human review. "The algorithm decided" is not acceptable accountability.
Where possible, AI systems used in consequential decisions should be able to explain why they produced a particular output. An applicant denied a loan or a defendant assessed as high-risk deserves an understandable reason.
When AI systems cause harm, someone must be accountable. AI systems themselves cannot be held accountable. The humans and organizations that build, deploy, and use them bear that responsibility.
┌─────────────────────────────────────────────────────────────────┐ │ MACHINE LEARNING PIPELINE │ │ │ │ Raw Data → Feature Engineering → Training Data │ │ │ │ │ ▼ │ │ Learning Algorithm │ │ │ │ │ ▼ │ │ Model │ │ │ │ │ ┌───────────────┴──────────────┐ │ │ ▼ ▼ │ │ Evaluation Deployment │ │ (validation / test) (new inputs arrive) │ │ │ │ │ │ ▼ ▼ │ │ Adjust and Retrain Predictions │ └─────────────────────────────────────────────────────────────────┘
Diagram Questions
| Student | Hours/week | Completion Rate | Trace | Prediction |
|---|---|---|---|---|
| Ana | 10 | 0.82 | 10 ≥ 8 AND 0.82 ≥ 0.75 → both conditions met | PASS |
| Ben | 6 | 0.91 | 6 < 8 (branch 1 fails); 0.91 ≥ 0.90 → branch 2 applies | PASS |
| Cara | 5 | 0.70 | 5 < 8 (branch 1 fails); 5 < 12 AND 0.70 < 0.90 (branch 2 fails) | FAIL |
TP = 110 (predicted condition, actually has it)
FP = 130 − 110 = 20 (predicted condition, actually does not)
FN = 120 − 110 = 10 (predicted no condition, actually has it)
TN = 80 − 20 = 60 (predicted no condition, actually does not)
Precision = TP / (TP + FP) = 110 / 130 ≈ 84.6%
Recall = TP / (TP + FN) = 110 / 120 ≈ 91.7%
Answer these questions before attempting the longer practice questions.
Identify two errors in this description. Explain what actually happens during neural network inference.
(a) Calculate the accuracy a trivial "always predict legitimate" baseline would achieve. (b) Explain why 99.2% accuracy is not sufficient evidence of readiness. (c) What additional metrics should be reported?
Identify three problems with this reasoning.
Design the feature set for a machine learning model that predicts whether a patient is at risk for hospital readmission within 30 days of discharge. List at least eight features, specify the data type of each (number, category, or Boolean), and explain why each feature might be predictive. Then identify one feature that might introduce bias and explain why.
You are evaluating two AI systems for automated essay scoring. System A: neural network trained on 500,000 graded essays; 87% accuracy within one grade point. System B: rule-based system counting sentence variety, vocabulary richness, transitions, and paragraph structure; 81% accuracy. (a) For which use — helping a teacher review essays quickly versus automatically assigning final grades — would each system be more appropriate, and why? (b) What two additional pieces of information would you want before recommending either system for high-stakes use?
These questions connect Chapter 26 to earlier chapters.
Chapter 27 introduces software engineering — the disciplined process of designing, building, testing, deploying, and maintaining software systems. Where this chapter described how AI systems are trained and evaluated, the next chapter zooms out to the entire software development lifecycle: gathering requirements, designing before coding, implementing incrementally, testing systematically, collaborating with version control, documenting for future maintainers, and managing real projects with deadlines, teams, and changing requirements. Many of the AI systems discussed in Chapter 26 are themselves complex software projects, and understanding software engineering will help you see how systems like these move from an idea to a working, maintained product.