Skip to main content

BabyBERT logo

Static Badge GitHub license PyTorch Ruff


Minimal implementation of the BERT architecture proposed by Devlin et al. using the PyTorch library. This implementation focuses on simplicity and readability, so the model code is not optimized for inference or training efficiency. BabyBERT can be fine-tuned for downstream tasks such as named-entity recognition (NER), sentiment classification, or question answering (QA).

See the roadmap below for my future plans for this library!

📦 Installation

pip install babybert

🚀 Quickstart

The following example demonstrates how to tokenize text, instantiate a BabyBERT model, and obtain contextual embeddings:

from babybert.tokenizer import WordPieceTokenizer
from babybert.model import BabyBERTConfig, BabyBERT

# Load a pretrained tokenizer and encode a text
tokenizer = WordPieceTokenizer.from_pretrained("toy-tokenizer")
encoded = tokenizer.batch_encode(["Hello, world!"])

# Initialize an untrained BabyBERT model
model_cfg = BabyBERTConfig.from_preset(
  "tiny", vocab_size=tokenizer.vocab_size, block_size=len(encoded['token_ids'][0])
)
model = BabyBERT(model_cfg)

# Obtain contextual embeddings
hidden = model(**encoded)
print(hidden)

[!TIP] For more usage examples, check out the examples/ directory!

🗺️ Roadmap

Model Implementation

  • Build initial model implementation
  • Write trainer class
  • Create custom WordPiece tokenizer
  • Introduce more parameter configurations
  • Set up pretrained model checkpoints

Usage Examples

  • Pretraining
  • Sentiment classification
  • Named entity recognition
  • Question answering

Release files for babybert 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 babybert 0.1.1
File Size Uploaded
babybert-0.1.1.tar.gz 280.1 kB Details

Built distribution (wheel)

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

Total release size: 308.4 kB

Release files / babybert-0.1.1.tar.gz

Download URL babybert-0.1.1.tar.gz
Size 280.1 kB
Tags Source
SHA-256 checksum
How to use checksums
31b8bf6ce39aa052b517d4461ed035965c3aa59df6e61812d99a687219b60fd8
BLAKE2b-256 checksum
How to use checksums
5519bc363d391d68593466a1bca0d11096e36c726460634f066ae5ca61c5dca6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 28, 2025.

Transparency log

Release files / babybert-0.1.1-py3-none-any.whl

Download URL babybert-0.1.1-py3-none-any.whl
Size 28.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9335602d1e6b774cc8290d58274ede2aa8f162297df4e812eb8ddb5079e0686
BLAKE2b-256 checksum
How to use checksums
ade593e71f49db00e7139d340ac7b44565dd657a96d9dd5b024c243cbe589163
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 28, 2025.

Transparency log

Release history Release notifications | RSS feed

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