質問の類似性と文法的正確性

Pythonで学ぶ自然言語処理(NLP)

Fouad Trad

Machine Learning Engineer

質問の類似性

  • 2つの質問が言い換えかを判定
  • 用途:
    • 重複排除
    • 類似質問のクラスタリング
    • 検索精度の向上
  • Quora Question Pairs (QQP) で学習したモデルを使用

3人が質問している画像。

Pythonで学ぶ自然言語処理(NLP)

QQP パイプライン

from transformers import pipeline

qqp_pipeline = pipeline( task="text-classification", model="textattack/bert-base-uncased-QQP" )
question1 = "How can I learn Python?" question2 = "What is the best way to study Python?"
result = qqp_pipeline({"text": question1, "text_pair": question2})
print(result)
{'label': 'LABEL_1', 'score': 0.6853412985801697}
Pythonで学ぶ自然言語処理(NLP)

QQP パイプライン

from transformers import pipeline
qqp_pipeline = pipeline(
    task="text-classification", 
    model="textattack/bert-base-uncased-QQP"
    )
question1 = "How can I learn Python?"
question2 = "What is the capital of France?"
result = qqp_pipeline({"text": question1, "text_pair": question2})
print(result)
{'label': 'LABEL_0', 'score': 0.9999338388442993}
Pythonで学ぶ自然言語処理(NLP)

文法的正確性の評価

  • テキストの文法的正しさを評価
  • 用途:

    • 教育ツール
    • 文法チェッカー
    • 文章支援ツール
  • Corpus of Linguistic Acceptability (CoLA) で学習したモデルを使用

書かれた文章の正しさを評価する人物の画像。

Pythonで学ぶ自然言語処理(NLP)

CoLA パイプライン

from transformers import pipeline
cola_classifier = pipeline(
  task="text-classification", 
  model="textattack/distilbert-base-uncased-CoLA"
)

result = cola_classifier("The cat sat on the mat.")
print(result)
[{'label': 'LABEL_1', 'score': 0.9918296933174133}]
Pythonで学ぶ自然言語処理(NLP)

CoLA パイプライン

from transformers import pipeline
cola_classifier = pipeline(
  task="text-classification", 
  model="textattack/distilbert-base-uncased-CoLA"
)
result = cola_classifier("The cat on sat mat the.")
print(result)
[{'label': 'LABEL_0', 'score': 0.9628171324729919}]
Pythonで学ぶ自然言語処理(NLP)

Let's practice!

Pythonで学ぶ自然言語処理(NLP)

Preparing Video For Download...