Minimal BERT implementation in PyTorch
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file babybert-0.1.1.tar.gz.
File metadata
- Download URL: babybert-0.1.1.tar.gz
- Upload date:
- Size: 280.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31b8bf6ce39aa052b517d4461ed035965c3aa59df6e61812d99a687219b60fd8
|
|
| MD5 |
eb584e7191935f2073e9ed88c943f955
|
|
| BLAKE2b-256 |
5519bc363d391d68593466a1bca0d11096e36c726460634f066ae5ca61c5dca6
|
Provenance
The following attestation bundles were made for babybert-0.1.1.tar.gz:
Publisher:
publish-to-pypi.yml on dross20/babybert
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
babybert-0.1.1.tar.gz -
Subject digest:
31b8bf6ce39aa052b517d4461ed035965c3aa59df6e61812d99a687219b60fd8 - Sigstore transparency entry: 446270570
- Sigstore integration time:
-
Permalink:
dross20/babybert@962f69ef72c5264e386956bba6939c4a333dc5a5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dross20
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@962f69ef72c5264e386956bba6939c4a333dc5a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file babybert-0.1.1-py3-none-any.whl.
File metadata
- Download URL: babybert-0.1.1-py3-none-any.whl
- Upload date:
- Size: 28.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9335602d1e6b774cc8290d58274ede2aa8f162297df4e812eb8ddb5079e0686
|
|
| MD5 |
ebf82fba56709efc7c553f026f84775a
|
|
| BLAKE2b-256 |
ade593e71f49db00e7139d340ac7b44565dd657a96d9dd5b024c243cbe589163
|
Provenance
The following attestation bundles were made for babybert-0.1.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on dross20/babybert
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
babybert-0.1.1-py3-none-any.whl -
Subject digest:
d9335602d1e6b774cc8290d58274ede2aa8f162297df4e812eb8ddb5079e0686 - Sigstore transparency entry: 446270600
- Sigstore integration time:
-
Permalink:
dross20/babybert@962f69ef72c5264e386956bba6939c4a333dc5a5 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dross20
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@962f69ef72c5264e386956bba6939c4a333dc5a5 -
Trigger Event:
push
-
Statement type: