Databricks认知服务:name' textsentiment'未定义

发布于 2025-01-28 16:27:35 字数 1131 浏览 5 评论 0 原文

我正在尝试使用以下指南实施认知服务

我已经实现了示例代码:

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

有什么想法吗?

I am trying to implement Cognitive Services using the following guide
https://learn.microsoft.com/en-us/azure/cognitive-services/big-data/getting-started

I have implemented the sample code:

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")))

I have installed the library Azure:mmlspark:0.17

But I keep on getting the error:

name 'TextSentiment' is not defined

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云裳 2025-02-04 16:27:35

我发现当前,只有一种群集类型可以使本教程工作是 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.
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文