From the course: Python for Data Science and Machine Learning Essential Training Part 2
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Coding demo: Implementing a generative AI model - Python Tutorial
From the course: Python for Data Science and Machine Learning Essential Training Part 2
Coding demo: Implementing a generative AI model
Quick note before we start coding. This is a conceptual or sampler and not a full modern LLM app built. We're going to use a simplified hugging basic sample to understand the mechanics of text generation end-to-end. In production today, you'll often use instruction tuned chat models and add components like retrieval. But the core ideas you'll learn here still apply. In this demo, I'm going to show you how to use a pre-trained model from the HuggingFaceTransformers library in order to generate text. This is actually a pretty straightforward process as you're about to see, but let me start by explaining a few of the key features that make it work. The tokenizer we're going to use is going to convert the input text to a format that the model understands, and then the generate function parameters like max length, then numBeams or number of beams, as well as noRepeat and gramSize. These all controls the length and creativity of…