基于规则的明显噪声预过滤步骤,基于通用语言建模的差劲语言和基于特定语言建模的粗俗语言
项目描述
bicleaner-hardrules
硬规则Bicleaner(bicleaner-hardrules
)是基于规则、基于通用语言模型的低质量语言和基于特定语言模型的粗俗语言进行预过滤的步骤。它是Bicleaner的一部分。
安装与要求
Bicleaner hard-rules是用Python编写的,可以使用pip
安装。它还需要支持7-gram语言模型的KenLM Python绑定。您可以通过运行以下命令轻松安装:
pip install bicleaner-hardrules
pip install --config-settings="--build-option=--max_order=7" https://github.com/kpu/kenlm/archive/master.zip
从v1.3开始,hard-rules使用FastSpell,它需要python-dev
和libhunspell-dev
。
sudo apt install python-dev libhunspell-dev
默认使用的Hunspell词典会自动安装。如果您需要更改默认的语言识别配置,请参阅https://github.com/mbanon/fastspell#configuration。
安装后,二进制文件(bicleaner-hardrules
)将位于您的python/installation/prefix/bin
目录中。这通常是$HOME/.local/bin
或/usr/local/bin
。
从源代码安装
从源代码安装时,可以从克隆的仓库直接安装
git clone https://github.com/bitextor/bicleaner-hardrules
cd bicleaner-hardrules
pip install .
或从pip
安装
pip install bicleaner-hardrules --no-binary :all:
清洗
bicleaner-hardrules
旨在检测平行语料库中明显的噪声句子对。被认为是噪声的句子将标记为0
,其余的将标记为1
。
默认情况下,输入文件(要分类的平行语料库)必须至少包含两列,如下所示:
- col1:源句子
- col2:目标句子
但可以通过使用--scol
和--tcol
标志自定义源和目标句子列的索引,以防您有更多列。
生成的输出文件将包含与原始输入文件相同的行和列,并添加一个包含Bicleaner hard-rules标签的额外列。
此工具可以与以下参数一起运行:
bicleaner-hardrules [-h]
[--annotated_output]
-s SOURCE_LANG
-t TARGET_LANG
[--tmp_dir TMP_DIR]
[-b BLOCK_SIZE]
[-p PROCESSES]
[--run_all_rules]
[--disable_lang_ident]
[--disable_minimal_length]
[--scol SCOL]
[--tcol TCOL]
[--disable_lm_filter]
[--disable_porn_removal]
[--dont_ignore_long]
[--metadata METADATA]
[--lm_threshold LM_THRESHOLD]
[-q]
[--debug]
[--logfile LOGFILE]
[input]
[output]
参数
-
位置参数
input
:要分类的制表符分隔的文件(默认行格式:SOURCE_SENTENCE TARGET_SENTENCE [EXTRA_COLUMNS]
,制表符分隔)。当输入为-时,读取标准输入。output
:分类的输出(默认:标准输出)。当输出为-时,写入标准输出。
-
可选
--annotated_output
:为每个句子添加一个额外的列,包含每个句子的评估(如果句子很好,则“保留”,否则拒绝的原因(默认:False))--metadata METADATA
:训练元数据(YAML文件),由bicleaner-train
生成或下载作为语言包的一部分。您只需将您想要清理的语言对的语言包untar
即可。tar文件包含YAML元数据文件。有一个脚本可以下载和解包可用的语言包。例如,如果您计划清理英语到捷克语文件,可以使用
$ bicleaner-download en cs ./models
将英语-捷克语语言包下载到./models目录并解包。您还可以使用
bilceaner-ai-download
为Bicleaner AI模型,并将HF标识符提供给--metadata
参数,如果它是从那里下载的,如下所示bicleaner-hardrules --metadata "bitextor/bicleaner-ai-full-en-es" ...
有关详细信息,请参阅此处。
-S SOURCE_TOKENIZER_COMMAND
:源语言分词器的完整命令(包括所需的标志)。如果没有提供,则使用Sacremoses分词器(带有escape=False
选项)。-T TARGET_TOKENIZER_COMMAND
:目标语言分词器的完整命令(包括所需的标志)。如果没有提供,则使用Sacremoses分词器(带有escape=False
选项)。--scol SCOL
:源句子列(从1开始)(默认:3)--tcol TCOL
:目标句子列(从1开始)(默认:4)--tmp_dir TMP_DIR
:创建此程序的临时文件的临时目录(默认:默认系统临时目录,由Unix中的环境变量TMPDIR定义)-b BLOCK_SIZE, --block_size BLOCK_SIZE
:每个块中的句子对数量(默认:10000)-p PROCESSES, --processes PROCESSES
:要使用的进程数(默认:所有CPU减一)--lm_threshold LM_THRESHOLD
:语言模型流畅度评分的阈值。所有语言模型流畅度评分低于阈值的句子对将被移除(分类器评分设置为0),除非设置了选项 --keep_lm_result。默认:0.5-A
或--run_all_rules
:对每个句子运行所有规则,而不是在第一个被丢弃的规则处停止(默认:False)-c CONFIG.yml
或--config CONFIG.yml
:规则配置文件(默认:无)--disable_hardrules
:禁用bicleaner_hardrules过滤(仅应用bicleaner_classify)(默认:False)--disable_lm_filter
:禁用LM过滤。--disable_porn_removal
:禁用色情内容移除。--disable_minimal_length
:不应用最小长度规则(默认:False)。--dont_ignore_long
:不忽略长度超过10000个字符的句子(默认:False)。-h, --help
:显示此帮助信息并退出
-
日志记录
-q, --quiet
:静默日志模式(默认:False)--debug
:调试日志模式(默认:False)--logfile LOGFILE
:将日志存储到文件中(默认:stderr
)-v, --version
:显示此脚本的版本并退出
示例
bicleaner-hardrules \
corpus.en-es.raw \
corpus.en-es.classifed
这将读取 "corpus.en-es.raw
" 文件,进行标记并将结果写入 corpus.classified
。新文件中的每一行都将包含与输入文件相同的内容,并添加一个由Bicleaner硬规则给出的标签列。
自动测试
我们包含了一个小的测试语料库和一个脚本来检查您的Bicleaner分类器是否按预期工作。要使用它,只需运行
python3.7 -m pytest -s tests/hardrules_test.py
这将下载所需的语言包,对提供的测试语料库进行分类,并检查分类评分。如果一切正常,输出将是“XX.XX秒通过了1个测试”。测试会话结束时,所有下载的数据都将被删除。
理解标注输出
当使用 --annotated_output
标志时,输出中会添加一个额外的列,包含每个句子的评估结果。如果评估结果是 keep
,则表示句子良好且通过了所有过滤器。额外列中的任何其他值都表示句子应被拒绝,并指示拒绝的原因。以下列出可能的拒绝值及其含义:
no_empty Sentence is empty
not_too_long Sentence is more than 1024 characters long
not_too_short Sentence is less than 3 words long
length_ratio The length ratio between the source sentence and target sentence (in bytes) is too low or too high
no_identical Alphabetic content in source sentence and target sentence is identical
no_literals Unwanted literals: "Re:","{{", "%s", "}}", "+++", "***", '=\"'
no_only_symbols The ratio of non-alphabetic characters in source sentence is more than 90%
no_only_numbers The ratio of numeric characters in source sentence is too high
no_urls There are URLs (disabled by default)
no_breadcrumbs There are more than 2 breadcrumb characters in the sentence
no_glued_words There are words in the sentence containing too many uppercased characters between lowercased characters
no_repeated_words There are more than 1 consecutive words repeated
no_unicode_noise Too many characters from unwanted unicode in source sentence
no_space_noise Too many consecutive single characters separated by spaces in the sentence (excludes digits)
no_paren Too many parenthesis or brackets in sentence
no_escaped_unicode There is unescaped unicode characters in sentence
no_bad_encoding Source sentence or target sentence contains mojibake
no_titles All words in source sentence or target sentence are uppercased or in titlecase
no_wrong_language Sentence is not in the desired language
no_porn Source sentence or target sentence contains text identified as porn
no_number_inconsistencies Sentence contains different numbers in source and target (disabled by default)
no_script_inconsistencies Sentence source or target contains characters from different script/writing systems (disabled by default)
lm_filter The sentence pair has low fluency score from the language model
训练分类器
如果您需要训练一个新的分类器(例如,因为它不在提供的语言包中,如bicleaner-data),您可以使用 bicleaner-train
。 bicleaner-train
是一个Python3工具,允许您训练一个分类器,该分类器可以预测一对句子是否是互译,并丢弃噪声过多的句子对。有关Bicleaner训练的详细信息,请访问我们的Wiki。
引用
如果您发现Bicleaner很有用,请考虑引用以下论文
V. M. Sánchez-Cartagena, M. Bañón, S. Ortiz-Rojas和G. Ramírez-Sánchez,
"Prompsit's submission to WMT 2018 Parallel Corpus Filtering shared task",
在第三届机器翻译会议,第二卷:共享任务论文。
布鲁塞尔,比利时:计算语言学协会,2018年10月
@InProceedings{prompsit:2018:WMT,
author = { V\'{i}ctor M. S\'{a}nchez-Cartagena and Marta Ba{\~n}\'{o}n and Sergio Ortiz-Rojas and Gema Ram\'{i}rez-S\'{a}nchez},
title = {Prompsit's submission to WMT 2018 Parallel Corpus Filtering shared task},
booktitle = {Proceedings of the Third Conference on Machine Translation, Volume 2: Shared Task Papers},
month = {October},
address = {Brussels, Belgium},
publisher = {Association for Computational Linguistics}
}
Gema Ramírez-Sánchez,Jaume Zaragoza-Bernabeu,Marta Bañón和Sergio Ortiz Rojas
"Bifixer and Bicleaner: two open-source tools to clean your parallel data.",
在欧洲翻译协会第二十二届年会。
里斯本,葡萄牙:欧洲翻译协会,2020年11月
@InProceedings{prompsit:2020:EAMT,
author = {Gema Ram\'{i}rez-S\'{a}nchez and Jaume Zaragoza-Bernabeu and Marta Ba{\~n}\'{o}n and Sergio Ortiz-Rojas},
title = {Bifixer and Bicleaner: two open-source tools to clean your parallel data.},
booktitle = {Proceedings of the 22nd Annual Conference of the European Association for Machine Translation},
pages = {291--298},
isbn = {978-989-33-0589-8},
year = {2020},
month = {November},
address = {Lisboa, Portugal},
publisher = {European Association for Machine Translation}
}
制作PyPi发行版
在存储库的根目录中运行
./scripts/release.sh
此脚本将创建源分发,编译二进制分发,并将wheel文件转换为通用的Python 3。然后,它将它们上传到PyPi,您需要一个PyPi中bicleaner-hardrules项目的用户账户维护者以及用户令牌。
此存储库中包含的所有文档和软件仅反映作者的观点。欧洲联盟创新和网络执行机构不对包含的信息的任何使用负责。
项目详情
下载文件
下载适用于您平台的电影。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分发
构建分发
散列 bicleaner_hardrules-2.10.5-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
算法 | 散列摘要 | |
---|---|---|
SHA256 | de45d6d51e99d1585baf709216ce25a0f3e6dd092e783692863a5788d730bee1 |
|
MD5 | f7c3c7e4d7aa12b37b2a743ee94e14bd |
|
BLAKE2b-256 | 8040c99a9ad4b16f862121e0a1096d5ca93801cd01aef73fde3357d8cd89c16f |