{"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/privacy-preserving-in-context-learning-with","title":"Privacy-Preserving In-Context Learning with Differentially Private Few-Shot Generation","arxiv_id":"2309.11765","date":"2023-09-21","proceeding":null,"authors":["Xinyu Tang","Richard Shin","Huseyin A. Inan","Andre Manoel","FatemehSadat Mireshghallah","Zinan Lin","Sivakanth Gopi","Janardhan Kulkarni","Robert Sim"],"abstract":"We study the problem of in-context learning (ICL) with large language models (LLMs) on private datasets. This scenario poses privacy risks, as LLMs may leak or regurgitate the private examples demonstrated in the prompt. We propose a novel algorithm that generates synthetic few-shot demonstrations from the private dataset with formal differential privacy (DP) guarantees, and show empirically that it can achieve effective ICL. We conduct extensive experiments on standard benchmarks and compare our algorithm with non-private ICL and zero-shot solutions. Our results demonstrate that our algorithm can achieve competitive performance with strong privacy levels. These results open up new possibilities for ICL with privacy protection for a broad range of applications.","url_abs":"https://arxiv.org/abs/2309.11765v2","url_pdf":"https://arxiv.org/pdf/2309.11765v2.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":"privacy-preserving-in-context-learning-with","repo_url":"https://github.com/microsoft/dp-few-shot-generation","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"none","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"in-context-learning","task_name":"In-Context Learning"},{"task_slug":"privacy-preserving","task_name":"Privacy Preserving"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2309.11765","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2309.11765"}},"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/microsoft/dp-few-shot-generation","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":17},"by_repo_kind":{"official":{"samples":17,"ran":17,"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":"44638cce82907058","entry":"bucket","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"lmapi/src/lmapi/async_tools/asyncitertools.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/lmapi/src/lmapi/async_tools/asyncitertools.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"44638cce82907058"}},{"code_sha256_prefix":"0bf84d7908b72654","entry":"construct_prompt_same","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_agnews.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_agnews.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0bf84d7908b72654"}},{"code_sha256_prefix":"fa8cab36e1361d87","entry":"construct_prompt_same","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_dbpedia.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_dbpedia.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"fa8cab36e1361d87"}},{"code_sha256_prefix":"5b5e01e114acc5e6","entry":"construct_prompt_same","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_movie.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_movie.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5b5e01e114acc5e6"}},{"code_sha256_prefix":"eecf2939e2cad740","entry":"construct_prompt_same","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_trec.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_trec.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"eecf2939e2cad740"}},{"code_sha256_prefix":"5c7d9873d8d10f37","entry":"densify","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/prob_utils.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/prob_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5c7d9873d8d10f37"}},{"code_sha256_prefix":"1adc0f8de046bd4b","entry":"format_full_datum_for_prompt","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_agnews.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_agnews.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1adc0f8de046bd4b"}},{"code_sha256_prefix":"5ccd170c8c25a1a9","entry":"format_full_datum_for_prompt","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_dbpedia.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_dbpedia.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5ccd170c8c25a1a9"}},{"code_sha256_prefix":"b6fe1bbe225ef52b","entry":"format_full_datum_for_prompt","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_movie.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_movie.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b6fe1bbe225ef52b"}},{"code_sha256_prefix":"9c8615eda7477f90","entry":"format_full_datum_for_prompt","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_trec.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_trec.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9c8615eda7477f90"}},{"code_sha256_prefix":"34f0eccbe92abf73","entry":"format_test_input_for_prompt","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_agnews.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_agnews.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"34f0eccbe92abf73"}},{"code_sha256_prefix":"52e0b351e17a4c5b","entry":"format_test_input_for_prompt","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_dbpedia.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_dbpedia.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"52e0b351e17a4c5b"}},{"code_sha256_prefix":"1eb0215575d63ba9","entry":"format_test_input_for_prompt","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_movie.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_movie.py","link_basis":"first_harvest_node","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":"1eb0215575d63ba9"}},{"code_sha256_prefix":"4d172e7132a9045a","entry":"format_test_input_for_prompt","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/run_exp_trec.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/run_exp_trec.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"4d172e7132a9045a"}},{"code_sha256_prefix":"ccccd602b13c9a9f","entry":"log_max_normalize","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/prob_utils.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/prob_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ccccd602b13c9a9f"}},{"code_sha256_prefix":"33a763306ed859f8","entry":"log_normalize","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"src/dp_few_shot_generation/prob_utils.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/src/dp_few_shot_generation/prob_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"33a763306ed859f8"}},{"code_sha256_prefix":"dbda3623619056cc","entry":"openai_token_to_bytes","repo":"microsoft/dp-few-shot-generation","repo_kind":"official","path":"lmapi/src/lmapi/openai.py","file_url":"https://github.com/microsoft/dp-few-shot-generation/blob/HEAD/lmapi/src/lmapi/openai.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"dbda3623619056cc"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}