INNER CODE UNIT · Python
min_index
HendrikStrobelt/detecting-fake-text · backend/api.py:232
min_index = max(0, mask_index - max_context)
max_index = min(tokens_tensor.shape[1] - 1,
mask_index + max_context + 1)
tokens_tensor = tokens_tensor[:, min_index:max_index]
# Add padding
needed_padding = max_context * 2 + 1 - tokens_tensor.shape[1]
if min_index == 0 and max_index == y.shape[1] - 1:
# Only when input is shorter than max_context
left_needed = (max_context) - mask_index
right_needed = needed_padding - left_needed
p = torch.nn.ConstantPad1d((left_needed, right_needed),
self.pad)
tokens_tensor = p(tokens_tensor)
elif min_index == 0:
p = torch.nn.ConstantPad1d((needed_padding, 0), self.pad)
tokens_tensor = p(tokens_tensor)
elif max_index == y.shape[1] - 1: