0

我尝试使用我刚刚在 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 stackoverflow----
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)上的一个错误。也许有人可以重现这个错误和/或找到解决这个问题的解决方案(甚至是 hack)

干杯

4

1 回答 1

1

与模型 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

于 2020-08-26T18:01:55.670 回答