{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5eb5f497",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "arxiv  old  test_logits.pkl  train_nemo_tts.ipynb  Untitled.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "!ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "09315925",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Found entries of length > 1 in alphabet. This is unusual unless style is BPE, but the alphabet was not recognized as BPE type. Is this correct?\n"
     ]
    }
   ],
   "source": [
    "import pickle\n",
    "from pyctcdecode.decoder import build_ctcdecoder\n",
    "with open(\"/home/georg/notebooks/test_logits.pkl\", \"rb\") as f:\n",
    "    logits = pickle.load(f)   \n",
    "labels = [\n",
    "    \"\", \"<s>\", \"</s>\", \"\\\\u2047\", \" \", \"E\", \"T\", \"A\", \"O\", \"N\", \"I\", \"H\", \"S\", \"R\", \"D\", \"L\", \"U\", \n",
    "    \"M\", \"W\", \"C\", \"F\", \"G\", \"Y\", \"P\", \"B\", \"V\", \"K\", \"\\'\", \"X\", \"J\", \"Q\", \"Z\"\n",
    "]\n",
    "decoder = build_ctcdecoder(labels)\n",
    "\n",
    "# test 1\n",
    "decoder.decode(logits)\n",
    "\n",
    "# test 2\n",
    "from multiprocessing import Pool\n",
    "with Pool() as pool:\n",
    "    text_list = decoder.decode_batch(pool, [logits])\n",
    "text_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1337e90d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'THE CUT ON HIS CHEST STILL DRIPPING BLOOD THE ACH OF HIS OVERSTRAINED EYES EVEN THE SOARING ARENA AROUND HIM WITH THE THOUSANDS OF SPECTATORS WERE TRIVIALITIES NOT WORTH THINKING ABOUT'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "decoder.decode(logits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "b39b851c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'THE CUT ON HIS CHEST STILL DRIPPING BLOOD THE ACH OF HIS OVERSTRAINED EYES EVEN THE SOARING ARENA AROUND HIM WITH THE THOUSANDS OF SPECTATORS WERE TRIVIALITIES NOT WORTH THINKING ABOUT'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from multiprocessing import Pool\n",
    "\n",
    "with Pool() as pool:\n",
    "    text_list = decoder.decode_batch(pool, [logits])\n",
    "    \n",
    "text_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9631f96",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "615fcddb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f5cfbdd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f1fbfecd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
