使用 Watson SDK API 进行主题建模示例

我有一系列文档,将在不同时间点上传到网上。我对文档的内容没有任何先验信息,也没有关于可能分配给这些文档的标签的任何信息,同时我也没有任何历史数据(因此我无法使用 Watson 自然语言分类器服务来训练分类器)。我希望对这些文档进行实时分类/主题分配。例如,我正在寻找类似于以下这样的 API:

service.getTopics('some text')

实时返回类似于以下内容:

"categories": [          {            "score": 0.949576,            "label": "/technology and computing/networking"          },          {            "score": 0.911692,            "label": "/technology and computing/networking/network monitoring and management"          },          {            "score": 0.879639,            "label": "/business and industrial/business operations/management"          }]

使用 Watson Discovery 或 NLU 服务是否可以实现?我正在使用 Python SDK API,示例或任何相关链接将非常有帮助。谢谢


回答:

我认为 Watson 自然语言理解服务的 categoriesconcepts 功能是最适合的。你不能直接通过 API 发送文档,因此你需要提取文本,但如果你能够做到这一点,那么:

从 API 文档页面借用的示例

from ibm_watson import NaturalLanguageUnderstandingV1from ibm_cloud_sdk_core.authenticators import IAMAuthenticatorfrom ibm_watson.natural_language_understanding_v1     import Features, ConceptsOptions, CategoriesOptionsauthenticator = IAMAuthenticator('{apikey}')natural_language_understanding = NaturalLanguageUnderstandingV1(    version='2019-07-12',    authenticator=authenticator)natural_language_understanding.set_service_url('{url}')response = natural_language_understanding.analyze(    text='IBM is an American multinational technology company '    'headquartered in Armonk, New York, United States, '    'with operations in over 170 countries.',    features=Features(        categories=CategoriesOptions(limit=5),        concepts=ConceptsOptions(limit=5))).get_result()

更多信息请参见 API 文档 – https://cloud.ibm.com/apidocs/natural-language-understanding/natural-language-understanding?code=python#categories

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注