我有一份将在不同时间点在线上传的文档列表。我没有任何有关内容的先验信息,也没有关于可以分配给文档的可能标签的任何信息,也没有任何历史数据(因此我无法使用 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 Natural Language Understanding 服务的类别
或概念
功能最适合。您无法直接使用 API 发送文档,因此您需要提取文本,但如果您能够做到这一点,那么:
从 API 文档页面抄袭的示例
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
关于python - 使用 Watson SDK API 的主题建模示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59880433/