Skip to main content

encoder-decoder-transformer

A from-scratch PyTorch implementation of the Transformer encoder-decoder architecture, including multi-head attention with rotary position embeddings (RoPE), pre-layer normalization, and a position-wise feed-forward network.

Installation

Install from source with uv:

uv add encoder-decoder-transformer

or with pip:

pip install encoder-decoder-transformer

The package targets Python 3.13 and depends on PyTorch.

Usage

Build a model and run a forward pass. Token indices are integer tensors of shape (batch, seq); the model returns log-probabilities of shape (batch, tgt_seq, tgt_vocab_size). Attention masks are boolean/integer tensors of shape (batch, seq_q, seq_k) (the model adds the head dimension).

import torch

from encoder_decoder import make_model

model = make_model(
    src_vocab_size=1000,
    tgt_vocab_size=1000,
    max_context=128,
    N=2,
    d_model=64,
    d_ff=256,
    h=4,
    dropout=0.1,
)

src = torch.randint(0, 1000, (2, 8))
tgt = torch.randint(0, 1000, (2, 8))
src_mask = torch.ones(2, 8, 8)
tgt_mask = torch.ones(2, 8, 8)

log_probs = model(src, tgt, src_mask, tgt_mask)
print(log_probs.shape)  # torch.Size([2, 8, 1000])

Development

Run the linters and type checker with:

uv run ruff check .
uv run ruff format --check .
uv run mypy

License

MIT

Metadata

Release files for encoder-decoder-transformer 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for encoder-decoder-transformer 0.1.0
File Size Uploaded
encoder_decoder_transformer-0.1.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for encoder-decoder-transformer 0.1.0
File Interpreter ABI Platform
encoder_decoder_transformer-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.1 kB

Release files / encoder_decoder_transformer-0.1.0.tar.gz

Download URL encoder_decoder_transformer-0.1.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
771d4d69f556b2b3769100c60c8cb6583510c121faac27ab7ef0056ae3246b58
BLAKE2b-256 checksum
How to use checksums
7e9e5cadf23334eb1c8c8f65475a2a42462c7f662247a48c24d3532a1bdb2122
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.

Transparency log

Release files / encoder_decoder_transformer-0.1.0-py3-none-any.whl

Download URL encoder_decoder_transformer-0.1.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fb69ab65a8bfa79268127c0b3d5f36653b2339744df325404167ba4ba0a36c4
BLAKE2b-256 checksum
How to use checksums
f43bd7d87f1cfac6518ba6058f8d1c751444e27d700077e0e3f440f9a3c2e4e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page