Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b455c91

Browse filesBrowse files
committed
Helper function for Vocab object
1 parent 735d5e7 commit b455c91
Copy full SHA for b455c91

File tree

Expand file treeCollapse file tree

1 file changed

+6
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-0
lines changed

‎torchtext/vocab.py

Copy file name to clipboardExpand all lines: torchtext/vocab.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ def __init__(self, counter, max_size=None, min_freq=1, specials=('<unk>', '<pad>
103103
def _default_unk_index(self):
104104
return self.unk_index
105105

106+
def get_token(self, index):
107+
result = self.itos[index]
108+
if result is None:
109+
return Vocab.UNK
110+
return result
111+
106112
def __getitem__(self, token):
107113
return self.stoi.get(token, self.stoi.get(Vocab.UNK))
108114

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.