Transform a sequence of int ids into a human-readable string. EOS is not expected in ids. Args: ids: list of integers to be converted. strip_extraneous: bool, whether to strip off extraneous tokens (EOS and PAD). Returns: s: human-
(self, ids, strip_extraneous=False)
| 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. |
| 189 | |
| 190 | EOS is not expected in ids. |
| 191 | |
| 192 | Args: |
| 193 | ids: list of integers to be converted. |
| 194 | strip_extraneous: bool, whether to strip off extraneous tokens |
| 195 | (EOS and PAD). |
| 196 | |
| 197 | Returns: |
| 198 | s: human-readable string. |
| 199 | """ |
| 200 | if strip_extraneous: |
| 201 | ids = strip_ids(ids, list(range(self._num_reserved_ids or 0))) |
| 202 | return " ".join(self.decode_list(ids)) |
| 203 | |
| 204 | def decode_list(self, ids): |
| 205 | """Transform a sequence of int ids into a their string versions. |
no test coverage detected