{"id":13715267,"url":"https://github.com/ottokart/punctuator2","last_synced_at":"2025-05-07T04:30:40.019Z","repository":{"id":43959248,"uuid":"54600309","full_name":"ottokart/punctuator2","owner":"ottokart","description":"A bidirectional recurrent neural network model with attention mechanism for restoring missing punctuation in unsegmented text","archived":false,"fork":false,"pushed_at":"2021-09-19T18:47:39.000Z","size":57,"stargazers_count":643,"open_issues_count":62,"forks_count":194,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-02-17T08:34:50.888Z","etag":null,"topics":["attention","demo","punctuation","recurrent-neural-networks","theano"],"latest_commit_sha":null,"homepage":"http://bark.phon.ioc.ee/punctuator","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ottokart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-23T23:34:56.000Z","updated_at":"2024-02-09T19:55:06.000Z","dependencies_parsed_at":"2022-08-28T03:11:45.128Z","dependency_job_id":null,"html_url":"https://github.com/ottokart/punctuator2","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ottokart%2Fpunctuator2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ottokart%2Fpunctuator2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ottokart%2Fpunctuator2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ottokart%2Fpunctuator2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ottokart","download_url":"https://codeload.github.com/ottokart/punctuator2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252813616,"owners_count":21808360,"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":["attention","demo","punctuation","recurrent-neural-networks","theano"],"created_at":"2024-08-03T00:00:56.904Z","updated_at":"2025-05-07T04:30:39.721Z","avatar_url":"https://github.com/ottokart.png","language":"Python","readme":"**[DEMO](http://bark.phon.ioc.ee/punctuator)** and **[DEMO2](http://bark.phon.ioc.ee/punctuator/game)**\n\n# Punctuator\n\nA bidirectional recurrent neural network model with attention mechanism for restoring missing inter-word punctuation in unsegmented text.\n\nThe model can be trained in two stages (second stage is optional):\n\n1. First stage is trained on punctuation annotated text. Here the model learns to restore puncutation based on textual features only.\n2. Optional second stage can be trained on punctuation *and* pause annotated text. In this stage the model learns to combine pause durations with textual features and adapts to the target domain. If pauses are omitted then only adaptation is performed. Second stage with pause durations can be used for example for restoring punctuation in automatic speech recognition system output.\n\n# How well does it work?\n\n* A working demo can be seen here: http://bark.phon.ioc.ee/punctuator\n* You can try to compete with this model here: http://bark.phon.ioc.ee/punctuator/game\n\nRemember that all the scores given below are on _unsegmented_ text and we did not use prosodic features, so, among other things, the model has to detect sentence boundaries in addition to the boundary type (?QUESTIONMARK, .PERIOD or !EXCLAMATIONMARK) based entirely on textual features. The scores are computed on the test set.\n\nTraining speed with default settings, an optimal Theano installation and a modern GPU should be around 10000 words per second.\n\nPretrained models can be downloaded [here](https://drive.google.com/drive/folders/0B7BsN5f2F1fZQnFsbzJ3TWxxMms?resourcekey=0-6yhuY9FOeITBBWWNdyG2aw\u0026usp=sharing) (Demo + 2 models from the Interspeech paper).\n\n## English TED talks\nTraining set size: 2.1M words. First stage only. More details can be found in [this paper](http://www.isca-speech.org/archive/Interspeech_2016/pdfs/1517.PDF).\nFor comparison, our [previous model](https://github.com/ottokart/punctuator) got an overall F1-score of 50.8.\n\nPUNCTUATION      | PRECISION | RECALL    | F-SCORE\n--- | --- | --- | ---\n,COMMA           | 64.4 | 45.2 | 53.1\n?QUESTIONMARK    | 67.5 | 58.7 | 62.8\n.PERIOD          | 72.3 | 71.5 | 71.9\n_Overall_        | _68.9_ | _58.1_ | _63.1_\n\n## English Europarl v7\nTraining set size: 40M words. First stage only. Details in [./example](https://github.com/ottokart/punctuator2/tree/master/example).\n\nYou can try to compete with this model [here](http://bark.phon.ioc.ee/punctuator/game).\n\nPUNCTUATION      | PRECISION | RECALL    | F-SCORE\n---              | ---       | ---       | ---\n?QUESTIONMARK    | 77.7      |  73.2     |  75.4\n!EXCLAMATIONMARK | 50.0      |  0.1      |  0.1\n,COMMA           | 68.9      |  72.0     |  70.4\n-DASH            | 55.9      |  8.8      |  15.2\n:COLON           | 60.9      |  23.8     |  34.2\n;SEMICOLON       | 44.7      |  1.1      |  2.2\n.PERIOD          | 84.7      |  84.1     |  84.4\n_Overall_        | _75.7_    | _73.9_    | _74.8_\n\n# Requirements\n* Python 2.7\n* Numpy\n* Theano\n\n# Requirements for data:\n\n* Cleaned text files for training and validation of the first phase model. Each punctuation symbol token must be surrounded by spaces.\n\n  Example:\n  ```to be ,COMMA or not to be ,COMMA that is the question .PERIOD```\n* *(Optional)* Pause annotated text files for training and validation of the second phase model. These should be cleaned in the same way as the first phase data. Pause durations in seconds should be marked after each word with a special tag `\u003csil=0.200\u003e`. Punctuation mark, if any, must come after the pause tag.\n\n  Example:\n  ```to \u003csil=0.000\u003e be \u003csil=0.100\u003e ,COMMA or \u003csil=0.000\u003e not \u003csil=0.000\u003e to \u003csil=0.000\u003e be \u003csil=0.150\u003e ,COMMA that \u003csil=0.000\u003e is \u003csil=0.000\u003e the \u003csil=0.000\u003e question \u003csil=1.000\u003e .PERIOD```\n\n  Second phase data can also be without pause annotations to do just target domain adaptation.\n  \nMake sure that first words of sentences don't have capitalized first letters. This would give the model unfair hints about period locations. Also, the text files you use for training and validation must be large enough (at least minibatch_size x sequence_length of words, which is 128x50=6400 words with default settings), otherwise you might get an error.\n\n# Configuration\nVocabulary size, punctuation tokens and their mappings, and converted data location can be configured in the header of data.py.\nSome model hyperparameters can be configured in the headings of main.py and main2.py. Learning rate and hidden layer size can be passed as arguments.\n\n# Usage\n\nFirst step is data conversion. Assuming that preprocessed and cleaned *.train.txt, *.dev.txt and *.test.txt files are located in `\u003cdata_dir\u003e`, the conversion can be initiated with:\n\n`python data.py \u003cdata_dir\u003e`\n\nIf you have second stage data as well, then:\n\n`python data.py \u003cdata_dir\u003e \u003csecond_stage_data_dir\u003e`\n\n\n\nThe first stage can be trained with:\n\n`python main.py \u003cmodel_name\u003e \u003chidden_layer_size\u003e \u003clearning_rate\u003e`\n\ne.g `python main.py \u003cmodel_name\u003e 256 0.02` works well.\n\n\n\nSecond stage can be trained with:\n\n`python main2.py \u003cmodel_name\u003e \u003chidden_layer_size\u003e \u003clearning_rate\u003e \u003cfirst_stage_model_path\u003e`\n\n\n\nPreprocessed text can be punctuated with e.g:\n\n`cat data.dev.txt | python punctuator.py \u003cmodel_path\u003e \u003cmodel_output_path\u003e`\n\nor, if pause annotations are present in data.dev.txt and you have a second stage model trained on pause annotated data, then:\n\n`cat data.dev.txt | python punctuator.py \u003cmodel_path\u003e \u003cmodel_output_path\u003e 1`\n\nPunctuation tokens in data.dev.txt don't have to be removed - the punctuator.py script ignores them.\n\n\nError statistics in this example can be computed with:\n\n`python error_calculator.py data.dev.txt \u003cmodel_output_path\u003e`\n\n\nYou can play with a trained model with (assumes the input text is similarly preprocessed as the training data):\n\n`python play_with_model.py \u003cmodel_path\u003e`\n\nor with:\n\n`python play_with_model.py \u003cmodel_path\u003e 1`\n\nif you want to see, which words the model sees as UNKs (OOVs).\n\n\n# Citing\n\nThe software is described in:\n\n    @inproceedings{tilk2016,\n      author    = {Ottokar Tilk and Tanel Alum{\\\"a}e},\n      title     = {Bidirectional Recurrent Neural Network with Attention Mechanism for Punctuation Restoration},\n      booktitle = {Interspeech 2016},\n      year      = {2016}\n    }\n\nWe used the [release v1.0](https://github.com/ottokart/punctuator2/releases/tag/v1.0) in the paper.\n\n# Alternatives\n* Punctuator reimplemented in Tensorflow: https://github.com/cadia-lvl/punctuation-prediction/tree/master/punctuator2tf2\n* A fork from this repository that uses additional prosodic features: https://github.com/alpoktem/punkProse\n* Convolutional neural network with slightly smaller accuracy but much higher speed (50x faster): https://github.com/vackosar/keras-punctuator (additional details here: https://github.com/ottokart/punctuator2/issues/14)\n* A general sequence labeling model: https://github.com/marekrei/sequence-labeler that can be used for punctuation restoration with small modifications (example here: https://github.com/ottokart/sequence-labeler). Punctuator2 can be probably used for other sequence labeling problems as well.\n* Our previous approach with unidirectional LSTM (less accurate, but useful if you don't want to use Theano): https://github.com/ottokart/punctuator\n","funding_links":[],"categories":["List","Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fottokart%2Fpunctuator2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fottokart%2Fpunctuator2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fottokart%2Fpunctuator2/lists"}