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

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

Built distribution (wheel)

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

Total release size: 18.1 kB

Release files / encoder_decoder_transformer-0.1.1.tar.gz

Download URL encoder_decoder_transformer-0.1.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b524a09d08259646f6d602bbc83f072b607c4fb91977eea2604f6f1ee0f06cf4
BLAKE2b-256 checksum
How to use checksums
d4f4569ccfc452d35a77762f7dc184f962928e6df00a7db09c30eedde4cc60cc
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.1-py3-none-any.whl

Download URL encoder_decoder_transformer-0.1.1-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1cd3b7388f841e569271691638f485889031cdb6ef6c3fe4cba83076014b64f1
BLAKE2b-256 checksum
How to use checksums
419f676ee8d92e6215636fef22869a5fee51848a82d1fc9623991ba65251564f
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

This release

0.1.1 This release

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