Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-257

BEiT Tokenizer Target

Problem

Map a patch's RGB values to the nearest codebook entry by squared Euclidean distance and return its index, breaking ties by the smaller index.

The signature is beit_tokenizer_target(patch_rgb, codebook). Return the codebook index.

Hint

BEiT predicts discrete visual tokens from a frozen dVAE tokenizer instead of raw pixels.

Test cases

case 1
in: [[1,0],[[1,0],[0,1],[0.5,0.5]]]
expected: 0
case 2
in: [[0,1],[[1,0],[0,1],[0.5,0.5]]]
expected: 1
case 3
in: [[0.4,0.6],[[1,0],[0,1],[0.5,0.5]]]
expected: 2
case 4
in: [[0.6,0.4],[[1,0],[0,1]]]
expected: 0
Starter codePython
def beit_tokenizer_target(patch_rgb, codebook):
    # Your code here
    pass

4 test cases · run your code against them in the editor