[英]IBM Watson Natural Language Understanding uploading multiple documents for analysis
[英]No module named 'ibm_watson.natural_language_understanding_v3'
我正在尝试使用 IBM Tone sentiment API,但在开始时遇到了困难。 我遵循https://cloud.ibm.com/apidocs/tone-analyzer?code=python中显示的文档。 运行以下代码后:
pip install --upgrade "ibm-watson>=6.0.0"
from ibm_watson import ToneAnalyzerV3
我收到以下错误: No module named 'ibm_watson.natural_language_understanding_v3'
即使在尝试访问Watson Tone Analyzer Customer Engagement 端点以访问 Natural Language Understanding ( https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-tone_analytics ) 时也是如此。 在页面上,它让我回到初始音调分析页面。
我将不胜感激有关如何在任何音调分析端点上开始使用 IBM 的指导
我建议直接使用 NLU 模块。 如果你 go 到REST API NLU Tone 文档,在右侧你可以看到你可以使用的示例代码。
它还在链接中解释了如何使用替代音调分析器的音调 model。
基本上,您需要参考 model tone-classifications-XX-v1
,其中 XX 是en
或fr
。
这是一些示例代码和基于文档的 output。
API
和URL
为NLU实例服务页面->管理选项卡中的值。
import json
from ibm_watson import NaturalLanguageUnderstandingV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_watson.natural_language_understanding_v1 import Features, ClassificationsOptions
apikey = 'APIKEY'
url = 'URL'
# Only 'en' and 'fr' available at the time of writing this.
language = 'en'
tone_model = f'tone-classifications-{language}-v1'
text = 'This is awesome! Thanks a lot! I am so happy this solved my problem.'
authenticator = IAMAuthenticator(apikey)
nlu = NaturalLanguageUnderstandingV1(
version='2022-04-07',
authenticator=authenticator
)
nlu.set_service_url(url)
response = nlu.analyze(
text=text,
features=Features(classifications=ClassificationsOptions(model=tone_model))).get_result()
print(json.dumps(response, indent=2))
这应该生成如下内容:
{
"usage": {
"text_units": 1,
"text_characters": 68,
"features": 1
},
"language": "en",
"classifications": [
{
"confidence": 0.867106,
"class_name": "satisfied"
},
{
"confidence": 0.729703,
"class_name": "excited"
},
{
"confidence": 0.283219,
"class_name": "polite"
},
{
"confidence": 0.154289,
"class_name": "sympathetic"
},
{
"confidence": 0.029122,
"class_name": "sad"
},
{
"confidence": 0.013206,
"class_name": "frustrated"
},
{
"confidence": 0.005977,
"class_name": "impolite"
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.