You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure ML Studio测试接口请求报错:source_words样本数不足排查

Azure ML Studio接口测试报错排查:['source_words']样本数为0的问题

问题描述

在使用Azure ML Studio测试接口时,平台提供的POST请求payload模板如下:

{
  "input_data": {
    "columns": [
      "content_type",
      "project_name",
      "source_words",
      "source_text",
      "target_locale",
      "evaluated_phase",
      "evaluated_translation",
      "evaluated_vendor",
      "lqe_phase"
    ],
    "index": [],
    "data": []
  }
}

按如下方式填充后:

{
  "input_data": {
    "columns": [
      "content_type",
      "project_name",
      "source_words",
      "source_text",
      "target_locale",
      "evaluated_phase",
      "evaluated_translation",
      "evaluated_vendor",
      "lqe_phase"
    ],
    "index": [],
    "data": [
      {
        "content_type": "some text",
        "project_name": "some text",
        "source_words": 1267,
        "source_text": "some text",
        "target_locale": "text",
        "evaluated_phase": "more text",
        "evaluated_translation": "text text",
        "evaluated_vendor": "text",
        "lqe_phase": "final text"
      }   
    ]
  }
}

其中仅source_words为整数类型,其余均为文本类型,但持续收到错误:
InnerException: ValueError: ['source_words']: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required.

2023-10-05更新:部署多个其他模型后,均出现相同错误。

可能的原因及解决办法

  • 数据格式不匹配:多数Azure ML部署的模型(尤其是基于Scikit-learn、XGBoost等框架训练的)要求data字段为数组的数组,而非键值对对象数组。当前使用的对象格式无法被模型正确解析,导致source_words字段被识别为0样本。
    修正后的payload格式如下:

    {
      "input_data": {
        "columns": [
          "content_type",
          "project_name",
          "source_words",
          "source_text",
          "target_locale",
          "evaluated_phase",
          "evaluated_translation",
          "evaluated_vendor",
          "lqe_phase"
        ],
        "index": [],
        "data": [
          ["some text", "some text", 1267, "some text", "text", "more text", "text text", "text", "final text"]
        ]
      }
    }
    

    注意data中的每个样本是一个数组,元素顺序必须和columns完全对应,无需指定键名。

  • 模型输入Schema配置错误:多个模型均报错,说明可能是部署时的输入数据集Schema与实际请求不匹配。检查模型部署时定义的输入列是否包含source_words,且数据类型设为整数;同时确认输入格式要求为“表格型数组”而非“JSON对象”。

  • 推理脚本(score.py)逻辑问题:自定义模型的推理脚本可能未适配对象数组格式的输入。检查score.py中的run()函数,确保它能正确读取input_data['data']并解析出source_words。例如如果脚本使用pd.DataFrame(input_data['data'], columns=input_data['columns'])构建数据集,必须保证data是数组数组,否则DataFrame无法正确加载,导致列样本数为0。

内容的提问来源于stack exchange,提问作者phil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 11:03:14