Skip to content

Instantly share code, notes, and snippets.

@lazuxd
Created July 20, 2021 12:52
Show Gist options
  • Save lazuxd/f1e95d40d7361b89ae188b22bc952b75 to your computer and use it in GitHub Desktop.
Save lazuxd/f1e95d40d7361b89ae188b22bc952b75 to your computer and use it in GitHub Desktop.
def __call__(self,
x: Union[np.ndarray, tf.Tensor],
y: Union[np.ndarray, tf.Tensor, None] = None) -> tf.Tensor:
for i in range(self.depth):
x = self._call_level(i, x)
y_logits = tf.linalg.matmul(x, self.wy)+self.by
if y is None:
# during prediction return softmax probabilities
return tf.nn.softmax(y_logits)
else:
# during training return loss
return tf.math.reduce_mean(
tf.nn.softmax_cross_entropy_with_logits(y, y_logits))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment