{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/gedi-generative-discriminator-guided-sequence","title":"GeDi: Generative Discriminator Guided Sequence Generation","arxiv_id":"2009.06367","date":"2020-09-14","proceeding":"Findings (EMNLP) 2021 11","authors":["Ben Krause","Akhilesh Deepak Gotmare","Bryan McCann","Nitish Shirish Keskar","Shafiq Joty","Richard Socher","Nazneen Fatema Rajani"],"abstract":"While large-scale language models (LMs) are able to imitate the distribution of natural language well enough to generate realistic text, it is difficult to control which regions of the distribution they generate. This is especially problematic because datasets used for training large LMs usually contain significant toxicity, hate, bias, and negativity. We propose GeDi as an efficient method for using smaller LMs as generative discriminators to guide generation from large LMs to make them safer and more controllable. GeDi guides generation at each step by computing classification probabilities for all possible next tokens via Bayes rule by normalizing over two class-conditional distributions; one conditioned on the desired attribute, or control code, and another conditioned on the undesired attribute, or anti control code. We find that GeDi gives stronger controllability than the state of the art method while also achieving generation speeds more than 30 times faster. Additionally, training GeDi on only four topics allows us to controllably generate new topics zero-shot from just a keyword, unlocking a new capability that previous controllable generation methods do not have. Lastly, we show that GeDi can make GPT-2 (1.5B parameters) significantly less toxic without sacrificing linguistic quality, making it by far the most practical existing method for detoxifying large language models while maintaining a fast generation speed.","url_abs":"https://arxiv.org/abs/2009.06367v2","url_pdf":"https://arxiv.org/pdf/2009.06367v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"gedi-generative-discriminator-guided-sequence","repo_url":"https://github.com/salesforce/GeDi","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"BSD-3-Clause"}},{"paper_slug":"gedi-generative-discriminator-guided-sequence","repo_url":"https://github.com/johnr0/TaleBrush-backend","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"gedi-generative-discriminator-guided-sequence","repo_url":"https://github.com/yugaljain1999/biasfree_bot_GeDi","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"attribute","task_name":"Attribute"},{"task_slug":"linguistic-acceptability","task_name":"Linguistic Acceptability"},{"task_slug":"word-embeddings","task_name":"Word Embeddings"}],"methods":[{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"cosine-annealing","method_name":"Cosine Annealing"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"discriminative-fine-tuning","method_name":"Discriminative Fine-Tuning"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"gpt-2","method_name":"GPT-2"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-cosine-annealing","method_name":"Linear Warmup With Cosine Annealing"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"weight-decay","method_name":"Weight Decay"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2009.06367","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2009.06367"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/johnr0/TaleBrush-backend","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/yugaljain1999/biasfree_bot_GeDi","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/salesforce/GeDi","reach":{"status":"ok","spdx":"BSD-3-Clause"}}],"summary":{"ran_fixture":1,"ran_honours":1,"ran_draft_wrong":2,"ran":1,"unverified":6},"by_repo_kind":{"official":{"samples":8,"ran":3,"repositories":1},"listed":{"samples":3,"ran":2,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"bf3d9775c3335f07","entry":"acc_and_f1","repo":"johnr0/TaleBrush-backend","repo_kind":"listed","path":"train_GeDi.py","file_url":"https://github.com/johnr0/TaleBrush-backend/blob/HEAD/train_GeDi.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"bf3d9775c3335f07"}},{"code_sha256_prefix":"12a1b5beef451d92","entry":"adjust_length_to_model","repo":"johnr0/TaleBrush-backend","repo_kind":"listed","path":"generate_GeDi.py","file_url":"https://github.com/johnr0/TaleBrush-backend/blob/HEAD/generate_GeDi.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"well_formed","behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"12a1b5beef451d92"}},{"code_sha256_prefix":"8d23fbe2b99b840b","entry":"gelu","repo":"salesforce/GeDi","repo_kind":"official","path":"modeling_gpt2.py","file_url":"https://github.com/salesforce/GeDi/blob/HEAD/modeling_gpt2.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"8d23fbe2b99b840b"}},{"code_sha256_prefix":"d30d6c3098df2c42","entry":"prune_linear_layer","repo":"salesforce/GeDi","repo_kind":"official","path":"modeling_utils.py","file_url":"https://github.com/salesforce/GeDi/blob/HEAD/modeling_utils.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d30d6c3098df2c42"}},{"code_sha256_prefix":"49f3df5f44c69b6f","entry":"top_k_top_p_filtering","repo":"salesforce/GeDi","repo_kind":"official","path":"modeling_utils.py","file_url":"https://github.com/salesforce/GeDi/blob/HEAD/modeling_utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"49f3df5f44c69b6f"}},{"code_sha256_prefix":"464d483ca9073ea6","entry":"SharedDropout2","repo":"salesforce/GeDi","repo_kind":"official","path":"modeling_gpt2.py","file_url":"https://github.com/salesforce/GeDi/blob/HEAD/modeling_gpt2.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"464d483ca9073ea6"}},{"code_sha256_prefix":"d53311eeea4a6085","entry":"add_sep","repo":"johnr0/TaleBrush-backend","repo_kind":"listed","path":"train_GeDi.py","file_url":"https://github.com/johnr0/TaleBrush-backend/blob/HEAD/train_GeDi.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d53311eeea4a6085"}},{"code_sha256_prefix":"35214bf3a3709500","entry":"calc_banned_ngram_tokens","repo":"salesforce/GeDi","repo_kind":"official","path":"modeling_utils.py","file_url":"https://github.com/salesforce/GeDi/blob/HEAD/modeling_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"35214bf3a3709500"}},{"code_sha256_prefix":"c4bac98236c1fc2c","entry":"load_tf_weights_in_gpt2","repo":"salesforce/GeDi","repo_kind":"official","path":"modeling_gpt2.py","file_url":"https://github.com/salesforce/GeDi/blob/HEAD/modeling_gpt2.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"c4bac98236c1fc2c"}},{"code_sha256_prefix":"95a0d8f647e7e5f3","entry":"proc_and_binarize","repo":"salesforce/GeDi","repo_kind":"official","path":"proc_data.py","file_url":"https://github.com/salesforce/GeDi/blob/HEAD/proc_data.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"95a0d8f647e7e5f3"}},{"code_sha256_prefix":"3c241ecfe3749a6d","entry":"simple_accuracy","repo":"salesforce/GeDi","repo_kind":"official","path":"train_GeDi.py","file_url":"https://github.com/salesforce/GeDi/blob/HEAD/train_GeDi.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"3c241ecfe3749a6d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}