Skip to main content

A remade version of basic transformers

Project description

Alpaca Transformer Model from Scratch

This project demonstrates the process of building a transformer model from scratch, utilizing PyTorch for deep learning. It covers the essential components of transformer architectures, such as tokenization, embedding layers, multi-head self-attention, and the training pipeline. This model is designed for educational purposes to help users understand and implement transformers without relying on pre-built models.

Table of Contents

  1. Project Overview
  2. Getting Started
  3. Usage
  4. Model Architecture
  5. Contributing
  6. License

Project Overview

The Alpaca Transformer is a custom-built transformer model designed from scratch to perform token classification tasks. It includes a custom tokenizer, vocabulary creation, tokenization process, and the full transformer architecture. The model is implemented in PyTorch, using standard transformer building blocks such as embedding layers, multi-head self-attention, and position encodings.

Key Features:

  • Tokenizer and vocabulary creation from scratch.
  • Transformer architecture with multi-head self-attention.
  • Training pipeline to fine-tune the model.
  • Modular and extensible codebase for educational purposes.
  • All the tools have been made into easy to use methods in the 'alpaca.py' file

Getting Started

Prerequisites

Before you begin, ensure that you have the following installed on your system:

  • Python (>= 3.7)
  • PyTorch (>= 1.7.0)
  • CUDA (for GPU acceleration, optional but recommended)

I personally used Python=3.12.7 and PyTorch=2.6.0-Cuda18 so if you're having issues try it.

Installation

  1. Clone the repository:
    git clone https://github.com/RazielMoesch/alpaca.git
    cd alpaca
    

or

pip install alpaca-transformer


## Usage

### Data Preperation
To train the model, you’ll need a dataset in text format. Each line in the dataset represents a sentence to be tokenized. The tokenizer will process the text into tokens, which are then padded to a uniform length (e.g., 512 tokens).
Prepare your dataset in a text file (eg., data.txt) where each line represents a sentence
The tokenization happens automatically when you use 'alpaca.dataset'
At the bottom of majority of the files there are left over test examples feel free to use them to understand how each file works.

### Training
To train the transformer model, you can follow these step:
1. Define your models optimizer, loss_fn and epochs
2. use 'alpaca.train()' this takes in multiple params.

## Model Architecture
This model follows a standard transformer architecture as its backbone:
- Tokenizer - Transforms text into interpratble tokens
- Embedding Layer - Maps tokens to vectors 
- Multi-Head Self Attention - Allows the model to focus on different parts of the input
- Feed-Forward-Network - A Linear,ReLU,Linear layer
- Positional-Encoding - Use sin and cos funcs to give the model info about the order of the sequence
- Stacking - Stack Many of these in Encoder and Decoder Layers to achieve a Transformer

## License
This is under a creative commons license just look at the file if you want specifics
Please don't outright steal. Only restriction.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alpaca_transformer-0.1.2.7.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alpaca_transformer-0.1.2.7-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file alpaca_transformer-0.1.2.7.tar.gz.

File metadata

  • Download URL: alpaca_transformer-0.1.2.7.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for alpaca_transformer-0.1.2.7.tar.gz
Algorithm Hash digest
SHA256 c16dc76774c1492b681530e34be56a8c2e9c38230bfee44ea02e03dd7a5ff1e6
MD5 7261cd71cc25c36978548f3f1375cb5a
BLAKE2b-256 2e5dd2b1b318c5c7aa31d77da8959100d0cc4c8438d2bf72b61067b6c5243fc9

See more details on using hashes here.

File details

Details for the file alpaca_transformer-0.1.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for alpaca_transformer-0.1.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a92fb412e6a05a6dae7fa790ba2293cd29c7929f6dd080f371c71fa47a10e87d
MD5 125674ac7e9d1c0e04a0b76df822a475
BLAKE2b-256 11a0b97c2afa04bd76775e9b67e08ed21bfa6cd7e2c886b6f07b21c1de0bb62f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page