00_pytorch_and_deep_learning_fundamentals.pdf

E
Deep Learning with
“What is deep learning?”
Machine learning is turning things (data)
into numbers and finding patterns in those
numbers.
The computer does this part.
How?
Code & math.
We’re going to be writing the code.
Arti
fi
cial
Intelligence
Machine
Learning
Machine Learning vs. Deep Learning
Deep
Learning
Traditional
programming
Machine
learning
algorithm
Starts with
Inputs Output
1. Cut vegetables
2. Season chicken
3. Preheat oven
4. Cook chicken for 30-minutes
5. Add vegetables
Starts with
Inputs Rules
Makes
Output
Figures out
1. Cut vegetables
2. Season chicken
3. Preheat oven
4. Cook chicken for 30-minutes
5. Add vegetables
Rules
“Why use machine learning (or
deep learning)?”
Better reason: For a complex
problem, can you think of all the rules?
(probably not)
Good reason: Why not?
Source: 2020 Machine Learning Roadmap video.
— A wise software engineer… (actually rule 1 of Google’s Machine Learning Handbook)
“If you can build a simple rule-based system
that doesn’t require machine learning, do
that.”
(maybe not very simple…)
What deep learning is good for
• Problems with long lists of rules—when the traditional
approach fails, machine learning/deep learning may help.
• Continually changing environments—deep learning can
adapt (‘learn’) to new scenarios.
• Discovering insights within large collections of data—can
you imagine trying to hand-craft rules for what 101 di
ff
erent
kinds of food look like?
🤖✅
What deep learning is not good for
• When you need explainability—the patterns learned by a deep
learning model are typically uninterpretable by a human.
• When the traditional approach is a better option — if you can
accomplish what you need with a simple rule-based system.
• When errors are unacceptable — since the outputs of deep
learning model aren’t always predictable.
• When you don’t have much data — deep learning models
usually require a fairly large amount of data to produce great
results.
🤖🚫
(typically)
(though we’ll see how to get great results without huge amounts of data)
Unstructured data
Deep
Learning
Machine Learning vs. Deep Learning
Structured data
Machine
Learning
Algorithm: neural
network
Algorithm: gradient
boosted machine
Machine Learning vs. Deep Learning
Structured data Unstructured data
• Random forest
• Gradient boosted models
• Naive Bayes
• Nearest neighbour
• Support vector machine
• …many more
• Neural networks
• Fully connected neural network
• Convolutional neural network
• Recurrent neural network
• Transformer
• …many more
What we’re focused on building
(with PyTorch)
(since the advent of deep learning these are
often referred to as “shallow algorithms”)
(depending how you represent your problem,
many algorithms can be used for both)
(common algorithms)
“What are neural networks?”
Neural Networks
[[116, 78, 15],
[117, 43, 96],
[125, 87, 23],
…,
[[0.983, 0.004, 0.013],
[0.110, 0.889, 0.001],
[0.023, 0.027, 0.985],
…,
Inputs
Numerical
encoding
Learns
representation
(patterns/features/weights)
Representation
outputs
Outputs
(a human can
understand these)
Ramen,
Spaghetti
Not a diaster
“Hey Siri, what’s
the weather
today?”
(choose the appropriate
neural network for your
problem)
(before data gets used
with a neural network,
it needs to be turned
into numbers)
Each of these nodes is
called a “hidden unit”
or “neuron”.
Anatomy of Neural Networks
Input layer
(data goes in here)
Output layer
(outputs learned representation or
prediction probabilities)
Hidden layer(s)
(learns patterns in data)
Note: “patterns” is an arbitrary term, you’ll often hear “embedding”, “weights”, “feature representation”,
“feature vectors” all referring to similar things.
# units/neurons = 2
# units/neurons = 3
# units/neurons = 1
Each layer is usually combination of
linear (straight line) and/or non-
linear (not-straight line) functions
Overall
architecture
Supervised
Learning
Unsupervised &
Self-supervised
Learning
Transfer
Learning
Types of Learning
We’ll be writing code to do these,
but the style of code can be adopted across learning paradigms.
“What is deep learning actually
used for?”
Source: 2020 Machine Learning Roadmap video.
Deep Learning Use Cases
Recommendation Translation
“Hey Siri, who’s the
biggest big dog of
them all?”
Speech recognition
Computer Vision Natural Language Processing (NLP)
To: daniel@mrdbourke.com
Hey Daniel,
This deep learning course is incredible!
I can’t wait to use what I’ve learned!
To: daniel@mrdbourke.com
Hay daniel…
C0ongratu1ations! U win $1139239230
Spam
Not spam
Sequence to sequence
(seq2seq)
Classi
fi
cation/regression
(some)
00_pytorch_and_deep_learning_fundamentals.pdf
“What is PyTorch?”
What is PyTorch?
• Most popular research deep learning framework*
• Write fast deep learning code in Python (able to run on a GPU/many
GPUs)
• Able to access many pre-built deep learning models (Torch Hub/
torchvision.models)
• Whole stack: preprocess data, model data, deploy model in your
application/cloud
• Originally designed and used in-house by Facebook/Meta (now open-
source and used by companies such as Tesla, Microsoft, OpenAI)
*Source: paperswithcode.com/trends February 2022
Why PyTorch?
Research favourite
Source: paperswithcode.com/trends February 2022
Why PyTorch?
Source: @fchollet Twitter
and PyTorch
Why PyTorch?
What is a GPU/TPU?
GPU (Graphics Processing Unit)
TPU (Tensor Processing Unit)
“What is a tensor?”
Neural Networks
[[116, 78, 15],
[117, 43, 96],
[125, 87, 23],
…,
[[0.983, 0.004, 0.013],
[0.110, 0.889, 0.001],
[0.023, 0.027, 0.985],
…,
Inputs
Numerical
encoding
Learns
representation
(patterns/features/weights)
Representation
outputs
Outputs
(a human can
understand these)
Ramen,
Spaghetti
Not spam
“Hey Siri, what’s
the weather
today?”
(choose the appropriate
neural network for your
problem)
(before data gets used
with an algorithm, it
needs to be turned into
numbers)
These are tensors!
[[116, 78, 15],
[117, 43, 96],
[125, 87, 23],
…,
[[0.983, 0.004, 0.013],
[0.110, 0.889, 0.001],
[0.023, 0.027, 0.985],
…,
Inputs
Numerical
encoding
Learns
representation
(patterns/features/weights)
Representation
outputs
Outputs
Ramen,
Spaghetti
These are tensors!
“What are we going to
cover?”
Source: @elonmusk Twitter
• Now:
• PyTorch basics & fundamentals (dealing with tensors and tensor operations)
• Later:
• Preprocessing data (getting it into tensors)
• Building and using pretrained deep learning models
• Fitting a model to the data (learning patterns)
• Making predictions with a model (using patterns)
• Evaluating model predictions
• Saving and loading models
• Using a trained model to make predictions on custom data
How: 👩🔬
👩🍳
What we’re going to cover
(broadly)
(we’ll be cooking up lots of code!)
What we’re going to cover
A PyTorch workflow
(one of many)
“How should I approach
this course?”
2. Explore and
experiment
How to approach this course
1. Code along
Motto #1: if in doubt, run the code!
Motto #2:
Experiment, experiment,
experiment!
3. Visualize what you
don’t understand
Motto #3:
Visualize, visualize, visualize!
4. Ask questions
🛠
5. Do the exercises
🤗
6. Share your work
(including the
“dumb” ones)
How not to approach this course
Avoid: 🧠
🔥
🔥
🔥 “I can’t learn
______”
Resources
https://www.github.com/mrdbourke/pytorch-deep-learning
Course materials
https://www.github.com/mrdbourke/pytorch-deep-learning/
discussions
Course Q&A
https://learnpytorch.io
Course online book
PyTorch website &
forums
This course
All things PyTorch
Let’s code!
tensor([[[1, 2, 3],
[3, 6, 9],
[2, 4, 5]]])
0
1
2
0 1 2
tensor([[[1, 2, 3],
[3, 6, 9],
[2, 4, 5]]])
tensor([[[1, 2, 3],
[3, 6, 9],
[2, 4, 5]]])
torch.Size([1, 3, 3])
0 1 2
Dimension (dim)
dim=0
dim=1
dim=2
Tensor dimensions
20 0 24 44
A*J + B*L + C*N A*K + B*M + C*O
D*J + E*L + F*N D*K + E*M + F*O
G*J + H*L + I*N G*K + H*M + I*O
44 38
126 86
58 63
4 6 8
5 0 3
3x2
3x3 3x2
4 7
6 8
8 1
J K
L M
N O
5 0 3
3 7 9
3 5 2
A B C
D E F
G H I
Dot product
3x3 3x2
torch.matmul( )
, )
* * *
= = =
+ +
3x2
For a live demo, checkout www.matrixmultiplication.xyz
Numbers on the inside must match New size is same as outside numbers
=
torch.matmul(
,
[[116, 78, 15],
[117, 43, 96],
[125, 87, 23],
…,
[[0.983, 0.004, 0.013],
[0.110, 0.889, 0.001],
[0.023, 0.027, 0.985],
…,
Inputs
Numerical
encoding
Learns
representation
(patterns/features/weights)
Representation
outputs
Outputs
Ramen,
Spaghetti
[[0.092, 0.210, 0.415],
[0.778, 0.929, 0.030],
[0.019, 0.182, 0.555],
…,
1. Initialise with random
weights (only at beginning)
2. Show examples
3. Update representation
outputs
4. Repeat with more
examples
Supervised
learning
(overview)
Tensor attributes
Attribute Meaning Code
Shape
The length (number of elements) of
each of the dimensions of a tensor.
tensor.shape
Rank/dimensions
The total number of tensor
dimensions. A scalar has rank 0, a
vector has rank 1, a matrix is rank 2, a
tensor has rank n.
tensor.ndim or tensor.size()
Speci
fi
c axis or dimension (e.g. “1st
axis” or “0th dimension”)
A particular dimension of a tensor. tensor[0], tensor[:, 1]…
00_pytorch_and_deep_learning_fundamentals.pdf
1 of 44

Recommended

Deep Learning using Tensorflow and Data Science Experience by
Deep Learning using Tensorflow and Data Science ExperienceDeep Learning using Tensorflow and Data Science Experience
Deep Learning using Tensorflow and Data Science ExperienceRoy Cecil
460 views21 slides
Deep learning with tensorflow by
Deep learning with tensorflowDeep learning with tensorflow
Deep learning with tensorflowCharmi Chokshi
1.5K views70 slides
AI Orange Belt - Session 1 by
AI Orange Belt - Session 1AI Orange Belt - Session 1
AI Orange Belt - Session 1AI Black Belt
443 views145 slides
DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify by
DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify
DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify Dataconomy Media
254 views59 slides
The Data Janitor Returns | Daniel Molnar | DN18 by
The Data Janitor Returns | Daniel Molnar | DN18The Data Janitor Returns | Daniel Molnar | DN18
The Data Janitor Returns | Daniel Molnar | DN18DataconomyGmbH
46 views59 slides
Data science unit 1 By: Professor Lili Saghafi by
Data science unit 1 By: Professor Lili Saghafi Data science unit 1 By: Professor Lili Saghafi
Data science unit 1 By: Professor Lili Saghafi Professor Lili Saghafi
194 views39 slides

More Related Content

Similar to 00_pytorch_and_deep_learning_fundamentals.pdf

Reproducibility and automation of machine learning process by
Reproducibility and automation of machine learning processReproducibility and automation of machine learning process
Reproducibility and automation of machine learning processDenis Dus
2.3K views39 slides
Deep learning introduction by
Deep learning introductionDeep learning introduction
Deep learning introductionAdwait Bhave
382 views44 slides
Introducing TensorFlow: The game changer in building "intelligent" applications by
Introducing TensorFlow: The game changer in building "intelligent" applicationsIntroducing TensorFlow: The game changer in building "intelligent" applications
Introducing TensorFlow: The game changer in building "intelligent" applicationsRokesh Jankie
1.7K views48 slides
Introduction to the intermediate Python - v1.1 by
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Andrei KUCHARAVY
847 views116 slides
Recent Advances in Machine Learning: Bringing a New Level of Intelligence to ... by
Recent Advances in Machine Learning: Bringing a New Level of Intelligence to ...Recent Advances in Machine Learning: Bringing a New Level of Intelligence to ...
Recent Advances in Machine Learning: Bringing a New Level of Intelligence to ...Brocade
1.4K views45 slides
Testing for the deeplearning folks by
Testing for the deeplearning folksTesting for the deeplearning folks
Testing for the deeplearning folksVishwas N
99 views46 slides

Similar to 00_pytorch_and_deep_learning_fundamentals.pdf(20)

Reproducibility and automation of machine learning process by Denis Dus
Reproducibility and automation of machine learning processReproducibility and automation of machine learning process
Reproducibility and automation of machine learning process
Denis Dus2.3K views
Deep learning introduction by Adwait Bhave
Deep learning introductionDeep learning introduction
Deep learning introduction
Adwait Bhave382 views
Introducing TensorFlow: The game changer in building "intelligent" applications by Rokesh Jankie
Introducing TensorFlow: The game changer in building "intelligent" applicationsIntroducing TensorFlow: The game changer in building "intelligent" applications
Introducing TensorFlow: The game changer in building "intelligent" applications
Rokesh Jankie1.7K views
Introduction to the intermediate Python - v1.1 by Andrei KUCHARAVY
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY847 views
Recent Advances in Machine Learning: Bringing a New Level of Intelligence to ... by Brocade
Recent Advances in Machine Learning: Bringing a New Level of Intelligence to ...Recent Advances in Machine Learning: Bringing a New Level of Intelligence to ...
Recent Advances in Machine Learning: Bringing a New Level of Intelligence to ...
Brocade1.4K views
Testing for the deeplearning folks by Vishwas N
Testing for the deeplearning folksTesting for the deeplearning folks
Testing for the deeplearning folks
Vishwas N99 views
Deep learning in production with the best by Adam Gibson
Deep learning in production   with the bestDeep learning in production   with the best
Deep learning in production with the best
Adam Gibson3.7K views
2014 manchester-reproducibility by c.titus.brown
2014 manchester-reproducibility2014 manchester-reproducibility
2014 manchester-reproducibility
c.titus.brown2.6K views
Data Science Accelerator Program by GoDataDriven
Data Science Accelerator ProgramData Science Accelerator Program
Data Science Accelerator Program
GoDataDriven581 views
Ardian Haxha- Flying with Python (OSCAL2014) by Open Labs Albania
Ardian Haxha- Flying with Python  (OSCAL2014)Ardian Haxha- Flying with Python  (OSCAL2014)
Ardian Haxha- Flying with Python (OSCAL2014)
Open Labs Albania338 views
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018 by Mike Harris
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris32 views
2014 nicta-reproducibility by c.titus.brown
2014 nicta-reproducibility2014 nicta-reproducibility
2014 nicta-reproducibility
c.titus.brown1.9K views
Introduction To TensorFlow by Spotle.ai
Introduction To TensorFlowIntroduction To TensorFlow
Introduction To TensorFlow
Spotle.ai1.1K views
Transferring Software Testing Tools to Practice by Tao Xie
Transferring Software Testing Tools to PracticeTransferring Software Testing Tools to Practice
Transferring Software Testing Tools to Practice
Tao Xie539 views
Machine learning the next revolution or just another hype by Jorge Ferrer
Machine learning   the next revolution or just another hypeMachine learning   the next revolution or just another hype
Machine learning the next revolution or just another hype
Jorge Ferrer1.4K views
Teaching Machine Learning with Physical Computing - July 2023 by Hal Speed
Teaching Machine Learning with Physical Computing - July 2023Teaching Machine Learning with Physical Computing - July 2023
Teaching Machine Learning with Physical Computing - July 2023
Hal Speed14 views
How do OpenAI GPT Models Work - Misconceptions and Tips for Developers by Ivo Andreev
How do OpenAI GPT Models Work - Misconceptions and Tips for DevelopersHow do OpenAI GPT Models Work - Misconceptions and Tips for Developers
How do OpenAI GPT Models Work - Misconceptions and Tips for Developers
Ivo Andreev46 views

Recently uploaded

Gross Anatomy of the Liver by
Gross Anatomy of the LiverGross Anatomy of the Liver
Gross Anatomy of the Liverobaje godwin sunday
69 views12 slides
MercerJesse2.1Doc.pdf by
MercerJesse2.1Doc.pdfMercerJesse2.1Doc.pdf
MercerJesse2.1Doc.pdfjessemercerail
280 views5 slides
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx by
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxEIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxISSIP
407 views50 slides
Recap of our Class by
Recap of our ClassRecap of our Class
Recap of our ClassCorinne Weisgerber
100 views15 slides
REPRESENTATION - GAUNTLET.pptx by
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptxiammrhaywood
151 views26 slides
Java Simplified: Understanding Programming Basics by
Java Simplified: Understanding Programming BasicsJava Simplified: Understanding Programming Basics
Java Simplified: Understanding Programming BasicsAkshaj Vadakkath Joshy
532 views155 slides

Recently uploaded(20)

EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx by ISSIP
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxEIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
ISSIP407 views
REPRESENTATION - GAUNTLET.pptx by iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood151 views
JQUERY.pdf by ArthyR3
JQUERY.pdfJQUERY.pdf
JQUERY.pdf
ArthyR396 views
How to empty an One2many field in Odoo by Celine George
How to empty an One2many field in OdooHow to empty an One2many field in Odoo
How to empty an One2many field in Odoo
Celine George97 views
When Sex Gets Complicated: Porn, Affairs, & Cybersex by Marlene Maheu
When Sex Gets Complicated: Porn, Affairs, & CybersexWhen Sex Gets Complicated: Porn, Affairs, & Cybersex
When Sex Gets Complicated: Porn, Affairs, & Cybersex
Marlene Maheu99 views
Relationship of psychology with other subjects. by palswagata2003
Relationship of psychology with other subjects.Relationship of psychology with other subjects.
Relationship of psychology with other subjects.
palswagata200377 views
Narration lesson plan by TARIQ KHAN
Narration lesson planNarration lesson plan
Narration lesson plan
TARIQ KHAN64 views
GCSE Spanish by WestHatch
GCSE SpanishGCSE Spanish
GCSE Spanish
WestHatch53 views
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant... by Ms. Pooja Bhandare
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Ms. Pooja Bhandare166 views

00_pytorch_and_deep_learning_fundamentals.pdf

  • 2. “What is deep learning?”
  • 3. Machine learning is turning things (data) into numbers and finding patterns in those numbers. The computer does this part. How? Code & math. We’re going to be writing the code.
  • 5. Traditional programming Machine learning algorithm Starts with Inputs Output 1. Cut vegetables 2. Season chicken 3. Preheat oven 4. Cook chicken for 30-minutes 5. Add vegetables Starts with Inputs Rules Makes Output Figures out 1. Cut vegetables 2. Season chicken 3. Preheat oven 4. Cook chicken for 30-minutes 5. Add vegetables Rules
  • 6. “Why use machine learning (or deep learning)?”
  • 7. Better reason: For a complex problem, can you think of all the rules? (probably not) Good reason: Why not?
  • 8. Source: 2020 Machine Learning Roadmap video.
  • 9. — A wise software engineer… (actually rule 1 of Google’s Machine Learning Handbook) “If you can build a simple rule-based system that doesn’t require machine learning, do that.” (maybe not very simple…)
  • 10. What deep learning is good for • Problems with long lists of rules—when the traditional approach fails, machine learning/deep learning may help. • Continually changing environments—deep learning can adapt (‘learn’) to new scenarios. • Discovering insights within large collections of data—can you imagine trying to hand-craft rules for what 101 di ff erent kinds of food look like? 🤖✅
  • 11. What deep learning is not good for • When you need explainability—the patterns learned by a deep learning model are typically uninterpretable by a human. • When the traditional approach is a better option — if you can accomplish what you need with a simple rule-based system. • When errors are unacceptable — since the outputs of deep learning model aren’t always predictable. • When you don’t have much data — deep learning models usually require a fairly large amount of data to produce great results. 🤖🚫 (typically) (though we’ll see how to get great results without huge amounts of data)
  • 12. Unstructured data Deep Learning Machine Learning vs. Deep Learning Structured data Machine Learning Algorithm: neural network Algorithm: gradient boosted machine
  • 13. Machine Learning vs. Deep Learning Structured data Unstructured data • Random forest • Gradient boosted models • Naive Bayes • Nearest neighbour • Support vector machine • …many more • Neural networks • Fully connected neural network • Convolutional neural network • Recurrent neural network • Transformer • …many more What we’re focused on building (with PyTorch) (since the advent of deep learning these are often referred to as “shallow algorithms”) (depending how you represent your problem, many algorithms can be used for both) (common algorithms)
  • 14. “What are neural networks?”
  • 15. Neural Networks [[116, 78, 15], [117, 43, 96], [125, 87, 23], …, [[0.983, 0.004, 0.013], [0.110, 0.889, 0.001], [0.023, 0.027, 0.985], …, Inputs Numerical encoding Learns representation (patterns/features/weights) Representation outputs Outputs (a human can understand these) Ramen, Spaghetti Not a diaster “Hey Siri, what’s the weather today?” (choose the appropriate neural network for your problem) (before data gets used with a neural network, it needs to be turned into numbers) Each of these nodes is called a “hidden unit” or “neuron”.
  • 16. Anatomy of Neural Networks Input layer (data goes in here) Output layer (outputs learned representation or prediction probabilities) Hidden layer(s) (learns patterns in data) Note: “patterns” is an arbitrary term, you’ll often hear “embedding”, “weights”, “feature representation”, “feature vectors” all referring to similar things. # units/neurons = 2 # units/neurons = 3 # units/neurons = 1 Each layer is usually combination of linear (straight line) and/or non- linear (not-straight line) functions Overall architecture
  • 17. Supervised Learning Unsupervised & Self-supervised Learning Transfer Learning Types of Learning We’ll be writing code to do these, but the style of code can be adopted across learning paradigms.
  • 18. “What is deep learning actually used for?”
  • 19. Source: 2020 Machine Learning Roadmap video.
  • 20. Deep Learning Use Cases Recommendation Translation “Hey Siri, who’s the biggest big dog of them all?” Speech recognition Computer Vision Natural Language Processing (NLP) To: daniel@mrdbourke.com Hey Daniel, This deep learning course is incredible! I can’t wait to use what I’ve learned! To: daniel@mrdbourke.com Hay daniel… C0ongratu1ations! U win $1139239230 Spam Not spam Sequence to sequence (seq2seq) Classi fi cation/regression (some)
  • 23. What is PyTorch? • Most popular research deep learning framework* • Write fast deep learning code in Python (able to run on a GPU/many GPUs) • Able to access many pre-built deep learning models (Torch Hub/ torchvision.models) • Whole stack: preprocess data, model data, deploy model in your application/cloud • Originally designed and used in-house by Facebook/Meta (now open- source and used by companies such as Tesla, Microsoft, OpenAI) *Source: paperswithcode.com/trends February 2022
  • 24. Why PyTorch? Research favourite Source: paperswithcode.com/trends February 2022
  • 25. Why PyTorch? Source: @fchollet Twitter and PyTorch
  • 27. What is a GPU/TPU? GPU (Graphics Processing Unit) TPU (Tensor Processing Unit)
  • 28. “What is a tensor?”
  • 29. Neural Networks [[116, 78, 15], [117, 43, 96], [125, 87, 23], …, [[0.983, 0.004, 0.013], [0.110, 0.889, 0.001], [0.023, 0.027, 0.985], …, Inputs Numerical encoding Learns representation (patterns/features/weights) Representation outputs Outputs (a human can understand these) Ramen, Spaghetti Not spam “Hey Siri, what’s the weather today?” (choose the appropriate neural network for your problem) (before data gets used with an algorithm, it needs to be turned into numbers) These are tensors!
  • 30. [[116, 78, 15], [117, 43, 96], [125, 87, 23], …, [[0.983, 0.004, 0.013], [0.110, 0.889, 0.001], [0.023, 0.027, 0.985], …, Inputs Numerical encoding Learns representation (patterns/features/weights) Representation outputs Outputs Ramen, Spaghetti These are tensors!
  • 31. “What are we going to cover?”
  • 33. • Now: • PyTorch basics & fundamentals (dealing with tensors and tensor operations) • Later: • Preprocessing data (getting it into tensors) • Building and using pretrained deep learning models • Fitting a model to the data (learning patterns) • Making predictions with a model (using patterns) • Evaluating model predictions • Saving and loading models • Using a trained model to make predictions on custom data How: 👩🔬 👩🍳 What we’re going to cover (broadly) (we’ll be cooking up lots of code!)
  • 34. What we’re going to cover A PyTorch workflow (one of many)
  • 35. “How should I approach this course?”
  • 36. 2. Explore and experiment How to approach this course 1. Code along Motto #1: if in doubt, run the code! Motto #2: Experiment, experiment, experiment! 3. Visualize what you don’t understand Motto #3: Visualize, visualize, visualize! 4. Ask questions 🛠 5. Do the exercises 🤗 6. Share your work (including the “dumb” ones)
  • 37. How not to approach this course Avoid: 🧠 🔥 🔥 🔥 “I can’t learn ______”
  • 40. tensor([[[1, 2, 3], [3, 6, 9], [2, 4, 5]]]) 0 1 2 0 1 2 tensor([[[1, 2, 3], [3, 6, 9], [2, 4, 5]]]) tensor([[[1, 2, 3], [3, 6, 9], [2, 4, 5]]]) torch.Size([1, 3, 3]) 0 1 2 Dimension (dim) dim=0 dim=1 dim=2 Tensor dimensions
  • 41. 20 0 24 44 A*J + B*L + C*N A*K + B*M + C*O D*J + E*L + F*N D*K + E*M + F*O G*J + H*L + I*N G*K + H*M + I*O 44 38 126 86 58 63 4 6 8 5 0 3 3x2 3x3 3x2 4 7 6 8 8 1 J K L M N O 5 0 3 3 7 9 3 5 2 A B C D E F G H I Dot product 3x3 3x2 torch.matmul( ) , ) * * * = = = + + 3x2 For a live demo, checkout www.matrixmultiplication.xyz Numbers on the inside must match New size is same as outside numbers = torch.matmul( ,
  • 42. [[116, 78, 15], [117, 43, 96], [125, 87, 23], …, [[0.983, 0.004, 0.013], [0.110, 0.889, 0.001], [0.023, 0.027, 0.985], …, Inputs Numerical encoding Learns representation (patterns/features/weights) Representation outputs Outputs Ramen, Spaghetti [[0.092, 0.210, 0.415], [0.778, 0.929, 0.030], [0.019, 0.182, 0.555], …, 1. Initialise with random weights (only at beginning) 2. Show examples 3. Update representation outputs 4. Repeat with more examples Supervised learning (overview)
  • 43. Tensor attributes Attribute Meaning Code Shape The length (number of elements) of each of the dimensions of a tensor. tensor.shape Rank/dimensions The total number of tensor dimensions. A scalar has rank 0, a vector has rank 1, a matrix is rank 2, a tensor has rank n. tensor.ndim or tensor.size() Speci fi c axis or dimension (e.g. “1st axis” or “0th dimension”) A particular dimension of a tensor. tensor[0], tensor[:, 1]…