Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AkiRusProd/numpy-transformer

Repository files navigation

numpy-transformer

Note

This model was implemented in numpy-nn-model repository; therefore, this repository is no longer supported.

What is this?

This is a fast numpy implementation of the Transformer (Seq2Seq) model in original paper "Attention is All You Need", that runs at CPU with numpy or GPU with cupy (very fast).

Training

The model was trained for 10 epochs. On my machine, training one epoch with CPU takes 3 hours, but with GPU takes 2 minutes!!!! Thus training of all epochs takes 20 minutes.
Note: You can`t open pre-trained model if CuPy is not installed, because this model was trained on GPU.

Dataset:

The dataset on which the model was trained is Multi30k dataset. To import this just run extract_data.py script.

Project Structure

Transformer model components:

Functional components:

  • activations.py - list of activation functions for the model
  • losses.py - list of loss functions for the model. But used only torch like Cross Entropy Loss
  • optimizers.py - list of gradient optimizers for the model. In this case, Adam is used with the Noam scheduler

Special utils:

Others:

  • (削除) tests - junk scripts. Do not pay attention to them (削除ここまで)

Examples

Examples of translated sentences of validation set:

Example No1
Input sentence: people sitting in a circle outside a large building
Decoded sentence: personen sitzen im freien vor einem großen gebäude
Target sentence: menschen die vor einem großen gebäude im kreis sitzen

Example No2
Input sentence: a woman sings in a club with a guitarist behind her
Decoded sentence: eine frau singt in einem club mit einem club
Target sentence: eine frau singt in einem klub mit einem gitarristen hinter ihr

Example No3
Input sentence: construction workers having a discussion by the tracks
Decoded sentence: bauarbeiter diskutieren einige von den bahngleisen
Target sentence: arbeiter diskutieren neben den schiene

Example No4
Input sentence: a man with graying hair shaves his beard
Decoded sentence: ein bärtiger mann bart trägt
Target sentence: ein mann mit ergrauenden haaren rasiert seinen bart

Example No5
Input sentence: a man in a black shirt and jeans standing on the sidewalk looking at the camera
Decoded sentence: ein mann in einem schwarzen oberteil und jeans steht auf dem gehweg und blickt auf die kamera
Target sentence: ein mann in einem schwarzen hemd und jeans steht auf dem gehsteig und blickt in die kamera

Example No6
Input sentence: a woman is laying down on a sofa laughing
Decoded sentence: eine frau liegt auf einem sofa und lacht
Target sentence: eine frau liegt auf einem sofa und lacht

Example No7
Input sentence: two males seem to be conversing while standing in front of a truck's back and behind a metal item while four people stand around them
Decoded sentence: vier personen stehen hinter ihnen unterhalten sich während hinter ihnen und hinter ihnen unterhalten und unterhalten und hinter ihnen stehen
Target sentence: zwei männer stehen vor dem heck eines lasters und hinter einem metallgegenstand und unterhalten sich anscheinend während vier weitere personen um sie herum stehen

Example No8
Input sentence: two rockers are singing and playing on a dark stage
Decoded sentence: zwei singen und spielen auf einer bühne
Target sentence: zwei rocker singen und spielen auf einer dunklen bühne

Example No9
Input sentence: a man fixing a little girl's bicycle
Decoded sentence: ein mann repariert ein kleines fahrrad
Target sentence: ein mann repariert das fahrrad eines kleinen mädchens

Example No10
Input sentence: a man eating a sandwich with his baby daughter in his lap
Decoded sentence: ein mann isst ein baby auf seiner tochter ein sandwich
Target sentence: ein mann isst ein sandwich und hält seine kleine tochter auf dem schoß

Attention plots:

References:

TODO:

  1. clean up and refactor code

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /