code: def test_guided_attention_loss_mask(device):
      from speechbrain.nnet.loss.guidedattn_loss import (
          GuidedAttentionLoss,
      )
  
      loss = GuidedAttentionLoss().to(device)
      input_lengths = torch.tensor([3, 2, 6], device=device)
      output_lengths = torch.tensor([4, 3, 5], device=device)
      soft_mask = loss.guided_attentions(input_lengths, output_lengths)
      ref_soft_mask = torch.tensor(
          [
              [
                  [0.0, 0.54216665, 0.9560631, 0.9991162, 0.0],
                  [0.7506478, 0.08314464, 0.2933517, 0.8858382, 0.0],
                  [0.9961341, 0.8858382, 0.2933517, 0.08314464, 0.0],
                  [0.0, 0.0, 0.0, 0.0, 0.0],
                  [0.0, 0.0, 0.0, 0.0, 0.0],
                  [0.0, 0.0, 0.0, 0.0, 0.0],
              ],
              [
                  [0.0, 0.7506478, 0.9961341, 0.0, 0.0],
                  [0.9560631, 0.2933517, 0.2933517, 0.0, 0.0],
                  [0.0, 0.0, 0.0, 0.0, 0.0],
                  [0.0, 0.0, 0.0, 0.0, 0.0],
                  [0.0, 0.0, 0.0, 0.0, 0.0],
                  [0.0, 0.0, 0.0, 0.0, 0.0],
              ],
              [
                  [0.0, 0.39346933, 0.86466473, 0.988891, 0.99966455],
                  [
                      0.2933517,
                      0.01379288,
                      0.49366438,
                      0.90436554,
                      0.993355,
                  ],
                  [
                      0.7506478,
                      0.1992626,
                      0.05404053,
                      0.5888877,
                      0.93427145,
                  ],
                  [
                      0.9560631,
                      0.6753475,
                      0.1175031,
                      0.1175031,
                      0.6753475,
                  ],
                  [
                      0.9961341,
                      0.93427145,
                      0.5888877,
                      0.05404053,
                      0.1992626,
                  ],
                  [
                      0.9998301,
                      0.993355,
                      0.90436554,
                      0.49366438,
                      0.01379288,
                  ],
              ],
          ],
          device=device,
      )
      assert torch.allclose(soft_mask, ref_soft_mask)
  
file_path: speechbrain/tests/unittests/test_losses.py
imports: import torch
  import pytest
label_desc: Use image node_id 8 for calling a global function with example usage: test_guided_attention_loss_mask(device) without return types