Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] LLM prompting guide #26274

Merged
merged 18 commits into from
Oct 12, 2023
Merged

Conversation

MKhalusova
Copy link
Contributor

@MKhalusova MKhalusova commented Sep 19, 2023

What does this PR do?

This PR addresses part 2.2 ("Prompting" ) of the issue #24575

It adds an LLM Prompting Guide to the docs that covers the following topics:

  • basics of prompting,
  • encoder-decoder models vs decoder-only models,
  • base vs instruct models,
  • basic prompts to solve common NLP tasks,
  • best practices for prompting,
  • advanced techniques like few-shot learning and chain-of-thought
  • prompting vs fine-tuning

Let me know, if there's anything missing that has to be included.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 20, 2023

The documentation is not available anymore as the PR was closed or merged.

@MKhalusova
Copy link
Contributor Author

The first draft of the LLM prompting guide is ready for review, let me know if anything major is missing. cc @patrickvonplaten

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! My main feedback is:

  • Let's maybe not pass default parameters to make sure the pipeline call function stays simple. E.g. I think we can remove all the num_return_sequences=1 statements as well as the eos_token_id=... statements as the model should have that set as the default (see here).
  • For task that do pure classification (sentiment analysis) or NER where there is arguably one and only one answer and where the model only generates a few tokens, I think it'd be better to not set do_sample=True and instead leave the sampling to be greedy - I don't think we want to introduce any randomness there. Maybe a 1-2 liner explaining the difference could also help there

docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved
docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved
docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved
docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved
docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved
docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved
docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved
docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved

This is a wrong answer, it should be 12. In this case, this can be due to the prompt being too basic, or due to the choice
of model, after all we've picked the smallest version of Falcon. Reasoning is difficult for models of all sizes, but larger
models are likely to perform better.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice I like this!

* "Lead" the output in the right direction by writing the first word (or even begin the first sentence for the model).
* Use advanced techniques like [Few-shot prompting](#few-shot-prompting) and [Chain-of-thought](#chain-of-thought)
* Test your prompts with different models to assess their robustness.
* Version and track the performance of your prompts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tips!

@MKhalusova MKhalusova marked this pull request as ready for review September 22, 2023 13:39
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great :)

Only left a few comments

docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved
docs/source/en/tasks/prompting.md Outdated Show resolved Hide resolved
docs/source/en/tasks/prompting.md Show resolved Hide resolved
@LysandreJik
Copy link
Member

Feel free to merge when satisfied with it!

@MKhalusova
Copy link
Contributor Author

@LysandreJik I'm happy with it, but I think we should wait for @gante to review it once he's back from vacation.

@MKhalusova
Copy link
Contributor Author

Gently pinging @gante for a review :)

Copy link
Member

@gante gante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great guide, with clear examples, great suggestions, and relevant caveats. Big thumbs up, thank you for writing this guide @MKhalusova 💛

@MKhalusova MKhalusova merged commit 0ebee8b into huggingface:main Oct 12, 2023
8 checks passed
helboukkouri pushed a commit to helboukkouri/transformers that referenced this pull request Oct 16, 2023
* llm prompting guide

* updated code examples

* an attempt to fix the code example tests

* set seed in examples

* added a doctest comment

* added einops to the doc_test_job

* string formatting

* string formatting, again

* added the toc to slow_documentation_tests.txt

* minor list fix

* string formatting + pipe renamed

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>

* replaced max_length with max_new_tokens and updated the outputs to match

* minor formatting fix

* removed einops from circleci config

* Apply suggestions from code review

Co-authored-by: Lysandre Debut <hi@lysand.re>

* removed einops and trust_remote_code parameter

---------

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Co-authored-by: Lysandre Debut <hi@lysand.re>
blbadger pushed a commit to blbadger/transformers that referenced this pull request Nov 8, 2023
* llm prompting guide

* updated code examples

* an attempt to fix the code example tests

* set seed in examples

* added a doctest comment

* added einops to the doc_test_job

* string formatting

* string formatting, again

* added the toc to slow_documentation_tests.txt

* minor list fix

* string formatting + pipe renamed

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>

* replaced max_length with max_new_tokens and updated the outputs to match

* minor formatting fix

* removed einops from circleci config

* Apply suggestions from code review

Co-authored-by: Lysandre Debut <hi@lysand.re>

* removed einops and trust_remote_code parameter

---------

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Co-authored-by: Lysandre Debut <hi@lysand.re>
EduardoPach pushed a commit to EduardoPach/transformers that referenced this pull request Nov 18, 2023
* llm prompting guide

* updated code examples

* an attempt to fix the code example tests

* set seed in examples

* added a doctest comment

* added einops to the doc_test_job

* string formatting

* string formatting, again

* added the toc to slow_documentation_tests.txt

* minor list fix

* string formatting + pipe renamed

* Apply suggestions from code review

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>

* replaced max_length with max_new_tokens and updated the outputs to match

* minor formatting fix

* removed einops from circleci config

* Apply suggestions from code review

Co-authored-by: Lysandre Debut <hi@lysand.re>

* removed einops and trust_remote_code parameter

---------

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Co-authored-by: Lysandre Debut <hi@lysand.re>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants