{"id":{"repo_id":"colostate","oai_identifier":"oai:mountainscholar.org:10217/245339"},"canonical_url":"https://search.ndltd.org/etd/colostate/oai:mountainscholar.org:10217/245339","repository":{"repo_id":"colostate","name":"Colorado State University","base_url":"https://api.mountainscholar.org/server/oai/request"},"display":{"title":"The impact of few-shot examples for LLM-based code vulnerability detection","abstract":"Large language models (LLMs) have shown promise for detecting software vulnerabilities through in-context learning (ICL), where a small number of labeled examples are provided in the prompt to guide model predictions. However, the effectiveness of ICL depends critically on how these few-shot examples are selected, and little is studied about what these models actually attend to when making their decisions. This work addresses both gaps directly. First, how should those few-shot examples be selected to maximize detection performance? Second, when the model makes correct predictions, is it actually focusing on the right tokens of the vulnerable code? The first part studies two selection criteria: Learn-from-Mistakes (LFM), which prioritizes examples on which the model consistently makes errors, and Learn-from-Nearest-Neighbors (LFNN), which retrieves semantically similar examples using a code embedding model. We evaluate these methods and three combined strategies on five datasets spanning C/C++, Python, and JavaScript, using Qwen2.5-Coder-7B-Instruct, Gemma-3-4b-it, and GPT-5-mini. As a single method, LFNN consistently improves performance on Python and JavaScript, while C/C++ datasets remain resistant to few-shot adaptation. Combined methods showed the best performance overall. The second part takes the LFNN pipeline and Qwen model, and audits its internal attribution behavior using Layer Integrated Gradients (LIG). Our experiments reveal that among the top-50 tokens identified by the attribution method, 40 to 52 percent belong to the injected few-shot examples. More strikingly, fewer than 2 percent of those top-50 tokens correspond to actual vulnerable tokens, even on samples the model predicted correctly. These findings show that even when LFNN improves detection accuracy, gradient-based attributions are not always grounded in the actual vulnerable code tokens, revealing a gap between performance and reliability in LLM-based code vulnerability detection.","abstract_html":"Large language models (LLMs) have shown promise for detecting software vulnerabilities through in-context learning (ICL), where a small number of labeled examples are provided in the prompt to guide model predictions. However, the effectiveness of ICL depends critically on how these few-shot examples are selected, and little is studied about what these models actually attend to when making their decisions. This work addresses both gaps directly. First, how should those few-shot examples be selected to maximize detection performance? Second, when the model makes correct predictions, is it actually focusing on the right tokens of the vulnerable code? The first part studies two selection criteria: Learn-from-Mistakes (LFM), which prioritizes examples on which the model consistently makes errors, and Learn-from-Nearest-Neighbors (LFNN), which retrieves semantically similar examples using a code embedding model. We evaluate these methods and three combined strategies on five datasets spanning C/C++, Python, and JavaScript, using Qwen2.5-Coder-7B-Instruct, Gemma-3-4b-it, and GPT-5-mini. As a single method, LFNN consistently improves performance on Python and JavaScript, while C/C++ datasets remain resistant to few-shot adaptation. Combined methods showed the best performance overall. The second part takes the LFNN pipeline and Qwen model, and audits its internal attribution behavior using Layer Integrated Gradients (LIG). Our experiments reveal that among the top-50 tokens identified by the attribution method, 40 to 52 percent belong to the injected few-shot examples. More strikingly, fewer than 2 percent of those top-50 tokens correspond to actual vulnerable tokens, even on samples the model predicted correctly. These findings show that even when LFNN improves detection accuracy, gradient-based attributions are not always grounded in the actual vulnerable code tokens, revealing a gap between performance and reliability in LLM-based code vulnerability detection.","abstract_has_math":false,"creators":["Hannan, Md Abdul, author","Mangal, Ravi, advisor","Ghosh, Sudipto, committee member","Vijayasarathy, Leo, committee member"],"institution":"Colorado State University. Libraries","degree_name":"Master of Science (M.S.)","degree_level":"Masters","degree_discipline":"Computer Science","degree_department":null,"school":null,"contributors":[],"advisors":[],"committee_chairs":[],"committee_members":[],"year":2026,"date_issued":"2026","date_published":"2026","updated_at":"2026-11-19T07:09:28Z","subjects":["few-shot","LLMs","attribution","vulnerability","LIG"],"languages":["eng","English"],"rights":["Copyright and other restrictions may apply. User is responsible for compliance with all applicable laws. For information about copyright law, please see https://libguides.colostate.edu/copyright.","This Item is protected by copyright and/or related rights (https://rightsstatements.org/vocab/InC/1.0/). You are free to use this Item in any way that is permitted by the copyright and related rights legislation that applies to your use. For other uses you need to obtain permission from the rights-holder(s)."],"rights_urls":[],"identifier_entries":[{"key":"dc:identifier.uri","label":"Identifier URI","values":["https://hdl.handle.net/10217/245339"],"render_values":[{"text":"https://hdl.handle.net/10217/245339","href":"https://hdl.handle.net/10217/245339","code":true}]},{"key":"dc:identifier","label":"Identifier","values":["Hannan_colostate_0053N_19738.pdf"],"render_values":[{"text":"Hannan_colostate_0053N_19738.pdf","href":null,"code":true}]}],"person_identifier_entries":[]},"links":{"outbound_url":"https://doi.org/10.25675/3.027353","outbound_label":"DOI","outbound_source":"dc:identifier.uri","record_url":"https://doi.org/10.25675/3.027353","record_label":"Repository record","record_kind":"doi","record_source":"dc:identifier.uri","access_status":null,"embargo_until":null,"access_note":null},"oai_pmh_record":{"url":"https://union.ndltd.org/oai-pmh/?verb=GetRecord&metadataPrefix=oai_dc&identifier=oai%3Aunion.ndltd.org%3Arepo%3Acolostate%3Aoai%3Amountainscholar.org%3A10217%2F245339","prefix":"oai_dc"},"source_record":{"url":"https://api.mountainscholar.org/server/oai/request?verb=GetRecord&metadataPrefix=dim&identifier=oai%3Amountainscholar.org%3A10217%2F245339","prefix":"dim"},"metadata_groups":[{"id":"people","label":"People","entries":[{"key":"dc:creator","label":"Author","values":["Hannan, Md Abdul, author","Mangal, Ravi, advisor","Ghosh, Sudipto, committee member","Vijayasarathy, Leo, committee member"]}]},{"id":"academic_context","label":"Academic Context","entries":[{"key":"dc:date.accessioned","label":"Dc Date Accessioned","values":["2026-08-24T10:38:31Z"]},{"key":"dc:date.issued","label":"Date","values":["2026"]},{"key":"dc:publisher","label":"Institution","values":["Colorado State University. Libraries"]},{"key":"dc:relation.ispartof","label":"Dc Relation Ispartof","values":["2020-"]},{"key":"dc:type","label":"Dc Type","values":["Text"]},{"key":"thesis:degree_discipline","label":"Discipline","values":["Computer Science"]},{"key":"thesis:degree_level","label":"Degree Level","values":["Masters"]},{"key":"thesis:degree_name","label":"Degree Name","values":["Master of Science (M.S.)"]},{"key":"thesis:institution_name","label":"Thesis Institution Name","values":["Colorado State University"]}]},{"id":"subjects_keywords","label":"Subjects and Keywords","entries":[{"key":"dc:subject","label":"Dc Subject","values":["few-shot","LLMs","attribution","vulnerability","LIG"]}]},{"id":"language_rights","label":"Language and Rights","entries":[{"key":"dc:language","label":"Dc Language","values":["English"]},{"key":"dc:language.iso","label":"Language (ISO)","values":["eng"]},{"key":"dc:rights","label":"Dc Rights","values":["Copyright and other restrictions may apply. User is responsible for compliance with all applicable laws. For information about copyright law, please see https://libguides.colostate.edu/copyright.","This Item is protected by copyright and/or related rights (https://rightsstatements.org/vocab/InC/1.0/). You are free to use this Item in any way that is permitted by the copyright and related rights legislation that applies to your use. For other uses you need to obtain permission from the rights-holder(s)."]}]},{"id":"identifiers","label":"Identifiers","entries":[{"key":"dc:identifier","label":"Identifier","values":["Hannan_colostate_0053N_19738.pdf"]},{"key":"dc:identifier.uri","label":"Identifier URI","values":["https://hdl.handle.net/10217/245339","https://doi.org/10.25675/3.027353"]}]},{"id":"additional","label":"Additional Metadata","entries":[{"key":"dc:description.abstract","label":"Abstract","values":["Large language models (LLMs) have shown promise for detecting software vulnerabilities through in-context learning (ICL), where a small number of labeled examples are provided in the prompt to guide model predictions. However, the effectiveness of ICL depends critically on how these few-shot examples are selected, and little is studied about what these models actually attend to when making their decisions. This work addresses both gaps directly. First, how should those few-shot examples be selected to maximize detection performance? Second, when the model makes correct predictions, is it actually focusing on the right tokens of the vulnerable code? The first part studies two selection criteria: Learn-from-Mistakes (LFM), which prioritizes examples on which the model consistently makes errors, and Learn-from-Nearest-Neighbors (LFNN), which retrieves semantically similar examples using a code embedding model. We evaluate these methods and three combined strategies on five datasets spanning C/C++, Python, and JavaScript, using Qwen2.5-Coder-7B-Instruct, Gemma-3-4b-it, and GPT-5-mini. As a single method, LFNN consistently improves performance on Python and JavaScript, while C/C++ datasets remain resistant to few-shot adaptation. Combined methods showed the best performance overall. The second part takes the LFNN pipeline and Qwen model, and audits its internal attribution behavior using Layer Integrated Gradients (LIG). Our experiments reveal that among the top-50 tokens identified by the attribution method, 40 to 52 percent belong to the injected few-shot examples. More strikingly, fewer than 2 percent of those top-50 tokens correspond to actual vulnerable tokens, even on samples the model predicted correctly. These findings show that even when LFNN improves detection accuracy, gradient-based attributions are not always grounded in the actual vulnerable code tokens, revealing a gap between performance and reliability in LLM-based code vulnerability detection."]},{"key":"dc:format.medium","label":"Dc Format Medium","values":["born digital","masters theses"]},{"key":"dc:title","label":"Title","values":["The impact of few-shot examples for LLM-based code vulnerability detection"]},{"key":"others:access_status","label":"Others Access Status","values":["open.access"]}]}],"canonical_facts":{"dc:creator":["Hannan, Md Abdul, author","Mangal, Ravi, advisor","Ghosh, Sudipto, committee member","Vijayasarathy, Leo, committee member"],"dc:date.accessioned":["2026-08-24T10:38:31Z"],"dc:date.issued":["2026"],"dc:description.abstract":["Large language models (LLMs) have shown promise for detecting software vulnerabilities through in-context learning (ICL), where a small number of labeled examples are provided in the prompt to guide model predictions. However, the effectiveness of ICL depends critically on how these few-shot examples are selected, and little is studied about what these models actually attend to when making their decisions. This work addresses both gaps directly. First, how should those few-shot examples be selected to maximize detection performance? Second, when the model makes correct predictions, is it actually focusing on the right tokens of the vulnerable code? The first part studies two selection criteria: Learn-from-Mistakes (LFM), which prioritizes examples on which the model consistently makes errors, and Learn-from-Nearest-Neighbors (LFNN), which retrieves semantically similar examples using a code embedding model. We evaluate these methods and three combined strategies on five datasets spanning C/C++, Python, and JavaScript, using Qwen2.5-Coder-7B-Instruct, Gemma-3-4b-it, and GPT-5-mini. As a single method, LFNN consistently improves performance on Python and JavaScript, while C/C++ datasets remain resistant to few-shot adaptation. Combined methods showed the best performance overall. The second part takes the LFNN pipeline and Qwen model, and audits its internal attribution behavior using Layer Integrated Gradients (LIG). Our experiments reveal that among the top-50 tokens identified by the attribution method, 40 to 52 percent belong to the injected few-shot examples. More strikingly, fewer than 2 percent of those top-50 tokens correspond to actual vulnerable tokens, even on samples the model predicted correctly. These findings show that even when LFNN improves detection accuracy, gradient-based attributions are not always grounded in the actual vulnerable code tokens, revealing a gap between performance and reliability in LLM-based code vulnerability detection."],"dc:format.medium":["born digital","masters theses"],"dc:identifier":["Hannan_colostate_0053N_19738.pdf"],"dc:identifier.uri":["https://hdl.handle.net/10217/245339","https://doi.org/10.25675/3.027353"],"dc:language":["English"],"dc:language.iso":["eng"],"dc:publisher":["Colorado State University. Libraries"],"dc:relation.ispartof":["2020-"],"dc:rights":["Copyright and other restrictions may apply. User is responsible for compliance with all applicable laws. For information about copyright law, please see https://libguides.colostate.edu/copyright.","This Item is protected by copyright and/or related rights (https://rightsstatements.org/vocab/InC/1.0/). You are free to use this Item in any way that is permitted by the copyright and related rights legislation that applies to your use. For other uses you need to obtain permission from the rights-holder(s)."],"dc:subject":["few-shot","LLMs","attribution","vulnerability","LIG"],"dc:title":["The impact of few-shot examples for LLM-based code vulnerability detection"],"dc:type":["Text"],"others:access_status":["open.access"],"thesis:degree_discipline":["Computer Science"],"thesis:degree_level":["Masters"],"thesis:degree_name":["Master of Science (M.S.)"],"thesis:institution_name":["Colorado State University"]},"updated_at":"2026-11-19T07:09:28Z"}