【问题标题】:Not able to get output result from Microsoft text analytics topic recognition无法从 Microsoft 文本分析主题识别中获取输出结果
【发布时间】:2017-03-06 21:17:18
【问题描述】:

我的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']

错误输出

开始主题检测。 Traceback(最近一次调用最后一次):

文件“./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/SampleCodehttps://docs.microsoft.com/en-us/azure/machine-learning/machine-learning-apps-text-analytics#topic-detection-apis

【问题讨论】:

    标签: python-2.7 azure-hub text-analytics-api


    【解决方案1】:

    您的输入格式似乎错误。应该是documents 而不是Inputs

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-23
      • 2013-06-12
      • 1970-01-01
      • 2015-09-10
      • 2023-01-12
      相关资源
      最近更新 更多