질문 유사성과 문법적 적합성

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...