Google cloud automl nlp - PullRequest
       52

Google cloud automl nlp

0 голосов
/ 03 октября 2019

Я пытаюсь обучить входящие сообщения, чтобы получить, если пользователю нужно что-то срочное или нет. В этом коде ниже я получаю оценку предсказания. Тем не менее, я хочу получить вероятность для каждого текста

{

    from google.cloud import automl_v1beta1 as automl
    # from automl_v1beta1 import ClassificationEvaluationMetrics.ConfidenceMetricsEntry
    from google.oauth2 import service_account

    credentials = service_account.Credentials.from_service_account_file('/Users/david.lerech/Downloads/fiverr-data-playground-ml-testing.json')

    automl_client = automl.AutoMlClient(credentials=credentials)

    # Create client for prediction service.
    prediction_client = automl.PredictionServiceClient(credentials=credentials)


    # Get the full path of the model.
    model_full_id = automl_client.model_path(
        project_id, compute_region, model_id
    )

    # Read the file content for prediction.
    with open(file_path, "rb") as content_file:
        snippet = content_file.read()

    # Set the payload by giving the content and type of the file.
    payload = {"text_snippet": {"content": snippet, "mime_type": "text/plain"}}
    # print (payload)

    # params is additional domain-specific parameters.
    # currently there is no additional parameters supported.
    params = {}

    response = prediction_client.predict(model_full_id, payload, params)
    print (response.payload)
    print("Prediction results:")
    for result in response.payload:
        print(result)
        print("Predicted class name: {}".format(result.display_name))
        print("Predicted class score: {}".format(result.classification.score))

}
...