{"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/learning-syntax-without-planting-trees","title":"Learning Syntax Without Planting Trees: Understanding When and Why Transformers Generalize Hierarchically","arxiv_id":"2404.16367","date":"2024-04-25","proceeding":null,"authors":["Kabir Ahuja","Vidhisha Balachandran","Madhur Panwar","Tianxing He","Noah A. Smith","Navin Goyal","Yulia Tsvetkov"],"abstract":"Transformers trained on natural language data have been shown to learn its hierarchical structure and generalize to sentences with unseen syntactic structures without explicitly encoding any structural bias. In this work, we investigate sources of inductive bias in transformer models and their training that could cause such generalization behavior to emerge. We extensively experiment with transformer models trained on multiple synthetic datasets and with different training objectives and show that while other objectives e.g. sequence-to-sequence modeling, prefix language modeling, often failed to lead to hierarchical generalization, models trained with the language modeling objective consistently learned to generalize hierarchically. We then conduct pruning experiments to study how transformers trained with the language modeling objective encode hierarchical structure. When pruned, we find joint existence of subnetworks within the model with different generalization behaviors (subnetworks corresponding to hierarchical structure and linear order). Finally, we take a Bayesian perspective to further uncover transformers' preference for hierarchical generalization: We establish a correlation between whether transformers generalize hierarchically on a dataset and whether the simplest explanation of that dataset is provided by a hierarchical grammar compared to regular grammars exhibiting linear generalization.","url_abs":"https://arxiv.org/abs/2404.16367v2","url_pdf":"https://arxiv.org/pdf/2404.16367v2.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":"learning-syntax-without-planting-trees","repo_url":"https://github.com/kabirahuja2431/transformers-hg","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"jax","reach":{"status":"ok"}}],"tasks":[{"task_slug":"inductive-bias","task_name":"Inductive Bias"},{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"}],"methods":[{"method_slug":"pruning","method_name":"Pruning"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2404.16367","atlas_url":"https://app.syntology.ai/?focus=2404.16367","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2404.16367"}},"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/kabirahuja2431/transformers-hg","reach":{"status":"ok"}}],"summary":{"ran":4,"unverified":12},"by_repo_kind":{"official":{"samples":16,"ran":4,"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":16,"samples":[{"code_sha256_prefix":"b220e701be05a184","entry":"ensure_valid_input","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/convert_graph_to_onnx.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/convert_graph_to_onnx.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":"b220e701be05a184"}},{"code_sha256_prefix":"7efe3db5c9e2f94d","entry":"generate_identified_filename","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/convert_graph_to_onnx.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/convert_graph_to_onnx.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":"7efe3db5c9e2f94d"}},{"code_sha256_prefix":"3d999b95009c7537","entry":"get_config_class_from_processor_class","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/utils/create_dummy_models.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/utils/create_dummy_models.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":"3d999b95009c7537"}},{"code_sha256_prefix":"0c0b81b081919d8e","entry":"get_processor_types_from_config_class","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/utils/create_dummy_models.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/utils/create_dummy_models.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":"0c0b81b081919d8e"}},{"code_sha256_prefix":"37a5eed2dbd663ca","entry":"gelu_fast","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/activations_tf.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/activations_tf.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":"37a5eed2dbd663ca"}},{"code_sha256_prefix":"b176efb26f72e507","entry":"get_architectures_from_config_class","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/utils/create_dummy_models.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/utils/create_dummy_models.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":"b176efb26f72e507"}},{"code_sha256_prefix":"e8d8bcdc4e03a8ce","entry":"get_base_transformer_cls","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"train_transformers.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/train_transformers.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":"e8d8bcdc4e03a8ce"}},{"code_sha256_prefix":"da751511d95929df","entry":"get_base_transformer_lm","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"train_transformers.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/train_transformers.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":"da751511d95929df"}},{"code_sha256_prefix":"a715ee364bed25a3","entry":"get_base_transformer_model","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"train_transformers.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/train_transformers.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":"a715ee364bed25a3"}},{"code_sha256_prefix":"dd3166a87bc972ff","entry":"get_configuration_file","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/configuration_utils.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/configuration_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":"dd3166a87bc972ff"}},{"code_sha256_prefix":"9a09cbf63a4ddff4","entry":"hertz_to_mel","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/audio_utils.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/audio_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":"9a09cbf63a4ddff4"}},{"code_sha256_prefix":"0da835817b8a57bc","entry":"infer_shapes","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/convert_graph_to_onnx.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/convert_graph_to_onnx.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":"0da835817b8a57bc"}},{"code_sha256_prefix":"7e7c601df5b22499","entry":"mel_filter_bank","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/audio_utils.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/audio_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":"7e7c601df5b22499"}},{"code_sha256_prefix":"2650530d2f0dd9b2","entry":"mel_to_hertz","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/audio_utils.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/audio_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":"2650530d2f0dd9b2"}},{"code_sha256_prefix":"cc8c8c3ebf0c343f","entry":"mish","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/activations_tf.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/activations_tf.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":"cc8c8c3ebf0c343f"}},{"code_sha256_prefix":"e2d56cb91f999bef","entry":"quick_gelu","repo":"kabirahuja2431/transformers-hg","repo_kind":"official","path":"transformers/src/transformers/activations_tf.py","file_url":"https://github.com/kabirahuja2431/transformers-hg/blob/HEAD/transformers/src/transformers/activations_tf.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":"e2d56cb91f999bef"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}