python - 使用 Watson SDK API 的主题建模示例

标签 python machine-learning nlp ibm-watson topic-modeling

我有一份将在不同时间点在线上传的文档列表。我没有任何有关内容的先验信息,也没有关于可以分配给文档的可能标签的任何信息,也没有任何历史数据(因此我无法使用 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/

相关文章:

python - 获取 pytorch 数据集的子集

python - 是否可以防止python的http.client.HTTPResponse.read()在没有数据时挂起?

python - 根据记录的大小/数量删除 Pandas 记录的优雅方式

python - 如何比较两个彩色图像之间的相似性?

java - 如何用OpenNLP实现阿尔巴尼亚语的命名实体识别?

python - 根据文本与 LDA 主题/特征簇的相似性对文本进行分组

twitter - 关于情感分析的自然语言处理工具列表 - 您推荐哪一个

python - 无法理解为什么正常停止线程会在Windows下的(wx)Python中挂起该线程的其余执行代码

python - 我如何将数据保存在文本文件python中

python - 为什么需要 "prediction space"?