Databricks认知服务:name' textsentiment'未定义
我已经实现了示例代码:
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
有什么想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现当前,只有一种群集类型可以使本教程工作是 databricks运行时版本: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.azuredge.net/maven
请参阅屏幕截图。
I found that currently, there is only one cluster type that can make this tutorial work which is Databricks Runtime Version: 6.4 Extended Support (includes Apache Spark 2.4.5, Scala 2.11) as the library supports only Runtime Version 7.0 or below. Also, It seems that you need to install the latest version of the library onto the cluster as follows:
Coordinate:
com.microsoft.ml.spark:mmlspark_2.11:1.0.0-rc3
Repository:
https://mmlspark.azureedge.net/maven
See the screenshot.
