AWS 服装实体识别:错误的 ARN 端点

AWS costum entity recognition: Wrong ARN-Endpoint

我尝试使用我刚刚在 Amazon Web Service (AWS) 上训练的自定义实体识别。 培训到目前为止有效:

但是,如果我尝试使用给定的 ARN-Endpoint 使用 AWS Lambda(下面的代码)识别我的实体,我会收到以下错误(即使 AWS 应该使用最新版本的 botocore/boto3 框架“ EntpointArn" 不可用 (Docs)):

Response:
{
  "errorMessage": "Parameter validation failed:\nUnknown parameter in input: \"EndpointArn\", must be one of: Text, LanguageCode",
  "errorType": "ParamValidationError",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 21, in lambda_handler\n    entities = client.detect_entities(\n",
    "  File \"/var/runtime/botocore/client.py\", line 316, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
    "  File \"/var/runtime/botocore/client.py\", line 607, in _make_api_call\n    request_dict = self._convert_to_request_dict(\n",
    "  File \"/var/runtime/botocore/client.py\", line 655, in _convert_to_request_dict\n    request_dict = self._serializer.serialize_to_request(\n",
    "  File \"/var/runtime/botocore/validate.py\", line 297, in serialize_to_request\n    raise ParamValidationError(report=report.generate_report())\n"
  ]
}

我在代码的前 4 行修复了这个错误:

#---The hack I found on Whosebug----
import sys
from pip._internal import main

main(['install', '-I', '-q', 'boto3', '--target', '/tmp/', '--no-cache-dir', '--disable-pip-version-check'])
sys.path.insert(0,'/tmp/')

#----------------------------------------

import json
import boto3

client = boto3.client('comprehend', region_name='us-east-1')

text = "Thats my nice text with different entities!"

entities = client.detect_entities(
            Text = text,
            LanguageCode = "de", #If you specify an endpoint, Amazon Comprehend uses the language of your custom model, and it ignores any language code that you provide in your request.
            EndpointArn = "arn:aws:comprehend:us-east-1:215057830319:entity-recognizer/MyFirstRecognizer"
)

但是,我仍然遇到一个无法修复的错误:

Response:
{
  "errorMessage": "An error occurred (ValidationException) when calling the DetectEntities operation: 1 validation error detected: Value 'arn:aws:comprehend:us-east-1:XXXXXXXXXXXX:entity-recognizer/MyFirstRecognizer' at 'endpointArn' failed to satisfy constraint: Member must satisfy regular expression pattern: arn:aws(-[^:]+)?:comprehend:[a-zA-Z0-9-]*:[0-9]{12}:entity-recognizer-endpoint/[a-zA-Z0-9](-*[a-zA-Z0-9])*",
  "errorType": "ClientError",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 25, in lambda_handler\n    entities = client.detect_entities(\n",
    "  File \"/tmp/botocore/client.py\", line 316, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
    "  File \"/tmp/botocore/client.py\", line 635, in _make_api_call\n    raise error_class(parsed_response, operation_name)\n"
  ]
}

如果我将 NodeJS 框架与给定端点一起使用,也会发生此错误。有趣的是,我发现的每个 ARN 端点(在教程中)看起来都和我的一模一样,并且与作为错误返回的正则表达式模式不匹配。

我不太确定是我在这里做错了什么,还是 AWS-Cloud(或 SDK)上的错误。也许有人可以重现此错误 and/or 找到解决方案(或甚至是 hack)对于这个问题

干杯

与模型 ARN 相比,端点 ARN 是不同的 AWS 资源。模型 ARN 指的是自定义模型,而端点托管该模型。在您的代码中,您传递的是 modelARN 而不是导致引发错误的 endpointARN。

您可以根据前缀区分这两个 ARN。

端点 arn - arn:aws:comprehend:us-east-1:XXXXXXXXXXXX:entity-recognizer-endpoint/xxxxxxxxxx

模型 arn - arn:aws:comprehend:us-east-1:XXXXXXXXXXXX:entity-recognizer/MyFirstRecognizer

您可以在文档页面上阅读有关 Comprehend 自定义端点及其定价的更多信息。 https://docs.aws.amazon.com/comprehend/latest/dg/detecting-cer-real-time.html