Repository navigation
Tibetan Translator V2
TenzinGayche edited this page Dec 17, 2025
·
1 revision
The tibetan_translator_v2 module provides a semantic-analysis-driven translation pipeline that uses pre-processed UCCA graphs, word-by-word translations, and multi-level summaries.
This version uses pre-computed semantic analysis instead of raw commentaries:
- Loads UCCA graph analysis
- Loads word-by-word translations
- Loads multi-level summaries
- Combines into unified interpretation
- Generates translation based on combined analysis
- Evaluates and refines iteratively
- Extracts glossary terms
V2 depends on outputs from other modules:
┌─────────────────────┐ ┌─────────────────────┐
│ ucca_generator │ │ word_by_word_ │
│ │ │ generator │
│ Generates UCCA │ │ │
│ semantic graphs │ │ Generates word-by- │
│ │ │ word translations │
└─────────┬───────────┘ └─────────┬───────────┘
│ │
│ │
▼ ▼
┌─────────────────────────────────────────────────┐
│ tibetan_translator_v2 │
│ │
│ Uses pre-processed semantic data for │
│ translation │
└─────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ tibetan_translator_v2 Workflow │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────┐ │
│ │ START │ │
│ └────┬────┘ │
│ │ │
│ ┌─────────────────────────┼─────────────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ process_ │ │ process_ │ │ process_ │ │
│ │ ucca │ │ word_by_word │ │ multilevel_ │ │
│ │ │ │ │ │ summary │ │
│ │ Loads UCCA │ │ Loads word- │ │ │ │
│ │ graph data │ │ by-word │ │ Loads multi- │ │
│ │ │ │ translation │ │ level summary│ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └─────────────────────────┼─────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ aggregator │ │
│ │ │ │
│ │ Combines UCCA + │ │
│ │ word-by-word + │ │
│ │ summary │ │
│ └────────┬────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────┐ │
│ │ translation_generator │◄────────────┐ │
│ └────────────┬─────────────┘ │ │
│ │ │ │
│ ▼ │ │
│ ┌──────────────────────────┐ │ │
│ │ llm_call_evaluator │ │ │
│ └────────────┬─────────────┘ │ │
│ │ │ │
│ ┌──────┴──────┐ │ │
│ │ route_ │ │ │
│ │ translation │ │ │
│ └──────┬──────┘ │ │
│ │ │ │
│ ┌─────────────────┼─────────────────┐ │ │
│ │ │ │ │ │
│ ▼ ▼ │ │ │
│ "Accepted" "Rejected + Feedback"───┴─────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ generate_ │ │
│ │ glossary │ │
│ └────────┬────────┘ │
│ │ │
│ ▼ │
│ ┌───────┐ │
│ │ END │ │
│ └───────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
tibetan_translator_v2/
├── __init__.py # Package exports
├── cli.py # Command-line interface
├── config.py # Configuration
├── models.py # Pydantic models (extended State)
├── prompts.py # Prompt templates
├── utils.py # Utilities and LLM setup
├── workflow.py # LangGraph workflow definition
└── processors/
├── __init__.py
├── commentary.py # Semantic data loaders (UCCA, word-by-word, summary)
├── translation.py # Translation generation
├── evaluation.py # Quality evaluation
├── formatting.py # Format checking
├── glossary.py # Glossary extraction
└── post_translation.py
Note: V2 is missing llm_provider.py that exists in V1.
Three parallel nodes load pre-processed data:
def process_ucca(state: State):
"""Loads the UCCA data into the state for the aggregator."""
return {"ucca": state.get("ucca", "")}
def process_word_by_word(state: State):
"""Loads the word-by-word translation into the state for the aggregator."""
return {"word_by_word": state.get("word_by_word", "")}
def process_multilevel_summary(state: State):
"""Loads the multi-level summary into the state for the aggregator."""
return {"multilevel_summary": state.get("multilevel_summary", "")}Combines semantic analysis data:
def aggregator(state: State):
"""Combine UCCA, word-by-word, and summary into a new commentary."""
# Combine the new inputs into a single string
combined_inputs = (
f"UCCA Analysis:\n{state.get('ucca', 'Not available.')}\n\n"
f"Word-by-Word Translation:\n{state.get('word_by_word', 'Not available.')}\n\n"
f"Multi-Level Summary:\n{state.get('multilevel_summary', 'Not available.')}\n\n"
)
language = state.get('language', 'English')
# Create the prompt for combining the inputs
prompt_messages = get_combined_commentary_prompt(
source_text=state['source'],
commentaries=combined_inputs,
has_commentaries=True,
language=language
)
# Use the thinking LLM for analysis
response = llm_thinking.invoke(prompt_messages)
# Extract content from response
commentary_content = ""
if hasattr(response, 'content'):
if isinstance(response.content, list) and len(response.content) > 1:
commentary_content = response.content[1].get('text', '')
else:
commentary_content = str(response.content)
else:
commentary_content = str(response)
return {"combined_commentary": commentary_content}These are identical to V1 - they use the same prompts and logic.
V2 extends the V1 State with additional semantic fields:
class State(TypedDict):
# === Same as V1 ===
translation: List[str]
plaintext_translation: str
source: str
sanskrit: str
language: str
feedback_history: List[str]
format_feedback_history: List[str]
combined_commentary: str
key_points: List[KeyPoint]
glossary: List[GlossaryEntry]
itteration: int
format_iteration: int
formated: bool
# Legacy fields (present but not used in workflow)
commentary1: str
commentary2: str
commentary3: str
commentary1_translation: str
commentary2_translation: str
commentary3_translation: str
# === V2 NEW FIELDS ===
ucca: str # UCCA graph analysis
word_by_word: str # Word-by-word translation
multilevel_summary: str # Multi-level summaryBefore using V2, you need to generate semantic data:
# Step 1: Generate UCCA graph
from ucca_generator.ucca_generator import run_ucca_generation_pipeline
ucca_result = run_ucca_generation_pipeline(tibetan_text)
ucca_data = ucca_result['ucca_graph'].model_dump_json()
# Step 2: Generate word-by-word translation
# (using word_by_word_generator)
# Step 3: Generate multi-level summary
# (using your summary generator)from tibetan_translator_v2 import optimizer_workflow
# Prepare initial state with semantic data
state = {
"source": "བོད་ཀྱི་བསྡུད་མ་འདུག",
"sanskrit": "Buddhist text in Sanskrit",
"language": "English",
# V2-specific inputs
"ucca": """
UCCA Graph (Root ID: 0)
|- [0] Type: Scene - "བོད་ཀྱི་བསྡུད་མ་འདུག"
|- [1] Type: Participant-Location - "བོད"
|- [2] Type: State - "བསྡུད་མ་འདུག"
""",
"word_by_word": """
བོད = Tibet
ཀྱི = of (genitive particle)
བསྡུད = suffering
མ = not
འདུག = exists
""",
"multilevel_summary": """
Literal: In Tibet, there is no suffering.
Philosophical: A statement about the nature of existence in Tibet.
Contextual: This may refer to the enlightened state achieved through practice.
""",
# Standard fields
"feedback_history": [],
"format_feedback_history": [],
"itteration": 0,
"format_iteration": 0,
"formated": False,
"glossary": [],
"translation": [],
"key_points": [],
"combined_commentary": "",
"plaintext_translation": "",
# Legacy fields (can be empty)
"commentary1": "",
"commentary2": "",
"commentary3": "",
"commentary1_translation": "",
"commentary2_translation": "",
"commentary3_translation": "",
}
# Run workflow
result = optimizer_workflow.invoke(state)
# Access results
final_translation = result["translation"][-1]
print(f"Translation: {final_translation}"){
"source": "Tibetan root text",
"sanskrit": "Corresponding Sanskrit text",
"language": "English",
"ucca": "UCCA graph analysis (from ucca_generator)",
"word_by_word": "Word-by-word translation",
"multilevel_summary": "Multi-level summary"
}Same as V1:
{
"translation": ["Final English translation"],
"combined_commentary": "Unified semantic analysis",
"glossary": [
{
"tibetan_term": "བྱང་ཆུབ་སེམས",
"translation": "bodhicitta",
"context": "The mind of enlightenment",
"category": "philosophical"
}
],
"plaintext_translation": "Plain text version"
}Complete example using all generators:
# Full semantic pipeline
# 1. Source text
tibetan_text = "མི་རྟག་པ་སྒོམ་པ་ལ་དགོས་པ་ཅི་ཡོད།"
sanskrit_text = "अनित्यता भावना"
# 2. Generate UCCA analysis
from ucca_generator.ucca_generator import run_ucca_generation_pipeline
ucca_result = run_ucca_generation_pipeline(tibetan_text)
ucca_text = format_ucca_for_translation(ucca_result['ucca_graph'])
# 3. Generate word-by-word (assuming you have this)
word_by_word = generate_word_by_word(tibetan_text)
# 4. Generate multi-level summary (assuming you have this)
summary = generate_multilevel_summary(tibetan_text)
# 5. Run translation with V2
from tibetan_translator_v2 import optimizer_workflow
state = {
"source": tibetan_text,
"sanskrit": sanskrit_text,
"language": "English",
"ucca": ucca_text,
"word_by_word": word_by_word,
"multilevel_summary": summary,
# ... other fields ...
}
result = optimizer_workflow.invoke(state)
print(result["translation"][-1])Use V2 when:
- ✅ You have access to UCCA graph generation
- ✅ Word-by-word translations are available
- ✅ Multi-level summaries have been prepared
- ✅ Need fine-grained semantic analysis
- ✅ Working with texts that lack traditional commentaries
- ✅ Building an automated semantic pipeline
- Pre-processing Required: Unlike V1, V2 requires pre-generated semantic data
- UCCA Format: The UCCA data should be formatted as readable text, not raw JSON
- Legacy Fields: Commentary fields are present for compatibility but not used
- Same Evaluation: Translation evaluation and refinement work identically to V1
- Tibetan-Translator-Comparison - V1 vs V2 differences
- Tibetan-Translator-V1 - V1 documentation
- UCCA-Generator-Overview - UCCA graph generation
- Translator-Prompts - Prompt templates