最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Python crifan 11563浏览 0评论

折腾:

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

期间,出错:

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 <module>

    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 <module>

    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

所以要再去解决。

果然是:

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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 学习了
    搬瓦工vps6年前 (2019-01-29)回复
92 queries in 0.269 seconds, using 22.16MB memory