pytorch / audio

Data manipulation and transformation for audio signal processing, powered by PyTorch
https://pytorch.org/audio
BSD 2-Clause "Simplified" License
2.43k stars 636 forks source link

Fail to align numbers #3713

Open amorin-gladia opened 7 months ago

amorin-gladia commented 7 months ago

šŸ› Describe the bug

Using MMS_FA to get word timestamp from transcription, I get very strange result from spoken numbers (in english here below). The numbers are neither detected and probabilities are very low for this words, all of them.

For example, using the simple audio "http://files.gladia.io/aligner/issue/date.wav" with awaited transcript "today is february eight two thousand nineteen", only "today is february" is detected. This is reproducible with other files including years.

This is code to simply reproduce it:

import math
import os
import requests
import torch
import torchaudio
import matplotlib.pyplot as plt

def run_example():
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    bundle = torchaudio.pipelines.MMS_FA

    audio_url = 'http://files.gladia.io/aligner/issue/date.wav'
    file_name = audio_url.split('/')[-1]
    with open(os.path.join('.', file_name), 'wb') as file:
        file.write(requests.get(audio_url).content)

    emission = get_emission(file_name, bundle, device)

    plot_emission(emission, file_name)

    DICTIONARY = bundle.get_dict(star=None)
    REVERSE_DICTIONARY = {v: k for k, v in DICTIONARY.items()}

    for emis in emission[0]:
        emis_list = emis.tolist()
        max_value = max(emis_list)
        corresponding_token = REVERSE_DICTIONARY[emis_list.index(max_value)]
        corresponding_prob = math.exp(max_value)
        print(corresponding_token, f"{corresponding_prob:.2f}")

def get_emission(audio_path: str, bundle, device: str) -> torch.Tensor:
    waveform, _ = torchaudio.load(audio_path)
    model = bundle.get_model(with_star=False).to(device)
    with torch.inference_mode():
        emission, _ = model(waveform.to(device))
        return emission

def plot_emission(emission, filename):
    emission_np = emission.cpu().numpy()
    fig, ax = plt.subplots(figsize=(20,5))
    im = ax.imshow(emission_np.T, aspect='auto', origin='lower', cmap='viridis')
    ax.set_title("Frame-wise class probabilities")
    ax.set_xlabel("Time")
    ax.set_ylabel("Labels")
    cbar = plt.colorbar(im)
    cbar.set_label('Probability')
    fig.tight_layout()
    plt.savefig(f"./{filename}.png")

Emission visualization:

date wav

Output:

- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
t 0.99
- 1.00
- 1.00
- 1.00
o 0.93
- 1.00
- 1.00
- 1.00
- 1.00
d 0.97
- 1.00
- 1.00
- 1.00
- 1.00
a 0.99
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
y 0.95
- 0.99
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
i 0.97
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
s 0.98
- 0.99
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
f 1.00
- 1.00
- 1.00
- 1.00
- 1.00
e 0.99
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
b 0.99
- 0.99
r 0.65
- 0.62
- 0.97
u 0.91
- 0.99
- 0.99
- 0.99
- 1.00
- 1.00
- 1.00
- 1.00
a 0.96
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
r 0.98
- 1.00
- 1.00
y 0.98
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 0.99
- 0.99
- 0.99
- 0.99
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00
- 1.00

Versions

PyTorch version: 2.1.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: Could not collect
CMake version: version 3.27.7
Libc version: glibc-2.31

Python version: 3.10.13 (main, Nov 20 2023, 13:31:06) [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-156-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: Tesla V100S-PCIE-32GB
Nvidia driver version: 525.147.05
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   40 bits physical, 48 bits virtual
CPU(s):                          15
On-line CPU(s) list:             0-14
Thread(s) per core:              1
Core(s) per socket:              1
Socket(s):                       15
NUMA node(s):                    1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           85
Model name:                      Intel(R) Xeon(R) Gold 6226R CPU @ 2.90GHz
Stepping:                        7
CPU MHz:                         2893.208
BogoMIPS:                        5786.41
Virtualization:                  VT-x
Hypervisor vendor:               KVM
Virtualization type:             full
L1d cache:                       480 KiB
L1i cache:                       480 KiB
L2 cache:                        60 MiB
L3 cache:                        240 MiB
NUMA node0 CPU(s):               0-14
Vulnerability Itlb multihit:     KVM: Mitigation: Split huge pages
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Retbleed:          Mitigation; Enhanced IBRS
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat umip pku ospke avx512_vnni md_clear arch_capabilities

Versions of relevant libraries:
[pip3] gladiaio-torchaudio==2.1.0a0
[pip3] numpy==1.23.5
[pip3] onnx==1.15.0
[pip3] onnxconverter-common==1.14.0
[pip3] onnxmltools==1.11.2
[pip3] onnxruntime-gpu==1.15.1
[pip3] skl2onnx==1.15.0
[pip3] torch==2.1.0
[pip3] torchaudio==2.1.0
[pip3] triton==2.1.0
[conda] Could not collect
jsoto-gladia commented 4 months ago

+1