0

我正在使用 IBM Watson Natural Language Understanding (NLU) API 提取概念。对于大多数文本,它能够提取至少 1 或 2 个概念,但是在一些简单的情况下,它不会返回任何概念。

from watson_developer_cloud import NaturalLanguageUnderstandingV1
from watson_developer_cloud.natural_language_understanding_v1 import Features, CategoriesOptions, ConceptsOptions, RelationsOptions

natural_language_understanding = NaturalLanguageUnderstandingV1( version='2018-11-16', iam_apikey='API-KEY', url='https://gateway.watsonplatform.net/natural-language-understanding/api')

post ="No job Never had any romantic experiences I just have no ability / infrastructure to get through life It's killing me I don't want to be part of this world because I can't fit in, can't compete, can't enjoy Why does it have to be so uncomfortable? I feel so sad on the inside Another night I wonder how it will ever change, will it require my effort completely? I DON'T KNOW WHAT TO FUCKING DO"

response = natural_language_understanding.analyze(
    text=post, features=Features(
            concepts=ConceptsOptions(limit=10))).get_result()

响应变量中返回的结果是

{'concepts': [], 'language': 'en', 'usage': {'features': 1, 'text_characters': 393, 'text_units': 1}}

这是我不知道的 API 的已知限制,还是我调用 API 的方式存在问题?

4

1 回答 1

0

对于相同的文本,我可以从具有相同限制和相同版本日期的 API 中获得以下概念作为输出。

"concepts": [
    {
        "text": "Existentialism",
        "relevance": 0.988784,
        "dbpedia_resource": "http://dbpedia.org/resource/Existentialism"
    },
    {
        "text": "The Brothers Karamazov",
        "relevance": 0.856152,
        "dbpedia_resource": "http://dbpedia.org/resource/The_Brothers_Karamazov"
    },
    {
        "text": "Fyodor Dostoyevsky",
        "relevance": 0.83996,
        "dbpedia_resource": "http://dbpedia.org/resource/Fyodor_Dostoyevsky"
    },
    {
        "text": "Human condition",
        "relevance": 0.716108,
        "dbpedia_resource": "http://dbpedia.org/resource/Human_condition"
    },
    {
        "text": "Psychology",
        "relevance": 0.687781,
        "dbpedia_resource": "http://dbpedia.org/resource/Psychology"
    },
    {
        "text": "Philosophy of life",
        "relevance": 0.675628,
        "dbpedia_resource": "http://dbpedia.org/resource/Philosophy_of_life"
    },
    {
        "text": "Meaning of life",
        "relevance": 0.65926,
        "dbpedia_resource": "http://dbpedia.org/resource/Meaning_of_life"
    },
    {
        "text": "Human nature",
        "relevance": 0.652501,
        "dbpedia_resource": "http://dbpedia.org/resource/Human_nature"
    }
]

您能否为任何著名的地方传递一些维基百科文本,以验证您是否在输出中完全返回了概念。还要确保在向 API 发送信息时没有设置任何默认语言。在大多数情况下,如果文本超过 100 个字符,NLU 会自动检测语言。例如,如果您将语言设置为西班牙语(es),它可能会调用西班牙语概念引擎,您可能会得到很少甚至没有结果。

于 2019-02-28T15:39:59.760 回答