README update
Browse files
README.md
CHANGED
|
@@ -27,14 +27,117 @@ tags:
|
|
| 27 |
- Whisper
|
| 28 |
---
|
| 29 |
|
| 30 |
-
# Causal Whisper
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
A large-v2 model is available for french, portuguese, spanish and german with a chunk size of 300[msec].
|
|
|
|
| 27 |
- Whisper
|
| 28 |
---
|
| 29 |
|
| 30 |
+
# CarelessWhisper - Causal Whisper Streaming Model
|
| 31 |
+
Causal Whisper Streaming is a fine tuned version of OpenAI Whisper, which can handle causal data and perform real-time transcription.
|
| 32 |
|
| 33 |
+

|
| 34 |
+
[](https://huggingface.co/spaces/MLSpeech/CarelessWhisper-causal-streaming)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
## Setup
|
| 38 |
+
We used Python 3.9.16, PyTorch 2.6.0, and PyTorch-Lightning 2.5.0 to train and test our models.
|
| 39 |
+
All of the required dependencies are available on `requirements.txt` file. Make sure all of the packages are installed before running anything.
|
| 40 |
+
Portions of this code are adapted from [OpenAI's Whisper](https://github.com/openai/whisper).
|
| 41 |
+
|
| 42 |
+
## Available Models
|
| 43 |
+
We fine-tuned three different sizes of Whisper, all support english only transcription.
|
| 44 |
+
A `large-v2` that was fine tuned on multilingual data is available, and supports English, French, Spanish, German and Portuguese with chunk size of 300 miliseconds.
|
| 45 |
+
|
| 46 |
+
| Size | Chunk Size [msec] | Multilingual |
|
| 47 |
+
|:----:|:-----------------:|:------------:|
|
| 48 |
+
| base | 40, 100, 200, 300 | N/A |
|
| 49 |
+
| small| 40, 100, 200, 300, 1000| N/A |
|
| 50 |
+
|large-v2| 40, 100, 200, 300, 1000| 300 |
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
## Running Inference
|
| 54 |
+
To run inference, download the repo content, and run accroding to following sections.
|
| 55 |
+
### CLI Usage
|
| 56 |
+
The transcription model is easily activated using the next command:
|
| 57 |
+
```bash
|
| 58 |
+
# Using a local microphone for streaming transcription, dumping the recording to out.wav
|
| 59 |
+
python causal_whisper_stream/streaming_transcribe.py \
|
| 60 |
+
--output_filename out.wav \ # path to dump recording to - optional
|
| 61 |
+
--channels 2 \ # number of channels
|
| 62 |
+
--model small \ # model size
|
| 63 |
+
--chunk_size 300 \ # chunk size in milliseconds
|
| 64 |
+
--device cuda \ # inference device
|
| 65 |
+
--beam_size 5 \ # run inference with beam of size 5
|
| 66 |
+
--ca_kv_cache \ # run inference with CA kv cache
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
A simulation of a stream on a wav file is also available:
|
| 70 |
+
```bash
|
| 71 |
+
# Simulating a stream on a wav file
|
| 72 |
+
python causal_whisper_stream/streaming_transcribe.py \
|
| 73 |
+
--model small \ # model size
|
| 74 |
+
--chunk_size 300 \ # chunk size in milliseconds
|
| 75 |
+
--device cuda \ # inference device
|
| 76 |
+
--beam_size 5 \ # run inference with beam of size 5
|
| 77 |
+
--ca_kv_cache \ # run inference with CA kv cache
|
| 78 |
+
--wav_file /path/to/audio.wav \ # path to audio file to transcribe
|
| 79 |
+
--simulate_stream \ # a must for a simulation to occur
|
| 80 |
+
--use_latency \ # simulating real latency of the chunk size - optional.
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
### Python Usage
|
| 84 |
+
If you prefer using python, a code sinppet utilizing a microphone or a wav file is provided below:
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
+
import torch
|
| 88 |
+
import causal_whisper_stream
|
| 89 |
+
|
| 90 |
+
model_size = "small" # model size
|
| 91 |
+
chunk_size = 300 # chunk size in milliseconds
|
| 92 |
+
multilingual = False # currently on large-v2_300msec supports other languages than english.
|
| 93 |
+
device = "cuda" if torch.cuda.is_avaialable() else "cpu"
|
| 94 |
+
|
| 95 |
+
model = causal_whisper_stream.load_streaming_model(name=model_size,
|
| 96 |
+
gran=chunk_size,
|
| 97 |
+
multilingual=multilingual,
|
| 98 |
+
device=device)
|
| 99 |
+
|
| 100 |
+
# using a local microphone recording
|
| 101 |
+
texts_microphone = model.transcribe(output_filename="/path/to/dump/file.wav",
|
| 102 |
+
channels=2,
|
| 103 |
+
beam_size=5,
|
| 104 |
+
ca_kv_cache=True)
|
| 105 |
+
|
| 106 |
+
# Simulating on a wav file
|
| 107 |
+
texts_wav_simulation = model.transcribe(simulate_stream=True,
|
| 108 |
+
wav_file="/path/to/file/you/want/to/transcribe.wav",
|
| 109 |
+
beam_size=5,
|
| 110 |
+
ca_kv_cache=True)
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
## Training
|
| 114 |
+
In order to train using LoRA, you can use our existing code. Make sure all the requirements are installed.
|
| 115 |
+
|
| 116 |
+
### CLI Interface
|
| 117 |
+
```bash
|
| 118 |
+
#
|
| 119 |
+
python training_code/train.py \
|
| 120 |
+
--lora \ # use LoRA fine-tuning, currently only this way is supported.
|
| 121 |
+
--streaming_train \ # streaming traing
|
| 122 |
+
--simulate_stream \ # simulate a stream of data, use streaming mel
|
| 123 |
+
--dataset LIBRI-960-ALIGNED \ # dataset name from a dict
|
| 124 |
+
--name example_training_base_model \ # name for differentiation
|
| 125 |
+
--size base \ # model size to train on
|
| 126 |
+
--batch_size 32 \ # batch size
|
| 127 |
+
--epochs 10 \ # maximal epochs
|
| 128 |
+
--learning_rate 1e-5 \ # initial learning rate
|
| 129 |
+
--rank 32 \ # LoRA rank
|
| 130 |
+
--gran 15 \ # Chunk size in encoder frames units. 15 encoder frames = 300msec
|
| 131 |
+
--extra_gran_blocks 1 \ # extra blocks for inital chunk. 1 means that an extra block is added for the beginning. i.e., the inital chunk will be 600msec.
|
| 132 |
+
--streaming_fraction 0.25 \ # fraction of samples out of the possible subsequences in the streaming process to train on
|
| 133 |
+
--top_k 5 \ # how many ckpts to save.
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
For more options and training configurations, run:
|
| 137 |
+
```bash
|
| 138 |
+
python training_code/train.py --help
|
| 139 |
+
```
|
| 140 |
+
### 🙏 Acknowledgements
|
| 141 |
+
|
| 142 |
+
This project uses components from [OpenAI's Whisper](https://github.com/openai/whisper), licensed under the MIT License.
|
| 143 |
|
|
|