Antrenarea unei rețele în TensorFlow

Introducere în TensorFlow în Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Imaginea arată un grafic 3D al unei funcții obiectiv complexe numite funcția eggholder.

Introducere în TensorFlow în Python

Inițializatori aleatori

  • Adesea este necesară inițializarea a mii de variabile
    • tf.ones() poate performa slab
    • Inițializarea individuală este anevoioasă
  • Alternativ, valorile inițiale se extrag dintr-o distribuție
    • Normală
    • Uniformă
    • Inițializatorul Glorot
Introducere în TensorFlow în Python

Inițializarea variabilelor în 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]))
Introducere în TensorFlow în Python

Inițializarea variabilelor în 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')
Introducere în TensorFlow în Python

Rețele neuronale și supraajustare

Imaginea arată predicțiile modelelor simple și complexe pe setul de antrenare.

Imaginea arată predicțiile modelelor simple și complexe pe setul de validare.

Introducere în TensorFlow în Python

Aplicarea dropout

Această imagine arată o rețea neuronală fără dropout.

Această imagine arată o rețea neuronală cu dropout aplicat pe noduri aleatorii.

Introducere în TensorFlow în Python

Implementarea dropout într-o rețea

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)
Introducere în TensorFlow în Python

Implementarea dropout într-o rețea

# 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)
Introducere în TensorFlow în Python

Să exersăm!

Introducere în TensorFlow în Python

Preparing Video For Download...