{"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/soft-prompt-generation-for-domain","title":"Soft Prompt Generation for Domain Generalization","arxiv_id":"2404.19286","date":"2024-04-30","proceeding":null,"authors":["Shuanghao Bai","Yuedi Zhang","Wanqi Zhou","Zhirong Luan","Badong Chen"],"abstract":"Large pre-trained vision language models (VLMs) have shown impressive zero-shot ability on downstream tasks with manually designed prompt. To further adapt VLMs to downstream tasks, soft prompt is proposed to replace manually designed prompt, which undergoes fine-tuning based on specific domain data. Prior prompt learning methods primarily learn a fixed prompt or residuled prompt from training samples. However, the learned prompts lack diversity and ignore information about unseen domains. In this paper, we reframe the prompt learning framework from a generative perspective and propose a simple yet efficient method for the Domain Generalization (DG) task, namely Soft Prompt Generation (SPG). Specifically, SPG consists of a two-stage training phase and an inference phase. During the training phase, we introduce soft prompt label for each domain, aiming to incorporate the generative model domain knowledge. During the inference phase, the generator of the generative model is employed to obtain instance-specific soft prompts for the unseen target domain. Extensive experiments on five domain generalization benchmarks of three DG tasks demonstrate that SPG achieves state-of-the-art performance. The code is available at https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN.","url_abs":"https://arxiv.org/abs/2404.19286v2","url_pdf":"https://arxiv.org/pdf/2404.19286v2.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":"soft-prompt-generation-for-domain","repo_url":"https://github.com/renytek13/soft-prompt-generation-with-cgan","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"diversity","task_name":"Diversity"},{"task_slug":"domain-generalization","task_name":"Domain Generalization"},{"task_slug":"prompt-learning","task_name":"Prompt Learning"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[{"leaderboard":"/sota/domain-generalization-on-domainnet","task":"Domain Generalization","dataset":"DomainNet","model":"SPG (CLIP, ViT-B/16)","rank_in_archive_order":12,"of":38,"metrics":{"Average Accuracy":"60.1"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-domainnet","task":"Domain Generalization","dataset":"DomainNet","model":"SPG (CLIP, ResNet-50)","rank_in_archive_order":21,"of":38,"metrics":{"Average Accuracy":"50.1"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-office-home","task":"Domain Generalization","dataset":"Office-Home","model":"SPG (CLIP, ViT-B/16)","rank_in_archive_order":11,"of":45,"metrics":{"Average Accuracy":"83.6"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-office-home","task":"Domain Generalization","dataset":"Office-Home","model":"SPG (CLIP, ResNet-50)","rank_in_archive_order":20,"of":45,"metrics":{"Average Accuracy":"73.8"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-pacs-2","task":"Domain Generalization","dataset":"PACS","model":"SPG (CLIP, ViT-B/16)","rank_in_archive_order":8,"of":133,"metrics":{"Average Accuracy":"97.0"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-pacs-2","task":"Domain Generalization","dataset":"PACS","model":"SPG (CLIP, ResNet-50)","rank_in_archive_order":18,"of":133,"metrics":{"Average Accuracy":"92.8"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-terraincognita","task":"Domain Generalization","dataset":"TerraIncognita","model":"SPG (CLIP, ViT-B/16)","rank_in_archive_order":24,"of":30,"metrics":{"Average Accuracy":"50.2"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-vlcs","task":"Domain Generalization","dataset":"VLCS","model":"SPG (CLIP, ResNet-50)","rank_in_archive_order":3,"of":37,"metrics":{"Average Accuracy":"84.0"},"uses_additional_data":false},{"leaderboard":"/sota/domain-generalization-on-vlcs","task":"Domain Generalization","dataset":"VLCS","model":"SPG (CLIP, ViT-B/16)","rank_in_archive_order":11,"of":37,"metrics":{"Average Accuracy":"82.4"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2404.19286","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2404.19286"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+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":"deterministic:regex_extraction","url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_draft_wrong":3,"ran":3,"unverified":3},"by_repo_kind":{"official":{"samples":9,"ran":6,"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":"98f385d847636a3e","entry":"basic_clean","repo":"renytek13/Soft-Prompt-Generation-with-CGAN","repo_kind":"official","path":"clip/simple_tokenizer.py","file_url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN/blob/HEAD/clip/simple_tokenizer.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"98f385d847636a3e"}},{"code_sha256_prefix":"fb8b765f896ca77c","entry":"fixed_patch","repo":"renytek13/Soft-Prompt-Generation-with-CGAN","repo_kind":"official","path":"utils/visual_prompt.py","file_url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN/blob/HEAD/utils/visual_prompt.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"fb8b765f896ca77c"}},{"code_sha256_prefix":"d919ae32e5e4e616","entry":"get_pairs","repo":"renytek13/Soft-Prompt-Generation-with-CGAN","repo_kind":"official","path":"clip/simple_tokenizer.py","file_url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN/blob/HEAD/clip/simple_tokenizer.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d919ae32e5e4e616"}},{"code_sha256_prefix":"98c70398b832504f","entry":"padding","repo":"renytek13/Soft-Prompt-Generation-with-CGAN","repo_kind":"official","path":"utils/visual_prompt.py","file_url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN/blob/HEAD/utils/visual_prompt.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"98c70398b832504f"}},{"code_sha256_prefix":"3f8752aa7aac40b9","entry":"random_patch","repo":"renytek13/Soft-Prompt-Generation-with-CGAN","repo_kind":"official","path":"utils/visual_prompt.py","file_url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN/blob/HEAD/utils/visual_prompt.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3f8752aa7aac40b9"}},{"code_sha256_prefix":"9542161e9640b858","entry":"whitespace_clean","repo":"renytek13/Soft-Prompt-Generation-with-CGAN","repo_kind":"official","path":"clip/simple_tokenizer.py","file_url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN/blob/HEAD/clip/simple_tokenizer.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9542161e9640b858"}},{"code_sha256_prefix":"39e6b23b55f376ea","entry":"build_model","repo":"renytek13/Soft-Prompt-Generation-with-CGAN","repo_kind":"official","path":"clip/model.py","file_url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN/blob/HEAD/clip/model.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"39e6b23b55f376ea"}},{"code_sha256_prefix":"021a688e5389b8b6","entry":"load","repo":"renytek13/Soft-Prompt-Generation-with-CGAN","repo_kind":"official","path":"clip/clip.py","file_url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN/blob/HEAD/clip/clip.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"021a688e5389b8b6"}},{"code_sha256_prefix":"60e8a0a6b4aae51d","entry":"save_split","repo":"renytek13/Soft-Prompt-Generation-with-CGAN","repo_kind":"official","path":"datasets/domainnet_coop.py","file_url":"https://github.com/renytek13/Soft-Prompt-Generation-with-CGAN/blob/HEAD/datasets/domainnet_coop.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"60e8a0a6b4aae51d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}