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
- This package is inspired by the original Transformer model.
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!
Metadata
Release files for simple-transformer 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simple_transformer-0.0.1.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_transformer-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.2 kB
Release files / simple_transformer-0.0.1.tar.gz
| Download URL | simple_transformer-0.0.1.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c5c005b40ad3794d27ba7504cc091e647789fcaa1e927716d02d44760100aa14
|
|
BLAKE2b-256 checksum How to use checksums |
f2d4e2586f08def4b2e542aad481ae3c1af151c02de29a4c767fd3e865c36b29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / simple_transformer-0.0.1-py3-none-any.whl
| Download URL | simple_transformer-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22d93a173af5d3b4f273735c1e2b4e424bccbfab8193c873a140204a40c363ac
|
|
BLAKE2b-256 checksum How to use checksums |
d71ab6d9c8bb7b5485f4fd0c2ccee3f19ba152311f97c6f606ac166341943108
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|