Git Product home page Git Product logo

conformer's Introduction

Conformer

Open In Colab

About

This is the implementation of Conformer [1] in Tensorflow 2

Note: This repository is still in development and constantly evolving. New features and updates will appear over time.

Motivation

I have seen many Conformer's implementations ([2], [3]) but none of them is in Tensorflow. Therefore, I wanted to challenge myself to implement this model in my favorite framework.

Installation

You should have Python 3.7 or higher. I highly recommend creating a virual environment like venv or conda.

The main part of this project uses only Tensorflow 2. However, I also use Tensorflow I/O for features augmentation (which is not needed right now)

Script for downloading dependencies (setuptools is not available right now)

pip install tensorflow
pip install tensorflow-io   # optional

Usage

import tensorflow as tf
from conformer import Conformer

batch_size, seq_len, input_dim = 3, 15, 256

model = Conformer(
    num_conv_filters=[512, 512], 
    num_blocks=1, 
    encoder_dim=512, 
    num_heads=8, 
    dropout_rate=0.4, 
    num_classes=10, 
    include_top=True
)

# Get sample input
inputs = tf.random.uniform((batch_size, seq_len, input_dim),
                            minval=-40,
                            maxval=40)

# Convert to 4-dimensional tensor to fit Conv2D
inputs = tf.expand_dims(inputs, axis=1)  

# Get output
outputs = model(inputs)     # [batch_size, 1, seq_len, num_class]
outputs = tf.squeeze(outputs, axis=1)

References

[1] Conformer: Convolution-augmented Transformer for Speech Recognition ๐Ÿ”—

[2] @sooftware's PyTorch implementation ๐Ÿ”—

[3] @jaketae's PyTorch implementation ๐Ÿ”—

conformer's People

Contributors

thanhtvt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

wendongj

conformer's Issues

Error in computing RelativeMHA

At line 105 in attention.py, you've written
context = self.out_linear(tf.reshape(context, [batch_size, -1, seq_len, self.d_model]), training=training)
which should've been
context = self.out_linear(tf.reshape(context, [batch_size, -1, self.d_model]), training=training)

Since output for each multihead attention should be [B, S, D_Model]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.