Aligner - PyTorch
Project description
Aligner - PyTorch
Sequence alignement methods with helpers for PyTorch.
Install
pip install aligner-pytorch
Usage
MAS
MAS (Monotonic Alignment Search) from GlowTTS. This can be used to get the alignment of any (similarity) matrix. Implementation in optimized Cython.
from aligner_pytorch import mas
sim = torch.rand(1, 4, 6) # [batch_size, x_length, y_length]
alignment = mas(sim)
"""
sim = tensor([[
[0.2, 0.8, 0.9, 0.9, 0.9, 0.4],
[0.6, 0.8, 0.9, 0.7, 0.1, 0.4],
[1.0, 0.4, 0.4, 0.2, 1.0, 0.7],
[0.1, 0.3, 0.1, 0.7, 0.6, 0.9]
]])
alignment = tensor([[
[1, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1]
]], dtype=torch.int32)
"""
XY Embedding to Alignment
Used during training to get the alignement of a x_embedding
with y_embedding
, computes the log probability from a normal distribution and the alignment with MAS.
from aligner_pytorch import get_alignment_from_embeddings
x_embedding = torch.randn(1, 4, 10)
y_embedding = torch.randn(1, 6, 10)
alignment = get_alignment_from_embeddings(
x_embedding=torch.randn(1, 4, 10), # [batch_size, x_length, features]
y_embedding=torch.randn(1, 6, 10), # [batch_size, y_length, features]
) # [batch_size, x_length, y_length]
"""
alignment = tensor([[
[1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1]
]], dtype=torch.int32)
"""
Duration Embedding to Alignment
Used during inference to compute the alignment from a trained duration embedding.
from aligner_pytorch import get_alignment_from_duration_embedding
alignment = get_alignment_from_duration_embedding(
embedding=torch.randn(1, 5), # Embedding: [batch_size, x_length]
scale=1.0, # Duration scale
y_length=10 # (Optional) fixes maximum output y_length
) # Output alignment [batch_size, x_length, y_length]
"""
alignment = tensor([[
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
]])
"""
Citations
Monotonic Alignment Search
@misc{2005.11129,
Author = {Jaehyeon Kim and Sungwon Kim and Jungil Kong and Sungroh Yoon},
Title = {Glow-TTS: A Generative Flow for Text-to-Speech via Monotonic Alignment Search},
Year = {2020},
Eprint = {arXiv:2005.11129},
}
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
aligner-pytorch-0.0.19.tar.gz
(108.5 kB
view details)
File details
Details for the file aligner-pytorch-0.0.19.tar.gz
.
File metadata
- Download URL: aligner-pytorch-0.0.19.tar.gz
- Upload date:
- Size: 108.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a7e41b3586aa062a91c8c3c0346275378fa896a96d81315c2b21d0c3d678804 |
|
MD5 | 618f989d74ab8e70fce9a31789fae9d4 |
|
BLAKE2b-256 | 6ec32aa2dce18b99182a36df4fa8c24f2df72bb1da03c16374f6c1b368bc839b |