Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Update transcription notebook, closes #365

davidmezzetti4868bdcc424b
diff --git a/examples/11_Transcribe_audio_to_text.ipynb b/examples/11_Transcribe_audio_to_text.ipynb
index 7384f684..90d35ab1 100644
--- a/examples/11_Transcribe_audio_to_text.ipynb
+++ b/examples/11_Transcribe_audio_to_text.ipynb
@@ -33,7 +33,7 @@
"source": [
"# Install dependencies\n",
"\n",
- "Install `txtai` and all dependencies. Since this notebook is using optional pipelines, we need to install the pipeline extras package."
+ "Install `txtai` and all dependencies. Since this notebook is using optional pipelines, we need to install the pipeline extras package. We'll also demonstrate running this pipeline through the API."
]
},
{
@@ -43,13 +43,13 @@
},
"source": [
"%%capture\n",
- "!pip install git+https://github.com/neuml/txtai#egg=txtai[pipeline]\n",
+ "!pip install git+https://github.com/neuml/txtai#egg=txtai[api,pipeline]\n",
"\n",
"# Get test data\n",
"!wget -N https://github.com/neuml/txtai/releases/download/v3.5.0/tests.tar.gz\n",
"!tar -xvzf tests.tar.gz"
],
- "execution_count": 1,
+ "execution_count": 8,
"outputs": []
},
{
@@ -77,9 +77,9 @@
"from txtai.pipeline import Transcription\n",
"\n",
"# Create transcription model\n",
- "transcribe = Transcription(\"facebook/wav2vec2-large-960h\")"
+ "transcribe = Transcription()"
],
- "execution_count": 2,
+ "execution_count": 9,
"outputs": []
},
{
@@ -101,7 +101,7 @@
"height": 497
},
"id": "-K2YJJzsVtfq",
- "outputId": "113fb43e-15d4-4a5d-f351-9a223af5abbd"
+ "outputId": "7f2fe352-de55-428e-f15a-28f389498961"
},
"source": [
"from IPython.display import Audio, display\n",
@@ -114,7 +114,7 @@
" print(text)\n",
" print()\n"
],
- "execution_count": 3,
+ "execution_count": 10,
"outputs": [
{
"output_type": "display_data",
@@ -137,7 +137,7 @@
"output_type": "stream",
"name": "stdout",
"text": [
- "Baging mobilizes invasion craft along coast as tiwan tensions escalates\n",
+ "Baging mobilizes invasion kraft along coast as tie one tensions escalates\n",
"\n"
]
},
@@ -162,7 +162,7 @@
"output_type": "stream",
"name": "stdout",
"text": [
- "Canada's last fully intact ice shelf has suddenly collapsed forming a manhatten sized ice berg\n",
+ "Canodas last fully intact ice shelf has suddenly collapsed forming a manhattan sized iceberge\n",
"\n"
]
},
@@ -262,7 +262,7 @@
"output_type": "stream",
"name": "stdout",
"text": [
- "U s virus cases top a million\n",
+ "Ues virus cases top a million\n",
"\n"
]
}
@@ -282,9 +282,7 @@
"source": [
"# OpenAI Whisper\n",
"\n",
- "**Update**: In September 2022, [OpenAI Whisper](https://github.com/openai/whisper) was released bringing a dramatic improvement in transcription quality. \n",
- "\n",
- "These models will no doubt roll into the Hugging Face Transformers library and make it possible to use the standard txtai transcription pipeline. But as of now, the model is only available on GitHub. Let's give it a try. "
+ "In September 2022, [OpenAI Whisper](https://github.com/openai/whisper) was released. This model brings a dramatic improvement in transcription quality. Whisper support was added to Hugging Face Transformers in v4.23.0. Let's give it a try."
],
"metadata": {
"id": "bDxW-tsCELob"
@@ -293,72 +291,8 @@
{
"cell_type": "code",
"source": [
- "%%capture\n",
- "!pip install git+https://github.com/openai/whisper.git git+https://github.com/neuml/txtai#egg=txtai[api]"
- ],
- "metadata": {
- "id": "rkzgzLn8FZTb"
- },
- "execution_count": 4,
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "source": [
- "Next we'll create a custom transcription pipeline using Whisper. We'll create the pipeline as a Python file so it can be used both in this Python instance and in an API instance."
- ],
- "metadata": {
- "id": "sNuIrWq5RcwC"
- }
- },
- {
- "cell_type": "code",
- "source": [
- "%%writefile transcription.py\n",
- "import whisper\n",
- "\n",
- "# Create Whisper pipeline\n",
- "class Transcription:\n",
- " def __init__(self, path=\"small\"):\n",
- " self.model = whisper.load_model(path)\n",
- "\n",
- " def __call__(self, files):\n",
- " return [self.model.transcribe(f, fp16=False, language=\"english\")[\"text\"].strip() for f in files]"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "kSSBAzeFPX1S",
- "outputId": "2fa0465b-8c97-43cd-a2a5-a513d3db0029"
- },
- "execution_count": 5,
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "Writing transcription.py\n"
- ]
- }
- ]
- },
- {
- "cell_type": "markdown",
- "source": [
- "Let's transcribe the files!"
- ],
- "metadata": {
- "id": "hYxuR2vGR1BO"
- }
- },
- {
- "cell_type": "code",
- "source": [
- "from transcription import Transcription\n",
- "\n",
"# Transcribe files\n",
- "transcribe = Transcription()\n",
+ "transcribe = Transcription(\"openai/whisper-base\")\n",
"for text in transcribe(files):\n",
" print(text)"
],
@@ -367,9 +301,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "-KgYwAQzFVll",
- "outputId": "6c97ccdd-3c43-429f-a67e-f1794781c25a"
+ "outputId": "7b1e9541-1a6f-4814-ae14-21f4bd9794e7"
},
- "execution_count": 10,
+ "execution_count": 11,
"outputs": [
{
"output_type": "stream",
@@ -378,9 +312,9 @@
"Beijing mobilizes invasion craft along coast as Taiwan tensions escalate.\n",
"Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan sized iceberg.\n",
"Maine Man wins from lottery ticket.\n",
- "make huge profits without working, make up to $100,000 a day.\n",
+ "make huge profits without working. Make up to $100,000 a day.\n",
"National Park Service warns against sacrificing slower friends in a bear attack.\n",
- "US virus cases top a million.\n"
+ "U.S. virus cases top of million.\n"
]
}
]
@@ -406,12 +340,13 @@
" path: sentence-transformers/nli-mpnet-base-v2\n",
" content: true\n",
"\n",
- "transcription.Transcription:\n",
+ "transcription:\n",
+ " path: openai/whisper-base\n",
"\n",
"workflow:\n",
" index:\n",
" tasks:\n",
- " - transcription.Transcription\n",
+ " - transcription\n",
" - index"
],
"metadata": {
@@ -419,9 +354,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "k3Rb2OU9Mq3h",
- "outputId": "2ba1d8c0-171e-4b67-8d67-70f50ce53fe5"
+ "outputId": "5e40ecd5-3df1-4864-c7a3-3e26bd087415"
},
- "execution_count": 7,
+ "execution_count": 12,
"outputs": [
{
"output_type": "stream",
@@ -447,9 +382,9 @@
"base_uri": "https://localhost:8080/"
},
"id": "cj49U095IxTc",
- "outputId": "508032b9-6bfa-4062-803a-06bf1193d4bd"
+ "outputId": "a55b8717-f5fc-4e8f-ef1b-5fecc3f8200a"
},
- "execution_count": 11,
+ "execution_count": 26,
"outputs": [
{
"output_type": "execute_result",
@@ -457,11 +392,11 @@
"text/plain": [
"[{'id': '2',\n",
" 'text': 'Maine Man wins from lottery ticket.',\n",
- " 'score': 0.12858600914478302}]"
+ " 'score': 0.1285860687494278}]"
]
},
"metadata": {},
- "execution_count": 11
+ "execution_count": 26
}
]
},
@@ -494,15 +429,15 @@
"base_uri": "https://localhost:8080/"
},
"id": "XDpqwf8PNHNo",
- "outputId": "d78cbda6-855b-4127-94a7-a710f3adf980"
+ "outputId": "7ec28122-69a3-47cc-d2ed-acaa186e4aa1"
},
- "execution_count": 9,
+ "execution_count": 29,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
- "[{\"id\":\"2\",\"text\":\"Maine Man wins from lottery ticket.\",\"score\":0.12858600914478302}]"
+ "[{\"id\":\"2\",\"text\":\"Maine Man wins from lottery ticket.\",\"score\":0.1285860687494278}]"
]
}
]
@@ -521,11 +456,11 @@
"source": [
"# Wrapping up\n",
"\n",
- "There is a lot of development in the audio transcription space. Keep an eye out for when Whisper is mainstreamed as a Hugging Face model. In the meantime, it's only a couple of lines of code to create a custom pipeline and worth it given the accuracy bump!"
+ "There is a lot of development in the audio transcription space. In only a couple of lines of code, high-quality transcription models are now readily available!"
],
"metadata": {
"id": "VCU8zGGDXQ0Y"
}
}
]
-}
\ No newline at end of file
+}