{"id":31066508,"url":"https://github.com/lennymalard/melpy-project","last_synced_at":"2025-09-15T18:03:22.691Z","repository":{"id":265557686,"uuid":"893608298","full_name":"lennymalard/melpy-project","owner":"lennymalard","description":"A NumPy-based deep learning library for building neural networks. It features an automatic differentiation engine and supports training models like LSTM, CNN, and FNN.","archived":false,"fork":false,"pushed_at":"2025-08-31T12:14:38.000Z","size":167157,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-13T19:31:40.074Z","etag":null,"topics":["automatic-differentiation","cnn","data-preprocessing","deep-learning","fnn","fnn-from-scratch","from-scratch","keras","lstm","machine-learning","neural-network","neural-networks","neural-networks-from-scratch","preprocessing","pytorch","tensorflow","tokenizer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lennymalard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-24T21:38:28.000Z","updated_at":"2025-08-31T12:14:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"e35e2f15-1f44-42b2-8b10-5786d2d465c4","html_url":"https://github.com/lennymalard/melpy-project","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"f8f9c4f6c93cdaeea86ae1d8ef8301cd727632a8"},"previous_names":["lennymalard/melpy-project"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lennymalard/melpy-project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lennymalard%2Fmelpy-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lennymalard%2Fmelpy-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lennymalard%2Fmelpy-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lennymalard%2Fmelpy-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lennymalard","download_url":"https://codeload.github.com/lennymalard/melpy-project/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lennymalard%2Fmelpy-project/sbom","scorecard":{"id":584314,"data":{"date":"2025-08-11","repo":{"name":"github.com/lennymalard/melpy-project","commit":"8793e5bd2f69d3763e5811c2d728b61691efba04"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.7,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":5,"reason":"7 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}}]},"last_synced_at":"2025-08-20T20:01:17.686Z","repository_id":265557686,"created_at":"2025-08-20T20:01:17.686Z","updated_at":"2025-08-20T20:01:17.686Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275058663,"owners_count":25398205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automatic-differentiation","cnn","data-preprocessing","deep-learning","fnn","fnn-from-scratch","from-scratch","keras","lstm","machine-learning","neural-network","neural-networks","neural-networks-from-scratch","preprocessing","pytorch","tensorflow","tokenizer"],"created_at":"2025-09-15T18:02:20.439Z","updated_at":"2025-09-15T18:03:22.658Z","avatar_url":"https://github.com/lennymalard.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca id=\"readme-top\"\u003e\u003c/a\u003e\n\n[![Contributors][contributors-shield]][contributors-url]\n[![Forks][forks-shield]][forks-url]\n[![Stargazers][stars-shield]][stars-url]\n[![Issues][issues-shield]][issues-url]\n[![MIT License][license-shield]][license-url]\n[![LinkedIn][linkedin-shield]][linkedin-url]\n\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/lennymalard/melpy-project\"\u003e\n    \u003cimg src=\"images/blank1-1.png\" alt=\"Melpy Project Logo\" width=\"371\" height=\"168\"\u003e\n  \u003c/a\u003e\n\n\u003ch3 align=\"center\" style=\"font-size: 25px;\"\u003e Crafting Deep Learning from the Ground Up \u003c/h3\u003e\n  \u003cp align=\"center\"\u003e\n    \u003ca\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/lennymalard/melpy-project\"\u003e\u003cstrong\u003eExplore the docs »\u003c/strong\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/lennymalard/melpy-project\"\u003eView Demo\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/lennymalard/melpy-project/issues/new?labels=bug\u0026template=bug-report---.md\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/lennymalard/melpy-project/issues/new?labels=enhancement\u0026template=feature-request---.md\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\n\n\u003cdetails\u003e\n  \u003csummary\u003eTable of Contents\u003c/summary\u003e\n  \u003col\u003e\n    \u003cli\u003e\n      \u003ca href=\"#about-the-project\"\u003eAbout The Project\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#built-with\"\u003eBuilt With\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\n      \u003ca href=\"#getting-started\"\u003eGetting Started\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#prerequisites\"\u003ePrerequisites\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#core-features\"\u003eCore Features\u003c/a\u003e\u003c/li\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#automatic-differentiation-engine\"\u003eAutomatic Differentiation Engine\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#popular-deep-learning-architectures\"\u003ePopular Deep Learning Architectures\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#modularity-and-extensibility\"\u003eModularity and Extensibility\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003cli\u003e\u003ca href=\"#model-creation-and-training\"\u003eModel Creation and Training\u003c/a\u003e\u003c/li\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#preprocessing\"\u003ePreprocessing\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#model-creation\"\u003eModel Creation\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#model-summary\"\u003eModel Summary\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#training-the-model\"\u003eTraining the Model\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#save-your-work\"\u003eSave your Work\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003cli\u003e\u003ca href=\"#errors\"\u003eErrors\u003c/a\u003e\u003c/li\u003e\n       \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#shape-errors\"\u003eShape Errors\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003cli\u003e\u003ca href=\"#roadmap\"\u003eRoadmap\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contributing\"\u003eContributing\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contact\"\u003eContact\u003c/a\u003e\u003c/li\u003e\n\n  \u003c/ol\u003e\n\u003c/details\u003e\n\n\n\n## About The Project\n\nMelpy is a **Python deep learning library** built **from scratch** using only **NumPy**. It provides an accessible way to create, train, and understand fundamental **neural network** architectures like **Feedforward Neural Networks (FNNs), Convolutional Neural Networks (CNNs), and Long Short-Term Memory (LSTMs)**, featuring a clear **automatic differentiation** engine. Ideal for learners and those seeking intuition into **machine learning** algorithms without high-level abstractions.\n\nStarted in 2022 during high school, this project stemmed from frustration with the lack of clarity in how complex algorithms worked in existing frameworks. Building custom implementations led to deeper understanding and evolved into Melpy.\n\nInspired by leading **machine learning** tools, Melpy simplifies creating and training common **deep learning** models. It includes essential tools for data preprocessing and visualization, offering a complete, albeit fundamental, **neural network** workflow. Melpy's key feature is simplicity, offering an accessible experience for beginners exploring **deep learning**. It serves as both a learning resource and a foundation for expansion, implementing core functionalities simply to provide clear intuition.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### Built With\n\n [![Numpy][Numpy.org]][numpy-url] [![Matplotlib][Matplotlib.org]][Matplotlib-url] [![tqdm][tqdm.github.io]][tqdm-url] [![H5PY][docs.h5py.org]][h5py-url]\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## Getting Started\n\n### Prerequisites\n\nRequires an up-to-date **Python** environment ([conda](https://www.anaconda.com/download) recommended for scientific use).\n\nDependencies (including **NumPy**) are installed automatically.\n\n### Installation\n\nMelpy is available on PyPI. Install the latest version using pip:\n   ```sh\n   pip3 install melpy --upgrade\n   ```\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## Core Features\n\n### Automatic Differentiation Engine\n\nMelpy computations rely on `Tensor` objects (extended **NumPy** arrays) and `Operation` types. Together, they construct **computational graphs**, enabling precise **gradient calculation** via an **automatic differentiation** algorithm. This simplifies implementing the **backpropagation** step for various layer types in your **neural network**.\n\n[Tensor](https://github.com/lennymalard/melpy-project/blob/main/melpy/Tensor.py#L4) extends NumPy arrays, adding `requires_grad` (bool), `grad` (gradient tensor), and `_op` (producing operation) attributes.\n```\nClass Tensor:\n    Function __init__(object, requires_grad, _operation, additional arguments):\n        Attributes\n        - array : float64 numpy array\n        - grad : melpy tensor\n        - requires_grad : bool\n        - _op : melpy operation\n```\n\n[Operation](https://github.com/lennymalard/melpy-project/blob/main/melpy/Tensor.py#L164) adds a forward pass (builds the graph) and a backward pass (computes derivatives, updates/propagates gradients).\n```\nClass _Operation:\n    Function __init__(x1, x2, additional arguments):\n        Attributes\n        - x1 : melpy tensor\n        - x2 : melpy tensor\n        - output : melpy tensor\n```\n\nExample: Compute y = 5 * x, find dy/dx using **automatic differentiation**.\n```python\nx = tensor([0, 1, 2, 3, 4], requires_grad=True)\ny = 5 * x\n\nprint(y)\n```\nOutput:\n```sh\n[0., 5., 10., 15., 20.]\n```\n\nPropagate gradient backward:\n```python\ny.backward(1)\n\nprint(x.grad)\n```\nOutput shows dy/dx = 5 for each element, as expected:\n```sh\n[5., 5., 5., 5., 5.]\n```\n\n\u003cbr\u003e\n\u003cdiv align=\"center\"\u003e\n \u003cimg src=\"images/graph.drawio.png\" alt=\"Computational graph for multiplication showing Tensors and Operation\" width=\"auto\" height=\"auto\"\u003e\n \u003cp \u003e\n  \u003cem\u003eFigure 1: Computational graph of the operation (forward/backward passes).\u003c/em\u003e\n \u003c/p\u003e\n\u003c/div\u003e\n\nTensor and Operation classes form Melpy's core, simplifying complex **neural network** architecture implementation.\n\n_Learn more about **automatic differentiation** on [Wikipedia](https://en.wikipedia.org/wiki/Automatic_differentiation)._\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### Popular Deep Learning Architectures\n\nMelpy supports common **deep learning models** built **from scratch**:\n* **Feedforward Neural Networks (FNNs)**: Using `Dense` layers for tasks like **classification** or regression on tabular data.\n* **Convolutional Neural Networks (CNNs)**: Using `Convolution2D` layers, suitable for basic **image recognition** tasks.\n* **Recurrent Neural Networks (RNNs)**: Specifically **Long Short-Term Memory (LSTM)** units for **sequence analysis** or time series prediction.\n\nBuild these architectures using provided layers and train using the `Sequential` class.\n\nFuture plans include Batch Normalization and potentially generative models like GANs.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### Modularity and Extensibility\n\nKey strength: Modularity. Melpy leverages Object-Oriented Programming with specific types, making it easy to add/modify layers, loss functions, callbacks, etc.\n\nThe `Tensor` type combined with **automatic differentiation** simplifies creating new components without manual **gradient calculation** for simpler tasks. The `Sequential` class integrates components while allowing custom **neural network** architectures and training loops. \n\nResult: Melpy is flexible, adaptable, and upgradable.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## Model Creation and Training\n\nExample: Train a **Feedforward Neural Network (FNN)** for Iris flower **classification**, a classic **machine learning** problem. The dataset has 3 classes and 4 features. Build models for tasks ranging from simple **classification** (like this example) to basic **image recognition** (using `Convolution2D`) or **sequence analysis** (with `LSTM`).\n\nLoad data and split:\n```python\nfrom sklearn.datasets import load_iris\nfrom sklearn.model_selection import train_test_split\n\niris_dataset = load_iris()\n\nX_train, X_test, y_train, y_test = train_test_split(\n        iris_dataset['data'], iris_dataset['target'], test_size=0.25, random_state=0)\n```\nVisualize data:\n```python\nimport matplotlib.pyplot as plt\n\nplt.figure()\nplt.scatter(X_train[:,0], X_train[:,1], c=y_train, alpha=0.3, cmap=\"coolwarm\")\nplt.show()\n```\n\u003cbr\u003e\n\u003cdiv align=\"center\"\u003e\n \u003cimg src=\"images/iris.png\" alt=\"Iris Dataset Scatter Plot showing feature correlation\" width=\"auto\" height=\"auto\"\u003e\n \u003cp \u003e\n  \u003cem\u003eFigure 2: Iris dataset visualized, showing feature separation.\u003c/em\u003e\n \u003c/p\u003e\n\u003c/div\u003e\n\nFigure 2 shows correlation between features (Sepal Length/Width) and species.\n\u003cbr\u003e\n\u003cbr\u003e\n\n### Preprocessing\n\n**Neural Networks** often require scaled input. Use `StandardScaler`:\n\n*The Standard Scaler centers data (removes mean) and scales by variance. More on [Feature Scaling](https://en.wikipedia.org/wiki/Feature_scaling).*\n```python\nfrom melpy.preprocessing import StandardScaler\n\nsc = StandardScaler()\nX_train = sc.transform(X_train)\nX_test = sc.transform(X_test)\n```\n\nEncode target labels using `OneHotEncoder` for **classification**:\n\n*One-hot encoding represents categories as binary vectors. More on [One-hot](https://en.wikipedia.org/wiki/One-hot).*\n```python\nfrom melpy.preprocessing import OneHotEncoder\n\nohe = OneHotEncoder()\ny_train = ohe.transform(y_train)\ny_test = ohe.transform(y_test)\n```\n\n### Model Creation\n\nFor this multi-class tabular **classification** problem, we need:\n*\t[Dense](https://en.wikipedia.org/wiki/Multilayer_perceptron) layers (Fully Connected) for feature learning.\n*\t[Softmax](https://en.wikipedia.org/wiki/Softmax_function) activation for probability outputs.\n*\t[Categorical Cross-Entropy](https://en.wikipedia.org/wiki/Cross-entropy) loss function for optimization.\n\nBuild the **neural network** model with `Sequential`:\n\n*Sequential models stack layers linearly; data flows sequentially.*\n```python\nimport melpy.NeuralNetworks as nn\n\n# Define the sequential model structure\nmodel = nn.Sequential(X_train, y_train, X_test, y_test)\n\n# Add layers: Input -\u003e Hidden (ReLU) -\u003e Output (Softmax)\nmodel.add(nn.Dense(X_train.shape[1], 6, activation=\"relu\"))\nmodel.add(nn.Dense(6, y_train.shape[1], activation=\"softmax\"))\n\n# Compile the model with loss function and optimizer\nmodel.compile(loss_function=nn.CategoricalCrossEntropy(), optimizer=nn.SGD(learning_rate=0.01))\n```\n\nWe define: Training/validation data, hidden layer (6 neurons, [ReLU](https://en.wikipedia.org/wiki/Rectifier_(neural_networks)) activation), output layer (Softmax activation), loss function, and optimizer (SGD).\n\n*This defines the **FNN architecture**. New to **deep learning**? Check [3Blue1Brown](https://youtu.be/aircAruvnKk?si=QMDAzU8ThgQ_nmTt)'s excellent video series.*\n\n### Model Summary\n\nView model structure:\n```python\nmodel.summary()\n```\n```sh\nDense: (1, 6)\nDense: (1, 3)\n```\n\n### Training the Model\n\nTrain the **neural network** model:\n```python\nmodel.fit(epochs=5000, verbose = 1, callbacks=[nn.LiveMetrics()])\nmodel.results()\n```\n\u003cdiv align=\"center\"\u003e\n \u003cimg src=\"images/livemetrics.png\" alt=\"Live Training Metrics Plot showing loss and accuracy\" width=\"auto\" height=\"auto\"\u003e\n \u003cp \u003e\n  \u003cem\u003eFigure 3: Plot updated during training via LiveMetrics() callback.\u003c/em\u003e\n \u003c/p\u003e\n\u003c/div\u003e\n\n```sh\nEpoch [5000/5000]: 100%|██████████| 5000/5000 [00:03\u003c00:00, 1543.94it/s, loss=0.0389, accuracy=0.988]\n\n-------------------------------------------------------------------\n| [TRAINING METRICS] train_loss: 0.03893 · train_accuracy: 0.9881 |\n-------------------------------------------------------------------\n| [VALIDATION METRICS] val_loss: 0.06848 · val_accuracy: 0.98246  |\n-------------------------------------------------------------------\n```\n\nAchieves ~98% accuracy on train/test. Good result for this simple **neural network**. Potential for 100% with tuning.\n\nRight plot shows model inputs colored by prediction, visually confirming good training performance.\n\n### Save Your Work\n\nSave trained **model parameters** and metrics:\n```python\nmodel.save_params(\"iris_parameters\")\nmodel.save_histories(\"iris_metrics\")\n```\n\nReload parameters with `load_params(path)` and metrics using [h5py](https://docs.h5py.org/en/stable/).\n\n_See more examples (including potential **CNN** or **LSTM** use cases) in the [Examples folder](https://github.com/lennymalard/melpy-project/tree/main/examples)_\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## Errors\n\nFirst, clear your console to avoid issues with old variables.\n\n### Shape Errors\nMost runtime errors in **neural network** code involve tensor shape mismatches. Common cause: Mismatched input/output feature counts between consecutive `Dense` or `Convolution2D` layers.\n\nDense example:\n```python\nmodel.add(nn.Dense(X_train.shape[1], 7, activation=\"relu\")) # Output has 7 features\nmodel.add(nn.Dense(6, y_train.shape[1], activation=\"softmax\")) # Expects 6 input features\n```\n```sh\nValueError: shapes (1,7) and (6,2) not aligned: 7 (dim 1) != 6 (dim 0) \n```\nConvolution2D example:\n```python\nmodel.add(nn.Convolution2D(in_channels=1, out_channels=32, ...)) # Output has 32 channels\nmodel.add(nn.Convolution2D(in_channels=12, out_channels=64, ...)) # Expects 12 input channels\n```\n```sh\nValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)-\u003e(n?,m?) (size 128 is different from 48)\n```\nResolution: Ensure `out_features`/`out_channels` of a layer match the expected `in_features`/`in_channels` of the *next* layer in the sequence. \n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## Roadmap\n\nFuture plans:\n* Optimize computation speed (potentially using Numba, JAX and/or multiprocessing).\n* Implement more **deep learning** architectures (e.g., GANs).\n* Add traditional **machine learning** algorithms.\n* Expand layer options.\n\nSee [open issues](https://github.com/lennymalard/melpy-project/issues) for proposed features and known issues.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## Contributing\n\nContributions make the open source community thrive and are **greatly appreciated**. Help improve this **deep learning library**!\n\nIf you have suggestions, please fork the repo and create a pull request, or open an issue with the \"enhancement\" tag. Don't forget to star the project! Thanks!\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## License\n\nDistributed under the MIT License. See `LICENSE.txt` for details.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n\n## Contact\n\nLenny Malard - lennymalard@gmail.com or [Linkedin](https://www.linkedin.com/in/lennymalard/)\n\nProject Link: [https://github.com/lennymalard/melpy-project](https://github.com/lennymalard/melpy-project)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n[contributors-shield]: https://img.shields.io/github/contributors/lennymalard/melpy-project.svg?style=for-the-badge\n[contributors-url]: https://github.com/lennymalard/melpy-project/graphs/contributors\n[forks-shield]: https://img.shields.io/github/forks/lennymalard/melpy-project.svg?style=for-the-badge\n[forks-url]: https://github.com/lennymalard/melpy-project/network/members\n[stars-shield]: https://img.shields.io/github/stars/lennymalard/melpy-project.svg?style=for-the-badge\n[stars-url]: https://github.com/lennymalard/melpy-project/stargazers\n[issues-shield]: https://img.shields.io/github/issues/lennymalard/melpy-project.svg?style=for-the-badge\n[issues-url]: https://github.com/lennymalard/melpy-project/issues/\n[license-shield]: https://img.shields.io/github/license/lennymalard/melpy-project.svg?style=for-the-badge\n[license-url]: https://github.com/lennymalard/melpy-project/blob/main/LICENSE\n[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge\u0026logo=linkedin\u0026colorB=555\n[linkedin-url]: https://www.linkedin.com/in/lennymalard\n[product-screenshot]: images/screenshot.png\n[Numpy-url]: https://numpy.org/\n[Numpy.org]:https://img.shields.io/badge/numpy-red?style=for-the-badge\u0026labelColor=blue\u0026color=blue\n[Matplotlib-url]: https://matplotlib.org\n[Matplotlib.org]: https://img.shields.io/badge/matplotlib-orange?style=for-the-badge\u0026labelColor=blue\u0026color=blue\u0026link=https%3A%2F%2Fmatplotlib.org%2F\n[tqdm-url]: https://tqdm.github.io\n[tqdm.github.io]: https://img.shields.io/badge/tqdm-orange?style=for-the-badge\u0026labelColor=blue\u0026color=blue\u0026link=https%3A%2F%2Ftqdm.github.io%2F\n[h5py-url]: https://docs.h5py.org/en/stable/\n[docs.h5py.org]: https://img.shields.io/badge/H5PY-blue?style=for-the-badge\u0026color=blue\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flennymalard%2Fmelpy-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flennymalard%2Fmelpy-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flennymalard%2Fmelpy-project/lists"}