📚 All Books 05-transformer_rl README ← Prev Next →
Table of Contents

Data Normalization and Standardization Techniques

2.3.1 Normalization Techniques

Normalization aims to scale the data to a specific range, typically between 0 and 1 or -1 and 1. Different normalization techniques are appropriate for different data types and characteristics.

x' = (x - x_min) / (x_max - x_min)

This method is susceptible to outliers, as a single extreme value can significantly affect the scaling. A robust alternative is using the interquartile range (IQR) instead of the full range to be less sensitive to outliers.

x' = (x - μ) / σ

where μ is the mean and σ is the standard deviation of the feature x. This method preserves the original shape of the data, making it suitable for comparing data across different modalities.

x' = x / |x_max|

2.3.2 Standardization for Different Modalities

The choice of normalization technique should consider the characteristics of each modality. For example:

2.3.3 Handling Missing Data

In real-world datasets, missing data is commonplace. Approaches to handling missing values are crucial for ensuring that normalization or standardization techniques are applied correctly.

2.3.4 Considerations for Multimodal Data

When dealing with multimodal data, selecting a normalization method requires careful consideration of how normalization impacts the representation learning process of the transformer models and the RL agent. Normalization methods should maintain the key features of each modality while enabling consistent representation across different modalities, leading to optimal performance in the multimodal learning process. Normalization should not introduce artificial biases that harm the RL agent's ability to learn. Furthermore, normalization parameters should be learned through the data itself, or trained using held-out validation sets for robustness.

2.3.5 Example Implementation (Python)

import numpy as np
from sklearn.preprocessing import StandardScaler, MinMaxScaler

# Toy multimodal batch: image embeddings, text embeddings, and a scalar reward signal
image_features = np.random.randn(256, 512)        # (batch, image_embed_dim)
text_features  = np.random.randn(256, 768)         # (batch, text_embed_dim)
reward_signal  = np.random.uniform(-10, 10, (256, 1))  # (batch, 1)

# Fit a separate scaler per modality so each keeps its own statistics
image_scaler = StandardScaler().fit(image_features)
text_scaler  = StandardScaler().fit(text_features)
reward_scaler = MinMaxScaler(feature_range=(-1, 1)).fit(reward_signal)

image_norm  = image_scaler.transform(image_features)
text_norm   = text_scaler.transform(text_features)
reward_norm = reward_scaler.transform(reward_signal)

# Concatenate into a single representation only after each modality
# has been normalized on its own scale, then feed to the transformer encoder.
multimodal_input = np.concatenate([image_norm, text_norm], axis=1)

Note that the scalers are fit independently per modality rather than on the concatenated tensor: fitting a single scaler across all modalities would let the modality with the largest raw variance dominate the resulting distribution, defeating the purpose of normalization. In production pipelines, the fitted scalers should be persisted alongside the model checkpoint and reused at inference time rather than refit on incoming data.

By carefully selecting and implementing appropriate normalization techniques, researchers can ensure the robustness, efficiency, and effectiveness of large multimodal transformer models trained with reinforcement learning.