NLPretext 概述
NLPretext 由 4 个模块组成:基本模块、社交模块、标记模块和增强模块。.
它们都包含不同的功能,用于处理最重要的文本预处理任务。.
基本预处理
基本模块是一个横向功能目录,可用于任何情况。它们可以处理
from nlpretext.basic.preprocess import replace_emails
示例 = “我已将这封邮件转发至 obama@whitehouse.gov”
example = replace_emails(example, replace_with=”*EMAIL*”)
打印(示例)
# “我已将此邮件转发给 *EMAIL*”
示例 = “我已将这封邮件转发至 obama@whitehouse.gov”
example = replace_emails(example, replace_with=”*EMAIL*”)
打印(示例)
# “我已将此邮件转发给 *EMAIL*”
社会预处理
"(《世界人权宣言》) 社会 该模块包含一系列在处理社会 data 时非常有用的便捷功能,例如
从 nlpretext.social.preprocess 导入 extract_emojis
示例 = “我爱护我的皮肤 😀”
example = extract_emojis(example)
print(example) #[‘:grinning_face:’] 打印(示例
示例 = “我爱护我的皮肤 😀”
example = extract_emojis(example)
print(example) #[‘:grinning_face:’] 打印(示例
文本增强
扩增模块可帮助您根据给定示例生成新文本,方法是修改初始文本中的某些单词,并保持相关实体不变(如果有的话),以完成 NER 任务。如果您希望实体以外的词保持不变,可以在停止词参数中指定。修改取决于所选的方法,模块目前支持的方法是使用同义词替换 Wordnet 或 nlpaug 库中的 BERT。.
创建端到端管道
默认管道
我们的程序库提供了一个预处理器对象,用于有效地管理所有预处理操作。.
如果您需要保留文本的所有元素,并执行最低限度的清理,请使用默认管道。它能对空白进行规范化处理,删除换行符,修复 unicode 问题,并删除社交 data 中经常出现的人工痕迹,如提及、标签和 HTML 标记。.
从 nlpretext 导入预处理器
text = “I just got the best dinner in my life @latourdargent !!!!我推荐 😀 #food #paris n”
预处理器 = 预处理器()
text = preprocessor.run(text) print(text)
# “我刚刚吃到了人生中最美味的晚餐!!我推荐”!我推荐"
定制管道
如果你对预处理管道中需要的预处理功能有清晰的概念,你可以在自己的预处理器中添加这些功能。.
从 nlpretext 导入预处理器
from nlpretext.basic.preprocess import (normalize_whitespace, remove_punct, remove_eol_characters, remove_stopwords, lower_text)
从 nlpretext.social.preprocess 导入 remove_mentions、remove_hashtag、remove_emoji
text = "I just got the best dinner in my life @latourdargent !!!!我推荐 😀 #food #paris n"
预处理器 = 预处理器()
preprocessor.pipe(lower_text)
preprocessor.pipe(remove_mentions)
preprocessor.pipe(remove_hashtag)
preprocessor.pipe(remove_emoji)
preprocessor.pipe(remove_eol_characters)
preprocessor.pipe(remove_stopwords, args=)
preprocessor.pipe(remove_punct)
preprocessor.pipe(normalize_whitespace)
text = preprocessor.run(text) print(text) # "推荐晚餐生活"
安装 NLPretext
要安装程序库,请运行
pip install nlpretext

博客






