{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "9sEfZoepGP8x" }, "source": [ "# Setup Environment" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "brKU69ZQvEiz", "outputId": "dc3c06c4-5a4f-4469-9447-acf5a15750c2" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/235.8 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m235.5/235.8 kB\u001b[0m \u001b[31m14.3 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m235.8/235.8 kB\u001b[0m \u001b[31m6.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h" ] } ], "source": [ "!pip install -q unidecode" ] }, { "cell_type": "markdown", "metadata": { "id": "Nwt1YBYVqcva" }, "source": [ "# Setup Model" ] }, { "cell_type": "code", "source": [ "!git clone https://huggingface.co/MahtaFetrat/Homo-GE2PE-Persian/" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "l_KnAgVoAS83", "outputId": "2d3fe260-e8bf-41e2-e35b-3b61dcd59dc7" }, "execution_count": 2, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Cloning into 'Homo-GE2PE-Persian'...\n", "remote: Enumerating objects: 32, done.\u001b[K\n", "remote: Counting objects: 100% (28/28), done.\u001b[K\n", "remote: Compressing objects: 100% (27/27), done.\u001b[K\n", "remote: Total 32 (delta 7), reused 0 (delta 0), pack-reused 4 (from 1)\u001b[K\n", "Unpacking objects: 100% (32/32), 27.25 KiB | 1.36 MiB/s, done.\n", "Filtering content: 100% (3/3), 218.23 MiB | 50.60 MiB/s, done.\n" ] } ] }, { "cell_type": "code", "source": [ "!unzip -q Homo-GE2PE-Persian/assets/Parsivar.zip\n", "!unzip -q Homo-GE2PE-Persian/model-weights/homo-ge2pe.zip -d homo-ge2pe\n", "!unzip -q Homo-GE2PE-Persian/model-weights/homo-t5.zip -d homo-t5" ], "metadata": { "id": "kbsS_rWVAkYt" }, "execution_count": 3, "outputs": [] }, { "cell_type": "code", "source": [ "!mv Homo-GE2PE-Persian/assets/GE2PE.py ./" ], "metadata": { "id": "sG6P0nbUAood" }, "execution_count": 4, "outputs": [] }, { "cell_type": "code", "execution_count": 5, "metadata": { "id": "VIRvJy8naB0f" }, "outputs": [], "source": [ "!sed -i 's+from collections import Iterable+from collections.abc import Iterable+g' /content/Parsivar/token_merger.py" ] }, { "cell_type": "markdown", "source": [ "# Inference" ], "metadata": { "id": "3UjjHbxNIIMt" } }, { "cell_type": "code", "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "Qs-J5B3ykaYz", "outputId": "a64ca839-b970-4796-88aa-0d80f3342e08" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "['teste model t/bdil nevise be vaj', '@in ketabe @ali @/st']" ] }, "metadata": {}, "execution_count": 6 } ], "source": [ "from GE2PE import GE2PE\n", "\n", "g2p = GE2PE(model_path='/content/homo-ge2pe') # or homo-t5\n", "\n", "g2p.generate(['تست مدل تبدیل نویسه به واج', 'این کتابِ علی است'], use_rules=True)" ] } ], "metadata": { "colab": { "provenance": [] }, "gpuClass": "standard", "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }