This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix duplicate line * Easy access to the output dimension of an activation layer * Take an ignore an attention mask in TransformerEmbeddings * Make it so a pooler can be derived from a huggingface module * Pooler that can load from a transformer module * Changelog * Update transformer_embeddings.py * Productivity through formatting * Don't break positional arguments * Some mode module names * Remove _get_input_arguments() Co-authored-by: Akshita Bhagia <akshita23bhagia@gmail.com>
- Loading branch information
Showing
5 changed files
with
27 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
from typing import Union, TYPE_CHECKING | ||
|
||
import torch | ||
|
||
from allennlp.common import FromParams | ||
from allennlp.modules.transformer.activation_layer import ActivationLayer | ||
|
||
if TYPE_CHECKING: | ||
from transformers.configuration_utils import PretrainedConfig | ||
|
||
|
||
class TransformerPooler(ActivationLayer, FromParams): | ||
|
||
_pretrained_relevant_module = ["pooler", "bert.pooler", "roberta.pooler"] | ||
|
||
def __init__( | ||
self, | ||
hidden_size: int, | ||
intermediate_size: int, | ||
activation: Union[str, torch.nn.Module] = "relu", | ||
): | ||
super().__init__(hidden_size, intermediate_size, "relu", pool=True) | ||
super().__init__(hidden_size, intermediate_size, activation, pool=True) | ||
|
||
@classmethod | ||
def _from_config(cls, config: "PretrainedConfig", **kwargs): | ||
return cls(config.hidden_size, config.hidden_size, "tanh") # BERT has this hardcoded |
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