我尝试使用我刚刚在 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)
干杯