Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

Unicode Scripts ใน TensorFlow และ Python คืออะไร

นิยาม

ทุก 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 พบบ่อย

CodeScriptตัวอย่าง
25 (COMMON)Latin, punctuation, digitsA, 1, ,
17 (HAN)Chinese characters中, 文, 芸
20 (HIRAGANA)Japanese Hiraganaこ, ん, に
21 (KATAKANA)Japanese Katakanaコ, ン, ニ
22 (HANGUL)Korean Hangul한, 글
23 (THAI)Thaiก, ข, ฃ