Databricks 认知服务:名称 'TextSentiment' 未定义

Databricks Cognitive Services: name 'TextSentiment' is not defined

我正在尝试使用以下指南实施认知服务 https://docs.microsoft.com/en-us/azure/cognitive-services/big-data/getting-started

我已经实现了示例代码:

from mmlspark.cognitive import *
from pyspark.sql.functions import col

# Add your subscription key from the Language service (or a general Cognitive Service key)
service_key = "ADD-SUBSCRIPTION-KEY-HERE"

df = spark.createDataFrame([
  ("I am so happy today, its sunny!", "en-US"),
  ("I am frustrated by this rush hour traffic", "en-US"),
  ("The cognitive services on spark aint bad", "en-US"),
], ["text", "language"])

sentiment = (TextSentiment()
    .setTextCol("text")
    .setLocation("eastus")
    .setSubscriptionKey(service_key)
    .setOutputCol("sentiment")
    .setErrorCol("error")
    .setLanguageCol("language"))

results = sentiment.transform(df)

# Show the results in a table
display(results.select("text", col("sentiment")[0].getItem("score").alias("sentiment")))

我已经安装了库 Azure:mmlspark:0.17

但我一直收到错误消息:

name 'TextSentiment' is not defined

有什么想法吗?

我发现目前只有一种集群类型可以使本教程正常运行,即 Databricks Runtime 版本:6.4 扩展支持(包括 Apache Spark 2.4.5、Scala 2.11) 因为该库仅支持运行时版本 7.0 或更低版本。此外,您似乎需要将最新版本的库安装到集群上,如下所示:

坐标: com.microsoft.ml.spark:mmlspark_2.11:1.0.0-rc3
存储库: https://mmlspark.azureedge.net/maven

见截图。