我运行这段代码是为了在我的模型中输入文本之前先处理它。
并得到了RecursionError:最大递归深度的比较
train_text是一个python系列,包含文本词干是来自nltk库的PorterStemmer对象。
train_corpus = []
for i in range(0, len(train_text)):
data = re.sub("[^a-zA-Z]", ' ', train_text[i]).lower().split()
data = [ps.stem(word) for word in data if not word in set(stopwords.words("english"))]
data = ' '.join(data)
train_corpus.append(data)RecursionError Traceback (most recent call last)
<ipython-input-25-4a8646f33f6f> in <module>()
57 for i in range(0, len(train_text)):
58 data = re.sub("[^a-zA-Z]", ' ', train_text[i]).lower().split()
---> 59 data = [ps.stem(word) for word in data if not word in set(stopwords.words("english"))]
60 data = ' '.join(data)
61 train_corpus.append(data)
<ipython-input-25-4a8646f33f6f> in <listcomp>(.0)
57 for i in range(0, len(train_text)):
58 data = re.sub("[^a-zA-Z]", ' ', train_text[i]).lower().split()
---> 59 data = [ps.stem(word) for word in data if not word in set(stopwords.words("english"))]
60 data = ' '.join(data)
61 train_corpus.append(data)
~\Anaconda3\lib\site-packages\nltk\stem\porter.py in stem(self, word)
665 stem = self._step1a(stem)
666 stem = self._step1b(stem)
--> 667 stem = self._step1c(stem)
668 stem = self._step2(stem)
669 stem = self._step3(stem)
....我能做些什么来解决这个问题?
谢谢。
发布于 2018-05-03 11:31:22
看起来它可以被文档:setrecursionlimit()赢得。
但是记住,递归并不是免费的--它消耗了memory_of_function_consumes * amount_of_circles_of_recursion --所以当您有大量递归运行时,您可以耗尽内存。这就是为什么这个限制是用Python硬编码的,我认为覆盖它是个坏主意。
https://stackoverflow.com/questions/50153832
复制相似问题