无法从 Microsoft 文本分析主题识别中获取输出结果

Not able to get output result from Microsoft text analytics topic recognition

我的rawdata.json文件

{"Inputs":[
    {"Id":"1","Text":"I loved the food at this restaurant"},
    {"Id":"2","Text":"I loved the food at sadthis restaurant"},
    {"Id":"3","Text":"I loved the food at tsadhis restaurant"},
......,   
    {"Id":"100","Text":"I hated the decor"}
],
"StopPhrases":[
    "restaurant", “visitor"
]}

我在我的模块中阅读了这个文件

file_path = '/home/sujith/pylzdata/rawdata.json'
f = open(file_path, 'r')
input_texts = f.read()

还有这个

print('Starting topic detection.')
uri = base_url + 'text/analytics/v2.0/topics'
req = urllib2.Request(uri, input_texts, headers)
response_headers = urllib2.urlopen(req).info()
uri = response_headers['operation-location']

错误输出

开始主题检测。 追溯(最近一次通话最后一次):

文件“./lzdata.py”,第 25 行,在

response_headers = urllib2.urlopen(req).info()

文件“/usr/lib/python2.7/urllib2.py”,第 127 行,在 urlopen

return _opener.open(url, data, timeout)

文件“/usr/lib/python2.7/urllib2.py”,第 410 行,打开

response = meth(req, response)

文件“/usr/lib/python2.7/urllib2.py”,第 523 行,在 http_response

'http', request, response, code, msg, hdrs)

文件“/usr/lib/python2.7/urllib2.py”,第 448 行,错误

return self._call_chain(*args)

文件“/usr/lib/python2.7/urllib2.py”,第 382 行,在 _call_chain

result = func(*args)

文件“/usr/lib/python2.7/urllib2.py”,第 531 行,在 http_error_default

raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

urllib2.HTTPError:HTTP 错误 400:错误请求

来源:https://text-analytics-demo.azurewebsites.net/Home/SampleCode, https://docs.microsoft.com/en-us/azure/machine-learning/machine-learning-apps-text-analytics#topic-detection-apis

看来你的输入格式有误。应该是 documents 而不是 Inputs:

{
     "documents": [  
         {
             "id": "1",
             "text": "First document"
         },
         ...
         {
             "id": "100",
             "text": "Final document"
         }
     ],
     "stopWords": [
         "issue", "error", "user"
     ],
     "stopPhrases": [
         "Microsoft", "Azure"
     ]
}

有关详细信息,请参阅以下博客 post - https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/quick-start