🤖 AI/ML

Data Augmentation

Data Augmentation

Artificially increasing training data. Image rotation, text paraphrasing.

📖 Detailed Explanation

Data Augmentation is a technique that artificially expands a dataset by applying various transformations to existing training data. For a Deep Learning model to learn effectively, it needs large amounts of diverse data, but collecting such data in practice takes considerable cost and time. Data Augmentation solves this problem and can significantly improve a model's generalization performance even with a small amount of original data.

In the image domain, techniques such as rotation, cropping, flipping, color adjustment, and noise addition are widely used. As of 2024-2025, advanced techniques such as MixUp, CutMix, AutoAugment, and RandAugment have become standard, and in particular, synthetic data generation using generative AI is rapidly emerging. Generating training images with Stable Diffusion or DALL-E is actively applied in practice.

In natural language processing, synonym replacement, Back Translation, sentence shuffling, and random deletion/insertion are used. Recently, paraphrasing and question-answer pair generation using GPT-4 or Claude have become commonplace, greatly reducing the cost of building NLP datasets. In speech recognition, speed perturbation, pitch adjustment, and background noise synthesis are applied.

The core of Data Augmentation is to provide variations that the model has not learned while preserving the labels (meaning) of the original data. Excessive augmentation can actually hinder learning, so selecting appropriate techniques and adjusting their intensity to fit the characteristics of the domain is important. In recent research, AutoML-based approaches that dynamically adjust the augmentation policy during training are also attracting attention.

💻 Code Example

PyTorch + Albumentations Image Augmentation (Practical Standard)

import albumentations as A
from albumentations.pytorch import ToTensorV2
import cv2

# 실무에서 가장 많이 쓰이는 증강 파이프라인
train_transform = A.Compose([
    A.RandomResizedCrop(height=224, width=224, scale=(0.8, 1.0)),
    A.HorizontalFlip(p=0.5),
    A.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.1),
    A.GaussianBlur(blur_limit=(3, 7), p=0.3),
    A.CoarseDropout(max_holes=8, max_height=16, max_width=16, p=0.3),
    A.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
    ToTensorV2()
])

# CutMix와 MixUp 적용 (정확도 2-3% 향상)
class CutMixMixUp:
    def __init__(self, cutmix_alpha=1.0, mixup_alpha=0.5):
        self.cutmix = A.RandomCutOut(cutmix_alpha)
        self.mixup_alpha = mixup_alpha

    def __call__(self, image1, image2, label1, label2):
        lam = np.random.beta(self.mixup_alpha, self.mixup_alpha)
        mixed_image = lam * image1 + (1 - lam) * image2
        return mixed_image, lam, label1, label2

# 이미지 로드 및 증강 적용
image = cv2.imread("sample.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
augmented = train_transform(image=image)
tensor_image = augmented["image"]

NLP Text Augmentation (LLM-Based Paraphrasing)

import nlpaug.augmenter.word as naw
from openai import OpenAI

# 전통적인 동의어 치환
synonym_aug = naw.SynonymAug(aug_src='wordnet')
text = "데이터 증강은 모델 성능을 향상시킵니다"
augmented_text = synonym_aug.augment(text)

# LLM 기반 고품질 패러프레이징 (2025년 실무 표준)
client = OpenAI()

def paraphrase_with_llm(text, n_variations=3):
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{
            "role": "user",
            "content": f"다음 문장을 {n_variations}가지 다른 방식으로 표현해주세요. "
                       f"의미는 유지하되 문장 구조와 어휘를 다양하게:\n\n{text}"
        }],
        temperature=0.8
    )
    return response.choices[0].message.content.split("\n")

# 역번역 (Back Translation) 증강
from googletrans import Translator
translator = Translator()

def back_translate(text, intermediate_lang='en'):
    translated = translator.translate(text, dest=intermediate_lang)
    back = translator.translate(translated.text, dest='ko')
    return back.text

📊 Performance & Cost

Augmentation Technique Performance Improvement Processing Time Difficulty of Application
Basic Augmentation (Flip, Rotate) +1-2% accuracy Almost none Very easy
CutMix / MixUp +2-3% accuracy +5% training time Easy
AutoAugment / RandAugment +3-5% accuracy +10-20% training time Moderate
Generative AI Synthetic Data +5-10% (when data is scarce) Data generation costs incurred High
LLM-Based Text Augmentation +3-7% accuracy API cost of about $0.01/sentence Easy

Practical Tip: For large-scale datasets at the ImageNet level, basic augmentation is sufficient, but for small datasets of 10,000 images or fewer, advanced augmentation techniques are essential. When using generative AI, GPT-4o-mini or Stable Diffusion XL Turbo offer good cost-effectiveness.

🗣️ Say It Like This in Practice

In a team meeting:

"We only have 5,000 training images right now, so overfitting is severe. I think we should apply an augmentation pipeline with Albumentations and add CutMix to effectively secure about 5 times more data diversity."

In a technical interview:

"Data Augmentation is not simply about increasing data; it is a technique that makes the model learn variations it has not seen to improve generalization performance. For images, we combine geometric transformations, color transformations, and region erasing techniques, and for NLP, we mainly use Back Translation and LLM-based paraphrasing."

When discussing data acquisition:

"If labeling costs are a burden, let's first consider synthetic data generation. If we generate images under various conditions with Stable Diffusion and mix them with the existing data, we can cut labeling costs by more than 50%."

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

⚠️ Common Mistakes & Cautions

❌ Mistake 1: Applying augmentation to validation/test data as well

Augmentation should be applied only to the training data. If augmentation is applied to validation/test data, the actual performance cannot be evaluated accurately. However, Test-Time Augmentation (TTA) is a separate technique that ensembles the predictions of multiple augmented versions at inference time.

❌ Mistake 2: Using augmentation techniques that do not fit the domain

Excessive color transformation in medical imaging, vertical flips in satellite images, and 90-degree rotation in document recognition create data far removed from the actual distribution and actually degrade performance. Example: for chest X-rays, left-right symmetry is meaningful, but upside-down inversion is unrealistic.

✅ The Right Approach

Before applying augmentation techniques, analyze the range of variation in the real data. Apply only the variations that can occur in the real environment, such as camera angles, lighting conditions, and text styles. In addition, it is essential to visualize samples after augmentation to confirm that the labels are still valid.

🔗 Related Terms

📚 Learn More