我有一系列文档,将在不同时间点上传到网上。我对文档的内容没有任何先验信息,也没有关于可能分配给这些文档的标签的任何信息,同时我也没有任何历史数据(因此我无法使用 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 自然语言理解服务的 categories
或 concepts
功能是最适合的。你不能直接通过 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