检查语法正确性
正在构建一款帮助用户提升语法能力的教育应用。其中一项核心功能是自动检查用户提交的句子在语法上是否可接受。现在请您使用基于 CoLA(Corpus of Linguistic Acceptability,语言可接受性语料库)训练的模型来实现这一功能,对句子是否正确进行分类。
本练习是课程的一部分
Python 中的自然语言处理(NLP)
练习说明
- 使用模型
"textattack/bert-base-uncased-CoLA"初始化一个classifierpipeline。 - 使用该 pipeline 检查
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)