synthetic data
**Synthetic Data and Data Augmentation**
**Why Synthetic Data?**
Real data is limited, expensive, and may have privacy concerns. Synthetic data enables training at scale.
**Data Augmentation**
**Image Augmentation**
```python
from torchvision import transforms
augment = transforms.Compose([
transforms.RandomHorizontalFlip(),
transforms.RandomRotation(15),
transforms.ColorJitter(brightness=0.2, contrast=0.2),
transforms.RandomResizedCrop(224, scale=(0.8, 1.0)),
])
```
**Text Augmentation**
```python
def text_augment(text):
augmentations = [
synonym_replacement,
random_insertion,
random_swap,
random_deletion,
back_translation,
]
return random.choice(augmentations)(text)
```
**LLM-Generated Augmentation**
```python
def llm_augment(text):
return llm.generate(f"""
Paraphrase this text while preserving the meaning:
{text}
Paraphrase:
""")
```
**Synthetic Data Generation**
**Tabular Data**
```python
from sdv.single_table import GaussianCopulaSynthesizer
synthesizer = GaussianCopulaSynthesizer(metadata)
synthesizer.fit(real_data)
synthetic_data = synthesizer.sample(1000)
```
**Image Generation**
```python
# Use diffusion models to generate training images
synthetic_images = diffusion_model.generate(
prompts=["a car on a highway", "a red sports car"],
num_images_per_prompt=100
)
```
**Instruction Data**
```python
def generate_instruction_data(domain, n):
return llm.generate(f"""
Generate {n} diverse instruction-response pairs for {domain}.
Format as JSON: [{{"instruction": "...", "response": "..."}}]
""")
```
**Quality Considerations**
| Aspect | Method |
|--------|--------|
| Diversity | Measure distribution coverage |
| Realism | Human evaluation, discriminators |
| Privacy | Differential privacy, membership inference |
| Utility | Downstream task performance |
**Use Cases**
| Domain | Application |
|--------|-------------|
| Healthcare | Replace sensitive patient data |
| Finance | Fraud detection training |
| Autonomous driving | Edge case scenarios |
| NLP | Low-resource languages |
**Best Practices**
- Validate synthetic data quality with real data holdout
- Mix synthetic with real when possible
- Use domain randomization for sim-to-real
- Monitor for distribution shift