{"id":37225906,"url":"https://github.com/daniel4x/gograd","last_synced_at":"2026-01-15T01:51:06.311Z","repository":{"id":275728115,"uuid":"926993946","full_name":"daniel4x/GoGrad","owner":"daniel4x","description":"An educational implementation of backpropagation computational graph in Go","archived":false,"fork":false,"pushed_at":"2025-02-14T13:41:11.000Z","size":1152,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-22T15:30:55.872Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/daniel4x.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-02-04T08:11:49.000Z","updated_at":"2025-02-14T13:41:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"323272d8-ed98-4a68-9a37-d3e76dc78ff7","html_url":"https://github.com/daniel4x/GoGrad","commit_stats":null,"previous_names":["daniel4x/gograd"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/daniel4x/GoGrad","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel4x%2FGoGrad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel4x%2FGoGrad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel4x%2FGoGrad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel4x%2FGoGrad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daniel4x","download_url":"https://codeload.github.com/daniel4x/GoGrad/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel4x%2FGoGrad/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28441031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T00:55:22.719Z","status":"ssl_error","status_checked_at":"2026-01-15T00:55:20.945Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-01-15T01:51:05.739Z","updated_at":"2026-01-15T01:51:06.299Z","avatar_url":"https://github.com/daniel4x.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoGrad \n\u0026middot; \n[![Go Reference](https://pkg.go.dev/badge/github.com/daniel4x/GoGrad)](https://pkg.go.dev/github.com/daniel4x/GoGrad) \n[![Go](https://github.com/daniel4x/GoGrad/actions/workflows/go.yml/badge.svg)](https://github.com/daniel4x/GoGrad/actions/workflows/go.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/daniel4x/GoGrad)](https://goreportcard.com/report/github.com/daniel4x/GoGrad)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./artifacts/gograd.png\" width=\"300\" alt=\"GoGrad Logo\" /\u003e\n\u003c/p\u003e\n\n\u003e **Educational Project** – Implementing computational graphs and backpropagation in Go, inspired by [micrograd](https://github.com/karpathy/micrograd) \u0026 [nn-zero-to-hero](https://github.com/karpathy/nn-zero-to-hero) by Andrej Karpathy.\n\n---\n\n## Table of Contents\n\n1. [Introduction](#introduction)  \n2. [Motivation](#motivation)  \n3. [Features](#features)  \n4. [Quick Start](#quick-start)  \n5. [Example: Training a Tiny Network](#example-training-a-tiny-network)  \n6. [Running Tests](#running-tests)  \n7. [Contributing](#contributing)  \n8. [License](#license)\n\n---\n\n## Introduction\n**GoGrad** is a minimal Go-based library for experimenting with computational graphs and automated differentiation (backprop). The goal is to provide a simple, readable codebase for learning how backpropagation actually works under the hood—**no heavy frameworks required**.\n\nYou’ll find:\n- A `Value` struct that tracks data, gradients, and the relationships between nodes in the graph.  \n- Basic ops (add, mul, pow, tanh, etc.) with corresponding backward passes.  \n- A small feedforward neural net (MLP) implementation with multiple layers, each composed of neurons.\n\n\u003e **Disclaimer**: This is **not** intended to be a production-grade deep learning framework. It's purely educational, focusing on the core backprop mechanics and a pinch of “neural net flavor”.\n\n---\n\n## Motivation\nWhy implement yet another deep learning library in Golang?  \n- **Hands-On Learning**: Implementing backprop from scratch is the best way to master how neural nets really work.  \n- **Go Ecosystem**: Go is known for simplicity, concurrency, and robust tooling. It’s a fun place to explore ML fundamentals without overhead.  \n- **Personal Growth**: I needed to learn Go for work and wanted to do something more interesting than “Hello, World!”  \n\n---\n\n## Features\n- **Core Autograd Engine**  \n  - A `Value` type that stores `data`, `grad`, and function references for backward propagation.\n  - Support for basic math ops: `+`, `-`, `*`, `/`, `Pow`, `Tanh`, etc.\n\n- **Multi-Layer Perceptron**  \n  - A minimal feedforward neural network (`MLP`) built on top of the `Value` nodes.\n  - Forward and backward passes with everything you need for small-scale toy problems.\n\n- **Tests**  \n  - Includes unit tests verifying correctness of the gradient computations against numerical approximations.\n\n---\n\n## Quick Start\n1. **Clone the repo**:\n   ```bash\n   git clone https://github.com/daniel4x/gograd.git\n   cd gograd\n   ```\n2. **Run tests** (verifies everything is working):\n   ```bash\n   go test ./engine -v\n   ```\n3. **Use it in your own code** (if you like):\n   ```go\n   go get github.com/daniel4x/gograd\n   ```\n   Then import in your project:\n   ```go\n   import (\n       \"github.com/daniel4x/gograd/engine\"\n   )\n   ```\n\n---\n\n## Example: Training a Tiny Network\n\nHere’s a minimal code snippet you can run to see “learning” in action:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/daniel4x/gograd/engine\"\n)\n\nfunc main() {\n    // 1) Define a small MLP (3 inputs -\u003e [4,4] hidden layers -\u003e 1 output)\n    nn := engine.NewMLP(3, []int{4, 4, 1})\n\n    // 2) Prepare a tiny dataset (XOR-ish or similar)\n    //    For example, we have 4 examples of (x1, x2, x3) -\u003e y\n    xData := [][]float64{\n        {2.0,  3.0, -1.0},\n        {3.0, -1.0,  0.5},\n        {0.5,  1.0,  1.0},\n        {1.0,  1.0, -1.0},\n    }\n    yData := []float64{ 1, -1, -1, 1 }\n\n    // Convert xData to Value slices\n    xVals := makeValueMatrix(xData)\n\n    // 3) Train loop\n    epochs := 50\n    lr := 0.05\n    for e := 0; e \u003c epochs; e++ {\n        // Forward pass: compute predictions and total loss\n        var loss *engine.Value\n        for i := 0; i \u003c len(xVals); i++ {\n            pred := nn.Call(xVals[i])\n            diff := pred.Sub(yData[i]).Pow(2) // (pred - y)^2\n            if i == 0 {\n                loss = diff\n            } else {\n                loss = loss.Add(diff)\n            }\n        }\n\n        // Zero out gradients\n        for _, p := range nn.Parameters() {\n            p.Grad = 0\n        }\n\n        // Backprop\n        loss.Backward()\n\n        // Gradient descent step\n        for _, p := range nn.Parameters() {\n            p.Data -= lr * p.Grad\n        }\n\n        fmt.Printf(\"Epoch %d - Loss: %.4f\\n\", e, loss.Data)\n    }\n\n    // 4) Final predictions\n    fmt.Println(\"\\nFinal Predictions:\")\n    for i := 0; i \u003c len(xVals); i++ {\n        pred := nn.Call(xVals[i])\n        fmt.Printf(\"x: %v, y: %.2f, pred: %.4f\\n\", xData[i], yData[i], pred.Data)\n    }\n}\n```\n\n**Output**: You should see the loss drop and the final predictions approaching the target `y` values.\n\n---\n\n## Running Tests\nAll engine tests live under the `engine` package. To run them:\n```bash\ngo test ./engine -v\n```\n- `-v` (verbose) will print each test case’s progress and show you iteration-by-iteration logs in certain tests.\n\n---\n\n## Contributing\nWhether you’re learning Go or backprop, contributions are welcome! Here’s how to get started:\n\n1. **Fork \u0026 Clone**:  \n   ```bash\n   git clone https://github.com/daniel4x/gograd.git\n   ```\n2. **Pick an Issue**: Look for [good first issue](https://github.com/daniel4x/gograd/labels/good%20first%20issue) or [help wanted](https://github.com/daniel4x/gograd/labels/help%20wanted) labels.\n3. **Create a Branch**:  \n   ```bash\n   git checkout -b my-new-feature\n   ```\n4. **Open a Pull Request**: Provide a clear description of what you’ve changed or added.\n\n**Ways to contribute**:\n- Implement new math ops (sigmoid, ReLU, etc.).\n- Add an example project (like the XOR problem).\n- Improve docs and code comments for clarity or best practices.\n\n---\n\n## License\nThis project is licensed under the [MIT License](LICENSE). Feel free to use it for learning and research.\n\n---\n\n\u003cp align=\"center\"\u003e\n  Made with ❤️ \u0026 Go.\n\u003c/p\u003e\n\n---\n\n**Happy Learning and Hacking!**  \nIf you find this project interesting or educational, consider giving it a ⭐ on GitHub.  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel4x%2Fgograd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel4x%2Fgograd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel4x%2Fgograd/lists"}