MCPcopy Index your code
hub / github.com/Turing-Project/WriteGPT / printable_text

Function printable_text

LanguageNetwork/GPT2/scripts/tokenization.py:100–120  ·  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

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

Callers 1

extract_generated_targetFunction · 0.70

Calls 2

decodeMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected