NotImplementedError: 不再支持 lemmatize 参数

我在自己的类似 gpt2 模型上运行了代码,但得到了下面的错误。如何解决这个 Python 中的实现错误。

corpus = WikiCorpus(file_path, lemmatize=False, lower=False, tokenizer_func=tokenizer_func)  File "C:\Rayi\python\text-generate\text-gene\lib\site-packages\gensim\corpora\wikicorpus.py", line 619, in __init__    raise NotImplementedError(NotImplementedError: The lemmatize parameter is no longer supported. If you need to lemmatize, use e.g. <https://github.com/clips/pattern>. Perform lemmatization as part of your tokenization function and pass it as the tokenizer_func parameter to this initializer.
import tensorflow as tffrom gensim.corpora import WikiCorpusimport osimport argparse# lang = 'bn'def store(corpus, lang):    base_path = os.getcwd()    store_path = os.path.join(base_path, '{}_corpus'.format(lang))    if not os.path.exists(store_path):        os.mkdir(store_path)    file_idx=1    for text in corpus.get_texts():        current_file_path = os.path.join(store_path, 'article_{}.txt'.format(file_idx))        with open(current_file_path, 'w' , encoding='utf-8') as file:            file.write(bytes(' '.join(text), 'utf-8').decode('utf-8'))        #endwith        file_idx += 1    #endfordef tokenizer_func(text: str, token_min_len: int, token_max_len: int, lower: bool) -> list:    return [token for token in text.split() if token_min_len <= len(token) <= token_max_len]def run(lang):    origin='https://dumps.wikimedia.org/{}wiki/latest/{}wiki-latest-pages-articles.xml.bz2'.format(lang,lang)    fname='{}wiki-latest-pages-articles.xml.bz2'.format(lang)    file_path = tf.keras.utils.get_file(origin=origin, fname=fname, untar=False, extract=False)    corpus = WikiCorpus(file_path, lemmatize=True, lower=False, tokenizer_func=tokenizer_func)    store(corpus, lang)if __name__ == '__main__':    ARGS_PARSER = argparse.ArgumentParser()    ARGS_PARSER.add_argument(        '--lang',        default='en',        type=str,        help='language code to download from wikipedia corpus'    )    ARGS = ARGS_PARSER.parse_args()    run(**vars(ARGS))

回答:

我找不到这个函数的任何实际文档,只找到了一些示例页面。

我所做的只是调用:

corpus = WikiCorpus(file_path, tokenizer_func=tokenizer_func)

如果你仍然想进行词形还原,可以在 tokenizer_func 中调用一些词形还原函数,正如错误消息中所描述的。

现在需要等待大约8小时来处理 😀

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注