# fxsjy/jieba architecture

> Architecture diagram of the GitHub repository fxsjy/jieba, 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/fxsjy/jieba
- Repository: https://github.com/fxsjy/jieba

## Overview

Jieba is a Python Chinese text-processing library. Its main workflow accepts text, segments it using a dictionary-backed DAG and probability-based path selection, and returns tokens; optional HMM or Paddle inference handles additional segmentation, while search mode refines token granularity. Separate capabilities provide part-of-speech tagging, parallel segmentation, token offsets, and TF-IDF/TextRank keyword extraction, plus a Whoosh analyzer. The graph follows documented capabilities and sampled imports/calls; some resource and parallel-mode wiring is documented but not shown in source excerpts.

Main entry points: [`jieba/posseg/__init__.py`](https://github.com/fxsjy/jieba/blob/master/jieba/posseg/__init__.py) (POS tagger), [`jieba/__init__.py`](https://github.com/fxsjy/jieba/blob/master/jieba/__init__.py) (Tokenizer), [`jieba/finalseg/__init__.py`](https://github.com/fxsjy/jieba/blob/master/jieba/finalseg/__init__.py) (HMM segmentation), [`jieba/lac_small/predict.py`](https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/predict.py) (Paddle predictor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_segmentation["Segmentation"]
  node_tokenizer["Tokenizer<br/>[__init__.py]"]
  node_lexicon["Main dictionary<br/>[dict.txt]"]
  node_parallel["Parallel segmentation<br/>[__init__.py]"]
  node_tokenize["Offset tokens<br/>[__init__.py]"]
end

subgraph group_models["Sequence Models"]
  node_finalseg["HMM segmentation<br/>[__init__.py]"]
  node_final_start["HMM start scores<br/>[prob_start.py]"]
  node_final_trans["HMM transition scores<br/>[prob_trans.py]"]
  node_final_emit["HMM emission scores<br/>[prob_emit.py]"]
  node_paddle_predict["Paddle predictor<br/>[predict.py]"]
  node_paddle_reader["Paddle input reader<br/>[reader_small.py]"]
  node_paddle_creator["Model creator<br/>[creator.py]"]
  node_paddle_network["BiGRU CRF network<br/>[nets.py]"]
  node_paddle_weights["Paddle model weights"]
end

subgraph group_language["Language Features"]
  node_posseg["POS tagger<br/>[__init__.py]"]
  node_pos_viterbi["POS Viterbi<br/>[viterbi.py]"]
  node_pos_char["Character states<br/>[char_state_tab.py]"]
  node_pos_start["POS start scores<br/>[prob_start.py]"]
  node_pos_trans["POS transition scores<br/>[prob_trans.py]"]
  node_pos_emit["POS emission scores<br/>[prob_emit.py]"]
  node_compat["Compatibility helpers<br/>[_compat.py]"]
end

subgraph group_analysis["Text Analysis"]
  node_tfidf["TF-IDF keywords<br/>[tfidf.py]"]
  node_textrank["TextRank keywords<br/>[textrank.py]"]
  node_whoosh["Whoosh analyzer<br/>[analyzer.py]"]
  node_idf_data["IDF corpus<br/>[idf.txt]"]
end

node_user(("Text caller"))

node_user -->|"submits text"| node_tokenizer
node_tokenizer -->|"uses dictionary"| node_lexicon
node_tokenizer -->|"recognizes unknowns"| node_finalseg
node_finalseg -->|"loads scores"| node_final_start
node_finalseg -->|"loads scores"| node_final_trans
node_finalseg -->|"loads scores"| node_final_emit
node_tokenizer -->|"dispatches mode"| node_paddle_predict
node_paddle_predict -->|"builds input"| node_paddle_reader
node_paddle_predict -->|"creates model"| node_paddle_creator
node_paddle_creator -->|"defines network"| node_paddle_network
node_paddle_predict -->|"loads checkpoint"| node_paddle_weights
node_posseg -->|"uses tokenizer"| node_tokenizer
node_posseg -->|"calls"| node_pos_viterbi
node_posseg -->|"loads states"| node_pos_char
node_posseg -->|"loads scores"| node_pos_start
node_posseg -->|"loads scores"| node_pos_trans
node_posseg -->|"loads scores"| node_pos_emit
node_user -->|"requests parallel mode"| node_parallel
node_user -->|"requests offsets"| node_tokenize
node_user -->|"requests keywords"| node_tfidf
node_tfidf -->|"segments text"| node_tokenizer
node_tfidf -->|"filters by POS"| node_posseg
node_tfidf -->|"loads IDF"| node_idf_data
node_user -->|"requests keywords"| node_textrank
node_textrank -->|"segments with tags"| node_posseg
node_user -->|"uses analyzer"| node_whoosh
node_whoosh -->|"requests search tokens"| node_tokenize
node_tokenizer -->|"uses helpers"| node_compat

click node_tokenizer "https://github.com/fxsjy/jieba/blob/master/jieba/__init__.py"
click node_lexicon "https://github.com/fxsjy/jieba/blob/master/jieba/dict.txt"
click node_finalseg "https://github.com/fxsjy/jieba/blob/master/jieba/finalseg/__init__.py"
click node_final_start "https://github.com/fxsjy/jieba/blob/master/jieba/finalseg/prob_start.py"
click node_final_trans "https://github.com/fxsjy/jieba/blob/master/jieba/finalseg/prob_trans.py"
click node_final_emit "https://github.com/fxsjy/jieba/blob/master/jieba/finalseg/prob_emit.py"
click node_paddle_predict "https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/predict.py"
click node_paddle_reader "https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/reader_small.py"
click node_paddle_creator "https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/creator.py"
click node_paddle_network "https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/nets.py"
click node_paddle_weights "https://github.com/fxsjy/jieba/tree/master/jieba/lac_small/model_baseline"
click node_posseg "https://github.com/fxsjy/jieba/blob/master/jieba/posseg/__init__.py"
click node_pos_viterbi "https://github.com/fxsjy/jieba/blob/master/jieba/posseg/viterbi.py"
click node_pos_char "https://github.com/fxsjy/jieba/blob/master/jieba/posseg/char_state_tab.py"
click node_pos_start "https://github.com/fxsjy/jieba/blob/master/jieba/posseg/prob_start.py"
click node_pos_trans "https://github.com/fxsjy/jieba/blob/master/jieba/posseg/prob_trans.py"
click node_pos_emit "https://github.com/fxsjy/jieba/blob/master/jieba/posseg/prob_emit.py"
click node_parallel "https://github.com/fxsjy/jieba/blob/master/jieba/__init__.py"
click node_tokenize "https://github.com/fxsjy/jieba/blob/master/jieba/__init__.py"
click node_tfidf "https://github.com/fxsjy/jieba/blob/master/jieba/analyse/tfidf.py"
click node_textrank "https://github.com/fxsjy/jieba/blob/master/jieba/analyse/textrank.py"
click node_whoosh "https://github.com/fxsjy/jieba/blob/master/jieba/analyse/analyzer.py"
click node_idf_data "https://github.com/fxsjy/jieba/blob/master/jieba/analyse/idf.txt"
click node_compat "https://github.com/fxsjy/jieba/blob/master/jieba/_compat.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_tokenizer,node_lexicon,node_parallel,node_tokenize toneBlue
class node_finalseg,node_final_start,node_final_trans,node_final_emit,node_paddle_predict,node_paddle_reader,node_paddle_creator,node_paddle_network,node_paddle_weights toneAmber
class node_posseg,node_pos_viterbi,node_pos_char,node_pos_start,node_pos_trans,node_pos_emit,node_compat toneMint
class node_tfidf,node_textrank,node_whoosh,node_idf_data toneRose
class node_user toneIndigo
```

## Components

### Segmentation

- [Tokenizer](https://github.com/fxsjy/jieba/blob/master/jieba/__init__.py): `jieba/__init__.py`
- [Main dictionary](https://github.com/fxsjy/jieba/blob/master/jieba/dict.txt): `jieba/dict.txt`
- [Parallel segmentation](https://github.com/fxsjy/jieba/blob/master/jieba/__init__.py): `jieba/__init__.py`
- [Offset tokens](https://github.com/fxsjy/jieba/blob/master/jieba/__init__.py): `jieba/__init__.py`

### Sequence Models

- [HMM segmentation](https://github.com/fxsjy/jieba/blob/master/jieba/finalseg/__init__.py): `jieba/finalseg/__init__.py`
- [HMM start scores](https://github.com/fxsjy/jieba/blob/master/jieba/finalseg/prob_start.py): `jieba/finalseg/prob_start.py`
- [HMM transition scores](https://github.com/fxsjy/jieba/blob/master/jieba/finalseg/prob_trans.py): `jieba/finalseg/prob_trans.py`
- [HMM emission scores](https://github.com/fxsjy/jieba/blob/master/jieba/finalseg/prob_emit.py): `jieba/finalseg/prob_emit.py`
- [Paddle predictor](https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/predict.py): `jieba/lac_small/predict.py`
- [Paddle input reader](https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/reader_small.py): `jieba/lac_small/reader_small.py`
- [Model creator](https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/creator.py): `jieba/lac_small/creator.py`
- [BiGRU CRF network](https://github.com/fxsjy/jieba/blob/master/jieba/lac_small/nets.py): `jieba/lac_small/nets.py`
- [Paddle model weights](https://github.com/fxsjy/jieba/tree/master/jieba/lac_small/model_baseline): `jieba/lac_small/model_baseline`

### Language Features

- [POS tagger](https://github.com/fxsjy/jieba/blob/master/jieba/posseg/__init__.py): `jieba/posseg/__init__.py`
- [POS Viterbi](https://github.com/fxsjy/jieba/blob/master/jieba/posseg/viterbi.py): `jieba/posseg/viterbi.py`
- [Character states](https://github.com/fxsjy/jieba/blob/master/jieba/posseg/char_state_tab.py): `jieba/posseg/char_state_tab.py`
- [POS start scores](https://github.com/fxsjy/jieba/blob/master/jieba/posseg/prob_start.py): `jieba/posseg/prob_start.py`
- [POS transition scores](https://github.com/fxsjy/jieba/blob/master/jieba/posseg/prob_trans.py): `jieba/posseg/prob_trans.py`
- [POS emission scores](https://github.com/fxsjy/jieba/blob/master/jieba/posseg/prob_emit.py): `jieba/posseg/prob_emit.py`
- [Compatibility helpers](https://github.com/fxsjy/jieba/blob/master/jieba/_compat.py): `jieba/_compat.py`

### Text Analysis

- [TF-IDF keywords](https://github.com/fxsjy/jieba/blob/master/jieba/analyse/tfidf.py): `jieba/analyse/tfidf.py`
- [TextRank keywords](https://github.com/fxsjy/jieba/blob/master/jieba/analyse/textrank.py): `jieba/analyse/textrank.py`
- [Whoosh analyzer](https://github.com/fxsjy/jieba/blob/master/jieba/analyse/analyzer.py): `jieba/analyse/analyzer.py`
- [IDF corpus](https://github.com/fxsjy/jieba/blob/master/jieba/analyse/idf.txt): `jieba/analyse/idf.txt`

### Other components

- **Text caller**

## Connections

- Text caller → Tokenizer: submits text (evidence: `README.md`)
- Tokenizer → Main dictionary: uses dictionary (evidence: `README.md`)
- Tokenizer → HMM segmentation: recognizes unknowns (evidence: `jieba/__init__.py`)
- HMM segmentation → HMM start scores: loads scores (evidence: `jieba/finalseg/__init__.py`)
- HMM segmentation → HMM transition scores: loads scores (evidence: `jieba/finalseg/__init__.py`)
- HMM segmentation → HMM emission scores: loads scores (evidence: `jieba/finalseg/__init__.py`)
- Tokenizer → Paddle predictor: dispatches mode (evidence: `jieba/__init__.py`)
- Paddle predictor → Paddle input reader: builds input (evidence: `jieba/lac_small/predict.py`)
- Paddle predictor → Model creator: creates model (evidence: `jieba/lac_small/predict.py`)
- Model creator → BiGRU CRF network: defines network (evidence: `jieba/lac_small/creator.py`)
- Paddle predictor → Paddle model weights: loads checkpoint (evidence: `jieba/lac_small/predict.py`)
- POS tagger → Tokenizer: uses tokenizer (evidence: `jieba/posseg/__init__.py`)
- POS tagger → POS Viterbi: calls (evidence: `jieba/posseg/__init__.py`)
- POS tagger → Character states: loads states (evidence: `jieba/posseg/__init__.py`)
- POS tagger → POS start scores: loads scores (evidence: `jieba/posseg/__init__.py`)
- POS tagger → POS transition scores: loads scores (evidence: `jieba/posseg/__init__.py`)
- POS tagger → POS emission scores: loads scores (evidence: `jieba/posseg/__init__.py`)
- Text caller → Parallel segmentation: requests parallel mode (evidence: `README.md`)
- Text caller → Offset tokens: requests offsets (evidence: `README.md`)
- Text caller → TF-IDF keywords: requests keywords (evidence: `README.md`)
- TF-IDF keywords → Tokenizer: segments text (evidence: `jieba/analyse/tfidf.py`)
- TF-IDF keywords → POS tagger: filters by POS (evidence: `jieba/analyse/tfidf.py`)
- TF-IDF keywords → IDF corpus: loads IDF (evidence: `jieba/analyse/tfidf.py`)
- Text caller → TextRank keywords: requests keywords (evidence: `README.md`)
- TextRank keywords → POS tagger: segments with tags (evidence: `jieba/analyse/textrank.py`)
- Text caller → Whoosh analyzer: uses analyzer (evidence: `README.md`)
- Whoosh analyzer → Offset tokens: requests search tokens (evidence: `jieba/analyse/analyzer.py`)
- Tokenizer → Compatibility helpers: uses helpers (evidence: `jieba/__init__.py`)
