Monash University · FACULTY OF COMPUTER SCIENCE

ECE5179 Chap.12 Vision Transformers, Evaluation and Decoding

- one subject, every graph, every model, every mark
7 Chapters6-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 12 of 12 · ECE5179

Vision Transformers, Evaluation and Decoding

Week 12 applies transformers to images and asks how language models are measured and used. The Vision Transformer cuts an image into patch tokens with a classification token and learns positions, outperforming convolutional networks only with very large data sets.

Perplexity and BLEU quantify a language model and its outputs, and decoding rules such as greedy search, temperature, top-k, top-p and beam search turn next-token probabilities into text.

In this chapter

What this chapter covers

  • 01

    Patch tokens, the classification token and learned positions

  • 02

    ViT variants and the data-scale comparison with ResNet

  • 03

    Linear probing and imageGPT

  • 04

    Perplexity as exponentiated cross-entropy

  • 05

    BLEU: clipped n-gram precision and brevity penalty

  • 06

    Greedy decoding, temperature, top-k and top-p

  • 07

    Beam search and choosing a decoder

Worked example · free

Greedy decoding against a beam of width two

Q [4 marks]. First-step probabilities are a 0.5, the 0.4 and an 0.1. After 'a', the next word is dog with probability 0.6 or cat with 0.3; after 'the', cat 0.8 or dog 0.15. Compare greedy decoding with beam search of width two over two steps. These marks are an AskSia revision weighting, not a published University allocation.
Greedy versus a beam of width two.Greedy versus a beam of width two. Greedy takes “a” (0.5) first and ends on “a dog” with joint probability 0.30; keeping “the” alive finds “the cat” at 0.32.a 0.5the 0.4dog → 0.30cat → 0.15cat → 0.32dog → 0.06best joint
Greedy versus a beam of width two. Greedy takes “a” (0.5) first and ends on “a dog” with joint probability 0.30; keeping “the” alive finds “the cat” at 0.32.
  • 1Greedy takes 'a' (0.5), then 'dog' (0.6), giving joint probability 0.30.
  • 1Beam search keeps 'a' and 'the' after step one.
  • 1Expansions score a dog 0.30, a cat 0.15, the cat 0.32 and the dog 0.06.
  • 1The best two beams are 'the cat' and 'a dog'; the winner is 'the cat' at 0.32.
Greedy decoding returns 'a dog' with probability 0.30, while a beam of width two finds 'the cat' with 0.32, because it kept the weaker first word whose continuation was far more certain.
Sia tip — Score each beam by the product of its conditional probabilities and show every expansion; the final choice alone earns little.
Glossary

Key terms

Patch embedding
A patch embedding maps each flattened image patch to a token vector, usually with a convolution whose stride equals the patch size.
Perplexity
Perplexity is the exponential of the average negative log-likelihood a language model assigns to the true next tokens.
Brevity penalty
The brevity penalty scales BLEU down when a candidate sentence is shorter than its reference.
Top-p sampling
Top-p sampling draws the next token from the smallest set of tokens whose probabilities add up to at least p.
Beam search
Beam search keeps the k most probable partial sequences at each step and expands only those.
FAQ

Vision Transformers, Evaluation and Decoding FAQ

How many tokens does a Vision Transformer read?

For an H by W image and patch size P there are (H/P) times (W/P) patch tokens, plus one classification token. A 224 by 224 image with 16 by 16 patches gives 196 patches and 197 tokens. Halving the patch size quadruples the patches and multiplies the attention table roughly sixteen-fold.

When does a Vision Transformer beat a convolutional network?

In the comparison the lectures present, ViTs trail ResNets when trained on ImageNet alone, draw level with ImageNet-21k, and pull ahead only with JFT-300M. Lacking convolution's built-in locality, a transformer needs much more data to learn it, so pre-trained ViTs are the practical choice for small data sets.

What does a perplexity score mean?

Perplexity is the exponential of the average cross-entropy on the true next tokens, so lower is better and a value of k behaves like choosing among k equally likely words. Scores depend on the data and tokeniser, so values from different data sets cannot be compared directly.

How does temperature change the next-token distribution?

Temperature divides the logits before the softmax. A value below one sharpens the distribution towards the most likely token, approaching greedy decoding, while a value above one flattens it towards uniform and increases variety. For logits 2, 1 and 0, temperature 0.5 gives about 0.87 to the top token and temperature 2 about 0.51.

Why does BLEU need a brevity penalty?

BLEU is built from precisions, which only ask whether the candidate's n-grams appear in the reference. A very short candidate made of safe words can therefore score perfect precision. The brevity penalty multiplies the score by exp(1 − r/c) when the candidate length c is below the reference length r.

What is the classification token in a Vision Transformer?

It is a learnable vector prepended to the sequence of patch tokens. Because it attends to every patch in every layer, its final vector summarises the whole image, and the classifier head reads only that vector to produce the class scores.

Study strategy

Exam move

Count ViT tokens for several image and patch sizes and relate each change to attention cost. Compute perplexity from a short list of token probabilities in both the average-log and product forms. Score one BLEU example fully, listing matched n-grams, clipping and the brevity penalty.

Then practise decoding by hand: temperature on three logits, top-k renormalisation, and a two-step beam search, and write one sentence for each on when you would choose it. Close the unit by linking back: perplexity is the exponential of the cross-entropy from the classification chapter, beam search is a search over the softmax outputs, and a ViT is the attention block from Chapter 10 applied to image patches.

Working through Vision Transformers, Evaluation and Decoding in ECE5179? Sia is AskSia’s AI Computer Science tutor — ask any ECE5179 Vision Transformers, Evaluation and Decoding question and get a clear, step-by-step explanation grounded in how ECE5179 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 161 of your Monash University subjects - and 1,000+ Bibles across every Australian university.
Sia - your ECE5179 tutor, unlimited, worked the way the exam marks it
The full 6-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works
ECE5179 · Neural networks and deep learning - independent study guide on the AskSia Library. More Monash University subjects · Microeconomics across all universities