10/29
Part 3 of 6 · Top-kLearn and do

Each row needs its own threshold, as a column

In a batch, every row has its own k-th largest score.

rows = torch.tensor([[0.3, 2.0, -1.0, 1.5, 0.0],
                     [5.0, 1.0, 4.0, 3.0, 2.0],
                     [-2.0, -1.0, 0.5, -3.0, 1.0]])
print(torch.topk(rows, 2, dim=-1).values[..., -1:])
print(torch.topk(rows, 2, dim=-1).values[..., -1])
Predict

Each row's 2nd largest value is its threshold. What shapes are values[..., -1:] and values[..., -1]?

Pick one to see what it prints.
Pick an answer above to see the rest