Fråglikhet och grammatisk korrekthet

Natural Language Processing (NLP) i Python

Fouad Trad

Machine Learning Engineer

Fråglikhet

  • Identifierar när två frågor är omformuleringar av varandra
  • Användbart för:
    • Deduplicering
    • Klustring av liknande frågor
    • Förbättrad sökprecision
  • Görs med modeller tränade på Quora Question Pairs (QQP)-datasetet

Bild som visar tre personer som ställer frågor.

Natural Language Processing (NLP) i Python

QQP-pipeline

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

QQP-pipeline

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

Bedöma grammatisk korrekthet

  • Bedömer hur grammatiskt korrekt en text är
  • Användbart för:

    • Utbildningsverktyg
    • Grammatikkontroller
    • Skrivassistenter
  • Görs med modeller tränade på Corpus of Linguistic Acceptability (CoLA)-datasetet

Bild som visar en person som bedömer korrektheten hos en skriven text.

Natural Language Processing (NLP) i Python

CoLA-pipeline

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}]
Natural Language Processing (NLP) i Python

CoLA-pipeline

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}]
Natural Language Processing (NLP) i Python

Nu kör vi en övning!

Natural Language Processing (NLP) i Python

Preparing Video For Download...