L'approccio low-level con esempi multipli
In questo esercizio, rafforzeremo l'intuizione sull'approccio low-level costruendo il primo livello denso nascosto nel caso in cui abbiamo più esempi. Supponiamo che il modello sia già addestrato e che i pesi del primo livello, weights1, e il bias, bias1, siano disponibili. Eseguiremo quindi la moltiplicazione di matrici del tensore borrower_features con la variabile weights1. Ricorda che il tensore borrower_features include istruzione, stato civile ed età. Infine, applicheremo la funzione sigmoide agli elementi di products1 + bias1, ottenendo dense1.
\(products1 = \begin{bmatrix} 3 & 3 & 23 \\ 2 & 1 & 24 \\ 1 & 1 & 49 \\ 1 & 1 & 49 \\ 2 & 1 & 29 \end{bmatrix} \begin{bmatrix} -0.6 & 0.6 \\ 0.8 & -0.3 \\ -0.09 & -0.08 \end{bmatrix}\)
Nota che matmul() e keras() sono stati importati da tensorflow.
Questo esercizio fa parte del corso
Introduzione a TensorFlow in Python
Istruzioni dell'esercizio
- Calcola
products1moltiplicando per matrice il tensore delle feature per i pesi. - Usa una funzione di attivazione sigmoide per trasformare
products1 + bias1. - Stampa le forme di
borrower_features,weights1,bias1edense1.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Compute the product of borrower_features and weights1
products1 = ____
# Apply a sigmoid activation function to products1 + bias1
dense1 = ____
# Print the shapes of borrower_features, weights1, bias1, and dense1
print('\n shape of borrower_features: ', borrower_features.shape)
print('\n shape of weights1: ', ____.shape)
print('\n shape of bias1: ', ____.shape)
print('\n shape of dense1: ', ____.shape)