{"id":25067003,"url":"https://github.com/shoyamanishi/tfstackdecoder","last_synced_at":"2026-05-16T17:36:44.968Z","repository":{"id":187800807,"uuid":"293335651","full_name":"ShoYamanishi/TFStackDecoder","owner":"ShoYamanishi","description":"A stack decoder for Tensorflow 2.x seq2seq models that generates N-Best.","archived":false,"fork":false,"pushed_at":"2020-09-19T14:34:29.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-20T22:54:35.154Z","etag":null,"topics":["decoder","nbest","seq2seq","tensorflow"],"latest_commit_sha":null,"homepage":"","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/ShoYamanishi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-06T18:13:44.000Z","updated_at":"2020-09-19T14:34:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"78c12f6c-7d34-4b7f-8cbb-09d6b0e966e9","html_url":"https://github.com/ShoYamanishi/TFStackDecoder","commit_stats":null,"previous_names":["shoyamanishi/tfstackdecoder"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ShoYamanishi/TFStackDecoder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShoYamanishi%2FTFStackDecoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShoYamanishi%2FTFStackDecoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShoYamanishi%2FTFStackDecoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShoYamanishi%2FTFStackDecoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShoYamanishi","download_url":"https://codeload.github.com/ShoYamanishi/TFStackDecoder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShoYamanishi%2FTFStackDecoder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33112064,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["decoder","nbest","seq2seq","tensorflow"],"created_at":"2025-02-06T20:29:02.212Z","updated_at":"2026-05-16T17:36:44.941Z","avatar_url":"https://github.com/ShoYamanishi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TFStackDecoder\nA stack decoder for Tensorflow 2.x seq2seq models that generates N-Best.\n\nI made it to retrieve N-best predicted sentences in the descending order of probability.\nThe predicited sentences can be similar in terms of edit distance.\nI want the same output always, given the same input, and therefore \n[tfa.seq2se2.BeamSearchDecoder](https://www.tensorflow.org/addons/api_docs/python/tfa/seq2seq/BeamSearchDecoder)\nis not suitable, as it uses sampling and designed to give variety of outputs.\n\nThe output will look like this:\n```\nInput: \u003cmcdonald\u003e\nPredicted translatons with probability (Nbest):\n[0.1748] \u003cマクドナルド\u003e\n[0.1044] \u003cマクダナルド\u003e\n[0.0557] \u003cマックドナルド\u003e\n[0.0546] \u003cマクダノルド\u003e\n[0.0400] \u003cマクダナード\u003e\n\n```\n\nIt assumes [the general RNN encoder-decoder framework](https://www.tensorflow.org/tutorials/text/nmt_with_attention).\n\nThe algorithm is based on the one given in Section 10.2 A^* (\"Stack\") Decoding in [JM09](https://www.pearson.com/us/higher-education/program/Jurafsky-Speech-and-Language-Processing-2nd-Edition/PGM181706.html).\n# Dependencies\n\n* [Tensorflow 2.x](https://www.tensorflow.org/)\n\n* [RedBlackTree](https://github.com/ShoYamanishi/RedBlackTree)\n\n\n# Contact\nFor any inquiries, please contact:\nShoichiro Yamanishi\n\nyamanishi72@gmail.com\n\n# Usage:\n\n```python\nfrom TFStackDecoder.stack_decoder import StackDecoder\nfrom TFStackDecoder.stack_decoder import StackDecoderPath\n\n# This is a replacement to evaluate() defined in the NMT tutorial\n# It does not generate data for attention plots.\n# It generates N-best sentences in the descending order of probability.\n\ndef evaluate_nbest(sentence):\n\n  sentence = preprocess_sentence(sentence)\n\n  inputs = [inp_lang.word_index[i] for i in sentence.split(' ')]\n  inputs = tf.keras.preprocessing.sequence.pad_sequences([inputs],\n                                                         maxlen=max_length_inp,\n                                                         padding='post')\n  inputs = tf.convert_to_tensor(inputs)\n\n  hidden = [tf.zeros((1, units))]\n  enc_out, enc_hidden = encoder(inputs, hidden)\n\n  dec_hidden = enc_hidden\n  dec_input = tf.expand_dims([targ_lang.word_index['\u003cstart\u003e']], 0)\n\n  BOS = [targ_lang.word_index['\u003cstart\u003e']\n  EOS = [targ_lang.word_index['\u003cend\u003e']\n\n  # Here decoder is assumed to have been defined as a GRU decoder\n  # with BahdanauAttention.\n  stack_decoder = StackDecoder(decoder, BOS, EOS, use_attn=True)\n\n  BEAM_WIDTH = 20\n  NUM_NBEST = 5\n  MAX_LEN = max_length_targ + 2 # this is defined early in the NMT tutorial.\n                                # + 2 is for BOS and EOS.\n  nbest_list = stack_decoder.NBest( enc_out, enc_hidden, BEAM_WIDTH, NUM_NBEST, MAX_LEN )\n\n  results = []\n  for r in nbest_list:\n    result = []\n    for i in r.sentence:\n      result.append( targ_lang.index_word[i] )\n    result = ' '.join(result)\n    results.append((r.log_prob, result))\n\n  return results, sentence\n```\n\n# References\n\n* NMT : [Neural machine translation with attention](https://www.tensorflow.org/tutorials/text/nmt_with_attention)\n\n* JM09 : Speech and Language Processing, 2nd., Daniel Jurafsky \u0026 James H. Martin, 2009 Pearson Education","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoyamanishi%2Ftfstackdecoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshoyamanishi%2Ftfstackdecoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoyamanishi%2Ftfstackdecoder/lists"}