AI Hints
Home›Fine-Tuning LLMs Tutorial›Setup, the Hub and pipeline()
Fine-Tuning LLMs · Lesson 9 of 120

Your First Model: pipeline()

Text in, text out.

⏱ 2 min read▶ Video at 13:43🎓 Free
Watch this lesson in the Fine-Tuning LLMs courseWatch on YouTube ↗Full Fine-Tuning LLMs course

The quickest way to use a model is the pipeline function. One line loads the model. One more line uses it. Let's try it.

  • The quickest way
  • One line to load
  • One line to use

Generate some text

We create a text generation pipeline, with our small model. Then we give it the start of a sentence. Max new tokens says how many tokens to add. Do sample equals false means always pick the most likely token. Run it. It finished our sentence, sensibly. But then it started repeating itself. This is a base model. It only continues text. It doesn't know when to stop.

app.pypython
from transformers import pipeline

generator = pipeline("text-generation", model="HuggingFaceTB/SmolLM2-135M")
result = generator("The best thing about a small bookshop is",
                   max_new_tokens=25, do_sample=False)
print(result[0]["generated_text"])
Output
The best thing about a small bookshop is that you can get a lot of books in a small
space.

The best thing about a small bookshop is that

What pipeline does for you

Pipeline hides three steps. First, the tokenizer turns your text into token IDs, which are numbers. Then the model predicts new tokens, one at a time. Finally, the tokenizer turns the new token IDs back into text. In the next lessons, we'll do each step ourselves.

  1. Tokenizetext → token IDs
  2. Modelpredict new tokens
  3. Decodetoken IDs → text

Summary

Let's recap. Pipeline loads a model in one line. Max new tokens limits the length. And a base model just continues text. Inside, pipeline tokenizes, runs the model, and decodes. Next, a closer look at tokenizers.

Key takeaways
  • pipeline()
  • max_new_tokens
  • Tokenize, model, decode
Next up: Tokenizers — text becomes numbers