Funções de ativação

Introdução ao TensorFlow em Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

O que é uma função de ativação?

  • Componentes de uma camada oculta típica
    • Linear: Multiplicação de matrizes
    • Não linear: Função de ativação
Introdução ao TensorFlow em Python

Por que as não linearidades são importantes

Esta imagem mostra uma rede simples em que o valor da fatura e a idade são usados para prever inadimplência.

Introdução ao TensorFlow em Python

Por que as não linearidades são importantes

Esta imagem mostra a relação entre o valor da fatura do cartão e a inadimplência para tomadores de 30 anos ou menos.

Introdução ao TensorFlow em Python

Um exemplo simples

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
Introdução ao TensorFlow em Python

Um exemplo simples

# 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
Introdução ao TensorFlow em Python

Um exemplo simples

# 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
Introdução ao TensorFlow em Python

A função de ativação sigmoid

  • Função de ativação sigmoid
    • Classificação binária
    • Baixo nível: tf.keras.activations.sigmoid()
    • Alto nível: sigmoid

A imagem mostra o gráfico da função de ativação sigmoid no intervalo -10 a 10.

Introdução ao TensorFlow em Python

A função de ativação ReLU

  • Função de ativação ReLU
    • Camadas ocultas
    • Baixo nível: tf.keras.activations.relu()
    • Alto nível: relu

A imagem mostra o gráfico da função de ativação ReLU no intervalo -10 a 10.

Introdução ao TensorFlow em Python

A função de ativação softmax

  • Função de ativação softmax
    • Camada de saída (>2 classes)
    • Baixo nível: tf.keras.activations.softmax()
    • Alto nível: softmax
Introdução ao TensorFlow em Python

Funções de ativação em redes neurais

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)
Introdução ao TensorFlow em Python

Vamos praticar!

Introdução ao TensorFlow em Python

Preparing Video For Download...