{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c8df4df8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# try nemo cap/punct\n",
    "# try nemo ner\n",
    "# try spacy ner?\n",
    "# try spgi punct asr?\n",
    "# try whisper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "93d4a7a4",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[NeMo W 2022-10-29 10:16:50 optimizers:67] Could not import distributed_fused_adam optimizer from Apex\n",
      "[NeMo W 2022-10-29 10:16:52 experimental:27] Module <class 'nemo.collections.nlp.data.language_modeling.megatron.megatron_batch_samplers.MegatronPretrainingRandomBatchSampler'> is experimental, not ready for production and is not fully supported. Use at your own risk.\n",
      "[NeMo W 2022-10-29 10:16:52 experimental:27] Module <class 'nemo.collections.nlp.models.text_normalization_as_tagging.thutmose_tagger.ThutmoseTaggerModel'> is experimental, not ready for production and is not fully supported. Use at your own risk.\n"
     ]
    }
   ],
   "source": [
    "from IPython.utils.io import capture_output\n",
    "import re\n",
    "\n",
    "import nemo.collections.nlp as nemo_nlp\n",
    "import spacy\n",
    "import whisper\n",
    "import tqdm\n",
    "\n",
    "from suno_utils.utils.text import normalize_whitespace\n",
    "from suno_utils.audio import Audio\n",
    "from suno_utils.utils.display import suppress_logging"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "182059d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100% [......................................................................] 407269414 / 407269414"
     ]
    }
   ],
   "source": [
    "with suppress_logging():\n",
    "    punct_model = nemo_nlp.models.PunctuationCapitalizationModel.from_pretrained(\n",
    "        model_name=\"punctuation_en_bert\",\n",
    "    )\n",
    "    punct_2_model = nemo_nlp.models.PunctuationCapitalizationModel.from_pretrained(\n",
    "        model_name=\"punctuation_en_distilbert\",\n",
    "    )\n",
    "    ner_model = nemo_nlp.models.TokenClassificationModel.from_pretrained(\n",
    "        model_name=\"ner_en_bert\",\n",
    "    )\n",
    "def punct_predict(fp):\n",
    "    with suppress_logging():\n",
    "        with capture_output():\n",
    "            punct_out = punct_model.add_punctuation_capitalization([fp])[0]\n",
    "    return punct_out\n",
    "def punct_2_predict(fp):\n",
    "    with suppress_logging():\n",
    "        with capture_output():\n",
    "            punct_out = punct_2_model.add_punctuation_capitalization([fp])[0]\n",
    "    return punct_out\n",
    "NER_LABEL_MAP = {v: k for k, v in ner_model._cfg.label_ids.items()}\n",
    "def ner_predict(text):\n",
    "    with suppress_logging():\n",
    "        with capture_output():\n",
    "            class_id_preds = ner_model._infer([text], 1)\n",
    "    class_preds = [NER_LABEL_MAP[idx][2:] for idx in class_id_preds]\n",
    "    tokens = text.split()\n",
    "    assert(len(tokens) == len(class_preds))\n",
    "    return list(zip(tokens, class_preds))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "e34d9f5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "whisper_model = whisper.load_model(\"medium.en\")\n",
    "# whisper_2_model = whisper.load_model(\"large\")\n",
    "def whisper_predict(fp):\n",
    "    audio = whisper.load_audio(fp)\n",
    "    audio = whisper.pad_or_trim(audio)\n",
    "    mels = whisper.log_mel_spectrogram(audio).to(whisper_model.device)\n",
    "    options = whisper.DecodingOptions(language=\"en\", without_timestamps=True)\n",
    "    result = whisper_model.decode(mels, options)\n",
    "    return result.text\n",
    "# def whisper_2_predict(fp):\n",
    "#     audio = whisper.load_audio(fp)\n",
    "#     audio = whisper.pad_or_trim(audio)\n",
    "#     mels = whisper.log_mel_spectrogram(audio).to(whisper_2_model.device)\n",
    "#     options = whisper.DecodingOptions(language=\"en\", without_timestamps=True)\n",
    "#     result = whisper_2_model.decode(mels, options)\n",
    "#     return result.text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "ab55da94",
   "metadata": {},
   "outputs": [],
   "source": [
    "# nlp = spacy.load('en_core_web_lg')\n",
    "# def spacy_predict(text):\n",
    "#     doc = nlp(text)\n",
    "#     new_text = text\n",
    "#     for ent in doc.ents[::-1]:\n",
    "#         new_text = new_text[:ent.end_char] + f\"[{ent.label_}]\" + new_text[ent.end_char:]\n",
    "#     return new_text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7cbe5427",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = []\n",
    "with open(\"transcripts.tsv\") as f:\n",
    "    for line in f.read().strip().split(\"\\n\"):\n",
    "        fp, s = line.split(\"\\t\")\n",
    "        data.append((fp, s.lower()))\n",
    "text_list = [e[1] for e in data]\n",
    "fp_list = [e[0] for e in data]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "8e006d94",
   "metadata": {},
   "outputs": [],
   "source": [
    "punct_out = [punct_predict(text) for text in text_list]\n",
    "punct_2_out = [punct_2_predict(text) for text in text_list]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5f38e17d",
   "metadata": {},
   "outputs": [],
   "source": [
    "ner_out = [ner_predict(text) for text in punct_out]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "3993c29c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# ner_2_out = [spacy_predict(text) for text in text_list]\n",
    "# ner_2_post_out = [spacy_predict(text) for text in punct_out]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "83937286",
   "metadata": {},
   "outputs": [],
   "source": [
    "asr_out = [whisper_predict(fp) for fp in fp_list]\n",
    "# asr_2_out = [whisper_2_predict(fp) for fp in fp_list]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3842095",
   "metadata": {},
   "source": [
    "## Consolidate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "87253ca6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<audio controls=\"controls\" autobuffer=\"autobuffer\" style=\"\">\n",
       "  <source src=\"data:audio/mpeg;base64,//M4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VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//M4xKAAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//M4xKAAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//M4xKAAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//M4xKAAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//M4xKAAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//M4xKAAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\"/>\n",
       "  Your browser does not support the audio element.\n",
       "</audio>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "Audio.from_file(fp_list[7]).play()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "d1afcf4b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['mustafa do you have a second',\n",
       " 'yo andy you got a second',\n",
       " 'seven eight nine',\n",
       " 'four five six',\n",
       " 'testing testing testing']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text_list[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "e80e5df0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mustafa, do you have a second?',\n",
       " 'Yo, Andy, you got a second?',\n",
       " 'Seven, eight nine.',\n",
       " 'Four, five, six.',\n",
       " 'Testing testing testing.']"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "punct_out[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "16324b94",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mustafa, do you have a second?',\n",
       " 'Yo, Andy, you got a second.',\n",
       " 'Seven, eight, nine.',\n",
       " 'Four, five, six.',\n",
       " 'Testing testing testing.']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "punct_2_out[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "120aef96",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[('Mustafa,', 'PER'),\n",
       "  ('do', ''),\n",
       "  ('you', ''),\n",
       "  ('have', ''),\n",
       "  ('a', ''),\n",
       "  ('second?', '')],\n",
       " [('Yo,', ''),\n",
       "  ('Andy,', 'PER'),\n",
       "  ('you', ''),\n",
       "  ('got', ''),\n",
       "  ('a', ''),\n",
       "  ('second?', '')],\n",
       " [('Seven,', ''), ('eight', ''), ('nine.', 'TIME')],\n",
       " [('Four,', ''), ('five,', ''), ('six.', '')],\n",
       " [('Testing', ''), ('testing', ''), ('testing.', '')]]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ner_out[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "feba52a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mustafar, do you have a second?',\n",
       " 'E-O-N-D, you got a second?',\n",
       " '789.',\n",
       " 'four five six.',\n",
       " 'Testing, testing, testing.']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "asr_out[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "b7542147",
   "metadata": {},
   "outputs": [],
   "source": [
    "# use bert punctuator\n",
    "\n",
    "# punctuation\n",
    "  # add distillbert commas\n",
    "  # use whisper to fixup ambiguous puntuation and all-uppercase words like JSON and FBI\n",
    "\n",
    "# capitalization\n",
    "  # find entities that remain uppercase\n",
    "    # ??use nemo/spacy pre/post punct??\n",
    "  # lowercase everything that is not entities\n",
    "  # lowercase rules like numbers and 'i'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "44d826de",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "50it [00:24,  2.04it/s]\n"
     ]
    }
   ],
   "source": [
    "number_set = set([\n",
    "    \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\", \n",
    "    \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\"\n",
    "])\n",
    "\n",
    "def _lower(m):\n",
    "    return \"<\" + m.group(1).lower() + \">\"\n",
    "\n",
    "out_texts = []\n",
    "for fp, text in tqdm.tqdm(zip(fp_list, text_list)):\n",
    "    # TODO: handle background speech brackets (keep track of position)\n",
    "    tokens = normalize_whitespace(text).split()\n",
    "    # punctuate and capitalize\n",
    "    with suppress_logging():\n",
    "        with capture_output():\n",
    "            punct_pred_1 = punct_model.add_punctuation_capitalization([text], return_labels=True)[0].split()\n",
    "            punct_pred_2 = punct_2_model.add_punctuation_capitalization([text], return_labels=True)[0].split()\n",
    "    assert(len(tokens) == len(punct_pred_1) == len(punct_pred_2))\n",
    "    punct_tokens = []\n",
    "    for t, p1, p2 in zip(tokens, punct_pred_1, punct_pred_2):\n",
    "        token_formatted = t\n",
    "        if p1[1] == \"U\":\n",
    "            token_formatted = token_formatted.capitalize()\n",
    "        punct_char = p1[0] if p1[0] != \"O\" else \"\"\n",
    "        if punct_char == \"\" and p2[0] == \",\":\n",
    "            punct_char = \",\"\n",
    "        punct_tokens.append((token_formatted, punct_char))\n",
    "    # use asr to fix punct and cap\n",
    "    # TODO: improve this with alignment\n",
    "    asr_out = whisper_predict(fp)\n",
    "    asr_tokens = set(asr_out.split())\n",
    "    asr_tokens_no_punct = set([t.strip(\".,?\") for t in asr_tokens])\n",
    "    fixed_punct_tokens = []\n",
    "    cap_next = False\n",
    "    for t, p in punct_tokens:\n",
    "        if cap_next:\n",
    "            t = t.capitalize()\n",
    "        cap_next = False\n",
    "        if t + p not in asr_tokens and t + \"?\" in asr_tokens:\n",
    "            p = \"?\"\n",
    "            cap_next = True\n",
    "        elif t + p not in asr_tokens and t + \".\" in asr_tokens:\n",
    "            p = \".\"\n",
    "            cap_next = True\n",
    "        if t not in asr_tokens and t.upper() in asr_tokens_no_punct:\n",
    "            t = t.upper()\n",
    "        fixed_punct_tokens.append((t, p))\n",
    "    text = \" \".join([\"\".join([t, p]) for t, p in fixed_punct_tokens])\n",
    "    if False:\n",
    "        \n",
    "        # lowercase everything other than proper nouns\n",
    "        # TODO: look at labels more properly and do alignment\n",
    "        ner_preds = ner_predict(text)\n",
    "        out_text = \" \".join([t if l != \"\" else t.lower() for t, l in ner_preds])\n",
    "        # TODO: and/or exclude labels in ner?\n",
    "        # final regex stuff\n",
    "        out_text = re.sub(r\"\\bI\\b\", \"i\", out_text)\n",
    "        out_text = re.sub(r\"(?<=[A-Za-z])\\*\\.\", \"*,\", out_text)\n",
    "        out_text = re.sub(r\"\\<([A-Za-z]+?)\\>\", _lower, out_text)\n",
    "    else:\n",
    "        out_text = text\n",
    "    out_tokens = out_text.split()\n",
    "    adjusted_tokens = []\n",
    "    for t1, t2 in zip(out_tokens[:-1], out_tokens[1:]):\n",
    "        add_comma = False\n",
    "        if t1.strip(\".,\") == t2.strip(\".,\"):\n",
    "            add_comma = True\n",
    "        if t1.strip(\".,\") in number_set and t2.strip(\".,\") in number_set:\n",
    "            add_comma = True\n",
    "        if add_comma:\n",
    "            t = t1.strip(\".,\") + \",\"\n",
    "        else:\n",
    "            t = t1\n",
    "        adjusted_tokens.append(t)\n",
    "    adjusted_tokens.extend(out_tokens[-1:])\n",
    "    adjusted_out_text = \" \".join(adjusted_tokens)\n",
    "    out_texts.append(adjusted_out_text)\n",
    "out_str = \"\\n\".join([\"\\t\".join([fp, text]) for fp, text in zip(fp_list, out_texts)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "c6b2e50f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# with open(\"formatted_transcripts.tsv\", \"w\") as f:\n",
    "#     f.write(out_str)\n",
    "with open(\"input_formatted_transcripts.tsv\", \"w\") as f:\n",
    "    f.write(out_str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "87ca3761",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(0, 'Mustafa, do you have a second?'),\n",
       " (1, 'Yo, Andy, you got a second?'),\n",
       " (2, 'Seven, eight, nine.'),\n",
       " (3, 'Four, five, six.'),\n",
       " (4, 'Testing testing. Testing.'),\n",
       " (5,\n",
       "  \"Yeah, sometimes I feel the same. Sometimes. Yeah, it's a little bit frustrating sometime.\"),\n",
       " (6,\n",
       "  'Yeah, well, sh*, should we try a design thing right now? <u> like, <u> test? After that we can talk about in the design world? <u>'),\n",
       " (7, 'Was their fault to learn?'),\n",
       " (8, 'Andy, you wanna jump into a pairing session?'),\n",
       " (9,\n",
       "  \"Yeah, and I feel like we all have could've all jumped into this thing and we all jumped off the thing, and we've been together each time.\"),\n",
       " (10, 'Is we shall we do?'),\n",
       " (11,\n",
       "  \"I, I didn't notice that he was sick, but yeah, the I, I, I knew about the house. [not at my ti*]. It's funny because like sometimes like, uh, I don't know. Like the. The times are so different are so, so different of us working remotely that it's funny.\"),\n",
       " (12, \"Yep, what's up?\"),\n",
       " (13, 'Uh, not bad, not bad. How was your trip?'),\n",
       " (14, 'Lacking any neutral.'),\n",
       " (15,\n",
       "  'One, two, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen.'),\n",
       " (16, 'Testing speechly.'),\n",
       " (17, 'One two.'),\n",
       " (18, 'Testing one, two, three.'),\n",
       " (19, 'Testing.'),\n",
       " (20,\n",
       "  \"Boom, it is really good. I don't feel like I've, I've you know, disconnected from a thing, and now I'm completely alone.\"),\n",
       " (21,\n",
       "  'Yo, I was just uh, debugging, uh, pop for pull flow, and we got it working. Uh, anyway, should we jump into the collaboration area?'),\n",
       " (22,\n",
       "  'Shall I ever question for you about how, how you want all the data from the feed back from *azur *am Because I think like the only option that I have is like sending back JSON.'),\n",
       " (23, 'Testing.'),\n",
       " (24,\n",
       "  \"Yeah, exactly. A nice. I didn't hear your wave, but I saw your, your wave not so long ago. So that was successful, too.\"),\n",
       " (25, 'Problem, thank today.'),\n",
       " (26, 'Yeah, it feels more like work.'),\n",
       " (27, 'Sounds good. Sound good.'),\n",
       " (28, 'Yeah, I, just ah, this was fun. we*.'),\n",
       " (29, 'Yo, uh, you wanna jump on a one on one?'),\n",
       " (30, 'Yeah, gr*. thanks.'),\n",
       " (31, \"Test what's going on?\"),\n",
       " (32, 'Got it. Do you wanna pair on the Prs? Then we can get them out?'),\n",
       " (33, \"Hey, Jay, if you're around, Uh, I think I finished the profiles.\"),\n",
       " (34, 'Yep.'),\n",
       " (35,\n",
       "  'I know, and, and honestly, Speechly is, is really good, and how fast it is.'),\n",
       " (36,\n",
       "  \"Uh, must to find out. we're just finishing our one on one, but we more often do. He was showing the Cam record. I saw you were here, so I figured we could do a quick short sync.\"),\n",
       " (37, 'You, Andy, quick question. Can you jump on a call?'),\n",
       " (38, \"Let's do it.\"),\n",
       " (39, 'Yeah.'),\n",
       " (40, 'Yo, Andy, you wanna try something new?'),\n",
       " (41, 'Yo, wanna see something cool?'),\n",
       " (42, 'Hello.'),\n",
       " (43, \"Oh, right, that's right. It's the funeral today.\"),\n",
       " (44, \"It says you're not in the walkie talkie area.\"),\n",
       " (45, 'Testing.'),\n",
       " (46,\n",
       "  'No, no, but I was just uh, watching a show on my computer with Pop on.'),\n",
       " (47,\n",
       "  \"Yeah, I'm just uh, just finishing, uh, reviewing the changes right now.\"),\n",
       " (48, 'Great.'),\n",
       " (49,\n",
       "  '*cup eh, do you wanna go to the collaboration area or in the one on ones?')]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(zip(range(len(out_texts)), out_texts))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8668f3e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/georg/notebooks/customers/speechly/punctuation\r\n"
     ]
    }
   ],
   "source": [
    "!pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "02d0f72e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " audios\t\t\t    'Punctuation guidelines.pdf'   transcripts.tsv\r\n",
      " formatted_transcripts.tsv   transcripts_base.tsv\t   Untitled.ipynb\r\n"
     ]
    }
   ],
   "source": [
    "!ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a0a424f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"/home/georg/notebooks/customers/speechly/punctuation/formatted_transcripts.tsv\") as f:\n",
    "    out = f.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0679913a",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"/home/georg/notebooks/customers/speechly/punctuation/transcripts_base.tsv\") as f:\n",
    "    out = f.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "64510d17",
   "metadata": {},
   "outputs": [],
   "source": [
    "out = out.replace(\"audios/\", \"\").replace(\".wav\", \"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "e6e9caa2",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"/home/georg/notebooks/customers/speechly/punctuation/transcripts_base_2.tsv\", \"w\") as f:\n",
    "    f.write(out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "0a117246",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "511"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(\" \".join([e.split(\"\\t\")[-1] for e in out.split(\"\\n\")]).split())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6eed724",
   "metadata": {},
   "outputs": [],
   "source": [
    "50 segments, 511 words, 302 seconds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "3e4025b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "60913.90728476821"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "10 * 60 * 60 / 302 * 511"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "468771ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "6000 segments, 60k words"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "fecdbd91",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "d = \"/mnt/data-ssd-1/data/private/customer/speechly/pop.com/sample-50/audios\"\n",
    "fns = os.listdir(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "922dd46c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from suno_utils.audio.conversion import get_duration_s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "2bcc1bb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "l = []\n",
    "for fn in fns:\n",
    "    fp = os.path.join(d, fn)\n",
    "    l.append(get_duration_s(fp))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "c31ea96f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "302.10600000000005"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ff7621f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# with open(\"/home/georg/notebooks/customers/speechly/punctuation/transcripts_formatted.tsv\", \"w\") as f:\n",
    "#     f.write(out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eccf82bf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3cb157bd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "7594cbff",
   "metadata": {},
   "outputs": [],
   "source": [
    "# fp = fp_list[4]\n",
    "# text = text_list[4]\n",
    "\n",
    "# tokens = normalize_whitespace(text).split()\n",
    "# # punctuate and capitalize\n",
    "# with suppress_logging():\n",
    "#     with capture_output():\n",
    "#         punct_pred_1 = punct_model.add_punctuation_capitalization([text], return_labels=True)[0].split()\n",
    "#         punct_pred_2 = punct_2_model.add_punctuation_capitalization([text], return_labels=True)[0].split()\n",
    "# assert(len(tokens) == len(punct_pred_1) == len(punct_pred_2))\n",
    "# punct_tokens = []\n",
    "# for t, p1, p2 in zip(tokens, punct_pred_1, punct_pred_2):\n",
    "#     token_formatted = t\n",
    "#     if p1[1] == \"U\":\n",
    "#         token_formatted = token_formatted.capitalize()\n",
    "#     punct_char = p1[0] if p1[0] != \"O\" else \"\"\n",
    "#     if punct_char == \"\" and p2[0] == \",\":\n",
    "#         punct_char = \",\"\n",
    "#     punct_tokens.append((token_formatted, punct_char))\n",
    "# # use asr to fix punct and cap\n",
    "# # TODO: improve this with alignment\n",
    "# asr_out = whisper_predict(fp)\n",
    "# asr_tokens = set(asr_out.split())\n",
    "# asr_tokens_no_punct = set([t.strip(\".,?\") for t in asr_tokens])\n",
    "# fixed_punct_tokens = []\n",
    "# cap_next = False\n",
    "# for t, p in punct_tokens:\n",
    "#     if cap_next:\n",
    "#         t = t.capitalize()\n",
    "#     cap_next = False\n",
    "#     if t + p not in asr_tokens and t + \"?\" in asr_tokens:\n",
    "#         p = \"?\"\n",
    "#         cap_next = True\n",
    "#     elif t + p not in asr_tokens and t + \".\" in asr_tokens:\n",
    "#         p = \".\"\n",
    "#         cap_next = True\n",
    "#     if t not in asr_tokens and t.upper() in asr_tokens_no_punct:\n",
    "#         t = t.upper()\n",
    "#     fixed_punct_tokens.append((t, p))\n",
    "# # lowercase everything other than proper nouns\n",
    "# # TODO: look at labels more properly and do alignment\n",
    "# ner_preds = ner_predict(\" \".join([\"\".join([t, p]) for t, p in fixed_punct_tokens]))\n",
    "# out_text = \" \".join([t if l != \"\" else t.lower() for t, l in ner_preds])\n",
    "# # TODO: and/or exclude labels in ner?\n",
    "# # final regex stuff\n",
    "# out_text = re.sub(r\"\\bI\\b\", \"i\", out_text)\n",
    "# out_tokens = out_text.split()\n",
    "# adjusted_tokens = []\n",
    "# for t1, t2 in zip(out_tokens[:-1], out_tokens[1:]):\n",
    "#     add_comma = False\n",
    "#     if t1.strip(\".,\") == t2.strip(\".,\"):\n",
    "#         add_comma = True\n",
    "#     if t1.strip(\".,\") in number_set and t2.strip(\".,\") in number_set:\n",
    "#         add_comma = True\n",
    "#     if add_comma:\n",
    "#         t = t1.strip(\".,\") + \",\"\n",
    "#     else:\n",
    "#         t = t1\n",
    "#     adjusted_tokens.append(t)\n",
    "# adjusted_tokens.extend(out_tokens[-1:])\n",
    "# adjusted_out_text = \" \".join(adjusted_tokens)\n",
    "# adjusted_out_text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e252e0a4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19f0c711",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25f915fb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "344a526e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ae28f62",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05811996",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "412d6bfd",
   "metadata": {},
   "source": [
    "## Playground"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "acac965a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[NeMo I 2022-09-22 16:47:26 tokenize_and_classify:64] Creating ClassifyFst grammars.\n"
     ]
    }
   ],
   "source": [
    "# create inverse text normalization instance\n",
    "from nemo_text_processing.inverse_text_normalization.inverse_normalize import InverseNormalizer\n",
    "inverse_normalizer = InverseNormalizer(lang='en')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "08398f23",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "we paid 15 for this desk\n"
     ]
    }
   ],
   "source": [
    "spoken = \"we paid fifteen for this desk\"\n",
    "un_normalized = inverse_normalizer.inverse_normalize(spoken, verbose=False)\n",
    "print(un_normalized)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e32f1009",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'we work for the f b i and others'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "spoken = \"we work for the f b i and others\"\n",
    "un_normalized = inverse_normalizer.inverse_normalize(spoken, verbose=False)\n",
    "un_normalized"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4298e937",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[NeMo I 2022-09-22 11:29:03 punctuation_capitalization_model:1143] Using batch size 1 for inference\n",
      "[NeMo I 2022-09-22 11:29:03 punctuation_capitalization_infer_dataset:91] Max length: 11\n",
      "[NeMo I 2022-09-22 11:29:03 data_preprocessing:404] Some stats of the lengths of the sequences:\n",
      "[NeMo I 2022-09-22 11:29:03 data_preprocessing:406] Min: 9 |                  Max: 9 |                  Mean: 9.0 |                  Median: 9.0\n",
      "[NeMo I 2022-09-22 11:29:03 data_preprocessing:412] 75 percentile: 9.00\n",
      "[NeMo I 2022-09-22 11:29:03 data_preprocessing:413] 99 percentile: 9.00\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 55.93batch/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['We work for the F, B, I and others.']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.add_punctuation_capitalization([\"we work for the f b i and others\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae8b4dfd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "471d20fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[NeMo I 2022-09-22 15:29:08 tokenize_and_classify:87] Creating ClassifyFst grammars.\n"
     ]
    }
   ],
   "source": [
    "from nemo_text_processing.text_normalization.normalize import Normalizer\n",
    "normalizer = Normalizer(input_case='cased', lang='en')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "bd4649d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Created cache_dir/en_tn_post_processing.far\n",
      "[NeMo I 2022-09-22 15:22:18 tokenize_and_classify_with_audio:101] Creating ClassifyFst grammars. This might take some time...\n",
      "Created cache_dir/_cased_en_tn_False_deterministic.far\n",
      "[NeMo I 2022-09-22 15:29:03 tokenize_and_classify_with_audio:229] ClassifyFst grammars are saved to cache_dir/_cased_en_tn_False_deterministic.far.\n",
      "Created cache_dir/en_tn_False_deterministic_verbalizer.far\n",
      "[NeMo I 2022-09-22 15:29:05 verbalize_final:76] VerbalizeFinalFst grammars are saved to cache_dir/en_tn_False_deterministic_verbalizer.far.\n"
     ]
    }
   ],
   "source": [
    "from nemo_text_processing.text_normalization.normalize_with_audio import NormalizerWithAudio\n",
    "normalizer = NormalizerWithAudio(\n",
    "        lang=\"en\",\n",
    "        input_case=\"cased\",\n",
    "        overwrite_cache=False,\n",
    "        cache_dir=\"cache_dir\",\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "4d5edf70",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'we work for the FBI and others'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "written = \"we work for the FBI and others\"\n",
    "normalized = normalizer.normalize(written, verbose=False, punct_post_process=False)\n",
    "normalized"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "460a93b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "we work for the FBI and others\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'we work for the F B I and others', 'we work for the FBI and others'}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "written = \"we work for the FBI and others\"\n",
    "normalized = normalizer_audio.normalize(written, n_tagged=10, punct_post_process=True)\n",
    "normalized"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ccfb347",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import nemo\n",
    "# import nemo.collections.nlp as nemo_nlp\n",
    "# tagger = nemo_nlp.models.duplex_text_normalization.DuplexTaggerModel.from_pretrained(model_name=\"itn_en_t5\")\n",
    "# decoder = nemo_nlp.models.duplex_text_normalization.DuplexDecoderModel.from_pretrained(model_name=\"itn_en_t5\")\n",
    "# normalizer = nemo_nlp.models.duplex_text_normalization.DuplexTextNormalizationModel(tagger, decoder, lang=\"en\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d95035b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72ea4a6a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50325085",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2e250ded",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47727e3a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e16a24c6",
   "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
}
