【已解决】Python调试Solr出错:ValueError: a must be 1-dimensional

栏目: 后端 · 发布时间: 6年前

内容简介:折腾:期间,出错:

折腾:

【已解决】合并基于搜索的兜底对话到产品Demo中

期间,出错:

【已解决】Python调试Solr出错:ValueError: a must be 1-dimensional

input:hi

http://localhost:8983/solr/qa/select?q=question_str%3A%22hi%22&fq=%2A%3A%2A+AND+scene%3Aqa&rows=1&fl=question%2Canswer%2Cid&wt=json&indent=false

http://localhost:8983/solr/qa/select?q=question%3A%22hi%22&fq=%2A%3A%2A+AND+scene%3Aqa&rows=100&fl=question%2Canswer%2Cid&wt=json&indent=false

Building prefix dict from the default dictionary …

Loading model from cache /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/jieba.cache

Loading model cost 1.271 seconds.

Prefix dict has been built succesfully.

Traceback (most recent call last):

File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1664, in

main()

File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1658, in main

globals = debugger.run(setup[‘file’], None, None, is_module)

File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1068, in run

pydev_imports.execfile(file, globals, locals)  # execute the script

File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile

exec(compile(contents+"\n", file, ‘exec’), glob, loc)

File "/Users/crifan/dev/dev_root/xxx/nlp/search/qa/iqa.py", line 168, in

main()

File "/Users/crifan/dev/dev_root/xx/nlp/search/qa/iqa.py", line 164, in main

print(reply.answer())

File "/Users/crifan/dev/dev_root/xxx/nlp/search/renderer/reply.py", line 85, in answer

answer = np.random.choice(self._answers)

File "mtrand.pyx", line 1122, in mtrand.RandomState.choice

ValueError: a must be 1-dimensional

所以要再去解决。

果然是:

【已解决】Python调试Solr出错:ValueError: a must be 1-dimensional

list的list,那么就去改为list

然后改为:

nlp/search/renderer/reply.py

def answer(self):

if isinstance(self._answers, list):

first_element = self._answers[0]

if isinstance(first_element, list):

# is list of list -> change to list

self._answers = first_element

if len(self._answers) == 0:

return None

if not self.counter:

answer = np.random.choice(self._answers)

else:

answer = self._answers[self.counter % len(self._answers)]

return self._inject(answer)

就可以了:

initing

model loaded

input:hi

http://localhost:8983/solr/qa/select?q=question_str%3A%22hi%22&fq=%2A%3A%2A+AND+scene%3Aqa&rows=1&fl=question%2Canswer%2Cid&wt=json&indent=false

Building prefix dict from the default dictionary …

http://localhost:8983/solr/qa/select?q=question%3A%22hi%22&fq=%2A%3A%2A+AND+scene%3Aqa&rows=100&fl=question%2Canswer%2Cid&wt=json&indent=false

Loading model from cache /var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/jieba.cache

Loading model cost 1.303 seconds.

Prefix dict has been built succesfully.

hi Carl !

input:say apple

http://localhost:8983/solr/qa/select?q=question_str%3A%22say+apple%22&fq=%2A%3A%2A+AND+scene%3Aqa&rows=1&fl=question%2Canswer%2Cid&wt=json&indent=false

http://localhost:8983/solr/qa/select?q=question%3A%22say+apple%22&fq=%2A%3A%2A+AND+scene%3Aqa&rows=100&fl=question%2Canswer%2Cid&wt=json&indent=false

apple .

input:next one

http://localhost:8983/solr/qa/select?q=question_str%3A%22next+one%22&fq=%2A%3A%2A+AND+scene%3Aqa&rows=1&fl=question%2Canswer%2Cid&wt=json&indent=false

You want the next bus. Is this correct?

【已解决】Python调试Solr出错:ValueError: a must be 1-dimensional


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

互联网+秋叶课堂:我的网课创业

互联网+秋叶课堂:我的网课创业

秋叶 / 北京:机械工业出版社 / 2016-3-1 / 39.0

在线教育被很多人视为 “互联网+”创业热潮中的下一个风口,越来越多的老师和创业者选择在线教育创业。本书作者秋叶老师2013年双11正式带一帮小伙伴开始在线教育创业,在短短两年内“从0到1”,累计做到了超500万元的销售业绩,成为国内Office领域在线教育运营最成功的团队之一。在这本书中秋叶老师结合自己的实战经历,向各位完整剖析了两年创业的真实复盘思考,是一本值得在线教育创业同行入手的必读书。 ......一起来看看 《互联网+秋叶课堂:我的网课创业》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具