開始使用免費開始

這段文字有回答問題嗎?

某大型科技公司的內容審核團隊需要自動驗證知識庫中的一段文字是否回答了使用者的查詢。他們想透過預先訓練的 QNLI 模型,加速評估每個回覆與問題的相關性。你的目標是實作一個解決方案,能判斷給定的段落是否包含特定問題的答案。

本練習屬於課程

Python 的 Natural Language Processing(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)
編輯並執行程式碼