{"id":13648318,"url":"https://github.com/cmusphinx/g2p-seq2seq","last_synced_at":"2025-05-11T07:22:01.633Z","repository":{"id":48169881,"uuid":"57041432","full_name":"cmusphinx/g2p-seq2seq","owner":"cmusphinx","description":"G2P with Tensorflow","archived":false,"fork":false,"pushed_at":"2024-07-29T10:50:34.000Z","size":887,"stargazers_count":672,"open_issues_count":46,"forks_count":192,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-04-22T07:45:34.921Z","etag":null,"topics":["cmudict","g2p","g2p-seq2seq"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cmusphinx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-04-25T12:53:41.000Z","updated_at":"2025-04-18T10:21:28.000Z","dependencies_parsed_at":"2025-04-22T07:37:07.676Z","dependency_job_id":"4628feba-0422-4467-8b63-3021cccf086e","html_url":"https://github.com/cmusphinx/g2p-seq2seq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2Fg2p-seq2seq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2Fg2p-seq2seq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2Fg2p-seq2seq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmusphinx%2Fg2p-seq2seq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmusphinx","download_url":"https://codeload.github.com/cmusphinx/g2p-seq2seq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253530007,"owners_count":21922787,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmudict","g2p","g2p-seq2seq"],"created_at":"2024-08-02T01:04:08.387Z","updated_at":"2025-05-11T07:22:01.615Z","avatar_url":"https://github.com/cmusphinx.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/cmusphinx/g2p-seq2seq.svg?branch=master)](https://travis-ci.org/cmusphinx/g2p-seq2seq)\n\n# Sequence-to-Sequence G2P toolkit\n\nThe tool does Grapheme-to-Phoneme (G2P) conversion using transformer model\nfrom tensor2tensor toolkit [1]. A lot of approaches in sequence modeling and\ntransduction problems use recurrent neural networks. But, transformer model\narchitecture eschews recurrence and instead relies entirely on an attention\nmechanism to draw global dependencies between input and output [2].\n\nThis implementation is based on python\n[TensorFlow](https://www.tensorflow.org/tutorials/seq2seq/),\nwhich allows an efficient training on both CPU and GPU.\n\n## Installation\n\nThe tool requires TensorFlow at least version 1.8.0 and Tensor2Tensor version 1.6.6 or higher. Please see the installation\n[guide](https://www.tensorflow.org/install/)\nfor TensorFlow installation details, and details about the Tensor2Tensor installation see [guide](https://github.com/tensorflow/tensor2tensor)\n\n\nThe g2p-seq2seq package itself uses setuptools, so you can follow standard installation process:\n\n```\nsudo python setup.py install\n```\n\nYou can also run the tests\n\n```\npython setup.py test\n```\n\nThe runnable script `g2p-seq2seq` is installed in  `/usr/local/bin` folder by default (you can adjust it with `setup.py` options if needed) . You need to make sure you have this folder included in your `PATH` so you can run this script from command line.\n\n## Running G2P\n\nA pretrained 3-layer transformer model with 256 hidden units is [available for download on cmusphinx website](https://sourceforge.net/projects/cmusphinx/files/G2P%20Models/g2p-seq2seq-model-6.2-cmudict-nostress.tar.gz/download).\nUnpack the model after download. The model is trained on [CMU English dictionary](http://github.com/cmusphinx/cmudict)\n\n```\nwget -O g2p-seq2seq-cmudict.tar.gz https://sourceforge.net/projects/cmusphinx/files/G2P%20Models/g2p-seq2seq-model-6.2-cmudict-nostress.tar.gz/download\ntar xf g2p-seq2seq-cmudict.tar.gz\n```\n\nThe easiest way to check how the tool works is to run it the interactive mode and type the words\n\n```\n$ g2p-seq2seq --interactive --model_dir model_folder_path\n...\n\u003e hello\n...\nPronunciations: [HH EH L OW]\n...\n\u003e\n```\n\nTo generate pronunciations for an English word list with a trained model, run\n\n```\n  g2p-seq2seq --decode your_wordlist --model_dir model_folder_path [--output decode_output_file_path]\n```\n\nThe wordlist is a text file with one word per line\n\nIf you wish to list top N variants of decoding, set return_beams flag and specify beam_size:\n\n```\n  g2p-seq2seq --decode your_wordlist --model_dir model_folder_path --return_beams --beam_size number_returned_beams [--output decode_output_file_path]\n```\n\nTo evaluate Word Error Rate of the trained model, run\n\n```\n  g2p-seq2seq --evaluate your_test_dictionary --model_dir model_folder_path\n```\n\nThe test dictionary should be a dictionary in standard format:\n```\nhello HH EH L OW\nbye B AY\n```\n\nYou may also calculate Word Error Rate considering all top N best decoded results. In this case we consider word decoding as error only if none of the decoded pronunciations will match with the ground true pronunciation of the word.\n\n## Training G2P system\n\nTo train G2P you need a dictionary (word and phone sequence per line).\nSee an [example dictionary](http://github.com/cmusphinx/cmudict)\n\n```\n  g2p-seq2seq --train train_dictionary.dic --model_dir model_folder_path\n```\n\nYou can set up maximum training steps:\n```\n  \"--max_epochs\" - Maximum number of training epochs (Default: 0).\n     If 0 train until no improvement is observed\n```\n\nIt is a good idea to play with the following parameters:\n```\n  \"--size\" - Size of each model layer (Default: 256).\n\n  \"--num_layers\" - Number of layers in the model (Default: 3).\n\n  \"--filter_size\" - The size of the filter layer in a convolutional layer (Default: 512)\n\n  \"--num_heads\" - Number of applied heads in Multi-attention mechanism (Default: 4)\n```\n\nYou can manually point out Development and Test datasets:\n```\n  \"--valid\" - Development dictionary (Default: created from train_dictionary.dic)\n  \"--test\" - Test dictionary (Default: created from train_dictionary.dic)\n```\n\nOtherwise, The program will split the dataset that you feed to it in the training mode itself. In the directory with the training data you will find three data files with the following extensions: \".train\", \".dev\" and \".test\".\n\nIn the case where you have raw dictionary with stress (for example, like in [CMU English dictionary](http://github.com/cmusphinx/cmudict)), you may set the following parameter while launching the train mode:\n```\n  \"--cleanup\" - Set to True to cleanup dictionary from stress and comments.\n```\n\nIf you need to continue training a saved model just point out the directory with the existing model:\n```\n  g2p-seq2seq --train train_dictionary.dic --model_dir model_folder_path\n```\n\nAnd, if you want to start training from scratch:\n```\n  \"--reinit\" - Rewrite model in model_folder_path\n```\n\nAlso, in case of solving inverse problem:\n```\n  \"--p2g\" - Run the program in a phoneme-to-grapheme conversion mode.\n```\n\nThe differences in pronunciations between short and long words can be significant. So, seq2seq models apply bucketing technique to take account of such problems. On the other hand, splitting initial data into too many buckets can worsen the final results. Because in this case there will not be sufficient amount of examples in each particular bucket. To get better results, you may tune the following three parameters that change the number and size of the buckets:\n```\n  \"--min_length_bucket\" - the size of the minimal bucket (Default: 6)\n  \"--max_length\" - maximal possible length of words or maximal number of phonemes in pronunciations (Default: 30)\n  \"--length_bucket_step\" - multiplier that controls the number of length buckets in the data. The buckets have maximum lengths from min_bucket_length to max_length, increasing by factors of length_bucket_step (Default: 1.5)\n```\n\nAfter training the model, you may freeze it:\n```\n  g2p-seq2seq --model_dir model_folder_path --freeze\n```\n\nFile \"frozen_model.pb\" will appear in \"model_folder_path\" directory after launching previous command. And now, if you run one of the decoding modes, The program will load and use this frozen graph.\n\n\n#### Word error rate on CMU dictionary data sets\n\nSystem | WER ([CMUdict PRONASYL 2007](https://sourceforge.net/projects/cmusphinx/files/G2P%20Models/phonetisaurus-cmudict-split.tar.gz)), % | WER ([CMUdict latest\\*](https://github.com/cmusphinx/cmudict)), %\n--- | --- | ---\nBaseline WFST (Phonetisaurus) | 24.4 | 33.89\nTransformer num_layers=3, size=256   | 20.6 | 30.2\n\\* These results pointed out for dictionary without stress.\n\n## References\n---------------------------------------\n\n[1] Lukasz Kaiser. \"Accelerating Deep Learning Research with the Tensor2Tensor Library.\" In Google Research Blog, 2017.\n\n[2] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lucasz Kaiser, and Illia Polosukhin. \"Attention Is All You Need.\"\narXiv preprint\narXiv:1706.03762, 2017.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmusphinx%2Fg2p-seq2seq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmusphinx%2Fg2p-seq2seq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmusphinx%2Fg2p-seq2seq/lists"}