Skip to main content

Conformer

PyPI Lint Code Base Upload Python Package Code style: black Open In Colab

GitHub stars GitHub followers Twitter Follow

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.

Release files for conformer-tf 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for conformer-tf 0.2.0
File Size Uploaded
conformer-tf-0.2.0.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for conformer-tf 0.2.0
File Interpreter ABI Platform
conformer_tf-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.2 kB

Release files / conformer-tf-0.2.0.tar.gz

Download URL conformer-tf-0.2.0.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
df253b3b7a26553e2101e093edbabd51243c018d0489de2272a6cffb1de253b8
BLAKE2b-256 checksum
How to use checksums
1c03f852267a7e13d0988605003e346b85299c9f0bdab748a882bd3a0be77901
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / conformer_tf-0.2.0-py3-none-any.whl

Download URL conformer_tf-0.2.0-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
387e740826598df4fe4d18673cce5f9d3c14bfea094c37cb6a9405620705c1de
BLAKE2b-256 checksum
How to use checksums
e869f7583412ac742a15cee044f5525bafad727e277a856e2615aca14063adb9
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page