Huấn luyện mạng trong TensorFlow

Nhập môn TensorFlow bằng Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Hình 3D của một hàm mục tiêu phức tạp gọi là hàm eggholder.

Nhập môn TensorFlow bằng Python

Bộ khởi tạo ngẫu nhiên

  • Thường cần khởi tạo hàng nghìn biến
    • tf.ones() có thể cho hiệu năng kém
    • Khó và tốn công nếu khởi tạo từng biến
  • Thay vào đó, lấy giá trị đầu từ phân phối
    • Chuẩn (Normal)
    • Phẳng (Uniform)
    • Glorot initializer
Nhập môn TensorFlow bằng Python

Khởi tạo biến trong TensorFlow

import tensorflow as tf

# Define 500x500 random normal variable
weights = tf.Variable(tf.random.normal([500, 500]))

# Define 500x500 truncated random normal variable
weights = tf.Variable(tf.random.truncated_normal([500, 500]))
Nhập môn TensorFlow bằng Python

Khởi tạo biến trong TensorFlow

# Define a dense layer with the default initializer
dense = tf.keras.layers.Dense(32, activation='relu')

# Define a dense layer with the zeros initializer
dense = tf.keras.layers.Dense(32, activation='relu',\
    kernel_initializer='zeros')
Nhập môn TensorFlow bằng Python

Mạng nơ-ron và overfitting

Dự đoán của mô hình đơn giản và phức tạp trên tập huấn luyện.

Dự đoán của mô hình đơn giản và phức tạp trên tập kiểm định.

Nhập môn TensorFlow bằng Python

Áp dụng dropout

Hình minh họa mạng nơ-ron không dùng dropout.

Hình minh họa mạng nơ-ron áp dụng dropout lên các nút ngẫu nhiên.

Nhập môn TensorFlow bằng Python

Cài đặt dropout trong mạng

import numpy as np
import tensorflow as tf

# Define input data
inputs = np.array(borrower_features, np.float32)
# Define dense layer 1
dense1 = tf.keras.layers.Dense(32, activation='relu')(inputs)
Nhập môn TensorFlow bằng Python

Cài đặt dropout trong mạng

# Define dense layer 2
dense2 = tf.keras.layers.Dense(16, activation='relu')(dense1)
# Apply dropout operation
dropout1 = tf.keras.layers.Dropout(0.25)(dense2)
# Define output layer
outputs = tf.keras.layers.Dense(1, activation='sigmoid')(dropout1)
Nhập môn TensorFlow bằng Python

Ayo berlatih!

Nhập môn TensorFlow bằng Python

Preparing Video For Download...