跳转到主要内容

单语语料库流畅度过滤器

项目描述

monocleaner

License

monocleaner是一个Python工具,旨在检测单语语料库中的不流畅句子。每个句子都被分配一个0到1之间的流畅度分数,分数越高表示越流畅。除了连续分数外,还通过一些手写的规则将0分分配给明显较差的句子。

尽管提供了一个训练工具(monocleaner-train),但您可能想使用可用的现成语言包。请访问 https://github.com/bitextor/monocleaner-data/releases/latest 或使用 monocleaner-download 下载最新的语言包。

引用

如果您觉得Monocleaner很有用,请考虑引用以下论文

V. M. Sánchez-Cartagena, M. Bañón, S. Ortiz-Rojas和G. Ramírez-Sánchez,
"Prompsit提交给WMT 2018并行语料库过滤共享任务",
第三届机器翻译会议论文集,第二卷:共享任务论文 中。
比利时布鲁塞尔:计算语言学协会,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}
}

安装与要求

Monocleaner 使用了需要 python-devFastSpell

sudo apt install python-dev

可以使用 pip 安装 Monocleaner。

python3 -m pip install monocleaner

Monocleaner 需要 KenLM 的 Python 绑定,支持 7-gram 语言模型。您可以通过运行以下命令轻松安装:

git clone https://github.com/kpu/kenlm
cd kenlm
pip install --config-settings="--build-option=--max_order=7" .
mkdir -p build && cd build
cmake .. -DKENLM_MAX_ORDER=7 -DCMAKE_INSTALL_PREFIX:PATH=/your/prefix/path
make -j all install

Monocleaner 所需的其余额外模块将随第一个命令自动下载和安装/升级(如有必要)。

安装后,两个二进制文件(monocleaner-trainmonocleaner)将位于您的 python/installation/prefix/bin 目录中。这通常是 $HOME/.local/bin/usr/local/bin

评分

monocleaner 的目的是检测单语语料库中的不流畅句子。每个句子都会分配一个介于 0 和 1 之间的流畅度分数,分数越高表示越流畅。除了连续分数外,一些手写的 hardrules 也会为显然较差的句子分配 0 分。

输入文件(单语语料库)必须每行包含一个句子。生成的输出文件将包含相同的行,并添加一个包含 Monocleaner 流畅度分数的列。

此工具可以按以下方式运行:

monocleaner [-h]
            [--scol SCOL]
            [--disable_lang_ident] 
            [--disable_hardrules]
            [--disable_minimal_length]
            [--disable_hbs]
            [--score_only]
            [--annotated_output]
            [--add_lang_ident]
            [--detect_script]
            [--run_all_rules]
            [--debug]
            [-q]
            [-v]
            model_dir [input] [output]

如果省略了输入和输出,它将读取 stdin 并写入 stdout。

输出文件将包含以下列,列的顺序如下,具体取决于前面的参数:

参数
1 句子 由 --score_only 禁用
2 分数 -
3 语言代码 由 --add_lang_ident 启用
4 Hardrule 标签 由 --annotated_output 启用

参数

  • 位置参数
    • model_dir:模型存储的目录。
    • input:输入文本文件,每行一个句子。当与输出同时省略时,将从 stdin 读取。
    • output:输出带有 Monocleaner 分数的制表符分隔的文本文件。当省略输出时,将写入 stdout。
  • 可选参数
    • --scol:句子列(从 1 开始)(默认:1)
    • --disable_lang_ident:禁用 hardrules 中的语言识别。(默认:False)
    • --disable_hardrules:禁用 hardrules 过滤(仅应用 Monocleaner 流畅度评分)(默认:False)
    • --disable_minimal_length:不应用最小长度规则 (默认:False)。
    • --disable_hbs:不要将塞尔维亚-克罗地亚语分组在 'hbs' 标签下。 (默认:False)
    • --score_only:仅输出一列,该列为 Monocleaner 分数 (默认:False)
    • --annotated_output:为每个句子添加 hardrules 注释。(默认:False)
    • --add_lang_ident:如果未禁用,添加另一个包含识别出的语言的列。(默认:False)
    • --detect_script:使用 FastSpell 检测书写脚本(仅支持塞尔维亚-克罗地亚语)(默认:False)
    • --run_all_rules:对每个句子运行所有 hardrules,而不是在第一个被丢弃的规则处停止。(默认:False)
  • 日志记录
    • --debug:调试日志模式(默认:False)
    • -q, --quiet:静默日志模式(默认:False)
    • -v, --version:显示此脚本的版本并退出

示例

monocleaner models/es mono.es.txt mono.es.scored.txt

这将使用位于 models/es 的西班牙语模型,读取 mono.es.txt 文件,并将句子写入 mono.es.scored.txt,添加 Monocleaner 分数列。

Monocleaner 硬规则

monocleaner-hardrules 是基于规则和由 FastSpell 识别出的不正确语言进行预过滤的可选步骤,以消除明显的噪声。它可以集成到 monocleaner 端点中,或单独使用。

清洁

monocleaner-hardrules旨在检测单语语料库中的明显嘈杂句子。被认为是嘈杂的句子将被标记为0,其余的将被标记为1。默认情况下,输入的单语文件必须包含至少一列需要清理的句子。如果有更多列,则可以通过--scol参数自定义需要清理的句子的列索引。

默认情况下,生成的输出文件将包含与原始输入文件相同的行和列,但是,总是添加一个包含Monocleaner硬规则得分的额外列。新插入的列的数量将取决于启用了哪些参数。

此工具可以按以下方式运行:

monocleaner-hardrules [-h]
            [--scol SCOL]
            [--disable_lang_ident]
            [--disable_minimal_length]
            [--disable_hbs]
            [--score_only]
            [--add_lang_ident]
            [--detect_script]
            [--annotated_output]
            [--run_all_rules]
            [--debug]
            [-q]
            [-v]
            language [input] [output]

输出文件将包含以下列,列的顺序如下,具体取决于前面的参数:

参数
1 句子 由 --score_only 禁用
2 分数 -
3 语言代码 由 --add_lang_ident 启用
4 Hardrule 标签 由 --annotated_output 启用

参数

  • 位置参数
    • language:语料库的语言代码,采用ISO 639-1格式(2个字符代码)。
    • input:输入文本文件,每行一个句子。当与输出同时省略时,将从 stdin 读取。
    • output:输出带有 Monocleaner 分数的制表符分隔的文本文件。当省略输出时,将写入 stdout。
  • 可选参数
    • --scol:句子列(从 1 开始)(默认:1)
    • --disable_lang_ident:禁用 hardrules 中的语言识别。(默认:False)
    • --disable_minimal_length:不应用最小长度规则 (默认:False)。
    • --disable_hbs:不要将塞尔维亚-克罗地亚语分组在 'hbs' 标签下。 (默认:False)
    • --score_only:仅输出一列,该列为 Monocleaner 分数 (默认:False)
    • --add_lang_ident:如果未禁用,添加另一个包含识别出的语言的列。(默认:False)
    • --detect_script:使用 FastSpell 检测书写脚本(仅支持塞尔维亚-克罗地亚语)(默认:False)
    • --annotated_output:为每个句子添加 hardrules 注释。(默认:False)
    • --run_all_rules:对每个句子运行所有 hardrules,而不是在第一个被丢弃的规则处停止。(默认:False)
  • 日志记录
    • --debug:调试日志模式(默认:False)
    • -q, --quiet:静默日志模式(默认:False)
    • -v, --version:显示此脚本的版本并退出

示例

monocleaner-hardrules en mono.en.txt mono.en.scored.txt

理解标注输出

当使用--annotated_output标志时,输出中会添加一个包含每个句子评估的额外列。如果评估返回keep标签(得分列:1),则表示该句子被认为良好且通过了所有过滤器。然而,额外列中的任何其他标签值(得分列:0)都表示该句子应被拒绝。拒绝原因、它们的意义以及应用硬规则的顺序如下所示

no_empty	Sentence is empty
no_titles	All words in source sentence or target sentence are uppercased or in titlecase
not_too_long	Sentence is more than 1024 characters long
not_too_short	Sentence is less than	3 words long
no_bad_encoding	Source sentence or target sentence contains mojibake
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_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_literals	Unwanted literals: "Re:","{{", "%s", "}}", "+++", "***", '=\"'
no_escaped_unicode	There is unescaped unicode characters in 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_wrong_language	Sentence is not in the desired language specifide in the cleaning command

Connecting Europe Facility

此存储库中包含的所有文档和软件仅反映作者的观点。欧盟创新和网络管理局不对包含的信息可能被使用的任何用途负责。

项目详情


下载文件

下载适用于您平台文件的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

monocleaner-1.6.2.tar.gz (34.1 KB 查看散列)

上传时间

构建分布

monocleaner-1.6.2-py3-none-any.whl (34.7 KB 查看散列)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面