Name | babybert JSON |
Version |
0.1.1
JSON |
| download |
home_page | None |
Summary | Minimal BERT implementation in PyTorch |
upload_time | 2025-08-28 22:46:02 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License
Copyright (c) 2025 Drew Ross
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. |
keywords |
bert
deep-learning
llm
machine-learning
minimal
nlp
pytorch
transformer
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://i.imgur.com/ORrR7Ci.png">
<source media="(prefers-color-scheme: light)" srcset="https://i.imgur.com/a59Qpu8.png">
<img src="https://i.imgur.com/a59Qpu8.png" width="750" style="height: auto;" alt="BabyBERT logo"></img>
</picture>
</p>
<div align="center">
<a href="https://www.python.org/"></a>
<a href="https://github.com/dross20/babybert/blob/main/LICENSE"></a>
<a href="https://pytorch.org/"></a>
<a href="https://github.com/astral-sh/ruff"></a>
</div>
---
Minimal implementation of the [BERT architecture proposed by Devlin et al.](https://arxiv.org/pdf/1810.04805) 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](#%EF%B8%8F-roadmap) below for my future plans for this library!
## π¦ Installation
```bash
pip install babybert
```
## π Quickstart
The following example demonstrates how to tokenize text, instantiate a BabyBERT model, and obtain contextual embeddings:
```python
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/`](https://github.com/dross20/babybert/tree/9b9c0107157cc1d43771162408ebde20739b076e/examples) directory!
## πΊοΈ Roadmap
### Model Implementation
- [x] Build initial model implementation
- [x] Write trainer class
- [x] Create custom WordPiece tokenizer
- [x] Introduce more parameter configurations
- [ ] Set up pretrained model checkpoints
### Usage Examples
- [x] Pretraining
- [x] Sentiment classification
- [ ] Named entity recognition
- [ ] Question answering
Raw data
{
"_id": null,
"home_page": null,
"name": "babybert",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "bert, deep-learning, llm, machine-learning, minimal, nlp, pytorch, transformer",
"author": null,
"author_email": "Drew Ross <drewross@ku.edu>",
"download_url": "https://files.pythonhosted.org/packages/55/19/bc363d391d68593466a1bca0d11096e36c726460634f066ae5ca61c5dca6/babybert-0.1.1.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <picture>\n <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://i.imgur.com/ORrR7Ci.png\">\n <source media=\"(prefers-color-scheme: light)\" srcset=\"https://i.imgur.com/a59Qpu8.png\">\n <img src=\"https://i.imgur.com/a59Qpu8.png\" width=\"750\" style=\"height: auto;\" alt=\"BabyBERT logo\"></img>\n </picture>\n</p>\n\n<div align=\"center\">\n \n <a href=\"https://www.python.org/\"></a>\n <a href=\"https://github.com/dross20/babybert/blob/main/LICENSE\"></a>\n <a href=\"https://pytorch.org/\"></a>\n <a href=\"https://github.com/astral-sh/ruff\"></a>\n \n</div>\n\n---\n\nMinimal implementation of the [BERT architecture proposed by Devlin et al.](https://arxiv.org/pdf/1810.04805) 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).\n\nSee the [roadmap](#%EF%B8%8F-roadmap) below for my future plans for this library!\n\n## \ud83d\udce6 Installation\n\n```bash\npip install babybert\n```\n\n## \ud83d\ude80 Quickstart\nThe following example demonstrates how to tokenize text, instantiate a BabyBERT model, and obtain contextual embeddings:\n```python\nfrom babybert.tokenizer import WordPieceTokenizer\nfrom babybert.model import BabyBERTConfig, BabyBERT\n\n# Load a pretrained tokenizer and encode a text\ntokenizer = WordPieceTokenizer.from_pretrained(\"toy-tokenizer\")\nencoded = tokenizer.batch_encode([\"Hello, world!\"])\n\n# Initialize an untrained BabyBERT model\nmodel_cfg = BabyBERTConfig.from_preset(\n \"tiny\", vocab_size=tokenizer.vocab_size, block_size=len(encoded['token_ids'][0])\n)\nmodel = BabyBERT(model_cfg)\n\n# Obtain contextual embeddings\nhidden = model(**encoded)\nprint(hidden)\n```\n\n> [!TIP]\n> For more usage examples, check out the [`examples/`](https://github.com/dross20/babybert/tree/9b9c0107157cc1d43771162408ebde20739b076e/examples) directory!\n\n## \ud83d\uddfa\ufe0f Roadmap\n\n### Model Implementation\n- [x] Build initial model implementation\n- [x] Write trainer class\n- [x] Create custom WordPiece tokenizer\n- [x] Introduce more parameter configurations\n- [ ] Set up pretrained model checkpoints\n\n### Usage Examples\n- [x] Pretraining\n- [x] Sentiment classification\n- [ ] Named entity recognition\n- [ ] Question answering\n\n\n\n\n\n\n\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2025 Drew Ross\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.",
"summary": "Minimal BERT implementation in PyTorch",
"version": "0.1.1",
"project_urls": {
"Repository": "https://github.com/dross20/babybert"
},
"split_keywords": [
"bert",
" deep-learning",
" llm",
" machine-learning",
" minimal",
" nlp",
" pytorch",
" transformer"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ade593e71f49db00e7139d340ac7b44565dd657a96d9dd5b024c243cbe589163",
"md5": "ebf82fba56709efc7c553f026f84775a",
"sha256": "d9335602d1e6b774cc8290d58274ede2aa8f162297df4e812eb8ddb5079e0686"
},
"downloads": -1,
"filename": "babybert-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ebf82fba56709efc7c553f026f84775a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 28272,
"upload_time": "2025-08-28T22:46:00",
"upload_time_iso_8601": "2025-08-28T22:46:00.998533Z",
"url": "https://files.pythonhosted.org/packages/ad/e5/93e71f49db00e7139d340ac7b44565dd657a96d9dd5b024c243cbe589163/babybert-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "5519bc363d391d68593466a1bca0d11096e36c726460634f066ae5ca61c5dca6",
"md5": "eb584e7191935f2073e9ed88c943f955",
"sha256": "31b8bf6ce39aa052b517d4461ed035965c3aa59df6e61812d99a687219b60fd8"
},
"downloads": -1,
"filename": "babybert-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "eb584e7191935f2073e9ed88c943f955",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 280148,
"upload_time": "2025-08-28T22:46:02",
"upload_time_iso_8601": "2025-08-28T22:46:02.107053Z",
"url": "https://files.pythonhosted.org/packages/55/19/bc363d391d68593466a1bca0d11096e36c726460634f066ae5ca61c5dca6/babybert-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-28 22:46:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dross20",
"github_project": "babybert",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "babybert"
}