【问题标题】:processing text with spacy nlp.pipe用 spacy nlp.pipe 处理文本
【发布时间】:2021-01-27 03:05:34
【问题描述】:

我正在使用下面的代码通过spacy nlp.pipe 处理 40,000 个摘要,这需要 8 分钟。有没有办法进一步加快速度?我还禁用了ner

nlp = spacy.load("en_core_web_md", disable=["ner"])

def process_abstract(df):
    cleaned_text = []
    document = list(nlp.pipe(df['abstract'].values))
    for doc in document:
        text = [token.text for token in doc 
                if token.is_punct==False and 
                token.is_stop==False and 
                token.like_num==False and 
                token.is_alpha==True
                ]
        cleaned_text.append(' '.join(text).lower())
    return cleaned_text

【问题讨论】:

    标签: python nlp spacy


    【解决方案1】:

    尝试调整 batch_sizen_process params

    def process_abstract(df):
        cleaned_text = []
        document = nlp.pipe(df["abstract"].to_list(), batch_size=256, n_process=12)
        for doc in document:
            text = [
                token.text
                for token in doc
                if not token.is_punct
                and not token.is_stop
                and not token.like_num
                and token.is_alpha
            ]
            cleaned_text.append(" ".join(text).lower())
        return cleaned_text
    

    另外请注意,加入 " " 您可能会有一些惊喜,因为 spaCy 的拆分规则比这要复杂一些。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 2018-06-29
      • 2020-05-18
      相关资源
      最近更新 更多