-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Add REALM #13292
Merged
Merged
Add REALM #13292
Changes from 109 commits
Commits
Show all changes
114 commits
Select commit
Hold shift + click to select a range
e68583f
REALM initial commit
qqaatw 4d85596
Retriever OK (Update new_gelu).
qqaatw 1ff4364
Encoder prediction score OK
qqaatw baee376
Encoder pretrained model OK
qqaatw 7ed7265
Update retriever comments
qqaatw dd3fb73
Update docs, tests, and imports
qqaatw 927b106
Prune unused models
qqaatw 96615bd
Make embedder as a module `RealmEmbedder`
qqaatw dea3b2f
Add RealmRetrieverOutput
qqaatw 66859e1
Update tokenization
qqaatw ae889ee
Pass all tests in test_modeling_realm.py
qqaatw 1b3bba2
Prune RealmModel
qqaatw 766d663
Update docs
qqaatw eb1837b
Add training test.
qqaatw b316149
Remove completed TODO
qqaatw 1b14c70
Style & Quality
qqaatw ce0ef70
Prune `RealmModel`
qqaatw 4760751
Merge branch 'master' into add_realm
qqaatw 92a6a5b
Fixup
qqaatw 28b8dac
Changes:
qqaatw bd6d2eb
Fix up
qqaatw 089fd65
Merge branch 'master' into add_realm
qqaatw 633e452
Style
qqaatw 728ef3c
Merge branch 'master' into add_realm
qqaatw 609d7f3
Add tokenization tests
qqaatw 8066399
Update `from_pretrained` tests
qqaatw 09a280c
Apply suggestions
qqaatw 769e8fb
Style & Quality
qqaatw d89a3bd
Merge branch 'master' into add_realm
qqaatw 9d5175b
Copy BERT model
qqaatw 6f64029
Fix comment to avoid docstring copying
qqaatw dc3695b
Make RealmBertModel private
qqaatw 850c38c
Fix bug
qqaatw a11d5c5
Style
qqaatw 831a230
Basic QA
qqaatw 81985e6
Save
qqaatw dbd925d
Complete reader logits
qqaatw f6ffc1e
Add searcher
qqaatw 8ee98d7
Complete searcher & reader
qqaatw 7158fe8
Move block records init to constructor
qqaatw 938ad0a
Fix training bug
qqaatw 55f6531
Add some outputs to RealmReader
qqaatw 89fd9c7
Add finetuned checkpoint variable names parsing
qqaatw 3e57b52
Fix bug
qqaatw 136b3ff
Update REALM config
qqaatw 9f62961
Add RealmForOpenQA
qqaatw de1f3f0
Update convert_tfrecord logits
qqaatw bd16314
Fix bugs
qqaatw c917ef9
Complete imports
qqaatw 113807f
Update docs
qqaatw f46b43e
Update naming
qqaatw a7b727d
Add brute-force searcher
qqaatw e1f3a45
Merge branch 'add_realmqa' into add_realm
qqaatw 426121c
Pass realm model tests
qqaatw 15d3978
Merge branch 'add_realmqa' into add_realm
qqaatw 63e9e70
Merge branch 'master' into add_realmqa
qqaatw 225b2e6
Style
qqaatw 93f315a
Exclude RealmReader from common tests
qqaatw f656bd4
Merge branch 'add_realmqa' into add_realm
qqaatw 4cad343
Fix
qqaatw dd81591
Fix
qqaatw 01ca717
Merge branch 'add_realmqa' into add_realm
qqaatw afa214b
fix readme
patrickvonplaten 36e7f1a
convert docs
patrickvonplaten a41734c
up
patrickvonplaten fb53dad
up
patrickvonplaten 02bae05
more make style
patrickvonplaten 8f50e8c
up
patrickvonplaten fef8cf3
upload
patrickvonplaten 8b723ae
up
patrickvonplaten 348936e
Fix
qqaatw b86139b
Update src/transformers/__init__.py
patrickvonplaten 581c20c
adapt testing
patrickvonplaten 2e6f91f
Merge branch 'add_realm' of https://github.com/qqaatw/transformers in…
patrickvonplaten c39b31f
change modeling code
patrickvonplaten bb78ce5
fix test
patrickvonplaten 851d9ea
up
patrickvonplaten 8e340a1
up
patrickvonplaten 620ac36
up
patrickvonplaten 9708e44
correct more
patrickvonplaten 818718c
make retriever work
patrickvonplaten 6492942
update
patrickvonplaten 0fb7b86
make style
patrickvonplaten 38e2ed0
finish main structure
patrickvonplaten bc56dbb
Resolve merge conflict
qqaatw a62ae6f
Make everything work
qqaatw 167b17b
Style
qqaatw 9627fe8
Fixup
qqaatw 8642eca
Merge upstream master
qqaatw 8bbebd4
Fixup
qqaatw 5c9118a
Update training test
qqaatw f0a2438
Merge branch 'master' of https://github.com/huggingface/transformers …
patrickvonplaten d6d94be
fix retriever
patrickvonplaten e172e73
remove hardcoded path
patrickvonplaten ec695cb
Fix
qqaatw 8550f4e
Merge branch 'add_realm' of https://github.com/qqaatw/transformers in…
qqaatw dc865ca
Fix modeling test
qqaatw ebd507c
Update model links
qqaatw db2f4fe
Initial retrieval test
qqaatw 16577d7
Fix modeling test
qqaatw 881bbd2
Complete retrieval tests
qqaatw 1927e4f
Fix
qqaatw 4048d7d
style
qqaatw 34322b5
Fix tests
qqaatw 06a5412
Fix docstring example
qqaatw 712c4b7
Minor fix of retrieval test
qqaatw 1701f70
Update license headers and docs
qqaatw 493aa10
Apply suggestions from code review
qqaatw fb43dd5
Style
qqaatw 54ee5cb
Merge branch 'master' into add_realm
sgugger a3cbaf0
Apply suggestions from code review
qqaatw 0f4721b
Add an example to RealmEmbedder
qqaatw 894ce5f
Fix
qqaatw d655e5f
Merge branch 'master' into add_realm
qqaatw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<!--Copyright 2022 The HuggingFace Team. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
--> | ||
|
||
# REALM | ||
|
||
## Overview | ||
|
||
The REALM model was proposed in `REALM: Retrieval-Augmented Language Model Pre-Training | ||
<https://arxiv.org/abs/2002.08909>`__ by Kelvin Guu, Kenton Lee, Zora Tung, Panupong Pasupat and Ming-Wei Chang. It's a | ||
retrieval-augmented language model that firstly retrieves documents from a textual knowledge corpus and then | ||
utilizes retrieved documents to process question answering tasks. | ||
|
||
The abstract from the paper is the following: | ||
|
||
*Language model pre-training has been shown to capture a surprising amount of world knowledge, crucial for NLP tasks | ||
such as question answering. However, this knowledge is stored implicitly in the parameters of a neural network, | ||
requiring ever-larger networks to cover more facts. To capture knowledge in a more modular and interpretable way, we | ||
augment language model pre-training with a latent knowledge retriever, which allows the model to retrieve and attend | ||
over documents from a large corpus such as Wikipedia, used during pre-training, fine-tuning and inference. For the | ||
first time, we show how to pre-train such a knowledge retriever in an unsupervised manner, using masked language | ||
modeling as the learning signal and backpropagating through a retrieval step that considers millions of documents. We | ||
demonstrate the effectiveness of Retrieval-Augmented Language Model pre-training (REALM) by fine-tuning on the | ||
challenging task of Open-domain Question Answering (Open-QA). We compare against state-of-the-art models for both | ||
explicit and implicit knowledge storage on three popular Open-QA benchmarks, and find that we outperform all previous | ||
methods by a significant margin (4-16% absolute accuracy), while also providing qualitative benefits such as | ||
interpretability and modularity.* | ||
|
||
This model was contributed by `qqaatw <https://huggingface.co/qqaatw>`__. The original code can be found `here | ||
<https://github.com/google-research/language/tree/master/language/realm>`__. | ||
|
||
## RealmConfig | ||
|
||
[[autodoc]] RealmConfig | ||
|
||
## RealmTokenizer | ||
|
||
[[autodoc]] RealmTokenizer | ||
- build_inputs_with_special_tokens | ||
- get_special_tokens_mask | ||
- create_token_type_ids_from_sequences | ||
- save_vocabulary | ||
- batch_encode_candidates | ||
|
||
## RealmRetriever | ||
|
||
[[autodoc]] RealmRetriever | ||
|
||
## RealmEmbedder | ||
|
||
[[autodoc]] RealmEmbedder | ||
- forward | ||
|
||
## RealmScorer | ||
|
||
[[autodoc]] RealmScorer | ||
- forward | ||
|
||
## RealmKnowledgeAugEncoder | ||
|
||
[[autodoc]] RealmKnowledgeAugEncoder | ||
- forward | ||
|
||
## RealmReader | ||
|
||
[[autodoc]] RealmReader | ||
- forward | ||
|
||
## RealmForOpenQA | ||
|
||
[[autodoc]] RealmForOpenQA | ||
- forward |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ | |
prophetnet, | ||
qdqbert, | ||
rag, | ||
realm, | ||
reformer, | ||
rembert, | ||
retribert, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
One more nit for follow-up PR.
Since this is a complex model it would be awesome to add a usage example either here or in
reserach_projects
dir like RAG.