Các bộ tối ưu hóa

Nhập môn TensorFlow bằng Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Cách tìm điểm cực tiểu

Hình ảnh cho thấy Grand Canyon.

1 Nguồn: U.S. National Park Service
Nhập môn TensorFlow bằng Python

Cách tìm điểm cực tiểu

Hình ảnh cho thấy Grand Canyon.

1 Nguồn: U.S. National Park Service
Nhập môn TensorFlow bằng Python

Cách tìm điểm cực tiểu

Hình ảnh cho thấy Grand Canyon.

1 Nguồn: U.S. National Park Service
Nhập môn TensorFlow bằng Python

Hình minh họa quỹ đạo học của các bộ tối ưu SGD, RMSprop và Adam cho một bài toán đơn giản.

Nhập môn TensorFlow bằng Python

Bộ tối ưu gradient descent

  • Bộ tối ưu Stochastic Gradient Descent (SGD)

    • tf.keras.optimizers.SGD()
    • learning_rate
  • Đơn giản, dễ hiểu

Nhập môn TensorFlow bằng Python

Bộ tối ưu RMSprop

  • Bộ tối ưu RMSprop (Root Mean Squared propagation)

    • Áp dụng tốc độ học khác nhau cho từng đặc trưng
    • tf.keras.optimizers.RMSprop()
    • learning_rate
    • momentum
    • decay
  • Cho phép đà (momentum) tăng và giảm

Nhập môn TensorFlow bằng Python

Bộ tối ưu Adam

  • Bộ tối ưu Adam (Adaptive Moment)

    • tf.keras.optimizers.Adam()
    • learning_rate
    • beta1
  • Hoạt động tốt với tham số mặc định

Nhập môn TensorFlow bằng Python

Ví dụ hoàn chỉnh

import tensorflow as tf

# Define the model function
def model(bias, weights, features = borrower_features):
    product = tf.matmul(features, weights)
    return tf.keras.activations.sigmoid(product+bias)
# Compute the predicted values and loss
def loss_function(bias, weights, targets = default, features = borrower_features):
    predictions = model(bias, weights)
    return tf.keras.losses.binary_crossentropy(targets, predictions)
# Minimize the loss function with RMS propagation
opt = tf.keras.optimizers.RMSprop(learning_rate=0.01, momentum=0.9)
opt.minimize(lambda: loss_function(bias, weights), var_list=[bias, weights])
Nhập môn TensorFlow bằng Python

Vamos praticar!

Nhập môn TensorFlow bằng Python

Preparing Video For Download...