https://github.com/pit-ray/vim-dnn
https://github.com/pit-ray/vim-dnn
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pit-ray/vim-dnn
- Owner: pit-ray
- License: mit
- Created: 2023-05-13T12:07:16.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-21T12:27:03.000Z (about 3 years ago)
- Last Synced: 2025-10-10T07:42:40.289Z (8 months ago)
- Language: Vim Script
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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()
```