atomgrad
1.0.0

Atomgrad是一種簡單的自動射擊發動機,旨在在微電磁和TinyGrad之間進行載體值,並在矢量值和標量值張量(原子)以及神經網絡API庫中進行autodiff。
sum , exp , reshape , randint , uniform等)。relu , sigmoid , tanh等。binary_cross_entropy & binary_accuracy 。您可以使用PIP安裝Atomgrad:
pip install atomgrad==0.3.0這是使用Atomgrad來計算函數梯度的一個簡單示例:
from atomgrad . atom import Atom
from atomgrad . graph import draw_dot
# create two tensors with gradients enabled
x = Atom ( 2.0 , requires_grad = True )
y = Atom ( 3.0 , requires_grad = True )
# define a function
z = x * y + x ** 2
# compute the backward pass
z . backward ()
# print the gradients
print ( x . grad ) # 7.0
print ( y . grad ) # 2.0
draw_dot ( z )
這是一個簡單的示例,即使用Atomgrad訓練一個16個節點隱藏的層神經網絡進行二進制分類。
import numpy as np
from atomgrad . atom import Atom
from atomgrad . nn import AtomNet , Layer
from atomgrad . optim import SGD
from atomgrad . metrics import binary_cross_entropy , binary_accuracy
# create a model
model = AtomNet (
Layer ( 2 , 16 ),
Layer ( 16 , 16 ),
Layer ( 16 , 1 )
)
# create an optimizer
optim = SGD ( model . parameters (), lr = 0.01 )
# load some data
x = [[ 2.0 , 3.0 , - 1.0 ],
[ 3.0 , - 1.0 , 0.5 ],
[ 0.5 , 1.0 , 1.0 ],
[ 1.0 , 1.0 , - 1.0 ],
[ 0.0 , 4.0 , 0.5 ],
[ 3.0 , - 1.0 , 0.5 ]]
y = [ 1 , 1 , 0 , 1 , 0 , 1 ]
x = Atom ( x )
y = Atom ( y )
model . fit ( x , y , optim , binary_cross_entropy , binary_accuracy , epochs = 100 )
#output
'''
...
epoch: 30 | loss: 0.14601783454418182 | accuracy: 100.0%
epoch: 35 | loss: 0.11600304394960403 | accuracy: 100.0%
epoch: 40 | loss: 0.09604986757040024 | accuracy: 100.0%
epoch: 45 | loss: 0.0816292017698288 | accuracy: 100.0%
''' examples/demos.ipynb Notebook中,簡單的Autodiff和四個二進制分類器(包括make_moons數據集和MNIST數據集)的示例。
注意:儘管atom.nn包括softmax激活和cat_cross_entropy ,但模型結果非常失望,可能是由於某些錯誤(如果您找到的話,請使用它!)。結果, AtomNet模型最適合二進制分類神經淨任務。