Solution: Loss and Activation function
Let’s review the solution.
Solution 1: Implementation of loss functions
Here is the implementation of the following functions:
- Softmax cross-entropy
- Cosine similarity
- Huber loss
- CELU
- Softplus
Let’s review the code line-by-line:
-
Lines 1–3: We import all the necessary libraries. JAX or, more specifically,
jax.nn, provides the necessary activation functions, while optax contains all the optimizer and loss functions. -
Lines 4–5: We define the JAX arrays:
logitsandlabels. -
Lines 8–13: We call the ...