Generate text with KerasNLP
Key Takeaways
This video demonstrates how to generate text with KerasNLP, a library developed by TensorFlow, using pre-trained models like GPT2, and fine-tuning them on custom datasets such as the Reddit dataset for specific writing styles.
Full Transcript
hi there welcome back to our last episode of apply the machine learning with caros TV and caros NP video series my name is way and I'm a developer advocate in Google ml team today we're going to cover a very exciting topic text generation large langage models are autoag these days and the core of this large Lang models is predicting the next word or token in a sentence which is often referred to as C LM pre trining large D models are complex to build and expensive to train from scratch luckily there are pre-trained LS available for use right away Caris NLP provides a large number of pre-end checkpoints that allows you to experiment with soda models without needing to train them yourself for example you can load the gpt2 model by calling the gbt2 co LM from preset method other than G gpt2 there are many other pre- Trend models available such as OPD arbert Roberta and so on you can find the complete model list in the link below now you can call the generat method to generate text where passing in a string my truth to emity was as a prompt and the gp2 model will try to write coherent text based on this prompt note that it takes about 18 seconds for the first round let's try another prompt this time it takes only 1.7 seconds which is about 10 times faster this is because the computational graph is compiled by X in the first round and reused in the second round behind the scene the quality of the generated text looks okay but we can improve it without fine tuning but before performance fine tuning let's spend a minute to talk about the architecture similar to the birth classifier we discussed last time the gbt2 Cal model also has a pre-processor tokenizer and backbone under the hood all of which can be easily loaded VI a simple front P set method for fine tuning we're going to use the Reddit tfue data set so that the output will follow reddits writing style here's an example of the training data since we're performing next word prediction in a language model we only need the document feature here next we Define a custom learning rate and kick off fine tuning using the fit method it takes quite a little bit of time and GPU memory but after it is finished the generated text will be closer to Reddit writing style and the generated lens will will be closer to our preset lens in the training set another thing you can do is to round the model on mobile devices you can convert the model to Testo light and run it on Android devices we want to go into the details of implementing this but you can find a code lab and a video below that teach you exactly how to do this one of the parameters that gives you final control over the generation process is a sampling method caring P offers several samply methods for example greedy search topk and beam search you can easily set the sampler VI stream when compiling the model by default the gp2 model uses topk sampling which basically means only sample from the topk candidate tokens or you can pass in a sampler instance like what we are doing here you can find out all the Samplers in the link below so that's it for text generation with caros NRP we have shown you how to generate text with a pre-trend gp2 model and find you the model for certain writing style and you can even build an Android app based on this now we have come to the end of our entire video series of Applied machine learning with caros CV and caros NP there are of course a lot more you can do with car CV and carp than we can cover in this video series I hope you find our videos useful to get started and I highly recommend you check out our comprehensive tutorials and documentation to learn more more importantly I look forward to seeing what you build with Caris CV and carp to solve your own practical machine learning problems and deliver real world business impact thank you very [Music] much [Music]
Original Description
Learn how to generate text with KerasNLP. Wei, a Developer Advocate at Google, shares how to fine-tune a Reddit dataset and how you can use the fine-tuned model on-device.
Chapters:
0:00 - Introduction
0:31 - Generate text with a pretrained model
1:53 - Fine-tuning on Reddit dataset
3:04 - On-device running
3:22 - Sampling methods
3:58 - Resources
Resources:
Tutorial → https://goo.gle/3V9iuBf
I/O 2023 workshop → https://goo.gle/3wSd9UN
On-device Large Language Models with Keras and TensorFlow Lite → https://goo.gle/4a2Mpzr
Github → https://goo.gle/3wH7KzT
Samplers → https://goo.gle/3T5NjV6
Watch more Applied ML with KerasCV and KerasNLP → https://goo.gle/AppliedMLwithKeras
Subscribe to the TensorFlow channel → https://goo.gle/TensorFlow
#TensorFlow
Speaker: Wei Wei
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from TensorFlow · TensorFlow · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 TensorFlow YouTube Channel is Here!
TensorFlow
Answering Your TF Questions #AskTensorFlow
TensorFlow
Chatting With the TensorFlow Community (TensorFlow Meets)
TensorFlow
All About TensorFlow Code (Coding TensorFlow)
TensorFlow
TensorFlow: an ML platform for solving impactful and challenging problems
TensorFlow
Keynote (TensorFlow Dev Summit 2018)
TensorFlow
tf.data: Fast, flexible, and easy-to-use input pipelines (TensorFlow Dev Summit 2018)
TensorFlow
Eager Execution (TensorFlow Dev Summit 2018)
TensorFlow
Machine Learning in JavaScript (TensorFlow Dev Summit 2018)
TensorFlow
Training Performance: A user’s guide to converge faster (TensorFlow Dev Summit 2018)
TensorFlow
The Practitioner's Guide with TF High Level APIs (TensorFlow Dev Summit 2018)
TensorFlow
Distributed TensorFlow (TensorFlow Dev Summit 2018)
TensorFlow
Debugging TensorFlow with TensorBoard plugins (TensorFlow Dev Summit 2018)
TensorFlow
TensorFlow Lite (TensorFlow Dev Summit 2018)
TensorFlow
Searching Over Ideas (TensorFlow Dev Summit 2018)
TensorFlow
Reconstructing Fusion Plasmas (TensorFlow Dev Summit 2018)
TensorFlow
Nucleus: TensorFlow toolkit for Genomics (TensorFlow Dev Summit 2018)
TensorFlow
Open Source Collaboration (TensorFlow Dev Summit 2018)
TensorFlow
Swift for TensorFlow - TFiwS (TensorFlow Dev Summit 2018)
TensorFlow
TensorFlow Hub (TensorFlow Dev Summit 2018)
TensorFlow
Applied AI at The Coca-Cola Company (TensorFlow Dev Summit 2018)
TensorFlow
Real-World Robot Learning (TensorFlow Dev Summit 2018)
TensorFlow
TensorFlow Extended (TFX) (TensorFlow Dev Summit 2018)
TensorFlow
Project Magenta (TensorFlow Dev Summit 2018)
TensorFlow
TensorFlow Dev Summit 2018 - Livestream
TensorFlow
Introducing TensorFlow Lite (Coding TensorFlow)
TensorFlow
TensorFlow Dev Summit 2018 Highlights
TensorFlow
Jeff Dean, Head of AI at Google discusses the impact of ML (TensorFlow Meets)
TensorFlow
TensorFlow Mobile vs. TF Lite and More! #AskTensorFlow
TensorFlow
Using TensorFlow to enable research & production across many fields (TensorFlow Meets)
TensorFlow
Teaching TensorFlow for Deep Learning at Stanford University (TensorFlow Meets)
TensorFlow
TensorFlow Lite for Android (Coding TensorFlow)
TensorFlow
Using the tf.data API to build input pipelines (TensorFlow Meets)
TensorFlow
Training Models in the Cloud & the Benefits of AI Toolkits #AskTensorFlow
TensorFlow
Execute operations immediately with TensorFlow's Eager Execution (TensorFlow Meets)
TensorFlow
TensorFlow Lite for iOS (Coding TensorFlow)
TensorFlow
Get started with TensorFlow's High-Level APIs (Google I/O '18)
TensorFlow
TensorFlow for JavaScript (Google I/O '18)
TensorFlow
TensorFlow in production: TF Extended, TF Hub, and TF Serving (Google I/O '18)
TensorFlow
Get started with TensorFlow's High-Level APIs in 5 mins | Google I/O 2018
TensorFlow
TensorFlow and deep reinforcement learning, without a PhD (Google I/O '18)
TensorFlow
TensorFlow Lite for mobile developers (Google I/O '18)
TensorFlow
Advances in machine learning and TensorFlow (Google I/O '18)
TensorFlow
Distributed TensorFlow training (Google I/O '18)
TensorFlow
Classification using neural networks & ML regression models #AskTensorFlow
TensorFlow
TensorFlow and Keras in R - Josh Gordon meets with J.J. Allaire (TensorFlow Meets)
TensorFlow
Focus on your experiment with TensorFlow Estimators (TensorFlow Meets)
TensorFlow
How to get started with AI/ML, retraining models, & more! #AskTensorFlow
TensorFlow
TensorFlow - the deep learning solution for mobile platforms (TensorFlow Meets)
TensorFlow
MiniGo: TensorFlow Meets Andrew Jackson (TensorFlow Meets)
TensorFlow
The growth of TensorFlow with added support for JS & Swift (TensorFlow Meets)
TensorFlow
At the intersection of TensorFlow & nuclear physics (TensorFlow Meets)
TensorFlow
NVidia TensorRT: high-performance deep learning inference accelerator (TensorFlow Meets)
TensorFlow
Try TensorFlow.js in your browser (Coding TensorFlow)
TensorFlow
TensorFlow Hub: reusing machine learning modules (TensorFlow Meets)
TensorFlow
How to use TensorFlow in PyCharm (TensorFlow Tip of the Week)
TensorFlow
Training models faster with TensorFlow Hub (TensorFlow Meets)
TensorFlow
Prepare your dataset for machine learning (Coding TensorFlow)
TensorFlow
Using ML to predict insulin use for Type 1 Diabetes (TensorFlow Meets)
TensorFlow
TFX: an end-to-end machine learning platform for TensorFlow (TensorFlow Meets)
TensorFlow
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
Building Production-Grade LLM Evaluation Pipelines: From Vibes to Metrics
Dev.to AI
Understanding "Handoffs" in LangChain(One Agent, Many Personalities)
Dev.to AI
Building Production-Grade LLM Evaluation Pipelines: From Vibes to Metrics
Dev.to AI
Building Production-Grade LLM Evaluation Pipelines: From Vibes to Metrics
Dev.to · Imus
Chapters (6)
Introduction
0:31
Generate text with a pretrained model
1:53
Fine-tuning on Reddit dataset
3:04
On-device running
3:22
Sampling methods
3:58
Resources
🎓
Tutor Explanation
DeepCamp AI