实体识别gcp自定义模型

2024-04-29 16:14:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用GCP上的Automl服务训练了一个用于命名实体识别的自定义模型。 下面是我使用python运行它的代码:

from google.cloud import automl

# TODO(developer): Uncomment and set the following variables
# project_id = "YOUR_PROJECT_ID"
# model_id = "YOUR_MODEL_ID"
# content = "text to predict"

prediction_client = automl.PredictionServiceClient()

# Get the full path of the model.
model_full_id = automl.AutoMlClient.model_path(
    project_id, "us-central1", model_id
)


text_snippet = automl.TextSnippet(
    content=text_content, mime_type="text/plain"
)
payload = automl.ExamplePayload(text_snippet=text_snippet)

response = prediction_client.predict(name=model_full_id, payload=payload)

for annotation_payload in response.payload:
    print(
        "Text Extract Entity Types: {}".format(
            annotation_payload.display_name
        )
    )
    print(
        "Text Score: {}".format(annotation_payload.text_extraction.score)
    )
    text_segment = annotation_payload.text_extraction.text_segment
    print("Text Extract Entity Content: {}".format(text_segment.content))
    print("Text Start Offset: {}".format(text_segment.start_offset))
    print("Text End Offset: {}".format(text_segment.end_offset))

我在predict函数中得到这个内部错误:

6.从(例外情况。从grpc错误(exc),exc) 文件“”,第3行,从 google.api_core.exceptions.InternalServerError:遇到500个内部错误。

GCP的人能解释错误的来源以及如何修复它吗


Tags: thetextidformatmodel错误segmentannotation
2条回答

text_content变量有问题。 在定义文本片段之前未定义它

结果是,当您调用predict时,您的有效负载为空(设置为None):

text_snippet = { content: None, mime_type='text/plain'}

记住取消注释并设置project_idmodel_id变量,因为您需要它们来获取AutoML期望的完整模型id

由于您已收到此内部错误,我们需要确保您在Issue Tracker上向产品团队提交问题之前没有碰到任何Quota & Limits

相关问题 更多 >