An open API service indexing awesome lists of open source software.

https://github.com/pit-ray/vim-dnn


https://github.com/pit-ray/vim-dnn

Last synced: 4 months ago
JSON representation

Awesome Lists containing this project

README

          

# vim-dnn

## Dependencies

- [vim-autograd](https://github.com/pit-ray/vim-autograd)

```vim
Plug 'pit-ray/vim-autograd', {'branch': 'vim9'}
```

## Usage

```vim
vim9script

import autoload 'autograd.vim' as ag
import '../autoload/dnn.vim' as nn

var Tensor = ag.Tensor
var HasModule = nn.HasModule

class MLP implements HasModule
this.l1: HasModule
this.l2: HasModule

def new(in_size: number, classes: number)
this.l1 = nn.Linear.new(in_size, 100)
this.l2 = nn.Linear.new(100, classes)
enddef

def GetParameters(): list
var params: list
params += this.l1.GetParameters()
params += this.l2.GetParameters()
return params
enddef

def Forward(...inputs: list): Tensor
var h = nn.ReLU(this.l1.Forward(inputs[0]))
h = nn.Softmax(this.l2.Forward(h))
return h
enddef
endclass

def Main()
var model = MLP.new(3, 13)

var inputs = ag.Zeros([2, 3])
var y = model.Forward(inputs)
echo y.data
enddef

Main()
```