{"id":23205497,"url":"https://github.com/sbartlett97/torch-electra","last_synced_at":"2025-07-06T16:02:10.541Z","repository":{"id":265522683,"uuid":"896181519","full_name":"sbartlett97/torch-electra","owner":"sbartlett97","description":"A Custom implementation of the ELECTRA training method using PyTorch and HuggingFace Transformers ","archived":false,"fork":false,"pushed_at":"2025-03-22T21:09:08.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T22:18:58.683Z","etag":null,"topics":["machine-learning","machine-learning-algorithms","masked-image-modeling","nlp","nlp-machine-learning","pretraining","pretraining-bert","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbartlett97.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-29T18:04:46.000Z","updated_at":"2025-03-22T21:09:12.000Z","dependencies_parsed_at":"2024-11-29T19:23:56.453Z","dependency_job_id":"d21b6160-8966-4cd1-9142-49af902b84e0","html_url":"https://github.com/sbartlett97/torch-electra","commit_stats":null,"previous_names":["sbartlett97/torch-electra"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbartlett97%2Ftorch-electra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbartlett97%2Ftorch-electra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbartlett97%2Ftorch-electra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbartlett97%2Ftorch-electra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbartlett97","download_url":"https://codeload.github.com/sbartlett97/torch-electra/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325649,"owners_count":20920713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["machine-learning","machine-learning-algorithms","masked-image-modeling","nlp","nlp-machine-learning","pretraining","pretraining-bert","python"],"created_at":"2024-12-18T16:37:42.522Z","updated_at":"2025-04-05T10:41:18.101Z","avatar_url":"https://github.com/sbartlett97.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ELECTRA Training Implementation\n\nA PyTorch-based implementation of the ELECTRA (Efficiently Learning an Encoder that Classifies Token Replacements Accurately) pre-training method using the HuggingFace Transformers library. This implementation focuses on providing an easy-to-use and extensible framework for pre-training transformer models using the ELECTRA approach.\n\n## Features\n\n- 🚀 Easy-to-use training pipeline\n- 🔧 Support for custom model configurations\n- 📊 Training progress tracking with loss curves\n- ⚡ Mixed precision training support\n- 🔄 Gradient accumulation for handling large batch sizes\n- 🎛️ Hyperparameter optimization using Optuna\n- 💾 Automatic checkpointing\n- 📈 Triangular learning rate scheduling (matching original paper)\n\n## Installation\n\n```bash\n# Clone the repository\ngit clone https://github.com/yourusername/electra-implementation.git\ncd electra-implementation\n\n# Install dependencies\npip install -r requirements.txt\n```\n\n## Quick Start\n\nTrain a model using default settings (base ELECTRA configuration):\n```bash\npython main.py --run_name my_electra_model\n```\n\n### Training Options\n\nChoose from different model sizes:\n```bash\n# Small ELECTRA\npython main.py --preset small --run_name electra_small\n\n# Base ELECTRA (default)\npython main.py --preset base --run_name electra_base\n\n# Large ELECTRA\npython main.py --preset large --run_name electra_large\n```\n\nCustomize training parameters:\n```bash\npython main.py \\\n    --preset base \\\n    --batch_size 32 \\\n    --steps 1000000 \\\n    --dataset_path \"your/dataset/path\" \\\n    --run_name custom_electra\n```\n\nRun hyperparameter optimization:\n```bash\npython main.py --preset base --optuna\n```\n\n## Model Architecture\n\nThe implementation follows the original ELECTRA paper's architecture:\n\n- **Generator \u0026 Discriminator**: Same number of layers but different widths\n- **Model Configurations**:\n  - Small: 12-layer discriminator, 12-layer generator (generator has 1/3 the width)\n  - Base: 12-layer discriminator, 12-layer generator (generator has 1/3 the width)\n  - Large: 24-layer discriminator, 24-layer generator (generator has 1/4 the width)\n- **Shared embeddings** between generator and discriminator\n\n## Training Details\n\n- Uses masked language modeling (MLM) for the generator\n- Implements replaced token detection (RTD) for the discriminator\n- Supports gradient accumulation for effective batch sizes\n- Implements triangular learning rate schedule with warmup\n- Uses mixed precision training for improved performance\n- Tracks and saves training metrics\n\n## Results and Metrics\n\nTraining progress can be monitored through:\n- Real-time loss tracking in the console\n- Generated loss curves (saved as `loss_curve.png`)\n- Training logs (saved as `training_log.csv`)\n\n## References\n\nThis implementation is based on the original ELECTRA paper and inspired by existing implementations:\n\n- **ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators**\n  Kevin Clark, Minh-Thang Luong, Quoc V. Le, Christopher D. Manning  \n  [ICLR 2020](https://openreview.net/pdf?id=r1xMH1BtvB)  \n  ```bibtex\n  @inproceedings{clark2020electra,\n    title = {{ELECTRA}: Pre-training Text Encoders as Discriminators Rather Than Generators},\n    author = {Kevin Clark and Minh-Thang Luong and Quoc V. Le and Christopher D. Manning},\n    booktitle = {ICLR},\n    year = {2020},\n    url = {https://openreview.net/pdf?id=r1xMH1BtvB}\n  }\n  ```\n\n- **PyTorch Implementation of ELECTRA**\n  Richard Wang  \n  [GitHub Repository](https://github.com/richarddwang/electra_pytorch)  \n  ```bibtex\n  @misc{electra_pytorch,\n    author = {Richard Wang},\n    title = {PyTorch implementation of ELECTRA},\n    year = {2020},\n    publisher = {GitHub},\n    journal = {GitHub repository},\n    howpublished = {\\url{https://github.com/richarddwang/electra_pytorch}}\n  }\n  ```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n- HuggingFace team for their Transformers library\n- PyTorch team and community\n- Original ELECTRA paper authors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbartlett97%2Ftorch-electra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbartlett97%2Ftorch-electra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbartlett97%2Ftorch-electra/lists"}