BendMlAutograd.linear_bwd: def of bend-ml-autograd@0.1.1.0 Import: import bend-ml-autograd@0.1.1.0/main.bend as BendMlAutograd Lines 215-221 of bend-ml-autograd@0.1.1.0/main.bend: https://jend.leeeet.dev/read.txt?path=bend-ml-autograd@0.1.1.0/main.bend&start_line=215&end_line=221 import Base import bend-ml-tensor@0.1.0.0/main.bend as T # Given the gradient dy arriving at y, returns (dx, (dW, db)): # dx = dy · Wᵀ (n x o)·(o x i) = n x i # dW = xᵀ · dy (i x n)·(n x o) = i x o # db = sum of the rows of dy # If any of these products had the wrong dimensions, the program would not compile. def linear_bwd(+n: Nat, +i: Nat, +o: Nat, x: T.Mat, w: T.Mat, +dy: T.Mat) -> T.Mat & (T.Mat & T.Vec): (T.Mat.matmul(n, o, i, dy, T.Mat.transpose(i, o, w)), (T.Mat.matmul(i, n, o, T.Mat.transpose(n, i, x), dy), T.Mat.col_sums(n, o, dy))) Uses (8): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=bend-ml-tensor@0.1.2.0/main.bend&name=Mat https://jend.leeeet.dev/definition.txt?path=bend-ml-tensor@0.1.2.0/main.bend&name=Mat.col_sums https://jend.leeeet.dev/definition.txt?path=bend-ml-tensor@0.1.2.0/main.bend&name=Mat.matmul https://jend.leeeet.dev/definition.txt?path=bend-ml-tensor@0.1.2.0/main.bend&name=Mat.transpose https://jend.leeeet.dev/definition.txt?path=bend-ml-tensor@0.1.2.0/main.bend&name=Vec