How To Use Hugging Face 🤗 Hub to Select a Model

Nicole Hall
5 min readMar 19, 2024

--

Navigating the vast universe of open-source models can be daunting. New models are released every week to the Hugging Face Hub. Hugging Face is an open platform that houses models, datasets, and machine learning demos. But how do you sift through the thousands of available models to find the perfect one for your project? In this post, I’ll show you how to use Hugging Face Hub to find the best fit for your project. Follow these steps to efficiently locate and choose a model that meets your specific needs.

  1. Begin your search by identifying what task you’re working on in machine learning terms. Let’s say you want to do automatic speech recognition. Start by clearly defining the machine learning task you’re working on. Understanding your task in machine learning terms is crucial for narrowing down your search. The Hugging Face Hub categorizes models based on tasks, making it easier to find models suited to your project.
Use the library of tasks in the left panel to begin to narrow your search.

2. Once you’ve identified your task, head to the Hugging Face Hub and choose it from the options available on the left side panel. This filters the models to those relevant to your chosen task.

Click the task, see the models.

3. Even after selecting a task, you might still find a wide array of models. There are over half a million models in the example above. You can further narrow your search by specifying additional criteria such as the language. In the example below, I’ve narrowed the search to models that transcribe speech in Spanish, which limits the results to 2,686 models.

4. Next you want to select a license that you are actually allowed to use. To determine if a license is permissive on the Hugging Face Hub, you would typically check the model card or the model’s page for its licensing information. A permissive license, in this context, means it allows broad use of the model, including for commercial purposes, with minimal restrictions. Common examples of permissive licenses include MIT, Apache 2.0, and BSD. These licenses are explicitly stated in the model’s documentation or model card on the Hugging Face Hub. If the model card or documentation specifies one of these or a similarly unrestricted license, it’s considered permissive.

5. Now that you know what you’re after, it’s helpful to sort the models. Hugging Face Hub allows you to sort the filtered models by downloads or trending. This way you can discover models that have recently gained popularity or attention within the machine learning community. This could be due to their performance on specific tasks surpassing that of existing models, their introduction of innovative techniques or architectures, or their applicability to current challenges in machine learning. This step helps you find models that are widely used or currently catching the community’s interest.

6. Before settling on a model, review its model card. A well-written model card is like a readme file for a model. It contains a lot of useful information, such as the model’s architecture, how it was trained, and what limitations it has. As you can see below, models can have checkpoints with varying number of parameters. So we say that this type of model comes in different sizes. Checkpoint refers to the saved model, including the pre-trained weights and all the necessary configurations. We often say we load a model, but technically speaking, we load a model checkpoint.

7. Some checkpoints have millions of parameters, others have a billion or a few billions of parameters. Depending on your hardware, you may not be able to run the largest checkpoints. To estimate how much memory will be needed for a model, navigate to files and versions. Find a file called pytorch_model.bin. This file stores the trained weights of the model so you can easily see its size. Add 20% on top. And this is approximately how much memory you’ll need to run this model.

8. To load this model from the Hugging Face Hub, you can use the Transformers library. Click the Use in Transformers button to get code snippets showing how to load the model checkpoint in your project. The code snippet references the pipeline object. The pipeline object simplifies preparing the data in the way the model can work with. For instance, it might change sound recordings into a special format known as a log Mel spectrogram (the Mel scale is designed to mimic the human ear’s response to different frequencies) for audio models. For text, the pipeline turns words into tokens, which are small chunks the model can understand. For pictures, the pipeline checks that they are the right size and look consistent before the model sees them. You don’t need to do any of these preprocessing steps by hand.

By following these steps, you can navigate the Hugging Face Hub to find a model that not only suits your project’s needs but is also compatible with your hardware and licensing requirements. Go build something great.

--

--

Nicole Hall

These posts are meant to share what I'm learning. I've learned a ton from Medium posts. I'm here to help others, even if it's just by way of encouragement ❤️️