Lesson · 40 min · Free
GenAI: Data Prep & Optimization
GenAI: Data Prep & Optimization Generative models—whether GANs, VAEs, or diffusion models—are only as good as the data you feed them. In pharmaceutical and biotech applications, training data often comes from messy r
GenAI: Data Prep & Optimization
Generative models—whether GANs, VAEs, or diffusion models—are only as good as the data you feed them. In pharmaceutical and biotech applications, training data often comes from messy real-world sources: molecular screening datasets, patient records, spectroscopy readings, or high-throughput assay results. Before any generative model can learn meaningful structure, the data must be cleaned, normalized, and represented in a form the network can process efficiently. The first step is cleaning and filtering . Experimental datasets frequently contain missing values, duplicate entries, measurement artifacts, and outlier records caused by instrument error. For molecular data, this may mean removing compounds with invalid structures or unreliable activity labels. A common rule of thumb: if you cannot trust a data point, the generative model will learn to reproduce that distrust. Careful curation at this stage prevents the model from memorizing noise. Next comes normalization and encoding . Neural networks train best when numerical features are on comparable scales—typically standardized to zero mean and unit variance, or scaled to a fixed range such as [0, 1]. For continuous descriptors like molecular weight, logP, or solubility, standardization stabilizes gradient flow during optimization. For categorical or sequential data (such as SMILES strings representing molecules), each token must be converted into a numerical representation, often via one-hot encoding or learned embeddings. Finally, optimization refers to tuning how the model learns from the prepared data. This includes choosing an appropriate batch size, learning rate, and optimizer (Adam is a robust default), as well as monitoring loss curves to detect instability—especially important for GANs, where generator and discriminator losses must remain balanced. Well-prepared data combined with sensible optimization hyperparameters is what separates a model that generates plausible drug-like molecules from one that produces chemical nonsense. The following example demonstrates a standard preprocessing pipeline for a molecular dataset using pandas and scikit-learn : import pandas as pd import numpy as np from sklearn.preprocessing import StandardScaler # Load molecular screening data df = pd.read_csv("compound_screening.csv") # Clean: drop duplicates and rows with missing critical values df = df.drop_duplicates(subset="smiles") df = df.dropna(subset=["smiles", "logP", "mol_weight", "activity"]) # Remove physiologically implausible outliers df = df[(df["mol_weight"] > 100) & (df["mol_weight"] < 900)] # Normalize continuous descriptors to zero mean, unit variance features = ["logP", "mol_weight", "activity"] scaler = StandardScaler() df[features] = scaler.fit_transform(df[features]) print(df[features].describe()) # Features are now ready for input to a generative model Once the data is prepared, the next example shows how to set up an optimization loop with sensible hyperparameters for training a generative model in PyTorch: import torch from torch.utils.data import DataLoader, TensorDataset # Wrap prepared data in a DataLoader for mini-batch training tensor_data = torch.tensor(df[features].values, dtype=torch.float32) dataset = TensorDataset(tensor_data) loader = DataLoader(dataset, batch_size=64, shuffle=True) # Optimizer setup: Adam with a moderate learning rate model = build_generator(input_dim=3, latent_dim=16) # user-defined optimizer = torch.optim.Adam(model.parameters(), lr=1e-4, betas=(0.5, 0.999)) for epoch in range(100): for batch, in loader: optimizer.zero_grad() loss = model.compute_loss(batch) # model-specific loss loss.backward() optimizer.step() print(f"Epoch {epoch+1}, loss: {loss.item():.4f}") Key takeaways: Clean data thoroughly: remove duplicates, handle missing values, and filter outliers before training—models learn noise just as readily as signal. Normalize continuous features (e.g., standardization) so no single descriptor dominates gradient updates. Encode categorical and sequential inputs (like SMILES strings) numerically using one-hot vectors or embeddings. Use mini-batch training via a DataLoader to improve training stability and memory efficiency. Start optimization with Adam (lr ≈ 1e-4) and monitor loss curves to catch instability early, particularly in adversarial setups. Practice exercise: Download a public molecular dataset (for example, a subset of the ESOL water solubility dataset). Clean it by removing duplicate SMILES strings and rows with missing descriptors, standardize the numerical features, and train a simple generator for 50 epochs. Record the loss curve and describe in two or three sentences how changing the learning rate from 1e-4 to 1e-2 affected training stability.
Watch the full lesson — free
This topic is part of Deep Generative Models: GANs, VAEs & Diffusion, a complete AI-narrated video course. Press play once and watch the entire lecture like a movie.
Start the course free →