问题描述
昨天我成功地训练了自己的NLP AutoML模型.我能够在GCP控制台中做出非常准确的预测.一切运行顺利.今天,我一直在尝试根据此示例 https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/language/automl/src/main/java/com/google/cloud/language/samples/PredictionApi.java
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
我使用了从GCP控制台复制的正确的projectId和modelId,但是我一直在等待结果.即使过了几分钟,仍然没有任何反应.没有异常被抛出.我使用europe-west3作为computeRegion.
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.
奇怪的是,我还使用Java客户端进行Google NLP情感分析,并且它可以正常工作并立即返回响应(基于此示例 https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/language/cloud-client/src/main/java/com/example/language/QuickstartSample.java )
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)
两个客户端都连接到相同的GCP项目(具有相同的projectId),但是其中只有一个可以正常工作.
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?
在此先感谢您的提示
这是代码:
公共类PredictionApi {
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());
}
}
}
推荐答案
europe-west3
不支持.当前在us-central1
中提供所有训练有素的automl模型.理论上,您应该会收到一些错误,例如您在.我很惊讶您没有收到来自服务器的任何错误消息.您介意分享您的客户端代码吗?
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?
这篇关于Java Google AutoML NLP客户端永远等待响应(不会引发异常)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!