Skip to content

Fix Vocab.to_tokens crash on single-element index lists - #2715

Closed
chessing234 wants to merge 1 commit into
d2l-ai:masterfrom
chessing234:fix/vocab-to-tokens-single-index
Closed

chessing234 wants to merge 1 commit into
d2l-ai:masterfrom
chessing234:fix/vocab-to-tokens-single-index

Conversation

@chessing234

Copy link
Copy Markdown

Vocab.to_tokens used len(indices) > 1 to decide whether to iterate. A one-element list like [15] fell through to self.idx_to_token[[15]], which raises TypeError because the key must be an int, not a list.

Use isinstance(indices, (list, tuple)) instead, matching how __getitem__ handles collections.

Made with Cursor

Use isinstance(list, tuple) instead of len(indices) > 1 so [15]
is treated as a collection, not a scalar index.

Co-authored-by: Cursor <cursoragent@cursor.com>
@chessing234 chessing234 closed this by deleting the head repository Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant