code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def is_first_subword(self, tokens: Union[str, int, List[str], List[int]]) \
-> Union[bool, List[bool]]:
"""Whether the token is the first subword token in a list of subword tokens
Parameters
----------
tokens
The input tokens
Returns
-------
... | Whether the token is the first subword token in a list of subword tokens
Parameters
----------
tokens
The input tokens
Returns
-------
ret
Whether the token is the first subword token in a sequence of subword tokens
that construct the... | is_first_subword | python | dmlc/gluon-nlp | src/gluonnlp/data/tokenizers/yttm.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/data/tokenizers/yttm.py | Apache-2.0 |
def __getstate__(self):
"""Support multiprocessing by making it pickleble"""
state = self.__dict__.copy()
state['_bpe'] = None
return state | Support multiprocessing by making it pickleble | __getstate__ | python | dmlc/gluon-nlp | src/gluonnlp/data/tokenizers/yttm.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/data/tokenizers/yttm.py | Apache-2.0 |
def list_sources(embedding_name=None):
"""Get valid token embedding names and their pre-trained file names.
Parameters
----------
embedding_name : str or None, default None
The pre-trained token embedding name.
Returns
-------
dict or list:
A list of all the valid pre-train... | Get valid token embedding names and their pre-trained file names.
Parameters
----------
embedding_name : str or None, default None
The pre-trained token embedding name.
Returns
-------
dict or list:
A list of all the valid pre-trained token embedding file names (`source`) for t... | list_sources | python | dmlc/gluon-nlp | src/gluonnlp/embedding/embed_loader.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/embedding/embed_loader.py | Apache-2.0 |
def load_embeddings(vocab=None, pretrained_name_or_dir='glove.6B.50d', unknown='<unk>',
unk_method=None):
"""Load pretrained word embeddings for building an embedding matrix for a given Vocab.
This function supports loading GloVe, Word2Vec and FastText word embeddings from remote sources.
... | Load pretrained word embeddings for building an embedding matrix for a given Vocab.
This function supports loading GloVe, Word2Vec and FastText word embeddings from remote sources.
You can also load your own embedding file(txt with Word2Vec or GloVe format) from a given file path.
Glove: an unsupervised l... | load_embeddings | python | dmlc/gluon-nlp | src/gluonnlp/embedding/embed_loader.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/embedding/embed_loader.py | Apache-2.0 |
def get_fasttext_model(model_name_or_dir='cc.en.300'):
""" Load fasttext model from the binaray file
This method will load fasttext model binaray file from a given file path or remote sources,
and return a `fasttext` model object. See `fasttext.cc` for more usage information.
Available sources:
['... | Load fasttext model from the binaray file
This method will load fasttext model binaray file from a given file path or remote sources,
and return a `fasttext` model object. See `fasttext.cc` for more usage information.
Available sources:
['wiki-news-300d-1M-subword', 'crawl-300d-2M-subword', 'cc.... | get_fasttext_model | python | dmlc/gluon-nlp | src/gluonnlp/embedding/embed_loader.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/embedding/embed_loader.py | Apache-2.0 |
def forward(self, data, valid_length):
"""
Generate the representation given the inputs.
This is used in training or fine-tuning a Bert model.
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C)
- layout =... |
Generate the representation given the inputs.
This is used in training or fine-tuning a Bert model.
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C)
- layout = 'TN'
Shape (seq_length, batch_siz... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/albert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/albert.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length=None):
"""Generate the representation given the inputs.
This is used in training or fine-tuning a Albert model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
... | Generate the representation given the inputs.
This is used in training or fine-tuning a Albert model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/albert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/albert.py | Apache-2.0 |
def get_initial_embedding(self, inputs, token_types=None):
"""Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
... | Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
token_types
... | get_initial_embedding | python | dmlc/gluon-nlp | src/gluonnlp/models/albert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/albert.py | Apache-2.0 |
def apply_pooling(self, sequence):
"""Generate the representation given the inputs.
This is used for pre-training or fine-tuning a Bert model.
Get the first token of the whole sequence which is [CLS]
Parameters
----------
sequence
- layout = 'NT'
... | Generate the representation given the inputs.
This is used for pre-training or fine-tuning a Bert model.
Get the first token of the whole sequence which is [CLS]
Parameters
----------
sequence
- layout = 'NT'
Shape (batch_size, sequence_length, units... | apply_pooling | python | dmlc/gluon-nlp | src/gluonnlp/models/albert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/albert.py | Apache-2.0 |
def from_cfg(cls, cfg, use_pooler=True, dtype=None) -> 'AlbertModel':
"""
Parameters
----------
cfg
use_pooler
Whether to use pooler
dtype
The dtype of the backbone model
Returns
-------
model
The created Alber... |
Parameters
----------
cfg
use_pooler
Whether to use pooler
dtype
The dtype of the backbone model
Returns
-------
model
The created AlbertModel
| from_cfg | python | dmlc/gluon-nlp | src/gluonnlp/models/albert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/albert.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length,
masked_positions):
"""Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
... | Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
token_types
The type of the token. For example, if... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/albert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/albert.py | Apache-2.0 |
def __init__(self, backbone_cfg,
weight_initializer=None,
bias_initializer=None):
"""
Parameters
----------
backbone_cfg
The cfg of the backbone model
weight_initializer
bias_initializer
"""
super().__init__()... |
Parameters
----------
backbone_cfg
The cfg of the backbone model
weight_initializer
bias_initializer
| __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/albert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/albert.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length,
masked_positions):
"""Generate the representation given the inputs.
This is used in training or fine-tuning a Albert model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch... | Generate the representation given the inputs.
This is used in training or fine-tuning a Albert model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/albert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/albert.py | Apache-2.0 |
def get_pretrained_albert(model_name: str = 'google_albert_base_v2',
root: str = get_model_zoo_home_dir(),
load_backbone: str = True,
load_mlm: str = False)\
-> Tuple[CN, SentencepieceTokenizer, str, str]:
"""Get the pretrained Al... | Get the pretrained Albert weights
Parameters
----------
model_name
The name of the Albert model.
root
The downloading root
load_backbone
Whether to load the weights of the backbone network
load_mlm
Whether to load the weights of MLM
Returns
-------
c... | get_pretrained_albert | python | dmlc/gluon-nlp | src/gluonnlp/models/albert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/albert.py | Apache-2.0 |
def __init__(self,
use_pooler: bool = False,
classifier_activation: bool = False,
extract_feature: bool = False,
pooler_activation='tanh',
**kwargs):
"""
Parameters
----------
use_pooler
Whe... |
Parameters
----------
use_pooler
Whether to use pooler
classifier_activation
extract_feature
Whether to extract the feature
pooler_activation
**kwargs
| __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/bart.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bart.py | Apache-2.0 |
def forward(self, src_data, src_valid_length, tgt_data, tgt_valid_length):
"""
Parameters
----------
src_data
- layout = 'NT'
Shape (batch_size, src_length)
- layout = 'TN'
Shape (src_length, batch_size)
src_valid_length
... |
Parameters
----------
src_data
- layout = 'NT'
Shape (batch_size, src_length)
- layout = 'TN'
Shape (src_length, batch_size)
src_valid_length
Shape (batch_size,)
tgt_data
- layout = 'NT'
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/bart.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bart.py | Apache-2.0 |
def apply_pooling(self, sequence, valid_length):
"""Generate the representation given the inputs.
This is used for pre-training or fine-tuning a BART model.
In BART, the pooled output is the embedding of the last token.
Parameters
----------
sequence
- layou... | Generate the representation given the inputs.
This is used for pre-training or fine-tuning a BART model.
In BART, the pooled output is the embedding of the last token.
Parameters
----------
sequence
- layout = 'NT'
Shape (batch_size, sequence_length,... | apply_pooling | python | dmlc/gluon-nlp | src/gluonnlp/models/bart.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bart.py | Apache-2.0 |
def from_cfg(cls, cfg,
dtype=None,
extract_feature=False,
use_pooler=True,
classifier_activation=False):
"""
Parameters
----------
cfg
The configuration
dtype
Data type of the loaded conf... |
Parameters
----------
cfg
The configuration
dtype
Data type of the loaded config
extract_feature
Whether to only extract feature.
If so, the output of the layer will be contextual embeddings or the
contextual embedding... | from_cfg | python | dmlc/gluon-nlp | src/gluonnlp/models/bart.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bart.py | Apache-2.0 |
def get_pretrained_bart(model_name: str = 'fairseq_bart_base',
root: str = get_model_zoo_home_dir(),
load_backbone: bool = True) \
-> Tuple[CN, HuggingFaceByteBPETokenizer, str, List]:
"""Get the pretrained RoBERTa weights
Parameters
----------
mo... | Get the pretrained RoBERTa weights
Parameters
----------
model_name
The name of the RoBERTa model.
root
The downloading root
load_backbone
Whether to load the weights of the backbone network
Returns
-------
cfg
Network configuration
tokenizer
... | get_pretrained_bart | python | dmlc/gluon-nlp | src/gluonnlp/models/bart.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bart.py | Apache-2.0 |
def get_backbone(model_name: str,
root: str = get_model_zoo_home_dir(),
**kwargs) -> Tuple['Block', str, BaseTokenizer, str, List]:
"""Get the backbone network
Parameters
----------
model_name
The name of the pretrained model
root
Downloaded directo... | Get the backbone network
Parameters
----------
model_name
The name of the pretrained model
root
Downloaded directory of the model zoo
Returns
-------
model_cls
The class to construct the backbone network
cfg
Path to the config file of the backbone
to... | get_backbone | python | dmlc/gluon-nlp | src/gluonnlp/models/base.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/base.py | Apache-2.0 |
def forward(self, data, valid_length):
"""
Generate the representation given the inputs.
This is used in training or fine-tuning a bert model.
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C)
- layout =... |
Generate the representation given the inputs.
This is used in training or fine-tuning a bert model.
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C)
- layout = 'TN'
Shape (seq_length, batch_siz... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/bert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bert.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length):
# pylint: disable=arguments-differ
"""Generate the representation given the inputs.
This is used in training or fine-tuning a bert model.
Parameters
----------
inputs
- layout = 'NT'
Shape... | Generate the representation given the inputs.
This is used in training or fine-tuning a bert model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/bert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bert.py | Apache-2.0 |
def get_initial_embedding(self, inputs, token_types=None):
"""Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
... | Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
token_types
... | get_initial_embedding | python | dmlc/gluon-nlp | src/gluonnlp/models/bert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bert.py | Apache-2.0 |
def apply_pooling(self, sequence):
"""Generate the representation given the inputs.
This is used for pre-training or fine-tuning a bert model.
Get the first token of the whole sequence which is [CLS].
Parameters
----------
sequence
- layout = 'NT'
... | Generate the representation given the inputs.
This is used for pre-training or fine-tuning a bert model.
Get the first token of the whole sequence which is [CLS].
Parameters
----------
sequence
- layout = 'NT'
Shape (batch_size, sequence_length, unit... | apply_pooling | python | dmlc/gluon-nlp | src/gluonnlp/models/bert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bert.py | Apache-2.0 |
def from_cfg(cls, cfg, use_pooler=True, dtype=None) -> 'BertModel':
"""
Parameters
----------
cfg
Configuration
use_pooler
Whether to output the pooled feature
dtype
data type of the model
Returns
-------
ret
... |
Parameters
----------
cfg
Configuration
use_pooler
Whether to output the pooled feature
dtype
data type of the model
Returns
-------
ret
The constructed BertModel
| from_cfg | python | dmlc/gluon-nlp | src/gluonnlp/models/bert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bert.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length,
masked_positions):
"""Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
... | Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
token_types
If the inputs contain two sequences, we... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/bert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bert.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length,
masked_positions):
"""Generate the representation given the inputs.
This is used in training or fine-tuning a bert model.
Parameters
----------
inputs
- layout = 'NT'
Shape (... | Generate the representation given the inputs.
This is used in training or fine-tuning a bert model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/bert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bert.py | Apache-2.0 |
def get_pretrained_bert(model_name: str = 'google_en_cased_bert_base',
root: str = get_model_zoo_home_dir(),
load_backbone: str = True,
load_mlm: str = False)\
-> Tuple[CN, HuggingFaceWordPieceTokenizer, str, str]:
"""Get the pretrained... | Get the pretrained bert weights
Parameters
----------
model_name
The name of the bert model.
root
The downloading root
load_backbone
Whether to load the weights of the backbone network
load_mlm
Whether to load the weights of MLM
Returns
-------
cfg
... | get_pretrained_bert | python | dmlc/gluon-nlp | src/gluonnlp/models/bert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/bert.py | Apache-2.0 |
def get_generator_cfg(model_config):
"""
Get the generator configuration from the Electra model config.
The size of generator is usually smaller than discriminator but same in electra small,
which exists a conflict between source code and original paper.
"""
generator_cfg = model_config.clone()... |
Get the generator configuration from the Electra model config.
The size of generator is usually smaller than discriminator but same in electra small,
which exists a conflict between source code and original paper.
| get_generator_cfg | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def __init__(self, units=512,
hidden_size=2048,
num_layers=6,
num_heads=8,
attention_dropout_prob=0.,
hidden_dropout_prob=0.,
output_attention=False,
dtype='float32',
output_all_encodi... |
Parameters
----------
units
The number of units
hidden_size
The hidden size
num_layers
Number of layers
num_heads
Number of heads
attention_dropout_prob
Dropout probability of the attention layer
... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def forward(self, data, valid_length):
"""Generate the representation given the inputs.
This is used in training or fine-tuning a Electra model.
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C)
- layout = 'TN'
... | Generate the representation given the inputs.
This is used in training or fine-tuning a Electra model.
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C)
- layout = 'TN'
Shape (seq_length, batch_size, C)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length=None):
"""Generate the representation given the inputs.
This is used in training or fine-tuning a Electra model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
... | Generate the representation given the inputs.
This is used in training or fine-tuning a Electra model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def get_initial_embedding(self, inputs, token_types=None):
"""Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
... | Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
token_types
... | get_initial_embedding | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def apply_layerwise_decay(self, layerwise_decay: int,
not_included: Optional[List[str]] = None,
num_additional_layers: int = 2):
"""Apply the layer-wise gradient decay
.. math::
lr = lr * layerwise_decay^(max_depth - layer_depth)
... | Apply the layer-wise gradient decay
.. math::
lr = lr * layerwise_decay^(max_depth - layer_depth)
Parameters
----------
layerwise_decay
Power rate of the layer-wise decay
not_included
A list or parameter names that not included in the layer-w... | apply_layerwise_decay | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def frozen_params(self, untunable_depth: int, not_included: Optional[List[str]] = None):
"""Froze part of parameters according to layer depth.
That is, make all layer that shallower than `untunable_depth` untunable
to stop the gradient backward computation and accelerate the training.
... | Froze part of parameters according to layer depth.
That is, make all layer that shallower than `untunable_depth` untunable
to stop the gradient backward computation and accelerate the training.
Parameters
----------
untunable_depth
the depth of the neural network st... | frozen_params | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length):
"""Getting the scores of the replaced token detection of the whole sentence
based on the corrupted tokens produced from a generator.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, ... | Getting the scores of the replaced token detection of the whole sentence
based on the corrupted tokens produced from a generator.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (se... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def __init__(self, backbone_cfg,
weight_initializer=None,
bias_initializer=None):
"""
Parameters
----------
backbone_cfg
Configuration of the backbone model
weight_initializer
bias_initializer
"""
super().__in... |
Parameters
----------
backbone_cfg
Configuration of the backbone model
weight_initializer
bias_initializer
| __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def tie_embeddings(self, word_embed_params=None,
token_type_embed_params=None,
token_pos_embed_params=None,
embed_layer_norm_params=None):
"""Tie the embedding layers between the backbone and the MLM decoder
Parameters
-------... | Tie the embedding layers between the backbone and the MLM decoder
Parameters
----------
word_embed_params
token_type_embed_params
token_pos_embed_params
embed_layer_norm_params
| tie_embeddings | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length, masked_positions):
"""Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, b... | Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
token_types
If the inputs contain two sequences, we ... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def __init__(self,
disc_cfg,
uniform_generator=False,
tied_generator=False,
tied_embeddings=True,
disallow_correct=False,
temperature=1.0,
gumbel_eps=1E-9,
dtype='float32',
... |
Parameters
----------
disc_cfg :
Config for discriminator model including scaled size for generator
uniform_generator :
Wether to get a generator with uniform weights, the mlm_scores from
which are totally random. In this case , a discriminator learn... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length,
original_tokens, masked_positions):
"""Getting the mlm scores of each masked positions from a generator,
then produces the corrupted tokens sampling from a gumbel distribution.
We also get the ground-truth and scores of the rep... | Getting the mlm scores of each masked positions from a generator,
then produces the corrupted tokens sampling from a gumbel distribution.
We also get the ground-truth and scores of the replaced token detection
which is output by a discriminator. The ground-truth is an array with same
sha... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def get_corrupted_tokens(self, inputs, original_tokens, masked_positions, logits):
"""
Sample from the generator to create corrupted input.
Parameters
----------
inputs
The masked input
- layout = 'NT'
Shape (batch_size, seq_length)
... |
Sample from the generator to create corrupted input.
Parameters
----------
inputs
The masked input
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
original_tokens... | get_corrupted_tokens | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def get_pretrained_electra(model_name: str = 'google_electra_small',
root: str = get_model_zoo_home_dir(),
load_backbone: bool = True,
load_disc: bool = False,
load_gen: bool = False) \
-> Tuple[CN, Huggi... | Get the pretrained Electra weights
Parameters
----------
model_name
The name of the Electra model.
root
The downloading root
load_backbone
Whether to load the weights of the backbone network
load_disc
Whether to load the weights of the discriminator
load_gen
... | get_pretrained_electra | python | dmlc/gluon-nlp | src/gluonnlp/models/electra.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/electra.py | Apache-2.0 |
def forward(self, x, layer_states):
"""
Parameters
----------
x
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
layer_states
- layout = 'NT'
... |
Parameters
----------
x
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
layer_states
- layout = 'NT'
Shape (2, batch_size, prev_len, C_in)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/gpt2.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/gpt2.py | Apache-2.0 |
def forward(self, x, layer_states):
"""
Parameters
----------
x
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
layer_states
- layout = 'NT'
... |
Parameters
----------
x
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
layer_states
- layout = 'NT'
Shape (2, batch_size, prev_len, C_in)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/gpt2.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/gpt2.py | Apache-2.0 |
def forward(self, x, states):
"""
Parameters
----------
x
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
states
The previous states
- layout = 'NT'
... |
Parameters
----------
x
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
states
The previous states
- layout = 'NT'
Shape (num_layers, 2, batch... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/gpt2.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/gpt2.py | Apache-2.0 |
def get_initial_embedding(self, inputs, prev_len):
"""Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
... | Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
prev_len
... | get_initial_embedding | python | dmlc/gluon-nlp | src/gluonnlp/models/gpt2.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/gpt2.py | Apache-2.0 |
def init_states(self, batch_size, ctx, dtype=None):
"""Initialize the states required for incremental decoding
Returns
-------
init_states
- layout = 'NT'
Shape (num_layers, 2, batch_size, 0, C_in)
- layout = 'TN'
Shape (num_layers... | Initialize the states required for incremental decoding
Returns
-------
init_states
- layout = 'NT'
Shape (num_layers, 2, batch_size, 0, C_in)
- layout = 'TN'
Shape (num_layers, 2, 0, batch_size, C_in)
| init_states | python | dmlc/gluon-nlp | src/gluonnlp/models/gpt2.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/gpt2.py | Apache-2.0 |
def forward(self, inputs, states):
"""Getting the logits. This can be used for language modeling.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
s... | Getting the logits. This can be used for language modeling.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
states
The states.
- l... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/gpt2.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/gpt2.py | Apache-2.0 |
def get_pretrained_gpt2(model_name: str = 'gpt2_124M',
root: str = get_model_zoo_home_dir(),
load_backbone: bool = True,
load_lm: bool = False)\
-> Tuple[CN, HuggingFaceByteBPETokenizer, str, str]:
"""Get the pretrained GPT-2 weights
... | Get the pretrained GPT-2 weights
Parameters
----------
model_name
The name of the GPT-2 model.
root
The downloading root
load_backbone
Whether to load the weights of the backbone network
load_lm
Whether to load the weights of LM
Returns
-------
cfg
... | get_pretrained_gpt2 | python | dmlc/gluon-nlp | src/gluonnlp/models/gpt2.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/gpt2.py | Apache-2.0 |
def __init__(self,
use_bottleneck: bool = True,
units: int = 512,
real_units: int = 128,
hidden_size: int = 2048,
num_heads: int = 8,
num_stacked_ffn: int = 1,
bottleneck_strategy: str = 'qk_sharing',
... |
Parameters
----------
use_bottleneck
Whether to use the bottleneck layer.
units
size of inter-bottleneck
real_units
size of intra-bottleneck
hidden_size
size of feed-forward network
num_heads
num_stacked_ff... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/mobilebert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/mobilebert.py | Apache-2.0 |
def forward(self, data, attn_mask):
"""
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
attn_mask
The attention mask
... |
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
attn_mask
The attention mask
Shape (batch_size, seq_length, seq_length)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/mobilebert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/mobilebert.py | Apache-2.0 |
def forward(self, data, valid_length):
"""
Generate the representation given the inputs.
This is used in training or fine-tuning a mobile bert model.
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C)
- l... |
Generate the representation given the inputs.
This is used in training or fine-tuning a mobile bert model.
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C)
- layout = 'TN'
Shape (seq_length, ba... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/mobilebert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/mobilebert.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length):
# pylint: disable=arguments-differ
"""Generate the representation given the inputs.
This is used in training or fine-tuning a mobile bert model.
Parameters
----------
inputs
- layout = 'NT'
... | Generate the representation given the inputs.
This is used in training or fine-tuning a mobile bert model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/mobilebert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/mobilebert.py | Apache-2.0 |
def get_initial_embedding(self, inputs, token_types=None):
"""Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
... | Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
token_types
... | get_initial_embedding | python | dmlc/gluon-nlp | src/gluonnlp/models/mobilebert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/mobilebert.py | Apache-2.0 |
def apply_pooling(self, sequence):
"""Generate the representation given the inputs.
This is used for pre-training or fine-tuning a mobile bert model.
Get the first token of the whole sequence which is [CLS]
Parameters
----------
sequence
- layout = 'NT'
... | Generate the representation given the inputs.
This is used for pre-training or fine-tuning a mobile bert model.
Get the first token of the whole sequence which is [CLS]
Parameters
----------
sequence
- layout = 'NT'
Shape (batch_size, sequence_length... | apply_pooling | python | dmlc/gluon-nlp | src/gluonnlp/models/mobilebert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/mobilebert.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length,
masked_positions):
"""Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
... | Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
token_types
The type of the token. For example, if ... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/mobilebert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/mobilebert.py | Apache-2.0 |
def forward(self, inputs, token_types, valid_length,
masked_positions):
"""Generate the representation given the inputs.
This is used in training or fine-tuning a mobile mobile bert model.
Parameters
----------
inputs
- layout = 'NT'
... | Generate the representation given the inputs.
This is used in training or fine-tuning a mobile mobile bert model.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/mobilebert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/mobilebert.py | Apache-2.0 |
def get_pretrained_mobilebert(model_name: str = 'google_uncased_mobilebert',
root: str = get_model_zoo_home_dir(),
load_backbone: str = True,
load_mlm: str = False)\
-> Tuple[CN, HuggingFaceWordPieceTokenizer, str, str]:
... | Get the pretrained mobile bert weights
Parameters
----------
model_name
The name of the mobile bert model.
root
The downloading root
load_backbone
Whether to load the weights of the backbone network
load_mlm
Whether to load the weights of MLM
Returns
---... | get_pretrained_mobilebert | python | dmlc/gluon-nlp | src/gluonnlp/models/mobilebert.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/mobilebert.py | Apache-2.0 |
def __init__(self,
vocab_size=50265,
units=768,
hidden_size=3072,
num_layers=12,
num_heads=12,
max_length=512,
hidden_dropout_prob=0.1,
attention_dropout_prob=0.1,
pos... |
Parameters
----------
vocab_size
units
hidden_size
num_layers
num_heads
max_length
hidden_dropout_prob
attention_dropout_prob
pos_embed_type
activation
pooler_activation
layer_norm_eps
embed_initial... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/roberta.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/roberta.py | Apache-2.0 |
def get_initial_embedding(self, inputs):
"""Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape ... | Get the initial token embeddings that considers the token type and positional embeddings
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
Returns
--... | get_initial_embedding | python | dmlc/gluon-nlp | src/gluonnlp/models/roberta.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/roberta.py | Apache-2.0 |
def apply_pooling(self, sequence):
"""Generate the representation given the inputs.
This is used for pre-training or fine-tuning a mobile bert model.
Get the first token of the whole sequence which is [CLS]
Parameters
----------
sequence
- layout = 'NT'
... | Generate the representation given the inputs.
This is used for pre-training or fine-tuning a mobile bert model.
Get the first token of the whole sequence which is [CLS]
Parameters
----------
sequence
- layout = 'NT'
Shape (batch_size, sequence_length... | apply_pooling | python | dmlc/gluon-nlp | src/gluonnlp/models/roberta.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/roberta.py | Apache-2.0 |
def forward(self, inputs, valid_length, masked_positions):
"""Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
... | Getting the scores of the masked positions.
Parameters
----------
inputs
- layout = 'NT'
Shape (batch_size, seq_length)
- layout = 'TN'
Shape (seq_length, batch_size)
valid_length
The valid length of each sequence
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/roberta.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/roberta.py | Apache-2.0 |
def get_pretrained_roberta(model_name: str = 'fairseq_roberta_base',
root: str = get_model_zoo_home_dir(),
load_backbone: bool = True,
load_mlm: bool = False) \
-> Tuple[CN, HuggingFaceByteBPETokenizer, str, str]:
"""Get the pr... | Get the pretrained RoBERTa weights
Parameters
----------
model_name
The name of the RoBERTa model.
root
The downloading root
load_backbone
Whether to load the weights of the backbone network
load_mlm
Whether to load the weights of MLM
Returns
-------
... | get_pretrained_roberta | python | dmlc/gluon-nlp | src/gluonnlp/models/roberta.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/roberta.py | Apache-2.0 |
def __init__(
self,
d_model,
d_kv,
d_ff,
is_decoder,
num_heads=12,
dropout_prob=0.1,
layer_norm_eps=1E-6,
activation='relu',
init_factor=1.0,
layout='NT',
dtype='float32'
):
"""
Parameters
... |
Parameters
----------
d_model
Equivalent to transformer's `units`.
d_kv
d_kv * num_heads (see below) = inner_dim.
d_ff
Equivalent to transformer's `hidden_size`.
is_decoder
If is_decoder, apply cross-attention.
... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def incremental_decode(
self,
step_hidden_states,
step_position_embeddings,
past_key_value,
mem_states,
step_mem_attn_mask
):
"""Incrementally generate the output given the decoder input.
Parameters
----------
step_hidden_states... | Incrementally generate the output given the decoder input.
Parameters
----------
step_hidden_states
Stepwise hidden states where L_seq = 1 as in `forward` case.
- layout = 'NT'
Shape (B, 1, d_model)
- layout = 'TN'
Shape (1,... | incremental_decode | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def forward(
self,
hidden_states,
self_attn_mask,
position_embeddings,
mem_states=None,
mem_attn_mask=None
):
"""
Parameters
----------
hidden_states
- layout = 'NT'
Shape (B, L_seq, d_model)
... |
Parameters
----------
hidden_states
- layout = 'NT'
Shape (B, L_seq, d_model)
- layout = 'TN'
Shape (L_seq, B, d_model)
self_attn_mask
if is_decoder, it should be a "causal" attention mask.
Shape (B, L_se... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def __init__(
self,
d_model,
d_kv,
d_ff,
num_layers=12,
num_heads=12,
dropout_prob=0.1,
layer_norm_eps=1E-6,
activation='relu',
init_factor=1.0,
layout='NT',
dtype='float32'
):
"""
Parameters... |
Parameters
----------
d_model
Equivalent to transformer's `units`.
d_kv
d_kv * num_heads (see below) = inner_dim.
d_ff
Equivalent to transformer's `hidden_size`.
num_layers
num_heads
dropout_prob
We use ... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def forward(self, hidden_states, valid_length):
"""
Parameters
----------
hidden_states
- layout = 'NT'
Shape (B, L_seq, d_model)
- layout = 'TN'
Shape (L_seq, B, d_model)
valid_length
Valid sequence length fo... |
Parameters
----------
hidden_states
- layout = 'NT'
Shape (B, L_seq, d_model)
- layout = 'TN'
Shape (L_seq, B, d_model)
valid_length
Valid sequence length for each sample feeded into the encoder.
Shape (B... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def incremental_decode(
self,
step_hidden_states,
position,
past_key_values,
mem_states,
mem_valid_length
):
"""Incrementally generate the output given the decoder input.
Parameters
----------
step_hidden_states
Step... | Incrementally generate the output given the decoder input.
Parameters
----------
step_hidden_states
Stepwise hidden states where L_seq = 1 as in `forward` case.
- layout = 'NT'
Shape (B, 1, d_model)
- layout = 'TN'
Shape (1,... | incremental_decode | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def forward(self, hidden_states, valid_length, mem_states, mem_valid_length):
"""
Parameters
----------
hidden_states
- layout = 'NT'
Shape (B, L_seq, d_model)
- layout = 'TN'
Shape (L_seq, B, d_model)
valid_length
... |
Parameters
----------
hidden_states
- layout = 'NT'
Shape (B, L_seq, d_model)
- layout = 'TN'
Shape (L_seq, B, d_model)
valid_length
Valid sequence length for each sample feeded into the decoder.
Shape (B... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def __init__(
self,
vocab_size=32128,
d_model=768,
d_kv=64,
d_ff=3072,
num_layers=12,
num_heads=12,
dropout_prob=0.1,
layer_norm_eps=1E-6,
activation='relu',
init_factor=1.0,
layout='NT',
dtype='float32'
... |
Parameters
----------
vocab_size
vocab_size should be no smaller than len(tokenizer._sp_model).
d_model
Equivalent to transformer's `units`.
d_kv
d_kv * num_heads (see below) = inner_dim.
d_ff
Equivalent to transformer'... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def encode(self, src_data, src_valid_length):
"""Encode the source data to memory states.
Parameters
----------
src_data
Token ids feeded into the encoder.
- layout = 'NT'
Shape (B, L_src_seq)
- layout = 'TN'
Shape ... | Encode the source data to memory states.
Parameters
----------
src_data
Token ids feeded into the encoder.
- layout = 'NT'
Shape (B, L_src_seq)
- layout = 'TN'
Shape (L_src_seq, B)
src_valid_length
Valid... | encode | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def decode(self, tgt_data, tgt_valid_length, mem_states, mem_valid_length):
"""Decode based on target data and memory states.
Parameters
----------
tgt_data
Token ids feeded into the decoder.
- layout = 'NT'
Shape (B, L_seq)
- layo... | Decode based on target data and memory states.
Parameters
----------
tgt_data
Token ids feeded into the decoder.
- layout = 'NT'
Shape (B, L_seq)
- layout = 'TN'
Shape (L_seq, B)
tgt_valid_length
Valid s... | decode | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def forward(self, src_data, src_valid_length, tgt_data, tgt_valid_length):
"""
Parameters
----------
src_data
Token ids feeded into the encoder.
- layout = 'NT'
Shape (B, L_src_seq)
- layout = 'TN'
Shape (L_src_seq, ... |
Parameters
----------
src_data
Token ids feeded into the encoder.
- layout = 'NT'
Shape (B, L_src_seq)
- layout = 'TN'
Shape (L_src_seq, B)
src_valid_length
Valid sequence length for each sample feeded i... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def state_batch_axis(self):
"""The returned 4-tuple corresponds to the batch axes of `init_states()` results.
Returns
-------
enc_out_batch_axis
src_valid_length_batch_axis
position_batch_axis
dec_layer_batch_axes
"""
if self.model.layout == 'NT... | The returned 4-tuple corresponds to the batch axes of `init_states()` results.
Returns
-------
enc_out_batch_axis
src_valid_length_batch_axis
position_batch_axis
dec_layer_batch_axes
| state_batch_axis | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def init_states(self, src_data, src_valid_length):
"""Initialize the states required for incremental decoding.
Parameters
----------
src_data
Token ids feeded into the encoder.
- layout = 'NT'
Shape (B, L_src_seq)
- layout = 'TN'
... | Initialize the states required for incremental decoding.
Parameters
----------
src_data
Token ids feeded into the encoder.
- layout = 'NT'
Shape (B, L_src_seq)
- layout = 'TN'
Shape (L_src_seq, B)
src_valid_length
... | init_states | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def forward(self, step_data, past_states):
"""
Parameters
----------
step_data
Stepwise batched token ids for incremental decoding.
Shape (B,)
past_states
A 4-tuple containing states of last incremental decoding step.
... |
Parameters
----------
step_data
Stepwise batched token ids for incremental decoding.
Shape (B,)
past_states
A 4-tuple containing states of last incremental decoding step.
1. mem_states
- layout = 'NT'
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/t5.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/t5.py | Apache-2.0 |
def transformer_base():
"""Configuration of Transformer WMT EN-DE Base"""
cfg = CN()
cfg.MODEL = CN()
cfg.MODEL.src_vocab_size = -1
cfg.MODEL.tgt_vocab_size = -1
cfg.MODEL.max_src_length = -1
cfg.MODEL.max_tgt_length = -1
cfg.MODEL.scale_embed = True
cfg.MODEL.pos_embed_type = "sinus... | Configuration of Transformer WMT EN-DE Base | transformer_base | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def __init__(self,
units: int = 512,
hidden_size: int = 2048,
num_heads: int = 8,
attention_dropout_prob: float = 0.1,
hidden_dropout_prob: float = 0.1,
activation_dropout_prob: float = 0.0,
layer_norm... |
Parameters
----------
units
hidden_size
num_heads
attention_dropout_prob
hidden_dropout_prob
activation_dropout_prob
layer_norm_eps
pre_norm
Whether to attach the normalization layer before attention layer
If pre_n... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def forward(self, data, attn_mask):
"""
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
attn_mask
Shape (batch_size, seq_leng... |
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
attn_mask
Shape (batch_size, seq_length, seq_length)
Returns
------... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def __init__(self, num_layers=6, recurrent=False,
units=512, hidden_size=2048, num_heads=8,
activation_dropout=0.0, dropout=0.1, use_qkv_bias=True,
attention_dropout=0.1, layer_norm_eps=1E-5, data_norm=False,
pre_norm=False, weight_initializer=None, bi... |
Parameters
----------
num_layers :
The number of layers
recurrent : bool
Whether the layers share weights or not
units
hidden_size
num_heads
dropout
layer_norm_eps
data_norm
Whether to apply LayerNorm t... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def forward(self, data, valid_length):
"""
Parameters
----------
data :
- layout = 'NT'
Shape (batch_size, seq_length, C)
- layout = 'TN'
Shape (seq_length, batch_size, C)
valid_length :
Shape (batch_size,)
... |
Parameters
----------
data :
- layout = 'NT'
Shape (batch_size, seq_length, C)
- layout = 'TN'
Shape (seq_length, batch_size, C)
valid_length :
Shape (batch_size,)
Returns
-------
out
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def __init__(self, units: int = 512,
mem_units: Optional[int] = None,
hidden_size: int = 2048,
num_heads: int = 8,
activation_dropout: float = 0.0,
dropout: float = 0.1,
attention_dropout: float = 0.1,
... |
Parameters
----------
units
mem_units
The number of units in the memory. By default, it is initialized to be the
same as the units.
hidden_size
num_heads
activation_dropout
dropout
attention_dropout
layer_norm_eps
... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def forward(self, data, mem, self_causal_mask, mem_attn_mask):
"""
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
mem
- layo... |
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
mem
- layout = 'NT'
Shape (batch_size, mem_length, C_mem)
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def init_states(self, batch_size, ctx, dtype='float32'):
"""Initialize the states required for incremental decoding
Returns
-------
init_key
- layout = 'NT'
Shape (batch_size, 0, N, C_key)
- layout = 'TN'
Shape (0, batch_size, N, C... | Initialize the states required for incremental decoding
Returns
-------
init_key
- layout = 'NT'
Shape (batch_size, 0, N, C_key)
- layout = 'TN'
Shape (0, batch_size, N, C_key)
init_value
- layout = 'NT'
... | init_states | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def incremental_decode(self, data, states, mem, mem_valid_length, mem_attn_mask=None):
"""Incrementally generate the output given the decoder input.
Parameters
----------
data
Shape (batch_size, C_in)
states
The previous states, contains
1. l... | Incrementally generate the output given the decoder input.
Parameters
----------
data
Shape (batch_size, C_in)
states
The previous states, contains
1. layout = 'NT':
- prev_multi_key
Shape (batch_size, prev_seq_len... | incremental_decode | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def forward(self, data, valid_length, mem_data, mem_valid_length):
"""
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
valid_length
... |
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, seq_length, C_in)
- layout = 'TN'
Shape (seq_length, batch_size, C_in)
valid_length
Shape (batch_size,)
mem_data
- layout = 'NT'
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def init_states(self, batch_size, ctx, dtype='float32'):
"""Initialize the states required for incremental decoding
Returns
-------
states
A list of states, each includes:
- init_key
- layout = 'NT'
Shape (batch_si... | Initialize the states required for incremental decoding
Returns
-------
states
A list of states, each includes:
- init_key
- layout = 'NT'
Shape (batch_size, 0, N, C_key)
- layout = 'TN'
... | init_states | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def incremental_decode(self, data, states, mem, mem_valid_length):
"""Incrementally generate the output given the decoder input.
Parameters
----------
data
Shape (batch_size, C_in)
states
The previous states, contain a list of
1. layout = 'NT... | Incrementally generate the output given the decoder input.
Parameters
----------
data
Shape (batch_size, C_in)
states
The previous states, contain a list of
1. layout = 'NT'
- prev_multi_key
Shape (batch_size, prev... | incremental_decode | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def __init__(self, src_vocab_size: int,
tgt_vocab_size: int,
max_src_length: Optional[int] = None,
max_tgt_length: Optional[int] = None,
scale_embed: bool = True,
pos_embed_type="sinusoidal",
shared_embed: bool = True,... |
Parameters
----------
src_vocab_size
The vocabulary size of the source language
tgt_vocab_size
The vocabulary size of the target language
max_src_length
The maximal length of the source sequence.
If it's negative, we will use trea... | __init__ | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def encode(self, src_data, src_valid_length):
"""Encode the source data to memory
Parameters
----------
src_data
- layout = 'NT'
Shape (batch_size, src_length)
- layout = 'TN'
Shape (src_length, batch_size)
src_valid_lengt... | Encode the source data to memory
Parameters
----------
src_data
- layout = 'NT'
Shape (batch_size, src_length)
- layout = 'TN'
Shape (src_length, batch_size)
src_valid_length
Shape (batch_size,)
Returns
... | encode | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def decode_seq(self, tgt_data, tgt_valid_length, mem_data, mem_valid_length):
"""Decode a sequence of inputs
Parameters
----------
tgt_data
- layout = 'NT'
Shape (batch_size, tgt_length)
- layout = 'TN'
Shape (tgt_length, batch_siz... | Decode a sequence of inputs
Parameters
----------
tgt_data
- layout = 'NT'
Shape (batch_size, tgt_length)
- layout = 'TN'
Shape (tgt_length, batch_size)
tgt_valid_length
Shape (batch_size,)
mem_data
... | decode_seq | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def forward(self, src_data, src_valid_length, tgt_data, tgt_valid_length):
"""
Parameters
----------
src_data
- layout = 'NT'
Shape (batch_size, src_length)
- layout = 'TN'
Shape (src_length, batch_size)
src_valid_length
... |
Parameters
----------
src_data
- layout = 'NT'
Shape (batch_size, src_length)
- layout = 'TN'
Shape (src_length, batch_size)
src_valid_length
Shape (batch_size,)
tgt_data
- layout = 'NT'
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def state_batch_axis(self) -> Tuple[int, int, int, List]:
"""Return a data structure that stores the batch axis of the internal states
of the inference model.
Returns
-------
enc_out_batch_axis
src_valid_length_batch_axis
position_batch_axis
dec_layer_ba... | Return a data structure that stores the batch axis of the internal states
of the inference model.
Returns
-------
enc_out_batch_axis
src_valid_length_batch_axis
position_batch_axis
dec_layer_batch_axis
| state_batch_axis | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def init_states(self, src_data, src_valid_length): # TODO(sxjscience) Revisit here, support auxiliary states?
"""Initialize the states required for incremental decoding
Parameters
----------
src_data
- layout = 'NT'
Shape (batch_size, src_length)
... | Initialize the states required for incremental decoding
Parameters
----------
src_data
- layout = 'NT'
Shape (batch_size, src_length)
- layout = 'TN'
Shape (src_length, batch_size)
src_valid_length
Shape (batch_size,)
... | init_states | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def forward(self, step_data, states):
"""
Parameters
----------
step_data
Shape (batch_size,)
states
It includes :
- layout = 'NT'
- mem_data : (batch_size, src_length, C_mem)
- mem_valid_length : (b... |
Parameters
----------
step_data
Shape (batch_size,)
states
It includes :
- layout = 'NT'
- mem_data : (batch_size, src_length, C_mem)
- mem_valid_length : (batch_size,)
- position : (bat... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer.py | Apache-2.0 |
def forward(self, data, mem, rel_positions, mask, query_r_bias, query_k_bias):
"""
Parameters
----------
data
The input data.
- layout = 'NT'
Shape (batch_size, query_length, units)
- layout = 'TN'
Shape (query_length,... |
Parameters
----------
data
The input data.
- layout = 'NT'
Shape (batch_size, query_length, units)
- layout = 'TN'
Shape (query_length, batch_size, units)
mem
The memory.
- layout = 'NT'
... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer_xl.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer_xl.py | Apache-2.0 |
def forward(self, data, mem_l, rel_positions, mask):
"""
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, query_length)
- layout = 'TN'
Shape (query_length, batch_size)
mem_l
Contains a list of mem... |
Parameters
----------
data
- layout = 'NT'
Shape (batch_size, query_length)
- layout = 'TN'
Shape (query_length, batch_size)
mem_l
Contains a list of memory objects, each one will contain:
- layout = 'NT'... | forward | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer_xl.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer_xl.py | Apache-2.0 |
def init_states(self, batch_size, ctx):
"""Initialize the states
Parameters
----------
batch_size
ctx
ctx of the initialized
Returns
-------
mems
A list of memory states
- layout = 'NT'
Shape (B, T, C)... | Initialize the states
Parameters
----------
batch_size
ctx
ctx of the initialized
Returns
-------
mems
A list of memory states
- layout = 'NT'
Shape (B, T, C)
- layout = 'TN'
Shape ... | init_states | python | dmlc/gluon-nlp | src/gluonnlp/models/transformer_xl.py | https://github.com/dmlc/gluon-nlp/blob/master/src/gluonnlp/models/transformer_xl.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.