問題相似度與文法正確性

Python 的 Natural Language Processing(NLP)

Fouad Trad

Machine Learning Engineer

問題相似度

  • 判斷兩個問題是否為同義改寫
  • 可用於:
    • 去重
    • 相似問題分群
    • 提升搜尋準確度
  • 使用在 Quora Question Pairs(QQP)資料集上訓練的模型完成

三個人在提問的圖示。

Python 的 Natural Language Processing(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 的 Natural Language Processing(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 的 Natural Language Processing(NLP)

評估文法正確性

  • 評估文字的文法正確程度
  • 可用於:

    • 教學工具
    • 文法檢查
    • 寫作助理
  • 使用在 Corpus of Linguistic Acceptability(CoLA)資料集上訓練的模型完成

評估書寫文字正確性的圖示。

Python 的 Natural Language Processing(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 的 Natural Language Processing(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 的 Natural Language Processing(NLP)

一起來練習吧!

Python 的 Natural Language Processing(NLP)

Preparing Video For Download...