【问题标题】:Java Google AutoML NLP client waiting forever for response (no exception thrown)Java Google AutoML NLP 客户端永远等待响应(不抛出异常)
【发布时间】:2019-06-11 18:03:44
【问题描述】:

我昨天成功训练了自己的 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/cloud-client/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());
    }
}

}

【问题讨论】:

    标签: java google-cloud-platform google-natural-language google-cloud-automl


    【解决方案1】:

    europe-west3 不受支持。所有经过训练的 automl 模型目前都在 us-central1 中提供服务。理论上,您应该会收到一些错误,例如您在 another stackoverflow post 中报告的错误。我有点惊讶您没有收到来自服务器的任何错误消息。您介意分享您的客户端代码吗?

    【讨论】:

    • 您好,宝,非常感谢您的回答。所以它在一个案例中有所帮助。将 computeRegion 更改为 us-central1 后,我可以在从 Google GitHub 帐户克隆的 Google 云示例中对我的模型进行预测。但是我在自己的项目中也有相同的代码,我想使用这个预测 API,但在那个项目中,相同的代码(也具有修改的 computeRegion 值)仍然没有返回任何响应或异常。你认为我在自己的项目中遗漏了什么吗? (可能在某些设置,属性我不知道)我会在下一条评论中粘贴代码你能看看吗?
    • 我从 GoogleCloudPlatform GitHub 示例中构建了 jar。当我从 Windows 命令行运行这个 jar 时,我能够成功地对我训练有素的模型进行预测。但是当我在我自己的 NLP 项目中使用这个 jar 作为 Maven 依赖项并从 Java 代码中调用它时,会出现同样的问题。我一直在等待预测结果,但什么也没有发生(没有抛出异常)。我真的不明白有什么问题。
    猜你喜欢
    • 1970-01-01
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多