Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
🐥A PyTorch implementation of OpenAI's finetuned transformer language model with a script to import the weights pre-trained by OpenAI
| Date | Stars |
|---|---|
| 2026-07-24 | 1521 |
| 2026-07-25 | 1521 |
| 2026-07-28 | 1521 |
| 2026-07-30 | 1521 |
| 2026-07-31 | 1522 |
| 2026-08-06 | 1522 |
Today
— stars today
This week
+1 stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.07%/day
# PyTorch implementation of OpenAI's Finetuned Transformer Language Model This is a PyTorch implementation of the [TensorFlow code](https://github.com/openai/finetune-transformer-lm) provided with OpenAI's paper ["Improving Language Understanding by Generative Pre-Training"](https://blog.openai.com/language-unsupervised/) by Alec Radford, Karthik Narasimhan, Tim Salimans and Ilya Sutskever. This implementation comprises **a script to load in the PyTorch model the weights pre-trained by the authors** with the TensorFlow implementation.  The model classes and loading script are located in [model_pytorch.py](model_pytorch.py). The names of the modules in the PyTorch model follow the names of the Variable in the TensorFlow implementation. This implementation tries to follow the original code as closely as possible to minimize the discrepancies. This implementation thus also comprises a modified Adam optimization algorithm as used in OpenAI's paper with: - fixed weights decay following the work of [Loshchilov et al.](https://arxiv.org/abs/1711.05101), and - scheduled learning rate as [commonly used for Transformers](http://nlp.seas.harvard.edu/2018/04/03/attention.html#optimizer). ## Requirements To use the model it-self by importing [model_pytorch.py](model_pytorch.py), you just need: - PyTorch (version >=0.4) To run the classifier training script in [train.py](train.py) you will need in addition: - tqdm - sklearn - spacy - ftfy - pandas You can download the weights of the OpenAI pre-trained version by cloning [Alec Radford's repo](https://github.com/openai/finetune-transformer-lm) and placing the `model` folder containing the pre-trained weights in the present repo. ## Using the pre-trained model as a Transformer Language Model The model can be used as a transformer language model with OpenAI's pre-trained weights as follow: ```python from model_pytorch import TransformerModel, load_openai_pretrained_model, DEFAULT_CONFIG args = DEFAULT_CONFIG model = TransformerModel(args) load_openai_pretrained_model(model) ``` This model generates Transformer's hidden states. You can use the `LMHead` class in [model_pytorch.py](model_pytorch.py) to add a decoder tied with the weights of the encoder and get a full language model. You can also use the `ClfHead` class in [model_pytorch.py](model_pytorch.py) to add a classifier on top of the transformer and get a classifier as described in OpenAI's publication. (see an example of both in the `__main__` function of [train.py](train.py)) To use the positional encoder of the transformer, you should encode your dataset using the `encode_dataset()` function of [utils.py](utils.py). Please refer to the beginning of the `__main__` function in [train.py](train.py) to see how to properly define the vocabulary and encode your dataset. ## Fine-tuning the pre-trained model on a classification task This model can also be integrated in a classifier as detailed in [OpenAI's paper](https://blog.openai.com/language-unsupervised/). An example of fine-tuning on the ROCStories Cloze task is included with the training code in [train.py](train.py) The ROCStories dataset can be downloaded from the associated [website](http://cs.rochester.edu/nlp/rocstories/). As with the [TensorFlow code](https://github.com/openai/finetune-transformer-lm), this code implements the ROCStories Cloze Test result reported in the paper which can be reproduced by running: ```bash python -m spacy download en python train.py --dataset rocstories --desc rocstories --submit --analysis --data_dir [path to data here] ``` #### First experiments on the ROCStories test set Finetuning the PyTorch model for 3 Epochs on ROCStories takes 10 minutes to run on a single NVidia K-80. The single run test accuracy of this PyTorch version is 85.84%, while the authors reports a median accuracy with the TensorFlow code of 85.8% and the paper reports a best single run accuracy of 86.5%. The authors i
Excerpt of 4,591 characters
Read on GitHubThomas Wolf · @huggingface
41
25
Tom B Brown · Anthropic · United States
7
4
Sosuke Kobayashi · Preferred Networks, Inc. @pfnet · Japan
2
Sylvain Gugger
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:34057035f683042b, topic:transformer, topic:language-model, readme:pretrained model
matched fp:34057035f683042b, topic:pytorch, readme:pre-training