https://github.com/archinetai/aligner-pytorch
Sequence alignement methods with helpers for PyTorch.
https://github.com/archinetai/aligner-pytorch
Last synced: about 2 months ago
JSON representation
Sequence alignement methods with helpers for PyTorch.
- Host: GitHub
- URL: https://github.com/archinetai/aligner-pytorch
- Owner: archinetai
- License: mit
- Created: 2022-10-20T10:10:04.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-30T07:18:49.000Z (over 2 years ago)
- Last Synced: 2025-03-21T03:34:25.534Z (2 months ago)
- Language: Python
- Homepage:
- Size: 215 KB
- Stars: 24
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Aligner - PyTorch
Sequence alignement methods with helpers for PyTorch.
## Install
```bash
pip install aligner-pytorch
```[](https://pypi.org/project/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.
```py
from aligner_pytorch import massim = 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.
```py
from aligner_pytorch import get_alignment_from_embeddingsx_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.
```py
from aligner_pytorch import get_alignment_from_duration_embeddingalignment = 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
```bibtex
@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},
}
```