言語的特徴

spaCyで学ぶNatural Language Processing

Azadeh Mobasher

Principal Data Scientist

品詞タグ付け(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)])

品詞タグ付けの例

spaCyで学ぶNatural Language Processing

POSの重要性

 

  • 多くのNLPタスクで精度が向上

 

I will fish tomorrow.

I ate fish.

 

  • 機械翻訳での利用例

 

verb -> pescaré

noun -> pescado
spaCyで学ぶNatural Language Processing

POSの重要性

 

  • 語義曖昧性解消(WSD)は、文中での語の意味を判定する課題
  • 語義の特定は機械翻訳などで重要

WSDの例

spaCyで学ぶNatural Language Processing

語義曖昧性解消(WSD)

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で学ぶNatural Language Processing

係り受け解析

  • 文の構文を解析
  • 2つのトークン間の関係を特定
  • 結果は木構造

係り受け解析の例

spaCyで学ぶNatural Language Processing

係り受け解析とspaCy

 

  • 係り受けラベルは、2つのトークン間の構文的関係の種類を示す

 

係り受けラベル 説明
nsubj 主語(名詞)
root ルート
det 限定詞
dobj 直接目的語
aux 助動詞
spaCyで学ぶNatural Language Processing

係り受け解析とdisplaCy

  • displaCy で係り受け木を描画できる
doc = nlp("We understand the differences.")

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

displaCyによる係り受け解析の例

spaCyで学ぶNatural Language Processing

係り受け解析とspaCy

  • .dep_ 属性でトークンの係り受けラベルを取得

 

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で学ぶNatural Language Processing

Passons à la pratique !

spaCyで学ぶNatural Language Processing

Preparing Video For Download...