นิยาม
ทุก Unicode code point 屬於 Script (สคริปต์/ระบบเขียน) หนึ่งเดียว เช่น Latin, Cyrillic, Han, Hiragana, Katakana, Thai, ฯลฯ
Script ช่วยระบุว่าตัวอักษรน่าจะมาจากภาษา/ระบบเขียนไหน
TensorFlow Operation
tf.strings.unicode_script(codepoints) คืนค่า int32 tensor รหัส script (mapping ไป ICU UScriptCode)
โค้ดตัวอย่าง
print("The below represent '芸' and 'Б' respectively")
uscript = tf.strings.unicode_script([33464, 1041])
print(uscript.numpy()) # [17, 8] == [USCRIPT_HAN, USCRIPT_CYRILLIC]
print("Applying to multidimensional strings")
print(tf.strings.unicode_script(batch_chars_ragged))ผลลัพธ์
The below represent '芸' and 'Б' respectively [17 8] Applying to multidimensional strings
คำอธิบาย
- รหัส script เป็น int32 (17=HAN, 8=CYRILLIC, 25=COMMON/Latin, 0=COMMON/punctuation)
- รองรับ input แบบ multi-dimensional: dense tensor หรือ RaggedTensor ของ codepoints
- ใช้ร่วมกับ
unicode_decodeและ script change detection เพื่อ segmentation
ตาราง Script Codes พบบ่อย
| Code | Script | ตัวอย่าง |
|---|---|---|
| 25 (COMMON) | Latin, punctuation, digits | A, 1, , |
| 17 (HAN) | Chinese characters | 中, 文, 芸 |
| 20 (HIRAGANA) | Japanese Hiragana | こ, ん, に |
| 21 (KATAKANA) | Japanese Katakana | コ, ン, ニ |
| 22 (HANGUL) | Korean Hangul | 한, 글 |
| 23 (THAI) | Thai | ก, ข, ฃ |