python - 使用模板在 Sagemaker 中部署拥抱面零样本分类返回错误,缺少位置参数“candidate_labels”
问题描述
我正在使用从 huggingface、Task: Zero-Shot Classification
、Configuration:生成的代码,AWS
并在 Sagemaker 的 jupyterlab 中运行它
from sagemaker.huggingface import HuggingFaceModel
import sagemaker
role = sagemaker.get_execution_role()
# Hub Model configuration. https://huggingface.co/models
hub = {
'HF_MODEL_ID':'facebook/bart-large-mnli',
'HF_TASK':'zero-shot-classification'
}
# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
transformers_version='4.6.1',
pytorch_version='1.7.1',
py_version='py36',
env=hub,
role=role,
)
# deploy model to SageMaker Inference
predictor = huggingface_model.deploy(
initial_instance_count=1, # number of instances
instance_type='ml.m5.xlarge' # ec2 instance type
)
predictor.predict({
'inputs': "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!"
})
返回以下错误:
ModelError:调用 InvokeEndpoint 操作时发生错误 (ModelError):从主服务器收到客户端错误 (400),消息为 "{ "code": 400, "type": "InternalServerException",
"message": " call () missing 1所需的位置参数:\u0027candidate_labels\u0027" } "。有关详细信息,请参阅 ... 在帐户 **** 中。
我尝试以不同的方式运行它们,例如,
predictor.predict({
'inputs': "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!",
'candidate_labels': ['science', 'life']
})
但还是不行。我应该如何运行它?
解决方案
零样本分类模型的请求主体模式在此链接中定义。
{
"inputs": "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!",
"parameters": {
"candidate_labels": [
"refund",
"legal",
"faq"
]
}
}
推荐阅读
- slurm - slurm 可以将 3 台单独的计算机作为一个“节点”运行吗?
- c# - 为什么将空值转换为 datetime2 会在 SQL 中引发转换错误?
- c - 无法从子级访问父级的共享变量
- size - 如何使用 makecode 查找我的 micro:bit 上使用了多少 RAM 内存?
- haskell - 将输出 Monad 类型的函数转换为输出原始值类型的函数
- javascript - 我如何获得输入字段的父级
- javascript - 更简单的方法将 onTap 功能绑定到微信小程序中的按钮
- react-native - 当我在本机反应中移回多个页面时,返回处理程序不起作用
- spring - Spring Integraton RSocket 和 Spring RSocket 交互问题
- ios - Swift Combine 属性继承在 Xcode 11.4 beta 2 / iOS 13.4 上引发“致命错误:调用已删除方法”