{"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/removing-nsfw-concepts-from-vision-and","title":"Safe-CLIP: Removing NSFW Concepts from Vision-and-Language Models","arxiv_id":"2311.16254","date":"2023-11-27","proceeding":null,"authors":["Samuele Poppi","Tobia Poppi","Federico Cocchi","Marcella Cornia","Lorenzo Baraldi","Rita Cucchiara"],"abstract":"Large-scale vision-and-language models, such as CLIP, are typically trained on web-scale data, which can introduce inappropriate content and lead to the development of unsafe and biased behavior. This, in turn, hampers their applicability in sensitive and trustworthy contexts and could raise significant concerns in their adoption. Our research introduces a novel approach to enhancing the safety of vision-and-language models by diminishing their sensitivity to NSFW (not safe for work) inputs. In particular, our methodology seeks to sever \"toxic\" linguistic and visual concepts, unlearning the linkage between unsafe linguistic or visual items and unsafe regions of the embedding space. We show how this can be done by fine-tuning a CLIP model on synthetic data obtained from a large language model trained to convert between safe and unsafe sentences, and a text-to-image generator. We conduct extensive experiments on the resulting embedding space for cross-modal retrieval, text-to-image, and image-to-text generation, where we show that our model can be remarkably employed with pre-trained generative models. Our source code and trained models are available at: https://github.com/aimagelab/safe-clip.","url_abs":"https://arxiv.org/abs/2311.16254v3","url_pdf":"https://arxiv.org/pdf/2311.16254v3.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":"removing-nsfw-concepts-from-vision-and","repo_url":"https://github.com/aimagelab/safe-clip","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"cross-modal-retrieval","task_name":"Cross-Modal Retrieval"},{"task_slug":"image-generation","task_name":"Image Generation"},{"task_slug":"image-retrieval","task_name":"Image Retrieval"},{"task_slug":"image-to-text","task_name":"Image to text"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"large-language-model","task_name":"Large Language Model"},{"task_slug":"retrieval","task_name":"Retrieval"},{"task_slug":"text-generation","task_name":"Text Generation"},{"task_slug":"text-to-image-generation","task_name":"Text-to-Image Generation"}],"methods":[{"method_slug":"clip","method_name":"CLIP"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2311.16254","atlas_url":"https://app.syntology.ai/?focus=2311.16254","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2311.16254"}},"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/aimagelab/safe-clip","reach":{"status":"ok"}}],"summary":{"ran_draft_wrong":1,"ran":2,"unverified":4},"by_repo_kind":{"official":{"samples":7,"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":7,"samples":[{"code_sha256_prefix":"592b3c1a88f93d7c","entry":"expand2square","repo":"aimagelab/safe-clip","repo_kind":"official","path":"LLaVA_generation/llava/mm_utils.py","file_url":"https://github.com/aimagelab/safe-clip/blob/HEAD/LLaVA_generation/llava/mm_utils.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"well_formed","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"592b3c1a88f93d7c"}},{"code_sha256_prefix":"c3ee9d07c900dd55","entry":"load_image_from_base64","repo":"aimagelab/safe-clip","repo_kind":"official","path":"LLaVA_generation/llava/mm_utils.py","file_url":"https://github.com/aimagelab/safe-clip/blob/HEAD/LLaVA_generation/llava/mm_utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c3ee9d07c900dd55"}},{"code_sha256_prefix":"632348f499baceca","entry":"replace_activation","repo":"aimagelab/safe-clip","repo_kind":"official","path":"openclip_zeroshot.py","file_url":"https://github.com/aimagelab/safe-clip/blob/HEAD/openclip_zeroshot.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"632348f499baceca"}},{"code_sha256_prefix":"1111a1c694170bfe","entry":"compute_recall","repo":"aimagelab/safe-clip","repo_kind":"official","path":"training/recall_computation.py","file_url":"https://github.com/aimagelab/safe-clip/blob/HEAD/training/recall_computation.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1111a1c694170bfe"}},{"code_sha256_prefix":"dc2da1c68d1c4b35","entry":"encode_dataset","repo":"aimagelab/safe-clip","repo_kind":"official","path":"training/recall_computation.py","file_url":"https://github.com/aimagelab/safe-clip/blob/HEAD/training/recall_computation.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"dc2da1c68d1c4b35"}},{"code_sha256_prefix":"344dff4791fd1381","entry":"process_images","repo":"aimagelab/safe-clip","repo_kind":"official","path":"LLaVA_generation/llava/mm_utils.py","file_url":"https://github.com/aimagelab/safe-clip/blob/HEAD/LLaVA_generation/llava/mm_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"344dff4791fd1381"}},{"code_sha256_prefix":"add3477ef19c6b53","entry":"recall","repo":"aimagelab/safe-clip","repo_kind":"official","path":"training/recall_computation.py","file_url":"https://github.com/aimagelab/safe-clip/blob/HEAD/training/recall_computation.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"add3477ef19c6b53"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}