{"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/discriminative-diffusion-models-as-few-shot","title":"Discffusion: Discriminative Diffusion Models as Few-shot Vision and Language Learners","arxiv_id":"2305.10722","date":"2023-05-18","proceeding":null,"authors":["Xuehai He","Weixi Feng","Tsu-Jui Fu","Varun Jampani","Arjun Akula","Pradyumna Narayana","Sugato Basu","William Yang Wang","Xin Eric Wang"],"abstract":"Diffusion models, such as Stable Diffusion, have shown incredible performance on text-to-image generation. Since text-to-image generation often requires models to generate visual concepts with fine-grained details and attributes specified in text prompts, can we leverage the powerful representations learned by pre-trained diffusion models for discriminative tasks such as image-text matching? To answer this question, we propose a novel approach, Discriminative Stable Diffusion (DSD), which turns pre-trained text-to-image diffusion models into few-shot discriminative learners. Our approach mainly uses the cross-attention score of a Stable Diffusion model to capture the mutual influence between visual and textual information and fine-tune the model via efficient attention-based prompt learning to perform image-text matching. By comparing DSD with state-of-the-art methods on several benchmark datasets, we demonstrate the potential of using pre-trained diffusion models for discriminative tasks with superior results on few-shot image-text matching.","url_abs":"https://arxiv.org/abs/2305.10722v3","url_pdf":"https://arxiv.org/pdf/2305.10722v3.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":"discriminative-diffusion-models-as-few-shot","repo_url":"https://github.com/eric-ai-lab/dsd","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"jax","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"image-generation","task_name":"Image Generation"},{"task_slug":"image-text-matching","task_name":"Image-text matching"},{"task_slug":"prompt-learning","task_name":"Prompt Learning"},{"task_slug":"text-matching","task_name":"Text Matching"},{"task_slug":"text-to-image-generation-1","task_name":"Text to Image Generation"},{"task_slug":"text-to-image-generation","task_name":"Text-to-Image Generation"}],"methods":[{"method_slug":"diffusion","method_name":"Diffusion"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2305.10722","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2305.10722"}},"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":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/eric-ai-lab/dsd","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"unverified":20},"by_repo_kind":{"official":{"samples":20,"ran":0,"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":"4294cf0378461ad2","entry":"average_score","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"dsd_infer.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/dsd_infer.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":"4294cf0378461ad2"}},{"code_sha256_prefix":"0ca47b5cf6386db5","entry":"average_score","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"dsd_train.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/dsd_train.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":"0ca47b5cf6386db5"}},{"code_sha256_prefix":"2aa969a20b25a144","entry":"compute_loss","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"utils/losses.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/utils/losses.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":"2aa969a20b25a144"}},{"code_sha256_prefix":"5bc35c622beca1cc","entry":"compute_score","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"utils/losses.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/utils/losses.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":"5bc35c622beca1cc"}},{"code_sha256_prefix":"61dde694c9bb23c2","entry":"evaluate_comvg","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"eval_score.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/eval_score.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":"61dde694c9bb23c2"}},{"code_sha256_prefix":"3c5ed43dcafc5436","entry":"evaluate_retrieval","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"eval_score.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/eval_score.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":"3c5ed43dcafc5436"}},{"code_sha256_prefix":"e1b88fc15ff00272","entry":"evaluate_vqa","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"eval_score.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/eval_score.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":"e1b88fc15ff00272"}},{"code_sha256_prefix":"6431708d8f3ff177","entry":"get_full_repo_name","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"dsd_train.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/dsd_train.py","link_basis":"plan_row","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":"6431708d8f3ff177"}},{"code_sha256_prefix":"9f228a3f87edcf83","entry":"get_timesteps","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"dsd_train.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/dsd_train.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":"9f228a3f87edcf83"}},{"code_sha256_prefix":"be7a240b9dcc2368","entry":"get_train_dataset","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"custom_datasets.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/custom_datasets.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":"be7a240b9dcc2368"}},{"code_sha256_prefix":"3cacd5275cbd348c","entry":"image_preprocess","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"playground.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/playground.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":"3cacd5275cbd348c"}},{"code_sha256_prefix":"831f5bc2bdeba8c9","entry":"image_preprocess","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"utils/process_dataset.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/utils/process_dataset.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":"831f5bc2bdeba8c9"}},{"code_sha256_prefix":"02a978e30e225398","entry":"load_json","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"utils/helper_functions.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/utils/helper_functions.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":"02a978e30e225398"}},{"code_sha256_prefix":"03616619ada8dbef","entry":"next_available_dirpath","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"dsd_infer.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/dsd_infer.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":"03616619ada8dbef"}},{"code_sha256_prefix":"8f1a44ab20956301","entry":"normalize_word","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"utils/glossary.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/utils/glossary.py","link_basis":"plan_row","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":"8f1a44ab20956301"}},{"code_sha256_prefix":"be2fda5ca6ae10b0","entry":"preprocess","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"diffusers/src/diffusers/pipelines/stable_diffusion/pipeline_dsd.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/diffusers/src/diffusers/pipelines/stable_diffusion/pipeline_dsd.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":"be2fda5ca6ae10b0"}},{"code_sha256_prefix":"c04400bfa2c2f6e0","entry":"process_word","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"utils/glossary.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/utils/glossary.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":"c04400bfa2c2f6e0"}},{"code_sha256_prefix":"248696bec32990b5","entry":"read_svo","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"utils/helper_functions.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/utils/helper_functions.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":"248696bec32990b5"}},{"code_sha256_prefix":"fc89a1b3e420c811","entry":"sanitize_text","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"dsd_infer.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/dsd_infer.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":"fc89a1b3e420c811"}},{"code_sha256_prefix":"42c588f76987fa6f","entry":"show_cropped_image","repo":"eric-ai-lab/dsd","repo_kind":"official","path":"utils/helper_functions.py","file_url":"https://github.com/eric-ai-lab/dsd/blob/HEAD/utils/helper_functions.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":"42c588f76987fa6f"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}