使用 SpaCy 标记 12GB xml 时内存不足

问题描述 投票:0回答:1

我正在尝试在 xml 中标记 12GB 的文本。该文件仅包含“内容词”,没有停用词。我正在尝试实现一个函数,以便通过文本块进行标记并清理 RAM。 (我有酷睿 i7 和 32GB RAM)

我尝试了以下方法但没有成功;

from spacy.util import minibatch
import spacy

nlp = spacy.load("es_core_news_sm")
nlp.disable_pipes('tok2vec', 'morphologizer', 'parser', 'senter', 'attribute_ruler', 'lemmatizer', 'ner')

def tokenizer(corpus_file):
    all_tokens = []

    with open(corpus_file, 'r', encoding='utf-8') as file:
        for batch in minibatch(file, size=100):
            docs = nlp.pipe(batch)
            for doc in docs:
                tokens = [token.text for token in doc if not token.is_space]
                all_tokens.extend(tokens)
    return all_tokens
nlp spacy tokenize
1个回答
0
投票

官方解决方案将随即将发布的版本 4 一起提供。请参阅 https://github.com/explosion/spaCy/issues/11295#event-7177460322 .

你必须处理你的技巧,例如,将其分解成更小的部分。

© www.soinside.com 2019 - 2024. All rights reserved.