【发布时间】:2019-07-11 15:18:30
【问题描述】:
我正在尝试标记詹姆士国王圣经的文本文件,但是当我尝试它时出现内存错误。所以我把文本分成了多个对象。现在我想使用 spaCy 对对象进行标记,然后将它们重新组合成一个 doc 对象。我看到其他人谈论类似的问题并转换为数组,然后在组合数组后返回文档。这是否可以解决我的问题或以后创建新问题?
我尝试运行它,但 colab 和我的计算机都没有支持它的 RAM。
nlp_spacy = spacy.load('en')
kjv_bible = gutenberg.raw('bible-kjv.txt')
#pattern for bracketed text titles
bracks = "[\[].*?[\]]"
kjv_bible = re.sub(bracks, "", kjv_bible)
kjv_bible = ' '.join(kjv_bible.split())
len(kjv_bible)
kjv_bible_doc = nlp_spacy(kjv_bible)
ValueError Traceback (most recent call
last)
<ipython-input-19-385936fadd40> in <module>()
----> 1 kjv_bible_doc = nlp_spacy(kjv_bible)
/usr/local/lib/python3.6/dist-packages/spacy/language.py in
__call__(self, text, disable, component_cfg)
378 if len(text) > self.max_length:
379 raise ValueError(
--> 380 Errors.E088.format(length=len(text),
max_length=self.max_length)
381 )
382 doc = self.make_doc(text)
ValueError: [E088] Text of length 4305663 exceeds maximum of 1000000.
The v2.x parser and NER models require roughly 1GB of temporary memory
per 100,000 characters in the input. This means long texts may cause
memory allocation errors. If you're not using the parser or NER, it's
probably safe to increase the `nlp.max_length` limit. The limit is in
number of characters, so you can check whether your inputs are too
long by checking `len(text)`.
nlp.max_length = 4305663
kjv_bible_doc = nlp_spacy(kjv_bible)
由于RAM内存导致笔记本崩溃
这行得通吗
np_array = doc.to_array([LOWER, POS, ENT_TYPE, IS_ALPHA])
np_array.extend(np_array2)
doc2.from_array([LOWER, POS, ENT_TYPE, IS_ALPHA], np_array)
【问题讨论】:
标签: python python-3.x spacy doc