{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-14T04:48:48.977933Z",
     "start_time": "2025-05-14T04:48:46.713213Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import sacrebleu\n",
    "import nltk\n",
    "from nltk.translate.meteor_score import meteor_score\n",
    "import jiwer\n",
    "import re"
   ],
   "id": "f51c4fcb0b983ca8",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-14T04:48:51.402584Z",
     "start_time": "2025-05-14T04:48:51.378988Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def preprocess_text(text):\n",
    "    text = text.strip().lower()\n",
    "    text = re.sub(r'[^\\w\\s\\u0900-\\u097F]', '', text)  # keep Devanagari + Dogri\n",
    "    text = re.sub(r'\\s+', ' ', text)\n",
    "    return text\n",
    "\n",
    "def evaluate_mt_scores(reference_file, hypothesis_file, output_file):\n",
    "    # Load files\n",
    "    with open(hypothesis_file, 'r', encoding='utf-8') as f:\n",
    "        hypotheses = [line.strip() for line in f if line.strip()]\n",
    "\n",
    "    with open(reference_file, 'r', encoding='utf-8') as f:\n",
    "        references = [line.strip() for line in f if line.strip()]\n",
    "\n",
    "    # Ensure same number of lines\n",
    "    assert len(hypotheses) == len(references), \"Mismatch in number of lines.\"\n",
    "\n",
    "    # BLEU and TER\n",
    "    bleu = sacrebleu.metrics.BLEU()\n",
    "    bleu_score = bleu.corpus_score(hypotheses, [references])\n",
    "\n",
    "    ter = sacrebleu.metrics.TER()\n",
    "    ter_score = ter.corpus_score(hypotheses, [references])\n",
    "\n",
    "    # METEOR\n",
    "    meteor_scores = [\n",
    "        meteor_score([ref.split()], hyp.split())\n",
    "        for ref, hyp in zip(references, hypotheses)\n",
    "    ]\n",
    "    avg_meteor = sum(meteor_scores) / len(meteor_scores)\n",
    "\n",
    "    # WER — Clean + score sentence-by-sentence\n",
    "    wer_scores = []\n",
    "    for ref, hyp in zip(references, hypotheses):\n",
    "        ref_clean = preprocess_text(ref)\n",
    "        hyp_clean = preprocess_text(hyp)\n",
    "        if ref_clean and hyp_clean:\n",
    "            wer_score = jiwer.wer(ref_clean, hyp_clean)\n",
    "            wer_scores.append(wer_score)\n",
    "\n",
    "    avg_wer = sum(wer_scores) / len(wer_scores) if wer_scores else 0.0\n",
    "\n",
    "    # Print nicely formatted output\n",
    "    print(bleu_score.format())\n",
    "    print(ter_score.format())\n",
    "    print(\"METEOR = {:.2f}\".format(avg_meteor * 100))\n",
    "    print(\"WER = {:.2f}%\".format(avg_wer * 100))\n",
    "\n",
    "    # Save to file\n",
    "    with open(output_file, 'w', encoding='utf-8') as out:\n",
    "        out.write(bleu_score.format() + \"\\n\")\n",
    "        out.write(ter_score.format() + \"\\n\")\n",
    "        out.write(\"METEOR = {:.2f}\\n\".format(avg_meteor * 100))\n",
    "        out.write(\"WER = {:.2f}%\\n\".format(avg_wer * 100))\n",
    "\n",
    "    print(f\"Scores written to: {output_file}\\n\")"
   ],
   "id": "45a3453af14417c5",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-14T05:00:29.186285Z",
     "start_time": "2025-05-14T05:00:20.509713Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Evaluate the RBMTS Output Results\n",
    "# For Small Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\RBMTS\\\\testRefSmall.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\RBMTS\\\\testPredSmall1_Aftr.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\RBMTS\\\\MT_Scores_Small.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "# For Medium Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\RBMTS\\\\testRefMedium.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\RBMTS\\\\testPredMedium1_Aftr.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\RBMTS\\\\MT_Scores_Medium.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "# For Large Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\RBMTS\\\\testRefLarge.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\RBMTS\\\\testPredLarge1_Aftr.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\RBMTS\\\\MT_Scores_Large.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)"
   ],
   "id": "a52cb8151159489d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BLEU = 60.78 83.1/62.8/56.6/47.1 (BP = 0.995 ratio = 0.995 hyp_len = 1483 ref_len = 1490)\n",
      "TER = 20.61\n",
      "METEOR = 49.42\n",
      "WER = 15.81%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\RBMTS\\MT_Scores_Small.txt\n",
      "\n",
      "BLEU = 54.17 73.1/57.7/48.7/43.3 (BP = 0.992 ratio = 0.992 hyp_len = 8234 ref_len = 8300)\n",
      "TER = 32.42\n",
      "METEOR = 68.38\n",
      "WER = 32.40%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\RBMTS\\MT_Scores_Medium.txt\n",
      "\n",
      "BLEU = 62.08 77.9/64.9/57.0/51.6 (BP = 1.000 ratio = 1.017 hyp_len = 21554 ref_len = 21204)\n",
      "TER = 27.32\n",
      "METEOR = 75.14\n",
      "WER = 27.59%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\RBMTS\\MT_Scores_Large.txt\n",
      "\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-14T05:07:06.641711Z",
     "start_time": "2025-05-14T05:06:57.532085Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Evaluate the SMT Output Results\n",
    "# For Small Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\SMT\\\\testRefSmall.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\SMT\\\\testPredSmall1_Aftr.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\SMT\\\\MT_Scores_Small.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "\n",
    "# For Medium Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\SMT\\\\testRefMedium.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\SMT\\\\testPredMedium1_Aftr.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\SMT\\\\MT_Scores_Medium.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "\n",
    "# For Large Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\SMT\\\\testRefLarge.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\SMT\\\\testPredLarge1_Aftr.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\SMT\\\\MT_Scores_Large.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)"
   ],
   "id": "f7f0353da866079b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BLEU = 30.29 40.8/33.0/29.4/21.6 (BP = 0.997 ratio = 0.997 hyp_len = 1487 ref_len = 1492)\n",
      "TER = 69.03\n",
      "METEOR = 20.58\n",
      "WER = 71.24%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\SMT\\MT_Scores_Small.txt\n",
      "\n",
      "BLEU = 43.65 68.8/48.5/37.1/29.3 (BP = 1.000 ratio = 1.067 hyp_len = 8857 ref_len = 8300)\n",
      "TER = 43.01\n",
      "METEOR = 68.32\n",
      "WER = 40.33%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\SMT\\MT_Scores_Medium.txt\n",
      "\n",
      "BLEU = 44.73 72.9/50.3/37.6/29.1 (BP = 1.000 ratio = 1.063 hyp_len = 22543 ref_len = 21204)\n",
      "TER = 40.17\n",
      "METEOR = 72.56\n",
      "WER = 38.83%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\SMT\\MT_Scores_Large.txt\n",
      "\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-14T05:07:43.635876Z",
     "start_time": "2025-05-14T05:07:39.398686Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "# Evaluate the NMT (RNN)  Output Results\n",
    "# For Small Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\RNN\\\\testRefSmall.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\RNN\\\\testPredSmall.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\RNN\\\\MT_Scores_Small.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "\n",
    "# For Medium Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\RNN\\\\testRefMedium.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\RNN\\\\testPredMedium.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\RNN\\\\MT_Scores_Medium.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "\n",
    "# For Large Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\RNN\\\\testRefLarge.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\RNN\\\\testPredLarge.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\RNN\\\\MT_Scores_Large.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)"
   ],
   "id": "d8430e10ab79deab",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BLEU = 10.59 11.5/7.0/7.2/21.9 (BP = 1.000 ratio = 1.843 hyp_len = 2754 ref_len = 1494)\n",
      "TER = 81.13\n",
      "METEOR = 9.06\n",
      "WER = 88.16%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\NMT\\RNN\\MT_Scores_Small.txt\n",
      "\n",
      "BLEU = 54.74 73.0/59.1/49.5/42.0 (BP = 1.000 ratio = 1.042 hyp_len = 8649 ref_len = 8300)\n",
      "TER = 27.06\n",
      "METEOR = 73.78\n",
      "WER = 26.50%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\NMT\\RNN\\MT_Scores_Medium.txt\n",
      "\n",
      "BLEU = 52.72 71.5/57.2/47.3/39.9 (BP = 1.000 ratio = 1.062 hyp_len = 22509 ref_len = 21204)\n",
      "TER = 28.35\n",
      "METEOR = 74.68\n",
      "WER = 27.69%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\NMT\\RNN\\MT_Scores_Large.txt\n",
      "\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-14T05:11:04.907308Z",
     "start_time": "2025-05-14T05:10:59.032941Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Evaluate the NMT (BRNN (Batch 32))  Output Results\n",
    "# For Small Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 32)\\\\testRefSmall.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 32)\\\\testPredSmall.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 32)\\\\MT_Scores_Small.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "\n",
    "# For Medium Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 32)\\\\testRefMedium.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 32)\\\\testPredMedium.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 32)\\\\MT_Scores_Medium.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "\n",
    "# For Large Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 32)\\\\testRefLarge.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 32)\\\\testPredLarge.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 32)\\\\MT_Scores_Large.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n"
   ],
   "id": "f045701961d175d6",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BLEU = 10.27 12.3/7.4/6.9/17.9 (BP = 1.000 ratio = 1.871 hyp_len = 2795 ref_len = 1494)\n",
      "TER = 79.72\n",
      "METEOR = 10.02\n",
      "WER = 87.56%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\NMT\\BRNN (Batch 32)\\MT_Scores_Small.txt\n",
      "\n",
      "BLEU = 53.99 73.2/58.9/48.5/40.7 (BP = 1.000 ratio = 1.036 hyp_len = 8601 ref_len = 8300)\n",
      "TER = 27.45\n",
      "METEOR = 73.75\n",
      "WER = 26.99%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\NMT\\BRNN (Batch 32)\\MT_Scores_Medium.txt\n",
      "\n",
      "BLEU = 54.55 73.2/59.0/49.1/41.8 (BP = 1.000 ratio = 1.053 hyp_len = 22333 ref_len = 21204)\n",
      "TER = 27.37\n",
      "METEOR = 75.63\n",
      "WER = 26.99%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\NMT\\BRNN (Batch 32)\\MT_Scores_Large.txt\n",
      "\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-23T06:06:35.778048Z",
     "start_time": "2025-04-23T06:06:32.052274Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "1378caebb7ee564b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BLEU = 10.27 12.3/7.4/6.9/17.9 (BP = 1.000 ratio = 1.871 hyp_len = 2795 ref_len = 1494)\n",
      "TER = 79.72\n",
      "METEOR = 10.02\n",
      "WER = 87.56%\n",
      "\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\TestData\\NMT\\BRNN (Batch 32)\\MT_Scores_Small.txt\n",
      "BLEU = 53.99 73.2/58.9/48.5/40.7 (BP = 1.000 ratio = 1.036 hyp_len = 8601 ref_len = 8300)\n",
      "TER = 27.45\n",
      "METEOR = 73.75\n",
      "WER = 26.99%\n",
      "\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\TestData\\NMT\\BRNN (Batch 32)\\MT_Scores_Medium.txt\n",
      "BLEU = 54.55 73.2/59.0/49.1/41.8 (BP = 1.000 ratio = 1.053 hyp_len = 22333 ref_len = 21204)\n",
      "TER = 27.37\n",
      "METEOR = 75.63\n",
      "WER = 26.99%\n",
      "\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\TestData\\NMT\\BRNN (Batch 32)\\MT_Scores_Large.txt\n"
     ]
    }
   ],
   "execution_count": 32
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-05-14T05:13:25.802851Z",
     "start_time": "2025-05-14T05:13:21.276111Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# Evaluate the NMT (BRNN (Batch 64))  Output Results\n",
    "# For Small Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 64)\\\\testRefSmall.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 64)\\\\testPredSmall.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 64)\\\\MT_Scores_Small.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "\n",
    "# For Medium Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 64)\\\\testRefMedium.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 64)\\\\testPredMedium.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 64)\\\\MT_Scores_Medium.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n",
    "\n",
    "\n",
    "# For Large Sentences\n",
    "reference_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 64)\\\\testRefLarge.txt\"\n",
    "hypothesis_file=\"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 64)\\\\testPredLarge.txt\"\n",
    "output_file = \"C:\\\\Users\\\\Asus\\\\OneDrive\\\\Phd Research Backup\\\\Research Paper PeerJ\\\\Revision\\\\Datasets\\\\Aautomatic Evaluation\\\\TestData\\\\NMT\\\\BRNN (Batch 64)\\\\MT_Scores_Large.txt\"\n",
    "evaluate_mt_scores(reference_file, hypothesis_file, output_file)\n"
   ],
   "id": "658257af28ce5187",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BLEU = 8.45 9.8/5.9/5.5/16.0 (BP = 1.000 ratio = 1.846 hyp_len = 2758 ref_len = 1494)\n",
      "TER = 84.97\n",
      "METEOR = 7.30\n",
      "WER = 92.07%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\NMT\\BRNN (Batch 64)\\MT_Scores_Small.txt\n",
      "\n",
      "BLEU = 52.55 71.6/56.9/46.9/39.9 (BP = 1.000 ratio = 1.040 hyp_len = 8630 ref_len = 8300)\n",
      "TER = 28.81\n",
      "METEOR = 71.44\n",
      "WER = 28.66%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\NMT\\BRNN (Batch 64)\\MT_Scores_Medium.txt\n",
      "\n",
      "BLEU = 50.86 70.0/55.3/45.3/38.1 (BP = 1.000 ratio = 1.066 hyp_len = 22613 ref_len = 21204)\n",
      "TER = 30.38\n",
      "METEOR = 73.33\n",
      "WER = 28.85%\n",
      "Scores written to: C:\\Users\\Asus\\OneDrive\\Phd Research Backup\\Research Paper PeerJ\\Revision\\Datasets\\Aautomatic Evaluation\\TestData\\NMT\\BRNN (Batch 64)\\MT_Scores_Large.txt\n",
      "\n"
     ]
    }
   ],
   "execution_count": 9
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
