{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": 15, "metadata": { "id": "mSG4QdpNvio4" }, "outputs": [], "source": [] }, { "cell_type": "code", "source": [ "!pip install kenlm" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "f3jTUbzZv442", "outputId": "76eb7e32-227b-4cef-a20f-38ae936c4d8a" }, "execution_count": 16, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Requirement already satisfied: kenlm in /usr/local/lib/python3.12/dist-packages (0.3.0)\n" ] } ] }, { "cell_type": "code", "source": [ "from huggingface_hub import hf_hub_download\n", "import kenlm\n", "\n", "# Step 1: Download the .arpa file from the dataset repository\n", "print(\"Downloading KenLM ARPA file from Hugging Face Dataset...\")\n", "model_path = hf_hub_download(\n", " repo_id=\"BeitTigreAI/tigre-data-kenLM\",\n", " filename=\"tigre-data-kenLM.arpa\",\n", " repo_type=\"dataset\", # 🔑 This is critical! It's a dataset repo, not a model\n", " local_dir=\"./kenlm_model\"\n", ")\n", "\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "Q8KTpqAqvj4d", "outputId": "6fface0f-230d-49a6-ea02-02ab06850f46" }, "execution_count": 17, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Downloading KenLM ARPA file from Hugging Face Dataset...\n" ] } ] }, { "cell_type": "code", "source": [ "import kenlm\n", "\n", "# Load the language model\n", "model = kenlm.Model(model_path)\n", "\n", "# Example sentences\n", "sentences = [\n", " \"አነ ምሩር ህሌኮ ምን ኪደትለ አፌተ\",\n", " \"እብ ረቢኩም ምን ተአምኖ፡ ለወለት ልብዬ ወዕንቼተ\",\n", " \"ህተ ትብል ሑዬቱ ወአነ እብል ሕቼተ\"\n", "]\n", "\n", "def test_sentence(sentence):\n", " log_prob = model.score(sentence)\n", " perplexity = model.perplexity(sentence)\n", " print(f\"Sentence: {sentence}\")\n", " print(f\"Log10 Probability: {log_prob:.4f}\")\n", " print(f\"Perplexity: {perplexity:.4f}\")\n", " print(\"-\" * 50)\n", "\n", "for sent in sentences:\n", " test_sentence(sent)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "UHem-Q4Kvslb", "outputId": "d9a947a0-01ae-402f-e592-0a9c6951d962" }, "execution_count": 18, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Sentence: አነ ምሩር ህሌኮ ምን ኪደትለ አፌተ\n", "Log10 Probability: -27.5345\n", "Perplexity: 8580.2515\n", "--------------------------------------------------\n", "Sentence: እብ ረቢኩም ምን ተአምኖ፡ ለወለት ልብዬ ወዕንቼተ\n", "Log10 Probability: -34.3204\n", "Perplexity: 19500.8208\n", "--------------------------------------------------\n", "Sentence: ህተ ትብል ሑዬቱ ወአነ እብል ሕቼተ\n", "Log10 Probability: -28.4631\n", "Perplexity: 11645.5115\n", "--------------------------------------------------\n" ] } ] }, { "cell_type": "markdown", "source": [ "\n", "\n", "\n", " \n", " \n", " Tigre LM Output Explanation\n", " \n", "\n", "\n", "\n", "

Understanding the Output

\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ScoreMeaningIdeal
Log10 ProbabilityLog of sentence probability. Higher (less negative) = more fluent.Closer to 0
PerplexityMeasures surprise. Lower = more natural.As low as possible
OOV
(in word scores)
True = word not in vocabulary. Affects confidence.
\n", " False = word is known.
False
\n", "\n", "

✅ Use this to:

\n", " \n", "\n", "\n", "" ], "metadata": { "id": "AF6K4_3R0wlM" } } ] }