liveBook · Manning

Logit

As explained in Hugging Face in Action

A logit is an unnormalized model output representing evidence for a class before conversion into normalized probabilities.

Logits are raw, unnormalized model outputs that represent evidence for possible classes before conversion into probabilities. Their values can be compared directly to select the highest-scoring class. section 3.2.3 section 6.2.2

Reading sentiment logits

A sequence-classification model returns logits with shape (1, 2): one batch item and two classes. For [-4.3428, 4.6955], argmax selects class 1, interpreted here as positive sentiment. section 3.2.3

Listing 6.12 Using a multimodal model to simultaneously process visual and textual data
from transformers import CLIPProcessor, CLIPModel

model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")  #1
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

labels = ["cat", "dog", "tiger", "train"]             
inputs = processor(text = labels,  #2
                   images = image,
                   return_tensors = "pt",
                   padding=True)

model.eval()

with torch.no_grad():
    outputs = model(**inputs)  #3

logits_per_image = outputs.logits_per_image  #4

probs = logits_per_image.softmax(dim=1)  #5
most_likely_index = torch.argmax(probs, dim=1).item()  #6
most_likely_object = labels[most_likely_index]

print(f"The most likely object is: {most_likely_object}")

Run a CLIP image-label comparison that extracts logits, applies softmax, and selects the most likely label. section 6.2.2

How Hugging Face in Action covers it

How deep it goes
Defines raw class outputs and demonstrates argmax selection and softmax conversion, without deriving their mathematical foundations.
Examples
Demonstrates sentiment classification and CLIP matching among cat, dog, tiger, and train labels.
What you can do after
Apply via PyTorch and Hugging Face Transformers to inspect logits, select classes, and convert scores into probabilities.
How it connects
Connects logits with class labels, probabilities, softmax, argmax, tokenizers, attention masks, and multimodal models.

Also explained in

Compare how 17 books explain logit →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hugging Face in Action. The section links point to the parts of the book it draws on.