활성화 함수(activation function)는 신경망의 각 선형 층 뒤에 놓여 출력값에 비선형성을 부여하는 요소입니다. 이 글에서는 신경망에 활성화 함수가 왜 필요한지 수식으로 살펴보고, 시그모이드(sigmoid)·ReLU·GELU의 정의와 모양 차이, 기울기 소실(vanishing gradient)과의 관계, 그리고 은닉층과 출력층에서 함수를 고르는 기준을 차례대로 정리합니다.
핵심 요약
활성화 함수는 각 층의 출력에 비선형성을 더해서, 신경망이 직선 하나로는 표현할 수 없는 복잡한 관계를 배울 수 있게 해 주는 함수입니다. 활성화 함수가 없으면 층을 아무리 쌓아도 하나의 선형 변환과 같습니다. 시그모이드는 출력을 0~1로 누르고, ReLU는 음수를 0으로 자르며, GELU는 0 근처를 부드럽게 처리합니다.
활성화 함수란 무엇이고 왜 필요합니까?
한 줄 답: 선형 층 사이에 비선형 함수를 넣어야 여러 층을 쌓았을 때 하나의 선형 변환으로 합쳐지지 않고, 꺾이거나 휘어진 결정 경계를 표현할 수 있기 때문입니다.
신경망의 선형 층 하나는 입력 x에 대해 Wx + b를 계산합니다. 만약 층 사이에 비선형 함수 없이 선형 층만 두 개 연속으로 쌓으면 그 결과는 다음과 같이 정리됩니다.
W2(W1x + b1) + b2 = (W2W1)x + (W2b1 + b2)
즉 가중치 행렬 W2W1과 편향 W2b1 + b2를 가진 또 하나의 단일 선형 변환이 되므로, 층을 아무리 깊게 쌓아도 직선 형태의 결정 경계밖에 그리지 못합니다. 각 선형 층 사이에 비선형 활성화 함수를 끼워 넣어야 비로소 꺾이거나 휘어진 결정 경계를 표현할 수 있습니다.

시그모이드·ReLU·GELU는 어떻게 다릅니까?
한 줄 답: 시그모이드는 입력을 (0, 1) 범위로 압축하고, ReLU는 음수를 0으로 두고 양수는 그대로 통과시키며, GELU는 입력의 부호만으로 자르지 않고 값의 크기에 따라 0 근처를 부드럽게 가중합니다.
PyTorch 공식 문서(torch.nn, Non-linear Activations, 버전 2.14 기준)에 정의된 주요 함수들의 수식은 다음과 같습니다.
ReLU(x) = max(0, x)
Sigmoid(x) = 1 / (1 + exp(-x))
GELU(x) = x * Φ(x)
Tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
Softmax(x_i) = exp(x_i) / Σ_j exp(x_j)
여기서 GELU(x) = x * Φ(x)의 Φ(x)는 표준 정규 분포(standard Gaussian distribution)의 누적 분포 함수(CDF)입니다. PyTorch의 torch.nn.GELU는 approximate='tanh' 옵션을 통해 tanh 기반 근사 계산도 제공합니다. Hendrycks와 Gimpel의 논문(Gaussian Error Linear Units (GELUs), arXiv:1606.08415, 2016년 6월 27일 제출)에서 설명하듯, GELU는 ReLU처럼 입력의 부호(sign)에 따라 통과 여부를 가르는 대신 입력값의 크기에 따라 입력을 가중합니다.
정의를 바탕으로 세 함수의 모양을 비교하면 다음과 같습니다.
- 시그모이드(Sigmoid): 어떤 입력이 들어오든 출력을
(0, 1)구간으로 눌러 담으며, 양쪽 끝으로 갈수록 곡선이 평평해집니다. - ReLU: 음수 입력에 대해서는 출력이
0이고, 양수 입력에 대해서는 입력값x를 그대로 내보내는 항등 함수(identity) 모양입니다. - GELU: 매우 작은 음수 입력에서는
0에 가깝고, 큰 양수 입력에서는x에 가까우며,0근처에서 부드럽게 이어집니다(일부 음수 구간에서는0보다 살짝 아래로 내려갔다가 올라옵니다).
| 함수 | 출력 범위 | 모양 | 자주 쓰이는 곳 |
|---|---|---|---|
| 시그모이드(Sigmoid) | (0, 1) | S자 곡선이며 양쪽 끝이 평평해집니다. | 단일 예/아니오 확률을 내는 출력층 |
| ReLU | [0, ∞) | 음수는 0이고 양수는 직선(x)으로 꺾입니다. | 은닉층 |
| GELU | 0보다 살짝 아래부터 위로 제한 없음 | 매우 작은 음수에서는 0, 큰 양수에서는 x에 가깝고 0 근처가 부드럽습니다. | 은닉층 |

기울기 소실과는 어떤 관계입니까?
한 줄 답: 시그모이드처럼 양쪽 끝에서 기울기가 0에 가까워지는 함수를 깊은 층에 반복해 쓰면 역전파 때 작은 기울기가 계속 곱해져 입력층 근처 기울기가 매우 작아지는데, ReLU는 양수 구간에서 기울기가 일정해 은닉층에서 널리 쓰입니다.
시그모이드 함수는 입력의 절댓값이 커지는 양쪽 평평한 끝 구간에서 기울기(slope)가 0에 가까워집니다. 신경망이 깊어질 때 역전파 과정에서 이러한 작은 기울기들이 여러 층을 거치며 계속 곱해지면, 입력층 쪽에 가까운 가중치들의 기울기가 매우 작아지는 기울기 소실(vanishing gradient) 현상이 나타날 수 있습니다.
반면 ReLU는 양수 입력 구간에서 기울기가 일정하게 유지됩니다. 이 특성은 깊은 신경망의 은닉층에서 ReLU가 널리 쓰이는 이유 중 하나입니다. 역전파 과정에서 기울기가 전달되는 원리는 별도 글인 역전파(Backpropagation)란? 신경망이 기울기로 가중치를 고칠 때 동작 원리에서 다룹니다.
활성화 함수는 어떻게 고릅니까?
한 줄 답: 출력층은 풀려는 과제의 출력 형태(단일 예/아니오 확률은 시그모이드, 다중 클래스 선택은 소프트맥스, 실수값 예측은 활성화 없음)에 맞춰 고르고, 은닉층은 주로 ReLU 계열이나 GELU를 사용합니다.
활성화 함수를 고를 때는 신경망의 출력층(output layer)과 은닉층(hidden layers)을 나누어 생각합니다.
- 출력층: 과제가 요구하는 출력 형태에 따라 결정됩니다. 단일 예/아니오 확률을 예측할 때는 시그모이드(sigmoid)를 쓰고, 여러 클래스 중 하나를 고르는 확률 분포가 필요할 때는 소프트맥스(softmax)를 쓰며, 연속적인 실수값을 예측할 때는 출력층에 별도의 활성화 함수를 두지 않는 경우가 많습니다.
- 은닉층: 층 사이에서 비선형성을 더하는 역할로 ReLU 계열 함수나 GELU를 흔히 사용합니다.
만약 활성화 함수를 적절히 골랐는데도 학습이 잘 진행되지 않는다면 학습률 설정도 함께 점검해 볼 필요가 있으며, 이는 별도 글인 「학습률(Learning Rate)이란?」(곧 발행 예정)에서 다룹니다.
자주 묻는 질문은 무엇입니까?
한 줄 답: 죽은 ReLU 현상과 LeakyReLU, 소프트맥스의 활성화 함수 분류 여부, 그리고 tanh의 특징을 정리했습니다.
죽은 ReLU란 무엇입니까?
정의상 ReLU는 음수 입력에 대해 출력과 기울기가 모두 0입니다. 따라서 어떤 뉴런(단위)의 입력이 모든 데이터에 대해 계속 음수로만 머무르면 기울기를 전혀 받지 못해 가중치 갱신이 멈추게 되는데, 이를 죽은 ReLU(Dead ReLU)라고 부릅니다. 이를 완화하기 위해 음수 입력 구간에서도 작은 기울기를 남겨 두는 LeakyReLU(torch.nn에 포함) 같은 변형이 존재합니다.
소프트맥스도 활성화 함수입니까?
PyTorch 공식 문서는 Softmax를 비선형 활성화 모듈("Non-linear Activations (other)") 목록에 포함하고 있으며, 주로 출력층에서 각 원소를 [0, 1] 범위로 바꾸고 전체 합이 1이 되도록 점수를 확률로 변환할 때 사용합니다.
tanh는 언제 씁니까?
tanh는 입력을 (-1, 1) 범위로 압축하며 중심이 0(zero-centered)이라는 특징이 있습니다. 출력의 중심이 0이어야 할 때 쓰이지만, 시그모이드와 마찬가지로 양쪽 끝 구간에서 곡선이 평평해진다는 성질이 있습니다.
함께 보면 좋은 글은 무엇입니까?
한 줄 답: 언어 모델의 학습 단계, AI 기초 개념 정리, 그리고 활성화 함수와 함께 동작하는 역전파·학습률 글을 함께 살펴보실 수 있습니다.
- 사전학습·파인튜닝·RLHF 차이: LLM은 어떤 단계로 만들어지나?
- AI 기초 개념 공부 정리 글
- 역전파(Backpropagation)란? 신경망이 기울기로 가중치를 고칠 때 동작 원리
- 「학습률(Learning Rate)이란?」 (곧 발행 예정)
출처는 어디입니까?
한 줄 답: PyTorch 공식 torch.nn 문서와 GELU 원 논문을 확인하여 작성했습니다.
- PyTorch Documentation,
torch.nn— Non-linear Activations (torch.nn.ReLU,torch.nn.GELU,torch.nn.Sigmoid,torch.nn.Tanh,torch.nn.Softmax, version 2.14), https://docs.pytorch.org/docs/stable/nn.html (확인 2026-10-25) - Dan Hendrycks, Kevin Gimpel, "Gaussian Error Linear Units (GELUs)", arXiv:1606.08415 (submitted 2016-06-27), https://arxiv.org/abs/1606.08415 (확인 2026-10-25)
An activation function sits after each linear layer in a neural network and introduces nonlinearity into the layer's output. This post explains mathematically why neural networks need activation functions, how sigmoid, ReLU, and GELU differ in definition and shape, how they connect to the vanishing gradient problem, and how to choose an activation for hidden layers versus the output layer.
Summary
An activation function adds nonlinearity to the output of each layer so a neural network can learn complex relationships that a single straight line cannot represent. Without an activation function, stacking any number of layers collapses into a single linear transformation. Sigmoid squashes outputs into (0, 1), ReLU clips negative values to 0, and GELU transitions smoothly around 0.
What is an activation function and why is it needed?
One-line answer: Putting a nonlinear function between linear layers keeps stacked layers from collapsing into a single linear map and allows the network to represent bent or curved decision boundaries.
A single linear layer computes Wx + b for an input x. If you stack two linear layers back to back without a nonlinearity in between, the combined operation simplifies algebraically:
W2(W1x + b1) + b2 = (W2W1)x + (W2b1 + b2)
Because the result is still one linear map with weight matrix W2W1 and bias W2b1 + b2, a network built only from linear layers can only draw straight decision boundaries no matter how many layers are stacked. Placing a nonlinear activation function between layers lets the network represent bent and curved boundaries.

How do sigmoid, ReLU, and GELU differ?
One-line answer: Sigmoid squashes any input into (0, 1), ReLU outputs 0 for negative inputs and the identity for positive inputs, and GELU weights inputs smoothly around 0 by their value rather than gating strictly by sign.
According to the official PyTorch documentation (torch.nn, Non-linear Activations, checked at version 2.14), the core functions are defined as follows:
ReLU(x) = max(0, x)
Sigmoid(x) = 1 / (1 + exp(-x))
GELU(x) = x * Φ(x)
Tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
Softmax(x_i) = exp(x_i) / Σ_j exp(x_j)
In GELU(x) = x * Φ(x), Φ(x) is the cumulative distribution function (CDF) of the standard Gaussian distribution. PyTorch's torch.nn.GELU also offers a tanh-based approximation via the approximate='tanh' option. As Hendrycks and Gimpel describe in Gaussian Error Linear Units (GELUs) (arXiv:1606.08415, submitted 2016-06-27), GELU weights inputs by their value rather than gating them by their sign as ReLU does.
From these definitions, the three functions take distinct shapes:
- Sigmoid: squashes any real input into the interval
(0, 1)and flattens at both ends. - ReLU: outputs
0for negative inputs and acts as the identity function (x) for positive inputs. - GELU: stays close to
0for very negative inputs, stays close toxfor large positive inputs, and bends smoothly around0(dipping slightly below0for some negative inputs).
| Function | Output range | Shape | Common placement |
|---|---|---|---|
| Sigmoid | (0, 1) | S-shaped curve that flattens at both ends. | Output layer for a single yes/no probability |
| ReLU | [0, ∞) | 0 for negative inputs and identity (x) for positive inputs. | Hidden layers |
| GELU | From slightly below 0, unbounded above | Close to 0 for very negative inputs, close to x for large positive inputs, smooth around 0. | Hidden layers |

How do activation functions relate to the vanishing gradient problem?
One-line answer: Sigmoid's slope gets close to 0 at both flat ends, so multiplying many such slopes across deep layers during backpropagation can make gradients near the input side very small, whereas ReLU keeps a constant slope for positive inputs.
Because sigmoid flattens at both ends, its slope approaches 0 when the input magnitude is large. When many layers use sigmoid and their slopes are multiplied together during backpropagation, the gradients reaching layers near the input side can become very small—a phenomenon known as the vanishing gradient problem.
ReLU, by contrast, has a constant slope for positive inputs, which is one reason it is widely used in hidden layers. How gradients are propagated backward through a network is covered in What is backpropagation? How a neural network uses gradients to fix its weights (Korean).
How do you choose an activation function?
One-line answer: Match the output layer activation to the task target—sigmoid for a single yes/no probability, softmax for choosing one of several classes, or often no activation for predicting a real-valued number—and commonly use ReLU-family functions or GELU in hidden layers.
Choosing an activation function is easiest when you separate the output layer from the hidden layers:
- Output layer: depends on the form of prediction the task requires. Use sigmoid for a single yes/no probability, softmax for choosing one of several classes, and often no activation when predicting a real-valued number.
- Hidden layers: commonly use ReLU-family activations or GELU to provide nonlinearity between linear layers.
If training does not progress well even with a suitable activation function, it is also worth checking the learning rate alongside the activation choice, as covered in the forthcoming post "What is a learning rate?" (coming soon).
What are the frequently asked questions?
One-line answer: Here are concise answers on dead ReLU units and LeakyReLU, how PyTorch classifies softmax, and when tanh is used.
What is a dead ReLU?
By definition, ReLU has both output and slope equal to 0 for negative inputs. If a unit's input stays negative across all data, it receives no gradient and stops updating, which is called a dead ReLU. Variants such as LeakyReLU (available in torch.nn) keep a small slope for negative inputs.
Is softmax also an activation function?
PyTorch lists Softmax among its activation modules ("Non-linear Activations (other)"), and it is typically used at the output layer to rescale a vector of scores so the elements lie in [0, 1] and sum to 1.
When is tanh used?
tanh squashes inputs into (-1, 1) and is centered at 0. It is useful when zero-centered outputs are desired, though like sigmoid it flattens at both ends.
What related posts are worth reading?
One-line answer: These posts cover language model training stages and AI basics, and companion posts cover backpropagation and the upcoming learning rate topic, which work directly alongside activation functions during training.
- Pre-training, fine-tuning, and RLHF differences: What stages build an LLM? (Korean)
- AI basics study notes (Korean)
- What is backpropagation? How a neural network uses gradients to fix its weights (Korean)
- "What is a learning rate?" (coming soon)
What are the sources?
One-line answer: This post is grounded in the official PyTorch torch.nn documentation and the GELU paper.
- PyTorch Documentation,
torch.nn— Non-linear Activations (torch.nn.ReLU,torch.nn.GELU,torch.nn.Sigmoid,torch.nn.Tanh,torch.nn.Softmax, version 2.14), https://docs.pytorch.org/docs/stable/nn.html (checked 2026-10-25) - Dan Hendrycks, Kevin Gimpel, "Gaussian Error Linear Units (GELUs)", arXiv:1606.08415 (submitted 2016-06-27), https://arxiv.org/abs/1606.08415 (checked 2026-10-25)
