An implementation of Conformer:Convolution-augmented Transformer for Speech Recognition in TensorFlow
Project description
Conformer
This repo implements Conformer: Convolution-augmented Transformer for Speech Recognition by Gulati et al. in TensorFlow. Conformer achieves the best of both worlds (transformers for content-based global interactions and CNNs to exploit local features) by studying how to combine convolution neural networks and transformers to model both local and global dependencies of an audio sequence in a parameter-efficient way.
It also significantly outperforms the previous Transformer and CNN based models achieving state-of-the-art accuracies.
Installation
Run the following to install:
pip install conformer-tf
Developing conformer-tf
To install conformer-tf
, along with tools you need to develop and test, run the following in your virtualenv:
git clone https://github.com/Rishit-dagli/Conformer.git
# or clone your own fork
cd Conformer
pip install -e .[dev]
To run rank and shape tests run the following:
pytest --verbose
Usage
In this section, I show a minimal example of creating a Convolutional Module, one of the main contributions of the paper and a Conformer block as well.
Create a Convolutional Module
import tensorflow as tf
from conformer_tf import ConformerConvModule
layer = ConformerConvModule(
dim = 512,
causal = False, # whether it is auto-regressive
expansion_factor = 2, # what multiple of the dimension to expand for the depthwise convolution
kernel_size = 31,
dropout = 0.
)
x = tf.random.normal([1, 1024, 512])
x = layer(x) + x # (1, 1024, 512)
Create a Conformer Block
import tensorflow as tf
from conformer_tf import ConformerBlock
conformer_block = ConformerBlock(
dim = 512,
dim_head = 64,
heads = 8,
ff_mult = 4,
conv_expansion_factor = 2,
conv_kernel_size = 31,
attn_dropout = 0.,
ff_dropout = 0.,
conv_dropout = 0.
)
x = tf.random.normal([1, 1024, 512])
conformer_block(x) # (1, 1024, 512)
Want to Contribute 🙋♂️?
Awesome! If you want to contribute to this project, you're always welcome! See Contributing Guidelines. You can also take a look at open issues for getting more information about current or upcoming tasks.
Want to discuss? 💬
Have any questions, doubts or want to present your opinions, views? You're always welcome. You can start discussions.
Citation
@misc{gulati2020conformer,
title={Conformer: Convolution-augmented Transformer for Speech Recognition},
author={Anmol Gulati and James Qin and Chung-Cheng Chiu and Niki Parmar and Yu Zhang and Jiahui Yu and Wei Han and Shibo Wang and Zhengdong Zhang and Yonghui Wu and Ruoming Pang},
year={2020},
eprint={2005.08100},
archivePrefix={arXiv},
primaryClass={eess.AS}
}
Phil Wang's PyTorch implementation was super helpful while building this.
License
Copyright 2020 Rishit Dagli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
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 Distribution
File details
Details for the file conformer-tf-0.2.0.tar.gz
.
File metadata
- Download URL: conformer-tf-0.2.0.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df253b3b7a26553e2101e093edbabd51243c018d0489de2272a6cffb1de253b8 |
|
MD5 | 97124f63c0642297419a9c715d75d2a7 |
|
BLAKE2b-256 | 1c03f852267a7e13d0988605003e346b85299c9f0bdab748a882bd3a0be77901 |
File details
Details for the file conformer_tf-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: conformer_tf-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 387e740826598df4fe4d18673cce5f9d3c14bfea094c37cb6a9405620705c1de |
|
MD5 | 9dcff1431c03acf2e4f12e7aab99ad81 |
|
BLAKE2b-256 | e869f7583412ac742a15cee044f5525bafad727e277a856e2615aca14063adb9 |