คุณลักษณะทางภาษาศาสตร์

การประมวลผลภาษาธรรมชาติด้วย spaCy

Azadeh Mobasher

Principal Data Scientist

การติดแท็ก POS

  • แท็ก POS ขึ้นอยู่กับบริบท คำโดยรอบ และแท็กของคำเหล่านั้น
import spacy
nlp = spacy.load("en_core_web_sm")
text = "My cat will fish for a fish tomorrrow in a fishy way."
print([(token.text, token.pos_, spacy.explain(token.pos_)) 
        for token in nlp(text)])

ตัวอย่างการติดแท็ก POS

การประมวลผลภาษาธรรมชาติด้วย spaCy

POS มีความสำคัญอย่างไร?

 

  • เพิ่มความแม่นยำให้งาน NLP หลายประเภท

 

I will fish tomorrow.

I ate fish.

 

  • กรณีใช้งานในระบบแปลภาษา

 

verb -> pescaré

noun -> pescado
การประมวลผลภาษาธรรมชาติด้วย spaCy

POS มีความสำคัญอย่างไร?

 

  • การแก้ความกำกวมของความหมายคำ (WSD) คือการตัดสินว่าคำหนึ่งถูกใช้ในความหมายใดในประโยค
  • การระบุความหมายของคำมีความสำคัญอย่างยิ่งในงานแปลภาษาเครื่อง เป็นต้น

ตัวอย่าง WSD

การประมวลผลภาษาธรรมชาติด้วย spaCy

การแก้ความกำกวมของความหมายคำ

import spacy
nlp = spacy.load("en_core_web_sm")

verb_text = "I will fish tomorrow."
noun_text = "I ate fish."


print([(token.text, token.pos_) for token in nlp(verb_text) if "fish" in token.text], "\n") print([(token.text, token.pos_) for token in nlp(noun_text) if "fish" in token.text])
[('fish', 'VERB', 'verb')] 
[('fish', 'NOUN', 'noun')]
การประมวลผลภาษาธรรมชาติด้วย spaCy

Dependency parsing

  • วิเคราะห์โครงสร้างวากยสัมพันธ์ของประโยค
  • แสดงความสัมพันธ์ระหว่างสอง token
  • ผลลัพธ์เป็นโครงสร้างต้นไม้

ตัวอย่างการวิเคราะห์ dependency

การประมวลผลภาษาธรรมชาติด้วย spaCy

Dependency parsing และ spaCy

 

  • Dependency label อธิบายประเภทความสัมพันธ์ทางวากยสัมพันธ์ระหว่างสอง token

 

Dependency label คำอธิบาย
nsubj ประธานหลัก (Nominal subject)
root รากประโยค (Root)
det คำกำหนดนาม (Determiner)
dobj กรรมตรง (Direct object)
aux กริยาช่วย (Auxiliary)
การประมวลผลภาษาธรรมชาติด้วย spaCy

Dependency parsing และ displaCy

  • displaCy สามารถวาดต้นไม้ dependency ได้
doc = nlp("We understand the differences.")

spacy.displacy.serve(doc, style="dep")

ตัวอย่าง dependency parser ด้วย displaCy

การประมวลผลภาษาธรรมชาติด้วย spaCy

Dependency parsing และ spaCy

  • ใช้แอตทริบิวต์ .dep_ เพื่อเข้าถึง dependency label ของ token

 

doc = nlp("We understand the differences.")
print([(token.text, token.dep_, spacy.explain(token.dep_)) for token in doc])
[('We', 'nsubj', 'nominal subject'), ('understand', 'ROOT', 'root'),
('the', 'det', 'determiner'), ('differences', 'dobj', 'direct object'),
('.', 'punct', 'punctuation')]
การประมวลผลภาษาธรรมชาติด้วย spaCy

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

การประมวลผลภาษาธรรมชาติด้วย spaCy

Preparing Video For Download...