代码
"""
Created on 2020/11/23 10:27
@Author: CY
@email: 5844104706@qq.com
"""
'''
Unicode 是一种标准的编码系统,用于表示几乎所有语言的字符。每个字符使用 0 和 0x10FFFF 之间的唯一整数码位进行编码。
Unicode 字符串是由零个或更多码位组成的序列。
TensorFlow 中表示 Unicode 字符串,以及如何使用标准字符串运算的 Unicode 等效项对其进行操作。
它会根据字符体系检测将 Unicode 字符串划分为不同词例。
'''
import tensorflow as tf
print(tf.constant(u"Thanks 😊"))
tf.constant([u"You're", u"welcome!"]).shape
text_utf8 = tf.constant(u"语言处理")
print(text_utf8)
text_utf16be = tf.constant(u"语言处理".encode("UTF-16-BE"))
print(text_utf16be)
text_chars = tf.constant([ord(char) for char in u"语言处理"])
print(text_chars)
tf.strings.unicode_decode(text_utf8, input_encoding='UTF-8')
tf.strings.unicode_encode(text_chars, output_encoding='UTF-8')
tf.strings.unicode_transcode(text_utf8, input_encoding='UTF8', output_encoding='UTF-16-BE')
batch_utf8 = [s.encode('UTF-8') for s in
[u'hÃllo', u'What is the weather tomorrow', u'Göödnight', u'😊']]
batch_chars_ragged = tf.strings