
Atomgrad เป็นเอ็นจิ้นอัตโนมัติแบบง่าย ๆ ที่มีจุดมุ่งหมายที่จะอยู่ระหว่าง micrograd และ Tinygrad ที่ทำงานอัตโนมัติในเทนเซอร์ที่มีค่าและสเกลาร์ที่มีค่าสเกลาร์ (อะตอม) ควบคู่ไปกับห้องสมุด Neural Network API
sum , exp , reshape , randint , uniform , ฯลฯ )relu , sigmoid , tanh ฯลฯbinary_cross_entropy & binary_accuracyคุณสามารถติดตั้ง AtomGrad โดยใช้ PIP:
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%
''' ตัวอย่างของ Autodiff อย่างง่ายและตัวแยกประเภทไบนารีสี่ตัวรวมถึงชุดข้อมูล make_moons และชุดข้อมูลตัวเลข MNIST อยู่ใน examples/demos.ipynb Notebook
หมายเหตุ: แม้ว่า atom.nn จะมีการเปิดใช้งาน softmax และ cat_cross_entropy ผลลัพธ์ของแบบจำลองค่อนข้างผิดหวังและอาจเกิดจากข้อผิดพลาดบางอย่าง (PLZ LMK ถ้าคุณพบ!) เป็นผลให้โมเดล AtomNet เหมาะที่สุดสำหรับการจำแนกแบบไบนารีงานประสาทสุทธิ