Created
July 20, 2021 12:52
-
-
Save lazuxd/f1e95d40d7361b89ae188b22bc952b75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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