將每個字符串拆分為具有起始偏移量的代碼點序列。
用法
tf.strings.unicode_split_with_offsets(
input, input_encoding, errors='replace', replacement_char=65533,
name=None
)參數
-
input一個N維度可能參差不齊的string張量,形狀為[D1...DN]。N必須是靜態已知的。 -
input_encoding用於解碼每個字符串的 unicode 編碼的字符串名稱。 -
errors指定無法使用指示的編碼轉換輸入字符串時的響應。之一:'strict':為任何非法子字符串引發異常。'replace':用replacement_char替換非法子字符串。'ignore':跳過非法子串。
-
replacement_char當errors='replace'時用於代替input中的無效子字符串的替換代碼點。 -
name操作的名稱(可選)。
返回
-
一個元組
N+1維張量(codepoints, start_offsets).codepoints是一個int32張量,形狀為[D1...DN, (num_chars)]。offsets是一個int64張量,形狀為[D1...DN, (num_chars)]。
如果
input是標量,則返回的張量為tf.Tensor,否則為tf.RaggedTensor。
此操作類似於 tf.strings.decode(...) ,但它還返回其各自字符串中每個字符的起始偏移量。此信息可用於將字符與原始字節序列對齊。
返回一個元組 (chars, start_offsets) 其中:
chars[i1...iN, j]是input[i1...iN]的子字符串,當使用input_encoding解碼時,它編碼其第j個字符。start_offsets[i1...iN, j]是使用input_encoding解碼時input[i1...iN]中第j字符的起始字節偏移量。
例子:
input = [s.encode('utf8') for s in (u'G\xf6\xf6dnight', u'\U0001f60a')]
result = tf.strings.unicode_split_with_offsets(input, 'UTF-8')
result[0].to_list() # character substrings
[[b'G', b'\xc3\xb6', b'\xc3\xb6', b'd', b'n', b'i', b'g', b'h', b't'],
[b'\xf0\x9f\x98\x8a']]
result[1].to_list() # offsets
[[0, 1, 3, 5, 6, 7, 8, 9, 10], [0]]
相關用法
- Python tf.strings.unicode_split用法及代碼示例
- Python tf.strings.unicode_script用法及代碼示例
- Python tf.strings.unicode_decode_with_offsets用法及代碼示例
- Python tf.strings.unicode_decode用法及代碼示例
- Python tf.strings.unicode_encode用法及代碼示例
- Python tf.strings.unicode_transcode用法及代碼示例
- Python tf.strings.unsorted_segment_join用法及代碼示例
- Python tf.strings.upper用法及代碼示例
- Python tf.strings.substr用法及代碼示例
- Python tf.strings.reduce_join用法及代碼示例
- Python tf.strings.regex_full_match用法及代碼示例
- Python tf.strings.regex_replace用法及代碼示例
- Python tf.strings.length用法及代碼示例
- Python tf.strings.bytes_split用法及代碼示例
- Python tf.strings.as_string用法及代碼示例
- Python tf.strings.lower用法及代碼示例
- Python tf.strings.split用法及代碼示例
- Python tf.strings.join用法及代碼示例
- Python tf.strings.to_hash_bucket用法及代碼示例
- Python tf.strings.ngrams用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.strings.unicode_split_with_offsets。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
