Hard Prompts Made Easy: Gradient-Based Discrete Optimization for Prompt Tuning and Discovery

The strength of modern generative models lies in their ability to be controlled through text-based prompts. Typical"hard"prompts are made from interpretable words and tokens, and must be hand-crafted by humans. There are also"soft"prompts, which consist of continuous feature vectors. These can be discovered using powerful optimization methods, but they cannot be easily interpreted, re-used across models, or plugged into a text-based interface. We describe an approach to robustly optimize hard text prompts through efficient gradient-based optimization. Our approach automatically generates hard text-based prompts for both text-to-image and text-to-text applications. In the text-to-image setting, the method creates hard prompts for diffusion models, allowing API users to easily generate, discover, and mix and match image concepts without prior knowledge on how to prompt the model. In the text-to-text setting, we show that hard prompts can be automatically discovered that are effective in tuning LMs for classification.

Paper

References (39)

Scroll for more · 27 remaining

Similar papers

Peer review

Reviewer 7Vg67/10 · confidence 3/52023-06-29

Summary

The paper presents an approach to optimize hard text prompts for generative models through efficient gradient-based optimization. The method automatically generates hard text-based prompts for both text-to-image and text-to-text applications, allowing users to easily generate, discover, and mix and match image concepts without prior knowledge on how to prompt the model. The paper highlights the advantages of hard prompts over soft prompts and demonstrates the effectiveness of the approach in tuning language models for classification.

Strengths

1. The paper's approach is efficient and can be optimized on smaller language models and then transferred to other, much larger models. 2. The method performs consistently across all four datasets and outperforms other gradient-based optimization baselines. It can achieve similar performance to CLIP Interrogator. However, the proposed method only uses the CLIP model for prompt discovery and 8 tokens in total demonstrating its simultaneous simplicity and strength. 3. The proposed approach can also be easily adapted to style transfer. Given several examples that share the same style, the method can extract their shared style characteristics into a single hard prompt and use this prompt to apply the style to new objects or scenes (Page 5).

Weaknesses

1. While the method can generate relevant tokens and phrases, the prompts are not always coherent English. This suggests that while the optimization process is finding relevant words to the task, it lacks the ability to create full sentences. 2. Longer prompts do not necessarily produce better results when generating with Stable Diffusion, even though they strictly reduce loss on the CLIP image encoder. Long prompts thus overfit and are less transferable. Thus, it may require hyperparameter tuning, which may heavy and tedious.

Questions

You mentioned that longer prompts do not necessarily produce better results and can lead to overfitting. Could you elaborate on the mechanisms behind this phenomenon and suggest potential strategies to mitigate this issue while maintaining the quality of the generated prompts?

Rating

7: Accept: Technically solid paper, with high impact on at least one sub-area, or moderate-to-high impact on more than one areas, with good-to-excellent evaluation, resources, reproducibility, and no unaddressed ethical considerations.

Confidence

3: You are fairly confident in your assessment. It is possible that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work. Math/other details were not carefully checked.

Soundness

4 excellent

Presentation

4 excellent

Contribution

4 excellent

Limitations

As the author has discussed, the generated prompts may still contain several un-interpretable tokens. Also, it may lack the ability to create full sentences.

Reviewer DXf66/10 · confidence 3/52023-07-04

Summary

The paper presents an easy-to-use approach to automatically obtain hard prompts for images. The work introduces PEZ, a gradient-based approach to obtain hard prompts for images. The experiments comparing a popular baseline show improved CLIP score. Finally, the qualitative results show that the method can distill prompts into shorter sequences and concatenates

Strengths

The paper is easy to follow. The algorithm is well explained and the results are quite promising. The results for prompt inversion appear to be fair and outperform the baseline. The analysis is quite clear and thorough. Overall, the work presents a straightforward method to get prompt tokens for images.

Weaknesses

The contribution of the work is limited: the work is mostly an application of existing work that discretizes soft prompts to tokens [a,b]. There is no significant difference between the proposed work and existing related work. The authors should clarify, in-depth, the main differences between their work and other work. Further, like AutoPrompt, the work suffers from gibberish prompts according to the authors (see Figure 2, “uuuu romantic canvas impressionist …”). This limitation makes the hard prompts harder to interpret. The explanation regarding the emoji appearing in the hard prompt (Figure 2 and line 174) is not entirely convincing. It would be really helpful to also know how often the model produces gibberish. Limited Evaluation: the experiments do not overwhelming support that PEZ is better than CLIP interrogator. On two out of the four datasets under consideration, CLIP interrogator achieves a higher CLIPScore. It is also unclear why AutoPromptSGD is not included in Table 1. Wouldn’t this be a good baseline? Negative Qualitative Examples: The paper could benefit from showing negative results where the method doesn’t perform as well. Nit: It would be helpful to look at the results along with Tables/Figures on the same page. At the moment, style transfer, prompt concatenation, and prompt distillation do not appear on the same page. [a] Gradient-Based Constrained Sampling from Language Models. EMNLP 2022. [b] Toward Human Readable Prompt Tuning: Kubrick’s The Shining is a good movie, and a good prompt too? ArXiv 2022.

Questions

Please address the questions in the weakness section. Minor: since you are using cosine distance as a loss function, does it run into instability issues? Is there a particular reason you are using cosine distance as a loss function?

Rating

6: Weak Accept: Technically solid, moderate-to-high impact paper, with no major concerns with respect to evaluation, resources, reproducibility, ethical considerations.

Confidence

3: You are fairly confident in your assessment. It is possible that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work. Math/other details were not carefully checked.

Soundness

2 fair

Presentation

2 fair

Contribution

2 fair

Limitations

The method requires the model weights to produce hard prompts. Given that recent methods use APIs, it would be useful to highlight this as a potential limitation.

Reviewer LSBN5/10 · confidence 3/52023-07-06

Summary

This paper works on hard prompt optimization with gradient methods, especially a discrete text prompt is discovered using CLIP, and optimized to prompt stable diffusion.

Strengths

1. Without hand-crafted design of hard prompt, the proposed solution directly discover and optimize prompt with gradient descent, leading to very efficient prompt engineering. 2. The learned prompt works great on stable diffusion and achieve effective style transfer, further explains the superiority of the proposed solution.

Weaknesses

The proposed solution works on discrete text prompt optimization without constraints on meaningfulness of the text, making it hard to directly understand to the effectiveness of prompt optimization.

Questions

1. Ablation study shows performance saturation with middle number of prompt length. More analysis is needed to explain this result. 2. Prompt distillation seems interesting to explain the prompt length issue, however, how the distillation ratio is correlated with the quality of the generated samples should also be explained further.

Rating

5: Borderline accept: Technically solid paper where reasons to accept outweigh reasons to reject, e.g., limited evaluation. Please use sparingly.

Confidence

3: You are fairly confident in your assessment. It is possible that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work. Math/other details were not carefully checked.

Soundness

3 good

Presentation

2 fair

Contribution

3 good

Limitations

Yes

Reviewer Lu7o5/10 · confidence 4/52023-07-07

Summary

This work proposes a new paradigm which optimizes discrete prompts simply by gradient projection to bridge the gap between relatively “easy-to-optimize” soft prompts and their hard counterparts. Their methodology is straightforward and effective in downstream text-to-image task requirements. And more specifically, comparing to existing gradient-based approaches, such as AutoPrompt, their approach is less hyper-parameter sensitive equipping with their gradient projection. All these advantages offer a new lens on how to optimize discrete prompts for text-to-image generation models, and LLMs likewise.

Strengths

1. This framework is easy to implement, by simply gradient projection in the soft embedding space, and the performance seems promising compared to popular caption-based "CLIP interrogator". It does contribute another approach for such optimization problem. 2. The experiments do show the advantages of such framework, such as "the insensitiveness to hyper-parameters". 3. The paper organization is good, and the writing is well-polished.

Weaknesses

1. I think adding more baselines in your main table would definitely be a plus! Currently, you mainly compare this to a heuristic-based yet popular method called "CLIP interrogator". Can you compare your approach with more diversified baselines, e.g., "AutoPrompt with different LRs", "RLPrompt", etc.. These can let readers gain a basic intuitive understandings of your method's performance against others. 2. In your main table, the improvements of yours compared to CLIP interrogator seems to be marginal, where your performance is almost the same level of performance with CLIP interrogator, even though you only include fewer tokens. 3. Besides, can you show some quantitative and qualitative examples on directly showing on the same set of images, what are the optimized prompts by CLIP interrogator, and what are the optimized prompts by yours (and perhaps, their word overlapping by distillation), such that we can enhance our understandings that your approach identify a "secret" language, like initial work [1] (in addition to possible application contributions, the secret language could also contribute to scientific research if your pipeline is good at identifying such phenomenon). Otherwise, to one of your contributions that your identified prompt is shorter, we may speculate that the prompts in CLIP interrogator can also be distilled into the same short length, and even with the same key tokens as your pipeline. Therefore, the secret language observation would be weaken. Besides, the CLIP interrogator even does not require any training with similar level of performance and even similar level of short lengths through distillation, why not we use their easier pipeline? --- Currently, figure 6 further enhances my confidence on such point as well, as your prompts include a lot of natural tokens in accordance with our common-sense understandings, such as cat images should use "cat" tokens. 4. Additionally, practitioners would be interested in your optimization efficiency as well for such algorithm to identify well-crafted prompts, comparing to many other soft/hard prompt optimization work. In terms of this, if you have better efficiency, that is also another good point, where I am also interested. [1] Discovering the hidden vocabulary of DALLE-2, arxiv 2022 So right now, I am more viewing this work's contribution as a different perspective/approach to prompt optimization for text-to-image generation models, and even more models. Of course, that is interesting, and useful/insightful to the community. However, a key limitation would be such utilities are not quite clear alongside all current prompt optimization approaches. And the performance improvement seems to somewhat limited compared to CLIP interrogator. Hopefully, my suggestions would be useful for you to improve your content.

Questions

See weaknesses.

Rating

5: Borderline accept: Technically solid paper where reasons to accept outweigh reasons to reject, e.g., limited evaluation. Please use sparingly.

Confidence

4: You are confident in your assessment, but not absolutely certain. It is unlikely, but not impossible, that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work.

Soundness

3 good

Presentation

3 good

Contribution

2 fair

Limitations

See weaknesses.

Reviewer Lu7o2023-08-12

Reviewer Lu7o Replies

<1. baselines> - From your rebuttal, I have understood what is your key advantage you want to show now. Precisely, that is the **efficiency** compared to other baselines (w/ your similar level of performance as many baselines), such as AutoPrompt, RLPrompt, etc. It would be much better for you to consider adding efficiency comparisons visualizations/discussions. Additionally, I am not sure whether RLPrompt would fail in this case, as image-level/instance-level optimization takes fewer time, which deserves some experiments as well. If it is weaker/much slower than your approach in a few cases, it would be good to include this and highlight several times in your paper, to make it more clear about your key advantages. Moreover, from your new AutoPrompt experiments, it would be good for you to add one **rigorous** figure on the efficiency comparison results, e.g., using the best setup and also the less good setup (such as other LR, prompt length in AutoPrompt), to position your approach. This would definitely add some values to your paper. <2. CLIP interrogator> - Thanks for your clarification. It does seem that interrogator performs much weaker with fewer tokens. But as you said, it would be good for you to incorporate some efficiency studies as well. That can address my concerns on your approach vs. CLIP interrogator. <3. Secret Language> - This part is just for one of your claims. You said you identify a secret language of text-to-image diffusion models [1]. But in the initial paper, the lexical items that they used are purely gibberish tokens, w/o any significant real-world meanings, such as "Apoploe vesrreaitais" for birds. But in your results, and also your new pdf results, you always include some natural tokens, for instance, "butterfly emoji + users', 'cruise + green render lights', "balloon relationships", “cat” for cat image, and many more shown in your paper figures. I am curious about more fine-grained studies on your generated prompts. For instance, others might suspect that when deleting your natural meaningful tokens, your generated results would fail completely, which may indicate a weaker claim of "secret language". Or in other words, perhaps, most of your used nonsense tokens are mainly search artifacts. Therefore, my comments are to say it would be better for you to provide some rigorous studies. I believe this point is also mentioned by reviewer DXf6, for which I agree with him/her. [1] Discovering the Hidden Vocabulary of DALLE-2 <4. efficiency results> - See 1, it would be better for you to provide rigorous studies to position your approach. For current rating, I am saying that this work should be further improved to be an interesting paper published in this conference. So I select the borderline rating, in which I would like to wait for other reviewers or ACs for final judgements.

Authorsrebuttal2023-08-18

Official Comment by Authors

Thank you for your positive and thoughtful response. > <1. baselines> and <4. efficiency results> We appreciate this suggestion. We have updated our draft to include a rigorous comparison of clip score v.s. wall-time. Due to the rebuttal rules, we can only present a markdown table here, but we will include our associated figure in the camera ready version also including RLPrompt, which is omitted here due to its very high runtime. | prompt length | lr | method | 100 steps | 200 steps | 400 steps | 600 steps | 1000 steps | |:-------------:|:---:|:----------:|:---------:|:-----:|:-----:|:-----:|:-----:| | 4 | 0.1 | AutoPrompt | 0.461 | 0.515 | 0.536 | 0.551 | 0.578 | | | | PEZ | 0.610 | 0.635 | 0.653 | 0.666 | 0.666 | | | 1 | AutoPrompt | 0.614 | 0.639 | 0.663 | 0.667 | 0.670 | | | | PEZ | 0.649 | 0.657 | 0.663 | 0.660 | 0.668 | | | 10 | AutoPrompt | 0.643 | 0.649 | 0.663 | 0.665 | 0.662 | | | | PEZ | 0.645 | 0.653 | 0.672 | 0.681 | 0.680 | | 8 | 0.1 | AutoPrompt | 0.516 | 0.553 | 0.582 | 0.598 | 0.614 | | | | PEZ | 0.632 | 0.656 | 0.671 | 0.677 | 0.678 | | | 1 | AutoPrompt | 0.641 | 0.654 | 0.656 | 0.672 | 0.683 | | | | PEZ | 0.667 | 0.673 | 0.674 | 0.684 | 0.690 | | | 10 | AutoPrompt | 0.644 | 0.662 | 0.671 | 0.671 | 0.676 | | | | PEZ | 0.670 | 0.677 | 0.679 | 0.679 | 0.682 | | 16 | 0.1 | AutoPrompt | 0.551 | 0.595 | 0.628 | 0.631 | 0.639 | | | | PEZ | 0.646 | 0.665 | 0.679 | 0.686 | 0.695 | | | 1 | AutoPrompt | 0.663 | 0.672 | 0.680 | 0.680 | 0.687 | | | | PEZ | 0.657 | 0.686 | 0.678 | 0.690 | 0.691 | | | 10 | AutoPrompt | 0.665 | 0.665 | 0.672 | 0.682 | 0.679 | | | | PEZ | 0.678 | 0.682 | 0.681 | 0.681 | 0.686 | > <2. CLIP interrogator> The CLIP interrogator consistently requires the same amount of time regardless of the length of the prompt. This is because it calculates the clip scores between the target image and all tokens in the prior bank, then selects the top-k to fill approximately 70 tokens. However, it's crucial to highlight that our method offers competitive prompts with significantly fewer tokens than the CLIP interrogator. This provides users with increased flexibility, allowing them to concatenate tokens or use the prompt as a style guide. Such flexibility stands as a notable advantage of our pipeline. Furthermore, quantifying the efficiency of the CLIP interrogator in terms of the number of steps can be challenging, so we have added an efficiency comparison based on wall time to our working draft and will include it in our camera-ready version. > <3. Secret Language> Prompted by your feedback, we have now conducted an experiment to see if all gibberish tokens are indeed search artifacts (not meaningful for generation). We present an example here and have added others to our working draft, including both instances where gibberish tokens are valuable and ones where they are not. Consider the following text, "translucent abyss assaulted surfing featured regrann nbappinterest", which produces a surfer in a wave tunnel found in Figure 9 of the Appendix. We find that some tokens like "nbappinterest" and "assaulted" are not necessary for good generations. However, "regrann" is crucial, despite sounding unrelated to the image at hand and despite "regrann" not being a real word. Nonetheless, "regrann" is critical for producing sensible images in numerous ways (i.e. not producing a second person, making sure the surf board is in one piece, etc.). These two words/tokens contribute to the image in ways that are non-obvious at first glance. We believe that this example and our other examples suggest that the language model extracts meaning from tokens which a human would not. We do agree that adding such examples is valuable, and we have now additionally clarified in our working draft that we are referring to the extraction of meaning from tokens which a human would not extract meaning from or where a human may extract vastly different meaning. Thank you again for engaging and for your helpful suggestions. We would greatly appreciate it if you would consider improving your score in light of our detailed response. Do you have any other questions we can address?

Reviewer Lu7o2023-08-21

Replies from Reviewer Lu7o

Thanks for your replies. I have the following comments: 1. Yes, it would be nice to incorporate more comparisons w.r.t. your efficiency comparisons. From now on, I am also curious about when AutoPrompt could be competitive to your approach, by tuning the hyper-parameters, e.g., more training steps. And for RLPrompt, it sounds like you may need to pay attention to its input format, e.g., how many examples are batched as the final reward calculations. Perhaps, you can also do some experiments, just for more clear and thorough baselines. 2. Yes, it would be nice. 3. For secret language section, yes, please make it much more clear in your work, to avoid any confusions or ambiguities. And more visualized examples on these phenomena are high encouraged. Hope my comments are informative enough for you to improve your work. I could raise my score as well for possible well-polished paper (I am looking forward to read the updated version), and let the ACs judge the final recommendations from our discussions.

Reviewer 7Vg62023-08-12

Acknowledgement of rebuttal

Thank you for the rebuttal. My questions were addressed . Thus I keep my score. Good luck!

Reviewer DXf62023-08-16

Reply to the Authors

Thank you for the detailed response. I really appreciate you uploading additional negative results in the PDF. I also liked your response to Reviewer LSBN where you have included prompts with more tokens (8 to 64). It would be awesome if you could include this ablation in the paper as well. I do have a few concerns: 1. The additional table included in the rebuttal shows that PEZ converges faster than AutoPrompt. This is a positive result. I would include this detail in the paper. But, as pointed out in my review, Table 1 in the paper is incomplete without AutoPrompt. It might be the case that AutoPrompt performs better than PEZ on all the other datasets. If the work is about efficiency compared to AutoPrompt, then you might have to highlight the tradeoffs between PEZ and AutoPrompt in terms of efficiency vs. performance. 2. Minor: could you clarify what you mean by the following statement? > It's important to note, however, that these two scenarios can be mitigated by optimizing with various initializations. Overall, I think the authors have put in a lot of effort to improve their paper. However, I feel the paper could be positioned better to highlight the practical benefits in terms of efficiency compared to existing work. I think the work would benefit from another round of submission. I will gladly increase my scores if other reviewers feel strongly about the paper.

Authorsrebuttal2023-08-18

Official Comment by Authors

Regarding 1, we included the results for AutoPrompt in Table 2 of the Appendix. PEZ shows improvement over AutoPrompt. We have updated our working draft to incorporate these findings, as well as the efficiency results like the table below, into the main paper and will include them in the camera-ready version. | prompt length | lr | method | 100 steps | 200 steps | 400 steps | 600 steps | 1000 steps | |:-------------:|:---:|:----------:|:---------:|:-----:|:-----:|:-----:|:-----:| | 4 | 0.1 | AutoPrompt | 0.461 | 0.515 | 0.536 | 0.551 | 0.578 | | | | PEZ | 0.610 | 0.635 | 0.653 | 0.666 | 0.666 | | | 1 | AutoPrompt | 0.614 | 0.639 | 0.663 | 0.667 | 0.670 | | | | PEZ | 0.649 | 0.657 | 0.663 | 0.660 | 0.668 | | | 10 | AutoPrompt | 0.643 | 0.649 | 0.663 | 0.665 | 0.662 | | | | PEZ | 0.645 | 0.653 | 0.672 | 0.681 | 0.680 | | 8 | 0.1 | AutoPrompt | 0.516 | 0.553 | 0.582 | 0.598 | 0.614 | | | | PEZ | 0.632 | 0.656 | 0.671 | 0.677 | 0.678 | | | 1 | AutoPrompt | 0.641 | 0.654 | 0.656 | 0.672 | 0.683 | | | | PEZ | 0.667 | 0.673 | 0.674 | 0.684 | 0.690 | | | 10 | AutoPrompt | 0.644 | 0.662 | 0.671 | 0.671 | 0.676 | | | | PEZ | 0.670 | 0.677 | 0.679 | 0.679 | 0.682 | | 16 | 0.1 | AutoPrompt | 0.551 | 0.595 | 0.628 | 0.631 | 0.639 | | | | PEZ | 0.646 | 0.665 | 0.679 | 0.686 | 0.695 | | | 1 | AutoPrompt | 0.663 | 0.672 | 0.680 | 0.680 | 0.687 | | | | PEZ | 0.657 | 0.686 | 0.678 | 0.690 | 0.691 | | | 10 | AutoPrompt | 0.665 | 0.665 | 0.672 | 0.682 | 0.679 | | | | PEZ | 0.678 | 0.682 | 0.681 | 0.681 | 0.686 | Regarding 2, for certain failure cases, we observed that users can achieve a more effective prompt by restarting the optimization with a different initialization for the hard prompt. This situation is similar to the "+5 seeds" scenario depicted in Table 1. We see that this phrase was ambiguous, so we have clarified it in our draft, and we thank you for pointing that out. Thank you again for your detailed and constructive feedback. We have incorporated each of your suggestions into our draft, and we would appreciate it if you would consider increasing your score accordingly. Do you have any other questions we can address?

Reviewer DXf62023-08-18

Updating score to weak accept

Thank you for adding the additional result. First, this Table highlights three points: (1) PEZ requires fewer prompt tokens, (2) PEZ converges faster than AutoPrompt, and (3) PEZ is robust to the change in learning rate. It would be great if you could include these points in the paper. It could help better position your work in terms of efficiency. Second, you could suggest an explanation for the high learning rate (lr=10). Finally, Your most recent response to the reviewer Lu7o is helpful to the readers. You could include that detail in the paper. I am updating my score from 4 to 6.

Program Chairsdecision2023-09-21

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC