conformer

sooftwareApache-2.0更新放缓

Conformer 的 PyTorch 非官方实现,把卷积和 Transformer 结合起来做语音识别,适合直接拿来训练或复现 ASR 模型。

[Unofficial] PyTorch implementation of "Conformer: Convolution-augmented Transformer for Speech Recognition" (INTERSPEECH 2020)

v1.0-zenodo发布于 2026-01-05 14:11 UTC1,137star192fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
pip install -e .
硬件要求按 README 说明

README 未说明显存要求;示例代码用 torch.cuda.is_available() 自动选择 GPU 或 CPU,因此可在 CPU 上运行

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Conformer 语音识别模型的 PyTorch 实现,只含模型代码,可直接嵌入自己的训练流程

Conformer 的 PyTorch 非官方实现,把卷积和 Transformer 结合起来做语音识别,适合直接拿来训练或复现 ASR 模型。

核心能力

  • 用卷积加 Transformer 同时建模音频的局部与全局依赖
  • 提供 Conformer 类,传入 num_classes、input_dim、encoder_dim 等参数即可实例化
  • 前向返回 outputs 与 output_lengths,可直接接 nn.CTCLoss 训练
  • 遵循 PEP-8 代码风格,docstring 规范便于生成文档

容易踩的坑

仓库只含模型代码,完整训练需配合 openspeech 项目;需自行安装 numpy 和与环境匹配的 PyTorch 版本;仅支持从源码用 setuptools 安装,未提供 pip 包

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

2 个版本v1.0-zenodo
  1. v1.0-zenodoZonodo release最新正式版2026-01-05 · 2026-01-05 14:11 UTC

    Zonodo release

  2. v1.02022-02-21 · 2022-02-21 02:45 UTC
    查看更新说明
    • Conformer encoder only
    • Update README.md (example with CTC loss)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    PyTorch implementation of Conformer: Convolution-augmented Transformer for Speech Recognition.


    Transformer models are good at capturing content-based global interactions, while CNNs exploit local features effectively. Conformer combine convolution neural networks and transformers to model both local and global dependencies of an audio sequence in a parameter-efficient way. Conformer significantly outperforms the previous Transformer and CNN based models achieving state-of-the-art accuracies.

    This repository contains only model code, but you can train with conformer at openspeech

    Installation

    This project recommends Python 3.7 or higher. We recommend creating a new virtual environment for this project (using virtual env or conda).

    Prerequisites

    • Numpy: pip install numpy (Refer here for problem installing Numpy).
    • Pytorch: Refer to PyTorch website to install the version w.r.t. your environment.

    Install from source

    Currently we only support installation from source code using setuptools. Checkout the source code and run the following commands:

    pip install -e .
    

    Usage

    import torch
    import torch.nn as nn
    from conformer import Conformer
    
    batch_size, sequence_length, dim = 3, 12345, 80
    
    cuda = torch.cuda.is_available()  
    device = torch.device('cuda' if cuda else 'cpu')
    
    criterion = nn.CTCLoss().to(device)
    
    inputs = torch.rand(batch_size, sequence_length, dim).to(device)
    input_lengths = torch.LongTensor([12345, 12300, 12000])
    targets = torch.LongTensor([[1, 3, 3, 3, 3, 3, 4, 5, 6, 2],
                                [1, 3, 3, 3, 3, 3, 4, 5, 2, 0],
                                [1, 3, 3, 3, 3, 3, 4, 2, 0, 0]]).to(device)
    target_lengths = torch.LongTensor([9, 8, 7])
    
    model = Conformer(num_classes=10, 
                      input_dim=dim, 
                      encoder_dim=32, 
                      num_encoder_layers=3).to(device)
    
    # Forward propagate
    outputs, output_lengths = model(inputs, input_lengths)
    
    # Calculate CTC Loss
    loss = criterion(outputs.transpose(0, 1), targets, output_lengths, target_lengths)
    

    Troubleshoots and Contributing

    If you have any questions, bug reports, and feature requests, please open an issue on github or
    contacts [email protected] please.

    I appreciate any kind of feedback or contribution. Feel free to proceed with small issues like bug fixes, documentation improvement. For major contributions and new features, please discuss with the collaborators in corresponding issues.

    Code Style

    I follow PEP-8 for code style. Especially the style of docstrings is important to generate documentation.

    Reference

    Author