help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
language-translation
/
examples
RSK World
language-translation
Language Translation Dataset - Machine Translation + Multilingual NLP + Parallel Corpus + Transformers
examples
  • __pycache__
  • example_usage.py3.8 KB
example_usage.py
examples/example_usage.py
Raw Download
Find: Go to:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Language Translation Dataset - Example Usage
Author: RSK World
Website: https://rskworld.in
Email: help@rskworld.in
Phone: +91 93305 39277
Copyright © 2016 RSK World. All rights reserved.

Example script showing how to use the Language Translation Dataset.
"""

import sys
from pathlib import Path

# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))

import pandas as pd
import json
from config import *

def example_load_tsv():
    """Example: Load and display TSV data."""
    print("=" * 60)
    print("Example 1: Loading TSV Data")
    print("=" * 60)
    
    if TRAIN_FILE_TSV.exists():
        df = pd.read_csv(TRAIN_FILE_TSV, sep='\t', encoding='utf-8')
        print(f"\nLoaded {len(df)} rows from {TRAIN_FILE_TSV.name}")
        print(f"\nColumns: {', '.join(df.columns)}")
        print(f"\nFirst 3 rows:")
        print(df.head(3).to_string())
    else:
        print(f"File not found: {TRAIN_FILE_TSV}")

def example_load_json():
    """Example: Load and display JSON data."""
    print("\n" + "=" * 60)
    print("Example 2: Loading JSON Data")
    print("=" * 60)
    
    if TRAIN_FILE_JSON.exists():
        with open(TRAIN_FILE_JSON, 'r', encoding='utf-8') as f:
            data = json.load(f)
        
        print(f"\nLoaded {len(data)} records from {TRAIN_FILE_JSON.name}")
        print(f"\nKeys: {', '.join(data[0].keys())}")
        print(f"\nFirst record:")
        print(json.dumps(data[0], indent=2, ensure_ascii=False))
    else:
        print(f"File not found: {TRAIN_FILE_JSON}")

def example_translate_pair():
    """Example: Display translation pairs."""
    print("\n" + "=" * 60)
    print("Example 3: Translation Pairs")
    print("=" * 60)
    
    if TRAIN_FILE_JSON.exists():
        with open(TRAIN_FILE_JSON, 'r', encoding='utf-8') as f:
            data = json.load(f)
        
        print(f"\nSample translation pairs:\n")
        for i, record in enumerate(data[:3], 1):
            print(f"Pair {i}:")
            print(f"  English: {record.get('english', 'N/A')}")
            print(f"  Spanish: {record.get('spanish', 'N/A')}")
            print(f"  French: {record.get('french', 'N/A')}")
            print(f"  German: {record.get('german', 'N/A')}")
            print()
    else:
        print(f"File not found: {TRAIN_FILE_JSON}")

def example_statistics():
    """Example: Calculate basic statistics."""
    print("\n" + "=" * 60)
    print("Example 4: Dataset Statistics")
    print("=" * 60)
    
    if TRAIN_FILE_TSV.exists():
        df = pd.read_csv(TRAIN_FILE_TSV, sep='\t', encoding='utf-8')
        
        print(f"\nDataset Statistics:")
        print(f"  Total rows: {len(df)}")
        print(f"  Total columns: {len(df.columns)}")
        
        for lang in LANGUAGES:
            if lang in df.columns:
                sentences = df[lang].dropna()
                avg_length = sentences.str.len().mean()
                print(f"\n  {lang.capitalize()}:")
                print(f"    Sentences: {len(sentences)}")
                print(f"    Avg length: {avg_length:.2f} characters")
    else:
        print(f"File not found: {TRAIN_FILE_TSV}")

def main():
    """Run all examples."""
    print("=" * 60)
    print("Language Translation Dataset - Example Usage")
    print(f"Author: {PROJECT_AUTHOR} ({PROJECT_WEBSITE})")
    print("=" * 60)
    
    example_load_tsv()
    example_load_json()
    example_translate_pair()
    example_statistics()
    
    print("\n" + "=" * 60)
    print("Examples complete!")
    print("=" * 60)
    print(f"\nFor more information, visit: {PROJECT_WEBSITE}")
    print(f"Contact: {PROJECT_EMAIL} | {PROJECT_PHONE}")

if __name__ == '__main__':
    main()

121 lines•3.8 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer