smoothnlp / SmoothNLP

专注于可解释的NLP技术 An NLP Toolset With A Focus on Explainable Inference
GNU General Public License v3.0
624 stars 112 forks source link

分词或者NER经常出现的错误:TypeError: string indices must be integers #24

Closed DenseAI closed 4 years ago

DenseAI commented 4 years ago

text = '香港(简称港,雅称香江;英语:Hong Kong,缩写作HK、HKSAR)是中华人民共和国两个特别行政区之一,位于南海北岸、珠江口东侧,北接广东省深圳市,西面与邻近的澳门特别行政区相距63公里,其余两面与南海邻接。全境由香港岛、九龙和新界组成,其中香港岛北部最为发达;' result = smoothnlp.ner(text)

出现一下错误: Traceback (most recent call last): File "F:/Research/Github/deep-learning-and-nlp/pkuseg/smoothnlp_try.py", line 71, in result = smoothnlp.ner(text) File "D:\Programs\Continuum\anaconda3\lib\site-packages\smoothnlp\utils__init.py", line 26, in trycatch return func(text) File "D:\Programs\Continuum\anaconda3\lib\site-packages\smoothnlp\utils\init.py", line 35, in toJson res = func(text) File "D:\Programs\Continuum\anaconda3\lib\site-packages\smoothnlp\init.py", line 64, in ner return nlp.ner(text) File "D:\Programs\Continuum\anaconda3\lib\site-packages\smoothnlp\server\init__.py", line 22, in ner return self.result['entities'] TypeError: string indices must be integers

victorzhrn commented 4 years ago

感谢您的反馈.

出错的原因是这样的, 在0.2.16版本之前, 我们对每一个基础功能做了字符串的长度限制, 限制为100. 目前已经改为两百, 此外. 在0.2.20版本后, 正式提供依赖标点的切句功能, 对于您提出的case, 建议切句后再运行基础pipeline.

注意, 在0.2.20版本调整后, 以下基础Pipeline功能仅对字符串长度做出了限制(不超过200). 如对较长corpus进行处理, 请先试用smoothnlp.split2sentences 进行切句预处理

示例:

import smoothnlp
smoothnlp.split2sentences("句子1!句子2!")
> ['句子1!', '句子2!']