Skip to content

Commit 155be75

Browse files
committed
indices out of range fixed
1 parent fc203aa commit 155be75

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

gliner/modeling/span_rep.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,10 @@ def extract_elements(sequence, indices):
374374
Returns:
375375
torch.Tensor: Extracted elements of shape [B, K, D].
376376
"""
377-
D = sequence.size(-1)
378-
379-
# Expand indices to [B, K, D]
377+
B, L, D = sequence.size()
378+
indices = torch.clamp(indices, 0, L - 1)
380379
expanded_indices = indices.unsqueeze(2).expand(-1, -1, D)
381-
382-
# Gather the elements
383380
extracted_elements = torch.gather(sequence, 1, expanded_indices)
384-
385381
return extracted_elements
386382

387383

0 commit comments

Comments
 (0)