MulaiMulai sekarang secara gratis

The low-level approach with multiple examples

In this exercise, we'll build further intuition for the low-level approach by constructing the first dense hidden layer for the case where we have multiple examples. We'll assume the model is trained and the first layer weights, weights1, and bias, bias1, are available. We'll then perform matrix multiplication of the borrower_features tensor by the weights1 variable. Recall that the borrower_features tensor includes education, marital status, and age. Finally, we'll apply the sigmoid function to the elements of products1 + bias1, yielding 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}\)

Note that matmul() and keras() have been imported from tensorflow.

Latihan ini adalah bagian dari kursus

Introduction to TensorFlow in Python

Lihat Kursus

Petunjuk latihan

  • Compute products1 by matrix multiplying the features tensor by the weights.
  • Use a sigmoid activation function to transform products1 + bias1.
  • Print the shapes of borrower_features, weights1, bias1, and dense1.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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)
Edit dan Jalankan Kode