MCPcopy Create free account
hub / github.com/tensorflow/models / tokenize

Method tokenize

official/nlp/tools/tokenization.py:207–232  ·  view source on GitHub ↗

Tokenizes a piece of text.

(self, text)

Source from the content-addressed store, hash-verified

205 self.split_on_punc = split_on_punc
206
207 def tokenize(self, text):
208 """Tokenizes a piece of text."""
209 text = convert_to_unicode(text)
210 text = self._clean_text(text)
211
212 # This was added on November 1st, 2018 for the multilingual and Chinese
213 # models. This is also applied to the English models now, but it doesn't
214 # matter since the English models were not trained on any Chinese data
215 # and generally don't have any Chinese data in them (there are Chinese
216 # characters in the vocabulary because Wikipedia does have some Chinese
217 # words in the English Wikipedia.).
218 text = self._tokenize_chinese_chars(text)
219
220 orig_tokens = whitespace_tokenize(text)
221 split_tokens = []
222 for token in orig_tokens:
223 if self.do_lower_case:
224 token = token.lower()
225 token = self._run_strip_accents(token)
226 if self.split_on_punc:
227 split_tokens.extend(self._run_split_on_punc(token))
228 else:
229 split_tokens.append(token)
230
231 output_tokens = whitespace_tokenize(" ".join(split_tokens))
232 return output_tokens
233
234 def _run_strip_accents(self, text):
235 """Strips accents from a piece of text."""

Callers 5

test_chineseMethod · 0.95
get_final_textFunction · 0.95

Calls 7

_clean_textMethod · 0.95
_run_strip_accentsMethod · 0.95
_run_split_on_puncMethod · 0.95
convert_to_unicodeFunction · 0.85
whitespace_tokenizeFunction · 0.85
joinMethod · 0.45