{"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/deep-k-nearest-neighbors-towards-confident","title":"Deep k-Nearest Neighbors: Towards Confident, Interpretable and Robust Deep Learning","arxiv_id":"1803.04765","date":"2018-03-13","proceeding":null,"authors":["Nicolas Papernot","Patrick McDaniel"],"abstract":"Deep neural networks (DNNs) enable innovative applications of machine\nlearning like image recognition, machine translation, or malware detection.\nHowever, deep learning is often criticized for its lack of robustness in\nadversarial settings (e.g., vulnerability to adversarial inputs) and general\ninability to rationalize its predictions. In this work, we exploit the\nstructure of deep learning to enable new learning-based inference and decision\nstrategies that achieve desirable properties such as robustness and\ninterpretability. We take a first step in this direction and introduce the Deep\nk-Nearest Neighbors (DkNN). This hybrid classifier combines the k-nearest\nneighbors algorithm with representations of the data learned by each layer of\nthe DNN: a test input is compared to its neighboring training points according\nto the distance that separates them in the representations. We show the labels\nof these neighboring points afford confidence estimates for inputs outside the\nmodel's training manifold, including on malicious inputs like adversarial\nexamples--and therein provides protections against inputs that are outside the\nmodels understanding. This is because the nearest neighbors can be used to\nestimate the nonconformity of, i.e., the lack of support for, a prediction in\nthe training data. The neighbors also constitute human-interpretable\nexplanations of predictions. We evaluate the DkNN algorithm on several\ndatasets, and show the confidence estimates accurately identify inputs outside\nthe model, and that the explanations provided by nearest neighbors are\nintuitive and useful in understanding model failures.","url_abs":"http://arxiv.org/abs/1803.04765v1","url_pdf":"http://arxiv.org/pdf/1803.04765v1.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":"deep-k-nearest-neighbors-towards-confident","repo_url":"https://github.com/bam098/deep_knn","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}},{"paper_slug":"deep-k-nearest-neighbors-towards-confident","repo_url":"https://github.com/fiona-lxd/AdvKnn","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"deep-k-nearest-neighbors-towards-confident","repo_url":"https://github.com/peck94/cann-detector","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"tf","reach":{"status":"ok"}},{"paper_slug":"deep-k-nearest-neighbors-towards-confident","repo_url":"https://github.com/rodgzilla/machine_learning_deep_knn","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok"}}],"tasks":[{"task_slug":"machine-translation","task_name":"Machine Translation"},{"task_slug":"malware-detection","task_name":"Malware Detection"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/1803.04765","atlas_url":"https://app.syntology.ai/?focus=1803.04765","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"1803.04765"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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/rodgzilla/machine_learning_deep_knn","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/peck94/cann-detector","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/fiona-lxd/AdvKnn","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/bam098/deep_knn","reach":{"status":"ok"}}],"summary":{"ran_draft_wrong":1,"ran_fixture":2},"by_repo_kind":{"listed":{"samples":3,"ran":3,"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":"26d9f9fc3682e736","entry":"get_feats","repo":"fiona-lxd/AdvKnn","repo_kind":"listed","path":"attack.py","file_url":"https://github.com/fiona-lxd/AdvKnn/blob/HEAD/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"26d9f9fc3682e736"}},{"code_sha256_prefix":"9327cee9ffcdcc5f","entry":"knn","repo":"fiona-lxd/AdvKnn","repo_kind":"listed","path":"attack.py","file_url":"https://github.com/fiona-lxd/AdvKnn/blob/HEAD/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9327cee9ffcdcc5f"}},{"code_sha256_prefix":"79c0d47a0e121164","entry":"perturb","repo":"fiona-lxd/AdvKnn","repo_kind":"listed","path":"attack.py","file_url":"https://github.com/fiona-lxd/AdvKnn/blob/HEAD/attack.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"79c0d47a0e121164"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}