Tokenizes a piece of text.
(self, text)
| 188 | self.never_split = never_split |
| 189 | |
| 190 | def tokenize(self, text): |
| 191 | """Tokenizes a piece of text.""" |
| 192 | text = self._clean_text(text) |
| 193 | # This was added on November 1st, 2018 for the multilingual and Chinese |
| 194 | # models. This is also applied to the English models now, but it doesn't |
| 195 | # matter since the English models were not trained on any Chinese data |
| 196 | # and generally don't have any Chinese data in them (there are Chinese |
| 197 | # characters in the vocabulary because Wikipedia does have some Chinese |
| 198 | # words in the English Wikipedia.). |
| 199 | text = self._tokenize_chinese_chars(text) |
| 200 | orig_tokens = whitespace_tokenize(text) |
| 201 | split_tokens = [] |
| 202 | for token in orig_tokens: |
| 203 | if self.do_lower_case and token not in self.never_split: |
| 204 | token = token.lower() |
| 205 | token = self._run_strip_accents(token) |
| 206 | split_tokens.extend(self._run_split_on_punc(token)) |
| 207 | |
| 208 | output_tokens = whitespace_tokenize(" ".join(split_tokens)) |
| 209 | return output_tokens |
| 210 | |
| 211 | def _run_strip_accents(self, text): |
| 212 | """Strips accents from a piece of text.""" |
nothing calls this directly
no test coverage detected