问题描述
我尝试使用我刚刚在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",line 607,in _make_api_call\n request_dict = self._convert_to_request_dict(\n",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"
]
}
#---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",line 25," File \"/tmp/botocore/client.py\",line 635,in _make_api_call\n raise error_class(parsed_response,operation_name)\n"
]
}
如果我使用给定端点的NodeJS框架,也会发生此错误。我应该提到的有趣的事情是,我(在教程中)发现的每个ARN端点看起来都和我的完全一样,并且与作为错误返回的regex模式不匹配。
我不确定在这里是否做错了什么,或者这是否是AWS-Cloud(或SDK)上的错误。也许有人可以重现此错误和/或找到解决方案(甚至是黑客)。对于这个问题
欢呼
解决方法
与模型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
您可以在文档页面上了解有关理解自定义端点及其定价的更多信息。 https://docs.aws.amazon.com/comprehend/latest/dg/detecting-cer-real-time.html