我昨天成功地训练了我自己的 NLP AutoML 模型。我能够在 GCP 控制台中进行非常准确的预测。一切都进行得很顺利。今天我一直在尝试根据这个示例从 Java 客户端进行预测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 作为计算区域。
奇怪的是,我还使用 Java 客户端进行 Google NLP 情绪分析,它可以正常工作并立即返回响应(基于此示例https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/language/云客户端/src/main/java/com/example/language/QuickstartSample.java)
两个客户端都连接到同一个 GCP 项目(具有相同的 projectId),但其中只有一个正常工作。
你知道什么可能是错的吗?
提前感谢您的任何提示
这是代码:
公共类 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());
}
}
}