• Stars
    star
    1,037
  • Rank 44,435 (Top 0.9 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple transformer implementation from scratch in pytorch.

former

Simple transformer implementation from scratch in pytorch. See http://peterbloem.nl/blog/transformers for an in-depth explanation.

Limitations

The models implemented here are designed to show the simplicity of transformer models and self-attention. As such they will not scale as far as the bigger transformers. For that you'll need a number of tricks that complicate the code (see the blog post for details).

All models in the repository consist of a single stack of transformer blocks (that is, no encoder/decoder structures). It turns out that this simple configuration often works best.

Installation and use

First, download or clone the repository. Then, in the directory that contains setup.py, run

pip install -e . 

The switch -e ensures that when you edit the code, the installed packaged is also changed. This means that you can, for instance, add print statements to the code to see how it works.

Then, from the same directory, run:

python experiments/classify.py

This will run a simple classification experiment on the IMDb dataset.

Hyperparameters are passed as command line arguments. The defaults should work well. The classification data is automatically downloaded, and the wikipedia data is included in the repository.

Requirements

Python 3.6+ is required. The pip command above should install all required packages. You may also need pip install future depending on the exact python version.

conda environment

The file environment.yml describes a complete conda environment with all dependencies. After cloning or downloading the project, you create the environment as follows:

conda env create -f environment.yml --name former
conda activate former

More Repositories

1

language-models

Keras implementations of three language models: character-level RNN, word-level RNN and Sentence VAE (Bowman, Vilnis et al 2016).
Python
42
star
2

pca-book

Source files for a book on Principal component analysis
TeX
33
star
3

pixel-models

Pytorch implementations of the PixelCNN (va Oord et al. 2016) and PixelVAE (Gulrajani et al. 2016) models
Python
31
star
4

kgbench-data

A set of benchmark repositories for node classification on knowledge graphs. To use, see https://github.com/pbloem/kgbench-loader
Python
24
star
5

blog

Example code to accompany blog posts
Jupyter Notebook
8
star
6

motive

A proof-of-concept library for motif analysis using MDL techniques.
Java
6
star
7

peterbloem.nl

Repository for personal website
CSS
4
star
8

Lilian

Machine Learning Toolkit
Java
4
star
9

machine-learning

Worksheets, sample code and homework for the course Machine Learning at the VU University Amsterdam.
Jupyter Notebook
4
star
10

attn-book

Work in progress. Book on attention and embeddings.
3
star
11

Lilian-experimental

Any research work in progress
Java
3
star
12

ifsem

Proof-of-concept implementation of the IFS-EM algorithm.
Java
2
star
13

gated-rgcn

Proof-of-concept gated RGCN.
Python
2
star
14

score

Jupyter Notebook
2
star
15

Publications

Anything scientific I'm writing, whether intended for publication or not.
TeX
2
star
16

orca

A JAVA port of the ORCA algorithm by Tomaz Hocevar
Java
1
star
17

cleartxt

A simple website (cleartxt.info) designed to quickly inform website owners about the problem of cleartext passwords.
CSS
1
star
18

Misc

Miscellaneous projects
Jupyter Notebook
1
star
19

leitner

Proof of concept flash card system
JavaScript
1
star
20

voynich-experiments

Java
1
star
21

motive-cls

Motif classificastion experiment
Java
1
star
22

oblique

Oblique strategy cards for academia.
Python
1
star
23

dyna

Dynamic knowledge graph embeddings
Python
1
star
24

krraftwerk

Python
1
star
25

embed

Implementation of basic KG embedding methods. Meant both as an example implementation and as a testbed for simple improvements.
Python
1
star