Repository navigation
UCCA Generator Overview
TenzinGayche edited this page Dec 17, 2025
·
1 revision
The UCCA Generator module creates semantic graph representations of Tibetan Buddhist texts using Claude LLMs. It provides two workflow options: a simple single-pass generator and an advanced iterative refinement workflow with commentary-based evaluation.
- Parse Tibetan Buddhist texts into structured semantic graphs
- Capture semantic relationships between concepts, participants, and processes
- Handle implicit content that is understood but not explicitly stated
- Provide English translations at the node level
- Refine graphs using scholarly commentaries (advanced workflow)
Input Text → LLM Generation → JSON Parsing → UCCAGraph
- Single-pass generation
- No evaluation or refinement
- Good for quick processing
┌─────────────────────────────────────┐
│ │
▼ │
┌─────────┐ ┌────────────────┐ ┌────────────────┐ │
│ START │───▶│ ucca_generator │───▶│ ucca_evaluator │──┤
└─────────┘ └────────────────┘ └────────────────┘ │
│ │
┌──────┴──────┐ │
│ route_ucca │ │
└──────┬──────┘ │
│ │
┌─────────────┼─────────────┤
│ │ │
▼ ▼ │
"Accepted" "Rejected" │
│ │ │
▼ └─────────────┘
┌─────┐ (feedback loop)
│ END │
└─────┘
Features:
- Iterative generation-evaluation loop
- Uses scholarly commentaries for evaluation
- Structured feedback with actionable suggestions
- Quality grading (bad/okay/good/great)
- Maximum 1 refinement iteration (configurable)
ucca_generator/
├── __init__.py # Package initialization
├── models.py # Pydantic data models
├── workflow.py # Simple generation workflow
├── ucca_agent.py # Advanced iterative workflow
└── ucca_generator.py # Pipeline entry point
| File | Responsibility |
|---|---|
models.py |
Defines UCCANode, UCCAGraph, State, ActionableSuggestion, StructuredFeedback
|
workflow.py |
generate_ucca_graph_step() - single-pass LLM generation |
ucca_agent.py |
Full LangGraph workflow with generation, evaluation, routing, and prompts |
ucca_generator.py |
run_ucca_generation_pipeline() - main entry point |
- Input: Tibetan text (optionally with English translation)
-
Prompt Construction: Uses
UCCA_GENERATION_PROMPT_TEMPLATEwith schema - LLM Invocation: Claude generates JSON response
- JSON Cleaning: Strips markdown code blocks if present
-
Validation: Parses into
UCCAGraphPydantic model - Output: Validated graph or error message
- Input: Tibetan source text + commentaries + Sanskrit (optional)
-
Initial Generation: Uses
get_ucca_generation_prompt() -
Evaluation: Uses
get_source_ucca_refinement_prompt()with commentaries - Grading: LLM assigns grade (bad/okay/good/great)
-
Routing:
- If "great" or max iterations → Accept
- Otherwise → Generate refined version with feedback
- Refinement: Uses feedback to improve graph
-
Output: Final
UCCAGraphwith feedback history
llm = ChatAnthropic(model="claude-3-sonnet-latest", max_tokens=8192)llm = ChatAnthropic(model="claude-3-7-sonnet-latest", max_tokens=8000)Both workflows use State TypedDict to track progress:
class State(TypedDict):
input_text: str
ucca_graph_json_str: Optional[str]
ucca_graph: Optional[UCCAGraph]
error_message: Optional[str]class State(TypedDict):
source: str # Tibetan source text
sanskrit: str # Sanskrit reference
language: str # Target language
feedback_history: List[str] # All evaluation feedback
commentary1: str # First commentary
commentary2: str # Second commentary
commentary3: str # Third commentary
itteration: int # Current iteration count
format_iteration: int # Format correction iteration
source_ucca: List[UCCAGraph] # History of generated graphs
latest_structured_suggestions: List[ActionableSuggestion]
grade: str # Latest quality gradeThe system recognizes these semantic node types for Tibetan Buddhist texts:
| Type | Description | Example |
|---|---|---|
| Parallel Scenes | Multiple scenes in parallel | Lists of attributes |
| Scene | Self-contained situation | Individual teaching |
| Participant-Agent | Entity performing action | The sage explaining |
| Participant-Patient | Entity receiving action | Concept being analyzed |
| Participant-Location | Where something occurs | Place of meditation |
| Participant-Goal | Purpose or aim | Enlightenment sought |
| Process | Main action or event | Act of meditation |
| State | Condition or situation | State of enlightenment |
| Adverbial | How a process occurs | Manner of practice |
| Linker | Connects scenes/participants | Transition words |
| Relator | Relates two entities | Teacher-student relation |
| Elaborator | Additional information | Commentary on concept |
| Implicit X | Conceptually present but unstated | Implied speaker |
from ucca_generator.ucca_generator import run_ucca_generation_pipeline
result = run_ucca_generation_pipeline("མི་རྟག་པ་སྒོམ་པ།")
if result['ucca_graph']:
for node in result['ucca_graph'].nodes:
print(f"{node.id}: {node.type} - {node.english_text}")from ucca_generator.ucca_agent import optimizer_workflow
initial_state = {
"source": "མི་རྟག་པ་སྒོམ་པ།",
"sanskrit": "",
"language": "Tibetan",
"feedback_history": [],
"commentary1": "First commentary text...",
"commentary2": "Second commentary text...",
"commentary3": "Third commentary text...",
"itteration": 0,
"format_iteration": 0,
"source_ucca": [],
"latest_structured_suggestions": [],
"grade": ""
}
result = optimizer_workflow.invoke(initial_state)
final_graph = result["source_ucca"][-1]- Commentaries are crucial for the advanced workflow - they guide semantic evaluation
- Implicit content should be marked with proper composite tags (e.g., "Implicit Participant-Agent")
- Parent-child relationships must form a valid DAG (no cycles)
-
Root node must have empty string
""forparent_id - All node IDs in children arrays must exist in the nodes list