{"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/characterizing-large-language-model-geometry","title":"Characterizing Large Language Model Geometry Helps Solve Toxicity Detection and Generation","arxiv_id":"2312.01648","date":"2023-12-04","proceeding":null,"authors":["Randall Balestriero","Romain Cosentino","Sarath Shekkizhar"],"abstract":"Large Language Models (LLMs) drive current AI breakthroughs despite very little being known about their internal representations. In this work, we propose to shed the light on LLMs inner mechanisms through the lens of geometry. In particular, we develop in closed form $(i)$ the intrinsic dimension in which the Multi-Head Attention embeddings are constrained to exist and $(ii)$ the partition and per-region affine mappings of the feedforward (MLP) network of LLMs' layers. Our theoretical findings further enable the design of novel principled solutions applicable to state-of-the-art LLMs. First, we show that, through our geometric understanding, we can bypass LLMs' RLHF protection by controlling the embedding's intrinsic dimension through informed prompt manipulation. Second, we derive interpretable geometrical features that can be extracted from any (pre-trained) LLM, providing a rich abstract representation of their inputs. We observe that these features are sufficient to help solve toxicity detection, and even allow the identification of various types of toxicity. Our results demonstrate how, even in large-scale regimes, exact theoretical results can answer practical questions in LLMs. Code: https://github.com/RandallBalestriero/SplineLLM","url_abs":"https://arxiv.org/abs/2312.01648v3","url_pdf":"https://arxiv.org/pdf/2312.01648v3.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":"characterizing-large-language-model-geometry","repo_url":"https://github.com/randallbalestriero/splinellm","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok","spdx":"NOASSERTION"}}],"tasks":[{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"large-language-model","task_name":"Large Language Model"}],"methods":[{"method_slug":"jigsaw","method_name":"Jigsaw"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2312.01648","atlas_url":"https://app.syntology.ai/?focus=2312.01648","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2312.01648"}},"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/randallbalestriero/splinellm","reach":{"status":"ok","spdx":"NOASSERTION"}}],"summary":{"ran_fixture":2,"ran":4,"ran_draft_wrong":1,"unverified":6},"by_repo_kind":{"official":{"samples":13,"ran":7,"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":13,"samples":[{"code_sha256_prefix":"30d7eec482ebf6b1","entry":"repeat_kv","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"modeling_llama.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":2,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"30d7eec482ebf6b1"}},{"code_sha256_prefix":"f725bc2d76076485","entry":"apply_rotary_pos_emb","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"modeling_llama.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f725bc2d76076485"}},{"code_sha256_prefix":"12a12995c1053234","entry":"fit_sup","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"statistic_analysis.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/statistic_analysis.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"12a12995c1053234"}},{"code_sha256_prefix":"23e3672bc122afcc","entry":"load_data","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"statistic_analysis.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/statistic_analysis.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"23e3672bc122afcc"}},{"code_sha256_prefix":"14bcb35bbf9ee4d1","entry":"load_data","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"text_features_figure.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/text_features_figure.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"14bcb35bbf9ee4d1"}},{"code_sha256_prefix":"b99eea6376d1e212","entry":"rotate_half","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"modeling_llama.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/modeling_llama.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b99eea6376d1e212"}},{"code_sha256_prefix":"949a366d9461e73b","entry":"text_with_autofit","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"text_features_figure.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/text_features_figure.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"949a366d9461e73b"}},{"code_sha256_prefix":"c2f133d308ead1c4","entry":"classify_dataset","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"huggingface_classifiers.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/huggingface_classifiers.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"c2f133d308ead1c4"}},{"code_sha256_prefix":"5c0bfe90ef68eed9","entry":"clustering","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"statistic_analysis.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/statistic_analysis.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"5c0bfe90ef68eed9"}},{"code_sha256_prefix":"f5cfb4bc1437b436","entry":"generative_model_inference","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"generation_utils.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/generation_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"f5cfb4bc1437b436"}},{"code_sha256_prefix":"edb3dc8a5aa98bf3","entry":"get_dataset","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"data_utils.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/data_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"edb3dc8a5aa98bf3"}},{"code_sha256_prefix":"21e2a016b769f048","entry":"load_generative_model_and_tokenizer","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"generation_utils.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/generation_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"21e2a016b769f048"}},{"code_sha256_prefix":"2315da591a30fd63","entry":"load_pile","repo":"randallbalestriero/splinellm","repo_kind":"official","path":"data_utils.py","file_url":"https://github.com/randallbalestriero/splinellm/blob/HEAD/data_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"2315da591a30fd63"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}