Convolutional Quasi-Recurrent Network (CQRN)
Project description
Convolutional Quasi-Recurrent Network (CQRN) for PyTorch
This repository contains the PyTorch implementation of the Convolutional Quasi-Recurrent Network(CQRN) proposed in paper A Convolutional Quasi-Recurrent Network for Real-time Speech Enhancement.
Requirements
Requirements are provided in requirements.txt.
- PyTorch 1.8 from a nightly release. Installation instructions can be found in Pytorch
Installation
From source:
- Clone the source:
git clone https://github.com/syljoy/pytorch-cqrn.git
2. Install the Pytorch-CQRN package into python virtual environment:
python setup.py install or pip install.
From PyPi:
pip install Pytorch-CQRN
Usage
import torch
from torchcqrn import CQRN
seq_len, batch_size, channels, hidden_size, bins, layers = \
7, 3, 1, 512, 257, 5
size = (seq_len, batch_size, channels, bins)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
input_tensor = torch.autograd.Variable(torch.rand(size),
requires_grad=True).to(device)
cqrn = CQRN(input_dim=channels, hidden_size=hidden_size, num_layers=layers,
dropout=0.4, window=2).to(device)
output, hidden = cqrn(input_tensor)
print(output.size(), hidden.size())
The full documentation for the CQRN is listed below:
CQRN(input_dim, hidden_size, num_layers, dropout, layers, save_prev_x, window, kernel_size)
Applies a multiple layer Convolutional Quasi-Recurrent Network (CQRN) to an input sequence.
Args:
input_dim: The number of channels in the input x.
hidden_size: The number of channels produced by the convolution.
num_layers: The number of CQRN layers to produce.
dropout: Whether to apply zoneout (i.e. failing to update elements in the hidden state) to the hidden state updates. Default: 0.0
layers: List of preconstructed CQRN layers to use for the CQRN module.
save_prev_x: Whether to store previous inputs for use in future masked convolutional windows (i.e. for a continuing sequence such as in language modeling). If true, you must call reset to remove cached previous values of x. Default: False.
window: Defines the size of the masked convolutional window (how many previous tokens to look when computing the CQRN values). Supports 1, 2 and 3. Default: 1.
kernel_size: The size of the convolving kernel. Default: [window, 9].
Inputs: input, hidden
- **input** of shape `(seq_len, batch, channels, bins)`: tensor
containing the features of the input sequence.
- **hidden** of shape `(hidden_size, batch, bins)`: tensor containing
the initial hidden state for the CQRN.
Outputs: output, next_hidden
- **output** of shape `(seq_len, batch, hidden_size, bins)`: tensor
containing the output of the CQRN for each timestep.
- **next_hidden** of shape `(layers, batch, hidden_size, bins)`:
tensor containing the hidden state for t=seq_len.
If you are using convolutional windows of size 2 or 3 (i.e. looking at the inputs from two previous timesteps to compute the input) and want to run over a long sequence in batches, you can set save_prev_x=True and call reset when you wish to reset the cached previous inputs.
If you want flexibility in the definition of each CQRN layer, you can construct individual CQRNLayer modules and pass them to the CQRN module using the layers argument.
Maintainers
Release History
- 0.1.0
- The first release
- Implement simple CQRNLayer and CQRN Model.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file PyTorch-CQRN-0.1.2.tar.gz.
File metadata
- Download URL: PyTorch-CQRN-0.1.2.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
289a2be5443769321de7b0e4d2bc811b87099f2f4dcb7c43837281224ace5649
|
|
| MD5 |
a9be4181b3542d0fa960aa9cf06e2141
|
|
| BLAKE2b-256 |
6c24b55ca68beb141b45c751257468da4cf944ad95cb142546d2a92508002e4c
|
File details
Details for the file PyTorch_CQRN-0.1.2-py3-none-any.whl.
File metadata
- Download URL: PyTorch_CQRN-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a179af9ad612e1ad2aeab01480913a1870208aa7dda0df4b1caa5786b6d8740
|
|
| MD5 |
70e56b72d8f1e12c00031d211e66c53d
|
|
| BLAKE2b-256 |
b4b7ca6a6dd37cd4aecfd082f82a01177b511fe6cd31a994e0877d2c8af4f14a
|