InferenceAI

Enter at least two characters to search.

Start free

Sliding Token Windows

mediumRAG20 min25 XP

Return full windows of size moving by stride; omit incomplete trailing windows.

Examples

EXAMPLE WALKTHROUGHoverlap

A guided view of the published example, not a trace of your code.

INPUT[[1,2,3,4,5],3,2]
TASKtoken_windows()
EXPECTED OUTPUT[[1,2,3],[3,4,5]]

Start with the input values shown in this example.

Example 1 of 2

Input: tokens = [1,2,3,4,5], size = 3, stride = 2

Output: [[1,2,3],[3,4,5]]

Explanation: overlap

Input: tokens = [1,2], size = 3, stride = 1

Output: []

Explanation: too short

Hint 1

Iterate start positions while start + size fits.

Topics

PythonRAG