Language model with adversarial loss
Explorations into adversarial losses on top of autoregressive loss for language modeling
I have tried this in the past, when GANs were still dominant. But at the time I was either too inexperienced or the research not there. Either way could not get it working. Will give it another shot in the next few weeks, mainly to see if an adversarial system could benefit world modeling
Usage
import torch
from transformer_lm_gan import (
LanguageModelGenerator,
Discriminator,
GAN,
)
gan = GAN(
strategy = 'gumbel_one_hot', # or 'rotate' for rotation trick, may try combination of two if both fails in experiments
generator = dict(
num_tokens = 256,
dim = 512,
depth = 6,
dim_head = 64,
heads = 8,
max_seq_len = 1024
),
discriminator = dict(
num_tokens = 256,
dim = 512,
depth = 2,
dim_head = 64,
heads = 9,
max_seq_len = 1024
)
).cuda()
seq = torch.randint(0, 256, (2, 1024)).cuda()
discr_loss = gan.discriminate_forward(seq)
discr_loss.backward()
gen_loss = gan.generate_forward(seq)
gen_loss.backward()
Citations
@inproceedings{Huang2025TheGI,
title = {The GAN is dead; long live the GAN! A Modern GAN Baseline},
author = {Yiwen Huang and Aaron Gokaslan and Volodymyr Kuleshov and James Tompkin},
year = {2025},
url = {https://api.semanticscholar.org/CorpusID:275405495}
}
Metadata
Release files for transformer-lm-gan 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| transformer_lm_gan-0.0.5.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| transformer_lm_gan-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / transformer_lm_gan-0.0.5.tar.gz
| Download URL | transformer_lm_gan-0.0.5.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d62126cfdb809a4094dbe921ef555458cad96c88b01ec88fde18ef710bda079f
|
|
BLAKE2b-256 checksum How to use checksums |
c28c25e88e659663d591a4ced9092d27983fcdd6f03752d52c4265a05be8dfcb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Release files / transformer_lm_gan-0.0.5-py3-none-any.whl
| Download URL | transformer_lm_gan-0.0.5-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36190f7d44f218b937c84549b2479027a449f164cb549d94232626d760bf3247
|
|
BLAKE2b-256 checksum How to use checksums |
d660115d57b7d4b1e138faee91b2ef521036fb2959506c4bd8663811a570a0e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|