Fonctions d'activation

Introduction à TensorFlow en Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Qu'est-ce qu'une fonction d'activation ?

  • Composants d'une couche cachée typique
    • Linéaire : Multiplication de matrices
    • Non linéaire : Fonction d'activation
Introduction à TensorFlow en Python

Pourquoi les non-linéarités sont essentielles

Cette image montre un réseau simple où le montant de la facture et l'âge servent à prédire le défaut de paiement.

Introduction à TensorFlow en Python

Pourquoi les non-linéarités sont essentielles

Cette image montre la relation entre le montant de la facture de carte de crédit et le défaut pour les emprunteurs de 30 ans et moins.

Introduction à TensorFlow en Python

Un exemple simple

import numpy as np
import tensorflow as tf

# Define example borrower features
young, old = 0.3, 0.6
low_bill, high_bill = 0.1, 0.5
# Apply matrix multiplication step for all feature combinations
young_high = 1.0*young + 2.0*high_bill
young_low = 1.0*young + 2.0*low_bill
old_high = 1.0*old + 2.0*high_bill
old_low = 1.0*old + 2.0*low_bill
Introduction à TensorFlow en Python

Un exemple simple

# Difference in default predictions for young
print(young_high - young_low)

# Difference in default predictions for old
print(old_high - old_low)
0.8 
0.8
Introduction à TensorFlow en Python

Un exemple simple

# Difference in default predictions for young
print(tf.keras.activations.sigmoid(young_high).numpy() - 
tf.keras.activations.sigmoid(young_low).numpy())

# Difference in default predictions for old
print(tf.keras.activations.sigmoid(old_high).numpy() - 
tf.keras.activations.sigmoid(old_low).numpy())
0.16337568
0.14204389
Introduction à TensorFlow en Python

La fonction d'activation sigmoïde

  • Fonction d'activation sigmoïde
    • Classification binaire
    • Bas niveau : tf.keras.activations.sigmoid()
    • Haut niveau : sigmoid

L'image montre la courbe de la fonction d'activation sigmoïde sur l'intervalle -10 à 10.

Introduction à TensorFlow en Python

La fonction d'activation ReLU

  • Fonction d'activation ReLU
    • Couches cachées
    • Bas niveau : tf.keras.activations.relu()
    • Haut niveau : relu

L'image montre la courbe de la fonction d'activation ReLU sur l'intervalle -10 à 10.

Introduction à TensorFlow en Python

La fonction d'activation softmax

  • Fonction d'activation softmax
    • Couche de sortie (> 2 classes)
    • Bas niveau : tf.keras.activations.softmax()
    • Haut niveau : softmax
Introduction à TensorFlow en Python

Fonctions d'activation dans les réseaux de neurones

import tensorflow as tf
# Define input layer
inputs = tf.constant(borrower_features, tf.float32)
# Define dense layer 1
dense1 = tf.keras.layers.Dense(16, activation='relu')(inputs)
# Define dense layer 2
dense2 = tf.keras.layers.Dense(8, activation='sigmoid')(dense1)
# Define output layer 
outputs = tf.keras.layers.Dense(4, activation='softmax')(dense2)
Introduction à TensorFlow en Python

Passons à la pratique !

Introduction à TensorFlow en Python

Preparing Video For Download...