← All projects

Grapheme-to-Phoneme (G2P) Conversion

June 1, 2022
PythonPyTorchSequence-to-SequenceAttention MechanismSpeech ProcessingDeep LearningNLP

Sequence-to-sequence model with attention mechanism for converting written text to phonetic representations.

Implementation of a sequence-to-sequence model with attention mechanism for Grapheme-to-Phoneme (G2P) conversion — the task of converting written text (graphemes) to their phonetic representations (phonemes).


Introduction

Grapheme-to-Phoneme conversion is a fundamental task in speech processing, essential for:

  • Text-to-Speech (TTS) Systems: Converting text input to pronunciation for speech synthesis
  • Automatic Speech Recognition: Mapping recognized phonemes back to text
  • Pronunciation Dictionaries: Generating phonetic transcriptions for new words

Architecture

Encoder-Decoder with Attention

The model uses a classic sequence-to-sequence architecture:

Input: "hello" (graphemes: h-e-l-l-o)
  ↓
Encoder LSTM → Hidden States
  ↓
Bahdanau Attention
  ↓
Decoder LSTM → Output Sequence
  ↓
Output: "HH AH0 L OW1" (phonemes in ARPAbet)

Key Components

  1. Bidirectional Encoder: Captures context from both directions of the input sequence
  2. Bahdanau Attention: Learns to focus on relevant input characters for each output phoneme
  3. Decoder with Teacher Forcing: Generates phoneme sequence with training stabilization

Features

  • Clean, modular PyTorch implementation
  • Training scripts with configurable hyperparameters

Results

NoneAccuracy (Token)Accuracy (Word)Word Error Rate
Training Dataset99.74%94.09%0.82%
Evaluate (Dev) Dataset99.52%93.77%0.93%

Applications

This G2P model can be integrated into:

  • Custom TTS pipelines
  • Pronunciation learning apps
  • Linguistic research tools

Repository

Code and pretrained models: https://github.com/QuyAnh2005/Grapheme-To-Phoneme