Exercise 1
Let’s create a NumPy implementation:
# UNQ_C1
# GRADED CELL: my_softmax
def my_softmax(z):
""" Softmax converts a vector of values to a probability distribution.
Args:
z (ndarray (N,)) : input data, N features
Returns:
a (ndarray (N,)) : softmax of z
"""
### START CODE HERE ###
n=len(z)
a=np.zeros_like(z)
for i in range(n):
a[i]=np.exp(z[i])/np.sum(np.exp(z))
### END CODE HERE ###
return a
Exercise 2
Below, using Keras Sequential model and Dense Layer with a ReLU activation to construct the three layer network described above.
# UNQ_C2
# GRADED CELL: Sequential model
tf.random.set_seed(1234) # for consistent results
model = Sequential(
[
### START CODE HERE ###
tf.keras.Input(shape=(400,)),
tf.keras.layers.Dense(units=25,activation='relu',name="L1"),
tf.keras.layers.Dense(units=15,activation='relu',name="L2"),
tf.keras.layers.Dense(units=10,activation='linear',name="L3"),
### END CODE HERE ###
], name = "my_model"
)