MCPcopy Create free account
hub / github.com/SooLab/CGFormer / __getitem__

Method __getitem__

bert/tokenization_utils_base.py:169–181  ·  view source on GitHub ↗

If the key is a string, get the value of the dict associated to `key` ('input_ids', 'attention_mask'...) If the key is an integer, get the EncodingFast for batch item with index `key`

(self, item: Union[int, str])

Source from the content-addressed store, hash-verified

167 return self._encodings is not None
168
169 def __getitem__(self, item: Union[int, str]) -> EncodingFast:
170 """ If the key is a string, get the value of the dict associated to `key` ('input_ids', 'attention_mask'...)
171 If the key is an integer, get the EncodingFast for batch item with index `key`
172 """
173 if isinstance(item, str):
174 return self.data[item]
175 elif self._encodings is not None:
176 return self._encodings[item]
177 else:
178 raise KeyError(
179 "Indexing with integers (to access backend Encoding for a given batch index) "
180 "is not available when using Python based tokenizers"
181 )
182
183 def __getattr__(self, item: str):
184 try:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected