开始使用免费开始使用

这段文本能回答该问题吗?

某大型科技公司的内容审核团队需要自动验证知识库中的一段文本是否回答了客户的查询。他们希望使用预训练的 QNLI 模型来评估每个回复的相关性,从而加快处理流程。您的目标是实现一个解决方案,用于分类给定的文本段是否包含针对特定问题的答案。

本练习是课程的一部分

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

查看课程

练习说明

  • 使用合适的 QNLI 模型(例如 "cross-encoder/qnli-electra-base")初始化一个 classifier pipeline。
  • 使用该 pipeline 评估给定的 passage 是否回答了 question

交互式实操练习

通过完成这段示例代码来试试这个练习。

from transformers import pipeline

# Initialize the QNLI pipeline
classifier = ____

passage = "Our refund policy allows customers to return any item within 30 days of purchase, provided the item is in its original condition and accompanied by the receipt. Refunds are issued to the original payment method within 5–7 business days."
question = "Can I get a refund if I return a product after 20 days?"

# Get the result
result = ____
print(result)
编辑并运行代码