{"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/guardt2i-defending-text-to-image-models-from","title":"GuardT2I: Defending Text-to-Image Models from Adversarial Prompts","arxiv_id":"2403.01446","date":"2024-03-03","proceeding":null,"authors":["Yijun Yang","Ruiyuan Gao","Xiao Yang","Jianyuan Zhong","Qiang Xu"],"abstract":"Recent advancements in Text-to-Image (T2I) models have raised significant safety concerns about their potential misuse for generating inappropriate or Not-Safe-For-Work (NSFW) contents, despite existing countermeasures such as NSFW classifiers or model fine-tuning for inappropriate concept removal. Addressing this challenge, our study unveils GuardT2I, a novel moderation framework that adopts a generative approach to enhance T2I models' robustness against adversarial prompts. Instead of making a binary classification, GuardT2I utilizes a Large Language Model (LLM) to conditionally transform text guidance embeddings within the T2I models into natural language for effective adversarial prompt detection, without compromising the models' inherent performance. Our extensive experiments reveal that GuardT2I outperforms leading commercial solutions like OpenAI-Moderation and Microsoft Azure Moderator by a significant margin across diverse adversarial scenarios. Our framework is available at https://github.com/cure-lab/GuardT2I.","url_abs":"https://arxiv.org/abs/2403.01446v2","url_pdf":"https://arxiv.org/pdf/2403.01446v2.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":"guardt2i-defending-text-to-image-models-from","repo_url":"https://github.com/cure-lab/guardt2i","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"guardt2i-defending-text-to-image-models-from","repo_url":"https://github.com/cure-lab/mma-diffusion","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"guardt2i-defending-text-to-image-models-from","repo_url":"https://github.com/yangyijune/mma-diffusion","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"NOASSERTION"}}],"tasks":[{"task_slug":"binary-classification","task_name":"Binary Classification"},{"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":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2403.01446","atlas_url":"https://app.syntology.ai/?focus=2403.01446","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2403.01446"}},"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/yangyijune/mma-diffusion","reach":{"status":"ok","spdx":"NOASSERTION"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/cure-lab/mma-diffusion","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/cure-lab/guardt2i","reach":null}],"summary":{"ran_violates":2,"ran_draft_wrong":2,"ran":4,"ran_fixture":1,"unverified":3},"by_repo_kind":{"official":{"samples":3,"ran":1,"repositories":1},"listed":{"samples":9,"ran":8,"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":12,"samples":[{"code_sha256_prefix":"e432fc8d1c6d470a","entry":"check_words","repo":"cure-lab/guardt2i","repo_kind":"official","path":"evaluation.py","file_url":"https://github.com/cure-lab/guardt2i/blob/HEAD/evaluation.py","link_basis":"first_harvest_node","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e432fc8d1c6d470a"}},{"code_sha256_prefix":"c8f23038de7bcdb7","entry":"cosine_distance","repo":"yangyijune/mma-diffusion","repo_kind":"listed","path":"src/image_space_attack/image_editing_attack.py","file_url":"https://github.com/yangyijune/mma-diffusion/blob/HEAD/src/image_space_attack/image_editing_attack.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c8f23038de7bcdb7"}},{"code_sha256_prefix":"13dc2cf88597bab9","entry":"decode_latents","repo":"yangyijune/mma-diffusion","repo_kind":"listed","path":"src/image_space_attack/image_editing_attack.py","file_url":"https://github.com/yangyijune/mma-diffusion/blob/HEAD/src/image_space_attack/image_editing_attack.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"13dc2cf88597bab9"}},{"code_sha256_prefix":"e72218600c06eb3d","entry":"denoise_and_dilate","repo":"yangyijune/mma-diffusion","repo_kind":"listed","path":"src/image_space_attack/image_editing_attack.py","file_url":"https://github.com/yangyijune/mma-diffusion/blob/HEAD/src/image_space_attack/image_editing_attack.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":"e72218600c06eb3d"}},{"code_sha256_prefix":"f1d34b6601986ffa","entry":"logits","repo":"yangyijune/mma-diffusion","repo_kind":"listed","path":"src/textual_attack.py","file_url":"https://github.com/yangyijune/mma-diffusion/blob/HEAD/src/textual_attack.py","link_basis":"plan_row","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f1d34b6601986ffa"}},{"code_sha256_prefix":"3e43cde496b041c3","entry":"prepare_mask_and_masked_image","repo":"yangyijune/mma-diffusion","repo_kind":"listed","path":"src/image_space_attack/utils.py","file_url":"https://github.com/yangyijune/mma-diffusion/blob/HEAD/src/image_space_attack/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":"3e43cde496b041c3"}},{"code_sha256_prefix":"84f6eb64e73f1bbb","entry":"preprocess","repo":"yangyijune/mma-diffusion","repo_kind":"listed","path":"src/image_space_attack/utils.py","file_url":"https://github.com/yangyijune/mma-diffusion/blob/HEAD/src/image_space_attack/utils.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":"84f6eb64e73f1bbb"}},{"code_sha256_prefix":"6cecfc267a0132f7","entry":"recover_image","repo":"yangyijune/mma-diffusion","repo_kind":"listed","path":"src/image_space_attack/utils.py","file_url":"https://github.com/yangyijune/mma-diffusion/blob/HEAD/src/image_space_attack/utils.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":"6cecfc267a0132f7"}},{"code_sha256_prefix":"f99e03e03e6b2072","entry":"token_gradient","repo":"yangyijune/mma-diffusion","repo_kind":"listed","path":"src/textual_attack.py","file_url":"https://github.com/yangyijune/mma-diffusion/blob/HEAD/src/textual_attack.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"f99e03e03e6b2072"}},{"code_sha256_prefix":"42734f935fcb7396","entry":"eval_decoder","repo":"cure-lab/guardt2i","repo_kind":"official","path":"training_code/train_cllm.py","file_url":"https://github.com/cure-lab/guardt2i/blob/HEAD/training_code/train_cllm.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":"42734f935fcb7396"}},{"code_sha256_prefix":"64762d38e7f09b9a","entry":"sample_control","repo":"yangyijune/mma-diffusion","repo_kind":"listed","path":"src/textual_attack.py","file_url":"https://github.com/yangyijune/mma-diffusion/blob/HEAD/src/textual_attack.py","link_basis":"plan_row","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":"64762d38e7f09b9a"}},{"code_sha256_prefix":"5fde6cab839cbeb2","entry":"train_decoder","repo":"cure-lab/guardt2i","repo_kind":"official","path":"training_code/train_cllm.py","file_url":"https://github.com/cure-lab/guardt2i/blob/HEAD/training_code/train_cllm.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":"5fde6cab839cbeb2"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}