Chapter 1 of 4 · 12 min
Introduction to language models
A language model predicts the next token given the tokens before it. Everything else — chat, summarisation, code completion — is built on top of that single objective.
In this chapter you will load a small model from HubClone, generate text with it and look at the probabilities it assigns to candidate tokens.
Your first generation
Install the client library, then load a model by its repository id.
from transformers import pipeline
gen = pipeline("text-generation", model="openai-community/gpt2")
print(gen("The best thing about open models is", max_new_tokens=20))