Skip to main content

Explorations into Transformer Language Model with Adversarial Loss

Project description

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}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transformer_lm_gan-0.0.5.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

transformer_lm_gan-0.0.5-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file transformer_lm_gan-0.0.5.tar.gz.

File metadata

  • Download URL: transformer_lm_gan-0.0.5.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for transformer_lm_gan-0.0.5.tar.gz
Algorithm Hash digest
SHA256 d62126cfdb809a4094dbe921ef555458cad96c88b01ec88fde18ef710bda079f
MD5 93fe6aed0499702c728d4bf8ce796332
BLAKE2b-256 c28c25e88e659663d591a4ced9092d27983fcdd6f03752d52c4265a05be8dfcb

See more details on using hashes here.

File details

Details for the file transformer_lm_gan-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for transformer_lm_gan-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 36190f7d44f218b937c84549b2479027a449f164cb549d94232626d760bf3247
MD5 2451ec593d9107451f6e79ceb6ffda1c
BLAKE2b-256 d660115d57b7d4b1e138faee91b2ef521036fb2959506c4bd8663811a570a0e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page