pytorch-pretrained-bert
PyTorch version of Google AI BERT model with script to load Google pre-trained models
What it is and what it does
This package provides op-for-op PyTorch reimplementations of four major pre-trained transformer models: BERT, OpenAI GPT, Transformer-XL, and GPT-2. It includes pre-trained weights converted from the original TensorFlow checkpoints and a suite of task-specific model heads for common NLP workflows like sequence classification, token classification, question answering, and masked language modeling.
The package is built on torch, numpy, boto3, requests, tqdm, and regex. It is designed for developers who want to fine-tune or adapt these models for downstream NLP tasks without reimplementing the transformer architecture. The repository includes examples, notebooks, and a command-line interface for checkpoint conversion, though the package itself has not seen a new release since April 2019.
Use it for:
- Fine-tune BERT for text classification tasks like sentiment analysis or intent detection.
- Use pre-trained GPT or GPT-2 for language generation and completion tasks.
- Adapt Transformer-XL for long-sequence modeling and perplexity evaluation on language corpora.
- Perform question answering with BertForQuestionAnswering on SQuAD-like datasets.
- Extract contextual embeddings from BERT for downstream machine learning pipelines.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides PyTorch implementations of BERT, GPT, Transformer-XL, and GPT-2 models with pre-trained weights and fine-tuning examples for natural language processing tasks.
Yes, if you need to work with BERT, GPT, or Transformer-XL in PyTorch and are comfortable with a package that has not received updates since April 2019. The implementation is well-tested, has low install friction, and carries permissive licensing. However, consider whether a more actively maintained alternative (such as HuggingFace Transformers, which this package predates) better suits your project's long-term maintenance needs.
Install
pytorch-pretrained-bert on PyPI
pip
pip install pytorch-pretrained-bertuv
uv add pytorch-pretrained-bertpoetry
poetry add pytorch-pretrained-bertInstalling pytorch-pretrained-bert
Before you install
Low install friction with pure Python wheels for both Python 2 and 3. Active maintenance with recent commits; however, the package has not received a release since April 2019 despite ongoing repository activity, suggesting it may be in maintenance mode rather than active development.
License in practice
Licensed under Apache (permissive), allowing commercial and private use with minimal restrictions. You may use, modify, and distribute the code freely provided you include a copy of the license and notice of changes.
Quickstart
pip install pytorch-pretrained-bert
from pytorch_pretrained_bert import BertModel, BertTokenizer
model = BertModel.from_pretrained('bert-base-uncased')
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
encoded = tokenizer.encode('Hello world')
output = model(encoded)
Requires PyTorch 0.4.1 or 1.0.0+; torch must be installed separately. Optional: ftfy and SpaCy for original OpenAI GPT tokenization (ftfy pinned to 4.4.3 for Python 2).
Verify before relying
- Whether pre-trained model weights are still downloadable from the original sources (Google, OpenAI) given the package's age.
- Compatibility with modern PyTorch versions beyond 1.0.0.
- Performance parity claims (e.g., ~91 F1 on SQuAD) on current datasets and hardware.
Package facts
| License | Apache (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — torch, numpy, boto3, requests, tqdm, regex |
| Maintenance | actively maintained — 2,668 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 78,578/month — #14,427 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytorch_pretrained_bert-0.6.2-py2-none-any.whl; pytorch_pretrained_bert-0.6.2-py3-none-any.whl
Keywords: BERT, NLP, deep, learning, google
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
fair-esmProvides pre-trained transformer protein…
permissive · top 15,000 on PyPI
spacy-transformersIntegrates pretrained transformer models (BERT,…
permissive · top 15,000 on PyPI
torchtexttorchtext provides text datasets, preprocessing…
permissive · top 15,000 on PyPI
curated-transformersCurated Transformers provides PyTorch…
permissive · top 5,000 on PyPI
spacy-curated-transformersIntegrates curated transformer models (ALBERT,…
permissive · top 5,000 on PyPI
loralibloralib provides PyTorch modules that implement…
permissive · top 15,000 on PyPI
bertopicBERTopic performs topic modeling on text…
permissive · top 15,000 on PyPI
bert-scoreBERTScore computes automatic evaluation metrics…
permissive · top 15,000 on PyPI
sentence-transformersComputes embeddings and reranking scores for…
permissive · top 1,000 on PyPI
transformer-lensTransformerLens loads and inspects the internal…
permissive · top 15,000 on PyPI