1. Hugging Face model navigation
Hi! Welcome to the course!
2. Meet your instructor...
I'm James, a Curriculum Manager here at DataCamp. This course was created in collaboration with Sean Benson, an applied AI researcher at the Amsterdam University Medical Center, and he focuses on multi-modal AI for personalized medicine. Let's get started!
3. Modalities covered
In this course, we'll learn how to use Hugging Face models to build applications using multiple data modalities, including text, images, audio, and video.
4. Hugging Face
Hugging Face provides access to over a million AI models, and more than a quarter of a million datasets, primarily used for training and refining models.
5. The Hub API
As well as navigating the Hub in the browser, we can access Hugging Face models and datasets via their API, installed with the huggingface_hub library.
Adding the command line interface by specifying "cli" in the install gives us quick access to the models in our account after performing the login step.
Throughout this course, the necessary libraries, models, and datasets will already be installed and available for you to use.
6. Searching for models
So how do we find the best model for us amongst the millions available on Hugging Face? We can search this vast collection using the Hugging Face API.
We import the HfApi class from huggingface_hub, and create an instance called api. We can then call the .list_models() method on api to return models based on different criteria.
We can retrieve models for a specific task and order by categories like popularity or number of downloads with the sort keyword. The limit keyword is useful to cap the number of models returned, and tags allows us to search on parameters specific to the model type.
Let's see an example.
7. Searching for models
We can search for text-to-image models from the author "CompVis".
CompVis is known for developing Stable Diffusion, a groundbreaking text-to-image model. The diffusers:StableDiffusionPipeline tag allows us to filter only the models that can be loaded with the diffusers Hugging Face library, which we'll use later in the course.
Finally, we'll sort by the number of downloads.
Casting the result to a list and subsetting the first element, we can see a ModelInfo object containing metadata about the most-downloaded Stable Diffusion model. This metadata contains information such as whether the model is private or public, the number of downloads and likes, the name of the code library needed to load it, and much more.
8. Using models from the API
From these ModelInfo objects, we can extract metadata like the model ID, using the .id attribute.
This can then be used directly in Hugging Face pipelines.
9. Available tasks
The number of tasks covered by models in Hugging Face is constantly increasing. To keep track of the possibilities, we can either check the webpage, or retrieve the information from this URL using code.
We open a with statement, call urlopen() on the url to retrieve the data, then load the JSON and assign it to the tasks variable.
Printing the keys shows the unique tasks currently available on Hugging Face.
10. Let's practice!
Let's see what models we can find in the exercises!