{"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/tree-transformer-integrating-tree-structures","title":"Tree Transformer: Integrating Tree Structures into Self-Attention","arxiv_id":"1909.06639","date":"2019-09-14","proceeding":"IJCNLP 2019 11","authors":["Yau-Shian Wang","Hung-Yi Lee","Yun-Nung Chen"],"abstract":"Pre-training Transformer from large-scale raw texts and fine-tuning on the desired task have achieved state-of-the-art results on diverse NLP tasks. However, it is unclear what the learned attention captures. The attention computed by attention heads seems not to match human intuitions about hierarchical structures. This paper proposes Tree Transformer, which adds an extra constraint to attention heads of the bidirectional Transformer encoder in order to encourage the attention heads to follow tree structures. The tree structures can be automatically induced from raw texts by our proposed \"Constituent Attention\" module, which is simply implemented by self-attention between two adjacent words. With the same training procedure identical to BERT, the experiments demonstrate the effectiveness of Tree Transformer in terms of inducing tree structures, better language modeling, and further learning more explainable attention scores.","url_abs":"https://arxiv.org/abs/1909.06639v2","url_pdf":"https://arxiv.org/pdf/1909.06639v2.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":"tree-transformer-integrating-tree-structures","repo_url":"https://github.com/yaushian/Tree-Transformer","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}},{"paper_slug":"tree-transformer-integrating-tree-structures","repo_url":"https://github.com/iceraionly/Tree-Transformer","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}},{"paper_slug":"tree-transformer-integrating-tree-structures","repo_url":"https://github.com/itzpankajpanwar/Tree-transform","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bert","method_name":"BERT"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-linear-decay","method_name":"Linear Warmup With Linear Decay"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"relu","method_name":"ReLU"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"},{"method_slug":"weight-decay","method_name":"Weight Decay"},{"method_slug":"wordpiece","method_name":"WordPiece"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/1909.06639","atlas_url":"https://app.syntology.ai/?focus=1909.06639","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"1909.06639"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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/itzpankajpanwar/Tree-transform","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/yaushian/Tree-Transformer","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/iceraionly/Tree-Transformer","reach":{"status":"ok"}}],"summary":{"ran":6,"ran_draft_wrong":2,"unverified":2},"by_repo_kind":{"listed":{"samples":10,"ran":8,"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":"30ac4034117b7c76","entry":"attention","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"attention.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/attention.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"30ac4034117b7c76"}},{"code_sha256_prefix":"a940e63fb38eb615","entry":"build_tree","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"parse.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/parse.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"a940e63fb38eb615"}},{"code_sha256_prefix":"4fdb28c59aa02f3c","entry":"cc","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"utils.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"4fdb28c59aa02f3c"}},{"code_sha256_prefix":"b1bec2c4b1c9b491","entry":"clones","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"modules.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/modules.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b1bec2c4b1c9b491"}},{"code_sha256_prefix":"60427abde198d7f8","entry":"dump_tree","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"parse.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/parse.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"60427abde198d7f8"}},{"code_sha256_prefix":"215c1b4a8625c6f5","entry":"make_save_dir","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"utils.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"215c1b4a8625c6f5"}},{"code_sha256_prefix":"c204acb9ea9e761d","entry":"read_json","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"utils.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"c204acb9ea9e761d"}},{"code_sha256_prefix":"7832e4cac7a9683c","entry":"word2tree","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"parse.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/parse.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"7832e4cac7a9683c"}},{"code_sha256_prefix":"009d3f80a8ce3436","entry":"get_std_opt","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"modules.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/modules.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"009d3f80a8ce3436"}},{"code_sha256_prefix":"79e53d4ea458987d","entry":"subsequent_mask","repo":"itzpankajpanwar/Tree-transform","repo_kind":"listed","path":"modules.py","file_url":"https://github.com/itzpankajpanwar/Tree-transform/blob/HEAD/modules.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"79e53d4ea458987d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}