All problems
Transformer Policy Context
Problem
Count the number of context windows of a given window size with a given overlap.
stride = window - overlap; return 0 for degenerate inputs, 1 when the sequence fits in one window, otherwise ceil((seq_len - window) / stride) + 1.
Hint
Overlapping windows let the transformer attend across context boundaries.
Test cases
case 1
in: [100,20,0]
expected: 5
case 2
in: [100,20,10]
expected: 9
case 3
in: [15,20,0]
expected: 1
case 4
in: [21,20,10]
expected: 2
Starter codePython
import math
def transformer_context_windows(seq_len, window, overlap):
# Your code here
pass4 test cases · run your code against them in the editor