未提供项目描述
项目描述
bifixer
用于修复双语语料库并标记近似重复项的工具。
BIFIXER 可以如何帮助您的平行语料库
- 修复多个文本问题
- 修复乱码
- 将 HTML 实体转换为它们所代表的字符
- 将错误的字母表中的字符替换为正确的字符
- 使用
--ignore_characters
来禁用此功能
- 规范化标点符号和空格(使用
--ignore_normalization
来禁用此功能) - 移除 HTML 标签(使用
--ignore_html
来禁用此功能) - 修正某些语言的常见拼写错误
- 目前支持:丹麦语、德语、英语、西班牙语、荷兰语、挪威语、葡萄牙语和土耳其语
- 使用
--ignore_orthography
来禁用此功能
- 移除源或目标为空的句子(使用
--ignore_empty
来禁用此功能) - 修复常见的分词问题(使用
--ignore_detokenization
来禁用此功能) - 获取并行句子的哈希值,以简化后续重复项的删除(使用
--ignore_duplicates
来禁用此功能)- 想要更强的去重效果?使用
--aggressive_dedup
标志来找到近重复句子(忽略大小写、重音、变音符号和数字) - 在下面的“标记重复和近重复句子”部分了解更多。
- 想要更强的去重效果?使用
- 提供更长的句子的更好分割
- 如果你有单语文本,请使用
monofixer.py
代替。
引用
如果你觉得 Bifixer 很有用,请考虑引用以下论文
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.",
在 第 22 届欧洲机器翻译协会年度会议论文集。
里斯本,葡萄牙:欧洲机器翻译协会,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}
}
安装
从源代码安装
git clone https://github.com/bitextor/bifixer
cd bifixer
pip install .
添加了自动测试以确保 Bifixer 中一切正常
cd bifixer
pytest
或无需手动下载存储库进行安装
pip install "bifixer @ git+https://github.com/bitextor/bifixer.git"
或直接从 PyPI 安装
pip install bifixer
此外,您还可以安装 conda 包
conda install -c bitextor bifixer
安装后,将有两个可执行文件(bifixer
和 monofixer
)可用于运行。
Loomchild 分割器
请注意,为了使用 Java 中的可选 loomchild
分割器模块,必须在安装过程中将其指定为可选依赖项
pip install bifixer[loomchild]
如果您不是使用默认的 Java 8,请下载它,并在安装前覆盖 'JAVA_HOME' 变量,例如
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
使用
Bifixer
usage: bifixer.py [-h] [--header] [--scol SCOL] [--tcol TCOL]
[--sdeferredcol SDEFERREDCOL] [--tdeferredcol TDEFERREDCOL]
[--ignore_characters] [--ignore_empty] [--ignore_long]
[--ignore_orthography] [--ignore_detokenization]
[--ignore_duplicates] [--aggressive_dedup]
[--ignore_segmentation] [--ignore_html]
[--words_before_segmenting WORDS_BEFORE_SEGMENTING]
[--segmenter {nltk,loomchild}] [--annotated_output] [--tmp_dir TMP_DIR] [-q]
[--debug] [--logfile LOGFILE] [-v]
input output srclang trglang
positional arguments:
input Tab-separated files to be bifixed
output Fixed corpus
srclang Source language (SL) of the input
trglang Target language (TL) of the input
optional arguments:
-h, --help show this help message and exit
Optional:
--header Input file will have header (default: False)
--scol SCOL Source sentence column (starting in 1). The name of
the field is expected instead of the position if
--header is set (default: 3)
--tcol TCOL Target sentence column (starting in 1). The name of
the field is expected instead of the position if
--header is set (default: 4)
--sdeferredcol SDEFERREDCOL
Source deferred standoff annotation column (starting
in 1). The name of the field is expected instead of
the position if --header is set (default: None)
--tdeferredcol TDEFERREDCOL
Target deferred standoff annotation column (starting
in 1). The name of the field is expected instead of
the position if --header is set (default: None)
--ignore_characters Doesn't fix mojibake, orthography, or other character
issues (default: False)
--ignore_empty Doesn't remove sentences with empty source or target
(default: False)
--ignore_long Doesn't ignore too long sentences (default: False)
--ignore_orthography Doesn't apply orthography fixing (default: False)
--ignore_html Doesn't remove HTML tags (default: False)
--ignore_detokenization
Doesn't fix common tokenization issues (default:
False)
--ignore_duplicates Doesn't obtain the hashes of parallel sentences
(default: False)
--aggressive_dedup Treats similar sentences as duplicates (marking them
with the same hash) (default: False)
--ignore_segmentation
Doesn't change segmentation of long sentences
(default: False)
--words_before_segmenting WORDS_BEFORE_SEGMENTING
Max words allowed in one side of a parallel sentence
before trying to segmentate it. Set to 0 to applicate
segmentation on everything. (default: 15)
--segmenter {nltk,loomchild}
Segmenter module. (default: nltk)
--annotated_output Adds an extra column indicating if the sentence pair was modified
('Yes' if it was modified, otherwise 'No') (default: False)
--tmp_dir TMP_DIR Temporary directory where creating the temporary files
of this program (default: /tmp)
Logging:
-q, --quiet Silent logging mode (default: False)
--debug Debug logging mode (default: False)
--logfile LOGFILE Store log to a file (default: <_io.TextIOWrapper
name='<stderr>' mode='w' encoding='UTF-8'>)
-v, --version show version of this script and exit
参数
- 位置参数
- INPUT:输入文件。制表符分隔的双语输入文件。默认情况下,预期的列是:SRC_URL TRG_URL SRC_SENTENCE TRG_SENTENCE [EXTRA COLUMNS]。当 INPUT 为 - 时,读取标准输入。
- OUTPUT:输出文件。制表符分隔的双语输出文件,是输入文件的修正版本。默认情况下,输出列是:SRC_URL TRG_URL SRC_SENTENCE TRG_SENTENCE [EXTRA COLUMNS] HASH RANKING。当 OUTPUT 为 - 时,写入标准输出。
- SRC LANG:源语言代码(2个字母的 ISO 639-1 代码)
- TRG LANG:目标语言代码(2个字母的 ISO 639-1 代码)
- 可选参数
- --tmp_dir TMP_DIR:临时文件目录
- --header:将输入文件的第一句话作为标题行处理。如果设置,输出将包含标题行
- --scol SCOL:源句子列的位置(从 1 开始)。如果设置了
--header
,预期的值将是字段名称。默认:如果未设置--header
,则默认为 3;否则为 src_text - --tcol TCOL : 目标句子列的位置(从1开始)。如果设置了
--header
,则期望值将是字段的名称。默认:未设置--header
时为4,否则为 trg_text - --sdeferredcol SDEFERREDCOL : 源延迟标注列(从1开始)。默认:无
- --tdeferredcol TDEFERREDCOL : 目标延迟标注列(从1开始)。默认:无
- --ignore_duplicates : 禁用去重(不会添加哈希或排名)
- --ignore_empty : 不删除空源或目标句子
- --ignore_long: 不删除过长的句子
- --ignore_html: 不删除HTML标签
- --ignore_segmentation : 禁用长句子的分段
- --segmenter: 分段器模块(
nltk
或loomchild
)。默认:nltk - --words_before_segmenting : 在尝试分段之前,句子中允许的最大单词数。默认:15
- --ignore_characters : 禁用文本修正(字符、编码...)
- --ignore_orthography 禁用正字法修正
- --ignore_detokenization : 不修复常见的分词问题。
- --aggressive_dedup: 将近似重复的句子视为重复(在哈希之前规范化句子)
- --annotated_output 添加一个额外的列,指示句子对是否被修改(如果已修改,则为 'Yes',否则为 'No')。默认:False
- --tmp_dir TMP_DIR:临时文件目录
- -q, --quiet : 静默日志模式
- --debug: 在运行时显示调试信息
- --logfile LOGFILE : 将日志存储到文件
- -v, --version : 显示版本号并退出
- -h, --help: 显示帮助并退出
Monofixer
python3.7 bifixer/monofixer.py --help
usage: monofixer.py [-h]
[--scol SCOL] [--sdeferredcol SDEFERREDCOL]
[--ignore_characters] [--ignore_long]
[--ignore_orthography] [--ignore_detokenization]
[--ignore_duplicates] [--aggressive_dedup]
[--ignore_segmentation] [--ignore_html]
[--words_before_segmenting WORDS_BEFORE_SEGMENTING]
[--segmenter {nltk,loomchild}] [--annotated_output] [--tmp_dir TMP_DIR] [-q]
[--debug] [--logfile LOGFILE] [-v]
input output lang
positional arguments:
input Tab-separated file to be fixed
output Fixed corpus
lang Language of the input
optional arguments:
-h, --help show this help message and exit
Optional:
--header Input file will have header (default: False)
--scol SCOL Sentence column (starting in 1). The name of the
field is expected instead of the position if --header
is set (default: 2)
--sdeferredcol SDEFERREDCOL
Source deferred standoff annotation column (starting
in 1). The name of the field is expected instead of
the position if --header is set (default: None)
--ignore_characters Doesn't fix mojibake, orthography, or other character
issues (default: False)
--ignore_long Doesn't ignore too long sentences (default: False)
--ignore_orthography Doesn't apply orthography fixing (default: False)
--ignore_detokenization
Doesn't fix common tokenization issues (default:
False)
--ignore_html Doesn't remove HTML tags (default: False)
--ignore_duplicates Doesn't obtain the hashes of sentences (default:
False)
--aggressive_dedup Treats similar sentences as duplicates (marking them
with the same hash) (default: False)
--ignore_segmentation
Doesn't change segmentation of long sentences
(default: False)
--words_before_segmenting WORDS_BEFORE_SEGMENTING
Max words allowed in a parallel sentence before trying
to segmentate it. Set to 0 to applicate segmentation
on everyt33hing. (default: 15)
--segmenter {nltk,loomchild}
Segmenter module. (default: nltk)
--annotated_output Adds an extra column indicating if the sentence was
modified ('Yes' if it was modified, otherwise 'No')
(default: False)
--tmp_dir TMP_DIR Temporary directory where creating the temporary files
of this program (default: /tmp)
Logging:
-q, --quiet Silent logging mode (default: False)
--debug Debug logging mode (default: False)
--logfile LOGFILE Store log to a file (default: <_io.TextIOWrapper
name='<stderr>' mode='w' encoding='UTF-8'>)
-v, --version show version of this script and exit
参数
- 位置参数
- INPUT : 输入文件。制表符分隔的单语输入文件。默认情况下,预期的列是:URL 句子 [额外列]。当 INPUT 是 - 时,从标准输入读取。
- OUTPUT : 输出文件。制表符分隔的单语输出文件,是输入文件的修正版本。默认情况下,输出列是:URL 句子 [额外列] HASH RANKING。当 OUTPUT 是 - 时,写入标准输出。
- LANG : 句子语言代码(2位ISO 639-1代码)
- 可选参数
- --tmp_dir TMP_DIR:临时文件目录
- --header:将输入文件的第一句话作为标题行处理。如果设置,输出将包含标题行
- --scol SCOL : 源句子列的位置(从1开始)。如果设置了
--header
,则期望值将是字段的名称。默认:未设置--header
时为2,否则为 src_text - --sdeferredcol SDEFERREDCOL 句子延迟标注列(从1开始)。默认:无
- --ignore_duplicates : 禁用去重(不会添加哈希或排名)
- --ignore_long: 不删除过长的句子
- --ignore_html: 不删除HTML标签
- --ignore_segmentation : 禁用长句子的分段
- --segmenter: 分段器模块(
nltk
或loomchild
)。默认:nltk - --words_before_segmenting : 在尝试分段之前,句子中允许的最大单词数。默认:15
- --ignore_characters : 禁用文本修正(字符、编码...)
- --ignore_orthography : 禁用正字法修正
- --ignore_detokenization : 不修复常见的分词问题。
- --aggressive_dedup: 将近似重复的句子视为重复(在哈希之前规范化句子)
- --annotated_output 添加一个额外的列,指示句子是否被修改(如果已修改,则为 'Yes',否则为 'No')。默认:False
- --tmp_dir TMP_DIR:临时文件目录
- -q, --quiet : 静默日志模式
- --debug: 在运行时显示调试信息
- --logfile LOGFILE : 将日志存储到文件
- -v, --version : 显示版本号并退出
- -h, --help: 显示帮助并退出
RUN
单线程运行
bifixer input-corpus.en-es output-corpus.en-es en es
并行运行
bifixer
可以通过您喜欢的任何方法进行并行化(例如,GNU parallel)
建议的使用方法
cat input-corpus.en-es \
| parallel -j 25 --pipe -k -l 30000 bifixer -q - - en es \
> output-corpus.en-es
其中两个 '-
' 表示从标准输入读取并写入标准输出,而 -q
告诉 bifixer 保持安静,以避免记录大量的信息消息。
标记重复和近似重复的句子
为了便于以后删除重复或近似重复的平行句子,Bifixer 为每个平行句子添加了两个新字段:hash
和 ranking
。
哈希是通过使用 XXHash 算法获得的,在修正源和目标句子(fixed_source+"\t"+fixed_target
)之后应用。在此步骤中相同的句子(请参阅下面的示例)将获得相同的哈希。
当使用 --aggressive_dedup
功能时,修正后的平行句子也会在计算哈希之前进行规范化(忽略大小写、重音和变音符号)。这样做,近似重复的句子(即它们仅在大小写或重音上有所不同)也将获得相同的哈希。规范化仅用于内部:应用 Bifixer 后,输出句子不会被规范化。
在每一行的末尾添加了一个 排名
列。当未使用 --aggressive_dedup
功能时,默认设置为 1。当使用 --aggressive_dedup
功能时,提供浮点数。这个数字(解释为越大越好)将在后续步骤中用于帮助去重算法从具有相同哈希值的句子中选择最佳句子。如果一组共享相同哈希值的句子的排名数字完全相同,则应只保留一个随机句子。否则,应保留排名数字最高的句子。
示例
输入文件
http://www.ehyz.com/2.html.tmp http://www.ehyz.com/2.html.tmp 1 year ago NuVid Hace 1 año NuVid
http://pandafoundation.com/index.php?page=7 http://pandafoundation.com/index.php?page=26 ©2007 Chengdu Research Base of Giant Panda Breeding ! All Rights Reserved ©2017 Fundación para la Investigación de Cría del Panda Gigante de Chengdu/ ¡Todos los derechos reservados!
http://www.boliviamall.com/4520.html http://www.boliviamall.com/4520.html Welcome Guest 1! Would you like to log in ? Bienvenido Invitado 1! ¿Le gustaria entrar ?
http://pandafoundation.com/index.php?page=157 http://pandafoundation.com/index.php?page=76 ©2007 Chengdu Research Base of Giant Panda Breeding ! All Rights Reserved ©2017 Fundación para la Investigación de Cría del Panda Gigante de Chengdu/ ¡Todos los derechos reservados!
http://www.ehyz.com/6.html.tmp http://www.ehyz.com/6.html.tmp 1 year ago NuVid Hace 1 año NuVid
http://www.boliviamall.com/4305.html http://www.boliviamall.com/4305.html Welcome Guest 12! Would you like to log in? ¡Bienvenido invitado 12! ¿Le gustaria entrar?
输出文件(使用 --aggressive_dedup
功能时,否则所有情况的排名数字均为 1)
http://www.ehyz.com/2.html.tmp http://www.ehyz.com/2.html.tmp 1 year ago NuVid Hace 1 año NuVid 9f1f7c6fc775a23a 88.25
http://pandafoundation.com/index.php?page=7 http://pandafoundation.com/index.php?page=26 ©2007 Chengdu Research Base of Giant Panda Breeding ! All Rights Reserved ©2017 Fundación para la Investigación de Cría del Panda Gigante de Chengdu/ ¡Todos los derechos reservados! d0278d1279f06823 91.93
http://www.boliviamall.com/4520.html http://www.boliviamall.com/4520.html Welcome Guest 1! Would you like to log in ? Bienvenido Invitado 1! ¿Le gustaría entrar ? e8f129b1624b9f5d 91.22
http://pandafoundation.com/index.php?page=157 http://pandafoundation.com/index.php?page=76 ©2007 Chengdu Research Base of Giant Panda Breeding ! All Rights Reserved ©2017 Fundación para la Investigación de Cría del Panda Gigante de Chengdu/ ¡Todos los derechos reservados! d0278d1279f06823 91.93
http://www.ehyz.com/6.html.tmp http://www.ehyz.com/6.html.tmp 1 year ago NuVid Hace 1 año NuVid 9f1f7c6fc775a23a 88.25
http://www.boliviamall.com/4305.html http://www.boliviamall.com/4305.html Welcome Guest 12! Would you like to log in? ¡Bienvenido invitado 12! ¿Le gustaría entrar? 422aeefd8f056b30 92.78
本存储库中包含的所有文档和软件仅反映作者的看法。欧洲联盟的创新和网络执行机构不对包含的信息的任何使用负责。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。