{"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/tlm-token-level-masking-for-transformers","title":"TLM: Token-Level Masking for Transformers","arxiv_id":"2310.18738","date":"2023-10-28","proceeding":null,"authors":["Yangjun Wu","Kebin Fang","Dongxiang Zhang","Han Wang","Hao Zhang","Gang Chen"],"abstract":"Structured dropout approaches, such as attention dropout and DropHead, have been investigated to regularize the multi-head attention mechanism in Transformers. In this paper, we propose a new regularization scheme based on token-level rather than structure-level to reduce overfitting. Specifically, we devise a novel Token-Level Masking (TLM) training strategy for Transformers to regularize the connections of self-attention, which consists of two masking techniques that are effective and easy to implement. The underlying idea is to manipulate the connections between tokens in the multi-head attention via masking, where the networks are forced to exploit partial neighbors' information to produce a meaningful representation. The generality and effectiveness of TLM are thoroughly evaluated via extensive experiments on 4 diversified NLP tasks across 18 datasets, including natural language understanding benchmark GLUE, ChineseGLUE, Chinese Grammatical Error Correction, and data-to-text generation. The results indicate that TLM can consistently outperform attention dropout and DropHead, e.g., it increases by 0.5 points relative to DropHead with BERT-large on GLUE. Moreover, TLM can establish a new record on the data-to-text benchmark Rotowire (18.93 BLEU). Our code will be publicly available at https://github.com/Young1993/tlm.","url_abs":"https://arxiv.org/abs/2310.18738v1","url_pdf":"https://arxiv.org/pdf/2310.18738v1.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":"tlm-token-level-masking-for-transformers","repo_url":"https://github.com/young1993/tlm","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"jax","reach":{"status":"ok"}}],"tasks":[{"task_slug":"data-to-text-generation","task_name":"Data-to-Text Generation"},{"task_slug":"grammatical-error-correction","task_name":"Grammatical Error Correction"},{"task_slug":"natural-language-understanding","task_name":"Natural Language Understanding"},{"task_slug":"text-generation","task_name":"Text Generation"}],"methods":[{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2310.18738","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2310.18738"}},"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":"deterministic:regex_extraction","url":"https://github.com/harvardnlp/boxscore-data","reach":{"status":"ok"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/Young1993/tlm","reach":{"status":"ok"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/blcuicall/CCL2022-CLTC","reach":{"status":"ok"}}],"summary":{"ran":18,"ran_draft_wrong":1,"unverified":9},"by_repo_kind":{"official":{"samples":14,"ran":8,"repositories":1},"found_in_text":{"samples":14,"ran":11,"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":28,"samples":[{"code_sha256_prefix":"743ceb9025a7955d","entry":"booleans_processing","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modeling_tf_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modeling_tf_utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"743ceb9025a7955d"}},{"code_sha256_prefix":"5967acfb31566dce","entry":"construct_parallel_data_lbl","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/data_preprocess.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/data_preprocess.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"5967acfb31566dce"}},{"code_sha256_prefix":"37070b4bd77f89f1","entry":"construct_parallel_data_para","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/data_preprocess.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/data_preprocess.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"37070b4bd77f89f1"}},{"code_sha256_prefix":"db0c9b6ddfd01ae5","entry":"convert_pytorch_state_dict_to_flax","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modeling_flax_pytorch_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modeling_flax_pytorch_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"db0c9b6ddfd01ae5"}},{"code_sha256_prefix":"1923fc05163d207d","entry":"convert_to_unicode","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track2/tokenization.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track2/tokenization.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1923fc05163d207d"}},{"code_sha256_prefix":"3c1eb64dde6b86af","entry":"dummy_loss","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modeling_tf_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modeling_tf_utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3c1eb64dde6b86af"}},{"code_sha256_prefix":"f02b7d24b3c3ecb3","entry":"encode_parallel_data","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/data_preprocess.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/data_preprocess.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f02b7d24b3c3ecb3"}},{"code_sha256_prefix":"bec43ad3f12fba68","entry":"get_correction_map","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/eval_char_level.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/eval_char_level.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"bec43ad3f12fba68"}},{"code_sha256_prefix":"befde8a6e72b2fa6","entry":"get_eval_metrics","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/eval_char_level.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/eval_char_level.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"befde8a6e72b2fa6"}},{"code_sha256_prefix":"1e8d0a0db7a3947f","entry":"get_weights_name","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track2/gector/gec_model.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track2/gector/gec_model.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1e8d0a0db7a3947f"}},{"code_sha256_prefix":"dd8f7751ef859581","entry":"infer_metric_tags_from_eval_results","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modelcard.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modelcard.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"dd8f7751ef859581"}},{"code_sha256_prefix":"6a3959a0ffd36577","entry":"keras_serializable","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modeling_tf_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modeling_tf_utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6a3959a0ffd36577"}},{"code_sha256_prefix":"deb4d1793cf3ba73","entry":"load_vocab","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track2/tokenization.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track2/tokenization.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"deb4d1793cf3ba73"}},{"code_sha256_prefix":"7b3c30e644fc5e5e","entry":"metric_file","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/eval_sent_level.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/eval_sent_level.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7b3c30e644fc5e5e"}},{"code_sha256_prefix":"18450df3733a6e7e","entry":"parse_keras_history","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modelcard.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modelcard.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"18450df3733a6e7e"}},{"code_sha256_prefix":"a66d2b78670c85e1","entry":"quick_gelu","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modeling_flax_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modeling_flax_utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a66d2b78670c85e1"}},{"code_sha256_prefix":"40a3d4e153df98ef","entry":"read_file","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/eval_sent_level.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/eval_sent_level.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"40a3d4e153df98ef"}},{"code_sha256_prefix":"1236c8c8ab59ff20","entry":"rename_key_and_reshape_tensor","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modeling_flax_pytorch_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modeling_flax_pytorch_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1236c8c8ab59ff20"}},{"code_sha256_prefix":"2384075fc45a1f65","entry":"sent_metric_detect","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/eval_sent_level.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/eval_sent_level.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2384075fc45a1f65"}},{"code_sha256_prefix":"301682fc3342590a","entry":"check_imports","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/dynamic_module_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/dynamic_module_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"301682fc3342590a"}},{"code_sha256_prefix":"9d98806acb3144b7","entry":"dtype_byte_size","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modeling_flax_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modeling_flax_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9d98806acb3144b7"}},{"code_sha256_prefix":"e3ce70ca9258800e","entry":"flax_shard_checkpoint","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modeling_flax_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modeling_flax_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e3ce70ca9258800e"}},{"code_sha256_prefix":"23c9c8f028972e4e","entry":"get_best_score","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/utils.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"23c9c8f028972e4e"}},{"code_sha256_prefix":"9b9e456240811606","entry":"get_char_metrics","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track1/eval_char_level.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track1/eval_char_level.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9b9e456240811606"}},{"code_sha256_prefix":"00cc853a73f3aeb6","entry":"get_relative_import_files","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/dynamic_module_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/dynamic_module_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"00cc853a73f3aeb6"}},{"code_sha256_prefix":"450aeffe7f80f917","entry":"get_relative_imports","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/dynamic_module_utils.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/dynamic_module_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"450aeffe7f80f917"}},{"code_sha256_prefix":"569927b3efc92b80","entry":"is_hf_dataset","repo":"Young1993/tlm","repo_kind":"official","path":"transformers/modelcard.py","file_url":"https://github.com/Young1993/tlm/blob/HEAD/transformers/modelcard.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"569927b3efc92b80"}},{"code_sha256_prefix":"0e5615f8994003cf","entry":"printable_text","repo":"blcuicall/CCL2022-CLTC","repo_kind":"found_in_text","path":"baselines/track2/tokenization.py","file_url":"https://github.com/blcuicall/CCL2022-CLTC/blob/HEAD/baselines/track2/tokenization.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"0e5615f8994003cf"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}