MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / encode

Method encode

NLP/EMNLP2019-MAL/src/preprocess/text_encoder.py:171–185  ·  view source on GitHub ↗

Transform a human-readable string into a sequence of int ids. The ids should be in the range [num_reserved_ids, vocab_size). Ids [0, num_reserved_ids) are reserved. EOS is not appended. Args: s: human-readable string to be converted. Returns:

(self, s)

Source from the content-addressed store, hash-verified

169 return self._num_reserved_ids
170
171 def encode(self, s):
172 """Transform a human-readable string into a sequence of int ids.
173
174 The ids should be in the range [num_reserved_ids, vocab_size). Ids [0,
175 num_reserved_ids) are reserved.
176
177 EOS is not appended.
178
179 Args:
180 s: human-readable string to be converted.
181
182 Returns:
183 ids: list of integers
184 """
185 return [int(w) + self._num_reserved_ids for w in s.split()]
186
187 def decode(self, ids, strip_extraneous=False):
188 """Transform a sequence of int ids into a human-readable string.

Callers 7

parse_argsFunction · 0.45
parse_argsFunction · 0.45
txt2txt_encoderFunction · 0.45
txt_encoderFunction · 0.45
txt2txt_encoderFunction · 0.45
txt_encoderFunction · 0.45
unicode_to_nativeFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected