Giter VIP home page Giter VIP logo

transformer_lightning's Introduction

TLT : Transformer-Lightning Language Model

Table of Contents

Introduction

This is an implementation of a transformer based language model using Pytorch-Lightning framework. The model consists of two transformer layers with 2 heads each combined with embedding and linear layers. The code uses pytorch-lightning framework that is built for fast research prototyping. Although the code does not leverage all the features of the lightning framework, but it has achieved good result in the language modelling task. For learning purposes, a Pytorch classical version from this project is also provided here (inspired from Pytorch team โค๏ธ).

Setup

The code is using pipenv as a virtual environment and package manager. To run the code, all you need is to install the necessary dependencies. open the terminal and type:

  • $ git clone https://github.com/Khamies/Transformer_Lightning.git
  • $ cd Transformer_Lightning
  • $ pipenv install

or

  • $ pip install requirements.txt

And you should be ready to go to play with code and build upon it!

Run the code

  • To train the model, run: python main.py

  • To train the model with specific arguments, run: python main.py --batch_size=64. The following command-line arguments are available:

    • Train batch size: --bsz_train
    • Test batch size: --bsz_test
    • bptt: --bptt
    • Learning rate: --lr
    • Embedding size: --embed_size
    • Size of FeedForward Neural Network (1st layer): --ffnn_size
    • Attention Heads: --nhead
    • Transformer Layers: --nlayers

Training

The model is trained on 10 epochs using Adam as an optimizer with a learning rate = 0.001 and batch size = 32, you can find all the model settings in settings.py. Here is the loss curve for the training step:

  • Cross Entropy Loss

Sample Generation

Here are some generated samples from the model:

<time> warner owns n million francs.
<media> concern said it is a share n million.

Citation

@misc{Khamies2021Transformer_Lightning,
author = {Khamies, Waleed},
title = {A pytorch implementation of transformer based language model using Pytorch-Lightning framework.},
year = {2021},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{ https://github.com/Khamies/Transformer_Lightning}},
}

Connect with me ๐Ÿ™‚

For any question or a collaboration, drop me a message here

Follow me on Linkedin!

Thank you โค๏ธ

License

transformer_lightning's People

Contributors

khamies avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.