⚡
VITORLAB
>Home>Projects>Workbench>Blog
GitHubLinkedIn
status: building
>Home>Projects>Workbench>Blog
status: building

Connect

Let's build something together

Always interested in collaborations, interesting problems, and conversations about code, design, and everything in between.

send a signal→

Find me elsewhere

GitHub
@neuxxkk
LinkedIn
/in/vitornms
Email
vitornms@gmail.com
WhatsApp
+55 31 98415-2360
Forged with& code

© 2026 VITORLAB — All experiments reserved

back to blog
aifeatured

Construindo uma Rede Neural do Zero em Python

Implementacao de um perceptron multi-camada sem frameworks. Entendendo backpropagation, gradient descent e funcoes de ativacao na pratica.

VN

Vitor Neuenschwander

CS Student & Developer

Nov 20, 202412 min
#python#neural-network#machine-learning#numpy

Motivacao

Antes de usar TensorFlow ou PyTorch, e fundamental entender como redes neurais funcionam por dentro. Este projeto implementa uma MLP completa usando apenas NumPy.

Estrutura da Rede

import numpy as np

class NeuralNetwork:

def __init__(self, layers):

self.weights = []

self.biases = []

for i in range(len(layers) - 1):

w = np.random.randn(layers[i], layers[i+1]) * 0.01

b = np.zeros((1, layers[i+1]))

self.weights.append(w)

self.biases.append(b)

def sigmoid(self, z):

return 1 / (1 + np.exp(-z))

def sigmoid_derivative(self, z):

s = self.sigmoid(z)

return s * (1 - s)

Forward Propagation

def forward(self, X):

self.activations = [X]

self.z_values = []

current = X

for i in range(len(self.weights)):

z = np.dot(current, self.weights[i]) + self.biases[i]

self.z_values.append(z)

current = self.sigmoid(z)

self.activations.append(current)

return current

Backpropagation

O coracao do aprendizado:

def backward(self, X, y, learning_rate=0.01):

m = X.shape[0]

output = self.activations[-1]

delta = (output - y) * self.sigmoid_derivative(self.z_values[-1])

for i in range(len(self.weights) - 1, -1, -1):

dw = np.dot(self.activations[i].T, delta) / m

db = np.sum(delta, axis=0, keepdims=True) / m

if i > 0:

delta = np.dot(delta, self.weights[i].T) * \

self.sigmoid_derivative(self.z_values[i-1])

self.weights[i] -= learning_rate * dw

self.biases[i] -= learning_rate * db

Resultados

Treinando no dataset XOR (problema classico nao-linear):

  • Arquitetura: 2-4-1 (2 entradas, 4 neuronios ocultos, 1 saida)
  • Epocas: 10.000
  • Acuracia final: 99.8%

Licoes Aprendidas

  • Inicializacao importa: Pesos muito grandes causam vanishing/exploding gradients
  • Learning rate: Muito alto diverge, muito baixo nao converge
  • Funcoes de ativacao: ReLU resolve o vanishing gradient problem
  • Conclusao

    Implementar uma rede neural do zero solidifica o entendimento dos conceitos fundamentais de deep learning. E um exercicio que recomendo a todo estudante de IA.

    share
    share:
    [RELATED_POSTS]

    Continue Reading

    algorithms

    Algoritmos de Grafos para Programacao Competitiva

    BFS, DFS, Dijkstra e Kruskal implementados em Python e C. Preparacao para a OBI e competicoes de programacao.

    Oct 5, 2024•15 min
    backend

    Padroes de API REST com Django e DRF

    Boas praticas para construir APIs REST com Django Rest Framework. Serializers, viewsets, autenticacao e paginacao.

    Sep 12, 2024•11 min