This repository was archived by the owner on Sep 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 814
Add pre-trained Roberta encoder for base and large architecture #1491
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ca2dbe
Added new roberta encoders and tests
f8c2cb3
Merge branch 'main' into roberta_encoder
7650b67
Added docs for roberta encoder
3303894
Updated truncate length. Added info on how model was trained along wi…
b64fbfa
Added datasets that roberta was trained on
687e7f0
Removing unnecessary new line
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 hidden or 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
Binary file not shown.
Binary file not shown.
Empty file.
This file contains hidden or 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,67 @@ | ||
| import torch | ||
| import torchtext | ||
|
|
||
| from ..common.assets import get_asset_path | ||
| from ..common.torchtext_test_case import TorchtextTestCase | ||
|
|
||
|
|
||
| class TestModels(TorchtextTestCase): | ||
| def test_roberta_base(self): | ||
| asset_path = get_asset_path("roberta.base.output.pt") | ||
| test_text = "Roberta base Model Comparison" | ||
|
|
||
| roberta_base = torchtext.models.ROBERTA_BASE_ENCODER | ||
| transform = roberta_base.transform() | ||
| model = roberta_base.get_model() | ||
| model = model.eval() | ||
|
|
||
| model_input = torch.tensor(transform([test_text])) | ||
| actual = model(model_input) | ||
| expected = torch.load(asset_path) | ||
| torch.testing.assert_close(actual, expected) | ||
|
|
||
| def test_roberta_base_jit(self): | ||
| asset_path = get_asset_path("roberta.base.output.pt") | ||
| test_text = "Roberta base Model Comparison" | ||
|
|
||
| roberta_base = torchtext.models.ROBERTA_BASE_ENCODER | ||
| transform = roberta_base.transform() | ||
| transform_jit = torch.jit.script(transform) | ||
| model = roberta_base.get_model() | ||
| model = model.eval() | ||
| model_jit = torch.jit.script(model) | ||
|
|
||
| model_input = torch.tensor(transform_jit([test_text])) | ||
| actual = model_jit(model_input) | ||
| expected = torch.load(asset_path) | ||
| torch.testing.assert_close(actual, expected) | ||
|
|
||
| def test_roberta_large(self): | ||
| asset_path = get_asset_path("roberta.large.output.pt") | ||
| test_text = "Roberta base Model Comparison" | ||
|
|
||
| roberta_large = torchtext.models.ROBERTA_LARGE_ENCODER | ||
| transform = roberta_large.transform() | ||
| model = roberta_large.get_model() | ||
| model = model.eval() | ||
|
|
||
| model_input = torch.tensor(transform([test_text])) | ||
| actual = model(model_input) | ||
| expected = torch.load(asset_path) | ||
| torch.testing.assert_close(actual, expected) | ||
|
|
||
| def test_roberta_large_jit(self): | ||
| asset_path = get_asset_path("roberta.large.output.pt") | ||
| test_text = "Roberta base Model Comparison" | ||
|
|
||
| roberta_large = torchtext.models.ROBERTA_LARGE_ENCODER | ||
| transform = roberta_large.transform() | ||
| transform_jit = torch.jit.script(transform) | ||
| model = roberta_large.get_model() | ||
| model = model.eval() | ||
| model_jit = torch.jit.script(model) | ||
|
|
||
| model_input = torch.tensor(transform_jit([test_text])) | ||
| actual = model_jit(model_input) | ||
| expected = torch.load(asset_path) | ||
| torch.testing.assert_close(actual, expected) | ||
This file contains hidden or 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 hidden or 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
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.
I think this can be written in much compact manner with parameterization.
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.
Added a followup item. Let me do this in a separate PR