-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
142 lines (108 loc) · 4.16 KB
/
Copy pathREADME
File metadata and controls
142 lines (108 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# AMML-2526 — Systematic Evaluation of Pre-trained Models and Training on a
Biased Low-Resource Dataset
This repository contains all code, data, and experiments for the *Advanced Methods in Machine Learning* coursework (2025–26).
It implements a two-part empirical study:
- **Task 1 — Representation analysis**
Reverse-engineering three pretrained VAEs using latent probes, reconstructions, posterior diversity, and UMAP embeddings.
- **Task 2 — Bias & mitigation**
Evaluating how class imbalance affects downstream digit classification when using a fixed VAE latent representation, and testing simple mitigation strategies.
The project follows a **reproducible research** layout: experiments are scripted, shared code is modularised, and all runs are deterministic via fixed random seeds.
---
## Project structure
```
amml-2526/
├── main.py
├── AMML_assignment_script.ipynb
├── pyproject.toml
├── uv.lock
├── .python-version
├── README.md
│
├── data/
│ ├── amml_model0_weights.pth
│ ├── amml_model1_weights.pth
│ └── amml_model2_weights.pth
│
├── experiments/
│ ├── task1/
│ │ ├── exp01_elbo.py
│ │ ├── exp02_recon.py
│ │ ├── exp03_probe.py
│ │ ├── exp04_umap.py
│ │ └── exp05_posterior_diversity.py
│ │
│ └── task2/
│ ├── exp01_bias_analysis.py
│ ├── exp02_class_weighting.py
│ └── exp03_oversampling.py
│
└── src/
└── amml/
├── __init__.py
├── data.py
├── vae.py
├── probe.py
├── metrics.py
├── plots.py
└── utils.py
```
---
## Directory overview
### `data/`
Contains the **three pretrained VAEs** supplied for the coursework:
- `amml_model0_weights.pth`
- `amml_model1_weights.pth`
- `amml_model2_weights.pth`
All models share the same architecture and training data but differ in training objectives or regularisation strategies.
---
### `src/amml/` — Core library
Reusable code shared across all experiments:
| File | Purpose |
|------|--------|
| `vae.py` | VAE architecture, encoder/decoder, latent sampling |
| `data.py` | Dataset loading, splits, class imbalance control |
| `probe.py` | Linear probes and downstream classifiers |
| `metrics.py` | ELBO, reconstruction error, balanced accuracy |
| `plots.py` | UMAPs, recon grids, recall bar plots |
| `utils.py` | Seeding, paths, and general helpers |
---
### `experiments/task1/` — Representation analysis
Each script probes a different aspect of the learned latent space:
| Script | What it measures |
|-------|-----------------|
| `exp01_elbo.py` | Evidence Lower Bound (ELBO) |
| `exp02_recon.py` | Reconstruction fidelity |
| `exp03_probe.py` | Linear probe performance |
| `exp04_umap.py` | Latent-space geometry (UMAP) |
| `exp05_posterior_diversity.py` | Posterior variance and spread |
Together, these experiments infer **what kind of representations** each pretrained VAE has learned.
---
### `experiments/task2/` — Bias and mitigation
All Task-2 experiments use a **fixed latent representation (Model 0)** to isolate the effect of dataset bias and mitigation strategies.
| Script | Purpose |
|-------|--------|
| `exp01_bias_analysis.py` | Baseline performance on imbalanced data |
| `exp02_class_weighting.py` | Loss re-weighting for minority classes |
| `exp03_oversampling.py` | Training set balancing via oversampling |
Each experiment is evaluated across **five random stratified splits** to estimate variability and robustness.
---
## Running the project
This project uses **uv** for environment and dependency management.
```bash
uv venv
source .venv/bin/activate
uv sync
```
Run Task 1 experiments:
```bash
uv run python experiments/task1/exp01_elbo.py
uv run python experiments/task1/exp02_recon.py
...
```
Run Task 2 experiments:
```bash
uv run python experiments/task2/exp01_bias_analysis.py
uv run python experiments/task2/exp02_class_weighting.py
uv run python experiments/task2/exp03_oversampling.py
```
All scripts save figures and metrics automatically to structured output directories.