Skip to main content

Monolingual corpus fluency filter

Project description

monocleaner

License

Monocleaner is a Python tool that aims at detecting poor fluent sentences in a monolingual corpus. It indicates the fluency of a sentence with a score between 1 and 0, where the higher score, the better the fluency is. Sentences considered to have obvious poor fluency are tagged with a 0.

Although a training tool (monocleaner-train) is provided, you may want to use the available ready-to-use language packages. Please, visit https://github.com/bitextor/monocleaner-data/releases/latest or use monocleaner-download to download the latest language packages.

Citation

If you find Monocleaner useful, please consider citing the following papers:

V. M. Sánchez-Cartagena, M. Bañón, S. Ortiz-Rojas and G. Ramírez-Sánchez,
"Prompsit's submission to WMT 2018 Parallel Corpus Filtering shared task",
in Proceedings of the Third Conference on Machine Translation, Volume 2: Shared Task Papers.
Brussels, Belgium: Association for Computational Linguistics, October 2018

@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}
}

Installation & Requirements

Monocleaner can be installed using pip:

python3.7 -m pip install monocleaner

Monocleaner requires the KenLM Python bindings with support for 7-gram language models. You can easily install it by running the following commands:

git clone https://github.com/kpu/kenlm
cd kenlm
python3.7 -m pip install . --install-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

The remaining extra modules required by Monocleaner will be automatically downloaded and installed/upgraded (if required) with the first command.

After installation, two binary files (monocleaner-train and monocleaner) will be located in your python/installation/prefix/bin directory. This is usually $HOME/.local/bin or /usr/local/bin/.

Monocleaner uses FastSpell that requires python-dev and libhunspell-dev:

sudo apt install python-dev libhunspell-dev

Also note that Hunspell language packages must be installed by hand if you are going to work with one of languages listed as similar, i.e.:

sudo apt-get install hunspell-es

or downloaded from an external source, such as https://github.com/wooorm/dictionaries/tree/main/dictionaries

You can also provide the path to the Hunspell dictionaries directories by using the dictpath atribute in {/YOUR/INSTALLATION/PATH}/config/hunspell.yaml (for example, venv/lib/python3.7/site-packages/fastspell/config/hunspell.yaml ) if you are installing from PyPI or with setup.py, or in /config/hunspell.yaml if you are running directly the code. Default path is /usr/share/hunspell.

Scoring

monocleaner aims at detecting poor fluent sentences in a monolingual corpus. It indicates the fluency of a sentence with a score between 1 and 0, where the higher score, the better the fluency is. Sentences considered to have obvious poor fluency are tagged with a 0.

The input file (monolingual corpus) must contain one sentence per line text. The generated output file will contain the same lines adding a column containing the Monocleaner fluency score.

This tool can be run with

monocleaner [-h]
            [--disable_minimal_length]
            [--disable_hardrules]
            [--score_only]
            [--annotated_output]
            [--add_lang_ident]
            [--debug]
            [-q]
            model_dir [input] [output]

If input and output are omitted, it will read from stdin and write to stdout.

Parameters

  • Positional arguments:
    • model_dir: Directory where the model is stored.
    • input: Input text file, one sentence per line. When omitted jointly with output, it will read from stdin.
    • output: Output tab-separated text file adding monocleaner score. When omitted output will be written to stdout.
  • Optional arguments:
    • --score_only: Only output one column which is the monocleaner score (default: False)
    • --add_lang_ident: Add another column with the identified language if it's not disabled.
    • --disable_hardrules: Disables the hardrules filtering (only monocleaner fluency scoring is applied) (default: False)
    • --disable_minimal_length : Don't apply minimal length rule (default: False).
  • Logging:
    • -q, --quiet: Silent logging mode (default: False)
    • --debug: Debug logging mode (default: False)
    • -v, --version: show version of this script and exit

Example

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

This will use the Spanish model located at models/es, read mono.es.txt file and write the sentences to mono.es.scored.txt adding the monocleaner score column.


Connecting Europe Facility

All documents and software contained in this repository reflect only the authors' view. The Innovation and Networks Executive Agency of the European Union is not responsible for any use that may be made of the information it contains.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monocleaner-1.1.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

monocleaner-1.1-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file monocleaner-1.1.tar.gz.

File metadata

  • Download URL: monocleaner-1.1.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for monocleaner-1.1.tar.gz
Algorithm Hash digest
SHA256 f34d7a15365c4e9e9d14d6d9a8dea5d6450ee8925ff66410b469286ea803b7e7
MD5 897d30938c53edc859fda7de3d557a07
BLAKE2b-256 b4d6480931ee5d3b978d666b6ad25ddd7c91f1f2e122e9db293480382f1bbb87

See more details on using hashes here.

Provenance

File details

Details for the file monocleaner-1.1-py3-none-any.whl.

File metadata

  • Download URL: monocleaner-1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for monocleaner-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2826764fc169b40a8825d6e5816b1bc45a56b687e3de99f919f7a12e548be54e
MD5 2650b22fc41806f1e4349b0f774a9a29
BLAKE2b-256 f0444c170d56cf585768673bdc6e6b5a5efea05fdc9bb00d770c5cc745de02a3

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page