🤖 AI/ML

Neural Network

Neural Network

Mimics biological neurons. Input, hidden, and output layers. The foundational structure of deep learning.

📖 Detailed Explanation

A Neural Network is a machine learning algorithm that mimics the neuron structure of the human brain. It consists of an input layer, hidden layers, and an output layer, and the nodes (neurons) of each layer are connected by weights to learn patterns in data.

Beginning with the McCulloch-Pitts neuron model in 1943, it became practical with the rediscovery of the backpropagation algorithm in 1986. After AlexNet won the ImageNet competition in 2012, the deep learning era began in earnest, and it has now become the foundational technology of all AI innovation.

The core of a neural network is a learning process in which forward propagation generates predictions, a loss function calculates the error, backpropagation computes the gradients, and gradient descent updates the weights. Activation functions (ReLU, Sigmoid, etc.) provide nonlinearity.

In practice, specialized architectures are chosen according to the purpose, such as CNN (images), RNN/Transformer (sequences), and GAN (generation). They are implemented with the PyTorch and TensorFlow frameworks, and when there are two or more hidden layers, it is called 'deep' learning.

💻 Code Example

# PyTorch로 구현하는 기본 신경망
# pip install torch

import torch
import torch.nn as nn
import torch.optim as optim

# 간단한 신경망 정의
class SimpleNN(nn.Module):
    def __init__(self, input_size, hidden_size, output_size):
        super(SimpleNN, self).__init__()
        # 입력층 -> 은닉층 1
        self.layer1 = nn.Linear(input_size, hidden_size)
        self.relu1 = nn.ReLU()
        # 은닉층 1 -> 은닉층 2
        self.layer2 = nn.Linear(hidden_size, hidden_size // 2)
        self.relu2 = nn.ReLU()
        # 은닉층 2 -> 출력층
        self.output = nn.Linear(hidden_size // 2, output_size)

    def forward(self, x):
        x = self.relu1(self.layer1(x))  # 첫 번째 은닉층
        x = self.relu2(self.layer2(x))  # 두 번째 은닉층
        x = self.output(x)              # 출력층
        return x

# 모델 생성
model = SimpleNN(input_size=784, hidden_size=256, output_size=10)
print(f"모델 구조:\n{model}")

# 손실 함수와 옵티마이저 정의
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)

# 학습 루프 예시
def train_step(model, data, target):
    model.train()
    optimizer.zero_grad()           # 기울기 초기화
    output = model(data)            # 순전파
    loss = criterion(output, target) # 손실 계산
    loss.backward()                 # 역전파 (기울기 계산)
    optimizer.step()                # 가중치 업데이트
    return loss.item()

# 파라미터 수 확인
total_params = sum(p.numel() for p in model.parameters())
print(f"총 파라미터 수: {total_params:,}")
# 총 파라미터 수: 235,146

🗣️ Say It Like This in Practice

💬 In an architecture design meeting
"It's a classification problem, so let's start with a basic MLP, and if performance falls short, let's increase the hidden layers or add regularization with Dropout. If it's image data, switching to a CNN is the right call."
💬 In an Interview
"A neural network predicts with forward propagation, calculates the error with a loss function, computes gradients with backpropagation, and updates the weights with gradient descent. Activation functions provide nonlinearity, and these days ReLU is widely used because it has fewer vanishing gradient problems."
💬 In a debugging situation
"If the loss isn't decreasing, it could be a learning rate problem. Start at 1e-3 and adjust, and if the gradient explodes, try applying gradient clipping."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Assuming a deeper network is always better

Increasing layers indiscriminately causes overfitting and vanishing gradient problems. An appropriate depth that matches the amount and complexity of the data is important.

❌
Omitting data normalization

If the scales of the input data differ, training becomes unstable. Using BatchNorm or standardizing the input data (mean=0, std=1) is essential.

✅
The right approach

Start with a simple model and gradually increase the complexity. Monitor the training/validation curves, and use Early Stopping and regularization techniques together.

🔗 Related Terms

📚 Learn More