opusfilter 3.2.0__tar.gz → 3.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {opusfilter-3.2.0 → opusfilter-3.3.0}/.github/workflows/ci.yml +2 -2
- {opusfilter-3.2.0/opusfilter.egg-info → opusfilter-3.3.0}/PKG-INFO +9 -8
- {opusfilter-3.2.0 → opusfilter-3.3.0}/README.md +1 -1
- {opusfilter-3.2.0 → opusfilter-3.3.0}/bin/opusfilter-duplicates +13 -3
- {opusfilter-3.2.0 → opusfilter-3.3.0}/bin/opusfilter-scores +1 -2
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/CHANGELOG.md +20 -1
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/CONTRIBUTING.md +2 -2
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/command_line_tools.md +2 -1
- opusfilter-3.3.0/docs/filters/script_and_language_identification_filters.md +204 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/functions/filtering_and_scoring.md +8 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/installation.md +14 -8
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/references.bib +13 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/filters.py +30 -10
- opusfilter-3.3.0/opusfilter/lid.py +364 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/opusfilter.py +4 -1
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/segment_hash.py +29 -6
- {opusfilter-3.2.0 → opusfilter-3.3.0/opusfilter.egg-info}/PKG-INFO +9 -8
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter.egg-info/SOURCES.txt +1 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter.egg-info/requires.txt +16 -6
- {opusfilter-3.2.0 → opusfilter-3.3.0}/requirements.txt +4 -2
- {opusfilter-3.2.0 → opusfilter-3.3.0}/setup.py +13 -6
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_autogen.py +3 -1
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_filters.py +14 -2
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_lid.py +85 -27
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_segment_hash.py +18 -0
- opusfilter-3.2.0/docs/filters/script_and_language_identification_filters.md +0 -58
- {opusfilter-3.2.0 → opusfilter-3.3.0}/.gitignore +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/.pylintrc +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/LICENSE +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/bin/opusfilter +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/bin/opusfilter-autogen +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/bin/opusfilter-cmd +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/bin/opusfilter-diagram +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/bin/opusfilter-test +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/automatic_configuration.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/conf.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/filters/alignment_model_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/filters/custom_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/filters/language_model_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/filters/length_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/filters/sentence_embedding_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/filters/special_character_and_similarity_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/functions/downloading_and_selecting_data.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/functions/preprocessing_text.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/functions/training_and_using_classifiers.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/functions/training_language_and_alignment_models.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/functions/using_score_files.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/index.rst +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/preprocessors/bpe_segmentation.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/preprocessors/custom_preprocessors.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/preprocessors/detokenizer.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/preprocessors/monolingual_sentence_splitter.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/preprocessors/morfessor_segmentation.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/preprocessors/reg_exp_sub.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/preprocessors/tokenizer.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/preprocessors/whitespaceNormalizer.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/references.rst +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/requirements.txt +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/docs/usage.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/example_configs/README.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/example_configs/paracrawl_fi-en/create_ce_sets.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/example_configs/paracrawl_fi-en/create_domain_sets.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/example_configs/paracrawl_fi-en/create_roc_auc_sets.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/example_configs/paracrawl_fi-en/devset_100_1_labels.jsonl +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/example_configs/paracrawl_fi-en/devset_100_2_labels.jsonl +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/example_configs/paracrawl_fi-en/prepare_data.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/example_configs/qed_lm_langid.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/__init__.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/autogen.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/autogen_cluster.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/classifier.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/embeddings.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/lm.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/pipeline.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/preprocessors.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/subwords.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/tokenization.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/util.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter/word_alignment.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter.egg-info/dependency_links.txt +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/opusfilter.egg-info/top_level.txt +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/pyproject.toml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/setup.cfg +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_classifier.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_embeddings.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_filter_pipeline.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_lm_filter.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_opusfilter.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_preprocessors.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_subwords.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_tokenization.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_util.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_wordalign_filter.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.0}/tests/test_yaml.py +0 -0
|
@@ -21,7 +21,7 @@ jobs:
|
|
|
21
21
|
fail-fast: false
|
|
22
22
|
matrix:
|
|
23
23
|
os: [ubuntu-latest]
|
|
24
|
-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
|
|
24
|
+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
25
25
|
requirements-file: ["requirements.txt"]
|
|
26
26
|
runs-on: ${{ matrix.os }}
|
|
27
27
|
steps:
|
|
@@ -49,7 +49,7 @@ jobs:
|
|
|
49
49
|
build-n-publish:
|
|
50
50
|
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
|
|
51
51
|
needs: build-n-test
|
|
52
|
-
runs-on: ubuntu-
|
|
52
|
+
runs-on: ubuntu-latest
|
|
53
53
|
steps:
|
|
54
54
|
- uses: actions/checkout@v4
|
|
55
55
|
- name: Check for main release tag
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: opusfilter
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.3.0
|
|
4
4
|
Summary: Toolbox for filtering parallel corpora
|
|
5
5
|
Home-page: https://github.com/Helsinki-NLP/OpusFilter
|
|
6
6
|
Author: Mikko Aulamo, Sami Virpioja
|
|
@@ -18,7 +18,8 @@ Requires-Dist: graphviz
|
|
|
18
18
|
Requires-Dist: py3langid>=0.2.2
|
|
19
19
|
Requires-Dist: matplotlib
|
|
20
20
|
Requires-Dist: morfessor
|
|
21
|
-
Requires-Dist: opus-fast-mosestokenizer
|
|
21
|
+
Requires-Dist: opus-fast-mosestokenizer==0.0.8.7; python_version < "3.9"
|
|
22
|
+
Requires-Dist: opus-fast-mosestokenizer>=0.0.8.7; python_version >= "3.9"
|
|
22
23
|
Requires-Dist: pandas>=1.0.0
|
|
23
24
|
Requires-Dist: xxhash>=3.2.0
|
|
24
25
|
Requires-Dist: sentence-splitter
|
|
@@ -29,7 +30,9 @@ Requires-Dist: requests
|
|
|
29
30
|
Requires-Dist: scikit-learn
|
|
30
31
|
Requires-Dist: subword_nmt
|
|
31
32
|
Requires-Dist: tqdm
|
|
32
|
-
Requires-Dist: lingua-language-detector
|
|
33
|
+
Requires-Dist: lingua-language-detector<2.1,>=1.3.0; python_version < "3.10"
|
|
34
|
+
Requires-Dist: lingua-language-detector>=2.1.1; python_version >= "3.10"
|
|
35
|
+
Requires-Dist: iso639-lang
|
|
33
36
|
Provides-Extra: test
|
|
34
37
|
Requires-Dist: pytest; extra == "test"
|
|
35
38
|
Provides-Extra: pycld2
|
|
@@ -49,16 +52,14 @@ Provides-Extra: laser
|
|
|
49
52
|
Requires-Dist: laserembeddings; extra == "laser"
|
|
50
53
|
Provides-Extra: varikn
|
|
51
54
|
Requires-Dist: varikn; extra == "varikn"
|
|
55
|
+
Provides-Extra: heliport
|
|
56
|
+
Requires-Dist: heliport>=0.10.0; extra == "heliport"
|
|
52
57
|
Provides-Extra: docs
|
|
53
58
|
Requires-Dist: myst-parser; extra == "docs"
|
|
54
59
|
Requires-Dist: sphinx; extra == "docs"
|
|
55
60
|
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
|
56
61
|
Requires-Dist: sphinxcontrib-bibtex; extra == "docs"
|
|
57
62
|
Provides-Extra: all
|
|
58
|
-
Requires-Dist: pycld2; extra == "all"
|
|
59
|
-
Requires-Dist: py3langid<0.3.0; extra == "all"
|
|
60
|
-
Requires-Dist: numpy<2.0.0; extra == "all"
|
|
61
|
-
Requires-Dist: fasttext; extra == "all"
|
|
62
63
|
Requires-Dist: eflomal>=2.0.0; extra == "all"
|
|
63
64
|
Requires-Dist: jieba>=0.42; extra == "all"
|
|
64
65
|
Requires-Dist: mecab-python3>=1.0.8; extra == "all"
|
|
@@ -98,7 +99,7 @@ Install from source:
|
|
|
98
99
|
|
|
99
100
|
### Troubleshooting
|
|
100
101
|
|
|
101
|
-
OpusFilter should generally work fine on Python 3.8 to 3.
|
|
102
|
+
OpusFilter should generally work fine on Python 3.8 to 3.13. In the case of troubles, try installing the exact versions in `requirements.txt`:
|
|
102
103
|
|
|
103
104
|
* `pip install -r requirements.txt`
|
|
104
105
|
|
|
@@ -25,7 +25,7 @@ Install from source:
|
|
|
25
25
|
|
|
26
26
|
### Troubleshooting
|
|
27
27
|
|
|
28
|
-
OpusFilter should generally work fine on Python 3.8 to 3.
|
|
28
|
+
OpusFilter should generally work fine on Python 3.8 to 3.13. In the case of troubles, try installing the exact versions in `requirements.txt`:
|
|
29
29
|
|
|
30
30
|
* `pip install -r requirements.txt`
|
|
31
31
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import argparse
|
|
4
4
|
import collections
|
|
5
5
|
import logging
|
|
6
|
+
import json
|
|
6
7
|
|
|
7
8
|
from tqdm import tqdm
|
|
8
9
|
|
|
@@ -24,20 +25,29 @@ parser.add_argument('--hash', type=str, default='xxh64',
|
|
|
24
25
|
help=('hash function from xxhash library, empty string '
|
|
25
26
|
'for no hashing (default "xxh64")'))
|
|
26
27
|
parser.add_argument('--letters-only', action='store_true', default=False,
|
|
27
|
-
help='lowercase input strings before hashing')
|
|
28
|
-
parser.add_argument('--lowercase', action='store_true', default=False,
|
|
29
28
|
help='remove all non-letters from intput strings before hashing')
|
|
29
|
+
parser.add_argument('--letter-words-only', action='store_true', default=False,
|
|
30
|
+
help='remove words with non-letter characters before hashing')
|
|
31
|
+
parser.add_argument('--lowercase', action='store_true', default=False,
|
|
32
|
+
help='lowercase input strings before hashing')
|
|
33
|
+
parser.add_argument('--tokenizers', type=str, metavar='JSON', default=None,
|
|
34
|
+
help=('load tokenizer specifications from a JSON list (e.g. \'[["moses", "en"], ["jieba", "zh"]]\'); '
|
|
35
|
+
'use with --letter-words-only'))
|
|
30
36
|
|
|
31
37
|
args = parser.parse_args()
|
|
32
38
|
|
|
33
39
|
if args.overlap and len(args.overlap) != len(args.files):
|
|
34
40
|
raise ValueError("The number of the main and overlap input files should match")
|
|
35
41
|
|
|
42
|
+
tokenizers = json.loads(args.tokenizers) if args.tokenizers else None
|
|
43
|
+
|
|
36
44
|
hasher = SegmentHasher(
|
|
37
45
|
compare='all',
|
|
38
46
|
method=args.hash,
|
|
39
47
|
letters_only=args.letters_only,
|
|
40
|
-
|
|
48
|
+
letter_words_only=args.letter_words_only,
|
|
49
|
+
lowercase=args.lowercase,
|
|
50
|
+
tokenizers=tokenizers
|
|
41
51
|
)
|
|
42
52
|
|
|
43
53
|
total = 0
|
|
@@ -14,8 +14,7 @@ from tqdm import tqdm
|
|
|
14
14
|
|
|
15
15
|
from pandas.plotting import scatter_matrix
|
|
16
16
|
|
|
17
|
-
from opusfilter.util import file_open
|
|
18
|
-
from opusfilter.classifier import lists_to_dicts
|
|
17
|
+
from opusfilter.util import file_open, lists_to_dicts
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
logger = logging.getLogger(__name__)
|
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.3.0] - 2025-07-02
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `letter_words_only` option for duplicate detection
|
|
15
|
+
- support for selection of possible languages for `lingua` language detection
|
|
16
|
+
- support for language detection based on `heliport` (a port of HeLI-OTS)
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- update library requirements and include Python 3.13 tests
|
|
21
|
+
- removed pycld2 and fasttext from the `[all]` extras
|
|
22
|
+
- refactored all language identification filters to have their own classes and marked `LanguageIDFilter` as deprecated
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- fix broken import in `opusfilter-scores`
|
|
27
|
+
|
|
10
28
|
## [3.2.0] - 2024-08-14
|
|
11
29
|
|
|
12
30
|
### Changed
|
|
@@ -216,7 +234,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
216
234
|
First tagged version.
|
|
217
235
|
|
|
218
236
|
|
|
219
|
-
[Unreleased]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.
|
|
237
|
+
[Unreleased]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.3.0...develop
|
|
238
|
+
[3.3.0]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.2.0...3.3.0
|
|
220
239
|
[3.2.0]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.1.0...3.2.0
|
|
221
240
|
[3.1.0]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.0.0...3.1.0
|
|
222
241
|
[3.0.0]: https://github.com/Helsinki-NLP/OpusFilter/compare/2.6.0...3.0.0
|
|
@@ -5,7 +5,7 @@ issues page. We are also happy to consider pull requests. There are a
|
|
|
5
5
|
few rules for pull requests:
|
|
6
6
|
|
|
7
7
|
* Make a pull request to the `develop` branch instead of `master`.
|
|
8
|
-
* The code should support at least Python versions from 3.8 to 3.
|
|
8
|
+
* The code should support at least Python versions from 3.8 to 3.13.
|
|
9
9
|
* Please follow [PEP 8](https://www.python.org/dev/peps/pep-0008/). Exception: The maximum line length is 127 characters instead of 79.
|
|
10
10
|
* Especially for new features, please include test cases for unit testing.
|
|
11
11
|
|
|
@@ -20,7 +20,7 @@ skips the respective tests if not.)
|
|
|
20
20
|
|
|
21
21
|
GitHub workflows defined in the project run automatically `flake8`
|
|
22
22
|
checks and unit testing with `pytest` using Python 3.8, 3.9, 3.10,
|
|
23
|
-
3.11, and 3.
|
|
23
|
+
3.11, 3.12, and 3.13.
|
|
24
24
|
|
|
25
25
|
Especially for larger contributions, consider using a code analysis
|
|
26
26
|
tool like [Pylint](https://github.com/PyCQA/pylint). Install it
|
|
@@ -30,7 +30,8 @@ number of duplicates in it, or two corpora for calculating the overlap
|
|
|
30
30
|
between them. The syntax for the `opusfilter-duplicates` is:
|
|
31
31
|
|
|
32
32
|
```
|
|
33
|
-
opusfilter-duplicates [--overlap FILE [FILE ...]] [--hash HASH] [--letters-only]
|
|
33
|
+
opusfilter-duplicates [--overlap FILE [FILE ...]] [--hash HASH] [--letters-only]
|
|
34
|
+
[--letter-words-only] [--lowercase] [--tokenizers JSON] FILE [FILE ...]
|
|
34
35
|
```
|
|
35
36
|
|
|
36
37
|
The options are essentially the same as for [`remove_duplicates`](remove_duplicates).
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# Script and language identification filters
|
|
2
|
+
|
|
3
|
+
## AlphabetRatioFilter
|
|
4
|
+
|
|
5
|
+
Filter segments based on what proportion of the characters are alphabetic characters.
|
|
6
|
+
|
|
7
|
+
Parameters:
|
|
8
|
+
|
|
9
|
+
* `threshold`: minimum proportion of alphabets in a segment (default 0.75)
|
|
10
|
+
* `exclude_whitespace`: whether to exclude whitespace characters from the ratio (default `false`)
|
|
11
|
+
|
|
12
|
+
Returned scores are proportions of alphabetic characters in the
|
|
13
|
+
segments (after removing whitespace if `exclude_whitespace` is
|
|
14
|
+
true). In filtering, all values have to be equal to or greater than
|
|
15
|
+
the minimum threshold.
|
|
16
|
+
|
|
17
|
+
In order to allow have different thresholds per language, the
|
|
18
|
+
threshold parameter can also be given as a list.
|
|
19
|
+
|
|
20
|
+
## CharacterScoreFilter
|
|
21
|
+
|
|
22
|
+
Filter segments based on what proportion of their alphabetic characters are in a given script. For a list of valid scripts, see e.g. [www.regular-expressions.info/unicode.html](https://www.regular-expressions.info/unicode.html).
|
|
23
|
+
|
|
24
|
+
Parameters:
|
|
25
|
+
|
|
26
|
+
* `scripts`: scripts for input segments
|
|
27
|
+
* `thresholds`: minimum proportion of characters in a script (default 1)
|
|
28
|
+
|
|
29
|
+
Returned scores are proportions of valid characters in the segments. In filtering, all values have to be equal to or greater than the minimum thresholds.
|
|
30
|
+
|
|
31
|
+
## LanguageIDFilter (deprecated)
|
|
32
|
+
|
|
33
|
+
*Note: The common LanguageIDFilter is now deprecated. Please see the method-specific language identification filters below.*
|
|
34
|
+
|
|
35
|
+
Filter segments based on their language identification confidence scores.
|
|
36
|
+
|
|
37
|
+
Parameters:
|
|
38
|
+
|
|
39
|
+
* `languages`: expected languages (ISO639 language codes) for the segments
|
|
40
|
+
* `id_method`: language indentification method (`langid`, `lingua`, `cld2`, `fasttext`, `heliport`; default `langid`)
|
|
41
|
+
* `thresholds`: minimum identification confidence score for the segments (a single float or a list of floats per language)
|
|
42
|
+
* `fasttext_model_path`: path for a `fasttext` model (required only for the `fasttext` method; default `null`)
|
|
43
|
+
* `langid_languages`: limit detection to a list of ISO 639-1 codes for possible languages (valid only for the `langid` and `lingua` methods; default `null`)
|
|
44
|
+
* `cld2_options`: a dictionary of options for the `cld2` method (valid only for the `cld2` method; default `null`)
|
|
45
|
+
* `lingua_mode`: a string specifying whether to use lingua's `high` or `low` accuracy mode
|
|
46
|
+
|
|
47
|
+
Returned scores are the language identification confidence scores from a given identification method for the segments. The scores range from 0 to 1. In filtering, all values have to be greater than the minimum thresholds. A negative threshold can be used to skip filtering for a language.
|
|
48
|
+
|
|
49
|
+
Currently the following identification methods are supported:
|
|
50
|
+
|
|
51
|
+
* `langid` (default) :cite:`lui-baldwin-2012-langid`
|
|
52
|
+
* See https://github.com/adbar/py3langid
|
|
53
|
+
* `lingua`
|
|
54
|
+
* See https://github.com/pemistahl/lingua-py
|
|
55
|
+
* `cld2`
|
|
56
|
+
* See https://github.com/CLD2Owners/cld2
|
|
57
|
+
* Requires [installing optional libraries](../installation.md).
|
|
58
|
+
* `fasttext` :cite:`joulin-etal-2016-fasttext` and :cite:`joulin-etal-2017-bag`
|
|
59
|
+
* A pretrained model can be downloaded from [fasttext.cc/docs/en/language-identification.html](https://fasttext.cc/docs/en/language-identification.html).
|
|
60
|
+
* Requires [installing optional libraries](../installation.md).
|
|
61
|
+
|
|
62
|
+
## LangidFilter
|
|
63
|
+
|
|
64
|
+
Filter segments based on the langid method :cite:`lui-baldwin-2012-langid`; see
|
|
65
|
+
https://github.com/adbar/py3langid
|
|
66
|
+
|
|
67
|
+
Parameters:
|
|
68
|
+
|
|
69
|
+
* `languages`: expected languages (ISO639 language codes) for the segments
|
|
70
|
+
* `thresholds`: minimum identification confidence score for the segments (a single float or a list of floats per language)
|
|
71
|
+
* `langid_languages`: limit detection to a list of ISO 639-1 codes for possible languages
|
|
72
|
+
|
|
73
|
+
Returned scores are the language identification confidence scores for
|
|
74
|
+
the segments. The scores range from 0 to 1. In filtering, all values
|
|
75
|
+
have to be greater than the minimum thresholds. A negative threshold
|
|
76
|
+
can be used to skip filtering for a language.
|
|
77
|
+
|
|
78
|
+
## Cld2Filter
|
|
79
|
+
|
|
80
|
+
Filter segments based on the CLD2 method; see https://github.com/CLD2Owners/cld2
|
|
81
|
+
|
|
82
|
+
Requires [installing optional libraries](../installation.md).
|
|
83
|
+
|
|
84
|
+
Parameters:
|
|
85
|
+
|
|
86
|
+
* `languages`: expected languages (ISO639 language codes) for the segments
|
|
87
|
+
* `thresholds`: minimum identification confidence score for the segments (a single float or a list of floats per language)
|
|
88
|
+
* `options`: a dictionary of options for the method (see https://github.com/CLD2Owners/cld2; default `null`)
|
|
89
|
+
|
|
90
|
+
Returned scores are the language identification confidence scores from
|
|
91
|
+
a given identification method for the segments. The scores range from
|
|
92
|
+
0 to 1. In filtering, all values have to be greater than the minimum
|
|
93
|
+
thresholds. A negative threshold can be used to skip filtering for a
|
|
94
|
+
language.
|
|
95
|
+
|
|
96
|
+
## FastTextFilter
|
|
97
|
+
|
|
98
|
+
Filter segments based on the Fasttext language identification models
|
|
99
|
+
(:cite:`joulin-etal-2016-fasttext`, :cite:`joulin-etal-2017-bag`), see
|
|
100
|
+
https://github.com/CLD2Owners/cld2.
|
|
101
|
+
|
|
102
|
+
Requires [installing optional libraries](../installation.md).
|
|
103
|
+
|
|
104
|
+
Parameters:
|
|
105
|
+
|
|
106
|
+
* `languages`: expected languages (ISO639 language codes) for the segments
|
|
107
|
+
* `thresholds`: minimum identification confidence score for the segments (a single float or a list of floats per language)
|
|
108
|
+
* `model_path`: path for a `fasttext` model
|
|
109
|
+
|
|
110
|
+
Returned scores are the language identification confidence scores from
|
|
111
|
+
a given identification method for the segments. The scores range from
|
|
112
|
+
0 to 1. In filtering, all values have to be greater than the minimum
|
|
113
|
+
thresholds. A negative threshold can be used to skip filtering for a
|
|
114
|
+
language.
|
|
115
|
+
|
|
116
|
+
## LinguaFilter
|
|
117
|
+
|
|
118
|
+
Filter segments based on the Lingua method; see https://github.com/pemistahl/lingua-py
|
|
119
|
+
|
|
120
|
+
Parameters:
|
|
121
|
+
|
|
122
|
+
* `languages`: expected languages (ISO639 language codes) for the segments
|
|
123
|
+
* `thresholds`: minimum identification confidence score for the segments (a single float or a list of floats per language)
|
|
124
|
+
* `langid_languages`: limit detection to a list of ISO 639-1 codes for possible languages (default `null`)
|
|
125
|
+
* `lingua_mode`: a string specifying whether to use lingua's `high` or `low` accuracy mode (default `low`)
|
|
126
|
+
|
|
127
|
+
Returned scores are the language identification confidence scores from
|
|
128
|
+
a given identification method for the segments. The scores range from
|
|
129
|
+
0 to 1. In filtering, all values have to be greater than the minimum
|
|
130
|
+
thresholds. A negative threshold can be used to skip filtering for a
|
|
131
|
+
language.
|
|
132
|
+
|
|
133
|
+
## HeliportSimpleFilter
|
|
134
|
+
|
|
135
|
+
Filter segments based on the HeLI-OTS method :cite:`jauhiainen-etal-2022-heli`; see
|
|
136
|
+
https://github.com/ZJaume/heliport
|
|
137
|
+
|
|
138
|
+
Requires [installing optional libraries](../installation.md).
|
|
139
|
+
|
|
140
|
+
Parameters:
|
|
141
|
+
|
|
142
|
+
* `languages`: expected languages (ISO639 language codes) for the segments
|
|
143
|
+
* `thresholds`: minimum identification score for the segments (a single float or a list of floats per language)
|
|
144
|
+
|
|
145
|
+
This version uses three distinct score values. Score 1.0 is used if
|
|
146
|
+
the method predicts the correct language. If the low-confidence label
|
|
147
|
+
`und` is returned, the language is considered correct with score
|
|
148
|
+
0.5. Finally, if a wrong language is predicted, the score will
|
|
149
|
+
0.0. A negative threshold can be used to skip filtering for a language.
|
|
150
|
+
|
|
151
|
+
## HeliportConfidenceFilter
|
|
152
|
+
|
|
153
|
+
Filter segments based on the HeLI-OTS method :cite:`jauhiainen-etal-2022-heli`; see
|
|
154
|
+
https://github.com/ZJaume/heliport
|
|
155
|
+
|
|
156
|
+
Requires [installing optional libraries](../installation.md).
|
|
157
|
+
|
|
158
|
+
Parameters:
|
|
159
|
+
|
|
160
|
+
* `languages`: expected languages (ISO639 language codes) for the segments
|
|
161
|
+
* `thresholds`: minimum identification score for the segments (a single float or a list of floats per language)
|
|
162
|
+
|
|
163
|
+
This version uses the confidence value returned by the method. It is
|
|
164
|
+
the difference between raw scores of the the best (lowest) and second
|
|
165
|
+
best language. The maximum value is 7.0, which is a penalty value for
|
|
166
|
+
the languages that do not match. The minimum value 0 is returned if
|
|
167
|
+
the best language does not match. The low-confidence label `und` is
|
|
168
|
+
considered as a match. A negative threshold can be used to skip
|
|
169
|
+
filtering for a language.
|
|
170
|
+
|
|
171
|
+
## HeliportRawScoreFilter
|
|
172
|
+
|
|
173
|
+
Filter segments based on the HeLI-OTS method :cite:`jauhiainen-etal-2022-heli`; see
|
|
174
|
+
https://github.com/ZJaume/heliport
|
|
175
|
+
|
|
176
|
+
Requires [installing optional libraries](../installation.md).
|
|
177
|
+
|
|
178
|
+
Parameters:
|
|
179
|
+
|
|
180
|
+
* `languages`: expected languages (ISO639 language codes) for the segments
|
|
181
|
+
* `thresholds`: minimum identification score for the segments (a single float or a list of floats per language)
|
|
182
|
+
* `topk`: the number of top languages to consider (default 50)
|
|
183
|
+
|
|
184
|
+
This version uses the raw scores returned by the method. A lower score
|
|
185
|
+
is better. If the correct language is among the top-k languages, the
|
|
186
|
+
score if that language is returned. Otherwise, the penalty value 7 is
|
|
187
|
+
returned. A threshold over the penalty value can be used to skip
|
|
188
|
+
filtering for a language.
|
|
189
|
+
|
|
190
|
+
## HeliportProbabilityFilter
|
|
191
|
+
|
|
192
|
+
Filter segments based on the HeLI-OTS method :cite:`jauhiainen-etal-2022-heli`; see
|
|
193
|
+
https://github.com/ZJaume/heliport
|
|
194
|
+
|
|
195
|
+
Requires [installing optional libraries](../installation.md).
|
|
196
|
+
|
|
197
|
+
* `languages`: expected languages (ISO639 language codes) for the segments
|
|
198
|
+
* `thresholds`: minimum identification score for the segments (a single float or a list of floats per language)
|
|
199
|
+
* `topk`: the number of top languages to consider (default 50)
|
|
200
|
+
|
|
201
|
+
This version transforms the raw scores of of the top-k languages into
|
|
202
|
+
probability-like values. If the correct language is not in the top-k
|
|
203
|
+
list, zero is returned. A negative threshold can be used to skip
|
|
204
|
+
filtering for a language.
|
|
@@ -11,6 +11,10 @@ Parameters:
|
|
|
11
11
|
* `compare`: select files for duplicate comparison (optional; default `all` or a list of indices)
|
|
12
12
|
* `hash`: select hash algorithm from xxhash (optional; default `xxh64`)
|
|
13
13
|
* `overlap`: remove overlap with a second set of files (optional; default `null`)
|
|
14
|
+
* `letters_only`: remove all non-letters from intput strings before hashing (optional; default `false`)
|
|
15
|
+
* `letter_words_only`: remove words with non-letter characters before hashing (optional; default `false`)
|
|
16
|
+
* `lowercase`: lowercase input strings before hashing (optional; default `false`)
|
|
17
|
+
* `tokenizers`: load tokenizer specifications from a list (optional; use with `letter_words_only`)
|
|
14
18
|
|
|
15
19
|
Duplicate filtering is recommended as a first step especially if you
|
|
16
20
|
combine different corpus collections (e.g. data crawled from web) and
|
|
@@ -38,6 +42,10 @@ sizes, but if do not care about memory use and want to be extra sure
|
|
|
38
42
|
there are no collisions, you can disable hashing by setting the `hash`
|
|
39
43
|
parameter as empty string or null.
|
|
40
44
|
|
|
45
|
+
For the `letter_words_only`, unless the input is pre-tokenized, you
|
|
46
|
+
should select tokenizers for each of the input files. See
|
|
47
|
+
[Tokenizer](tokenizer.md) for description of the tokenizer parameters.
|
|
48
|
+
|
|
41
49
|
## filter
|
|
42
50
|
|
|
43
51
|
Filter parallel data with a combination of filters.
|
|
@@ -12,7 +12,7 @@ Install from source:
|
|
|
12
12
|
|
|
13
13
|
Note that all required libraries are not available to install via PyPI
|
|
14
14
|
on Windows OS. On Linux and MacOS, it should work directly for Python
|
|
15
|
-
versions from 3.8 to 3.
|
|
15
|
+
versions from 3.8 to 3.13.
|
|
16
16
|
|
|
17
17
|
## Required libraries
|
|
18
18
|
|
|
@@ -39,23 +39,29 @@ See `setup.py` for possible version requirements.
|
|
|
39
39
|
|
|
40
40
|
## Optional libraries and tools
|
|
41
41
|
|
|
42
|
-
### FastText and
|
|
42
|
+
### FastText, PyCLD2, and heliport language identification
|
|
43
43
|
|
|
44
44
|
The language identification libraries currently supported out-of-the-box
|
|
45
45
|
are [py3langid](https://github.com/adbar/py3langid) and
|
|
46
|
-
[lingua](https://github.com/pemistahl/lingua-py). The support for
|
|
46
|
+
[lingua](https://github.com/pemistahl/lingua-py). The support for
|
|
47
47
|
[PyCLD2](https://github.com/aboSamoor/pycld2) and
|
|
48
48
|
[FastText models](https://fasttext.cc/docs/en/language-identification.html)
|
|
49
49
|
have been changed to optional due to the lack of support especially
|
|
50
|
-
for newer Python versions.
|
|
50
|
+
for newer Python versions. Also the support for
|
|
51
|
+
[heliport](https://github.com/ZJaume/heliport) is optional. Please
|
|
52
|
+
note that `heliport` has GPL-3.0 license.
|
|
51
53
|
|
|
52
54
|
The PyCLD2 support can be installed automatically with pip by
|
|
53
|
-
including the extras `[pycld2]`
|
|
54
|
-
|
|
55
|
+
including the extras `[pycld2]` (e.g. `pip install
|
|
56
|
+
opusfilter[pycld2]`).
|
|
55
57
|
|
|
56
58
|
The support for FastText models can be installed automatically with
|
|
57
|
-
pip by including the extras `[fasttext]`
|
|
58
|
-
|
|
59
|
+
pip by including the extras `[fasttext]` (e.g. `pip install
|
|
60
|
+
opusfilter[fasttext]`).
|
|
61
|
+
|
|
62
|
+
The support for `heliport` can be installed automatically with pip by
|
|
63
|
+
including the extras `[heliport]` (e.g. `pip install
|
|
64
|
+
opusfilter[heliport]`).
|
|
59
65
|
|
|
60
66
|
### Jieba and MeCab word segmentation
|
|
61
67
|
|
|
@@ -68,6 +68,19 @@
|
|
|
68
68
|
pages = "261--266"
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
% Jauhiainen et al. (2022)
|
|
72
|
+
@inproceedings{jauhiainen-etal-2022-heli,
|
|
73
|
+
title = "{H}e{LI}-{OTS}, Off-the-shelf Language Identifier for Text",
|
|
74
|
+
author = "Jauhiainen, Tommi and Jauhiainen, Heidi and Lind{\'e}n, Krister",
|
|
75
|
+
booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference",
|
|
76
|
+
month = jun,
|
|
77
|
+
year = "2022",
|
|
78
|
+
address = "Marseille, France",
|
|
79
|
+
publisher = "European Language Resources Association",
|
|
80
|
+
url = "https://aclanthology.org/2022.lrec-1.416/",
|
|
81
|
+
pages = "3912--3922"
|
|
82
|
+
}
|
|
83
|
+
|
|
71
84
|
% Joulin et al. (2016)
|
|
72
85
|
@article{joulin-etal-2016-fasttext,
|
|
73
86
|
author = {Armand Joulin and Edouard Grave and Piotr Bojanowski and Matthijs Douze and Herv{\'{e}} J{\'{e}}gou and Tom{\'{a}}s Mikolov},
|
|
@@ -11,6 +11,8 @@ from typing import Iterator, List, Tuple
|
|
|
11
11
|
import regex
|
|
12
12
|
|
|
13
13
|
from . import FilterABC, ConfigurationError, CLEAN_LOW, CLEAN_HIGH, CLEAN_BETWEEN, CLEAN_TRUE, CLEAN_FALSE
|
|
14
|
+
from .lid import Cld2Filter, FastTextFilter, HeliportConfidenceFilter, HeliportProbabilityFilter, \
|
|
15
|
+
HeliportRawScoreFilter, HeliportSimpleFilter, LangidFilter, LinguaFilter # pylint: disable=W0611 # noqa: F401
|
|
14
16
|
from .lm import CrossEntropyFilter, CrossEntropyDifferenceFilter, LMClassifierFilter # pylint: disable=W0611 # noqa: F401
|
|
15
17
|
from .util import check_args_compability
|
|
16
18
|
from .word_alignment import WordAlignFilter # pylint: disable=W0611 # noqa: F401
|
|
@@ -283,7 +285,12 @@ class CharacterScoreFilter(FilterABC):
|
|
|
283
285
|
class LanguageIDFilter(FilterABC):
|
|
284
286
|
"""Language identification confidence filter
|
|
285
287
|
|
|
286
|
-
|
|
288
|
+
This common filter class for different language identification
|
|
289
|
+
methods should be replaced by the respective method-specific
|
|
290
|
+
filter classes defined in the lid submodule.
|
|
291
|
+
|
|
292
|
+
For backward compatibility, this still supports four methods:
|
|
293
|
+
|
|
287
294
|
* langid (default): see :cite:`lui-baldwin-2012-langid`
|
|
288
295
|
* cld2: see https://github.com/CLD2Owners/cld2
|
|
289
296
|
* fasttext: see :cite:`joulin-etal-2016-fasttext` and :cite:`joulin-etal-2017-bag`
|
|
@@ -299,12 +306,23 @@ class LanguageIDFilter(FilterABC):
|
|
|
299
306
|
fasttext_model_path=None, langid_languages=None, cld2_options=None,
|
|
300
307
|
lingua_mode=None, **kwargs):
|
|
301
308
|
super().__init__(**kwargs)
|
|
309
|
+
suggested_filters = {
|
|
310
|
+
'langid': 'LangidFilter',
|
|
311
|
+
'cld2': 'Cld2Filter',
|
|
312
|
+
'fasttext': 'FastTextFilter',
|
|
313
|
+
'lingua': 'LinguaFilter'
|
|
314
|
+
}
|
|
315
|
+
logger.warning("LanguageIDFilter for id_method %s is deprecated, use %s instead.",
|
|
316
|
+
id_method, suggested_filters[id_method])
|
|
302
317
|
if languages is None:
|
|
303
318
|
raise ConfigurationError("A list of language codes needs to be defined")
|
|
304
319
|
self.identifier = None
|
|
305
320
|
self.cld2_options = None
|
|
306
321
|
self.fasttext_model = None
|
|
307
322
|
self.lingua_detector = None
|
|
323
|
+
if langid_languages and id_method not in {'langid', 'lingua'}:
|
|
324
|
+
raise ConfigurationError(
|
|
325
|
+
"langid_languages option is supported only by the langid and lingua methods")
|
|
308
326
|
if id_method == 'fasttext':
|
|
309
327
|
self.init_fastttext(fasttext_model_path)
|
|
310
328
|
else:
|
|
@@ -313,17 +331,13 @@ class LanguageIDFilter(FilterABC):
|
|
|
313
331
|
"path to model was set")
|
|
314
332
|
if id_method == 'langid':
|
|
315
333
|
self.init_langid(langid_languages)
|
|
316
|
-
else:
|
|
317
|
-
if langid_languages:
|
|
318
|
-
raise ConfigurationError(
|
|
319
|
-
"langid_languages option is supported only by the method langid")
|
|
320
334
|
if id_method == 'cld2':
|
|
321
335
|
self.cld2_options = cld2_options if cld2_options else {}
|
|
322
336
|
else:
|
|
323
337
|
if cld2_options:
|
|
324
338
|
raise ConfigurationError("cld2_options is supported only by the method cld2")
|
|
325
339
|
if id_method == "lingua":
|
|
326
|
-
self.init_lingua(lingua_mode if lingua_mode else 'low')
|
|
340
|
+
self.init_lingua(lingua_mode if lingua_mode else 'low', langid_languages)
|
|
327
341
|
else:
|
|
328
342
|
if lingua_mode:
|
|
329
343
|
raise ConfigurationError("lingua_mode is supported only by the method lingua")
|
|
@@ -351,11 +365,17 @@ class LanguageIDFilter(FilterABC):
|
|
|
351
365
|
raise
|
|
352
366
|
self.fasttext_model = fasttext.load_model(os.path.join(self.workdir, fasttext_model_path))
|
|
353
367
|
|
|
354
|
-
def init_lingua(self, lingua_mode):
|
|
368
|
+
def init_lingua(self, lingua_mode, languages):
|
|
355
369
|
"""Initialize lingua identifier"""
|
|
356
|
-
from lingua import LanguageDetectorBuilder
|
|
357
|
-
|
|
358
|
-
|
|
370
|
+
from lingua import LanguageDetectorBuilder, IsoCode639_1
|
|
371
|
+
if languages:
|
|
372
|
+
for code in languages:
|
|
373
|
+
if not hasattr(IsoCode639_1, code.upper()):
|
|
374
|
+
raise ConfigurationError(f"Language {code} not supported by lingua")
|
|
375
|
+
from_languages = LanguageDetectorBuilder.from_iso_codes_639_1(
|
|
376
|
+
*[getattr(IsoCode639_1, code.upper()) for code in languages])
|
|
377
|
+
else:
|
|
378
|
+
from_languages = LanguageDetectorBuilder.from_all_languages()
|
|
359
379
|
if lingua_mode == "high":
|
|
360
380
|
self.lingua_detector = from_languages.with_preloaded_language_models().build()
|
|
361
381
|
elif lingua_mode == "low":
|