Skip to content

goldstraw/rust_transformer

Repository files navigation

Rust Transformer from Scratch

This repository contains a Rust implementation of a transformer built from scratch. The transformer is configured for sentiment analysis, and a dataset of movie reviews is included in the repository for training and testing the transformer.

Overview

This project implements an encoder-only transformer, built without any external machine learning libraries. The transformer uses word embeddings generated from my WordEmbeddings repository to encode words. Sample word embeddings are included in the repository.

Usage

To use this transformer implementation, you must have Rust and Cargo installed on your machine. After installing Rust and Cargo, you can clone this repository to your local machine.

To run the transformer, use the following command:

$ cargo run --release

This command will train the transformer on the movie review dataset and then run tests on a test set. The results of the training and testing will be printed to the console.

Example Training

Cost over time of the transformer This specific model was trained with 12 words & 50 dimensions per sample, 2 encoder blocks, 3 attention heads, a hidden layer size of 400 and a learning rate of 0.001.

Further Reading

Original paper: Attention Is All You Need

Original paper for dataset: Learning Word Vectors for Sentiment Analysis

For more information about this project, read my blog post on transformers.

License

The source code for the transformer is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.

About

A transformer built from scratch in Rust.

Resources

License

Stars

Watchers

Forks

Languages