{"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/k-adapter-infusing-knowledge-into-pre-trained","title":"K-Adapter: Infusing Knowledge into Pre-Trained Models with Adapters","arxiv_id":"2002.01808","date":"2020-02-05","proceeding":"Findings (ACL) 2021 8","authors":["Ruize Wang","Duyu Tang","Nan Duan","Zhongyu Wei","Xuanjing Huang","Jianshu ji","Guihong Cao","Daxin Jiang","Ming Zhou"],"abstract":"We study the problem of injecting knowledge into large pre-trained models like BERT and RoBERTa. Existing methods typically update the original parameters of pre-trained models when injecting knowledge. However, when multiple kinds of knowledge are injected, the historically injected knowledge would be flushed away. To address this, we propose K-Adapter, a framework that retains the original parameters of the pre-trained model fixed and supports the development of versatile knowledge-infused model. Taking RoBERTa as the backbone model, K-Adapter has a neural adapter for each kind of infused knowledge, like a plug-in connected to RoBERTa. There is no information flow between different adapters, thus multiple adapters can be efficiently trained in a distributed way. As a case study, we inject two kinds of knowledge in this work, including (1) factual knowledge obtained from automatically aligned text-triplets on Wikipedia and Wikidata and (2) linguistic knowledge obtained via dependency parsing. Results on three knowledge-driven tasks, including relation classification, entity typing, and question answering, demonstrate that each adapter improves the performance and the combination of both adapters brings further improvements. Further analysis indicates that K-Adapter captures versatile knowledge than RoBERTa.","url_abs":"https://arxiv.org/abs/2002.01808v5","url_pdf":"https://arxiv.org/pdf/2002.01808v5.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":"k-adapter-infusing-knowledge-into-pre-trained","repo_url":"https://github.com/microsoft/K-Adapter","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"k-adapter-infusing-knowledge-into-pre-trained","repo_url":"https://github.com/stevekgyang/sccl","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"dependency-parsing","task_name":"Dependency Parsing"},{"task_slug":"entity-typing","task_name":"Entity Typing"},{"task_slug":"question-answering","task_name":"Question Answering"},{"task_slug":"relation-classification","task_name":"Relation Classification"},{"task_slug":"relation-extraction","task_name":"Relation Extraction"}],"methods":[{"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":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"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":"residual-connection","method_name":"Residual Connection"},{"method_slug":"roberta","method_name":"RoBERTa"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"weight-decay","method_name":"Weight Decay"},{"method_slug":"wordpiece","method_name":"WordPiece"}],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/entity-typing-on-open-entity","task":"Entity Typing","dataset":"Open Entity","model":"K-Adapter ( fac-adapter )","rank_in_archive_order":1,"of":3,"metrics":{"F1":"77.6916","Precision":"79.6712","Recall":"75.8081"},"uses_additional_data":false},{"leaderboard":"/sota/entity-typing-on-open-entity","task":"Entity Typing","dataset":"Open Entity","model":"K-Adapter ( fac-adapter + lin-adapter )","rank_in_archive_order":2,"of":3,"metrics":{"F1":"77.6127","Precision":"78.9956","Recall":"76.2774"},"uses_additional_data":false},{"leaderboard":"/sota/relation-classification-on-tacred-1","task":"Relation Classification","dataset":"TACRED","model":"RoBERTa","rank_in_archive_order":8,"of":17,"metrics":{"F1":"71.3"},"uses_additional_data":false},{"leaderboard":"/sota/relation-classification-on-tacred-1","task":"Relation Classification","dataset":"TACRED","model":"K-Adapter","rank_in_archive_order":13,"of":17,"metrics":{"F1":"72.0"},"uses_additional_data":false},{"leaderboard":"/sota/relation-extraction-on-tacred","task":"Relation Extraction","dataset":"TACRED","model":"K-ADAPTER (F+L)","rank_in_archive_order":14,"of":40,"metrics":{"F1":"72.04","F1 (1% Few-Shot)":"13.8","F1 (10% Few-Shot)":"56.0","F1 (5% Few-Shot)":"45.1"},"uses_additional_data":true}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2002.01808","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2002.01808"}},"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/stevekgyang/sccl","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/microsoft/K-Adapter","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_draft_wrong":5,"ran_honours":1,"ran":1,"unverified":7},"by_repo_kind":{"listed":{"samples":14,"ran":7,"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":"0f786c407fb1ee4c","entry":"swish","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_bert.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/modeling_bert.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":2,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0f786c407fb1ee4c"}},{"code_sha256_prefix":"35ef111fc00c21b4","entry":"build_tf_to_pytorch_map","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_transfo_xl.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/modeling_transfo_xl.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":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"35ef111fc00c21b4"}},{"code_sha256_prefix":"8d23fbe2b99b840b","entry":"gelu","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_gpt2.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/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":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8d23fbe2b99b840b"}},{"code_sha256_prefix":"fdc64f4c72036ae4","entry":"gelu","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_bert.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/modeling_bert.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"fdc64f4c72036ae4"}},{"code_sha256_prefix":"69c6d14de8190cfb","entry":"gelu","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_distilbert.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/modeling_distilbert.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"69c6d14de8190cfb"}},{"code_sha256_prefix":"0c145728a35789fa","entry":"load_tf_weights_in_bert","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_bert.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/modeling_bert.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":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0c145728a35789fa"}},{"code_sha256_prefix":"93228a3eb5c4d179","entry":"sample_logits","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_transfo_xl_utilities.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/modeling_transfo_xl_utilities.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"93228a3eb5c4d179"}},{"code_sha256_prefix":"743523b60fbbb166","entry":"accuracy","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"lin-adapter.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/lin-adapter.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"743523b60fbbb166"}},{"code_sha256_prefix":"264258aac6e8741c","entry":"evaluate","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"fac-adapter.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/fac-adapter.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"264258aac6e8741c"}},{"code_sha256_prefix":"0e86198a445a228c","entry":"evaluate","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"lin-adapter.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/lin-adapter.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0e86198a445a228c"}},{"code_sha256_prefix":"6b8a0eeef9e90879","entry":"get_property2idx_dict","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"fac-adapter.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/fac-adapter.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6b8a0eeef9e90879"}},{"code_sha256_prefix":"654e91efc679fe84","entry":"load_tf_weights_in_gpt2","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_gpt2.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/modeling_gpt2.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"654e91efc679fe84"}},{"code_sha256_prefix":"42ee168c3ae12e60","entry":"load_tf_weights_in_openai_gpt","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_openai.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/modeling_openai.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"42ee168c3ae12e60"}},{"code_sha256_prefix":"23d246e59ef9447b","entry":"load_tf_weights_in_transfo_xl","repo":"microsoft/K-Adapter","repo_kind":"listed","path":"pytorch_transformers/modeling_transfo_xl.py","file_url":"https://github.com/microsoft/K-Adapter/blob/HEAD/pytorch_transformers/modeling_transfo_xl.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"23d246e59ef9447b"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}