# google-research/bert architecture

> Architecture diagram of the GitHub repository google-research/bert, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google-research/bert
- Repository: https://github.com/google-research/bert

## Overview

This repository is Google’s TensorFlow BERT research toolkit: it provides pretraining-data generation, BERT pretraining, task fine-tuning and inference, and intermediate feature extraction. A typical workflow prepares text with WordPiece tokenization, trains or loads a BERT model, then uses a task runner to produce predictions or evaluation results. The README also documents compact, multilingual, and whole-word-masking model variants. Connections below follow shown calls, imports listed in the source index, or explicit README statements; unsampled implementations are not inferred.

Main entry points: [`run_classifier.py`](https://github.com/google-research/bert/blob/master/run_classifier.py) (Task classifier), [`run_classifier_with_tfhub.py`](https://github.com/google-research/bert/blob/master/run_classifier_with_tfhub.py) (Hub classifier), [`run_squad.py`](https://github.com/google-research/bert/blob/master/run_squad.py) (SQuAD runner), [`extract_features.py`](https://github.com/google-research/bert/blob/master/extract_features.py) (Feature extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Data preparation"]
  node_prepdata["Pretraining data"]
  node_tokenizer["WordPiece tokenizer<br/>[tokenization.py]"]
end

subgraph group_model["BERT runtime"]
  node_bert["BERT encoder<br/>[modeling.py]"]
end

subgraph group_tasks["Task workflows"]
  node_features["Feature extraction"]
  node_classifier["Task classifier<br/>[run_classifier.py]"]
  node_hubclassifier["Hub classifier"]
  node_squad["SQuAD runner<br/>[run_squad.py]"]
  node_outputs["Predictions and features"]
end

subgraph group_train["Training support"]
  node_pretrain["Pretraining runner<br/>[run_pretraining.py]"]
  node_optimizer["Optimizer<br/>[optimization.py]"]
end

node_user(("Researcher"))
node_tfhub["TensorFlow Hub"]

node_user -->|"prepares corpus"| node_prepdata
node_prepdata -->|"tokenizes text"| node_tokenizer
node_user -->|"trains model"| node_pretrain
node_pretrain -->|"builds encoder"| node_bert
node_pretrain -->|"creates training op"| node_optimizer
node_user -->|"runs task"| node_classifier
node_classifier -->|"tokenizes examples"| node_tokenizer
node_classifier -->|"builds encoder"| node_bert
node_classifier -->|"creates training op"| node_optimizer
node_classifier -.->|"writes predictions"| node_outputs
node_user -->|"runs question answering"| node_squad
node_squad -.->|"tokenizes examples"| node_tokenizer
node_squad -.->|"builds encoder"| node_bert
node_squad -->|"creates training op"| node_optimizer
node_squad -.->|"writes answers"| node_outputs
node_user -->|"extracts representations"| node_features
node_features -->|"tokenizes examples"| node_tokenizer
node_features -->|"builds encoder"| node_bert
node_features -.->|"writes vectors"| node_outputs
node_user -->|"runs Hub example"| node_hubclassifier
node_hubclassifier -->|"reuses data processing"| node_classifier
node_hubclassifier -->|"creates training op"| node_optimizer
node_hubclassifier -->|"loads module"| node_tfhub
node_hubclassifier -.->|"evaluates task"| node_outputs
node_user -->|"enables whole-word masking"| node_prepdata

click node_prepdata "https://github.com/google-research/bert/blob/master/create_pretraining_data.py"
click node_tokenizer "https://github.com/google-research/bert/blob/master/tokenization.py"
click node_features "https://github.com/google-research/bert/blob/master/extract_features.py"
click node_bert "https://github.com/google-research/bert/blob/master/modeling.py"
click node_pretrain "https://github.com/google-research/bert/blob/master/run_pretraining.py"
click node_classifier "https://github.com/google-research/bert/blob/master/run_classifier.py"
click node_hubclassifier "https://github.com/google-research/bert/blob/master/run_classifier_with_tfhub.py"
click node_squad "https://github.com/google-research/bert/blob/master/run_squad.py"
click node_optimizer "https://github.com/google-research/bert/blob/master/optimization.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_prepdata,node_tokenizer toneBlue
class node_bert toneAmber
class node_features,node_classifier,node_hubclassifier,node_squad,node_outputs toneMint
class node_pretrain,node_optimizer toneRose
class node_user,node_tfhub toneIndigo
```

## Components

### Data preparation

- [Pretraining data](https://github.com/google-research/bert/blob/master/create_pretraining_data.py): `create_pretraining_data.py`
- [WordPiece tokenizer](https://github.com/google-research/bert/blob/master/tokenization.py): `tokenization.py`

### BERT runtime

- [BERT encoder](https://github.com/google-research/bert/blob/master/modeling.py): `modeling.py`

### Task workflows

- [Feature extraction](https://github.com/google-research/bert/blob/master/extract_features.py): `extract_features.py`
- [Task classifier](https://github.com/google-research/bert/blob/master/run_classifier.py): `run_classifier.py`
- [Hub classifier](https://github.com/google-research/bert/blob/master/run_classifier_with_tfhub.py): `run_classifier_with_tfhub.py`
- [SQuAD runner](https://github.com/google-research/bert/blob/master/run_squad.py): `run_squad.py`
- **Predictions and features**

### Training support

- [Pretraining runner](https://github.com/google-research/bert/blob/master/run_pretraining.py): `run_pretraining.py`
- [Optimizer](https://github.com/google-research/bert/blob/master/optimization.py): `optimization.py`

### Other components

- **Researcher**
- **TensorFlow Hub**

## Connections

- Researcher → Pretraining data: prepares corpus (evidence: `README.md`)
- Pretraining data → WordPiece tokenizer: tokenizes text (evidence: `create_pretraining_data.py`)
- Researcher → Pretraining runner: trains model (evidence: `run_pretraining.py`)
- Pretraining runner → BERT encoder: builds encoder (evidence: `run_pretraining.py`)
- Pretraining runner → Optimizer: creates training op (evidence: `run_pretraining.py`)
- Researcher → Task classifier: runs task (evidence: `README.md`)
- Task classifier → WordPiece tokenizer: tokenizes examples (evidence: `run_classifier.py`)
- Task classifier → BERT encoder: builds encoder (evidence: `run_classifier.py`)
- Task classifier → Optimizer: creates training op (evidence: `run_classifier.py`)
- Task classifier → Predictions and features: writes predictions
- Researcher → SQuAD runner: runs question answering (evidence: `run_squad.py`)
- SQuAD runner → WordPiece tokenizer: tokenizes examples (evidence: `run_squad.py`)
- SQuAD runner → BERT encoder: builds encoder (evidence: `run_squad.py`)
- SQuAD runner → Optimizer: creates training op (evidence: `run_squad.py`)
- SQuAD runner → Predictions and features: writes answers
- Researcher → Feature extraction: extracts representations (evidence: `extract_features.py`)
- Feature extraction → WordPiece tokenizer: tokenizes examples (evidence: `extract_features.py`)
- Feature extraction → BERT encoder: builds encoder (evidence: `extract_features.py`)
- Feature extraction → Predictions and features: writes vectors
- Researcher → Hub classifier: runs Hub example (evidence: `README.md`)
- Hub classifier → Task classifier: reuses data processing (evidence: `run_classifier_with_tfhub.py`)
- Hub classifier → Optimizer: creates training op (evidence: `run_classifier_with_tfhub.py`)
- Hub classifier → TensorFlow Hub: loads module (evidence: `run_classifier_with_tfhub.py`)
- Hub classifier → Predictions and features: evaluates task
- Researcher → Pretraining data: enables whole-word masking (evidence: `README.md`)
