首页 > 解决方案 > 使用模板在 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']
})

但还是不行。我应该如何运行它?

标签: pythonmodelamazon-sagemakerhuggingface-transformers

解决方案


零样本分类模型的请求主体模式在此链接中定义。

{
    "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"
        ]
    }
}

推荐阅读