Giter Site home page Giter Site logo

deniskore / py-ml-to-rs Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 19 KB

An example of loading a Python-trained model into a Rust-based API.

License: MIT License

Jupyter Notebook 68.97% Rust 31.03%
machine-learning rust-ml tenserflow rust rust-lang python-rust

py-ml-to-rs's Introduction

Build Status

Intro

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:
  1. Plain text
  2. Rot13
  3. Caesar
  4. Base85
  5. Base64
  6. Base58

Dependencies

  • Python 3.10+
  • Rust 1.75+

Train Model

  1. Download the English Wiktionary dump.
  2. Open test.ipynb and modify the variable wiktionary_dump_filepath to point to the downloaded dump file.
  3. Execute the first cell in the notebook.
  4. Execute the second cell in the notebook to train the model (ensure that all dependencies associated with TensorFlow and Keras are properly installed).
  5. To evaluate the model, run the third cell.

Usage of web_api

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

License

This project is licensed under the MIT license.

py-ml-to-rs's People

Contributors

deniskore avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.