What deep learning is
- Lesson 1
- 45 min
- Module 1: What a neural network is
Lesson 1 of 23 · Deep Learning and Transformers ExplainedWhat deep learning is
1. What a neural network is
2. Tensors and PyTorch
3. How neural networks learn
4. Diagnose training problems
5. Represent sequences and meaning
6. Assemble a transformer
7. Use pretrained models
8. Under the hood: the mathematicsOptional
What you will be able to do
Understand what deep learning is, and when it is worth its cost, before you build a network. You meet the problem that runs through this course: sending each of Larkfield’s support tickets to the right team.
Before you startWhat to know and to have ready
What you need to know
- What a model, training and a prediction are, from What machine learning is in the machine learning course.
- Logistic regression: a weighted sum bent into a score from 0 to 1, from Classification intuition.
- Validation data and accuracy, from Train, validation and test sets and Classification metrics.
What you need on your computer
- A browser. This lesson has no code. You install PyTorch in Module 2, in Set up PyTorch.
All numbers in this lesson come from the course’s recorded runs.
Your phone already uses deep learning
Section titled “Your phone already uses deep learning”Open the photo app on your phone and search for “dog”. It finds your dog photos, although nobody typed “dog” next to them. Speak a message, and the phone writes it as text. Point the camera at a menu in another language, and it shows a translation.
Nobody wrote the rules for these tools. Try to write the rule for “this photo shows a dog”: four legs, fur, a tail. A cat matches too, and a dog that lies down does not. The machine learning course met the same problem with cats and spam. There, the answer was to learn the rule from examples.
These phone tools go one step further. They learn from the raw input itself: the pixels of a photo, the sound wave of your voice, the words of a sentence. No person decides first which facts about the photo matter. The model finds them. This is deep learning, and this course shows how it works, from one neuron to a small transformer.
Larkfield’s problem: who answers this ticket?
Section titled “Larkfield’s problem: who answers this ticket?”Larkfield is the home-and-garden shop of the earlier courses. Five support teams answer customer tickets: delivery, returns, payment, warranty and account. Today, a person reads every new ticket and sends it to one team. This is called routing.
Grace leads support. She wants routing done automatically, so that a ticket reaches the right team in seconds and nobody spends the first hour of the day sorting. A wrong team costs time: the ticket waits in the wrong queue, and then someone passes it on by hand.
Grace wrote down how her people choose the team. Here is her routing policy in plain words. The first rule is the most important: choose the team for the customer’s main request. Other topics that the customer mentions in passing do not decide the team.
| Team | Answers tickets about |
|---|---|
| delivery | an order on its way: late, lost, tracking, the courier, a missing box, an item broken when it arrives |
| returns | sending an item back: labels, exchanges, a wrong item to send back, collection of a bulky return |
| payment | money: double charges, declined cards, invoices, discount codes, a confirmed refund that has not reached the card |
| warranty | a product that develops a fault after some use: it stops working, a part breaks; repairs, safety problems |
| account | sign-in, password reset, email change, saved addresses and cards, marketing emails, loyalty points |
Two boundaries cause most mistakes, even for people. Broken on arrival goes to delivery; broken after use goes to warranty. And “Where is my refund?” goes to returns until the shop confirms that it received the item, then to payment.
The course has 5,896 Larkfield tickets, each with the team that Grace’s policy gives. The tickets are made up for this course; Module 2 says how. 600 of them are the validation tickets, and every router in this lesson is measured on them.
First try: a keyword rule
Section titled “First try: a keyword rule”Tomás, an AI engineer at Larkfield, has a quick idea. “A ticket about delivery says delivery. Let’s look for keywords.” He writes one list of word patterns for each team. The rule checks the teams in a fixed order, and the first team whose pattern matches wins:
- delivery: deliver, parcel, courier, tracking, arriv…
- returns: return, send back, exchange, label
- payment: charg…, card, invoice, refund, payment, paid, discount
- warranty: broke, stopped working, guarantee, warrant…, repair, faulty
- account: log in, password, account, email, sign in
If no pattern matches, the rule chooses delivery, the most common team. Here are three real validation tickets, shortened, with the rule’s steps.
Ticket T-64697. “…The electric kettle was listed at a specific price on the checkout page, but my card statement shows a higher amount. The delivery was smooth earlier this week… Could you please review the charge and confirm the correct amount?” The rule checks delivery first and finds deliver. It stops: delivery. Grace’s policy says payment. The customer mentions the delivery only to say that it went well.
Ticket T-64704. “I have been using the electric kettle for about a week. Yesterday the handle became very hot during use, and I noticed a faint burning smell… I have stopped using it. Could you let me know whether this is a known safety issue…?” No pattern matches. “Stopped using” is not “stopped working”, and the customer never says broke or faulty. The rule falls back to delivery. Grace’s policy says warranty: a safety problem after use.
Ticket T-64710. “Hi, this isn’t a delivery issue, the hammock arrived fine. The problem is that I can’t log in to my account, and the password reset email never came through…” The rule finds deliver and stops: delivery. The policy says account. The customer said “isn’t”, but a keyword cannot read “not”.
On all 600 validation tickets, the keyword rule is right 57.3% of the time. Always answering “delivery”, without reading anything, gives 27.5%. So the rule helps, but it sends more than 4 tickets in 10 to the wrong team. The chart shows where it fails.
- The request is plain or on a boundary
- Other words get in the way
Text description of the chart
Accuracy of the keyword rule on the validation tickets, by how the ticket is written. Plain tickets: 72%. Tickets on one of the policy’s boundaries: 54%. Tickets that mention another team’s words in passing (distractor): 42%. Tickets with a solved problem from another team first and the real request last (two topics): 40%. Tickets with a negation such as “not a delivery problem”: 26%.
Can Tomás fix the rule? He can add patterns and change the order. But each change that fixes some tickets breaks others, because the same word means different things in different tickets. You try one change yourself in Your turn below.
The idea: let the model find the features
Section titled “The idea: let the model find the features”The machine learning course gave the first answer: do not write the rule, learn it from examples. Its models, such as logistic regression, learn a weight for each feature: each column of a table, such as priority or word_count. But a person chose those columns.
A ticket is free text, not a table. So a person must first turn the text into columns. The simplest way is one column for each word: how often the word appears in the ticket. A common version, TF-IDF, also gives very common words such as “the” less weight. Logistic regression then learns one weight for each word and each team. “Password” pushes a ticket toward account; “refund” pushes it toward payment.
This works far better than keywords, because the model learns how much each word counts from 4,696 training tickets, instead of from Tomás’s guesses. But a person still chose what the model sees: single words, counted, with their order thrown away.
A neural network goes one step further. It starts from the raw input, turned into numbers, and learns its own features in layers. The first layer learns useful combinations of the inputs. The next layer learns combinations of those combinations. Nobody tells it which combinations matter; it finds them from the examples and their right answers. The diagram compares the three ways.
Text description of the diagram
Three rows. Each row starts with the ticket text and ends with a team.
Row 1, a person writes the rule: the text goes into a keyword rule. For example, “deliver” goes to delivery and “return” goes to returns.
Row 2, a person chooses the features and a model learns the weights: the text becomes features chosen by a person, one count per word. Logistic regression learns one weight per word and team.
Row 3, a neural network learns its own features: the text, as numbers, goes into layers. The layers learn which patterns matter, from examples.
Why “deep”? A network with many layers in a chain is called deep, and each layer builds on the one before. Why “neural”? The first networks were loosely inspired by brain cells. The next lesson shows how loose that link is.
Where does this matter most? In a photo, one pixel says almost nothing. “Pixel 4,812 is brown” is a useless column. A deep network learns small patterns first, such as edges, then shapes made of edges, then objects made of shapes. Nobody could write those columns by hand, and that is why deep learning won first on images and sound.
The honest result for Larkfield
Section titled “The honest result for Larkfield”Priya, Larkfield’s data scientist, measured each router on the same 600 validation tickets. She also trained the course’s first network, which you build in Modules 2 and 3. The chart puts them side by side.
Text description of the chart
Accuracy on the 600 validation tickets. Always answering “delivery”: 27.5%. The keyword rule: 57.3%. Word counts (TF-IDF) with logistic regression, the tools of the machine learning course: 98.8%. The first network of this course, at its best epoch: 98.3%.
Read the chart carefully. Word counts with logistic regression route 98.8% of the tickets right. The first network gets 98.3%. On these short tickets, the words decide the team, and counting words is enough. So the linear model is the best and cheapest router for Larkfield, and Larkfield should use it.
Omar, the product manager, asks the obvious question: “Then why learn deep learning on this task?” Priya has two answers.
First, the task is small, familiar and fast, so you can watch every part of a network learn: its shapes, its loss, its mistakes. A strong, simple baseline next to it keeps every result honest. Second, word counts have a limit, and you will see it. “Damaged on arrival” and “not damaged, it broke after a month” need word order and context. Module 5 shows tickets where counting fails. Then Modules 5 and 6 build attention and a small transformer, the kind of network inside today’s language models.
That transformer will do worse than the linear model on these tickets. About 4,700 tickets are far too few to learn a language from nothing. The fix is to start from a model that has already read a lot of text, a pretrained model. Module 7 runs one, and the case study “Fine-tune a small transformer” measures what that pretraining buys.
When deep learning is worth it, and when it is not
Section titled “When deep learning is worth it, and when it is not”Deep learning is a good choice when these things are true:
- The input is raw and rich: images, sound, free text. A person cannot write the useful features.
- The pattern is hard to describe, like “a dog” or “a tired voice”.
- There is a lot of data, or a pretrained model that already learned from a lot of data and that you can adapt.
The machine learning course’s models are usually better in these cases:
- The data is a table of facts that a person chose: amounts, dates, counts, categories. Gradient boosting is very hard to beat there.
- There is little data, a few thousand rows or fewer.
- People need explanations, for example why a loan was refused.
- Speed and cost matter more than the last point of accuracy.
What deep learning costs: more data, more computing time, more settings to tune, results that are harder to explain, and more ways to fail silently. Module 4 is about those failures. The case study “Deep network or gradient boosting?” trains both on the same table of data and asks which is worth it.
The case studies at the end of the course
Section titled “The case studies at the end of the course”Larkfield’s tickets run through every lesson, so you see one problem from many sides. The course ends with four case studies on other data: images, a table, a pretrained model and a tiny language model. Each one takes real, public data from the raw file to a tested result and a recommendation.
Case studies in this course
At the end of the course, you use what you learn on a realistic project, from the data to the recommendation. Complete at least one for the certificate; the others are optional.
- Classify clothing imagesTrain and diagnose a small network on Fashion-MNIST end to end: a baseline, training curves, a confusion matrix, the errors it makes, and a saved, reproducible model.
- Deep network or gradient boosting?Compare a neural network with gradient boosting on an open tabular dataset under the same split and metric, and decide honestly whether the network is worth its cost.
- Fine-tune a small transformerAdapt a small pretrained transformer to a text classification task on open data, compare it with a model trained from scratch, and measure what the pretraining bought.
- Train a tiny language modelTrain a character-level transformer on public-domain text with next-token prediction, watch its samples improve during training, and measure loss on held-out text.
Some descriptions use words that the course teaches later, such as a confusion matrix or fine-tuning. For now, read the list as a map of where the course goes. Each case study is also a portfolio piece, a project that you can show and talk about in an interview. Most learners start them after Module 7.
Guided practice: rule, model or network?
Section titled “Guided practice: rule, model or network?”- Read the six tasks below.
- For each task, choose one way: a rule that a person writes, a model of the machine learning course, or a neural network.
- Write one reason for each choice: what is the input, how much data is there, and does someone need an explanation?
- Compare your answers with the example answer.
The six tasks:
- Give free delivery to every order above $50.
- Find a cracked plant pot in a photo that a customer sends with a ticket.
- Predict whether a business customer pays an invoice late, from a table of 15 facts about 3,000 customers.
- Route Larkfield’s tickets to the five teams.
- Turn a customer’s voice message into text.
- Tell a customer why their warranty claim was refused, with the reason in the policy.
Show an example answer
| Task | Way | Why |
|---|---|---|
| 1. Free delivery above $50 | Rule | The rule is exact and one line long. |
| 2. Cracked pot in a photo | Network | The input is pixels. Nobody can write “cracked” as columns, and pretrained image models exist. |
| 3. Late payment from 15 facts | Machine learning course | A small table of chosen facts: gradient boosting or logistic regression is cheaper, often as good or better, and easier to explain. |
| 4. Route tickets | Machine learning course first | Word counts with logistic regression reach 98.8%. A network is worth trying only where word order matters, and only if it beats this baseline. |
| 5. Voice to text | Network | Sound is raw input. Use a pretrained speech model; do not train one from nothing. |
| 6. Explain a refused claim | Rule, or a simple model with a person | The customer needs a reason from the policy. A network’s weights cannot give it. |
The key question is not “which model is cleverer?” It is “what is the input, how much data is there, and who must understand the answer?”
Your turn: check payment first
Section titled “Your turn: check payment first”Tomás sees that ticket T-64697 went to delivery because the rule checks delivery first. He moves payment to the top of the list: payment, delivery, returns, warranty, account.
Before you read the answer, predict: does the accuracy on the 600 validation tickets go up a lot, a little, or down? Is T-64697 fixed? Is T-64710 (“this isn’t a delivery issue… I can’t log in”) fixed?
Show the answer
T-64697 is fixed: it has card and charge, so payment now matches first. T-64710 is still wrong: it has no payment word, so delivery matches next.
On all 600 tickets, accuracy goes from 57.3% to only 58.8%. The new order fixes 56 tickets, but it breaks 47 others. Here is one that it breaks, T-64700: “The refund for my first order came through yesterday, so that’s all sorted now. Anyway, my watering can was marked as delivered this morning, but the courier left it with my neighbour…” The customer mentions a solved refund first. Payment now matches first, and the ticket leaves the delivery team.
Every word appears in tickets of several teams. A rule that looks at one word at a time cannot know which mention is the real request. A model that weighs all the words together can.
Common mistake
A higher score elsewhere taken as a reason to switch
Symptom: Tomás reads about a large network that routes support tickets very well. He wants to replace Priya’s word-count model with a network at once. A month later, the network is slower to train, harder to explain to Grace, and no more accurate.
Cause: a result on other data says nothing about Larkfield’s tickets. On these tickets, the linear model already routes 98.8% right, and the first network reaches 98.3%. The question was never “is a network powerful?” It was “does a network beat our baseline, on our data, by enough to pay for its cost?”
Fix: measure every new model against the simple baseline, on the same validation tickets, with the same metric. Keep the simple model unless the new one wins clearly. Write down the cost too: training time, the computer it needs, and how you will explain its answers.
Knowledge check
Section titled “Knowledge check”Check your understanding
In your own words: what does a neural network do that the logistic regression of the machine learning course does not?
Show the answer
Logistic regression learns one weight for each feature, but a person chooses the features, such as one count per word. A neural network starts from the raw input as numbers and learns its own features in layers. Each layer learns combinations of what the layer before it found. So the network can find patterns that nobody wrote down as a column, which matters most for images, sound and text.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Check your understanding
Why does the keyword rule send ticket T-64710 ('this isn't a delivery issue … I can't log in to my account') to delivery?
Show the answer
The rule checks the delivery patterns first, and the ticket contains the word “delivery”. The first match wins, so the rule stops there. A keyword cannot read “isn’t”, and the rule never looks at “log in” or “password”, which come later in the ticket. Grace’s policy chooses the team for the main request, which is account.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Check your understanding
Predict: Larkfield wants to predict which orders will be returned, from a table of 12 facts per order (price, category, delivery time …) and 8,000 past orders. Is deep learning the first thing to try? Why?
Show the answer
No. The data is a small table of facts that a person chose. So the machine learning course’s models come first: logistic regression as a baseline, then gradient boosting. They train fast, need less data and are easier to explain. A network is worth trying only if it beats them clearly on the same validation data. The case study “Deep network or gradient boosting?” tests exactly this question.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Recap
- Deep learning learns its own features from raw input, such as pixels, sound or text, in a chain of layers. The machine learning course’s models learn weights for features that a person chose.
- Larkfield’s problem: route each ticket to one of five teams, following Grace’s policy. A keyword rule gets 57.3%; it fails on negations and on other teams’ words in passing.
- On these tickets, word counts with logistic regression get 98.8%, and the first network 98.3%. The linear model is Larkfield’s best router. The course uses the task to see how networks learn, and later where word counts reach their limit.
- Choose deep learning for raw, rich input, patterns that are hard to describe, and a lot of data or a pretrained model. Choose the machine learning course’s models for tables of facts, little data and decisions that need explanations.
Next, open the network up: one neuron, which turns out to be an old friend, and then layers of them.
Next: Neurons and layers