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

Refactoring the generate() function #6949

Merged
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
29a3ff0
first draft
patrickvonplaten Sep 4, 2020
3d7d954
show design proposition for new generate method
patrickvonplaten Sep 11, 2020
3c8a12a
up
patrickvonplaten Sep 11, 2020
a4e884a
make better readable
patrickvonplaten Sep 11, 2020
3792726
make first version
patrickvonplaten Oct 19, 2020
94720c7
fix merge conflicts
patrickvonplaten Oct 19, 2020
296c92d
gpt2 tests pass
patrickvonplaten Oct 19, 2020
867cd78
Merge branch 'master' of https://github.com/huggingface/transformers …
patrickvonplaten Oct 20, 2020
ba7cc98
make beam search for gpt2 work
patrickvonplaten Oct 20, 2020
9d1145e
add first encoder-decoder code
patrickvonplaten Oct 20, 2020
128beff
delete typo
patrickvonplaten Oct 22, 2020
f1697b0
make t5 work
patrickvonplaten Oct 22, 2020
af53ad7
save indermediate
patrickvonplaten Oct 22, 2020
0672e68
:wqaMerge remote-tracking branch 'main/master' into generation_refactor
patrickvonplaten Oct 22, 2020
d6f2c22
make bart work with beam search
patrickvonplaten Oct 22, 2020
3b48c16
finish beam search bart / t5
patrickvonplaten Oct 22, 2020
5df79e2
add default kwargs
patrickvonplaten Oct 22, 2020
ed85be7
make more tests pass
patrickvonplaten Oct 26, 2020
55a8e3a
fix no bad words sampler
patrickvonplaten Oct 26, 2020
67335a1
some fixes and tests for all distribution processors
patrickvonplaten Oct 27, 2020
929b7db
fix test
patrickvonplaten Oct 27, 2020
49f3904
fix rag slow tests
patrickvonplaten Oct 27, 2020
9148b90
merge conflict
patrickvonplaten Oct 27, 2020
0edd6c9
merge to master
patrickvonplaten Oct 27, 2020
c110c48
add nograd to generate
patrickvonplaten Oct 27, 2020
bd36d58
make all slow tests pass
patrickvonplaten Oct 27, 2020
382fa82
speed up generate
patrickvonplaten Oct 27, 2020
f948904
fix edge case bug
patrickvonplaten Oct 27, 2020
2618ca4
small fix
patrickvonplaten Oct 27, 2020
98a61ab
correct typo
patrickvonplaten Oct 27, 2020
df01065
add type hints and docstrings
patrickvonplaten Oct 28, 2020
37fd850
fix typos in tests
patrickvonplaten Oct 28, 2020
785850d
add beam search tests
patrickvonplaten Oct 28, 2020
f2fbfd6
add tests for beam scorer
patrickvonplaten Oct 29, 2020
3de3d4e
fix test rag
patrickvonplaten Oct 29, 2020
6450550
finish beam search tests
patrickvonplaten Oct 29, 2020
e0fd26d
move generation tests in seperate file
patrickvonplaten Oct 29, 2020
a6d7ca4
fix generation tests
patrickvonplaten Oct 30, 2020
1d3e1e9
more tests
patrickvonplaten Oct 30, 2020
cd98f12
add aggressive generation tests
patrickvonplaten Oct 30, 2020
94cc484
fix tests
patrickvonplaten Oct 30, 2020
af83fa5
add gpt2 sample test
patrickvonplaten Oct 30, 2020
2ddc17b
add more docstring
patrickvonplaten Oct 30, 2020
532d35e
Merge branch 'master' into generation_refactor
patrickvonplaten Nov 1, 2020
d0a77f2
add more docs
patrickvonplaten Nov 1, 2020
bd53c5b
finish doc strings
patrickvonplaten Nov 2, 2020
e2f9761
apply some more of sylvains and sams comments
patrickvonplaten Nov 2, 2020
eb5f578
fix some typos
patrickvonplaten Nov 2, 2020
182764e
make fix copies
patrickvonplaten Nov 2, 2020
cf4535e
apply lysandres and sylvains comments
patrickvonplaten Nov 3, 2020
67518f6
final corrections on examples
patrickvonplaten Nov 3, 2020
12b54ec
small fix for reformer
patrickvonplaten Nov 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,4 @@ conversion utilities for the following models:
internal/pipelines_utils
internal/tokenization_utils
internal/trainer_utils
internal/generation_utils
50 changes: 50 additions & 0 deletions docs/source/internal/generation_utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Utilities for Generation
-----------------------------------------------------------------------------------------------------------------------

This page lists all the utility functions used by :meth:`~transformers.PretrainedModel.generate`,
:meth:`~transformers.PretrainedModel.greedy_search`, :meth:`~transformers.PretrainedModel.sample`,
:meth:`~transformers.PretrainedModel.beam_search`, and :meth:`~transformers.PretrainedModel.beam_sample`.

Most of those are only useful if you are studying the code of the generate methods in the library.

LogitsProcessor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A :class:`~transformers.LogitsProcessor` can be used to modify the prediction scores of a language model head for
generation.

.. autoclass:: transformers.LogitsProcessor
:members: __call__

.. autoclass:: transformers.LogitsProcessorList
:members: __call__

.. autoclass:: transformers.MinLengthLogitsProcessor
:members: __call__

.. autoclass:: transformers.TemperatureLogitsWarper
:members: __call__

.. autoclass:: transformers.RepetitionPenaltyLogitsProcessor
:members: __call__

.. autoclass:: transformers.TopPLogitsWarper
:members: __call__

.. autoclass:: transformers.TopKLogitsWarper
:members: __call__

.. autoclass:: transformers.NoRepeatNGramLogitsProcessor
:members: __call__

.. autoclass:: transformers.NoBadWordsLogitsProcessor
:members: __call__

BeamSearch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.BeamScorer
:members: process, finalize

.. autoclass:: transformers.BeamSearchScorer
:members: process, finalize
13 changes: 13 additions & 0 deletions src/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,19 @@
TextDataset,
TextDatasetForNextSentencePrediction,
)
from .generation_beam_search import BeamScorer, BeamSearchScorer
from .generation_logits_process import (
LogitsProcessor,
LogitsProcessorList,
LogitsWarper,
MinLengthLogitsProcessor,
NoBadWordsLogitsProcessor,
NoRepeatNGramLogitsProcessor,
RepetitionPenaltyLogitsProcessor,
TemperatureLogitsWarper,
TopKLogitsWarper,
TopPLogitsWarper,
)
from .generation_utils import top_k_top_p_filtering
from .modeling_albert import (
ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
Expand Down
Loading