# fzp0424/self_correct_mt architecture

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

- Interactive diagram: https://gitdiagram.com/fzp0424/self_correct_mt
- Repository: https://github.com/fzp0424/self_correct_mt

## Overview

TEaR is an LLM-based machine-translation self-correction application. Its main workflow accepts source text, generates an initial translation, estimates translation errors, and conditionally refines the result; file mode additionally reads paired datasets and persists segment results. The shared library builds prompts and dispatches requests to supported model providers. Evaluation is a separate capability. The workflow edges are grounded in the shown callers and library; dataset and prompt details not sampled are represented only where those callers explicitly reference them.

Main entry points: [`run_file.py`](https://github.com/fzp0424/self_correct_mt/blob/main/run_file.py) (File input), [`ter_lib.py`](https://github.com/fzp0424/self_correct_mt/blob/main/ter_lib.py) (Translate), [`run_cmd.py`](https://github.com/fzp0424/self_correct_mt/blob/main/run_cmd.py) (Command input), [`demo.py`](https://github.com/fzp0424/self_correct_mt/blob/main/demo.py) (Demo workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry points"]
  node_command_input["Command input<br/>[run_cmd.py]"]
  node_file_input["File input<br/>[run_file.py]"]
  node_demo["Demo workflow<br/>[demo.py]"]
end

subgraph group_workflow["Translation workflow"]
  node_translate["Translate<br/>[ter_lib.py]"]
  node_estimate["Estimate errors<br/>[ter_lib.py]"]
  node_refine["Refine translation<br/>[ter_lib.py]"]
  node_model_dispatch["Model dispatch<br/>[ter_lib.py]"]
end

subgraph group_resources["Prompts and data"]
  node_prompt_templates["Prompt templates"]
  node_few_shot_data["Few-shot examples"]
  node_language_pairs["Language pairs<br/>[language_pair.json]"]
  node_translation_data[("Translation datasets")]
  node_result_output["Result JSON"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation_runner["Evaluation runner<br/>[evaluation.py]"]
  node_evaluation_data["Evaluation samples"]
end

node_user(("User"))
node_model_services{{"LLM providers"}}
node_metric_services{{"Metric models"}}

node_user -->|"enters text"| node_command_input
node_user -->|"starts run"| node_file_input
node_user -->|"runs example"| node_demo
node_command_input -->|"calls"| node_translate
node_command_input -->|"calls"| node_estimate
node_command_input -->|"calls conditionally"| node_refine
node_file_input -->|"calls"| node_translate
node_file_input -->|"calls"| node_estimate
node_file_input -->|"calls conditionally"| node_refine
node_demo -->|"calls"| node_translate
node_demo -->|"calls"| node_estimate
node_demo -->|"calls conditionally"| node_refine
node_translate -->|"requests completion"| node_model_dispatch
node_estimate -->|"requests assessment"| node_model_dispatch
node_refine -->|"requests correction"| node_model_dispatch
node_model_dispatch -->|"invokes provider"| node_model_services
node_translate -->|"loads template"| node_prompt_templates
node_estimate -->|"loads template"| node_prompt_templates
node_refine -->|"loads template"| node_prompt_templates
node_translate -->|"loads examples"| node_few_shot_data
node_command_input -->|"checks pair"| node_language_pairs
node_file_input -->|"selects pair"| node_language_pairs
node_file_input -->|"reads segments"| node_translation_data
node_file_input -->|"appends results"| node_result_output
node_evaluation_runner -->|"reads samples"| node_evaluation_data
node_evaluation_runner -->|"scores translations"| node_metric_services

click node_command_input "https://github.com/fzp0424/self_correct_mt/blob/main/run_cmd.py"
click node_file_input "https://github.com/fzp0424/self_correct_mt/blob/main/run_file.py"
click node_demo "https://github.com/fzp0424/self_correct_mt/blob/main/demo.py"
click node_translate "https://github.com/fzp0424/self_correct_mt/blob/main/ter_lib.py"
click node_estimate "https://github.com/fzp0424/self_correct_mt/blob/main/ter_lib.py"
click node_refine "https://github.com/fzp0424/self_correct_mt/blob/main/ter_lib.py"
click node_model_dispatch "https://github.com/fzp0424/self_correct_mt/blob/main/ter_lib.py"
click node_prompt_templates "https://github.com/fzp0424/self_correct_mt/tree/main/prompts"
click node_few_shot_data "https://github.com/fzp0424/self_correct_mt/tree/main/prompts/data-shots"
click node_language_pairs "https://github.com/fzp0424/self_correct_mt/blob/main/language_pair.json"
click node_translation_data "https://github.com/fzp0424/self_correct_mt/tree/main/dataset/mt"
click node_evaluation_runner "https://github.com/fzp0424/self_correct_mt/blob/main/eval/evaluation.py"
click node_evaluation_data "https://github.com/fzp0424/self_correct_mt/tree/main/eval/zh-en"

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_command_input,node_file_input,node_demo,node_user toneBlue
class node_translate,node_estimate,node_refine,node_model_dispatch toneAmber
class node_prompt_templates,node_few_shot_data,node_language_pairs,node_translation_data,node_result_output toneMint
class node_evaluation_runner,node_evaluation_data toneRose
class node_model_services,node_metric_services toneIndigo
```

## Components

### User entry points

- [Command input](https://github.com/fzp0424/self_correct_mt/blob/main/run_cmd.py): `run_cmd.py`
- [File input](https://github.com/fzp0424/self_correct_mt/blob/main/run_file.py): `run_file.py`
- [Demo workflow](https://github.com/fzp0424/self_correct_mt/blob/main/demo.py): `demo.py`

### Translation workflow

- [Translate](https://github.com/fzp0424/self_correct_mt/blob/main/ter_lib.py): `ter_lib.py`
- [Estimate errors](https://github.com/fzp0424/self_correct_mt/blob/main/ter_lib.py): `ter_lib.py`
- [Refine translation](https://github.com/fzp0424/self_correct_mt/blob/main/ter_lib.py): `ter_lib.py`
- [Model dispatch](https://github.com/fzp0424/self_correct_mt/blob/main/ter_lib.py): `ter_lib.py`

### Prompts and data

- [Prompt templates](https://github.com/fzp0424/self_correct_mt/tree/main/prompts): `prompts`
- [Few-shot examples](https://github.com/fzp0424/self_correct_mt/tree/main/prompts/data-shots): `prompts/data-shots`
- [Language pairs](https://github.com/fzp0424/self_correct_mt/blob/main/language_pair.json): `language_pair.json`
- [Translation datasets](https://github.com/fzp0424/self_correct_mt/tree/main/dataset/mt): `dataset/mt`
- **Result JSON**

### Evaluation

- [Evaluation runner](https://github.com/fzp0424/self_correct_mt/blob/main/eval/evaluation.py): `eval/evaluation.py`
- [Evaluation samples](https://github.com/fzp0424/self_correct_mt/tree/main/eval/zh-en): `eval/zh-en`

### Other components

- **User**
- **LLM providers**
- **Metric models**

## Connections

- User → Command input: enters text (evidence: `run_cmd.py`)
- User → File input: starts run (evidence: `run_file.py`)
- User → Demo workflow: runs example (evidence: `README.md`)
- Command input → Translate: calls (evidence: `run_cmd.py`)
- Command input → Estimate errors: calls (evidence: `run_cmd.py`)
- Command input → Refine translation: calls conditionally (evidence: `run_cmd.py`)
- File input → Translate: calls (evidence: `run_file.py`)
- File input → Estimate errors: calls (evidence: `run_file.py`)
- File input → Refine translation: calls conditionally (evidence: `run_file.py`)
- Demo workflow → Translate: calls (evidence: `demo.py`)
- Demo workflow → Estimate errors: calls (evidence: `demo.py`)
- Demo workflow → Refine translation: calls conditionally (evidence: `demo.py`)
- Translate → Model dispatch: requests completion (evidence: `run_cmd.py`)
- Estimate errors → Model dispatch: requests assessment (evidence: `run_cmd.py`)
- Refine translation → Model dispatch: requests correction (evidence: `run_cmd.py`)
- Model dispatch → LLM providers: invokes provider (evidence: `ter_lib.py`)
- Translate → Prompt templates: loads template (evidence: `ter_lib.py`)
- Estimate errors → Prompt templates: loads template (evidence: `ter_lib.py`)
- Refine translation → Prompt templates: loads template (evidence: `ter_lib.py`)
- Translate → Few-shot examples: loads examples (evidence: `ter_lib.py`)
- Command input → Language pairs: checks pair (evidence: `run_cmd.py`)
- File input → Language pairs: selects pair (evidence: `run_file.py`)
- File input → Translation datasets: reads segments (evidence: `run_file.py`)
- File input → Result JSON: appends results (evidence: `run_file.py`)
- Evaluation runner → Evaluation samples: reads samples (evidence: `eval/evaluation.py`)
- Evaluation runner → Metric models: scores translations (evidence: `eval/evaluation.py`)
