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.2

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.2
File Size Uploaded
encoder_decoder_transformer-0.1.2.tar.gz 6.5 kB Details

Built distribution (wheel)

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

Total release size: 18.1 kB

Release files / encoder_decoder_transformer-0.1.2.tar.gz

Download URL encoder_decoder_transformer-0.1.2.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
deac1de65f1dd3cad76c00b1658398a09193060cc118fd067d7890132e0dd975
BLAKE2b-256 checksum
How to use checksums
04695284fef8169979434f80b9433ac595ad63497267e0bdbf5fa358cdca06db
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.2-py3-none-any.whl

Download URL encoder_decoder_transformer-0.1.2-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55983db0ac088d7bd1cf9ed57f61d9d9e49ebc57041113f9a8042ecbba2b2987
BLAKE2b-256 checksum
How to use checksums
0e3f78061ba2d5002e5bb9c5bac803bb845c5a0aface56a87c0561ebce1ea42e
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

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

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