Entity recognition gcp custom model

275 Views Asked by At

I trained a custom model for named entity recognition using Automl service on GCP. Here is my code to run it using 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))

I get this internal error in predict function:

six.raise_from(exceptions.from_grpc_error(exc), exc) File "", line 3, in raise_from google.api_core.exceptions.InternalServerError: 500 Internal error encountered.

Can someone from GCP explain the source of error and how to fix it?

2

There are 2 best solutions below

0
On

Since you have received this Internal error, we would need to make sure that you are not hitting any of the Quota & Limits before submitting your issue to the product team on Issue Tracker

0
On

There is a problem with the text_content variable. It is not defined before you define text_snippet.

The result is when you call predict, your payload is empty (set to None):

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

Remember to uncomment and set the project_id and model_id variables because you need them to get the full model id that AutoML expects.