问题相似性与语法正确性

Python 中的自然语言处理(NLP)

Fouad Trad

Machine Learning Engineer

问题相似性

  • 判断两问是否为同义改写
  • 用途:
    • 去重
    • 相似问题聚类
    • 提升搜索准确性
  • 使用 Quora Question Pairs(QQP)数据集训练的模型

显示三个人在提问的图像。

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)

评估语法正确性

  • 评估文本的语法正确性
  • 用途:

    • 教学工具
    • 语法检查
    • 写作助手
  • 使用语言可接受性语料库(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)

Vamos praticar!

Python 中的自然语言处理(NLP)

Preparing Video For Download...