Skip to main content

PyTorch edit-distance functions

Project description

PyTorch edit-distance functions

Useful functions for E2E Speech Recognition training with PyTorch and CUDA.

Here is a simple use case with Reinforcement Learning and RNN-T loss:

blank = torch.tensor([0], dtype=torch.int).cuda()
space = torch.tensor([1], dtype=torch.int).cuda()

xs = model.greedy_decode(xs, sampled=True)

torch_edit_distance.remove_blank(xs, xn, blank)

rewards = 1 - torch_edit_distance.compute_wer(xs, ys, xn, yn, blank, space)

nll = rnnt_loss(zs, ys, xn, yn)

loss = nll * rewards

levenshtein_distance

Levenshtein edit-distance with detailed statistics for ins/del/sub operations.

collapse_repeated

Merge repeated tokens, useful for CTC-based model.

remove_blank

Remove unnecessary blank tokens, useful for CTC, RNN-T, RNA models.

strip_separator

Remove leading, trailing and repeated middle separators.

Requirements

  • C++11 compiler (tested with GCC 5.4).
  • Python: 3.5, 3.6, 3.7 (tested with version 3.6).
  • PyTorch >= 1.0.0 (tested with version 1.1.0).
  • CUDA Toolkit (tested with version 10.0).

Install

There is no compiled version of the package. The following setup instructions compile the package from the source code locally.

From Pypi

pip install torch_edit_distance

From GitHub

git clone https://github.com/1ytic/pytorch-edit-distance
cd pytorch-edit-distance
python setup.py install

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for torch-edit-distance, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size torch_edit_distance-0.3.0.tar.gz (7.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page