MCPcopy Index your code
hub / github.com/LdDl/gan-go

github.com/LdDl/gan-go @v0.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.0 ↗ · + Follow
108 symbols 226 edges 15 files 37 documented · 34%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Generative adversarial networks

Recipe for simple GAN in Golang ecosystem via Gorgonia library

Generating f(x) = x^2 Generating f(x) = sin(x)

Table of Contents

About

This just a repository with simple example how to build GAN in Gorgonia

What is GAN? * Short: such networks are just two neural networks (Discriminator and Generator) contesting each other. Generator must "cheat" on Discriminator and the last one should detect lies. * Long: Wiki-page about GAN's - https://en.wikipedia.org/wiki/Generative_adversarial_network

Note: although there is code with some wrappings/aliasing and helping abstractions and functions in repository, this does not pretend to be high-level machine learning framework

Note #2: By the way... Code is ugly since I've decided to handle errors instead of using panic(...) calls. Panicing is considered to be in main functions of examples only

Current examples folder contains limited set of layer types: - [x] Linear - [x] Convolutional - [x] Maxpool - [ ] AvgPool - [x] Flatten - [x] Reshape

Why

Just want to do that in Golang ecosystem.

Instruments

Code is written on Golang - https://golang.org/

Used machine learning library - Gorgonia

Plotting library - gonum

Usage

  • Get the repo shell git clone https://github.com/LdDl/gan-go.git

  • Navigate to examples folder shell cd gan-go cd cmd/examples

  • Pick one of examples. E.g. parabola: shell cd parabola

  • Run example go run main.go

  • Output

    After programm terminates there should be multiple files: 1. Single image for reference function - reference_function.png 2. Multiple images for generated data on N-th epoch - gen_reference_fun_%N-th epoch%.png 3. Single image for generated data on last epoch - gen_reference_func_final.png

    Example for parabola:

    Actual reference function:

    Reference function

    Generated data on 0-th epoch:

    Generated data on 0-th epoch

    Generated data on 10-th epoch:

    Generated data on 10-th epoch

    Generated data on 60-th epoch:

    Generated data on 60-th epoch

    Generated data on 150-th epoch:

    Generated data on 150-th epoch

    Generated data on last epoch:

    Generated data on last epoch

ToDo

Current stage of TODO list for future releases: - [x] Reduce duplicating of code for .Fwd() method of each neural network type (GAN/Discriminator/Generator) - [ ] Switch Layer from struct to interface or use other technique for building clean code - [x] Add basic layers: Linear, Convolutional, Maxpool, Flatten - [ ] Deal with batch process - [x] More loss function - [x] Cross Entropy - [x] Binary Cross Entropy - [x] L1 - [x] Huber (PSEUDO) - [ ] Examples for text data generation WIP - [ ] Simple LSTM - [ ] Proper layer types for RNN WIP - [ ] Examples - [ ] RNN - [ ] GRU - [ ] Embedding

Code explanation

@TODO

Support and contributing

If you have troubles or questions please open an issue.

If you want to improve this library / fix some bugs and etc. you can make PR

Extension points exported contracts — how you extend this code

ActivationFunc (FuncType)
ActivationFunc Just an alias to Gorgonia'a api_gen.go - https://github.com/gorgonia/gorgonia/blob/master/api_gen.go#L1
activation.go
ReferenceFunction (FuncType)
(no doc)
utils.go
ArgumentFunction (FuncType)
(no doc)
utils.go

Core symbols most depended-on inside this repo

Learnables
called by 30
gan.go
Out
called by 27
gan.go
Fwd
called by 14
gan.go
Step
called by 12
utils.go
GeneratorOut
called by 4
gan.go
GeneratorLearnables
called by 4
gan.go
noWeightsAllowed
called by 3
layer.go
addNoiseToNoZeroValues
called by 3
cmd/examples/train_cnn/main.go

Shape

Function 74
Method 18
Struct 9
TypeAlias 4
FuncType 3

Languages

Go100%

Modules by API surface

activation.go25 symbols
utils.go23 symbols
layer.go7 symbols
gan.go7 symbols
loss.go6 symbols
generator.go5 symbols
discriminator.go5 symbols
cmd/examples/sin/main.go5 symbols
cmd/examples/parabola/main.go5 symbols
network.go4 symbols
cmd/examples/train_embedding/main.go4 symbols
cmd/examples/generate_symbol/main.go4 symbols

For agents

$ claude mcp add gan-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page