Skip to main content

A simple and modular implementation of the Transformer model in PyTorch

Project description

Simple Transformer

A simple and modular implementation of the Transformer model in PyTorch. This package provides an intuitive interface to build Transformer models for a variety of NLP tasks like translation, summarization, and more.


🌟 Features

  • Encoder, Decoder, and Self-Attention layers implemented.
  • Highly customizable architecture (e.g., number of layers, attention heads, embedding size).
  • Supports Masked and Unmasked attention mechanisms.
  • Easy to integrate and extend for different use cases.

🚀 Installation

Via pip

You can install the package directly from PyPI:

pip install simple-transformer

From Source

Alternatively, clone the repository and install it locally:

git clone https://github.com/nullHawk/simple-transformer.git
cd simple-transformer
pip install .

📝 Usage

Basic Transformer Model

Here's how you can use the basic Transformer model in your project:

import torch
from simple_transformer import Transformer

# Define input parameters
src_vocab_size = 10
trg_vocab_size = 10
src_pad_idx = 0
trg_pad_idx = 0

# Initialize the Transformer model
model = Transformer(
    src_vocab_size=src_vocab_size,
    trg_vocab_size=trg_vocab_size,
    src_pad_idx=src_pad_idx,
    trg_pad_idx=trg_pad_idx,
)

# Example input (batch_size=2, sequence_length=9)
src = torch.tensor([[1, 5, 6, 4, 3, 9, 5, 2, 0], [1, 8, 7, 3, 4, 5, 6, 7, 2]])
trg = torch.tensor([[1, 7, 4, 3, 5, 9, 2, 0], [1, 5, 6, 2, 4, 7, 6, 2]])

# Forward pass through the Transformer model
out = model(src, trg[:, :-1])
print(out.shape)

🔧 Components

  • Encoder: Processes the source sequence, extracting context information.
  • Decoder: Generates the target sequence based on the encoded input.
  • Self-Attention: Enables each word in a sequence to focus on other words in the same sequence.
  • Transformer: The central model combining the encoder and decoder for sequence-to-sequence tasks.

📦 Requirements

  • Python >= 3.7
  • PyTorch >= 1.9.0

📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.


🙏 Acknowledgements


By adjusting the structure and including headers for each section, the README is now cleaner and more visually appealing. This layout should enhance readability and user experience when browsing through your GitHub repository!

Project details


Download files

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

Source Distribution

simple_transformer-0.0.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

simple_transformer-0.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file simple_transformer-0.0.1.tar.gz.

File metadata

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

File hashes

Hashes for simple_transformer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c5c005b40ad3794d27ba7504cc091e647789fcaa1e927716d02d44760100aa14
MD5 b216184de469ff4e2a7c027f009619f6
BLAKE2b-256 f2d4e2586f08def4b2e542aad481ae3c1af151c02de29a4c767fd3e865c36b29

See more details on using hashes here.

File details

Details for the file simple_transformer-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_transformer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 22d93a173af5d3b4f273735c1e2b4e424bccbfab8193c873a140204a40c363ac
MD5 4910dd320228e2586d66b8eb495d9c55
BLAKE2b-256 d71ab6d9c8bb7b5485f4fd0c2ccee3f19ba152311f97c6f606ac166341943108

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