python - 使用 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 发现或 NLU 服务?我正在使用 python SDK API,一个示例/任何相关链接都会非常有帮助。谢谢
解决方案
我认为 Watson Natural Language Understanding 服务的categories
或concepts
特性是最合适的。您不能直接使用 API 发送文档,因此您需要提取文本,但如果您能够这样做,那么:
摘自 API Docs 页面的示例
from ibm_watson import NaturalLanguageUnderstandingV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_watson.natural_language_understanding_v1
import Features, ConceptsOptions, CategoriesOptions
authenticator = 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
推荐阅读
- sql-server - SQL Server 中公式的动态计算
- go - 并行运行基准测试,即模拟同时请求
- node.js - Node Express Gateway 多个 API 端点
- verilog - 为什么一旦测试台进入 fr_count 条件块,我的“数据”寄存器变量会重置为 0?
- python - Openpyxl 没有写入我的 Excel 电子表格
- scala - 在这种情况下我可以避免变异吗?
- php - 2 如何改变'X' col。如果表格的每一行表示在单独的 HTML 表单中,并且每个提交按钮更改“X”值,则单击一次表格的值?
- android - Android Sqlite onupgrade 从数据库中删除表
- java - 有没有办法在到期时重建ehcache
- angular - 使用 AngularJS 在 Firebase 实时数据库中使用 .indexOn 规则过滤数据