Skip to main content

Multi code-snippet generator for notebooks

Project description

📘 Machine Learning Snippet Generator (lerl)

A lightweight Python library that generates ready-to-run Machine Learning code snippets for students, beginners, and researchers working with AI algorithms.

This library does not run AI algorithms internally — instead, it returns formatted, complete Python scripts for:

  • Monte Carlo Prediction
  • Temporal Difference (TD(0))
  • Policy Iteration
  • Value Iteration (coming soon)
    • more upcoming AI algorithms

You can copy the output, paste it into a Jupyter Notebook, Colab, VS Code, or PyCharm, and run it directly.


🚀 Features

✔ Generates complete RL scripts as strings
✔ Code always follows correct RL implementations
✔ Uses format_snippet() to return clean, properly formatted code
✔ Ideal for learning, assignments, and quick experimentation
✔ Zero dependencies for running the library itself
✔ Works in: Jupyter Notebook, Google Colab, VS Code, Spyder, PyCharm


📦 Installation

Install the package using pip:

pip install lerl

---

Upgrade:

pip install --upgrade lerl

🧠 Available Code Snippet Functions

Function Name Algorithm Description
monte_carlo_code() Monte Carlo Prediction Returns a full script for MC value estimation on FrozenLake
td_code() Temporal Difference (TD-0) Generates complete TD learning code with convergence plots
complete_policy_iteration_code() Policy Iteration Returns policy evaluation + improvement + convergence visualization
complete_value_iteration_code() Value Iteration (Coming soon — ready function placeholder)

📝 Example Usage

▶️ Generate Monte Carlo Snippet

from lerl import monte_carlo_code

print(monte_carlo_code())

▶️ Generate TD(0) Snippet

from lerl import td_code

print(td_code())

▶️ Generate Policy Iteration Code

from lerl import complete_policy_iteration_code

print(complete_policy_iteration_code())

Each function returns a complete runnable script containing:

  • Gym environment setup
  • Algorithm implementation
  • Value function updates
  • Convergence plots
  • Printed results

📚 Example Output (Short Preview)

import numpy as np
import gymnasium as gym
import matplotlib.pyplot as plt

env = gym.make('FrozenLake-v1', is_slippery = 'False')

def monte_carlo(env, policy, episodes = 10000, df = 0.99):
    ...

(Full script provided when calling the function.)


🏗 Internal Architecture

lerl/
│
├── __init__.py
├── qrl.py                # Main snippet-generating functions
├── utils.py              # format_snippet() helper
└── README.md

📜 License

This project is licensed under the MIT License. Feel free to use it in academic or commercial projects.


⭐ Support

If this library helps you learn or build RL assignments, give it a ⭐ on GitHub and share it with your friends!


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

lerl-0.3.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lerl-0.3.0-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file lerl-0.3.0.tar.gz.

File metadata

  • Download URL: lerl-0.3.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for lerl-0.3.0.tar.gz
Algorithm Hash digest
SHA256 17816fc0f000486b8a4dbbfad9a825c251ac239b6dca2ff50ae73a4d755a12ec
MD5 8baeac6777e29494633ebe8866e0b484
BLAKE2b-256 a1f3d6b116a3ea3b33a6bc3054858a3f3a40d60b5578725116eae4af23cb1ff7

See more details on using hashes here.

File details

Details for the file lerl-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lerl-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for lerl-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d14702a403d38a2e39d48a89055c142b12f02d315ea37528cc22f5f83e3a40b7
MD5 591730a4c0db5a8888eb7fc05811a4ea
BLAKE2b-256 58bd8df2767c451f8b6d90fe90bf4826d0d87694a595ce871a2a70a46fa4ad0a

See more details on using hashes here.

Supported by

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