เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

แนวทาง low-level กับตัวอย่างหลายรายการ

ในแบบฝึกหัดนี้ เราจะเสริมความเข้าใจเกี่ยวกับแนวทาง low-level ด้วยการสร้าง dense hidden layer แรกสำหรับกรณีที่มีตัวอย่างหลายรายการ สมมติว่าโมเดลผ่านการเทรนแล้ว และค่าน้ำหนักของเลเยอร์แรก weights1 รวมถึงค่า bias bias1 พร้อมใช้งานแล้ว จากนั้นเราจะคูณเมทริกซ์ระหว่างเทนเซอร์ borrower_features กับตัวแปร weights1 โดย borrower_features ประกอบด้วยข้อมูลระดับการศึกษา สถานภาพสมรส และอายุ สุดท้าย เราจะประยุกต์ใช้ฟังก์ชัน sigmoid กับสมาชิกของ products1 + bias1 เพื่อให้ได้ 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}\)

โปรดทราบว่า matmul() และ keras() ถูกนำเข้ามาจาก tensorflow แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

TensorFlow เบื้องต้นใน Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • คำนวณ products1 โดยคูณเมทริกซ์ของเทนเซอร์ features กับค่าน้ำหนัก
  • ใช้ฟังก์ชัน activation แบบ sigmoid เพื่อแปลงค่า products1 + bias1
  • แสดงรูปร่างของ borrower_features, weights1, bias1 และ dense1

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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)
แก้ไขและรันโค้ด