Deep Learning
Deep Learning
Multilayer neural network-based machine learning. CNN, RNN, and Transformer are representative architectures.
Deep Learning
Multilayer neural network-based machine learning. CNN, RNN, and Transformer are representative architectures.
Deep Learning is a field of machine learning that uses artificial neural networks with multiple layers to learn complex patterns from data. "Deep" refers to the depth of the neural network, that is, a large number of hidden layers, and a network with three or more layers is generally called deep learning.
The concept of deep learning has existed since the 1940s, but it entered a full-scale revival in 2012 when AlexNet showed overwhelming performance at the ImageNet competition. Advances in GPU computing power, the availability of big data, and training techniques such as ReLU/Dropout made this possible.
Deep learning transforms data received at the input layer into increasingly abstract features as it passes through multiple hidden layers. The neurons in each layer perform computations through weights and activation functions, and the weights are updated in the direction that minimizes error using the backpropagation algorithm.
Today, deep learning is a core technology in nearly every AI field, including image classification (CNN), natural language processing (Transformer), speech recognition, autonomous driving, and drug discovery. Innovative models such as GPT-4, Stable Diffusion, and AlphaFold are all based on deep learning.
import torch
import torch.nn as nn
import torch.optim as optim
from torchvision import datasets, transforms
from torch.utils.data import DataLoader
# 간단한 딥러닝 모델 (3개의 은닉층)
class DeepNeuralNetwork(nn.Module):
def __init__(self):
super().__init__()
self.flatten = nn.Flatten()
self.layers = nn.Sequential(
nn.Linear(28*28, 512), # 입력층 → 은닉층1
nn.ReLU(),
nn.Dropout(0.2),
nn.Linear(512, 256), # 은닉층1 → 은닉층2
nn.ReLU(),
nn.Dropout(0.2),
nn.Linear(256, 128), # 은닉층2 → 은닉층3
nn.ReLU(),
nn.Linear(128, 10) # 은닉층3 → 출력층
)
def forward(self, x):
x = self.flatten(x)
return self.layers(x)
# 데이터 로드 (MNIST)
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])
train_data = datasets.MNIST('./data', train=True, download=True, transform=transform)
train_loader = DataLoader(train_data, batch_size=64, shuffle=True)
# 모델, 손실함수, 옵티마이저 설정
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = DeepNeuralNetwork().to(device)
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)
# 학습 루프
for epoch in range(5):
model.train()
total_loss = 0
for batch_x, batch_y in train_loader:
batch_x, batch_y = batch_x.to(device), batch_y.to(device)
optimizer.zero_grad()
output = model(batch_x)
loss = criterion(output, batch_y)
loss.backward() # 역전파
optimizer.step() # 가중치 업데이트
total_loss += loss.item()
print(f"Epoch {epoch+1}, Loss: {total_loss/len(train_loader):.4f}")
"Traditional ML has limitations for this problem. We need to extract complex patterns from images, so we'll use a CNN-based deep learning model, and if data is insufficient, we'll apply transfer learning with a pretrained model."
"Deep learning differs from traditional ML in that feature engineering is automated. However, it requires a lot of data and computing resources, and it has the drawback of low interpretability."
"These days, Transformer is the mainstream, rather than CNN or RNN. Images are processed with ViT, and multimodal models are also Transformer-based. However, they require a lot of computation, so optimization techniques like FlashAttention are essential."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
If you have fewer than 10,000 data points, or if you are working with tabular data, XGBoost or LightGBM may deliver better performance. Deep learning is not a cure-all.
Deep learning has many parameters and is therefore prone to overfitting. Be sure to apply Dropout, Early Stopping, Data Augmentation, and Regularization.
Proceed in this order: problem definition → baseline (simple ML) → deep learning. Make active use of Transfer Learning, and monitor the validation loss to detect overfitting early.