text = u" LAC是个优秀的分词工具" 报错
- Dominant language
- C++
- Stars
- 4k
- Forks
- 592
- PR merge metrics
- No merged PRs in 30d
Description
text = u" LAC是个优秀的分词工具" 报错 输入有连续空格(或者tab出来的空格)报错,尽管用户可以自行对输入过滤,但实际情况总有可能会有这种情况出现,希望能有所处理。

from LAC import LAC
# 装载词语重要性模型
lac = LAC(mode='rank')
# 单个样本输入,输入为Unicode编码的字符串
text = u" LAC是个优秀的分词工具"
rank_result = lac.run(text)
---------------------------------------------------------------------------IndexError Traceback (most recent call last) in
6 # 单个样本输入,输入为Unicode编码的字符串
7 text = u" LAC是个优秀的分词工具"
----> 8 rank_result = lac.run(text)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/LAC/lac.py in run(self, texts)
79 if mode=='rank', 返回分词,词性,词语重要性结果
80 """
---> 81 return self.model.run(texts)
82
83 def train(self, model_save_dir, train_data, test_data=None, iter_num=10, thread_num=10):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/LAC/models.py in run(self, texts)
335
336 rank_decode = self.predictor.run([tensor_words, crf_decode[0]])
--> 337 weight = self.parse_result(tags_for_rank, rank_decode[0], words_length)
338
339 for _ in range(len(result)):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/LAC/models.py in parse_result(self, tags_for_rank, result, words_length)
369 weight_out.append(weight[ind])
370 continue
--> 371 weight_out[-1] = max(weight_out[-1], weight[ind])
372
373 batch_out.append(weight_out)
IndexError: list index out of range
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure with LAC in rank mode using the shown input containing leading spaces or tabs. Start at LAC/lac.py run and follow the traceback into models.py run and parse_result; the work is done when this input is handled without IndexError and returns a ranking result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100