opusfilter 3.2.0__tar.gz → 3.3.1__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.1}/.github/workflows/ci.yml +2 -2
- {opusfilter-3.2.0/opusfilter.egg-info → opusfilter-3.3.1}/PKG-INFO +8 -8
- {opusfilter-3.2.0 → opusfilter-3.3.1}/README.md +1 -1
- {opusfilter-3.2.0 → opusfilter-3.3.1}/bin/opusfilter-duplicates +13 -3
- {opusfilter-3.2.0 → opusfilter-3.3.1}/bin/opusfilter-scores +1 -2
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/CHANGELOG.md +32 -1
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/CONTRIBUTING.md +2 -2
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/command_line_tools.md +2 -1
- opusfilter-3.3.1/docs/filters/script_and_language_identification_filters.md +204 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/filters/special_character_and_similarity_filters.md +6 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/functions/filtering_and_scoring.md +9 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/installation.md +23 -11
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/references.bib +13 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/autogen.py +11 -2
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/filters.py +31 -11
- opusfilter-3.3.1/opusfilter/lid.py +364 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/opusfilter.py +4 -1
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/segment_hash.py +29 -6
- {opusfilter-3.2.0 → opusfilter-3.3.1/opusfilter.egg-info}/PKG-INFO +8 -8
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter.egg-info/SOURCES.txt +1 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter.egg-info/requires.txt +11 -6
- {opusfilter-3.2.0 → opusfilter-3.3.1}/requirements.txt +4 -2
- {opusfilter-3.2.0 → opusfilter-3.3.1}/setup.py +12 -6
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_autogen.py +3 -1
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_filters.py +5 -3
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_lid.py +89 -28
- {opusfilter-3.2.0 → opusfilter-3.3.1}/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.1}/.gitignore +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/.pylintrc +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/LICENSE +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/bin/opusfilter +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/bin/opusfilter-autogen +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/bin/opusfilter-cmd +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/bin/opusfilter-diagram +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/bin/opusfilter-test +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/automatic_configuration.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/conf.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/filters/alignment_model_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/filters/custom_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/filters/language_model_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/filters/length_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/filters/sentence_embedding_filters.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/functions/downloading_and_selecting_data.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/functions/preprocessing_text.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/functions/training_and_using_classifiers.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/functions/training_language_and_alignment_models.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/functions/using_score_files.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/index.rst +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/preprocessors/bpe_segmentation.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/preprocessors/custom_preprocessors.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/preprocessors/detokenizer.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/preprocessors/monolingual_sentence_splitter.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/preprocessors/morfessor_segmentation.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/preprocessors/reg_exp_sub.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/preprocessors/tokenizer.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/preprocessors/whitespaceNormalizer.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/references.rst +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/requirements.txt +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/docs/usage.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/example_configs/README.md +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/example_configs/paracrawl_fi-en/create_ce_sets.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/example_configs/paracrawl_fi-en/create_domain_sets.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/example_configs/paracrawl_fi-en/create_roc_auc_sets.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/example_configs/paracrawl_fi-en/devset_100_1_labels.jsonl +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/example_configs/paracrawl_fi-en/devset_100_2_labels.jsonl +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/example_configs/paracrawl_fi-en/prepare_data.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/example_configs/qed_lm_langid.yaml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/__init__.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/autogen_cluster.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/classifier.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/embeddings.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/lm.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/pipeline.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/preprocessors.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/subwords.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/tokenization.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/util.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter/word_alignment.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter.egg-info/dependency_links.txt +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/opusfilter.egg-info/top_level.txt +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/pyproject.toml +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/setup.cfg +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_classifier.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_embeddings.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_filter_pipeline.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_lm_filter.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_opusfilter.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_preprocessors.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_subwords.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_tokenization.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_util.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/tests/test_wordalign_filter.py +0 -0
- {opusfilter-3.2.0 → opusfilter-3.3.1}/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.1
|
|
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,7 @@ 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>=0.0.8.
|
|
21
|
+
Requires-Dist: opus-fast-mosestokenizer>=0.0.8.11
|
|
22
22
|
Requires-Dist: pandas>=1.0.0
|
|
23
23
|
Requires-Dist: xxhash>=3.2.0
|
|
24
24
|
Requires-Dist: sentence-splitter
|
|
@@ -29,7 +29,9 @@ Requires-Dist: requests
|
|
|
29
29
|
Requires-Dist: scikit-learn
|
|
30
30
|
Requires-Dist: subword_nmt
|
|
31
31
|
Requires-Dist: tqdm
|
|
32
|
-
Requires-Dist: lingua-language-detector
|
|
32
|
+
Requires-Dist: lingua-language-detector<2.1,>=1.3.0; python_version < "3.10"
|
|
33
|
+
Requires-Dist: lingua-language-detector>=2.1.1; python_version >= "3.10"
|
|
34
|
+
Requires-Dist: iso639-lang
|
|
33
35
|
Provides-Extra: test
|
|
34
36
|
Requires-Dist: pytest; extra == "test"
|
|
35
37
|
Provides-Extra: pycld2
|
|
@@ -49,16 +51,14 @@ Provides-Extra: laser
|
|
|
49
51
|
Requires-Dist: laserembeddings; extra == "laser"
|
|
50
52
|
Provides-Extra: varikn
|
|
51
53
|
Requires-Dist: varikn; extra == "varikn"
|
|
54
|
+
Provides-Extra: heliport
|
|
55
|
+
Requires-Dist: heliport>=0.10.0; extra == "heliport"
|
|
52
56
|
Provides-Extra: docs
|
|
53
57
|
Requires-Dist: myst-parser; extra == "docs"
|
|
54
58
|
Requires-Dist: sphinx; extra == "docs"
|
|
55
59
|
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
|
56
60
|
Requires-Dist: sphinxcontrib-bibtex; extra == "docs"
|
|
57
61
|
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
62
|
Requires-Dist: eflomal>=2.0.0; extra == "all"
|
|
63
63
|
Requires-Dist: jieba>=0.42; extra == "all"
|
|
64
64
|
Requires-Dist: mecab-python3>=1.0.8; extra == "all"
|
|
@@ -98,7 +98,7 @@ Install from source:
|
|
|
98
98
|
|
|
99
99
|
### Troubleshooting
|
|
100
100
|
|
|
101
|
-
OpusFilter should generally work fine on Python 3.8 to 3.
|
|
101
|
+
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
102
|
|
|
103
103
|
* `pip install -r requirements.txt`
|
|
104
104
|
|
|
@@ -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,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.3.1] - 2025-12-10
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- changed `HtmlTagFilter` to accept broken tags in order to avoid inconsistent results
|
|
15
|
+
- update required `opus-fast-mosestokenizer` version for better platform support
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- broken citations and links in the documentation
|
|
20
|
+
|
|
21
|
+
## [3.3.0] - 2025-07-02
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- `letter_words_only` option for duplicate detection
|
|
26
|
+
- support for selection of possible languages for `lingua` language detection
|
|
27
|
+
- support for language detection based on `heliport` (a port of HeLI-OTS)
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- update library requirements and include Python 3.13 tests
|
|
32
|
+
- removed pycld2 and fasttext from the `[all]` extras
|
|
33
|
+
- refactored all language identification filters to have their own classes and marked `LanguageIDFilter` as deprecated
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- fix broken import in `opusfilter-scores`
|
|
38
|
+
|
|
10
39
|
## [3.2.0] - 2024-08-14
|
|
11
40
|
|
|
12
41
|
### Changed
|
|
@@ -216,7 +245,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
216
245
|
First tagged version.
|
|
217
246
|
|
|
218
247
|
|
|
219
|
-
[Unreleased]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.
|
|
248
|
+
[Unreleased]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.3.1...develop
|
|
249
|
+
[3.3.1]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.3.0...3.3.1
|
|
250
|
+
[3.3.0]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.2.0...3.3.0
|
|
220
251
|
[3.2.0]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.1.0...3.2.0
|
|
221
252
|
[3.1.0]: https://github.com/Helsinki-NLP/OpusFilter/compare/3.0.0...3.1.0
|
|
222
253
|
[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:p}`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:p}`joulin-etal-2016-fasttext` and {cite:p}`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:p}`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:t}`joulin-etal-2016-fasttext`, {cite:t}`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:p}`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:p}`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:p}`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:p}`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.
|
{opusfilter-3.2.0 → opusfilter-3.3.1}/docs/filters/special_character_and_similarity_filters.md
RENAMED
|
@@ -8,6 +8,12 @@ The returned scores are two boolean values indicating whether the
|
|
|
8
8
|
segments contain HTML tags. In filtering, a segment pair is accepted
|
|
9
9
|
if none of the segments contains HTML tags.
|
|
10
10
|
|
|
11
|
+
The beautifulsoup4 library is used for detecting HTML. Up to
|
|
12
|
+
OpusFilter version 3.3.0, the behavior on broken HTML tags varies
|
|
13
|
+
depending on the input and installed library versions. For newer
|
|
14
|
+
versions, broken HTML is not considered as HTML, i.e., it is accepted
|
|
15
|
+
by the filter.
|
|
16
|
+
|
|
11
17
|
## TerminalPunctuationFilter
|
|
12
18
|
|
|
13
19
|
Filter segments based on a penalty score with respect to the
|
|
@@ -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,11 @@ 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](../preprocessors/tokenizer.md) for description of the
|
|
48
|
+
tokenizer parameters.
|
|
49
|
+
|
|
41
50
|
## filter
|
|
42
51
|
|
|
43
52
|
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
|
|
|
@@ -72,24 +78,30 @@ automatically with pip by including the extras `[mecab]` or `[all]`
|
|
|
72
78
|
### LASER sentence embeddings
|
|
73
79
|
|
|
74
80
|
For using sentence embeddings filters, you need to install
|
|
75
|
-
`laserembeddings` (https://github.com/yannvgn/laserembeddings). It can
|
|
81
|
+
`laserembeddings` (<https://github.com/yannvgn/laserembeddings>). It can
|
|
76
82
|
be installed automatically with pip by including the extras `[laser]`
|
|
77
83
|
or `[all]` (e.g. `pip install opusfilter[laser]`). The package will also
|
|
78
84
|
require a number of additional libraries, including PyTorch, jieba,
|
|
79
85
|
and MeCab. Note that you need also to download the prebuild models
|
|
80
86
|
with `python -m laserembeddings download-models`.
|
|
81
87
|
|
|
88
|
+
**Note:** The current latest release `laserembeddings==1.1.2` does not
|
|
89
|
+
support `torch>=2.0.0` and thus fails on Python 3.12 and above. The
|
|
90
|
+
code itself works on Python 3.12 and 3.13, but you need to fix
|
|
91
|
+
`pyproject.toml` to allow later `torch` versions, and install it
|
|
92
|
+
manually.
|
|
93
|
+
|
|
82
94
|
### VariKN n-gram models
|
|
83
95
|
|
|
84
96
|
For using n-gram language model filters, you need to install the
|
|
85
|
-
Python wrapper for VariKN (https://github.com/vsiivola/variKN). It can
|
|
97
|
+
Python wrapper for VariKN (<https://github.com/vsiivola/variKN>). It can
|
|
86
98
|
be installed automatically with pip by including the extras `[varikn]`
|
|
87
99
|
or `[all]` (e.g. `pip install opusfilter[varikn]`).
|
|
88
100
|
|
|
89
101
|
### Eflomal word alignment
|
|
90
102
|
|
|
91
103
|
For using word alignment filters, you need to install elfomal
|
|
92
|
-
(https://github.com/robertostling/eflomal). It can be installed
|
|
104
|
+
(<https://github.com/robertostling/eflomal>). It can be installed
|
|
93
105
|
automatically with pip by including the extras `[eflomal]` or `[all]`
|
|
94
106
|
(e.g. `pip install opusfilter[eflomal]`). Note that you will need `Cython`
|
|
95
107
|
for the installation.
|
|
@@ -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},
|
|
@@ -14,6 +14,7 @@ import ruamel.yaml
|
|
|
14
14
|
from . import CLEAN_LOW, CLEAN_HIGH, CLEAN_BETWEEN, CLEAN_TRUE, CLEAN_FALSE
|
|
15
15
|
from . import OpusFilterError, ConfigurationError
|
|
16
16
|
from . import filters as filtermodule
|
|
17
|
+
from . import lid as lidmodule
|
|
17
18
|
from .autogen_cluster import ScoreClusters
|
|
18
19
|
from .classifier import load_dataframe
|
|
19
20
|
from .opusfilter import OpusFilter
|
|
@@ -171,6 +172,13 @@ def parse_filter_specs(specs):
|
|
|
171
172
|
return name, params
|
|
172
173
|
|
|
173
174
|
|
|
175
|
+
def get_lang_id_filters():
|
|
176
|
+
"""Return all language identification filters"""
|
|
177
|
+
names = ['LanguageIDFilter'] # old deprecated filter
|
|
178
|
+
names += [var for var in dir(lidmodule) if var.endswith('Filter')]
|
|
179
|
+
return names
|
|
180
|
+
|
|
181
|
+
|
|
174
182
|
class AutoFiltersABC(metaclass=abc.ABCMeta):
|
|
175
183
|
"""Abstract base class for automatic filter configuration"""
|
|
176
184
|
|
|
@@ -181,13 +189,14 @@ class AutoFiltersABC(metaclass=abc.ABCMeta):
|
|
|
181
189
|
filters = self.DEFAULT_FILTERS
|
|
182
190
|
filters = [parse_filter_specs(spec) for spec in filters]
|
|
183
191
|
self.filters_to_add = []
|
|
192
|
+
lang_id_filters = get_lang_id_filters()
|
|
184
193
|
for filter_name, filter_params in filters:
|
|
185
194
|
if filter_name == 'CharacterScoreFilter' and 'scripts' not in filter_params:
|
|
186
195
|
if not scripts:
|
|
187
196
|
logger.warning('Cannot add CharacterScoreFilter (no scripts provided)')
|
|
188
197
|
continue
|
|
189
198
|
filter_params['scripts'] = scripts
|
|
190
|
-
if filter_name
|
|
199
|
+
if filter_name in lang_id_filters and 'languages' not in filter_params:
|
|
191
200
|
if not langs:
|
|
192
201
|
logger.warning('Cannot add LanguageIDFilter (no languages provided)')
|
|
193
202
|
continue
|
|
@@ -217,7 +226,7 @@ class DefaultParameterFilters(AutoFiltersABC):
|
|
|
217
226
|
'AverageWordLengthFilter', 'AlphabetRatioFilter',
|
|
218
227
|
'TerminalPunctuationFilter', 'NonZeroNumeralsFilter',
|
|
219
228
|
'LongestCommonSubstringFilter', 'SimilarityFilter', 'RepetitionFilter',
|
|
220
|
-
'CharacterScoreFilter',
|
|
229
|
+
'CharacterScoreFilter', 'LinguaFilter']
|
|
221
230
|
|
|
222
231
|
def set_filter_thresholds(self):
|
|
223
232
|
"""Set filter thresholds"""
|