自然语言理解(NLU)没有概念返回

时间:2019-02-28 13:42:01

标签: ibm-cloud ibm-watson watson-nlu

我正在使用IBM Watson自然语言理解(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的方式有问题?

1 个答案:

答案 0 :(得分: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"
    }
]

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