Hello everyone,
I am new to NLP and fastai. I was trying to follow along with Chapter 10 in the fastai book, but instead of using the IMDB reviews, I wanted to use reddit data. The corpus itself is very large. When I try to create a dataloader, it gives me the following error:
Process Process-1:
Traceback (most recent call last):
File "/home/jayanth/anaconda3/envs/fastai_nlp/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/home/jayanth/anaconda3/envs/fastai_nlp/lib/python3.8/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/jayanth/anaconda3/envs/fastai_nlp/lib/python3.8/site-packages/fastcore/parallel.py", line 118, in _f_pg
for i,b in enumerate(obj(batch)): queue.put((start_idx+i,b))
File "/home/jayanth/anaconda3/envs/fastai_nlp/lib/python3.8/site-packages/fastai/text/core.py", line 136, in <genexpr>
return (L(o).map(self.post_f) for o in self.tok(maps(*self.rules, batch)))
File "/home/jayanth/anaconda3/envs/fastai_nlp/lib/python3.8/site-packages/fastai/text/core.py", line 122, in <genexpr>
return (L(doc).attrgot('text') for doc in self.pipe(map(str,items), batch_size=self.buf_sz))
File "/home/jayanth/anaconda3/envs/fastai_nlp/lib/python3.8/site-packages/spacy/language.py", line 829, in pipe
for doc in docs:
File "/home/jayanth/anaconda3/envs/fastai_nlp/lib/python3.8/site-packages/spacy/language.py", line 814, in <genexpr>
docs = (self.make_doc(text) for text in texts)
File "/home/jayanth/anaconda3/envs/fastai_nlp/lib/python3.8/site-packages/spacy/language.py", line 464, in make_doc
raise ValueError(
ValueError: [E088] Text of length 25282131 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)`.
It seems the number of characters in my corpus of text is higher than what the SpacyTokenizer can handle. I searched online for a solution and it seems the most suggested solution is to:
nlp = spacy.load('en_core_web_sm')
nlp.max_length = 10**10
I tried running this line of code before I created my datablock and it still didn’t fix it.
I looked through fastai2/text/core.py and it seems the SpacyTokenizer class initiates by:
nlp = spacy.blank('en', disable=["parser", "tagger", "ner"])
I tried doing
nlp = spacy.blank('en', disable=["parser", "tagger", "ner"])
nlp.max_length = 10**10
And it still didn’t fix this. How can I fix this? I appreciate any pointers. Thanks!
EDIT : To clarify, the max_length still remains 10**6.