跳转到内容
主站 新闻 控制台

Hugging Face 中的决策模型

· Hugging Face
教程模型卡

大语言模型(LLM)极其擅长生成文本。我们用它们来回答问题、编写代码、对问题进行推理,以及完成更多工作。但并非所有问题都需要生成文本。

设想一个客户支持系统收到了以下消息:

“我的订阅被扣了两次费。我今天就需要退款。”

系统需要确定应该由哪个团队处理该请求、紧急程度如何,以及客户是否在要求退款。

我们可以让大语言模型返回一个包含这些答案的 JSON 对象。

Terminal window
llama cli -hf ggml-org/gemma-4-e4b-it-GGUF:Q4_0
> We have the following customer support ticket, "I was charged twice for my subscription. I need a refund today.", which team should handle the request, how urgent it is, and whether the customer is requesting a refund. Give the answers in JSON.
[Start thinking]
...
[end thinking]
```json
{
"team_to_handle": "Billing",
"urgency": "High",
"request_refund": true
}

但如果模型可以直接评估可用选项,并返回这些选项的概率分布,而_无需生成任何文本_呢?

from transformers import pipeline
decide = pipeline("decision", model="autotrust/GEV-26B-Decide")
decision = decide(
{
"state": "I was charged twice for my order and want a refund.",
"questions": {
"department": {
"type": "choice",
"instructions": "Which team should handle this?",
"criteria": {
"billing": "Payments and refunds",
"technical": "Bugs and technical issues",
"sales": "Pricing and subscriptions"
}
},
}
}
)
# {
# 'department': {
# 'type': 'choice',
# 'choice': 'billing',
# 'confidence': 0.9974000453948975,
# 'probabilities': {
# 'billing': 0.9982666969299316,
# 'technical': 0.0010246571619063616,
# 'sales': 0.0007087149424478412
# }
# }
# }

这就是**决策模型(decision models)**背后的核心理念。

什么是决策模型?

决策模型接收一些输入上下文(状态,state),结合一组预定义的可能答案(原语,primitives)来评估问题,并返回带有概率的结构化决策。我们不再要求模型逐个词元(token)地生成答案,而是要求它为我们应用程序已经理解的答案分配概率。

[Image 12: 决策模型的状态与原语](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/de