问题
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());
}
}
}
回答1:
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?
来源:https://stackoverflow.com/questions/54237611/java-google-automl-nlp-client-waiting-forever-for-response-no-exception-thrown