沃森DSX得到“索引错误”,但码头木星env。不要
问题描述:
我在Watson DSX上运行以下Python脚本并出现错误。 (IndexError:列表索引超出范围)沃森DSX得到“索引错误”,但码头木星env。不要
(1)相同的程序在Docker Jupiter笔记本环境中正常运行。
(2)如果输入文件大小变小,在Waston DSX上正常运行。
请你告诉我是什么原因呢,和我应该怎么办不发生错误?
!pip install janome
data = get_object_storage_file_with_credentials_8b9fb794cc1049b09563d144c8861966('KITDemo', 'kusa-out.txt')
#data = get_object_storage_file_with_credentials_8b9fb794cc1049b09563d144c8861966('KITDemo', 'kusa2-out.txt')
txt = data.getvalue()
word_list = []
from janome.tokenizer import Tokenizer
t = Tokenizer()
for token in t.tokenize(txt, stream=True):
partOfSpeech = token.part_of_speech.split(',')[0]
if partOfSpeech == u'名詞':
word_list.append(token.surface)
以下是完整的堆栈跟踪。
IndexError Traceback (most recent call last)
<ipython-input-4-9a7681ae1aa6> in <module>()
2 from janome.tokenizer import Tokenizer
3 t = Tokenizer()
----> 4 for token in t.tokenize(txt, stream=True):
5 partOfSpeech = token.part_of_speech.split(',')[0]
6 if partOfSpeech == u'名詞':
答
IndexError: list index out of range
固定在JANOME版本0.3.6。 https://github.com/mocobeta/janome/blob/0.3.6/CHANGES.txt
请升级janome。如果升级后仍然有问题,请在此处创建问题。 https://github.com/mocobeta/janome/issues
您可以发布完整的堆栈跟踪? –
可能是在输入数据中,这导致标记生成器以产生空令牌,或触发IndexError本身的问题。您是否尝试过使用不同的大型输入数据集,或者只使用一个?也许通过在循环的开始打印'token'添加一些调试输出,例如。然后在打印完最后一个标记后检查输入数据。 –