Skip to main content

Aligner - PyTorch

Sequence alignement methods with helpers for PyTorch.

Install

pip install aligner-pytorch

PyPI - Python Version

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},
}

Metadata

Release files for aligner-pytorch 0.0.19

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aligner-pytorch 0.0.19
File Size Uploaded
aligner-pytorch-0.0.19.tar.gz 108.5 kB Details

Release files / aligner-pytorch-0.0.19.tar.gz

Download URL aligner-pytorch-0.0.19.tar.gz
Size 108.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0a7e41b3586aa062a91c8c3c0346275378fa896a96d81315c2b21d0c3d678804
BLAKE2b-256 checksum
How to use checksums
6ec32aa2dce18b99182a36df4fa8c24f2df72bb1da03c16374f6c1b368bc839b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release history Release notifications | RSS feed

This release

0.0.19 This release

1 release file

0.0.18

1 release file

0.0.17

1 release file

0.0.16

1 release file

0.0.14

1 release file

0.0.13

2 release files

0.0.12

1 release file

0.0.11

1 release file

0.0.10

2 release files

0.0.9

1 release file

0.0.8

1 release file

0.0.6

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page