word2vecで大規模のテキストデータを解析しようと以下のプログラムを実行しましたが、
#テキストデータの前処理
import spacy
nlp = spacy.load("ja_ginza")
#名詞、動詞、形容詞のみ抽出
include_pos = ('NOUN', 'VERB', 'ADJ')
#不要語を指定
stopwords = ('する', 'ある', 'ない', 'いう', ' ','もの', 'こと', 'よう','ため', 'なる', '\u3000', '\n', 'ほう', 'いる', 'くる')
def extract_words(sent, pos_tags, stopwords):
words = [token.lemma_ for token in sent
if token.pos_ in pos_tags and token.lemma_ not in stopwords]
return words
doc = nlp(text)
sents = [extract_words(sent, include_pos, stopwords)
for sent in doc.sents]
その過程で、以下の様なエラーが起こってしまいました。
ValueError: [E088] Text of length 1955617 exceeds maximum of 1000000. The 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=1955617
を追加して実行したところ、以下のエラーが起こってしまいました。これはどうすれば解決できますか?
Exception: Tokenization error: Input is too long, it can't be more than 49149 bytes, was 5813534
なお、実行環境はGoogle Colabratoryで、以下の記事を参考にしました。