atomgrad
1.0.0

Atomgradは、ニューラルネットワークAPIライブラリと組み合わせたベクトル値とスカラー値テンソル(原子)で自動装置を実行するマイクログラードとTinygradの間にあることを目的とするシンプルなオートグラードエンジンです。
sum 、 exp 、 reshape 、 randint 、 uniformなど)をサポートします。relu 、 sigmoid 、 tanhなどの活性化機能をサポートします。binary_cross_entropy & binary_accuracyをサポートします。PIPを使用してAtomgradをインストールできます。
pip install atomgrad==0.3.0Atomgradを使用して関数の勾配を計算する簡単な例を次に示します。
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を使用して、バイナリ分類のために1つの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%
''' make_moonsデータセットやMnist Digits Datasetを含む単純な自動装置と4つのバイナリ分類子の例はexamples/demos.ipynbノートブックにあります。
注: atom.nnにはsoftmaxアクティブ化とcat_cross_entropyが含まれていますが、モデルの結果は非常に失望しており、いくつかのバグが原因である可能性があります(見つけた場合はplz lmk!)。その結果、 AtomNetモデルは、バイナリ分類ニューラルネットタスクに最適です。