Metadata-Version: 2.4
Name: opuscleaner
Version: 0.0.0
Project-URL: Documentation, https://github.com/hplt-project/opuscleaner#readme
Project-URL: Issues, https://github.com/hplt-project/opuscleaner/issues
Project-URL: Source, https://github.com/hplt-project/opuscleaner
Author-email: Jelmer van der Linde <jelmer@ikhoefgeen.nl>
License-Expression: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.9
Requires-Dist: babel==2.17.0
Requires-Dist: fastapi==0.78.0
Requires-Dist: pyyaml>=6.0.1
Requires-Dist: uvicorn==0.20.0
Requires-Dist: xxhash==3.2.0
Provides-Extra: all
Requires-Dist: babel; extra == 'all'
Requires-Dist: bicleaner; extra == 'all'
Requires-Dist: bifixer; extra == 'all'
Requires-Dist: fasttext; extra == 'all'
Requires-Dist: fugashi[unidic-lite]==1.1.2; extra == 'all'
Requires-Dist: hanziconv==0.3.2; extra == 'all'
Requires-Dist: iso639-lang==2.6.3; extra == 'all'
Requires-Dist: laserembeddings[ja,zh]==1.1.2; extra == 'all'
Requires-Dist: more-itertools; extra == 'all'
Requires-Dist: opusfilter==2.6.0; extra == 'all'
Requires-Dist: pycld2==0.41; extra == 'all'
Requires-Dist: requests; extra == 'all'
Requires-Dist: sacremoses; extra == 'all'
Requires-Dist: spacy-pkuseg; extra == 'all'
Description-Content-Type: text/markdown

# OpusCleaner
OpusCleaner is a machine translation/language model data cleaner and training scheduler. The Training scheduler has moved to [OpusTrainer](https://github.com/hplt-project/OpusTrainer).

## Cleaner
The cleaner bit takes care of downloading and cleaning multiple different datasets and preparing them for translation.

```sh
opuscleaner-clean --parallel 4 data/train-parts/dataset.filter.json | gzip -c > clean.gz
```

### Installation for cleaning
If you just want to use OpusCleaner for cleaning, you can install it from PyPI, and then run it

```sh
pip3 install opuscleaner
opuscleaner-server
```

Then you can go to http://127.0.0.1:8000/ to show the interface.

You can also install and run OpusCleaner on a remote machine, and use [SSH local forwarding](https://www.ssh.com/academy/ssh/tunneling-example) (e.g. `ssh -L 8000:localhost:8000 you@remote.machine`) to access the interface on your local machine.

### Dependencies
(Mainly listed as shortcuts to documentation)

- [FastAPI](https://fastapi.tiangolo.com) as the base for the backend part.
- [Pydantic](https://pydantic-docs.helpmanual.io/) for conversion of untyped JSON to typed objects. And because FastAPI automatically supports it and gives you useful error messages if you mess up things.
- [Vue](https://vuejs.org/guide/introduction.html) for frontend

### Screenshots

List and categorize the datasets you are going to use for training.
[<img src="https://github.com/hplt-project/OpusCleaner/raw/main/.github/screenshots/list-datasets.png" width="100%">](https://github.com/hplt-project/OpusCleaner/blob/main/.github/screenshots/list-datasets.png)

Download more datasets right from the interface.
[<img src="https://github.com/hplt-project/OpusCleaner/raw/main/.github/screenshots/add-datasets.png" width="100%">](https://github.com/hplt-project/OpusCleaner/blob/main/.github/screenshots/add-datasets.png)

Filter each individual dataset, showing you the results immediately.
[<img src="https://github.com/hplt-project/OpusCleaner/raw/main/.github/screenshots/filter-datasets.png" width="100%">](https://github.com/hplt-project/OpusCleaner/blob/main/.github/screenshots/filter-datasets.png)

Compare the dataset at different stages of filtering to see what the impact is of each filter.
[<img src="https://github.com/hplt-project/OpusCleaner/raw/main/.github/screenshots/diff-filter-output.png" width="100%">](https://github.com/hplt-project/OpusCleaner/blob/main/.github/screenshots/diff-filter-output.png)

### Using your own data
OpusCleaner scans for datasets and finds them automatically if they're in the right format. When you download OPUS data, it will get converted to this format, and there's nothing stopping you from adding your own in the same format.

By default, it scans for files matching `data/train-parts/*.*.gz` and will derive which files make up a dataset from the filenames: `name.en.gz` and `name.de.gz` will be a dataset called _name_. The files are your standard moses format: a single sentence per line, and each Nth line in the first file will match with the Nth line of the second file.

When in doubt, just download one of the OPUS datasets through OpusCleaner, and replicate the format for your own dataset.

If you want to use another path, you can use the `DATA_PATH` environment variable to change it, e.g. run `DATA_PATH="./my-datasets/*.*.gz" opuscleaner-server`.

### Paths
- `data/train-parts` is scanned for datasets. You can change this by setting the `DATA_PATH` environment variable, the default is `data/train-parts/*.*.gz`.
- `filters` should contain filter json files. You can change the `FILTER_PATH` environment variable, the default is `<PYTHON_PACKAGE>/filters/*.json`.


### Installation for development
For building from source (i.e. git, not anything downloaded from Pypi) you'll need to have node + npm installed.

```sh
python3 -m venv .env
bash --init-file .env/bin/activate
pip install -e .
```

Finally you can run `opuscleaner-server` as normal. The `--reload` option will cause it to restart when any of the python files change.

```sh
opuscleaner-server serve --reload
```

Then go to http://127.0.0.1:8000/ for the "interface" or http://127.0.0.1:8000/docs for the API.

### Frontend development

If you're doing frontend development, try also running:

```sh
cd frontend
npm run dev
```

Then go to http://127.0.0.1:5173/ for the "interface".

This will put vite in hot-reloading mode for easier Javascript dev. All API requests will be proxied to the python server running in 8000, which is why you need to run both at the same time.

## Filters

If you want to use LASER, you will also need to download its assets:

```sh
python -m laserembeddings download-models
```

## Packaging

Run `npm build` in the `frontend/` directory first, and then run `hatch build .` in the project directory to build the wheel and source distribution.

To push a new release to Pypi from Github, tag a commit with a `vX.Y.Z` version number (including the `v` prefix). Then publish a release on Github. This should trigger a workflow that pushes a sdist + wheel to pypi.

# Acknowledgements

This project has received funding from the European Union’s Horizon Europe research and innovation programme under grant agreement No 101070350 and from UK Research and Innovation (UKRI) under the UK government’s Horizon Europe funding guarantee [grant number 10052546]
