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

Function printable_text

official/nlp/tools/tokenization.py:104–124  ·  view source on GitHub ↗

Returns text encoded in a way suitable for print or `tf.logging`.

(text)

Source from the content-addressed store, hash-verified

102
103
104def printable_text(text):
105 """Returns text encoded in a way suitable for print or `tf.logging`."""
106
107 # These functions want `str` for both Python2 and Python3, but in one case
108 # it's a Unicode string and in the other it's a byte string.
109 if six.PY3:
110 if isinstance(text, str):
111 return text
112 elif isinstance(text, bytes):
113 return text.decode("utf-8", "ignore")
114 else:
115 raise ValueError("Unsupported string type: %s" % (type(text)))
116 elif six.PY2:
117 if isinstance(text, str):
118 return text
119 elif isinstance(text, unicode):
120 return text.encode("utf-8")
121 else:
122 raise ValueError("Unsupported string type: %s" % (type(text)))
123 else:
124 raise ValueError("Not running on Python2 or Python 3?")
125
126
127def load_vocab(vocab_file):

Callers 2

encode_piecesFunction · 0.70
convert_tokens_to_idsMethod · 0.70

Calls 2

decodeMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected