🤖 AI/ML

Neural Network

Neural Network

An artificial neural network that imitates biological neurons. Composed of an input layer, hidden layers, and an output layer. The foundational structure of deep learning.

📖 Detailed Explanation

A Neural Network (also called an artificial neural network) is a mathematical model that mimics the operating principles of biological neurons. It consists of an Input Layer, Hidden Layer(s), and an Output Layer, and the nodes (neurons) in each layer are connected by links with weights, learning patterns in data.

The history of neural networks begins with the McCulloch-Pitts neuron model in 1943. The Backpropagation algorithm in 1986 and AlexNet's victory in ImageNet in 2012 opened the era of deep learning. Since the emergence of the Transformer in 2017, they have developed into large language models such as GPT and BERT.

The core operating principles are Forward Propagation and backpropagation. In forward propagation, the input passes through the weights and activation functions and is converted into the output, and in backpropagation, the gradient of the loss function is calculated to update the weights. This process is repeated thousands to millions of times, and the model learns.

As of 2024-2025, neural networks are the foundation of all AI applications. Various architectures such as CNN (images), RNN/LSTM (sequences), Transformer (language/multimodal), and GNN (graphs) are used in their specialized areas. PyTorch and TensorFlow are used in practice as the two leading frameworks.

💻 Code Example

# PyTorch로 뉴럴 네트워크 구현
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader, TensorDataset

# 간단한 다층 퍼셉트론(MLP) 정의
class NeuralNetwork(nn.Module):
    def __init__(self, input_size, hidden_sizes, output_size):
        super().__init__()
        layers = []

        # 입력층 -> 첫 번째 은닉층
        layers.append(nn.Linear(input_size, hidden_sizes[0]))
        layers.append(nn.ReLU())
        layers.append(nn.BatchNorm1d(hidden_sizes[0]))
        layers.append(nn.Dropout(0.3))

        # 은닉층들
        for i in range(len(hidden_sizes) - 1):
            layers.append(nn.Linear(hidden_sizes[i], hidden_sizes[i+1]))
            layers.append(nn.ReLU())
            layers.append(nn.BatchNorm1d(hidden_sizes[i+1]))
            layers.append(nn.Dropout(0.3))

        # 출력층
        layers.append(nn.Linear(hidden_sizes[-1], output_size))

        self.network = nn.Sequential(*layers)

    def forward(self, x):
        return self.network(x)

# 모델 생성 및 학습
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = NeuralNetwork(
    input_size=784,       # 28x28 이미지
    hidden_sizes=[512, 256, 128],
    output_size=10        # 10개 클래스
).to(device)

# 손실 함수 & 옵티마이저
criterion = nn.CrossEntropyLoss()
optimizer = optim.AdamW(model.parameters(), lr=1e-3, weight_decay=1e-4)
scheduler = optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=100)

# 학습 루프
def train_epoch(model, loader, criterion, optimizer):
    model.train()
    total_loss = 0
    for X, y in loader:
        X, y = X.to(device), y.to(device)

        optimizer.zero_grad()
        outputs = model(X)
        loss = criterion(outputs, y)
        loss.backward()  # 역전파
        optimizer.step()  # 가중치 업데이트

        total_loss += loss.item()
    return total_loss / len(loader)

print(f"모델 파라미터 수: {sum(p.numel() for p in model.parameters()):,}")

📊 Performance & Cost

Comparison of major neural network architectures as of January 2025:

Architecture Use case Representative Models Parameter
Transformer Language/Multimodal GPT-4, Claude 3 ~1.7T
CNN Image Classification/Detection ConvNeXt, EfficientNet ~200M
ViT Vision Transformer DINOv2, CLIP ~1B
U-Net Image Segmentation Stable Diffusion ~900M
GNN Graph Data GraphSAGE, GAT ~10M

🗣️ Say It Like This in Practice

💬 In a Meeting
"Since the input features of this task are structured data, let's start with a simple 3-layer MLP, and if performance is insufficient, experiment by adding a Residual Connection or Attention layer."
💬 In an Interview
"Training a neural network is the process of finding the optimum in parameter space by following the gradient of the loss function. Here, batch normalization reduces Internal Covariate Shift, and Dropout prevents overfitting through an ensemble effect. The combination of the AdamW optimizer and the Cosine Annealing scheduler works well for most tasks."
💬 In a Technical Discussion
"There is a trade-off between a model's expressiveness and its generalization performance. Increasing the parameters risks overfitting to the training data, so proper regularization and Early Stopping are important. Recently, the Double Descent phenomenon has also been drawing attention."

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

⚠️ Common Mistakes & Cautions

❌
Using a complex architecture from the start

Start with a simple baseline (logistic regression, shallow MLP). A complex model is not always better, and it is also harder to debug.

❌
Ignoring Learning Rate tuning

The learning rate is the most important hyperparameter. If it is too large, training diverges, and if it is too small, convergence is slow. Use a Learning Rate Finder or a Scheduler.

✅
Right approach: systematic experiments

Track experiments with MLflow or Weights & Biases, and automate hyperparameter search (Optuna). Reproducible experiments are the first step toward a good model.

🔗 Related Terms

📚 Learn More