TensorFlowASR

repository·main·Indexed 21 days ago

https://github.com/tensorspeech/tensorflowasr

A library for implementing state-of-the-art Automatic Speech Recognition (ASR) architectures in TensorFlow 2. It supports end-to-end models including Conformer, Jasper, DeepSpeech2, and RNN Transducer, with support for TFLite conversion for efficient deployment. The library includes tools for speech feature extraction via NumpySpeechFeaturizer and TFSpeechFeaturizer, various tokenizers (Character, Wordpiece, Sentencepiece), and built-in augmentations like SpecAugment.

Tokens
5K
Snippets
17
Records
32
Agent score
74%

What's inside TensorFlowASR

  1. RNN Transducer Subwords (v1.0.x) Model Details

    main

    This record provides the technical specifications and training metrics for the RNN Transducer Subwords model (v1.0.x). This model uses a subword vocabulary for speech recognition tasks.

    Model Specifications

    • Subword Vocabulary Size: 1008
    • Maximum Subword Length: 10
    • Total Parameters: 54,914,480
    • Training Corpus: All training sets

    Training Performance (v1.0.x)

    • Training Duration: Approximately 94.5 hours continuous (or ~10.5 days using Google Colab TPUs with 12-hour daily limits).
    • Training Hardware: 8 Google Colab TPUs.
    • Training Epochs: 21 (standard) or 25 (for improved error rates).

    Error Rates (Greedy Decoding)

    Test SetBatch SizeEpochWER (%)CER (%)
    Test-clean82113.1396.023
    Test-clean82512.7945.671

    Note: WER = Word Error Rate, CER = Character Error Rate.

  2. Supported ASR Architectures and Models

    main

    TensorFlowASR supports several Automatic Speech Recognition (ASR) architectures, categorized into two main baseline types:

    Transducer Models

    End-to-end models using RNNT Loss for training. Supported architectures include:

    • Conformer (See examples/models/transducer/conformer)
    • Streaming Conformer (See examples/models/transducer/conformer)
    • ContextNet (See examples/models/transducer/contextnet)
    • RNN Transducer (See examples/models/transducer/rnnt)
    • Streaming Transducer

    CTC Models

    End-to-end models using CTC Loss for training. Supported architectures include:

    • DeepSpeech2 (See examples/models/ctc/deepspeech2)
    • Jasper (See examples/models/ctc/jasper)

    All models can be converted to TFLite to reduce memory and computation for deployment.

  3. Configure training with Jinja2 YAML templates

    main

    Configuration files use the .yml.j2 extension, meaning they are Jinja2 templates containing YAML content. This allows you to import and compose configurations from different modules, such as decoder settings and model architectures.

    Example of a composed config file:

    {% import "examples/datasets/librispeech/sentencepiece/sp.yml.j2" as decoder_config with context %}
    {{decoder_config}}
    
    {% import "examples/models/transducer/conformer/small.yml.j2" as config with context %}
    {{config}}
  4. Use the Sentencepiece Tokenizer

    main

    The Sentencepiece Tokenizer splits an entire sentence directly into subwords and maps each subword to an index.

    Key details:

    • The blank token can be set to at index 0.
    • Best use case: Languages with a large vocabulary where words are combinations of other words; it is applicable to any language.
  5. Extract speech features from signals

    main

    Speech features are extracted from a raw signal using a TensorFlow Keras layer. The extraction process is parameterized by sample_rate, frame_ms, stride_ms, and num_feature_bins.

    The resulting feature tensor has the shape (B, T, num_feature_bins, num_channels), where:

    • B: Batch size
    • T: Time frames
    • num_feature_bins: Number of frequency bins
    • num_channels: Number of feature types (1-4 channels)

    Supported feature channels include:

    1. Spectrogram, Log Mel Spectrogram, Log Gammatone Spectrogram, or MFCCs.
    2. Delta features (derived from channel 1).
    3. Delta-delta features (second-order deltas derived from channel 1).
    4. Pitch features (e.g., via librosa.core.piptrack).

    For the specific implementation details, refer to the feature_extraction.py module.

    # Note: The specific API call depends on the implementation in feature_extraction.py
    # Expected shape: (B, T, num_feature_bins, num_channels)
  6. Use the Wordpiece Tokenizer

    main

    The Wordpiece Tokenizer splits text into words and then further decomposes those words into subwords before mapping them to indices.

    Key details:

    • The blank token can be set to at index 0.
    • Best use case: Languages with a large vocabulary where words are combinations of other words; it is applicable to any language.
    • Variants:
      • Wordpiece split by whitespace.
      • Wordpiece where whitespace is treated as a separate token.
  7. Use the Character Tokenizer

    main

    The Character Tokenizer splits text into individual characters and maps each to an index.

    Key details:

    • The index starts from 1.
    • The index 0 is reserved for the blank token.
    • Best use case: Languages with a small number of characters where characters are not combinations of other characters (e.g., English, Vietnamese).

    Refer to the librespeech configuration templates for implementation details.

  8. Perform streaming inference with TFLite

    main

    To support streaming inference, use the model's output states to feed the next chunk of audio.

    For each chunk of audio signal, the model produces outputs that include next_tokens, next_encoder_states, and next_decoder_states. To continue the stream, overwrite the current previous_tokens, previous_encoder_states, and previous_decoder_states with these next_* values before processing the next audio chunk.

    schemas.PredictOutputWithTranscript(
        transcript=self.tokenizer.detokenize(outputs.tokens),
        tokens=outputs.tokens,
        next_tokens=outputs.next_tokens,
        next_encoder_states=outputs.next_encoder_states,
        next_decoder_states=outputs.next_decoder_states,
    )
  9. Create TFRecords (Required for TPU)

    main

    If you are training on TPUs, you must create tfrecords datasets. You can use the tensorflow_asr utils create_tfrecords command to convert your data. You can specify which modes to generate using the --mode flag (e.g., ["train","eval"]).

    tensorflow_asr utils create_tfrecords \
        --config-path=/path/to/config.yml.j2 \
        --mode=["train","eval","test"] \
        --datadir=/path/to/datadir
  10. Convert models to TFLite format

    main

    Use the tensorflow_asr tflite CLI command to convert a trained Keras model (.h5) into a TensorFlow Lite (.tflite) file.

    Key parameters:

    • --config-path: Path to the model configuration file (.yml.j2).
    • --h5: Path to the trained weights file.
    • --bs: Batch size (typically 1 for mobile/edge inference).
    • --beam-width: Set to 0 for greedy search, or >0 to enable beam search.
    • --output: Destination path for the .tflite file.
    tensorflow_asr tflite \
        --config-path=/path/to/config.yml.j2 \
        --h5=/path/to/weight.h5 \
        --bs=1 \
        --beam-width=0 \
        --output=/path/to/output.tflite
  11. Configure testing with Jinja2 YAML templates

    main

    Configuration files use the config.yml.j2 format, which is a Jinja2 template containing YAML content. The testing configuration should be identical to the configuration used during training. It defines inputs, outputs, and vocabulary options. You can use Jinja2 imports to compose configurations from existing templates found in examples/*/*.yml.j2.

    {% import "examples/datasets/librispeech/sentencepiece/sp.yml.j2" as decoder_config with context %}
    {{decoder_config}}
    
    {% import "examples/models/transducer/conformer/small.yml.j2" as config with context %}
    {{config}}