journal article·2025-04-10Open access

Neighborhood Deviation Attack Against In-Context Learning

Dai Hou, Zhenkai Yang, Lei Zheng, Bo Jin, Huan Xu, Ying Li, Bo Xu, Kai Peng

Applied Sciences· Volume 15· Issue 8

Abstract

In-context learning (ICL) enables large language models (LLMs) to adapt to new tasks using only a few examples, without requiring fine-tuning. However, the new privacy and security risks brought about by this increasing capability have not received enough attention, and there is a lack of research on this issue. In this work, we propose a novel membership inference attack (MIA) method, termed Neighborhood Deviation Attack, specifically designed to evaluate the privacy risks of LLMs in ICL. Unlike traditional MIA methods, our approach does not require access to model parameters and instead relies solely on analyzing the model’s output behavior. We first generate neighborhood prefixes for target samples and use the LLM, conditioned on ICL examples, to complete the text. We then compute the deviation between the original and completed texts and infer membership based on these deviations. We conduct experiments on three datasets and three LLMs and further explore the influence of key hyperparameters on the method’s performance and their underlying reasons. Experimental results show that our method is significantly better than the comparative methods in terms of stability and achieves better accuracy in most cases. Furthermore, we discuss four potential defense strategies, including increasing the diversity of ICL examples and introducing controlled randomness in the inference process to reduce the risk of privacy leakage.
Source: crossref · Quality: baseline

Research context

OpenAlex topics: Privacy-Preserving Technologies in Data · Adversarial Robustness in Machine Learning · COVID-19 diagnosis using AI

SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.

Affiliations

State Grid Hubei Information & Telecommunication Company, Wuhan 430048, China

Hubei Key Laboratory of Smart Internet Technology, School of Electronic Information and Communications, Huazhong University of Science and Technology, Wuhan 430074, China

Funding

Key Research and Development Program of Hubei Province, China

References (59)

Show source-provided references
1. Zhao, W.X., Zhou, K., Li, J., Tang, T., Wang, X., Hou, Y., Min, Y., Zhang, B., Zhang, J., and Dong, Z. (2023). A survey of large language models. arXiv.
2. Hadi, M.U., Al-Tashi, Q., Qureshi, R., Shah, A., Muneer, A., Irfan, M., Zafar, A., Shaikh, M.B., Akhtar, N., and Wu, J. (2023). A survey on large language models: Applications, challenges, limitations, and practical usage. Authorea Prepr., 3.10.36227/techrxiv.23589741.v1 ↗
3. Rao, A., Kim, J., Kamineni, M., Pang, M., Lie, W., and Succi, M.D. (2023). Evaluating ChatGPT as an adjunct for radiologic decision-making. medRxiv.10.1101/2023.02.02.23285399 ↗
4. Kung, T.H., Cheatham, M., Medenilla, A., Sillos, C., De Leon, L., Elepaño, C., Madriaga, M., Aggabao, R., Diaz-Candido, G., and Maningo, J. (2023). Performance of ChatGPT on USMLE: Potential for AI-assisted medical education using large language models. PLoS Digit. Health, 2.10.1371/journal.pdig.0000198 ↗
5. ChatGPT for good? On opportunities and challenges of large language models for education10.1016/j.lindif.2023.102274 ↗
6. Liu, X.Y., Wang, G., Yang, H., and Zha, D. (2023, January 15). FinGPT: Democratizing Internet-scale Data for Financial Large Language Models. Proceedings of the NeurIPS 2023 Workshop on Instruction Tuning and Instruction Following, New Orleans, LA, USA.
7. Wu, S., Irsoy, O., Lu, S., Dabravolski, V., Dredze, M., Gehrmann, S., Kambadur, P., Rosenberg, D., and Mann, G. (2023). Bloomberggpt: A large language model for finance. arXiv.
8. ChatGPT for design, manufacturing, and education10.1016/j.procir.2023.04.001 ↗
9. Fraiwan, M., and Khasawneh, N. (2023). A review of chatgpt applications in education, marketing, software engineering, and healthcare: Benefits, drawbacks, and research directions. arXiv.
10. Dong, Q., Li, L., Dai, D., Zheng, C., Ma, J., Li, R., Xia, H., Xu, J., Wu, Z., and Liu, T. (2022). A survey on in-context learning. arXiv.
11. Duan, H., Dziedzic, A., Yaghini, M., Papernot, N., and Boenisch, F. (2024). On the privacy risk of in-context learning. arXiv.
12. Survey of artificial intelligence data security and privacy protection
13. Membership inference attacks on machine learning: A survey10.1145/3523273 ↗
14. Huang, W., Wang, Y., and Chen, C. (2024, January 12–16). Privacy Evaluation Benchmarks for NLP Models. Proceedings of the Findings of the Association for Computational Linguistics: EMNLP 2024, Miami, FL, USA.10.18653/v1/2024.findings-emnlp.147 ↗
15. Security and privacy challenges of large language models: A survey10.1145/3712001 ↗
16. Ko, M., Jin, M., Wang, C., and Jia, R. (2023, January 1–6). Practical membership inference attacks against large-scale multi-modal models: A pilot study. Proceedings of the 2023 IEEE/CVF International Conference on Computer Vision (ICCV), Paris, France.10.1109/ICCV51070.2023.00449 ↗
17. Fu, W., Wang, H., Gao, C., Liu, G., Li, Y., and Jiang, T. (2023). Practical membership inference attacks against fine-tuned large language models via self-prompt calibration. arXiv.
18. Shi, W., Ajith, A., Xia, M., Huang, Y., Liu, D., Blevins, T., Chen, D., and Zettlemoyer, L. (2024, January 7–11). Detecting Pretraining Data from Large Language Models. Proceedings of the Twelfth International Conference on Learning Representations, Vienna, Austria.
19. Shokri, R., Stronati, M., Song, C., and Shmatikov, V. (2017, January 22–26). Membership inference attacks against machine learning models. Proceedings of the 2017 IEEE Symposium on Security and Privacy (SP), San Jose, CA, USA.10.1109/SP.2017.41 ↗
20. Rahimian, S., Orekondy, T., and Fritz, M. (2020). Sampling Attacks: Amplification of Membership Inference Attacks by Repeated Queries. arXiv.
21. LOGAN: Membership Inference Attacks Against Generative Models10.2478/popets-2019-0008 ↗
22. Nasr, M., Shokri, R., and Houmansadr, A. (2019, January 19–23). Comprehensive privacy analysis of deep learning: Passive and active white-box inference attacks against centralized and federated learning. Proceedings of the 2019 IEEE Symposium on Security and Privacy (SP), San Francisco, CA, USA.10.1109/SP.2019.00065 ↗
23. Wu, B., Chen, C., Zhao, S., Chen, C., Yao, Y., Sun, G., Wang, L., Zhang, X., and Zhou, J. (2020, January 7–12). Characterizing membership privacy in stochastic gradient langevin dynamics. Proceedings of the AAAI Conference on Artificial Intelligence, New York, NY, USA.10.1609/aaai.v34i04.6107 ↗
24. Ye, J., Maddi, A., Murakonda, S.K., Bindschaedler, V., and Shokri, R. (2022, January 7–11). Enhanced membership inference attacks against machine learning models. Proceedings of the 2022 ACM SIGSAC Conference on Computer and Communications Security, Los Angeles, CA, USA.10.1145/3548606.3560675 ↗
25. meMIA: Multi-level Ensemble Membership Inference Attack10.1109/TAI.2024.3445326 ↗
26. Carlini, N., Tramer, F., Wallace, E., Jagielski, M., Herbert-Voss, A., Lee, K., Roberts, A., Brown, T., Song, D., and Erlingsson, U. (2021, January 11–13). Extracting training data from large language models. Proceedings of the 30th USENIX security symposium (USENIX Security 21), Vancouver, BC, Canada.
27. Mireshghallah, F., Goyal, K., Uniyal, A., Berg-Kirkpatrick, T., and Shokri, R. (2022, January 7–11). Quantifying Privacy Risks of Masked Language Models Using Membership Inference Attacks. Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, Abu Dhabi, United Arab Emirates.10.18653/v1/2022.emnlp-main.570 ↗
28. Mattern, J., Mireshghallah, F., Jin, Z., Schoelkopf, B., Sachan, M., and Berg-Kirkpatrick, T. (2023, January 9–14). Membership Inference Attacks against Language Models via Neighbourhood Comparison. Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics, Toronto, ON, Canada.10.18653/v1/2023.findings-acl.719 ↗
29. Feng, Q., Kasa, S.R., Yun, H., Teo, C.H., and Bodapati, S.B. (2024). Exposing privacy gaps: Membership inference attack on preference data for LLM alignment. arXiv.
30. Xie, R., Wang, J., Huang, R., Zhang, M., Ge, R., Pei, J., Gong, N., and Dhingra, B. (2024, January 12–16). ReCaLL: Membership Inference via Relative Conditional Log-Likelihoods. Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing, Miami, FL, USA.10.18653/v1/2024.emnlp-main.493 ↗
31. Wang, Z., Liu, G., Yang, Y., and Wang, C. (2024). Membership Inference Attack against Long-Context Large Language Models. arXiv.
32. Wen, R., Li, Z., Backes, M., and Zhang, Y. (2024, January 14–18). Membership inference attacks against in-context learning. Proceedings of the 2024 on ACM SIGSAC Conference on Computer and Communications Security, Salt Lake City, UT, USA.10.1145/3658644.3690306 ↗
33. Demystifying membership inference attacks in machine learning as a service10.1109/TSC.2019.2897554 ↗
34. Language models are few-shot learners
35. Touvron, H., Lavril, T., Izacard, G., Martinet, X., Lachaux, M.A., Lacroix, T., Rozière, B., Goyal, N., Hambro, E., and Azhar, F. (2023). Llama: Open and efficient foundation language models. arXiv.
36. Achiam, J., Adler, S., Agarwal, S., Ahmad, L., Akkaya, I., Aleman, F.L., Almeida, D., Altenschmidt, J., Altman, S., and Anadkat, S. (2023). Gpt-4 technical report. arXiv.
37. Sun, T., Shao, Y., Qian, H., Huang, X., and Qiu, X. (2022, January 17–23). Black-box tuning for language-model-as-a-service. Proceedings of the International Conference on Machine Learning, PMLR, Baltimore, MD, USA.
38. Mo, Y., Liu, J., Yang, J., Wang, Q., Zhang, S., Wang, J., and Li, Z. (2024). C-ICL: Contrastive in-context learning for information extraction. arXiv.10.18653/v1/2024.findings-emnlp.590 ↗
39. Zhang, K., Lv, A., Chen, Y., Ha, H., Xu, T., and Yan, R. (2024, January 11–16). Batch-ICL: Effective, Efficient, and Order-Agnostic In-Context Learning. Proceedings of the Findings of the Association for Computational Linguistics ACL 2024, Bangkok, Thailand.10.18653/v1/2024.findings-acl.638 ↗
40. Jiang, G., Ding, Z., Shi, Y., and Yang, D. (2024). P-ICL: Point in-context learning for named entity recognition with large language models. arXiv.
41. Wei, J., Tay, Y., Bommasani, R., Raffel, C., Zoph, B., Borgeaud, S., Yogatama, D., Bosma, M., Zhou, D., and Metzler, D. (2022). Emergent abilities of large language models. arXiv.
42. Min, S., Lyu, X., Holtzman, A., Artetxe, M., Lewis, M., Hajishirzi, H., and Zettlemoyer, L. (2022, January 7–11). Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?. Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, Abu Dhabi, United Arab Emirates.10.18653/v1/2022.emnlp-main.759 ↗
43. Zhou, W., Ge, T., Xu, K., Wei, F., and Zhou, M. (August, January 28). BERT-based lexical substitution. Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, Florence, Italy.
44. Zhang, X., Zhao, J., and LeCun, Y. (2015). Character-level convolutional networks for text classification. Advances in Neural Information Processing Systems, MIT Press.
45. Li, X., and Roth, D. (August, January 26). Learning question classifiers. Proceedings of the COLING 2002: The 19th International Conference on Computational Linguistics, Taipei, Taiwan.10.3115/1072228.1072378 ↗
46. Dubey, A., Jauhri, A., Pandey, A., Kadian, A., Al-Dahle, A., Letman, A., Mathur, A., Schelten, A., Yang, A., and Fan, A. (2024). The llama 3 herd of models. arXiv.
47. Language models are unsupervised multitask learners
48. Devlin, J., Chang, M.W., Lee, K., and Toutanova, K. (2019, January 2–7). Bert: Pre-training of deep bidirectional transformers for language understanding. Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), Minneapolis, MN, USA.
49. Con2Vec: Learning embedding representations for contrast sets10.1016/j.knosys.2021.107382 ↗
50. Ni, J., Abrego, G.H., Constant, N., Ma, J., Hall, K., Cer, D., and Yang, Y. (2022). Sentence-T5: Scalable Sentence Encoders from Pre-trained Text-to-Text Models. Findings of the Association for Computational Linguistics: ACL 2022, Association for Computational Linguistics.10.18653/v1/2022.findings-acl.146 ↗
51. Reimers, N., and Gurevych, I. (2019, January 3–7). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), Hong Kong, China.10.18653/v1/D19-1410 ↗
52. Papineni, K., Roukos, S., Ward, T., and Zhu, W.J. (2002, January 6–12). Bleu: A method for automatic evaluation of machine translation. Proceedings of the 40th Annual Meeting of the Association for Computational Linguistics, Philadelphia, PA, USA.10.3115/1073083.1073135 ↗
53. Martin, J.H., and Jurafsky, D. (2009). Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition, Pearson/Prentice Hall.
54. Lin, C.Y. (2004, January 25–26). Rouge: A package for automatic evaluation of summaries. Proceedings of the Text Summarization Branches Out, Barcelona, Spain.
55. Yeom, S., Giacomelli, I., Fredrikson, M., and Jha, S. (2018, January 9–12). Privacy risk in machine learning: Analyzing the connection to overfitting. Proceedings of the 2018 IEEE 31st Computer Security Foundations Symposium (CSF), Oxford, UK.10.1109/CSF.2018.00027 ↗
56. Lost in the Middle: How Language Models Use Long Contexts10.1162/tacl_a_00638 ↗
57. Freitag, M., and Al-Onaizan, Y. (2017). Beam Search Strategies for Neural Machine Translation. arXiv.10.18653/v1/W17-3207 ↗
58. Holtzman, A., Buys, J., Forbes, M., Bosselut, A., Golub, D., and Choi, Y. (2018). Learning to Write with Cooperative Discriminators. arXiv.10.18653/v1/P18-1152 ↗
59. Holtzman, A., Buys, J., Forbes, M., and Choi, Y. (2019). The Curious Case of Neural Text Degeneration. arXiv.