{"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/fine-tuning-vs-retrieval-augmented-generation","title":"Fine Tuning vs. Retrieval Augmented Generation for Less Popular Knowledge","arxiv_id":"2403.01432","date":"2024-03-03","proceeding":null,"authors":["Heydar Soudani","Evangelos Kanoulas","Faegheh Hasibi"],"abstract":"Language Models (LMs) memorize a vast amount of factual knowledge, exhibiting strong performance across diverse tasks and domains. However, it has been observed that the performance diminishes when dealing with less-popular or low-frequency concepts and entities, for example in domain specific applications. The two prominent approaches to enhance the performance of LMs on low-frequent topics are: Retrieval Augmented Generation (RAG) and fine-tuning (FT) over synthetic data. This paper explores and evaluates the impact of RAG and FT on customizing LMs in handling low-frequency entities on question answering tasks. We conduct extensive experiments on twelve LMs of varying size and type and different fine tuning, data augmentation, and retrieval models. Our findings indicate that while FT boosts the performance across entities of varying popularity, RAG surpasses FT by a large margin particularly for least popular factual knowledge. Additionally, the success of both RAG and FT approaches is amplified by improving retrieval and data augmentation techniques. Fine tuning, while beneficial for small LMs, requires extensive resources. To address this issue, we propose the new Stimulus RAG approach that surpasses the effectiveness of fine tuning based approaches, thereby eliminating the need for the costly data augmentation and fine tuning step for enriching LMs with less popular factual knowledge. The code is available at \\url{https://github.com/informagi/RAGvsFT}.","url_abs":"https://arxiv.org/abs/2403.01432v5","url_pdf":"https://arxiv.org/pdf/2403.01432v5.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":"fine-tuning-vs-retrieval-augmented-generation","repo_url":"https://github.com/heydarsoudani/ragvsft","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"data-augmentation","task_name":"Data Augmentation"},{"task_slug":"question-answering","task_name":"Question Answering"},{"task_slug":"rag","task_name":"RAG"},{"task_slug":"retrieval","task_name":"Retrieval"},{"task_slug":"retrieval-augmented-generation","task_name":"Retrieval-augmented Generation"}],"methods":[{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bart","method_name":"BART"},{"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":"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":"rag","method_name":"RAG"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"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":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2403.01432","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2403.01432"}},"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/heydarsoudani/ragvsft","reach":{"status":"ok"}}],"summary":{"ran":15,"unverified":4},"by_repo_kind":{"official":{"samples":19,"ran":15,"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":19,"samples":[{"code_sha256_prefix":"18e768963a04b1c3","entry":"calculate_relative_popularity","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component0_preprocessing/relative_popularity_bucketing.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component0_preprocessing/relative_popularity_bucketing.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":"18e768963a04b1c3"}},{"code_sha256_prefix":"e1fee8e3b0d495f4","entry":"calculated_accuracy","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"analysis/plot_results.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/analysis/plot_results.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":"e1fee8e3b0d495f4"}},{"code_sha256_prefix":"885a140ff8e2fe75","entry":"convert_to_url_format","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component0_preprocessing/create_costomized_dataset.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component0_preprocessing/create_costomized_dataset.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":"885a140ff8e2fe75"}},{"code_sha256_prefix":"9a0d33580478460b","entry":"extract_json_objects","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component0_preprocessing/create_costomized_dataset.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component0_preprocessing/create_costomized_dataset.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":"9a0d33580478460b"}},{"code_sha256_prefix":"a41e1c043c80020e","entry":"load_dataset_qa","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component2_AnsGen/finetuning/flant5_finetuning.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component2_AnsGen/finetuning/flant5_finetuning.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":"a41e1c043c80020e"}},{"code_sha256_prefix":"adb13beccd33442d","entry":"load_dataset_qa","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component2_AnsGen/finetuning/llm_finetuning.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component2_AnsGen/finetuning/llm_finetuning.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":"adb13beccd33442d"}},{"code_sha256_prefix":"ae696033188ab5b7","entry":"load_json_file","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component2_AnsGen/finetuning/flant5_finetuning.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component2_AnsGen/finetuning/flant5_finetuning.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":"ae696033188ab5b7"}},{"code_sha256_prefix":"ee3add82700b2786","entry":"load_json_file","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component2_AnsGen/finetuning/opt_finetuning.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component2_AnsGen/finetuning/opt_finetuning.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":"ee3add82700b2786"}},{"code_sha256_prefix":"5de2b9b470eeba70","entry":"load_json_file","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component3_highlighter/sentence_highlighter.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component3_highlighter/sentence_highlighter.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":"5de2b9b470eeba70"}},{"code_sha256_prefix":"e9ad136bfabde8b4","entry":"load_json_files","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component2_AnsGen/finetuning/opt_finetuning.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component2_AnsGen/finetuning/opt_finetuning.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":"e9ad136bfabde8b4"}},{"code_sha256_prefix":"48b100358417247d","entry":"load_relations_data","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component2_AnsGen/finetuning/flant5_finetuning.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component2_AnsGen/finetuning/flant5_finetuning.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":"48b100358417247d"}},{"code_sha256_prefix":"3137917c97622aa7","entry":"load_relations_data","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component3_highlighter/sentence_highlighter.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component3_highlighter/sentence_highlighter.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":"3137917c97622aa7"}},{"code_sha256_prefix":"b099238f8b55282e","entry":"split_by_relation","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component0_preprocessing/relative_popularity_bucketing.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component0_preprocessing/relative_popularity_bucketing.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":"b099238f8b55282e"}},{"code_sha256_prefix":"e353bb80690f02dd","entry":"split_to_buckets","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"analysis/plot_results.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/analysis/plot_results.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":"e353bb80690f02dd"}},{"code_sha256_prefix":"b0f02c29c4153f5c","entry":"split_to_buckets","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component1_retrieval/utils.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component1_retrieval/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":"b0f02c29c4153f5c"}},{"code_sha256_prefix":"02f693941998e280","entry":"get_wikipedia_title_from_wikidata","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component0_preprocessing/create_costomized_dataset.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component0_preprocessing/create_costomized_dataset.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":"02f693941998e280"}},{"code_sha256_prefix":"d8772189b543b83f","entry":"main","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component1_retrieval/data_postprocessing.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component1_retrieval/data_postprocessing.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":"d8772189b543b83f"}},{"code_sha256_prefix":"ea3cc6f0ff764ddf","entry":"sig_test","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"analysis/plot_results.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/analysis/plot_results.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":"ea3cc6f0ff764ddf"}},{"code_sha256_prefix":"7018bfe9d2340be1","entry":"split_to_buckets","repo":"heydarsoudani/ragvsft","repo_kind":"official","path":"component0_preprocessing/relative_popularity_bucketing.py","file_url":"https://github.com/heydarsoudani/ragvsft/blob/HEAD/component0_preprocessing/relative_popularity_bucketing.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":"7018bfe9d2340be1"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}