trax/tf_numpy/examples/mnist/model.py
def train(self, x, y):
        """Runs a single training pass.

        Args:
            x: 2-d array of size batch_size x image_size.
            y: 2-d array of size batch_size x num_classes in one-hot notation.
            learning_rate: The learning rate.

        Returns:
            The loss of this training pass
        """
        len_dim_0 = x.shape[0]
        x = np.reshape(x, (len_dim_0, 784))
        with tf.GradientTape() as tape:
            tape.watch(self.layers)
            y_out = self.forward(x)
            loss = self.mean_squared_error(y_out, y)
            grads = tape.gradient(loss, self.layers)
            temp_layers = []
            for layer, grad in zip(self.layers, grads):
                new_w = layer.weights - (self.learning_rate * grad.weights)
                new_b = layer.biases - (self.learning_rate * grad.biases)
                temp_layers.append(self.Layer(new_w, new_b))
            self.layers = temp_layers

        return loss
Runs a single training pass.

        Args:
            x: 2-d array of size batch_size x image_size.
            y: 2-d array of size batch_size x num_classes in one-hot notation.
            learning_rate: The learning rate.

        Returns:
            The loss of this training pass
        
Runs a single training pass.
Runs a single training pass .
def train(self, x, y):
        len_dim_0 = x.shape[0]
        x = np.reshape(x, (len_dim_0, 784))
        with tf.GradientTape() as tape:
            tape.watch(self.layers)
            y_out = self.forward(x)
            loss = self.mean_squared_error(y_out, y)
            grads = tape.gradient(loss, self.layers)
            temp_layers = []
            for layer, grad in zip(self.layers, grads):
                new_w = layer.weights - (self.learning_rate * grad.weights)
                new_b = layer.biases - (self.learning_rate * grad.biases)
                temp_layers.append(self.Layer(new_w, new_b))
            self.layers = temp_layers
        return loss
def train ( self , x , y ) : len_dim_0 = x . shape [ 0 ] x = np . reshape ( x , ( len_dim_0 , 784 ) ) with tf . GradientTape ( ) as tape : tape . watch ( self . layers ) y_out = self . forward ( x ) loss = self . mean_squared_error ( y_out , y ) grads = tape . gradient ( loss , self . layers ) temp_layers = [ ] for layer , grad in zip ( self . layers , grads ) : new_w = layer . weights - ( self . learning_rate * grad . weights ) new_b = layer . biases - ( self . learning_rate * grad . biases ) temp_layers . append ( self . Layer ( new_w , new_b ) ) self . layers = temp_layers return loss
Runs a single training pass.
Runs a single training pass .
"""Runs a single training pass.

        Args:
            x: 2-d array of size batch_size x image_size.
            y: 2-d array of size batch_size x num_classes in one-hot notation.
            learning_rate: The learning rate.

        Returns:
            The loss of this training pass
        """
The loss of this training pass
The loss of this training pass
self
x
2-d array of size batch_size x image_size.
2 - d array of size batch_size x image_size .
y
2-d array of size batch_size x num_classes in one-hot notation.
2 - d array of size batch_size x num_classes in one - hot notation .
learning_rate
The learning rate.
The learning rate .