AI tools

What is Hugging Face, and how do you try models there?

· By Robert Scales · 4 min read

Short answer

Hugging Face runs the Hub, a free website where people share machine learning models, datasets and demo apps, with more than 50,000 models so far. You can try many models right in your browser: open a model's page, read its model card, and type into the small test box, called an inference widget, without installing anything.

If GPT-3 is a single powerful model you reach through one company's API, Hugging Face is closer to a public library of models. The company runs the Hugging Face Hub, a website where researchers, companies and hobbyists publish their models and datasets for others to download, study and use. Its documentation counts more than 50,000 models, 5,000 datasets and 5,000 demos, covering text, images and audio.

For a beginner, the Hub is the easiest place to see what many different models can do. Plenty of them can be tried in a web browser in seconds, with no code at all.

What you find on the Hub

Everything on the Hub lives in a repository, a folder of files with a full version history, like a project on GitHub. There are three kinds:

  • Models: the trained files themselves, ready to download, along with instructions for using them, often with the company's open-source Transformers library.
  • Datasets: collections of text, images or audio used to train and test models, each described by a dataset card.
  • Spaces: small interactive apps that demonstrate a model in the browser.

Each model page is built around a model card, a description written by the model's authors. A good card tells you what the model does, what data it learned from, how well it scored on tests, and what its limitations and biases are. Pages also carry tags for the task (translation, summarization, text classification and so on), the languages and the license, which makes searching easier.

Many model pages also include an inference widget: a small box where you type an input and the Hub runs the model for you on its own servers and shows the output. For production use the Hub also offers an API, but the widget is enough to explore.

A worked example: an English-to-French model

Here is a complete walk-through with a real model, Helsinki-NLP/opus-mt-en-fr, published by the Helsinki-NLP research group.

  1. Go to huggingface.co and click Models.
  2. In the task filters on the left, choose Translation, then type en-fr in the search box.
  3. Open Helsinki-NLP/opus-mt-en-fr.
  4. Read the model card. It is short: source language English, target language French, trained on OPUS (a large public collection of translated texts), with the model type and the date of the original weights.
  5. Look at the benchmark table. It lists BLEU scores, a common automatic measure of how close a translation is to a human reference, on several test sets. The scores range from about 27.5 on one news test to 50.5 on Tatoeba, a set of short everyday sentences. That spread is itself useful information: the model is stronger on simple sentences than on news writing.
  6. Find the Hosted inference API box on the right and type a sentence, for example:
Prompt
The library will be closed on Monday, but you can return books in the drop box.
  1. Click Compute. The model is loaded on demand, so the first request may take a little longer; then the French translation appears. You can also view the raw output as JSON, the data format a program would receive.

Try a harder sentence afterwards, with an idiom or a long, technical clause, and compare. You will quickly get a feel for where a dedicated translation model is reliable and where it struggles.

The same page also shows how many times the model was downloaded in the last month (more than 600,000 in early July) and which Spaces use it.

Try it: Pick a task you care about, such as summarization or sentiment analysis, filter the Hub by that task, and test the same three inputs on two different models. Note which one gives better results and what each model card says about its training data.

What is a Space?

A Space is a small web app hosted on the Hub that lets anyone try a model through a friendly interface. Where the inference widget offers a plain text box, a Space can have buttons, sliders, image uploads and several steps. People use Spaces to build a portfolio, show a project at a conference or share a research demo with colleagues.

Under the hood, a Space is a repository like any other on the Hub. Its creator writes a short Python program using one of two libraries: Gradio, which makes it quick to wrap a model in a simple input-and-output interface, or Streamlit, which allows more complete web apps. A Space can also be a plain HTML page. Extra Python packages are listed in a requirements.txt file, and the Hub builds the environment automatically. Each Space runs with up to 16 GB of memory and 8 CPU cores, and some paying organizations can request a GPU.

To explore, click Spaces at the top of the Hub and browse. On a model page, the "Spaces using this model" list leads straight to demos built on it, which is a good way to see a model inside a real application. If you build one yourself later, the Spaces documentation recommends keeping private keys in the Space's settings rather than writing them into the code.

Sources

  1. Hugging Face Hub documentation (archived 24 June 2022) — Hugging Face, June 24, 2022
  2. Helsinki-NLP/opus-mt-en-fr model page (archived 4 July 2022) — Hugging Face / Helsinki-NLP, July 4, 2022
  3. Spaces (Hugging Face Hub documentation, archived 25 May 2022) — Hugging Face, May 25, 2022

Get the free Guide to Artificial Intelligence

Sign up for the weekly newsletter and receive the free guide: what changed in AI this week, one lesson, one prompt to try. Unsubscribe in one click.

How we handle your address

Back to top

Display

Your choices are saved in this browser only. No data is sent.

Text size
100%
Colours
Reading
More settings
Accessibility statement