# baidu/senta architecture

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

- Interactive diagram: https://gitdiagram.com/baidu/senta
- Repository: https://github.com/baidu/senta

## Overview

Senta is a PaddlePaddle sentiment-analysis toolkit: it offers SKEP pretraining and model training, plus a one-call prediction interface for sentence sentiment, aspect sentiment, and opinion extraction. The training path configures a model and trainer, prepares task data, and runs training/evaluation; the documented prediction path initializes a supported model and predicts on text. The graph preserves the documented task breadth, but several task-specific readers and prediction internals were not sampled, so uncertain wiring is omitted.

Main entry points: [`senta/training/base_trainer.py`](https://github.com/baidu/senta/blob/master/senta/training/base_trainer.py) (Base trainer), [`senta/models/ernie_classification.py`](https://github.com/baidu/senta/blob/master/senta/models/ernie_classification.py) (Classification models), [`pretraining.py`](https://github.com/baidu/senta/blob/master/pretraining.py) (Pretraining entry), [`senta/train.py`](https://github.com/baidu/senta/blob/master/senta/train.py) (Training entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Prediction API"]
  node_senta_api["Senta API<br/>[train.py]"]
  node_task_outputs["Sentiment tasks"]
end

subgraph group_data["Data preparation"]
  node_dataset["Dataset<br/>[data_set.py]"]
  node_task_readers["Task readers"]
  node_field_readers["Field readers"]
  node_tokenizers["Tokenizers"]
  node_batch_prep["Batch preparation<br/>[util_helper.py]"]
end

subgraph group_models["Models"]
  node_classification["Classification models"]
  node_sequence_label["Sequence labeling"]
  node_language_models["Language models"]
  node_ernie_encoder["ERNIE encoder<br/>[ernie.py]"]
  node_embedding["ERNIE embedding<br/>[ernie_embedding.py]"]
end

subgraph group_training["Training and evaluation"]
  node_pretrain_entry["Pretraining entry<br/>[pretraining.py]"]
  node_train_entry["Training entry<br/>[train.py]"]
  node_registry["Component registry<br/>[register.py]"]
  node_trainer["Base trainer<br/>[base_trainer.py]"]
  node_task_trainer["GLUE task trainer"]
  node_metrics["Metrics<br/>[metrics.py]"]
  node_glue_eval["GLUE evaluation<br/>[glue_eval.py]"]
end

node_user(("User"))

node_user -->|"initializes and predicts"| node_senta_api
node_senta_api -->|"returns predictions"| node_task_outputs
node_pretrain_entry -->|"selects readers"| node_task_readers
node_pretrain_entry -->|"constructs model"| node_language_models
node_pretrain_entry -->|"uses trainer"| node_trainer
node_train_entry -->|"resolves components"| node_registry
node_train_entry -->|"constructs model"| node_classification
node_train_entry -->|"builds trainer"| node_trainer
node_dataset -->|"uses fields"| node_field_readers
node_field_readers -->|"formats batches"| node_batch_prep
node_field_readers -->|"uses embedding"| node_embedding
node_embedding -->|"builds embeddings"| node_ernie_encoder
node_classification -->|"runs encoder"| node_ernie_encoder
node_classification -->|"computes metrics"| node_metrics
node_trainer -->|"specialized by"| node_task_trainer
node_task_trainer -->|"extends"| node_trainer
node_trainer -.->|"evaluates outputs"| node_metrics
node_classification -->|"uses task evaluation"| node_glue_eval

click node_senta_api "https://github.com/baidu/senta/blob/master/senta/train.py"
click node_pretrain_entry "https://github.com/baidu/senta/blob/master/pretraining.py"
click node_train_entry "https://github.com/baidu/senta/blob/master/senta/train.py"
click node_registry "https://github.com/baidu/senta/blob/master/senta/common/register.py"
click node_dataset "https://github.com/baidu/senta/blob/master/senta/data/data_set.py"
click node_task_readers "https://github.com/baidu/senta/tree/master/senta/data/data_set_reader"
click node_field_readers "https://github.com/baidu/senta/tree/master/senta/data/field_reader"
click node_tokenizers "https://github.com/baidu/senta/tree/master/senta/data/tokenizer"
click node_batch_prep "https://github.com/baidu/senta/blob/master/senta/data/util_helper.py"
click node_classification "https://github.com/baidu/senta/blob/master/senta/models/ernie_classification.py"
click node_sequence_label "https://github.com/baidu/senta/blob/master/senta/models/ernie_crf_sequence_label.py"
click node_language_models "https://github.com/baidu/senta/blob/master/senta/models/ernie_multil_task_language_model.py"
click node_ernie_encoder "https://github.com/baidu/senta/blob/master/senta/modules/ernie.py"
click node_embedding "https://github.com/baidu/senta/blob/master/senta/modules/token_embedding/ernie_embedding.py"
click node_trainer "https://github.com/baidu/senta/blob/master/senta/training/base_trainer.py"
click node_task_trainer "https://github.com/baidu/senta/blob/master/senta/training/glue_task_trainer.py"
click node_metrics "https://github.com/baidu/senta/blob/master/senta/metrics/metrics.py"
click node_glue_eval "https://github.com/baidu/senta/blob/master/senta/metrics/glue_eval.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_senta_api,node_task_outputs,node_user toneBlue
class node_dataset,node_task_readers,node_field_readers,node_tokenizers,node_batch_prep toneAmber
class node_classification,node_sequence_label,node_language_models,node_ernie_encoder,node_embedding toneMint
class node_pretrain_entry,node_train_entry,node_registry,node_trainer,node_task_trainer,node_metrics,node_glue_eval toneRose
```

## Components

### Prediction API

- [Senta API](https://github.com/baidu/senta/blob/master/senta/train.py): `senta/train.py`
- **Sentiment tasks**

### Data preparation

- [Dataset](https://github.com/baidu/senta/blob/master/senta/data/data_set.py): `senta/data/data_set.py`
- [Task readers](https://github.com/baidu/senta/tree/master/senta/data/data_set_reader): `senta/data/data_set_reader`
- [Field readers](https://github.com/baidu/senta/tree/master/senta/data/field_reader): `senta/data/field_reader`
- [Tokenizers](https://github.com/baidu/senta/tree/master/senta/data/tokenizer): `senta/data/tokenizer`
- [Batch preparation](https://github.com/baidu/senta/blob/master/senta/data/util_helper.py): `senta/data/util_helper.py`

### Models

- [Classification models](https://github.com/baidu/senta/blob/master/senta/models/ernie_classification.py): `senta/models/ernie_classification.py`
- [Sequence labeling](https://github.com/baidu/senta/blob/master/senta/models/ernie_crf_sequence_label.py): `senta/models/ernie_crf_sequence_label.py`
- [Language models](https://github.com/baidu/senta/blob/master/senta/models/ernie_multil_task_language_model.py): `senta/models/ernie_multil_task_language_model.py`
- [ERNIE encoder](https://github.com/baidu/senta/blob/master/senta/modules/ernie.py): `senta/modules/ernie.py`
- [ERNIE embedding](https://github.com/baidu/senta/blob/master/senta/modules/token_embedding/ernie_embedding.py): `senta/modules/token_embedding/ernie_embedding.py`

### Training and evaluation

- [Pretraining entry](https://github.com/baidu/senta/blob/master/pretraining.py): `pretraining.py`
- [Training entry](https://github.com/baidu/senta/blob/master/senta/train.py): `senta/train.py`
- [Component registry](https://github.com/baidu/senta/blob/master/senta/common/register.py): `senta/common/register.py`
- [Base trainer](https://github.com/baidu/senta/blob/master/senta/training/base_trainer.py): `senta/training/base_trainer.py`
- [GLUE task trainer](https://github.com/baidu/senta/blob/master/senta/training/glue_task_trainer.py): `senta/training/glue_task_trainer.py`
- [Metrics](https://github.com/baidu/senta/blob/master/senta/metrics/metrics.py): `senta/metrics/metrics.py`
- [GLUE evaluation](https://github.com/baidu/senta/blob/master/senta/metrics/glue_eval.py): `senta/metrics/glue_eval.py`

### Other components

- **User**

## Connections

- User → Senta API: initializes and predicts (evidence: `README.md`)
- Senta API → Sentiment tasks: returns predictions (evidence: `README.md`)
- Pretraining entry → Task readers: selects readers (evidence: `pretraining.py`)
- Pretraining entry → Language models: constructs model (evidence: `pretraining.py`)
- Pretraining entry → Base trainer: uses trainer (evidence: `pretraining.py`)
- Training entry → Component registry: resolves components (evidence: `senta/train.py`)
- Training entry → Classification models: constructs model (evidence: `senta/train.py`)
- Training entry → Base trainer: builds trainer (evidence: `senta/train.py`)
- Dataset → Field readers: uses fields (evidence: `senta/data/data_set.py`)
- Field readers → Batch preparation: formats batches (evidence: `senta/data/field_reader/ernie_classification_field_reader.py`)
- Field readers → ERNIE embedding: uses embedding (evidence: `senta/data/field_reader/ernie_classification_field_reader.py`)
- ERNIE embedding → ERNIE encoder: builds embeddings (evidence: `senta/modules/token_embedding/ernie_embedding.py`)
- Classification models → ERNIE encoder: runs encoder (evidence: `senta/models/ernie_classification.py`)
- Classification models → Metrics: computes metrics (evidence: `senta/models/ernie_classification.py`)
- Base trainer → GLUE task trainer: specialized by (evidence: `senta/training/glue_task_trainer.py`)
- GLUE task trainer → Base trainer: extends (evidence: `senta/training/glue_task_trainer.py`)
- Base trainer → Metrics: evaluates outputs
- Classification models → GLUE evaluation: uses task evaluation (evidence: `senta/models/ernie_one_sent_classification_ch.py`)
