esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

AI engineering / Core / 02.07

Hugging Face Tasks

Many jobs do not need a big chat model. Small ready-made models, grouped by task, can do one thing each, and a pipeline runs them in a few lines.

14 min readFree

One job, one small model

The last lesson, Running models locally, ended with a promise: next, Hugging Face tasks, ready-made models for everyday jobs. Here it is.

Think of a kitchen. A chef's knife can chop, slice, peel and carve. But if you only peel potatoes all day, a small peeler is quicker, cheaper and easier to hand to a new cook. A big chat model is the chef's knife. A task model is the peeler.

By the end you will know what a task is, where to find models grouped by task, how a pipeline runs one in a few lines, how the same idea works in JavaScript, and how to decide between a small task model and a chat model. You will also run a small program of your own.

Key words

Task
One clear job a model does, such as sorting reviews into good and bad, or turning speech into text.
Task model
A model trained to do one task. It does not chat. You give it an input and it gives back a fixed kind of answer.
Pipeline
A ready-made helper that wraps a model together with the steps before and after it, so you call one function.
Label and score
The usual answer of a sorting model: the group it picked (the label) and how sure it is, as a number (the score).
Zero-shot
Sorting text into groups the model was never trained on, because you hand it the group names when you ask.
Named entity
A name of a real thing in a text, such as a person, a place or a company.
Inference
Using a trained model to get an answer. Training builds the model. Inference uses it.

The task view of AI

Most people meet AI as a chat box. You type, it answers. So it is easy to think every AI job needs a big chat model.

Look at what products actually ask. Is this review happy or angry? Which words in this email are names? What does this audio say? Which language is this? Each one is a single, narrow job with a small, fixed kind of answer. A label. A list of names. A line of text.

A model trained for just one of these jobs can be much smaller than a chat model. Smaller usually means it loads quicker, answers quicker and costs less to run. It also tends to answer in the same shape every time, which is easier to build on. The tasks pages give no timing or cost numbers, so treat this as a rule of thumb, and measure on your own data before you rely on it.

The earlier lesson Hugging Face showed where such models live and how to read a model page. This lesson is about picking them by the job they do.

The Tasks pages

Hugging Face keeps a page called Tasks. Its opening line says: "Hugging Face is the home for all Machine Learning tasks." For each task it offers demos, use cases, models and datasets.

The page groups tasks under six headings. You do not need to learn them all. Just know the map.

  • Language

    Under Natural Language Processing you find text classification, token classification, zero-shot classification, summarization, translation, question answering and more.

  • Pictures and sound

    Computer Vision has image classification, object detection and image segmentation. Audio has automatic speech recognition and text-to-speech.

  • The rest

    Multimodal (models that mix text, images or audio), Tabular (rows and columns, like a spreadsheet) and Reinforcement Learning.

Seven everyday jobs

These seven jobs cover a lot of real products. For each one, the Tasks pages describe what goes in and what comes out.

  1. 1

    Sentiment (text classification)

    Input: a review. Output: a label such as POSITIVE or NEGATIVE, and a score. Use it to sort feedback.

  2. 2

    Summarization

    The Summarization page defines it as "producing a shorter version of a document while preserving its important information". It adds that some models extract text from the original and others generate entirely new text.

  3. 3

    Translation

    Input: text in one language. Output: text in another.

  4. 4

    Named entities (token classification)

    The Token Classification page says NER models "could be trained to identify specific entities in a text, such as dates, individuals and places". Its example labels "Omar" as a person and "Zürich" as a place. Use it to pull names out of invoices or emails.

  5. 5

    Zero-shot classification

    The page describes it as predicting "a class that wasn't seen by the model during training". You pass the text and a list of candidate labels, and get a score for each.

  6. 6

    Image classification

    Input: a picture. Output: a list of labels with scores.

  7. 7

    Speech recognition

    Input: audio. Output: the words that were spoken, as text.

Notice the shape. Every job has an input type and an answer type. A chat model can do all seven, but it answers in free text. A task model answers in the shape the task defines. When you build a product, that fixed shape is a gift.

The pipeline idea

A model does not take raw text. Something has to turn your sentence into numbers first, and something has to turn the model's numbers back into words or labels. The earlier lesson Tokenization, in Machine Learning Foundations, goes deeper on the first part.

A pipeline hides all of that. The Transformers documentation calls the Pipeline "a simple but powerful inference API that is readily available for a variety of machine learning tasks with any model from the Hugging Face Hub". Transformers is the Hugging Face Python library for using models.

You choose a task with the task identifier. The docs say you load a pipeline "by setting the task identifier in the `task` parameter". They also say "each task is configured to use a default pretrained model and preprocessor, but this can be overridden with the `model` parameter if you want to use a different model".

Here is a snippet from those docs. It is a speech recognition pipeline. Read it as text. It was not run here, because it needs a real model download.

Text
# From the Transformers documentation (Pipeline), shown without its output (not run here)
from transformers import pipeline

pipeline = pipeline(task="automatic-speech-recognition", model="openai/whisper-large-v3")
pipeline("https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac")

Two lines do the whole job. The first picks the task and the model. The second hands over an audio file and gets text back. That is the pipeline idea: pick a task, get a function.

The docs also show that sorting tasks return a list of dictionaries, each with a label and a score. Keep that shape in your head, because the next section builds it yourself.

Try it: a stand-in task model

Let's build the same shape, free and offline. The code below is a stand-in. It is not a real task model. It counts happy words and unhappy words from two short lists, and has never learned anything.

It has the same outside shape as the docs describe: you call `pipeline("sentiment-analysis")`, you get a function, and you call it with text to get back a list holding a label and a score. A real model is trained on many examples, so it can read tone and context. A real one needs a download, is slower than a word list, can give a different answer from run to run, and can fail on text it has never seen. Do not mistake this stand-in for one.

We run it on six made-up reviews. Each has a hand label, the answer a person would give. At the end, the code counts how many it got right.

Python
import re

POSITIVE = {"love", "great", "fast", "easy", "helpful", "perfect", "good"}
NEGATIVE = {"broken", "slow", "late", "refund", "bad", "terrible", "disappointed"}

def pipeline(task):
    """A stand-in for a ready-made task model. Word lists, no learning."""
    if task != "sentiment-analysis":
        raise ValueError("this stand-in only knows sentiment-analysis")

    def run(text):
        words = re.findall(r"[a-z']+", text.lower())
        pos = sum(w in POSITIVE for w in words)
        neg = sum(w in NEGATIVE for w in words)
        if pos == neg:
            return [{"label": "NEGATIVE", "score": 0.5}]
        label = "POSITIVE" if pos > neg else "NEGATIVE"
        score = round(max(pos, neg) / (pos + neg), 2)
        return [{"label": label, "score": score}]

    return run

reviews = [
    ("Great app, fast and easy to use", "POSITIVE"),
    ("The parcel came late and the box was broken", "NEGATIVE"),
    ("I love the new design, very helpful", "POSITIVE"),
    ("Terrible support, I want a refund", "NEGATIVE"),
    ("Not bad at all, I was pleasantly surprised", "POSITIVE"),
    ("Good idea but slow and buggy", "NEGATIVE"),
]

pipe = pipeline("sentiment-analysis")
right = 0
for text, truth in reviews:
    out = pipe(text)
    ok = out[0]["label"] == truth
    right += ok
    print(out, "ok" if ok else "WRONG", "|", text)
print(right, "of", len(reviews), "right:", round(100 * right / len(reviews)), "percent")

Output

[{'label': 'POSITIVE', 'score': 1.0}] ok | Great app, fast and easy to use
[{'label': 'NEGATIVE', 'score': 1.0}] ok | The parcel came late and the box was broken
[{'label': 'POSITIVE', 'score': 1.0}] ok | I love the new design, very helpful
[{'label': 'NEGATIVE', 'score': 1.0}] ok | Terrible support, I want a refund
[{'label': 'NEGATIVE', 'score': 1.0}] WRONG | Not bad at all, I was pleasantly surprised
[{'label': 'NEGATIVE', 'score': 0.5}] ok | Good idea but slow and buggy
5 of 6 right: 83 percent

It got 5 of 6 right, which is 83 percent. The scores are all 1.0 or 0.5 because we only count words, so the score here is just how one-sided the count was. A real model's score comes from its training, and says how sure it is. Do not trust a high score on its own: our stand-in gave 1.0 on a wrong answer.

Look at the one miss. "Not bad at all, I was pleasantly surprised" is a happy review. But our stand-in saw the word "bad" and stopped there. It cannot read "not bad" as a pair. That is the gap between a word list and a trained model. The trained model has seen many sentences like it.

Also notice "Good idea but slow and buggy". It had one happy word, one unhappy word, and "buggy" was not in our list. The code broke the tie by guessing NEGATIVE with a score of 0.5, which happened to match the hand label. Luck, not skill.

accuracy=answers that match the hand labelsall answers=56≈0.83\text{accuracy} = \frac{\text{answers that match the hand labels}}{\text{all answers}} = \frac{5}{6} \approx 0.83

In words: accuracy is the share of answers that were right. Five right out of six is about 83 percent. Six reviews is far too few to trust. A real test uses hundreds of reviews that your own users wrote.

Quick check

Why did the stand-in get "Not bad at all, I was pleasantly surprised" wrong?

The same idea in JavaScript

Many AI products are web apps, so you may want this in JavaScript. Transformers.js is a library for that. Its docs say: "Run 🤗 Transformers directly in your browser, with no need for a server!"

The docs say it "is designed to be functionally equivalent to Hugging Face's transformers python library, meaning you can run the same pretrained models using a very similar API". It uses ONNX Runtime to run models in the browser. A runtime is the program that runs a model file.

Here is the quick tour from the docs. The first block is Python, the second is JavaScript. Read them side by side. Neither was run here.

Text
# From the Transformers.js docs (Quick tour), shown without its output (not run here)
from transformers import pipeline

# Allocate a pipeline for sentiment-analysis
pipe = pipeline('sentiment-analysis')

out = pipe('I love transformers!')
Text
# From the Transformers.js docs (Quick tour), shown without its output (not run here)
import { pipeline } from '@huggingface/transformers';

// Allocate a pipeline for sentiment-analysis
const pipe = await pipeline('sentiment-analysis');

const out = await pipe('I love transformers!');

Same task name, same two steps. Only the language changes. The docs add that you can pass a model id as the second argument to use a different model. They also say that in the browser the model runs on your CPU by default (through WASM), and that you can ask for your GPU by setting `device: 'webgpu'`. WASM is a way to run fast compiled code inside a web page.

The docs list the kinds of jobs it supports: text classification, named entity recognition, question answering, summarization and translation, image classification, automatic speech recognition and more. Not every task is supported. Check the supported-tasks table in the docs before you plan around one.

  • In the browser

    The docs say there is no need for a server. The cost is that the visitor's device does the work, and the model has to reach it first.

  • In Python

    The Transformers library, with the same task names.

  • In JavaScript

    Transformers.js, with a very similar API, so what you learn carries over.

Tip

A model that runs in the browser has to be downloaded by every new visitor. Test it on a slow phone connection before you ship it.

Task model or chat model?

Now the real question for a builder. Which one do you reach for?

Take a made-up example. A shop gets 10,000 reviews a day and wants each tagged positive or negative. Say a chat model call costs 1 unit per review and a small task model costs 0.1 unit. Those numbers are made up, to show the shape of the sum. At 10,000 reviews, the chat model costs 10,000 units a day and the task model costs 1,000. Real prices change often, so look them up when you plan.

A task model tends to win when these things are true.

  • The job is narrow

    One clear input, one fixed kind of answer, such as a label, a list of names or a transcript.

  • You have volume

    Thousands of calls, where a small saving on each one adds up.

  • You want the same answer shape every time

    A label from a fixed list is much easier to build on than a paragraph of free text.

A chat model tends to win when the job is wide or fuzzy. Here is how the two compare.

Text
Question                                      Pick
--------------------------------------------  ----------------------
One narrow job, high volume                   task model
Answer must come from a fixed list of labels  task model
Must run offline or on the user's device      task model
Many different jobs behind one box            chat model
The job changes every week, no training data  chat model
Needs long, flowing writing or reasoning      chat model

Zero-shot classification sits in the middle. The Tasks page says the effectiveness of a zero-shot model "seems to scale with model size", with larger models generally doing better. So if you need labels you can change without retraining, a zero-shot model is handy. But a small one may be less sure than a bigger one.

You can also combine them. Let a small task model sort 10,000 reviews, then send only the angry ones to a chat model to write a reply. That keeps the expensive call for where it helps.

Quick check

You must tag 50,000 support emails a day as billing, bug or other, using the same three labels every time. What is the best first thing to try?

What to remember

  • Think in jobs

    Write the job as one sentence. If it is narrow, look for a task model before you reach for a chat model.

  • Pipelines make it short

    Pick a task name and get a function. The same idea works in Python and in JavaScript with Transformers.js.

  • Test, then choose

    Compare on your own examples, and compare real costs when you plan. Small is not always better, and big is not always needed.

Next: embedding models, choosing the model that turns text into vectors.

Sources

How is this lesson?

Last updated on 16 November 2026

Learn with me

Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.