I built a simple neural network (at least i tried to) #1351
Closed
nico-byte
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Recently i heard about mojo and thought i could try to write a neural network in mojo. I thought that would be very easy because mojo is called a subset of Python. Oh boy, i was so naive. Well, i was able to get the general logic to work but had various problems to solve. The first problem i encountered was that my weights and biases either were way too small or way too high (like 1.5e-235...). I noticed that as soon as i am initializing a matrix (from the Matrix Multiplication Docs and some modifications) with the rand or randn function i will encounter this issue. I thought i solved it when i applied the functions to the matrices outside the Matrix struct. When i did that i encountered a "malloc() corrupted top size" error and my code won't compile. Now i just did some experimenting, nothing really works as expected and i introduced a major memory leak, that i couldn't find yet but i still wanted to show it here because i don't think the code is complete garbage and i couldn't find any example on how to write a neural network in mojo.
Here it is, maybe some of you guys see what's wrong here :)
You can find the complete project on my github - https://github.com/nico-byte/mojo_nn
`from random import rand, randn
from math import sqrt
from memory.unsafe import DTypePointer
import numjo as nj
from numjo import Matrix
from time import now
from math import tanh
from math import exp
struct Network:
var _inodes: Int
var _hnodes_l1: Int
var _hnodes_l2: Int
var _onodes: Int
var lr: Float32
var _wih: Matrix
var _whh: Matrix
var _who: Matrix
var _bih_l1: Matrix
var _bih_l2: Matrix
var _bho: Matrix
Beta Was this translation helpful? Give feedback.
All reactions