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 9.4.0).
- Python: 3.5, 3.6, 3.7, 3.8, 3.9 (tested with version 3.8).
- PyTorch >= 1.5.0 (tested with version 1.13.1+cu116).
- CUDA Toolkit (tested with version 11.2).
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
Test
python -m torch_edit_distance.test
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
File details
Details for the file torch_edit_distance-0.4.0.tar.gz
.
File metadata
- Download URL: torch_edit_distance-0.4.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce402efa87680f9215858d5d36e70115b2212cc09feb248a8d6e29508b98fe9c |
|
MD5 | fc5efb59666f5374f878193f198c1863 |
|
BLAKE2b-256 | 42e162aaebb2c9bd17e3e7bc2a002d6fc31a87823b031c501f6acb4dd8f677ba |