Generate text with KerasNLP

TensorFlow Official · Beginner ·🧠 Large Language Models ·2y ago

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 The TensorFlow YouTube Channel is Here!
The TensorFlow YouTube Channel is Here!
TensorFlow
2 Answering Your TF Questions #AskTensorFlow
Answering Your TF Questions #AskTensorFlow
TensorFlow
3 Chatting With the TensorFlow Community (TensorFlow Meets)
Chatting With the TensorFlow Community (TensorFlow Meets)
TensorFlow
4 All About TensorFlow Code (Coding TensorFlow)
All About TensorFlow Code (Coding TensorFlow)
TensorFlow
5 TensorFlow: an ML platform for solving impactful and challenging problems
TensorFlow: an ML platform for solving impactful and challenging problems
TensorFlow
6 Keynote (TensorFlow Dev Summit 2018)
Keynote (TensorFlow Dev Summit 2018)
TensorFlow
7 tf.data: Fast, flexible, and easy-to-use input pipelines (TensorFlow Dev Summit 2018)
tf.data: Fast, flexible, and easy-to-use input pipelines (TensorFlow Dev Summit 2018)
TensorFlow
8 Eager Execution (TensorFlow Dev Summit 2018)
Eager Execution (TensorFlow Dev Summit 2018)
TensorFlow
9 Machine Learning in JavaScript (TensorFlow Dev Summit 2018)
Machine Learning in JavaScript (TensorFlow Dev Summit 2018)
TensorFlow
10 Training Performance: A user’s guide to converge faster (TensorFlow Dev Summit 2018)
Training Performance: A user’s guide to converge faster (TensorFlow Dev Summit 2018)
TensorFlow
11 The Practitioner's Guide with TF High Level APIs (TensorFlow Dev Summit 2018)
The Practitioner's Guide with TF High Level APIs (TensorFlow Dev Summit 2018)
TensorFlow
12 Distributed TensorFlow (TensorFlow Dev Summit 2018)
Distributed TensorFlow (TensorFlow Dev Summit 2018)
TensorFlow
13 Debugging TensorFlow with TensorBoard plugins (TensorFlow Dev Summit 2018)
Debugging TensorFlow with TensorBoard plugins (TensorFlow Dev Summit 2018)
TensorFlow
14 TensorFlow Lite (TensorFlow Dev Summit 2018)
TensorFlow Lite (TensorFlow Dev Summit 2018)
TensorFlow
15 Searching Over Ideas (TensorFlow Dev Summit 2018)
Searching Over Ideas (TensorFlow Dev Summit 2018)
TensorFlow
16 Reconstructing Fusion Plasmas (TensorFlow Dev Summit 2018)
Reconstructing Fusion Plasmas (TensorFlow Dev Summit 2018)
TensorFlow
17 Nucleus: TensorFlow toolkit for Genomics (TensorFlow Dev Summit 2018)
Nucleus: TensorFlow toolkit for Genomics (TensorFlow Dev Summit 2018)
TensorFlow
18 Open Source Collaboration (TensorFlow Dev Summit 2018)
Open Source Collaboration (TensorFlow Dev Summit 2018)
TensorFlow
19 Swift for TensorFlow - TFiwS (TensorFlow Dev Summit 2018)
Swift for TensorFlow - TFiwS (TensorFlow Dev Summit 2018)
TensorFlow
20 TensorFlow Hub (TensorFlow Dev Summit 2018)
TensorFlow Hub (TensorFlow Dev Summit 2018)
TensorFlow
21 Applied AI at The Coca-Cola Company (TensorFlow Dev Summit 2018)
Applied AI at The Coca-Cola Company (TensorFlow Dev Summit 2018)
TensorFlow
22 Real-World Robot Learning (TensorFlow Dev Summit 2018)
Real-World Robot Learning (TensorFlow Dev Summit 2018)
TensorFlow
23 TensorFlow Extended (TFX) (TensorFlow Dev Summit 2018)
TensorFlow Extended (TFX) (TensorFlow Dev Summit 2018)
TensorFlow
24 Project Magenta (TensorFlow Dev Summit 2018)
Project Magenta (TensorFlow Dev Summit 2018)
TensorFlow
25 TensorFlow Dev Summit 2018 - Livestream
TensorFlow Dev Summit 2018 - Livestream
TensorFlow
26 Introducing TensorFlow Lite (Coding TensorFlow)
Introducing TensorFlow Lite (Coding TensorFlow)
TensorFlow
27 TensorFlow Dev Summit 2018 Highlights
TensorFlow Dev Summit 2018 Highlights
TensorFlow
28 Jeff Dean, Head of AI at Google discusses the impact of ML (TensorFlow Meets)
Jeff Dean, Head of AI at Google discusses the impact of ML (TensorFlow Meets)
TensorFlow
29 TensorFlow Mobile vs. TF Lite and More! #AskTensorFlow
TensorFlow Mobile vs. TF Lite and More! #AskTensorFlow
TensorFlow
30 Using TensorFlow to enable research & production across many fields (TensorFlow Meets)
Using TensorFlow to enable research & production across many fields (TensorFlow Meets)
TensorFlow
31 Teaching TensorFlow for Deep Learning at Stanford University (TensorFlow Meets)
Teaching TensorFlow for Deep Learning at Stanford University (TensorFlow Meets)
TensorFlow
32 TensorFlow Lite for Android (Coding TensorFlow)
TensorFlow Lite for Android (Coding TensorFlow)
TensorFlow
33 Using the tf.data API to build input pipelines (TensorFlow Meets)
Using the tf.data API to build input pipelines (TensorFlow Meets)
TensorFlow
34 Training Models in the Cloud & the Benefits of AI Toolkits #AskTensorFlow
Training Models in the Cloud & the Benefits of AI Toolkits #AskTensorFlow
TensorFlow
35 Execute operations immediately with TensorFlow's Eager Execution (TensorFlow Meets)
Execute operations immediately with TensorFlow's Eager Execution (TensorFlow Meets)
TensorFlow
36 TensorFlow Lite for iOS (Coding TensorFlow)
TensorFlow Lite for iOS (Coding TensorFlow)
TensorFlow
37 Get started with TensorFlow's High-Level APIs (Google I/O '18)
Get started with TensorFlow's High-Level APIs (Google I/O '18)
TensorFlow
38 TensorFlow for JavaScript (Google I/O '18)
TensorFlow for JavaScript (Google I/O '18)
TensorFlow
39 TensorFlow in production: TF Extended, TF Hub, and TF Serving (Google I/O '18)
TensorFlow in production: TF Extended, TF Hub, and TF Serving (Google I/O '18)
TensorFlow
40 Get started with TensorFlow's High-Level APIs in 5 mins |  Google I/O 2018
Get started with TensorFlow's High-Level APIs in 5 mins | Google I/O 2018
TensorFlow
41 TensorFlow and deep reinforcement learning, without a PhD (Google I/O '18)
TensorFlow and deep reinforcement learning, without a PhD (Google I/O '18)
TensorFlow
42 TensorFlow Lite for mobile developers (Google I/O '18)
TensorFlow Lite for mobile developers (Google I/O '18)
TensorFlow
43 Advances in machine learning and TensorFlow (Google I/O '18)
Advances in machine learning and TensorFlow (Google I/O '18)
TensorFlow
44 Distributed TensorFlow training (Google I/O '18)
Distributed TensorFlow training (Google I/O '18)
TensorFlow
45 Classification using neural networks & ML regression models #AskTensorFlow
Classification using neural networks & ML regression models #AskTensorFlow
TensorFlow
46 TensorFlow and Keras in R - Josh Gordon meets with J.J. Allaire (TensorFlow Meets)
TensorFlow and Keras in R - Josh Gordon meets with J.J. Allaire (TensorFlow Meets)
TensorFlow
47 Focus on your experiment with TensorFlow Estimators (TensorFlow Meets)
Focus on your experiment with TensorFlow Estimators (TensorFlow Meets)
TensorFlow
48 How to get started with AI/ML, retraining models, & more! #AskTensorFlow
How to get started with AI/ML, retraining models, & more! #AskTensorFlow
TensorFlow
49 TensorFlow - the deep learning solution for mobile platforms (TensorFlow Meets)
TensorFlow - the deep learning solution for mobile platforms (TensorFlow Meets)
TensorFlow
50 MiniGo: TensorFlow Meets Andrew Jackson (TensorFlow Meets)
MiniGo: TensorFlow Meets Andrew Jackson (TensorFlow Meets)
TensorFlow
51 The growth of TensorFlow with added support for JS & Swift (TensorFlow Meets)
The growth of TensorFlow with added support for JS & Swift (TensorFlow Meets)
TensorFlow
52 At the intersection of TensorFlow & nuclear physics (TensorFlow Meets)
At the intersection of TensorFlow & nuclear physics (TensorFlow Meets)
TensorFlow
53 NVidia TensorRT: high-performance deep learning inference accelerator (TensorFlow Meets)
NVidia TensorRT: high-performance deep learning inference accelerator (TensorFlow Meets)
TensorFlow
54 Try TensorFlow.js in your browser (Coding TensorFlow)
Try TensorFlow.js in your browser (Coding TensorFlow)
TensorFlow
55 TensorFlow Hub: reusing machine learning modules (TensorFlow Meets)
TensorFlow Hub: reusing machine learning modules (TensorFlow Meets)
TensorFlow
56 How to use TensorFlow in PyCharm (TensorFlow Tip of the Week)
How to use TensorFlow in PyCharm (TensorFlow Tip of the Week)
TensorFlow
57 Training models faster with TensorFlow Hub (TensorFlow Meets)
Training models faster with TensorFlow Hub (TensorFlow Meets)
TensorFlow
58 Prepare your dataset for machine learning (Coding TensorFlow)
Prepare your dataset for machine learning (Coding TensorFlow)
TensorFlow
59 Using ML to predict insulin use for Type 1 Diabetes (TensorFlow Meets)
Using ML to predict insulin use for Type 1 Diabetes (TensorFlow Meets)
TensorFlow
60 TFX: an end-to-end machine learning platform for TensorFlow (TensorFlow Meets)
TFX: an end-to-end machine learning platform for TensorFlow (TensorFlow Meets)
TensorFlow

This video teaches how to use KerasNLP to generate text with pre-trained models and fine-tune them for specific writing styles, allowing users to create custom language models for various applications.

Key Takeaways
  1. Load a pre-trained model like GPT2 using KerasNLP
  2. Generate text using the pre-trained model
  3. Prepare a custom dataset like the Reddit dataset for fine-tuning
  4. Fine-tune the pre-trained model on the custom dataset
  5. Use the fine-tuned model to generate text in the desired writing style
  6. Explore different sampling methods like greedy search, topk sampling, and beam search
💡 Fine-tuning pre-trained language models on custom datasets can significantly improve the quality and relevance of generated text for specific applications or writing styles.

Related Reads

📰
Building Production-Grade LLM Evaluation Pipelines: From Vibes to Metrics
Learn to build production-grade LLM evaluation pipelines to catch hallucinations before deployment and improve model reliability
Dev.to AI
📰
Understanding "Handoffs" in LangChain(One Agent, Many Personalities)
Learn to implement 'handoffs' in LangChain to make a single agent behave differently in various conversation stages
Dev.to AI
📰
Building Production-Grade LLM Evaluation Pipelines: From Vibes to Metrics
Learn to build production-grade LLM evaluation pipelines to catch hallucinations before deployment, replacing manual 'vibe checks' with automated metrics
Dev.to AI
📰
Building Production-Grade LLM Evaluation Pipelines: From Vibes to Metrics
Learn to build production-grade LLM evaluation pipelines, replacing subjective 'vibes' with quantitative 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
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →