Explore different way to mix speech model(wav2vec2, hubert) and nlp model(BART,T5,GPT) together
Project description
SpeechMix
Explore different way to mix speech model(wav2vec2, hubert) and nlp model(BART,T5,GPT) together.
Introduction
For the same input:
from datasets import load_dataset
import soundfile as sf
# define function to read in sound file
def map_to_array(batch):
speech, _ = sf.read(batch["file"])
batch["speech"] = speech
return batch
# load dummy dataset and read soundfiles
ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
ds = ds.map(map_to_array)
transcript = ds['text'][0]
speech = ds["speech"][0]
Speech encoder NLP decoder
model = SpeechMixED("facebook/wav2vec2-base-960h", "facebook/bart-large")
transcript_tensor = model.tokenizer(transcript, return_tensors="pt").input_ids
speech_tensor = model.processor(speech, return_tensors="pt").input_values
model(speech_tensor, transcript_tensor)
Speech encoder NLP decoder only fine-tune on cross attention/projection/decoder embedding
model = SpeechMixED("facebook/wav2vec2-base-960h", "facebook/bart-large", ftl=True)
transcript_tensor = model.tokenizer(transcript, return_tensors="pt").input_ids
speech_tensor = model.processor(speech, return_tensors="pt").input_values
model(speech_tensor, transcript_tensor)
Speech encoder NLP encoder decoder
model = SpeechMixEED("facebook/wav2vec2-base-960h", "facebook/bart-large")
transcript_tensor = model.tokenizer(transcript, return_tensors="pt").input_ids
speech_tensor = model.processor(speech, return_tensors="pt").input_values
model(speech_tensor, transcript_tensor)
Speech encoder NLP encoder decoder only fine-tune on layer norm and attention
model = SpeechMixEED("facebook/wav2vec2-base-960h", "facebook/bart-large", lna=True)
transcript_tensor = model.tokenizer(transcript, return_tensors="pt").input_ids
speech_tensor = model.processor(speech, return_tensors="pt").input_values
model(speech_tensor, transcript_tensor)
Speech encoder NLP encoder decoder only fine-tune on speech encoder
model = SpeechMixEED("facebook/wav2vec2-base-960h", "facebook/bart-large", fne=True)
transcript_tensor = model.tokenizer(transcript, return_tensors="pt").input_ids
speech_tensor = model.processor(speech, return_tensors="pt").input_values
model(speech_tensor, transcript_tensor)
Installation
pip install
pip install speechmix
Build from source
git clone and cd into this project.
pip install -e .
Example
usage:
python train.py --speech_model_config facebook/wav2vec2-large-robust-ft-libri-960h --nlp_model_config facebook/mbart-large-50-one-to-many-mmt --SpeechMixEED --lna --dataset librispeech_asr --field clean --train_split train.100 --test_split validation --batch 3 --grad_accum 8
python train.py --speech_model_config facebook/wav2vec2-large-robust-ft-libri-960h --nlp_model_config facebook/mbart-large-50-one-to-many-mmt --SpeechMixEED --fne --dataset librispeech_asr --field clean --train_split train.100 --test_split validation --batch 3 --grad_accum 8
python train.py --speech_model_config facebook/wav2vec2-large-robust-ft-libri-960h --nlp_model_config facebook/mbart-large-50-one-to-many-mmt --SpeechMixED --dataset librispeech_asr --field other --train_split train.500 --test_split validation --batch 3 --grad_accum 8
python train.py --speech_model_config facebook/wav2vec2-large-robust-ft-libri-960h --nlp_model_config facebook/mbart-large-50-one-to-many-mmt --SpeechMixED --ftl --dataset librispeech_asr --field other --train_split train.500 --test_split validation --batch 3 --grad_accum 8
python train.py --speech_model_config facebook/wav2vec2-large-robust-ft-libri-960h --nlp_model_config facebook/mbart-large-50-one-to-many-mmt --SpeechMixSelf --dataset librispeech_asr --field clean --train_split train.100 --test_split validation --batch 3 --grad_accum 10
python train.py --speech_model_config facebook/wav2vec2-large-robust-ft-libri-960h --nlp_model_config facebook/mbart-large-50-one-to-many-mmt --SpeechMixGAN --dataset librispeech_asr --field clean --train_split train.100 --test_split validation --batch 3 --grad_accum 10
python train.py --speech_model_config facebook/wav2vec2-large-robust-ft-libri-960h --nlp_model_config facebook/mbart-large-50-one-to-many-mmt --SpeechMixSelf --dataset common_voice --field en --train_split train --test_split test --batch 5 --grad_accum 8
python train.py --speech_model_config facebook/wav2vec2-large-robust-ft-libri-960h --nlp_model_config facebook/mbart-large-50-one-to-many-mmt --SpeechMixEED --lna --dataset patrickvonplaten/librispeech_asr_dummy --field clean --train_split validation --test_split test --batch 3 --grad_accum 4
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file speechmix-0.0.22.tar.gz
.
File metadata
- Download URL: speechmix-0.0.22.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b088f18e4d5e63f872204b1617c1f295b0b8ea894562c8cbfb5300c1a29f5d2 |
|
MD5 | 4abb38d15db1d546720a0b0b06527d28 |
|
BLAKE2b-256 | 525d0b06b16ae4461626bf46072e20aee4ff4ed143bcbe0253ea337a5dcf3ab2 |
File details
Details for the file speechmix-0.0.22-py3.7.egg
.
File metadata
- Download URL: speechmix-0.0.22-py3.7.egg
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 535cc5037817a300eefb4e40f8f91f43ae1898a567451028b19f4594a9d9ebe7 |
|
MD5 | 2887ce90b130a831fda926d839feb944 |
|
BLAKE2b-256 | 3f25eb55df25532b890416142a6e36525488bfa552e456e903f45189a87504f1 |
File details
Details for the file speechmix-0.0.22-py3-none-any.whl
.
File metadata
- Download URL: speechmix-0.0.22-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36396e9c812b9c07f2a6740b00829650a3e3c1c975067ee3a6510be1f4f70b08 |
|
MD5 | 704d895c2e1a5746ce398b6182573753 |
|
BLAKE2b-256 | ded6be0e2abf18b6d089dd860662b95effe31bdbcb7ebc7fede4f1a61368c6d6 |