-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
Enhance DataCollatorForLanguageModeling with Configurable Token Replacement Probabilities #35251
Enhance DataCollatorForLanguageModeling with Configurable Token Replacement Probabilities #35251
Conversation
… that provides more control over the token masking and relacing
… that provides more control over the token masking and relacing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this addition to the class! Some suggestions before we can merge it, though:
- You"ll need to run
pip install transformers[quality]
followed bymake style
to fix the code style issues - We"ll need some tests to cover these new options! They should go in
tests/trainer/test_data_collator.py
.
Because the collator uses random sampling, though, please don"t write tests that check the number of masked tokens is close to the expected value - these are very flaky and tend to randomly fail 1% of the time, which is very annoying in our CI. Instead, I suggest setting values to 0 or 1 and confirming that you get the expected behaviour - e.g. set mask_replace_prob=1
and confirm that every token is either the original token or [MASK]
. You can also set illegal values and confirm that an error is raised.
… the DataCollatorForLanguageModeling
Thanks for the feedback!
|
@mahdibaghbanzadeh this looks good now! Let me know whenever you"re ready for final review and I"ll ping a core maintainer |
@Rocketknight1 Thanks, Please let them know to do the final review. |
cc @ArthurZucker for core maintainer review! |
hi @mahdibaghbanzadeh, and sorry for the Christmas delay! The core maintainers are pretty overworked at the moment, but I just did a final review and I"m happy with this. Let me know if there"s anything you want to change before we merge! |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
hi @Rocketknight1 and happy New Year! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merging, in that case, and thank you for the PR!
This pull request introduces enhancements to the
DataCollatorForLanguageModeling
class, providing greater flexibility for token replacement during masked language modeling (MLM). The key changes include:Configurable Replacement Probabilities:
mask_replace_prob
: Specifies the probability of replacing masked tokens with the[MASK]
token (default: 80%).random_replace_prob
: Specifies the probability of replacing masked tokens with random tokens from the vocabulary (default: 10%).Edge Case Handling:
random_replace_prob
to the remaining probability after applyingmask_replace_prob
.mask_replace_prob
andrandom_replace_prob
does not exceed 1.Backward Compatibility:
Examples of New Functionality
Replace 80% of masked tokens with
[MASK]
, 10% with random tokens, and leave 10% unchanged.[MASK]
:Additional Notes
This enhancement gives users greater control over MLM training configurations, catering to various pretraining and fine-tuning use cases.