GANs & Conditional GANs
Generative AI has exploded (deepfakes, image generators, ChatGPT). Several research groups apply the newest generative approaches to Ambient Intelligence — this lecture surveys the main families.
GANs — Generative Adversarial Networks
- One of the first generative approaches (2014); mainly adopted for data augmentation.
- Adversarial training: the discriminator learns which inputs are real and which are synthetic; the generator learns to "fool" the discriminator.
- A known problem — mode collapse: the generator produces only a limited variety of samples.
Conditional GANs (CGAN)
- With classic GANs you may need to train a model for each class of interest.
- CGANs condition the generation on specific classes, training a single model (the class label y is fed to both generator and discriminator).
- Time-series example: ActivityGAN — a generator of 1D-transposed + 1D-conv layers produces a 100-point activity segment; a 2D-conv discriminator decides fake/real.
From AutoEncoders to Variational AutoEncoders
Can we generate with a plain AutoEncoder?
Using the Decoder of an AE to generate data looks tempting — draw random samples from the latent space and decode them. But this usually does not work: it is hard to ensure a "regularity" in the latent space, because the classic AE is trained only to encode and decode, so the latent organization typically overfits the training data. Without explicit regularization, some latent points are "meaningless" once decoded.
Besides the reconstruction loss, a VAE adds the Kullback-Leibler loss to minimize the distance between the estimated distribution and a Gaussian N(0,I) — this is what regularizes the latent space.
Simple AutoEncoder
- input x → encoding → latent representation z = e(x) → decoding → reconstruction d(z)
Variational AutoEncoder
- input x → encoding → latent distribution p(z|x) → sampling → z ~ p(z|x) → decoding → reconstruction d(z)
Regular vs irregular latent space: in an irregular space, close points may be dissimilar once decoded and some points are meaningless; with regularization we want a regular space where points close in the latent space are similar once decoded.
Conditional VAE
It is possible to condition the generation with different input modalities (e.g., generating images from a text prompt). The encoder maps the input into a latent representation also considering the conditioning information c, and the decoder reconstructs from the latent space also using that additional information.
Diffusion Models
- The model is trained to denoise the input data in several steps. Generation: starting from complete noise, generate a synthetic sample step by step.
- The most effective approach in Computer Vision; systems like MidJourney (images) and Suno (music) are based on advanced diffusion models.
Forward Diffusion
- Adding noise to the image at different steps until reaching pure noise (no information)
Backward Diffusion
- At each step t, the model learns how to remove noise to reach step t−1 (the tricky part). After training, generation starts from pure noise by denoising step by step
Denoising with a U-net
Diffusion models usually rely on a U-net for denoising at each step (originally proposed for medical image segmentation). While it looks like an AutoEncoder, it also leverages skip connections: the decoder also uses information from the input, enabling high-quality generation — and skip connections make separating the encoder from the decoder impossible.
Latent Diffusion Models
The diffusion process is run in a latent space: a variational encoder maps the input to a latent z, the diffusion model operates there, and a variational decoder reconstructs the output in pixel space. Generation can be conditioned with other modalities (e.g., text) by (1) enhancing the U-net with encoder-decoder attention (cross-attention) to focus on multiple input types, and (2) using a conditional VAE after denoising. For time series, diffusion serves imputation, generation, and forecasting.
GAN vs VAE vs Diffusion
| Family | Trade-offs |
|---|---|
| GAN | High-quality samples, low diversity (mode collapse), hard to train |
| VAE | Low-fidelity samples, high diversity, easy to train |
| Diffusion | High-fidelity samples, high diversity, easy to train, but slow in sample generation |
Using LLMs in Ambient Intelligence (prompting)
Transformers are "advanced" seq2seq models, so they can be trained to generate sequences (text, time series); predictive self-supervised learning pre-trains them on large unlabeled corpora. LLMs are Transformers pre-trained with self-supervision on massive text (e.g., next-word prediction), usually fine-tuned on a labeled corpus to learn human-like conversations so they can be prompted. LLMs are being applied across time-series tasks (forecasting, classification, interpolation, anomaly detection, generation) and domains (EEG, finance, ECG, traffic, audio, IoT, robotics).
Leveraging LLMs to annotate unlabeled data
- Smart-home sensor events can be translated into human-readable sentences (e.g., "the fridge has been opened"), so a window of sensor data maps to a sentence.
- Goal: ask an LLM to determine the activity from the textual description of a window. Useful additions to the prompt: temporal information (morning/afternoon/evening), room-layout descriptions (rooms, spatial arrangement, sensors per room), and sensor activations.
ADL-LLM
A window of sensor data is transformed to text, then the LLM is given a system prompt ("act as a HAR system…", listing locations, interactions and possible activities) and returns the most likely activity (e.g., ACTIVITY = preparing a hot meal) — a zero-shot recognizer.
Other prompting-based methods
AgentSense
An LLM generates personalities, high-level schedules and low-level daily routines; mapped to a VirtualHome simulator → virtual motion/door/object sensor data to train a classifier.
TDOST
Transform sensor-data windows into natural-language sentences encoding semantics rather than sensor patterns → train on the labeled source home and transfer weights to a target home (cross-home transfer).
HARGPT
Feed raw IMU (accelerometer/gyroscope) readings to an LLM with a prompt template → the LLM reasons step-by-step and predicts the activity (zero-shot).
Adapting LLMs to Sensor Data
Fine-tuning & PromptCast
- Google (2023) showed that fine-tuning LLMs on health data (activity recognition, atrial-fibrillation classification, stress) is a promising direction.
- PromptCast: fine-tune an LLM for time-series forecasting by phrasing the series and target as text ("the temperature were 77, 68, 66, 73 degrees… 76 degrees tomorrow").
LLM reprogramming (Time-LLM)
Time-LLM implements this: time-series patches are reprogrammed against pre-trained word embeddings (text prototypes) via multi-head attention, passed through the frozen pre-trained LLM body, and an output projection produces the forecast.
Natural Language Supervision (NLS) for HAR
- Goal: learn a shared latent representation common to sensor data and text. HAR is then done by computing cosine-similarity scores between the sensor embedding and all activity-label embeddings.
- This can enable zero-shot classification: since sensor data is mapped into the text space, we can classify activities unseen during training.
- Built with cross-modal contrastive pre-training (a text encoder + an IMU encoder, each with a projection head, trained so matching sensor/text pairs align).
Generating Large-Scale HAR Datasets
Because of labeled data scarcity, it would be great to generate massive labeled inertial data — but generative methods themselves need a lot of data. Idea: leverage generative models trained on other modalities where large labeled datasets exist — here, the 3D motion domain.
Generating 3D human motion from text
Generating motion from textual descriptions is useful (games, film-making, animating robots), and massive labeled datasets are available. Since synthetic sensor patterns can be produced from synthetic motion (simulating devices placed on the body), these pre-trained models can automatically generate labeled inertial datasets.
VQ-VAE → T2M-GPT
- VQ-VAE (Vector Quantized VAE): learns a discrete representation of human motion — quantization maps motion sequences into sequences of symbols from a codebook C of K symbols. The encoder maps motion → symbols; the decoder reconstructs motion from the discrete sequence.
- T2M-GPT: once the VQ-VAE is trained, the encoder maps each 3D motion to a sequence of symbols. A Transformer is trained with text embeddings as input (e.g., CLIP) and an autoregressive task to predict the most likely sequence of symbols from text. At inference, it generates the symbol sequence from text, and the decoder turns it into 3D motion.
IMUGPT — from text to inertial sensor data
An LLM turns the activity name into motion descriptions, T2M-GPT generates 3D motions from that text, and the 3D motion is mapped (via inverse kinematics / IMUSim, with a motion filter & calibration) to synthetic inertial sensor data — a full labeled HAR dataset.
Final Quiz — Exam Style
16 MCQs + 2 open-ended. One is the actual simulation question (Q9) reproduced verbatim; the rest follow the professor's recipe — sibling distractors, one-word swaps, and a FALSE question hiding an absolutizer.
Why is a Variational AutoEncoder better than a "classic" AutoEncoder for Generative AI?
a) GAN: a generator and a discriminator trained adversarially — the discriminator separates real vs synthetic, the generator fools it; gives high-quality but low-diversity samples (mode collapse) and is hard to train; mainly used for data augmentation (CGANs condition on a class to train one model). VAE: an encoder maps to a latent distribution, a sample is decoded; low-fidelity, high-diversity, easy to train. Diffusion: trained to denoise in steps — forward diffusion adds noise to pure noise, backward diffusion learns to remove it; generation starts from noise and denoises step by step; high-fidelity, high-diversity, easy to train, but slow at sampling; the most effective in CV (MidJourney, Suno). Diffusion denoises with a U-net whose skip connections let the decoder reuse input info (high quality, and they make encoder/decoder inseparable). Latent Diffusion Models run the diffusion in a latent space (variational encoder → diffusion → variational decoder), and can be conditioned by other modalities via cross-attention.
b) A classic AE is trained only to encode and decode, so its latent space is irregular and overfits — sampling random latent points often yields meaningless reconstructions. The VAE fixes this by regularizing training: the encoder outputs a normal distribution (mean μ and standard deviation σ) instead of a single point, a sample z ~ p(z|x) is drawn and decoded, and the loss adds a KL divergence term pulling the latent distribution toward N(0,I) on top of the reconstruction loss. This yields a regular latent space where points close together decode to similar outputs (avoiding meaningless gaps) and overfitting is mitigated — enabling generation. A Conditional VAE additionally conditions both encoder and decoder on extra information c (e.g., text), so generation can be steered by another modality.
a) Prompting: smart-home events translate to sentences ("the fridge has been opened"), so a window maps to text; ADL-LLM prompts an LLM (with locations, interactions, candidate activities, plus temporal/layout/sensor info) to output the activity zero-shot. TDOST turns windows into sentences encoding semantics to enable cross-home transfer (train on source, transfer weights to target). HARGPT feeds raw IMU readings to an LLM with a prompt template for step-by-step zero-shot recognition. Fine-tuning: Google (2023) fine-tuned LLMs on health data (activity, atrial fibrillation, stress); PromptCast fine-tunes for time-series forecasting via text. Reprogramming (Time-LLM): keep the backbone frozen, convert the series into text-prototype tokens, fine-tune only the head (few-shot). Natural Language Supervision: learn a shared latent space for sensor data and text via cross-modal contrastive pre-training (IMU encoder + text encoder); classify by cosine similarity to activity-label embeddings, enabling zero-shot recognition of unseen activities. Cons of prompting: scalability is questionable since LLMs aren't trained on raw sensor data.
b) Labeled inertial data is scarce and generative models need lots of data, so we borrow from the 3D-motion domain, where massive labeled datasets exist. VQ-VAE learns a discrete motion representation: motion sequences are quantized into sequences of symbols from a codebook of K symbols (encoder → symbols, decoder → motion). T2M-GPT then trains a Transformer with CLIP text embeddings and an autoregressive objective to predict the symbol sequence from text, which the VQ-VAE decoder turns into 3D motion. IMUGPT chains it end-to-end: an LLM expands an activity name into motion descriptions, T2M-GPT generates 3D motion, and the motion is mapped (inverse kinematics / IMUSim, motion filter, calibration) to synthetic IMU data — automatically labeled by the seed activity. Limitations: it reuses models trained on a significantly different task and reconstructs IMU data with ad-hoc methods — an approximation that may miss subtle movements, and it can only cover activity types present in T2M-GPT's training motions.