NoAtt (rnn/attentions.py)

FunASR · funasr/models/language_model/rnn/attentions.py · python · MIT
voice

RNN attention modules for speech synthesis and NLP models.

# Source: https://github.com/modelscope/FunASR | License: MIT | Copyright 2025 FunASR
# Provided via justclaw.it.com; keep this notice with the code.
"""Attention modules for RNN."""

import math
import six

import torch
import torch.nn.functional as F

from funasr.models.transformer.utils.nets_utils import make_pad_mask
from funasr.models.transformer.utils.nets_utils import to_device


def _apply_attention_constraint(e, last_attended_idx, backward_window=1, forward_window=3):
    """Apply monotonic attention constraint.

    This function apply the monotonic attention constraint
    introduced in `Deep Voice 3: Scaling
    Text-to-Speech with Convolutional Sequence Learning`_.

    Args:
        e (Tensor): Attention energy before applying softmax (1, T).
        last_attended_idx (int): 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key