I have a list of words(tokens) through which I iterate. I want to perform a certain transformation on moving windows of that list. The size of the windows size can be of variable length.
for i in range(0,len(tokens)-(window_size+1),step):
doc2vec.model.infer_vector(tokens[i:i+window_size])
The for loop goes through the length of the tokens at a step defined in the variable, it takes as many token as the variable window_size says. The problem I see is in the last iteration. The iteration ends at the the length of the tokens - the windows size(+1 so that the substracted value is included). Let's say the window size is 10 and the step is 5 and the length of tokens is 98. In such a situation my code would do the last calculation at 85:95 and leave out the last three elements. I want to a solution that would work for variable window_size, step and tokens length. To illustrate, as of now it would work fine if the length of tokens is 95, but if it is 98 three elements would be left. I would want them to be calculated together 88:98.