1

I trained succesfully my own NLP AutoML model yesterday. I am able to do quite accurate predictions in GCP console. Everything ran smoothly. Today I have been trying to do prediction from Java client based on this example https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/language/automl/src/main/java/com/google/cloud/language/samples/PredictionApi.java

I use correct projectId and modelId that I copied from GCP console but I am waiting for result forever. Even after couple of minutes there is still no response. There is no exception thrown. I use europe-west3 as computeRegion.

Strange thing is that I also use Java client for Google NLP Sentiment Analysis and it works without problems and returns response immediately (based on this example https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/language/cloud-client/src/main/java/com/example/language/QuickstartSample.java)

Both clients are connected to the same GCP project (have the same projectId) but only one of them is working properly.

Do you please have some clue what could be wrong?

Thank you in advance for any hints

This is the code:

public class PredictionApi {

public static void main(String[] args) throws IOException {
    PredictionApi predictionApi = new PredictionApi();
    predictionApi.predict("projectId", "us-central1", "modelId");
}

private void predict(String projectId, String computeRegion, String modelId) throws IOException {
    PredictionServiceClient predictionClient = PredictionServiceClient.create();
    ModelName name = ModelName.of(projectId, computeRegion, modelId);
    String content = "BERLIN Germany and China want to sign two agreements to deepen their cooperation in the financial sector later this week a German government document seen by Reuters showed on Wednesday";
    TextSnippet textSnippet =
            TextSnippet.newBuilder().setContent(content).setMimeType("text/plain").build();
    ExamplePayload payload = ExamplePayload.newBuilder().setTextSnippet(textSnippet).build();

    Map<String, String> params = new HashMap<String, String>();
    PredictResponse response = predictionClient.predict(name, payload, params);

    System.out.println("Prediction results:");
    for (AnnotationPayload annotationPayload : response.getPayloadList()) {
        System.out.println("Predicted Class name :" + annotationPayload.getDisplayName());
        System.out.println(
                "Predicted Class Score :" + annotationPayload.getClassification().getScore());
    }
}

}

Oliver Eder
  • 85
  • 2
  • 10

1 Answers1

0

europe-west3 is not supported. All trained automl models are currently served in us-central1. You should in theory receive some error like what you reported in another stackoverflow post. I am a bit surprised you didn't receive any error message from the server. Do you mind share your client side code?

bao
  • 176
  • 2
  • Hi Bao, thank you very much for your answer. So it helped in one case. After I changed computeRegion to us-central1 I am able to do prediction on my model in the google cloud examples cloned from Google GitHub account. But I have identical code also in my own project where I want to use this prediction API but in that project the same code (also with modified computeRegion value) still does not return any response or exception. Do you think that I miss something in my own project? (maybe in some settings, properties I dont know) I will paste the code in next comment Can you please have a look? – Oliver Eder Feb 05 '19 at 15:26
  • I built jar from GoogleCloudPlatform GitHub examples. When I run this jar from Windows command line I am able to successfully do predictions on my trained model. BUT when I use this jar as Maven dependency in my own NLP project and I call it from Java code, same problem occurs. I am waiting forever for prediction result and nothing happens (no exception is thrown). I really dont understand what can be wrong. – Oliver Eder Feb 17 '19 at 22:01