檢查語法正確性
正在開發一款教育型 App,協助使用者提升文法能力。核心功能之一是自動檢查使用者提交的句子是否在語法上可被接受。你受託使用以 CoLA(Corpus of Linguistic Acceptability)語料訓練的模型來分類句子是否正確,並實作這個功能。
本練習屬於課程
Python 的 Natural Language Processing(NLP)
練習說明
- 使用模型
"textattack/bert-base-uncased-CoLA"初始化classifier管線。 - 使用該管線檢查
user_text是否在語法上可被接受。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from transformers import pipeline
# Initialize the pipeline
classifier = ____
user_text = "Although she was knowing the answer, she didn't raised her hand during the class discussion."
# Classify grammatical acceptability
result = ____
print(result)