Learning rate scheduling with TensorFlow
Key Takeaways
This video demonstrates how to schedule the learning rate using TensorFlow and Keras, improving the consistency of model training.
Full Transcript
in our other videos we talked about the basics of fine-tuning a language model with tensorflow and as always when i refer to videos i'll link them below but still can we do better so here's the code from our model fine tuning video and while while it works we could definitely tweak a couple of things by far the most important thing is the learning rate in this video we'll talk about how to change it which will make your training much more consistently successful in fact there are two things we want to change about the default learning rate for adam the first is that it's way too high for our models so by default adam uses a learning rate of 10 to the minus 3 which is very high for training transformers we're going to start at 5 by 10 to the minus 5 which is 20 times lower than the default and secondly we don't just want a constant learning rate we can get even better performance if we decay the learning rate down to a tiny value or even to zero over the course of training so that's what this polynomial decay schedule thing is doing that name might be intimidating especially if you only vaguely remember what a polynomial is for maths class so i'll show you what that decay looks like in a second but first we need to tell the scheduler how long training is going to be so that it decays at the right speed and that's what this code here is doing so we're computing how many mini batches the model is going to see over the entire training run and to compute that we're taking the size of the training set dividing it by the batch size which gives us the number of batches per epoch and then we're multiplying that by the number of epochs to get the total number of batches it's going to see over the whole training run so once we know how many batches how many training steps we're taking we just pass all of that information to the scheduler and we're ready to go so what does the polynomial decay schedule look like with default options it's actually just a linear schedule so it looks like this it starts at our initial value which is 5 by 10 to the minus 5 or five e minus five and then it decays down at a constant rate until it hits zero right at the very end of training so why do they call it polynomial and not linear well if you tweak the options you can get a higher order a truly polynomial decay schedule but there's no need to do that right now by default you get a linear schedule and if you were aware that a linear function is a special case of a polynomial you can feel proud so that aside how do we actually use the scheduler so this is easily we just pass it to adam you'll notice the first time when we compiled the model we just passed the string atom keras recognizes the names of common optimizers and loss functions if you pass them as strings so it saves time and it avoids imports to do it that way if you only want the default settings but we're professional machine learners now with our very own learning rate schedule so we have to do things properly so the first thing we do is we import the optimizer then we initialize it with our scheduler in the learning rate argument and then we compile the model using our new optimizer and whatever loss function you want we'll leave that unchanged this will be sparse categorical cross-entropy if you're following along from the fine-tuning video but it can be anything else that you're using yourself so now we have a high performance model ready to go all that remains is to fit the model just like we did before and remember because we've compiled the model with the new optimizer and the new learning rate we actually don't need to change anything about the fit.call at all we just call fit here exactly the same command we used before or if you've seen in other videos but now we get a beautiful training with a nice smooth a good initial learning rate and a solid learning rate decay and you will get much better performance as a result
Original Description
This is the olversion of the Learning rate Scheduling with TensorFlow, you should watch https://youtu.be/cpzq6ESSM5c instead.
How to schedule the learning rate using TensorFlow and Keras.
This video is part of the Hugging Face course: http://huggingface.co/course
Open in colab to run the code samples:
https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/videos/tf_lr_scheduling.ipynb
Related videos:
- Introduction to Keras: https://youtu.be/rnTGBy2ax1c
- Fine-tuning with TensorFlow: https://youtu.be/alq1l8Lv9GA
- Prediction and metrics: https://youtu.be/nx10eh4CoOs
Have a question? Checkout the forums: https://discuss.huggingface.co/c/course/20
Subscribe to our newsletter: https://huggingface.curated.co/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from HuggingFace · HuggingFace · 19 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
▶
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
The Future of Natural Language Processing
HuggingFace
Trends in Model Size & Computational Efficiency in NLP
HuggingFace
Increasing Data Usage in Natural Language Processing
HuggingFace
In Domain & Out of Domain Generalization in the Future of NLP
HuggingFace
The Limits of NLU & the Rise of NLG in the Future of NLP
HuggingFace
The Lack of Robustness in the Future of NLP
HuggingFace
Inductive Bias, Common Sense, Continual Learning in The Future of NLP
HuggingFace
Train a Hugging Face Transformers Model with Amazon SageMaker
HuggingFace
What is Transfer Learning?
HuggingFace
The pipeline function
HuggingFace
Navigating the Model Hub
HuggingFace
Transformer models: Decoders
HuggingFace
The Transformer architecture
HuggingFace
Transformer models: Encoder-Decoders
HuggingFace
Transformer models: Encoders
HuggingFace
Keras introduction
HuggingFace
The push to hub API
HuggingFace
Fine-tuning with TensorFlow
HuggingFace
Learning rate scheduling with TensorFlow
HuggingFace
TensorFlow Predictions and metrics
HuggingFace
Welcome to the Hugging Face course
HuggingFace
The tokenization pipeline
HuggingFace
Supercharge your PyTorch training loop with Accelerate
HuggingFace
The Trainer API
HuggingFace
Batching inputs together (PyTorch)
HuggingFace
Batching inputs together (TensorFlow)
HuggingFace
Hugging Face Datasets overview (Pytorch)
HuggingFace
Hugging Face Datasets overview (Tensorflow)
HuggingFace
What is dynamic padding?
HuggingFace
What happens inside the pipeline function? (PyTorch)
HuggingFace
What happens inside the pipeline function? (TensorFlow)
HuggingFace
Instantiate a Transformers model (PyTorch)
HuggingFace
Instantiate a Transformers model (TensorFlow)
HuggingFace
Preprocessing sentence pairs (PyTorch)
HuggingFace
Preprocessing sentence pairs (TensorFlow)
HuggingFace
Write your training loop in PyTorch
HuggingFace
Managing a repo on the Model Hub
HuggingFace
Chapter 1 Live Session with Sylvain
HuggingFace
Chapter 2 Live Session with Lewis
HuggingFace
The push to hub API
HuggingFace
Chapter 2 Live Session with Sylvain
HuggingFace
Chapter 3 live sessions with Lewis (PyTorch)
HuggingFace
Day 1 Talks: JAX, Flax & Transformers 🤗
HuggingFace
Day 2 Talks: JAX, Flax & Transformers 🤗
HuggingFace
Day 3 Talks JAX, Flax, Transformers 🤗
HuggingFace
Chapter 4 live sessions with Omar
HuggingFace
Deploy a Hugging Face Transformers Model from S3 to Amazon SageMaker
HuggingFace
Deploy a Hugging Face Transformers Model from the Model Hub to Amazon SageMaker
HuggingFace
Run a Batch Transform Job using Hugging Face Transformers and Amazon SageMaker
HuggingFace
[Webinar] How to add machine learning capabilities with just a few lines of code
HuggingFace
Hugging Face + Zapier Demo Video
HuggingFace
Hugging Face + Google Sheets Demo
HuggingFace
Hugging Face Infinity Launch - 09/28
HuggingFace
Build and Deploy a Machine Learning App in 2 Minutes
HuggingFace
Hugging Face Infinity - GPU Walkthrough
HuggingFace
Otto - 🤗 Infinity Case Study
HuggingFace
Workshop: Getting started with Amazon Sagemaker Train a Hugging Face Transformers and deploy it
HuggingFace
Workshop: Going Production: Deploying, Scaling & Monitoring Hugging Face Transformer models
HuggingFace
🤗 Tasks: Causal Language Modeling
HuggingFace
🤗 Tasks: Masked Language Modeling
HuggingFace
More on: LLM Engineering
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Want to get started with deep learning
Reddit r/deeplearning
Building a Deepfake Detector From Scratch — What Nobody Tells You
Medium · Deep Learning
Unfolding the Meandering Path: High-Dimensional Invariance and the Flat 2D Plane of Neural…
Medium · Deep Learning
Implementing Neural Style Transfer from Scratch: The Project That Started It All
Medium · Deep Learning
🎓
Tutor Explanation
DeepCamp AI