MCPcopy Index your code
hub / github.com/OptimalScale/LMFlow / encode

Method encode

src/lmflow/models/hf_decoder_model.py:210–242  ·  view source on GitHub ↗

Perform encoding process of the tokenizer. Parameters ------------ inputs : str or list. The text sequence. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns --

(self, input: Union[str, list[str]], *args, **kwargs)

Source from the content-addressed store, hash-verified

208 return tokenized_datasets
209
210 def encode(self, input: Union[str, list[str]], *args, **kwargs) -> Union[list[int], list[list[int]]]:
211 """
212 Perform encoding process of the tokenizer.
213
214 Parameters
215 ------------
216 inputs : str or list.
217 The text sequence.
218
219 args : Optional.
220 Positional arguments.
221
222 kwargs : Optional.
223 Keyword arguments.
224
225 Returns
226 ------------
227 outputs :
228 if string input,return the tokenized inputs.
229 "Hello,world!"-> [101, 7592, 1010, 2088, 102]
230 if batch input,return {input_ids,attention_mask,token_type_ids}
231 ["Hello,world!","Hello!"] ->
232 {
233 'input_ids': tensor([[ 101, 7592, 1010, 2088, 102],...),
234 'attention_mask': tensor([[1, 1, 1, 1, 1],[0,0,1,1,1]])
235 }
236 """
237 if isinstance(input, list):
238 return self.tokenizer(text=input, **kwargs) # batch encode,will automatically do left padding
239 elif isinstance(input, str):
240 return self.tokenizer.encode(text=input, **kwargs)
241 else:
242 raise NotImplementedError(f'type "{type(input)}" cannot be encoded')
243
244 def decode(self, input, **kwargs) -> Union[str, list[str]]:
245 """

Callers 15

test_encodeMethod · 0.95
test_inferenceMethod · 0.95
tokenizeMethod · 0.80
simple_funcMethod · 0.80
_encode_templateMethod · 0.80
remove_last_separatorMethod · 0.80
add_special_starterMethod · 0.80
add_special_stopperMethod · 0.80
_encode_templateMethod · 0.80
tokenizeMethod · 0.80
tokenizeMethod · 0.80

Calls

no outgoing calls

Tested by 2

test_encodeMethod · 0.76
test_inferenceMethod · 0.76