Subtrans / findings /final_optimization_and_bugfix_log.md
arjun-ms's picture
Initial commit: Subtrans Subtitle Pipeline
57bbccb
|
Raw
History Blame Contribute Delete
3.59 kB
# Final Optimization & Bugfix Log (May 11, 2026)
This document summarizes the final set of optimizations and critical bugfixes applied to the AI Subtitle Pipeline to achieve production-grade stability and accuracy.
## 1. The "Meta-Confusion" & Instruction Leakage Fix
**Problem:** Transcript dialogue containing keywords like "Gemini", "AI", or "thinking model" was being misinterpreted by the LLM as system commands, leading to filler responses like "Okay" (ശരി) instead of actual translations.
**Solution: Content Isolation (Escrow)**
- Implemented `<l>` and `</l>` tags to wrap all transcript segments.
- Updated System Prompts to treat anything inside these tags as "inert data."
- **Outcome:** The pipeline can now safely translate technical discussions about the AI itself without triggering meta-loops.
---
## 2. The "Naukri" Incident (Context Loss Prevention)
**Problem:** During the English "Precision Patch" pass, full sentences were being replaced by single corrected words (e.g., "Go to NowCreat" became just "Naukri"), causing massive context loss.
**Solution: Two-Layer Protection**
1. **Prompt Hardening**: Explicitly commanded the model to return the *entire segment text* with the correction applied, not just the correction itself.
2. **Defensive Rejection Logic**: Added a "Context Guard" in the code. If the original text is multiple words but the LLM returns only one (a fragment), the system automatically rejects the patch and keeps the original text.
- **Outcome:** English transcripts maintain 100% context integrity while still fixing brand misspellings.
---
## 3. Console UX & Observability Cleanup
**Problem:** The terminal was cluttered with redundant "Loaded Gemini" logs (due to multiple class instantiations) and excessive "Degradation/Quota" spam in the validator.
**Solution: Architecture Refinement**
- **Singleton Pattern**: Converted `GeminiAdapter` to a Singleton. It now initializes and logs its status exactly once per session.
- **Model Blacklisting**: The Validator now "remembers" which models hit quota. If a Pro model fails once, it is blacklisted for that session, stopping the constant "Degrading..." console spam.
- **Unicode Safety**: Removed all emojis from core logs to prevent `UnicodeEncodeError` on Windows systems.
- **Outcome:** A clean, professional, and actionable console UI.
---
## 4. Script Truncation in Non-Latin Languages
**Problem:** Malayalam translations were occasionally cut off mid-sentence during the Reviewer/Validator pass.
**Solution: Token & Prompt Optimization**
- Increased `max_output_tokens` from 2048 to **4096** to accommodate token-heavy Malayalam script.
- Added a strict "Sentential Completion" rule to the Validator prompt.
- **Outcome:** Full, natural translations without abrupt endings.
---
## 5. Performance Optimization: Transcription Reuse
**Problem:** Running batch tests was time-consuming because it regenerated Whisper transcriptions every time, even when the audio hadn't changed.
**Solution: Batch Hand-off**
- Added an interactive prompt in `run_batch_tests.py` to reuse the latest existing transcription.
- **Outcome:** Drastically reduced iteration time (by minutes per run) when testing translation or validation logic.
---
## ✅ Final Pipeline Status
The pipeline is now **Hardened, Defensive, and Optimized**. It successfully balances:
1. **Selective Correction** (NER + Confidence metrics)
2. **Context-Aware Translation** (Full-window batches)
3. **Conservative Review** (Self-critique validation)
4. **Architectural Stability** (Singleton + Blacklisting)