A friend of mine asked me to demonstrate how to load a model trained in Python into a Rust service. In response, this repository showcases the entire process of training a machine learning model to distinguish between various text encodings, achieving around 98.5% validation accuracy, using data sourced from the English Wiktionary. Subsequently, the trained model is seamlessly integrated into a Rust-based microservice, utilizing the ntex-rs. This implementation is streamlined with minimal dependencies, ensuring a lightweight and efficient service.
Supported encodings:
- Plain text
- Rot13
- Caesar
- Base85
- Base64
- Base58
- Python 3.10+
- Rust 1.75+
- Download the English Wiktionary dump.
- Open
test.ipynb
and modify the variablewiktionary_dump_filepath
to point to the downloaded dump file. - Execute the first cell in the notebook.
- Execute the second cell in the notebook to train the model (ensure that all dependencies associated with TensorFlow and Keras are properly installed).
- To evaluate the model, run the third cell.
Run in the web_api directory:
cargo run --release
Run the following command in terminal:
curl -X POST -H "Content-Type: application/json" -d '{"language":"English","data":"HELLO WORLD"}' http://127.0.0.1:3000/predict
The prediction will be presented in the following format:
{"text":"99.51","rot13":"0.00","caesar":"0.49","base85":"0.00","base64":"0.00","base58":"0.00"}
This project is licensed under the MIT license.