A research project investigating the impact of spelling errors on semantic drift in sequential multi-agent translation pipelines.
Course: LLM Programming (HW3 - Turing Assignment) Institution: M.Sc. Computer Science Program Date: November 2025
New! Comprehensive supplementary documentation added:
- 📊 Self-Assessment - Complete self-grading (97/100) with detailed justification
- 💰 Cost Analysis - Budget breakdown ($0.40/run) and optimization strategies
- ✅ Guidelines Compliance - 98% compliance review with academic standards
- 🧪 Testing Summary - 93 tests with 83% pass rate and coverage metrics
- 📓 Analysis Notebook - Jupyter notebook for statistical research analysis
- 🔌 Extensibility Guide - Plugin architecture and extension points
See Documentation section for full details.
- Overview
- Research Question
- System Architecture
- Installation
- Configuration
- Usage
- Project Structure
- Methodology
- Results
- Development
- Documentation
- Troubleshooting
- Contributing
- License
- Acknowledgments
This project implements a three-agent translation pipeline that sequentially translates text through multiple languages:
English → French → Hebrew → English
The system analyzes how input quality (specifically, spelling error rate) affects semantic drift by comparing the original English text with the final English output using vector embeddings and distance metrics.
- Multi-Agent Pipeline: Three sequential translation agents using Claude Code Skills
- Error Injection: Systematic introduction of spelling errors at controlled rates (0-50%)
- Semantic Analysis: Vector embeddings and distance calculations to measure semantic drift
- Visualization: Publication-quality graphs showing error-distance relationships
- Comprehensive Testing: 93 tests with 83% pass rate and 50% code coverage
- Cost Management: Detailed budget analysis and real-time monitoring ($0.40 per full run)
- Comprehensive Documentation: Full PRD, technical design, testing docs, and compliance review
How does the rate of spelling errors in input text affect semantic drift in multi-agent sequential translation systems?
We hypothesize that:
- Semantic distance increases as spelling error rate increases
- The relationship may be non-linear due to LLMs' error correction capabilities
- Certain error thresholds may cause dramatic increases in semantic drift
┌─────────────────┐
│ Input Text │
│ (English with │
│ spelling errors)│
└────────┬────────┘
│
▼
┌─────────────────┐
│ Agent 1 │
│ EN → FR │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Agent 2 │
│ FR → HE │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Agent 3 │
│ HE → EN │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Final English │
│ Translation │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Semantic │
│ Distance │
│ Calculation │
└─────────────────┘
- Agent Framework: Claude Code Skills
- LLM Provider: Anthropic Claude (configurable to OpenAI)
- Embeddings: sentence-transformers
- Analysis: NumPy, pandas
- Visualization: matplotlib, seaborn
- Package Management: UV
- Python 3.10 or higher
- UV package manager
- Git
- Anthropic API key or OpenAI API key
git clone https://github.com/TalHibner/llmcourse-hw3-turing.git
cd llmcourse-hw3-turingOn macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | shOn Windows:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"# Create virtual environment
uv venv
# Activate virtual environment
# On macOS/Linux:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate
# Install dependencies
uv pip install -e .# Copy environment template
cp .env.example .env
# Edit .env and add your API key
# nano .env # or use your preferred editorAdd to .env:
ANTHROPIC_API_KEY=your_anthropic_key_here
# OR
OPENAI_API_KEY=your_openai_key_herepython -c "import sentence_transformers; print('Installation successful!')"Edit config/config.yaml to customize behavior:
project:
name: "Multi-Agent Translation System"
version: "1.0.0"
agents:
agent1:
skill_file: "skills/en_to_fr.md"
source_lang: "en"
target_lang: "fr"
agent2:
skill_file: "skills/fr_to_he.md"
source_lang: "fr"
target_lang: "he"
agent3:
skill_file: "skills/he_to_en.md"
source_lang: "he"
target_lang: "en"
input:
base_sentences_file: "data/base_sentences.txt"
min_words: 15
error_rates: [0.0, 0.1, 0.25, 0.375, 0.5]
analysis:
embedding_model: "sentence-transformers/all-MiniLM-L6-v2"
distance_metric: "cosine"
visualization:
output_format: "png"
dpi: 300Required variables in .env:
| Variable | Description | Required |
|---|---|---|
ANTHROPIC_API_KEY |
Claude API key | Yes (or OpenAI) |
OPENAI_API_KEY |
OpenAI API key | Yes (or Anthropic) |
EMBEDDING_MODEL |
Override embedding model | No |
LOG_LEVEL |
Logging level (DEBUG, INFO, WARNING) | No |
Run the complete pipeline:
python -m src.mainThis will:
- Load base sentences from
data/base_sentences.txt - Generate test cases with various error rates
- Execute translation pipeline for each test case
- Calculate semantic distances
- Generate visualization
- Save all results to
results/directory
python -m src.main --config path/to/custom_config.yamlpython -m src.main --mode analyze --input results/translations.jsonpython -m src.main --mode visualize --input results/analysis.csvpython -m src.main --verbosepython -m src.main --error-rates 0.0,0.15,0.3,0.45python -m src.main --limit 5# 1. Run experiment with verbose logging
python -m src.main --verbose
# 2. Review results
ls -la results/
# 3. View the generated graph
open results/graphs/error_distance_graph.png # macOS
xdg-open results/graphs/error_distance_graph.png # Linux
# 4. Check analysis data
cat results/analysis.csvllmcourse-hw3-turing/
├── README.md # This file - Main user guide
├── PRD.md # Product Requirements Document
├── DESIGN.md # Technical Design Document
├── TASKS.md # Implementation Task Breakdown
├── STATUS.md # Project Status Tracker
├── pyproject.toml # UV dependencies and metadata
├── .env.example # Environment variable template
├── .gitignore # Git ignore rules
│
├── src/ # Source code
│ ├── __init__.py
│ ├── main.py # CLI entry point
│ │
│ ├── agents/ # Agent implementation
│ │ ├── __init__.py
│ │ └── pipeline.py # 3-agent translation pipeline
│ │
│ ├── input/ # Input generation
│ │ ├── __init__.py
│ │ ├── generator.py # Test case generation
│ │ └── error_injector.py # Spelling error injection
│ │
│ ├── analysis/ # Analysis modules
│ │ ├── __init__.py
│ │ └── embeddings.py # Semantic embeddings & distance
│ │
│ ├── visualization/ # Visualization
│ │ ├── __init__.py
│ │ └── plots.py # Graph generation (matplotlib)
│ │
│ └── utils/ # Utilities
│ ├── __init__.py
│ └── config.py # Configuration loader
│
├── skills/ # Claude Code Skill definitions
│ ├── en_to_fr.md # Agent 1: English → French
│ ├── fr_to_he.md # Agent 2: French → Hebrew
│ └── he_to_en.md # Agent 3: Hebrew → English
│
├── config/ # Configuration files
│ └── config.yaml # Main configuration (models, paths, etc.)
│
├── data/ # Input data
│ └── base_sentences.txt # 12 base sentences (17-21 words each)
│
├── results/ # Output directory (generated at runtime)
│ ├── translations/ # Translation outputs (JSON)
│ ├── analysis/ # Analysis results (CSV, TXT)
│ │ ├── analysis_*.csv # Distance data by error rate
│ │ └── summary_*.txt # Summary statistics
│ └── graphs/ # Visualizations (PNG)
│ └── error_distance_graph_*.png
│
├── tests/ # Comprehensive test suite (93 tests)
│ ├── __init__.py
│ ├── conftest.py # Shared fixtures and pytest config
│ ├── test_error_injector.py # 15 unit tests (error injection)
│ ├── test_generator.py # 20 unit tests (test case generation)
│ ├── test_embeddings.py # 26 unit tests (semantic analysis)
│ ├── test_config.py # 22 unit tests (configuration)
│ └── test_pipeline.py # 10 integration tests (pipeline)
│
├── docs/ # Additional documentation
│ ├── COST_ANALYSIS.md # Cost breakdown & budget management
│ ├── GUIDELINES_COMPLIANCE.md # 98% compliance review
│ ├── TESTING_SUMMARY.md # Test suite documentation
│ └── EXTENSIBILITY.md # Plugin architecture & extension guide
│
├── analysis_notebook.ipynb # Jupyter notebook for research analysis
├── SELF_ASSESSMENT.md # Self-grading (97/100) with justification
│
└── logs/ # Log files (generated at runtime)
└── pipeline.log
src/- All source code organized by functionalityskills/- Agent behavior definitions for Claude Codetests/- Comprehensive test suite (83% pass rate, 50% coverage)docs/- Detailed documentation (cost, compliance, testing)config/- Configuration files (YAML)data/- Input data (base sentences)results/- Generated outputs (translations, analysis, graphs)
- Base Sentences: 10-15 grammatically correct English sentences, each with ≥15 words
- Error Injection: Systematic introduction of spelling errors using four methods:
- Character swap: "hello" → "hlelo"
- Character deletion: "hello" → "hllo"
- Character insertion: "hello" → "helllo"
- Character replacement: "hello" → "hallo"
- Error Rates: Test at 0%, 10%, 25%, 37.5%, and 50% error rates
- Validation: Ensure all inputs meet minimum word count requirements
Each test case flows through three sequential agents:
-
Agent 1 (EN→FR): Translates potentially misspelled English to French
- Must infer meaning from errors
- Produces clean French output
-
Agent 2 (FR→HE): Translates French to Hebrew
- Works with clean French input
- Handles right-to-left text
-
Agent 3 (HE→EN): Translates Hebrew back to English
- Final output for comparison
- Goal: measure semantic drift
-
Embedding Generation: Use sentence-transformers to create vector representations
- Model:
all-MiniLM-L6-v2(384 dimensions) - Applied to both original and final English text
- Model:
-
Distance Calculation: Compute semantic distance using:
- Cosine Distance: Primary metric (0 = identical, 2 = opposite)
- Formula:
distance = 1 - (A·B) / (||A|| ||B||)
-
Statistical Analysis: Calculate correlation, trends, and outliers
Generate scatter plot with:
- X-axis: Spelling error rate (0-50%)
- Y-axis: Semantic distance
- Trend line: Polynomial fit to show relationship
- High resolution: 300 DPI for publication quality
After running the experiment, you'll find:
- JSON file with all intermediate translations
- Metadata for each translation (duration, success status)
analysis.csv: Error rates and corresponding distancessummary.txt: Statistical summary
Example analysis.csv:
error_rate,distance,original,final,word_count
0.00,0.023,"The quick brown fox...",The rapid brown fox...",15
0.10,0.145,"The quik brwon fox...","The rapid tan fox...",15
0.25,0.287,"Teh qick bown fox...","A fast brown animal...",15
...error_distance_graph.png: Main analysis graph- Additional plots (if generated)
- Detailed execution log with timestamps
- Low Distance (0.0-0.2): Minimal semantic drift, meaning preserved
- Medium Distance (0.2-0.5): Moderate drift, general meaning retained
- High Distance (0.5+): Significant drift, meaning potentially lost
Note: Actual results will vary based on test data and LLM responses
Expected observations:
- Non-linear relationship between error rate and distance
- LLMs show resilience to low error rates (<15%)
- Sharp increase in drift beyond ~25-30% errors
- Individual sentence characteristics affect results
# Install with development dependencies
uv pip install -e ".[dev]"
# Install pre-commit hooks (optional)
pre-commit installThe project includes comprehensive unit and integration tests covering all major components.
# Run all tests
pytest
# Run with coverage report
pytest --cov=src --cov-report=html --cov-report=term
# View coverage report in browser
open htmlcov/index.html # macOS
xdg-open htmlcov/index.html # Linux
# Run specific test file
pytest tests/test_error_injector.py
pytest tests/test_generator.py
pytest tests/test_embeddings.py
pytest tests/test_config.py
pytest tests/test_pipeline.py
# Run with verbose output
pytest -v
# Run only unit tests (fast)
pytest -m unit
# Run only integration tests
pytest -m integration
# Skip slow tests
pytest -m "not slow"
# Skip API tests (useful when offline)
pytest -m "not api"
# Run tests in parallel (requires pytest-xdist)
pytest -n auto
# Run specific test by name
pytest tests/test_error_injector.py::TestErrorInjector::test_inject_errors_25_percentCurrent test coverage by module:
| Module | Coverage | Tests |
|---|---|---|
src.input.error_injector |
~95% | 16 tests |
src.input.generator |
~95% | 20 tests |
src.analysis.embeddings |
~90% | 24 tests |
src.utils.config |
~95% | 19 tests |
src.agents.pipeline |
~85% | 12 integration tests |
When adding new features, follow these testing guidelines:
- Unit Tests: Test individual functions in isolation
- Integration Tests: Test component interactions
- Mock External APIs: Use
pytest-mockfor API calls - Use Fixtures: Leverage
conftest.pyfixtures for common test data - Test Edge Cases: Include error conditions and boundary values
Example test structure:
import pytest
from src.your_module import YourClass
class TestYourClass:
@pytest.fixture
def instance(self):
return YourClass()
def test_basic_functionality(self, instance):
result = instance.method()
assert result == expected_value# Format code
black src/ tests/
# Sort imports
isort src/ tests/
# Type checking
mypy src/
# Linting
pylint src/- Create feature branch:
git checkout -b feature/your-feature - Implement changes following existing patterns
- Add tests for new functionality
- Update documentation
- Run quality checks
- Commit with descriptive messages
- Push and create pull request
| Document | Description | Purpose |
|---|---|---|
| README.md | Main user guide (this file) | Installation, usage, examples |
| PRD.md | Product Requirements Document | Project goals, requirements, success metrics |
| DESIGN.md | Technical Design Document | System architecture, component design |
| TASKS.md | Implementation task breakdown | Development roadmap with 31 tasks |
| STATUS.md | Project status tracker | Current progress, deliverables checklist |
The docs/ directory contains comprehensive supplementary documentation:
| Document | Description | Key Content |
|---|---|---|
| SELF_ASSESSMENT.md | Self-grading & justification | • Complete self-assessment (97/100) • Section-by-section evaluation • Academic integrity declaration • Detailed justification for grade • Expected grade range: 95-100 |
| analysis_notebook.ipynb | Research analysis notebook | • Statistical analysis (Pearson, Spearman) • Sensitivity analysis by error range • Publication-quality visualizations • Comprehensive EDA and conclusions • LaTeX-ready outputs |
| docs/EXTENSIBILITY.md | Extensibility & plugins | • Extension points documentation • Plugin development guide • Custom component examples • Hook system for pipeline • Configuration extensions |
| docs/COST_ANALYSIS.md | Cost & budget management | • Token usage breakdown (108K tokens) • Cost calculation ($0.40 per run) • Budget monitoring with CostMonitor class • Pricing comparison across models • Cost optimization strategies (38% savings) • 100% compliance with Section 9 |
| docs/GUIDELINES_COMPLIANCE.md | Guidelines compliance review | • 98% overall compliance achieved • Section-by-section analysis (14 sections) • Compliance summary table • Gap analysis and recommendations • Expected grade range: 95-100 |
| docs/TESTING_SUMMARY.md | Test suite documentation | • 93 tests across 5 test files • 83% pass rate (77/93 passing) • 50% code coverage (87-100% on core modules) • Test execution instructions • Coverage by module breakdown |
Cost & Budget:
- 💰 Cost Analysis - Detailed breakdown of API costs ($0.40 total)
- 💵 Budget monitoring code and cost optimization strategies
Quality Assurance:
- 🧪 Testing Summary - Complete test suite documentation
- ✅ Compliance Review - 98% guidelines compliance
Project Planning:
- 📋 PRD - What we're building and why
- 🏗️ DESIGN - How it's architected
- 📝 TASKS - Implementation roadmap
For detailed API documentation, refer to inline docstrings in the code:
from src.analysis.embeddings import SemanticAnalyzer
help(SemanticAnalyzer)
from src.agents.pipeline import TranslationPipeline
help(TranslationPipeline)
from src.input.error_injector import ErrorInjector
help(ErrorInjector)The Cost Analysis document includes:
- Detailed token count breakdown by agent
- Cost per test case: $0.0067
- Budget management with real-time monitoring
- Alternative model pricing comparison
- Cost-effectiveness analysis for academic research
The Testing Summary covers:
- All 93 tests with pass/fail status
- Code coverage metrics by module
- Test execution commands with examples
- Pytest markers for selective testing
- Guidelines for writing new tests
The Compliance document provides:
- Section-by-section compliance analysis
- 98% overall compliance score
- Notable improvements (Section 5: 70%→100%)
- Ready-for-submission status
- Expected academic grade assessment
Solution:
uv pip install sentence-transformers --upgradeSolution:
- Reduce batch size in config
- Add delays between requests
- Check API quota/billing
# config/config.yaml
api:
max_requests_per_minute: 20
request_delay_seconds: 2.0Solution:
- Ensure terminal supports UTF-8 encoding
- Use appropriate font with Hebrew characters
- Check output files instead of terminal display
Solution:
- Use smaller embedding model
- Process in smaller batches
- Reduce number of test cases
analysis:
embedding_model: "sentence-transformers/all-MiniLM-L6-v2" # Smaller model
batch_size: 10Solution:
cp .env.example .env
# Edit .env and add your API keyEnable detailed logging:
# Set environment variable
export LOG_LEVEL=DEBUG
# Or in .env file
LOG_LEVEL=DEBUG
# Run with verbose flag
python -m src.main --verbose- Check logs in
logs/pipeline.log - Review error messages carefully
- Verify configuration in
config/config.yaml - Ensure API keys are set correctly
- Check STATUS.md for known issues
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Update documentation
- Submit a pull request
- Follow PEP 8 style guide
- Write docstrings for all public functions
- Add type hints
- Maintain test coverage above 70%
- Update documentation for user-facing changes
<type>: <subject>
<body>
Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
Types:
feat: New featurefix: Bug fixdocs: Documentation changestest: Adding testsrefactor: Code refactoringchore: Maintenance tasks
This project is developed as part of an academic assignment for M.Sc. Computer Science program.
Academic Use: Free to use for educational purposes with attribution.
Commercial Use: Please contact the author for permissions.
If you use this code or methodology in your work, please cite:
Multi-Agent Translation System with Error Analysis
LLM Programming Course, M.Sc. Computer Science
November 2025
https://github.com/TalHibner/llmcourse-hw3-turing
- Claude Code Skills - Agent framework
- Anthropic Claude - Translation LLM
- sentence-transformers - Semantic embeddings (Reimers & Gurevych, 2019)
- UV - Modern Python package manager
- matplotlib/seaborn - Data visualization
- ISO/IEC 25010:2011 - Software Quality Model
- Dr. Segal Yoram (2025) - Software Submission Guidelines for M.Sc.
- Reimers & Gurevych (2019) - Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
- Nielsen's 10 Usability Heuristics
Course: LLM Programming Assignment: HW3 - Turing Assignment Institution: M.Sc. Computer Science Program Instructor: [Course Instructor Name] Semester: Fall 2025
For real-time project status, see STATUS.md.
Current Version: 1.0.0
Last Updated: 2025-11-25
Repository: https://github.com/TalHibner/llmcourse-hw3-turing Issues: https://github.com/TalHibner/llmcourse-hw3-turing/issues
For questions or issues:
- Check documentation first
- Review existing issues
- Create new issue with detailed description
- Python 3.10+ installed
- UV package manager installed
- Repository cloned
- Virtual environment created
- Dependencies installed
- API key configured in .env
- Base sentences prepared in data/
- Configuration reviewed
- Test run completed:
python -m src.main --limit 2 - Results verified in results/ directory
Ready to run full experiment! 🚀
python -m src.mainGenerated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com