การจำแนกโทเค็น

การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

Fouad Trad

Machine Learning Engineer

การจำแนกข้อความ vs. การจำแนกโทเค็น

การจำแนกข้อความ

  • จำแนกทั้งประโยคหรือคู่ของข้อความ

ภาพแสดงงาน text classification และ QNLI ที่เคยแสดงในวิดีโอก่อนหน้า

การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

การจำแนกข้อความ vs. การจำแนกโทเค็น

การจำแนกข้อความ

  • จำแนกทั้งประโยคหรือคู่ของข้อความ

ภาพแสดงงาน text classification และ QNLI ที่เคยแสดงในวิดีโอก่อนหน้า

การจำแนกโทเค็น

  • กำหนดป้ายกำกับให้กับโทเค็นแต่ละตัวในประโยค

ภาพแสดงประโยคที่แบ่งตามคำ แต่ละคำมีสีต่างกันแทนคลาสที่ต่างกัน

  • การรู้จำนิติบุคคลที่มีชื่อ (NER)
  • การติดแท็กส่วนของคำพูด (PoS)
การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

การรู้จำนิติบุคคลที่มีชื่อ (NER)

  • ระบุนิติบุคคล เช่น ชื่อบุคคล สถานที่ องค์กร วันที่ และอื่นๆ

ภาพแสดงการวิเคราะห์ NER ของประโยค "Apple opened a new office in Toronto in March 2023" โดย Apple ถูกระบุเป็นองค์กร Toronto เป็นสถานที่ และ March 2023 เป็นวันที่

  • ประโยชน์ในด้าน:
    • การค้นคืนข้อมูล
    • การตอบคำถาม
การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

NER ในโค้ด

from transformers import pipeline

ner_pipeline = pipeline(task="ner",
model="dslim/bert-base-NER",
grouped_entities=True)
ner_results = ner_pipeline("Zara Venn established NovaCore Dynamics in London.")
print(ner_results)
[{'entity_group': 'PER', 'score': np.float32(0.99840075), 'word': 'Zara Venn', 'start': 0, 'end': 9}, 
 {'entity_group': 'ORG', 'score': np.float32(0.99875560), 'word': 'NovaCore Dynamics', 'start': 21, 'end': 38}, 
 {'entity_group': 'LOC', 'score': np.float32(0.99960726), 'word': 'London', 'start': 42, 'end': 48}]
การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

การติดแท็กส่วนของคำพูด (PoS)

  • กำหนดบทบาททางไวยากรณ์ (คำนาม กริยา คำคุณศัพท์) ให้กับแต่ละคำ

ภาพแสดงแท็ก PoS ของประโยค "The quick fox jumps over the lazy dog" โดย "the" เป็น determiner, "quick" และ "lazy" เป็น adjective, "fox" และ "dogs" เป็น noun, "jumps" เป็น verb และ "over" เป็น preposition

  • ประโยชน์ในด้าน:
    • การวิเคราะห์ไวยากรณ์เชิงโครงสร้าง
    • การแก้ไขไวยากรณ์
    • การสร้างข้อความ
การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

การติดแท็ก PoS ในโค้ด

pos_pipeline = pipeline(task="token-classification",

model="vblagoje/bert-english-uncased-finetuned-pos",
grouped_entities=True)
pos_results = pos_pipeline("Zara Venn established NovaCore Dynamics in London.") print(pos_results)
[{'entity_group': 'PROPN', 'score': np.float32(0.9982983), 'word': 'zara venn', 'start': 0, 'end': 9},  
 {'entity_group': 'VERB', 'score': np.float32(0.99940944), 'word': 'established', 'start': 10, 'end': 21},  
 {'entity_group': 'PROPN', 'score': np.float32(0.99455726), 'word': 'novacore dynamics', 'start': 22, 'end': 39},  
 {'entity_group': 'ADP', 'score': np.float32(0.99935526), 'word': 'in', 'start': 40, 'end': 42},  
 {'entity_group': 'PROPN', 'score': np.float32(0.99847955), 'word': 'london', 'start': 43, 'end': 49}]
การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

มาฝึกกันเถอะ!

การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python

Preparing Video For Download...