Downloads · 30 days
0
IRedDragonICY/jfleg-gec-transformer-ensemble
jfleg-gec-transformer-ensemble is a text generation model from IRedDragonICY. Use it when you need the model to write or continue text. It is set up for keras. The card lists the license as mit.
Downloads · 30 days
0
Access
Public
Updated Jul 18, 2026
Repo size
460 MB
Likes
0
Public
Click a slice to open those files.
.h5517 MB · 100%
From the Hugging Face model README
This repository hosts a progression of custom-built, from-scratch TensorFlow/Keras Transformer models trained specifically for Grammatical Error Correction (GEC) on the JFLEG dataset.
The project demonstrates how to effectively train deep sequence-to-sequence architectures in a severely low-resource environment (approximately 1,200 training pairs) through architectural optimizations, dynamic synthetic data generation, and weighted ensemble methods. The final ensemble model achieves a test accuracy of 72.88% and a corpus GLEU score of 0.5506, representing a massive 3x performance improvement over a standard baseline Transformer.
The repository tracks the evolution of the model across three main architectural iterations, proving that architectural efficiency and data pipeline engineering supersede raw parameter count in low-resource NLP:
To overcome the strict 1,200-sentence constraint of the JFLEG training split, a highly optimized data augmentation pipeline was implemented:
All models were evaluated on the exact same unseen test split (151 sentences) using masked categorical accuracy and sparse categorical cross-entropy loss.
| Experiment Phase | Description | Test Loss | Test Accuracy |
|---|---|---|---|
| Exp 1 | Baseline Transformer (Adam 1e-4, 30 epochs) | 5.1960 | 23.60% |
| Exp 2 | Baseline + Noam warmup schedule | 7.3017 | 21.96% |
| Exp 3 | Baseline + Early stopping (restore best weights) | 5.5911 | 22.65% |
| Exp 4 | Transformer V2 (Pre-LN + GELU + Weight Tying) | 6.0062 | 53.88% |
| Exp 5 | Transformer V2 + 4-reference augmentation | 2.9344 | 61.20% |
| Exp 6 | Transformer V2 + Synthetic pretraining + Fine-tuning | 2.3589 | 64.59% |
| Exp 7 | Transformer V3 (Pointer-Generator) + Mined noise | 2.1011 | 68.51% |
| Exp 8 | Ensemble (Exp 6 + Exp 7) | 1.8429 | 70.58% |
| Exp 9 | Transformer V3b (Real-heavy data + Label Smoothing + SWA) | 1.7759 | 71.16% |
| Exp 10 | Ensemble 3 Models (Exp 6, 7, 9) | 1.6317 | 72.80% |
| Exp 11 | Weighted Ensemble 5 Models (Validation-selected) | 1.5278 | 72.88% |
Note: The final GLEU score for the Exp 11 Ensemble is 0.5506 (evaluated via batch greedy decoding against 4 references).
This repository includes the saved weights for the key experimental milestones, allowing researchers to load and test specific phases of the architectural evolution.
tokenizer_jfleg.json & tokenizer_jfleg.pkl: The fitted vocabulary tokenizer (Vocab size: 12,000).best_model_config.json: Configuration hyperparameters, metadata, and ensemble weights.transformer_jfleg.weights.h5 to transformer_jfleg_p5.weights.h5: Early iteration baseline weights.transformer_jfleg_p6.weights.h5: V2 Architecture trained with dynamic noise.transformer_jfleg_p7.weights.h5: V3 Pointer-Generator model.transformer_jfleg_p9.weights.h5: V3b Pointer-Generator model (optimized with label smoothing).transformer_jfleg_p11a.weights.h5 & transformer_jfleg_p11b.weights.h5: Additional high-capacity pointer models trained with different seeds for the final ensemble.Intended Use: This model is intended for educational and research purposes to demonstrate the viability of training complex sequence-to-sequence models on extremely small datasets using architectural modifications and dynamic data augmentation.
Limitations: The accuracy plateau observed around 73% is primarily an artifact of the dataset mapping rather than model capability constraints. Error decomposition shows that the remaining errors are heavily concentrated on "novel" tokens—words inserted by human annotators that do not exist anywhere in the source sentence. Because the automated test script evaluates exact token matches, the model is inherently penalized for providing valid, alternative grammatical corrections that do not exactly match the specific annotator's arbitrary word choice.
Because these are custom-built Keras layers and not standard Hugging Face transformers classes, you must recreate the architecture in your Python environment before loading the weights.
import tensorflow as tf
import pickle
import json
# 1. Load Tokenizer
with open("tokenizer_jfleg.pkl", "rb") as f:
tokenizer = pickle.load(f)
# 2. Define Custom Classes
# Ensure you have defined the custom classes:
# PreLNEncoder, PreLNDecoder, TiedOutputLayer, PointerGeneratorHead, TransformerV3b
# (Refer to the training notebook for the exact class definitions).
# 3. Instantiate Model
model_p9 = TransformerV3b(
num_layers=6,
d_model=256,
num_heads=8,
dff=1024,
vocab_size=12000,
pe_input=80,
pe_target=79,
dropout_rate=0.2
)
# 4. Build the graph with a dummy pass
dummy_enc_input = tf.constant([[1, 2, 3]])
dummy_dec_input = tf.constant([[1]])
model_p9(dummy_enc_input, dummy_dec_input, training=False)
# 5. Load Weights
model_p9.load_weights("transformer_jfleg_p9.weights.h5")
print("Model successfully loaded and ready for inference!")
If you utilize this training methodology, the dynamic mined noise pipeline, or the pointer-generator modifications, please reference this repository.