repo stringlengths 7 54 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 20 28.4k | docstring stringlengths 1 46.3k | docstring_tokens listlengths 1 1.66k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value | summary stringlengths 4 350 | obf_code stringlengths 7.85k 764k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
dmlc/gluon-nlp | src/gluonnlp/embedding/token_embedding.py | TokenEmbedding.serialize | def serialize(self, file_path, compress=True):
"""Serializes the TokenEmbedding to a file specified by file_path.
TokenEmbedding is serialized by converting the list of tokens, the
array of word embeddings and other metadata to numpy arrays, saving all
in a single (optionally compressed... | python | def serialize(self, file_path, compress=True):
"""Serializes the TokenEmbedding to a file specified by file_path.
TokenEmbedding is serialized by converting the list of tokens, the
array of word embeddings and other metadata to numpy arrays, saving all
in a single (optionally compressed... | [
"def",
"serialize",
"(",
"self",
",",
"file_path",
",",
"compress",
"=",
"True",
")",
":",
"if",
"self",
".",
"unknown_lookup",
"is",
"not",
"None",
":",
"warnings",
".",
"warn",
"(",
"'Serialization of `unknown_lookup` is not supported. '",
"'Save it manually and p... | Serializes the TokenEmbedding to a file specified by file_path.
TokenEmbedding is serialized by converting the list of tokens, the
array of word embeddings and other metadata to numpy arrays, saving all
in a single (optionally compressed) Zipfile. See
https://docs.scipy.org/doc/numpy-1.... | [
"Serializes",
"the",
"TokenEmbedding",
"to",
"a",
"file",
"specified",
"by",
"file_path",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L696-L737 | train | Serializes the TokenEmbedding object to a file specified by file_path. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/embedding/token_embedding.py | TokenEmbedding.deserialize | def deserialize(cls, file_path, **kwargs):
"""Create a new TokenEmbedding from a serialized one.
TokenEmbedding is serialized by converting the list of tokens, the
array of word embeddings and other metadata to numpy arrays, saving all
in a single (optionally compressed) Zipfile. See
... | python | def deserialize(cls, file_path, **kwargs):
"""Create a new TokenEmbedding from a serialized one.
TokenEmbedding is serialized by converting the list of tokens, the
array of word embeddings and other metadata to numpy arrays, saving all
in a single (optionally compressed) Zipfile. See
... | [
"def",
"deserialize",
"(",
"cls",
",",
"file_path",
",",
"*",
"*",
"kwargs",
")",
":",
"# idx_to_token is of dtype 'O' so we need to allow pickle",
"npz_dict",
"=",
"np",
".",
"load",
"(",
"file_path",
",",
"allow_pickle",
"=",
"True",
")",
"unknown_token",
"=",
... | Create a new TokenEmbedding from a serialized one.
TokenEmbedding is serialized by converting the list of tokens, the
array of word embeddings and other metadata to numpy arrays, saving all
in a single (optionally compressed) Zipfile. See
https://docs.scipy.org/doc/numpy-1.14.2/neps/npy... | [
"Create",
"a",
"new",
"TokenEmbedding",
"from",
"a",
"serialized",
"one",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L740-L784 | train | Create a new TokenEmbedding from a serialized one. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/staticbert/static_export_squad.py | evaluate | def evaluate(data_source):
"""Evaluate the model on a mini-batch.
"""
log.info('Start predict')
tic = time.time()
for batch in data_source:
inputs, token_types, valid_length = batch
out = net(inputs.astype('float32').as_in_context(ctx),
token_types.astype('float32')... | python | def evaluate(data_source):
"""Evaluate the model on a mini-batch.
"""
log.info('Start predict')
tic = time.time()
for batch in data_source:
inputs, token_types, valid_length = batch
out = net(inputs.astype('float32').as_in_context(ctx),
token_types.astype('float32')... | [
"def",
"evaluate",
"(",
"data_source",
")",
":",
"log",
".",
"info",
"(",
"'Start predict'",
")",
"tic",
"=",
"time",
".",
"time",
"(",
")",
"for",
"batch",
"in",
"data_source",
":",
"inputs",
",",
"token_types",
",",
"valid_length",
"=",
"batch",
"out",... | Evaluate the model on a mini-batch. | [
"Evaluate",
"the",
"model",
"on",
"a",
"mini",
"-",
"batch",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/staticbert/static_export_squad.py#L210-L223 | train | Evaluate the model on a mini - batch. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/registry.py | register | def register(class_=None, **kwargs):
"""Registers a dataset with segment specific hyperparameters.
When passing keyword arguments to `register`, they are checked to be valid
keyword arguments for the registered Dataset class constructor and are
saved in the registry. Registered keyword arguments can be... | python | def register(class_=None, **kwargs):
"""Registers a dataset with segment specific hyperparameters.
When passing keyword arguments to `register`, they are checked to be valid
keyword arguments for the registered Dataset class constructor and are
saved in the registry. Registered keyword arguments can be... | [
"def",
"register",
"(",
"class_",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"_real_register",
"(",
"class_",
")",
":",
"# Assert that the passed kwargs are meaningful",
"for",
"kwarg_name",
",",
"values",
"in",
"kwargs",
".",
"items",
"(",
")",
... | Registers a dataset with segment specific hyperparameters.
When passing keyword arguments to `register`, they are checked to be valid
keyword arguments for the registered Dataset class constructor and are
saved in the registry. Registered keyword arguments can be retrieved with
the `list_datasets` func... | [
"Registers",
"a",
"dataset",
"with",
"segment",
"specific",
"hyperparameters",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/registry.py#L34-L97 | train | Registers a new dataset with the specified hyperparameters. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/registry.py | create | def create(name, **kwargs):
"""Creates an instance of a registered dataset.
Parameters
----------
name : str
The dataset name (case-insensitive).
Returns
-------
An instance of :class:`mxnet.gluon.data.Dataset` constructed with the
keyword arguments passed to the create functio... | python | def create(name, **kwargs):
"""Creates an instance of a registered dataset.
Parameters
----------
name : str
The dataset name (case-insensitive).
Returns
-------
An instance of :class:`mxnet.gluon.data.Dataset` constructed with the
keyword arguments passed to the create functio... | [
"def",
"create",
"(",
"name",
",",
"*",
"*",
"kwargs",
")",
":",
"create_",
"=",
"registry",
".",
"get_create_func",
"(",
"Dataset",
",",
"'dataset'",
")",
"return",
"create_",
"(",
"name",
",",
"*",
"*",
"kwargs",
")"
] | Creates an instance of a registered dataset.
Parameters
----------
name : str
The dataset name (case-insensitive).
Returns
-------
An instance of :class:`mxnet.gluon.data.Dataset` constructed with the
keyword arguments passed to the create function. | [
"Creates",
"an",
"instance",
"of",
"a",
"registered",
"dataset",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/registry.py#L100-L115 | train | Creates an instance of a registered dataset. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/registry.py | list_datasets | def list_datasets(name=None):
"""Get valid datasets and registered parameters.
Parameters
----------
name : str or None, default None
Return names and registered parameters of registered datasets. If name
is specified, only registered parameters of the respective dataset are
ret... | python | def list_datasets(name=None):
"""Get valid datasets and registered parameters.
Parameters
----------
name : str or None, default None
Return names and registered parameters of registered datasets. If name
is specified, only registered parameters of the respective dataset are
ret... | [
"def",
"list_datasets",
"(",
"name",
"=",
"None",
")",
":",
"reg",
"=",
"registry",
".",
"get_registry",
"(",
"Dataset",
")",
"if",
"name",
"is",
"not",
"None",
":",
"class_",
"=",
"reg",
"[",
"name",
".",
"lower",
"(",
")",
"]",
"return",
"_REGSITRY... | Get valid datasets and registered parameters.
Parameters
----------
name : str or None, default None
Return names and registered parameters of registered datasets. If name
is specified, only registered parameters of the respective dataset are
returned.
Returns
-------
d... | [
"Get",
"valid",
"datasets",
"and",
"registered",
"parameters",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/registry.py#L118-L146 | train | Get valid datasets and registered parameters. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/extract_vocab.py | parse_args | def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description='Vocabulary extractor.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--max-size', type=int, default=None)
parser.add_argument('--min-freq', type=int, defau... | python | def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description='Vocabulary extractor.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--max-size', type=int, default=None)
parser.add_argument('--min-freq', type=int, defau... | [
"def",
"parse_args",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Vocabulary extractor.'",
",",
"formatter_class",
"=",
"argparse",
".",
"ArgumentDefaultsHelpFormatter",
")",
"parser",
".",
"add_argument",
"(",
"'--max-... | Parse command line arguments. | [
"Parse",
"command",
"line",
"arguments",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/extract_vocab.py#L32-L44 | train | Parse command line arguments. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/extract_vocab.py | get_vocab | def get_vocab(args):
"""Compute the vocabulary."""
counter = nlp.data.Counter()
start = time.time()
for filename in args.files:
print('Starting processing of {} after {:.1f} seconds.'.format(
filename,
time.time() - start))
with open(filename, 'r') as f:
... | python | def get_vocab(args):
"""Compute the vocabulary."""
counter = nlp.data.Counter()
start = time.time()
for filename in args.files:
print('Starting processing of {} after {:.1f} seconds.'.format(
filename,
time.time() - start))
with open(filename, 'r') as f:
... | [
"def",
"get_vocab",
"(",
"args",
")",
":",
"counter",
"=",
"nlp",
".",
"data",
".",
"Counter",
"(",
")",
"start",
"=",
"time",
".",
"time",
"(",
")",
"for",
"filename",
"in",
"args",
".",
"files",
":",
"print",
"(",
"'Starting processing of {} after {:.1... | Compute the vocabulary. | [
"Compute",
"the",
"vocabulary",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/extract_vocab.py#L47-L87 | train | Compute the vocabulary. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/bert.py | BERTClassifier.forward | def forward(self, inputs, token_types, valid_length=None): # pylint: disable=arguments-differ
"""Generate the unnormalized score for the given the input sequences.
Parameters
----------
inputs : NDArray, shape (batch_size, seq_length)
Input words for the sequences.
... | python | def forward(self, inputs, token_types, valid_length=None): # pylint: disable=arguments-differ
"""Generate the unnormalized score for the given the input sequences.
Parameters
----------
inputs : NDArray, shape (batch_size, seq_length)
Input words for the sequences.
... | [
"def",
"forward",
"(",
"self",
",",
"inputs",
",",
"token_types",
",",
"valid_length",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"_",
",",
"pooler_out",
"=",
"self",
".",
"bert",
"(",
"inputs",
",",
"token_types",
",",
"valid_length",
")",
... | Generate the unnormalized score for the given the input sequences.
Parameters
----------
inputs : NDArray, shape (batch_size, seq_length)
Input words for the sequences.
token_types : NDArray, shape (batch_size, seq_length)
Token types for the sequences, used to i... | [
"Generate",
"the",
"unnormalized",
"score",
"for",
"the",
"given",
"the",
"input",
"sequences",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/bert.py#L111-L130 | train | Generate the unnormalized score for the given input sequences. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/evaluation.py | add_parameters | def add_parameters(parser):
"""Add evaluation specific parameters to parser."""
group = parser.add_argument_group('Evaluation arguments')
group.add_argument('--eval-batch-size', type=int, default=1024)
# Datasets
group.add_argument(
'--similarity-datasets', type=str,
default=nlp.da... | python | def add_parameters(parser):
"""Add evaluation specific parameters to parser."""
group = parser.add_argument_group('Evaluation arguments')
group.add_argument('--eval-batch-size', type=int, default=1024)
# Datasets
group.add_argument(
'--similarity-datasets', type=str,
default=nlp.da... | [
"def",
"add_parameters",
"(",
"parser",
")",
":",
"group",
"=",
"parser",
".",
"add_argument_group",
"(",
"'Evaluation arguments'",
")",
"group",
".",
"add_argument",
"(",
"'--eval-batch-size'",
",",
"type",
"=",
"int",
",",
"default",
"=",
"1024",
")",
"# Dat... | Add evaluation specific parameters to parser. | [
"Add",
"evaluation",
"specific",
"parameters",
"to",
"parser",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/evaluation.py#L38-L70 | train | Add evaluation specific parameters to parser. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/evaluation.py | validate_args | def validate_args(args):
"""Validate provided arguments and act on --help."""
# Check correctness of similarity dataset names
for dataset_name in args.similarity_datasets:
if dataset_name.lower() not in map(
str.lower,
nlp.data.word_embedding_evaluation.word_similarit... | python | def validate_args(args):
"""Validate provided arguments and act on --help."""
# Check correctness of similarity dataset names
for dataset_name in args.similarity_datasets:
if dataset_name.lower() not in map(
str.lower,
nlp.data.word_embedding_evaluation.word_similarit... | [
"def",
"validate_args",
"(",
"args",
")",
":",
"# Check correctness of similarity dataset names",
"for",
"dataset_name",
"in",
"args",
".",
"similarity_datasets",
":",
"if",
"dataset_name",
".",
"lower",
"(",
")",
"not",
"in",
"map",
"(",
"str",
".",
"lower",
",... | Validate provided arguments and act on --help. | [
"Validate",
"provided",
"arguments",
"and",
"act",
"on",
"--",
"help",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/evaluation.py#L73-L89 | train | Validate provided arguments and act on -- help. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/evaluation.py | iterate_similarity_datasets | def iterate_similarity_datasets(args):
"""Generator over all similarity evaluation datasets.
Iterates over dataset names, keyword arguments for their creation and the
created dataset.
"""
for dataset_name in args.similarity_datasets:
parameters = nlp.data.list_datasets(dataset_name)
... | python | def iterate_similarity_datasets(args):
"""Generator over all similarity evaluation datasets.
Iterates over dataset names, keyword arguments for their creation and the
created dataset.
"""
for dataset_name in args.similarity_datasets:
parameters = nlp.data.list_datasets(dataset_name)
... | [
"def",
"iterate_similarity_datasets",
"(",
"args",
")",
":",
"for",
"dataset_name",
"in",
"args",
".",
"similarity_datasets",
":",
"parameters",
"=",
"nlp",
".",
"data",
".",
"list_datasets",
"(",
"dataset_name",
")",
"for",
"key_values",
"in",
"itertools",
".",... | Generator over all similarity evaluation datasets.
Iterates over dataset names, keyword arguments for their creation and the
created dataset. | [
"Generator",
"over",
"all",
"similarity",
"evaluation",
"datasets",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/evaluation.py#L92-L103 | train | Generator over all similarity evaluation datasets. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/evaluation.py | iterate_analogy_datasets | def iterate_analogy_datasets(args):
"""Generator over all analogy evaluation datasets.
Iterates over dataset names, keyword arguments for their creation and the
created dataset.
"""
for dataset_name in args.analogy_datasets:
parameters = nlp.data.list_datasets(dataset_name)
for key... | python | def iterate_analogy_datasets(args):
"""Generator over all analogy evaluation datasets.
Iterates over dataset names, keyword arguments for their creation and the
created dataset.
"""
for dataset_name in args.analogy_datasets:
parameters = nlp.data.list_datasets(dataset_name)
for key... | [
"def",
"iterate_analogy_datasets",
"(",
"args",
")",
":",
"for",
"dataset_name",
"in",
"args",
".",
"analogy_datasets",
":",
"parameters",
"=",
"nlp",
".",
"data",
".",
"list_datasets",
"(",
"dataset_name",
")",
"for",
"key_values",
"in",
"itertools",
".",
"pr... | Generator over all analogy evaluation datasets.
Iterates over dataset names, keyword arguments for their creation and the
created dataset. | [
"Generator",
"over",
"all",
"analogy",
"evaluation",
"datasets",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/evaluation.py#L106-L117 | train | Generator over all analogy evaluation datasets. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/evaluation.py | get_similarity_task_tokens | def get_similarity_task_tokens(args):
"""Returns a set of all tokens occurring the evaluation datasets."""
tokens = set()
for _, _, dataset in iterate_similarity_datasets(args):
tokens.update(
itertools.chain.from_iterable((d[0], d[1]) for d in dataset))
return tokens | python | def get_similarity_task_tokens(args):
"""Returns a set of all tokens occurring the evaluation datasets."""
tokens = set()
for _, _, dataset in iterate_similarity_datasets(args):
tokens.update(
itertools.chain.from_iterable((d[0], d[1]) for d in dataset))
return tokens | [
"def",
"get_similarity_task_tokens",
"(",
"args",
")",
":",
"tokens",
"=",
"set",
"(",
")",
"for",
"_",
",",
"_",
",",
"dataset",
"in",
"iterate_similarity_datasets",
"(",
"args",
")",
":",
"tokens",
".",
"update",
"(",
"itertools",
".",
"chain",
".",
"f... | Returns a set of all tokens occurring the evaluation datasets. | [
"Returns",
"a",
"set",
"of",
"all",
"tokens",
"occurring",
"the",
"evaluation",
"datasets",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/evaluation.py#L120-L126 | train | Returns a set of all tokens occurring the evaluation datasets. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/evaluation.py | get_analogy_task_tokens | def get_analogy_task_tokens(args):
"""Returns a set of all tokens occuring the evaluation datasets."""
tokens = set()
for _, _, dataset in iterate_analogy_datasets(args):
tokens.update(
itertools.chain.from_iterable(
(d[0], d[1], d[2], d[3]) for d in dataset))
return ... | python | def get_analogy_task_tokens(args):
"""Returns a set of all tokens occuring the evaluation datasets."""
tokens = set()
for _, _, dataset in iterate_analogy_datasets(args):
tokens.update(
itertools.chain.from_iterable(
(d[0], d[1], d[2], d[3]) for d in dataset))
return ... | [
"def",
"get_analogy_task_tokens",
"(",
"args",
")",
":",
"tokens",
"=",
"set",
"(",
")",
"for",
"_",
",",
"_",
",",
"dataset",
"in",
"iterate_analogy_datasets",
"(",
"args",
")",
":",
"tokens",
".",
"update",
"(",
"itertools",
".",
"chain",
".",
"from_it... | Returns a set of all tokens occuring the evaluation datasets. | [
"Returns",
"a",
"set",
"of",
"all",
"tokens",
"occuring",
"the",
"evaluation",
"datasets",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/evaluation.py#L129-L136 | train | Returns a set of all tokens occuring the evaluation datasets. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/evaluation.py | evaluate_similarity | def evaluate_similarity(args, token_embedding, ctx, logfile=None,
global_step=0):
"""Evaluate on specified similarity datasets."""
results = []
for similarity_function in args.similarity_functions:
evaluator = nlp.embedding.evaluation.WordEmbeddingSimilarity(
idx... | python | def evaluate_similarity(args, token_embedding, ctx, logfile=None,
global_step=0):
"""Evaluate on specified similarity datasets."""
results = []
for similarity_function in args.similarity_functions:
evaluator = nlp.embedding.evaluation.WordEmbeddingSimilarity(
idx... | [
"def",
"evaluate_similarity",
"(",
"args",
",",
"token_embedding",
",",
"ctx",
",",
"logfile",
"=",
"None",
",",
"global_step",
"=",
"0",
")",
":",
"results",
"=",
"[",
"]",
"for",
"similarity_function",
"in",
"args",
".",
"similarity_functions",
":",
"evalu... | Evaluate on specified similarity datasets. | [
"Evaluate",
"on",
"specified",
"similarity",
"datasets",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/evaluation.py#L145-L197 | train | Evaluate on specified similarity datasets. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/evaluation.py | evaluate_analogy | def evaluate_analogy(args, token_embedding, ctx, logfile=None, global_step=0):
"""Evaluate on specified analogy datasets.
The analogy task is an open vocabulary task, make sure to pass a
token_embedding with a sufficiently large number of supported tokens.
"""
results = []
exclude_question_wor... | python | def evaluate_analogy(args, token_embedding, ctx, logfile=None, global_step=0):
"""Evaluate on specified analogy datasets.
The analogy task is an open vocabulary task, make sure to pass a
token_embedding with a sufficiently large number of supported tokens.
"""
results = []
exclude_question_wor... | [
"def",
"evaluate_analogy",
"(",
"args",
",",
"token_embedding",
",",
"ctx",
",",
"logfile",
"=",
"None",
",",
"global_step",
"=",
"0",
")",
":",
"results",
"=",
"[",
"]",
"exclude_question_words",
"=",
"not",
"args",
".",
"analogy_dont_exclude_question_words",
... | Evaluate on specified analogy datasets.
The analogy task is an open vocabulary task, make sure to pass a
token_embedding with a sufficiently large number of supported tokens. | [
"Evaluate",
"on",
"specified",
"analogy",
"datasets",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/evaluation.py#L200-L259 | train | Evaluate on the specified analogy datasets. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/evaluation.py | log_similarity_result | def log_similarity_result(logfile, result):
"""Log a similarity evaluation result dictionary as TSV to logfile."""
assert result['task'] == 'similarity'
if not logfile:
return
with open(logfile, 'a') as f:
f.write('\t'.join([
str(result['global_step']),
result['... | python | def log_similarity_result(logfile, result):
"""Log a similarity evaluation result dictionary as TSV to logfile."""
assert result['task'] == 'similarity'
if not logfile:
return
with open(logfile, 'a') as f:
f.write('\t'.join([
str(result['global_step']),
result['... | [
"def",
"log_similarity_result",
"(",
"logfile",
",",
"result",
")",
":",
"assert",
"result",
"[",
"'task'",
"]",
"==",
"'similarity'",
"if",
"not",
"logfile",
":",
"return",
"with",
"open",
"(",
"logfile",
",",
"'a'",
")",
"as",
"f",
":",
"f",
".",
"wr... | Log a similarity evaluation result dictionary as TSV to logfile. | [
"Log",
"a",
"similarity",
"evaluation",
"result",
"dictionary",
"as",
"TSV",
"to",
"logfile",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/evaluation.py#L262-L280 | train | Log a similarity evaluation result dictionary as TSV to logfile. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/pretraining_utils.py | get_model_loss | def get_model_loss(ctx, model, pretrained, dataset_name, dtype, ckpt_dir=None, start_step=None):
"""Get model for pre-training."""
# model
model, vocabulary = nlp.model.get_model(model,
dataset_name=dataset_name,
pretrai... | python | def get_model_loss(ctx, model, pretrained, dataset_name, dtype, ckpt_dir=None, start_step=None):
"""Get model for pre-training."""
# model
model, vocabulary = nlp.model.get_model(model,
dataset_name=dataset_name,
pretrai... | [
"def",
"get_model_loss",
"(",
"ctx",
",",
"model",
",",
"pretrained",
",",
"dataset_name",
",",
"dtype",
",",
"ckpt_dir",
"=",
"None",
",",
"start_step",
"=",
"None",
")",
":",
"# model",
"model",
",",
"vocabulary",
"=",
"nlp",
".",
"model",
".",
"get_mo... | Get model for pre-training. | [
"Get",
"model",
"for",
"pre",
"-",
"training",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/pretraining_utils.py#L36-L60 | train | Get model for pre - training. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/pretraining_utils.py | get_pretrain_dataset | def get_pretrain_dataset(data, batch_size, num_ctxes, shuffle, use_avg_len,
num_buckets, num_parts=1, part_idx=0, prefetch=True):
"""create dataset for pretraining."""
num_files = len(glob.glob(os.path.expanduser(data)))
logging.debug('%d files found.', num_files)
assert num_fil... | python | def get_pretrain_dataset(data, batch_size, num_ctxes, shuffle, use_avg_len,
num_buckets, num_parts=1, part_idx=0, prefetch=True):
"""create dataset for pretraining."""
num_files = len(glob.glob(os.path.expanduser(data)))
logging.debug('%d files found.', num_files)
assert num_fil... | [
"def",
"get_pretrain_dataset",
"(",
"data",
",",
"batch_size",
",",
"num_ctxes",
",",
"shuffle",
",",
"use_avg_len",
",",
"num_buckets",
",",
"num_parts",
"=",
"1",
",",
"part_idx",
"=",
"0",
",",
"prefetch",
"=",
"True",
")",
":",
"num_files",
"=",
"len",... | create dataset for pretraining. | [
"create",
"dataset",
"for",
"pretraining",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/pretraining_utils.py#L62-L107 | train | create a pretraining dataset based on the data. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/pretraining_utils.py | get_dummy_dataloader | def get_dummy_dataloader(dataloader, target_shape):
"""Return a dummy data loader which returns a fixed data batch of target shape"""
data_iter = enumerate(dataloader)
_, data_batch = next(data_iter)
logging.debug('Searching target batch shape: %s', target_shape)
while data_batch[0].shape != target_... | python | def get_dummy_dataloader(dataloader, target_shape):
"""Return a dummy data loader which returns a fixed data batch of target shape"""
data_iter = enumerate(dataloader)
_, data_batch = next(data_iter)
logging.debug('Searching target batch shape: %s', target_shape)
while data_batch[0].shape != target_... | [
"def",
"get_dummy_dataloader",
"(",
"dataloader",
",",
"target_shape",
")",
":",
"data_iter",
"=",
"enumerate",
"(",
"dataloader",
")",
"_",
",",
"data_batch",
"=",
"next",
"(",
"data_iter",
")",
"logging",
".",
"debug",
"(",
"'Searching target batch shape: %s'",
... | Return a dummy data loader which returns a fixed data batch of target shape | [
"Return",
"a",
"dummy",
"data",
"loader",
"which",
"returns",
"a",
"fixed",
"data",
"batch",
"of",
"target",
"shape"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/pretraining_utils.py#L109-L127 | train | Return a dummy data loader which returns a fixed data batch of target_shape. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/pretraining_utils.py | save_params | def save_params(step_num, model, trainer, ckpt_dir):
"""Save the model parameter, marked by step_num."""
param_path = os.path.join(ckpt_dir, '%07d.params'%step_num)
trainer_path = os.path.join(ckpt_dir, '%07d.states'%step_num)
logging.info('[step %d] Saving checkpoints to %s, %s.',
step... | python | def save_params(step_num, model, trainer, ckpt_dir):
"""Save the model parameter, marked by step_num."""
param_path = os.path.join(ckpt_dir, '%07d.params'%step_num)
trainer_path = os.path.join(ckpt_dir, '%07d.states'%step_num)
logging.info('[step %d] Saving checkpoints to %s, %s.',
step... | [
"def",
"save_params",
"(",
"step_num",
",",
"model",
",",
"trainer",
",",
"ckpt_dir",
")",
":",
"param_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"ckpt_dir",
",",
"'%07d.params'",
"%",
"step_num",
")",
"trainer_path",
"=",
"os",
".",
"path",
".",
... | Save the model parameter, marked by step_num. | [
"Save",
"the",
"model",
"parameter",
"marked",
"by",
"step_num",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/pretraining_utils.py#L129-L136 | train | Save the model parameter marked by step_num. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/pretraining_utils.py | log | def log(begin_time, running_num_tks, running_mlm_loss, running_nsp_loss, step_num,
mlm_metric, nsp_metric, trainer, log_interval):
"""Log training progress."""
end_time = time.time()
duration = end_time - begin_time
throughput = running_num_tks / duration / 1000.0
running_mlm_loss = running_... | python | def log(begin_time, running_num_tks, running_mlm_loss, running_nsp_loss, step_num,
mlm_metric, nsp_metric, trainer, log_interval):
"""Log training progress."""
end_time = time.time()
duration = end_time - begin_time
throughput = running_num_tks / duration / 1000.0
running_mlm_loss = running_... | [
"def",
"log",
"(",
"begin_time",
",",
"running_num_tks",
",",
"running_mlm_loss",
",",
"running_nsp_loss",
",",
"step_num",
",",
"mlm_metric",
",",
"nsp_metric",
",",
"trainer",
",",
"log_interval",
")",
":",
"end_time",
"=",
"time",
".",
"time",
"(",
")",
"... | Log training progress. | [
"Log",
"training",
"progress",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/pretraining_utils.py#L138-L150 | train | Log training progress. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/pretraining_utils.py | split_and_load | def split_and_load(arrs, ctx):
"""split and load arrays to a list of contexts"""
assert isinstance(arrs, (list, tuple))
# split and load
loaded_arrs = [mx.gluon.utils.split_and_load(arr, ctx, even_split=False) for arr in arrs]
return zip(*loaded_arrs) | python | def split_and_load(arrs, ctx):
"""split and load arrays to a list of contexts"""
assert isinstance(arrs, (list, tuple))
# split and load
loaded_arrs = [mx.gluon.utils.split_and_load(arr, ctx, even_split=False) for arr in arrs]
return zip(*loaded_arrs) | [
"def",
"split_and_load",
"(",
"arrs",
",",
"ctx",
")",
":",
"assert",
"isinstance",
"(",
"arrs",
",",
"(",
"list",
",",
"tuple",
")",
")",
"# split and load",
"loaded_arrs",
"=",
"[",
"mx",
".",
"gluon",
".",
"utils",
".",
"split_and_load",
"(",
"arr",
... | split and load arrays to a list of contexts | [
"split",
"and",
"load",
"arrays",
"to",
"a",
"list",
"of",
"contexts"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/pretraining_utils.py#L153-L158 | train | split and load arrays to a list of contexts | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/pretraining_utils.py | forward | def forward(data, model, mlm_loss, nsp_loss, vocab_size, dtype):
"""forward computation for evaluation"""
(input_id, masked_id, masked_position, masked_weight, \
next_sentence_label, segment_id, valid_length) = data
num_masks = masked_weight.sum() + 1e-8
valid_length = valid_length.reshape(-1)
... | python | def forward(data, model, mlm_loss, nsp_loss, vocab_size, dtype):
"""forward computation for evaluation"""
(input_id, masked_id, masked_position, masked_weight, \
next_sentence_label, segment_id, valid_length) = data
num_masks = masked_weight.sum() + 1e-8
valid_length = valid_length.reshape(-1)
... | [
"def",
"forward",
"(",
"data",
",",
"model",
",",
"mlm_loss",
",",
"nsp_loss",
",",
"vocab_size",
",",
"dtype",
")",
":",
"(",
"input_id",
",",
"masked_id",
",",
"masked_position",
",",
"masked_weight",
",",
"next_sentence_label",
",",
"segment_id",
",",
"va... | forward computation for evaluation | [
"forward",
"computation",
"for",
"evaluation"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/pretraining_utils.py#L161-L179 | train | forward computation for evaluation | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/pretraining_utils.py | evaluate | def evaluate(data_eval, model, nsp_loss, mlm_loss, vocab_size, ctx, log_interval, dtype):
"""Evaluation function."""
mlm_metric = MaskedAccuracy()
nsp_metric = MaskedAccuracy()
mlm_metric.reset()
nsp_metric.reset()
eval_begin_time = time.time()
begin_time = time.time()
step_num = 0
... | python | def evaluate(data_eval, model, nsp_loss, mlm_loss, vocab_size, ctx, log_interval, dtype):
"""Evaluation function."""
mlm_metric = MaskedAccuracy()
nsp_metric = MaskedAccuracy()
mlm_metric.reset()
nsp_metric.reset()
eval_begin_time = time.time()
begin_time = time.time()
step_num = 0
... | [
"def",
"evaluate",
"(",
"data_eval",
",",
"model",
",",
"nsp_loss",
",",
"mlm_loss",
",",
"vocab_size",
",",
"ctx",
",",
"log_interval",
",",
"dtype",
")",
":",
"mlm_metric",
"=",
"MaskedAccuracy",
"(",
")",
"nsp_metric",
"=",
"MaskedAccuracy",
"(",
")",
"... | Evaluation function. | [
"Evaluation",
"function",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/pretraining_utils.py#L182-L238 | train | Evaluate the model on the data. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/pretraining_utils.py | get_argparser | def get_argparser():
"""Argument parser"""
parser = argparse.ArgumentParser(description='BERT pretraining example.')
parser.add_argument('--num_steps', type=int, default=20, help='Number of optimization steps')
parser.add_argument('--num_buckets', type=int, default=1,
help='Numbe... | python | def get_argparser():
"""Argument parser"""
parser = argparse.ArgumentParser(description='BERT pretraining example.')
parser.add_argument('--num_steps', type=int, default=20, help='Number of optimization steps')
parser.add_argument('--num_buckets', type=int, default=1,
help='Numbe... | [
"def",
"get_argparser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'BERT pretraining example.'",
")",
"parser",
".",
"add_argument",
"(",
"'--num_steps'",
",",
"type",
"=",
"int",
",",
"default",
"=",
"20",
",",
... | Argument parser | [
"Argument",
"parser"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/pretraining_utils.py#L240-L285 | train | Returns an argument parser for the bert pretraining example. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/machine_translation/dataprocessor.py | _cache_dataset | def _cache_dataset(dataset, prefix):
"""Cache the processed npy dataset the dataset into a npz
Parameters
----------
dataset : SimpleDataset
file_path : str
"""
if not os.path.exists(_constants.CACHE_PATH):
os.makedirs(_constants.CACHE_PATH)
src_data = np.concatenate([e[0] for e... | python | def _cache_dataset(dataset, prefix):
"""Cache the processed npy dataset the dataset into a npz
Parameters
----------
dataset : SimpleDataset
file_path : str
"""
if not os.path.exists(_constants.CACHE_PATH):
os.makedirs(_constants.CACHE_PATH)
src_data = np.concatenate([e[0] for e... | [
"def",
"_cache_dataset",
"(",
"dataset",
",",
"prefix",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"_constants",
".",
"CACHE_PATH",
")",
":",
"os",
".",
"makedirs",
"(",
"_constants",
".",
"CACHE_PATH",
")",
"src_data",
"=",
"np",
".... | Cache the processed npy dataset the dataset into a npz
Parameters
----------
dataset : SimpleDataset
file_path : str | [
"Cache",
"the",
"processed",
"npy",
"dataset",
"the",
"dataset",
"into",
"a",
"npz"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/machine_translation/dataprocessor.py#L33-L49 | train | Cache the processed npy dataset into a npz
| Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/machine_translation/dataprocessor.py | load_translation_data | def load_translation_data(dataset, bleu, args):
"""Load translation dataset
Parameters
----------
dataset : str
args : argparse result
Returns
-------
"""
src_lang, tgt_lang = args.src_lang, args.tgt_lang
if dataset == 'IWSLT2015':
common_prefix = 'IWSLT2015_{}_{}_{}_{... | python | def load_translation_data(dataset, bleu, args):
"""Load translation dataset
Parameters
----------
dataset : str
args : argparse result
Returns
-------
"""
src_lang, tgt_lang = args.src_lang, args.tgt_lang
if dataset == 'IWSLT2015':
common_prefix = 'IWSLT2015_{}_{}_{}_{... | [
"def",
"load_translation_data",
"(",
"dataset",
",",
"bleu",
",",
"args",
")",
":",
"src_lang",
",",
"tgt_lang",
"=",
"args",
".",
"src_lang",
",",
"args",
".",
"tgt_lang",
"if",
"dataset",
"==",
"'IWSLT2015'",
":",
"common_prefix",
"=",
"'IWSLT2015_{}_{}_{}_{... | Load translation dataset
Parameters
----------
dataset : str
args : argparse result
Returns
------- | [
"Load",
"translation",
"dataset"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/machine_translation/dataprocessor.py#L117-L198 | train | Load translation dataset | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/machine_translation/dataprocessor.py | make_dataloader | def make_dataloader(data_train, data_val, data_test, args,
use_average_length=False, num_shards=0, num_workers=8):
"""Create data loaders for training/validation/test."""
data_train_lengths = get_data_lengths(data_train)
data_val_lengths = get_data_lengths(data_val)
data_test_lengths... | python | def make_dataloader(data_train, data_val, data_test, args,
use_average_length=False, num_shards=0, num_workers=8):
"""Create data loaders for training/validation/test."""
data_train_lengths = get_data_lengths(data_train)
data_val_lengths = get_data_lengths(data_val)
data_test_lengths... | [
"def",
"make_dataloader",
"(",
"data_train",
",",
"data_val",
",",
"data_test",
",",
"args",
",",
"use_average_length",
"=",
"False",
",",
"num_shards",
"=",
"0",
",",
"num_workers",
"=",
"8",
")",
":",
"data_train_lengths",
"=",
"get_data_lengths",
"(",
"data... | Create data loaders for training/validation/test. | [
"Create",
"data",
"loaders",
"for",
"training",
"/",
"validation",
"/",
"test",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/machine_translation/dataprocessor.py#L206-L265 | train | Create a data loader for training validation and test. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/stream.py | _Prefetcher.run | def run(self):
"""Method representing the process’s activity."""
random.seed(self.seed)
np.random.seed(self.np_seed)
if not isinstance(self, multiprocessing.Process):
# Calling mxnet methods in a subprocess will raise an exception if
# mxnet is built with GPU supp... | python | def run(self):
"""Method representing the process’s activity."""
random.seed(self.seed)
np.random.seed(self.np_seed)
if not isinstance(self, multiprocessing.Process):
# Calling mxnet methods in a subprocess will raise an exception if
# mxnet is built with GPU supp... | [
"def",
"run",
"(",
"self",
")",
":",
"random",
".",
"seed",
"(",
"self",
".",
"seed",
")",
"np",
".",
"random",
".",
"seed",
"(",
"self",
".",
"np_seed",
")",
"if",
"not",
"isinstance",
"(",
"self",
",",
"multiprocessing",
".",
"Process",
")",
":",... | Method representing the process’s activity. | [
"Method",
"representing",
"the",
"process’s",
"activity",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/stream.py#L228-L270 | train | Method representing the process s activity. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/block.py | RNNCellLayer.forward | def forward(self, inputs, states=None): # pylint: disable=arguments-differ
"""Defines the forward computation. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`."""
batch_size = inputs.shape[self._batch_axis]
skip_states = states is None
if skip_states:
... | python | def forward(self, inputs, states=None): # pylint: disable=arguments-differ
"""Defines the forward computation. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`."""
batch_size = inputs.shape[self._batch_axis]
skip_states = states is None
if skip_states:
... | [
"def",
"forward",
"(",
"self",
",",
"inputs",
",",
"states",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"batch_size",
"=",
"inputs",
".",
"shape",
"[",
"self",
".",
"_batch_axis",
"]",
"skip_states",
"=",
"states",
"is",
"None",
"if",
"skip... | Defines the forward computation. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`. | [
"Defines",
"the",
"forward",
"computation",
".",
"Arguments",
"can",
"be",
"either",
":",
"py",
":",
"class",
":",
"NDArray",
"or",
":",
"py",
":",
"class",
":",
"Symbol",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/block.py#L48-L69 | train | Defines the forward computation. Arguments can be eitherNDArray or Symbol. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/train/embedding.py | CSREmbeddingModel.hybrid_forward | def hybrid_forward(self, F, words, weight):
"""Compute embedding of words in batch.
Parameters
----------
words : mx.nd.NDArray
Array of token indices.
"""
#pylint: disable=arguments-differ
embeddings = F.sparse.dot(words, weight)
return embe... | python | def hybrid_forward(self, F, words, weight):
"""Compute embedding of words in batch.
Parameters
----------
words : mx.nd.NDArray
Array of token indices.
"""
#pylint: disable=arguments-differ
embeddings = F.sparse.dot(words, weight)
return embe... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"words",
",",
"weight",
")",
":",
"#pylint: disable=arguments-differ",
"embeddings",
"=",
"F",
".",
"sparse",
".",
"dot",
"(",
"words",
",",
"weight",
")",
"return",
"embeddings"
] | Compute embedding of words in batch.
Parameters
----------
words : mx.nd.NDArray
Array of token indices. | [
"Compute",
"embedding",
"of",
"words",
"in",
"batch",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/train/embedding.py#L120-L131 | train | Compute embedding of words in batch. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/train/embedding.py | FasttextEmbeddingModel.load_fasttext_format | def load_fasttext_format(cls, path, ctx=cpu(), **kwargs):
"""Create an instance of the class and load weights.
Load the weights from the fastText binary format created by
https://github.com/facebookresearch/fastText
Parameters
----------
path : str
Path to t... | python | def load_fasttext_format(cls, path, ctx=cpu(), **kwargs):
"""Create an instance of the class and load weights.
Load the weights from the fastText binary format created by
https://github.com/facebookresearch/fastText
Parameters
----------
path : str
Path to t... | [
"def",
"load_fasttext_format",
"(",
"cls",
",",
"path",
",",
"ctx",
"=",
"cpu",
"(",
")",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"open",
"(",
"path",
",",
"'rb'",
")",
"as",
"f",
":",
"new_format",
",",
"dim",
",",
"bucket",
",",
"minn",
",",... | Create an instance of the class and load weights.
Load the weights from the fastText binary format created by
https://github.com/facebookresearch/fastText
Parameters
----------
path : str
Path to the .bin model file.
ctx : mx.Context, default mx.cpu()
... | [
"Create",
"an",
"instance",
"of",
"the",
"class",
"and",
"load",
"weights",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/train/embedding.py#L232-L280 | train | Load the class from the fastText binary format. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/natural_language_inference/utils.py | logging_config | def logging_config(logpath=None,
level=logging.DEBUG,
console_level=logging.INFO,
no_console=False):
"""
Config the logging.
"""
logger = logging.getLogger('nli')
# Remove all the current handlers
for handler in logger.handlers:
lo... | python | def logging_config(logpath=None,
level=logging.DEBUG,
console_level=logging.INFO,
no_console=False):
"""
Config the logging.
"""
logger = logging.getLogger('nli')
# Remove all the current handlers
for handler in logger.handlers:
lo... | [
"def",
"logging_config",
"(",
"logpath",
"=",
"None",
",",
"level",
"=",
"logging",
".",
"DEBUG",
",",
"console_level",
"=",
"logging",
".",
"INFO",
",",
"no_console",
"=",
"False",
")",
":",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"'nli'",
")",... | Config the logging. | [
"Config",
"the",
"logging",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/natural_language_inference/utils.py#L27-L56 | train | Configure the logging. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/train_glove.py | parse_args | def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description='GloVe with GluonNLP',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Data options
group = parser.add_argument_group('Data arguments')
group.add_argument(
'cooccurr... | python | def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description='GloVe with GluonNLP',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Data options
group = parser.add_argument_group('Data arguments')
group.add_argument(
'cooccurr... | [
"def",
"parse_args",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'GloVe with GluonNLP'",
",",
"formatter_class",
"=",
"argparse",
".",
"ArgumentDefaultsHelpFormatter",
")",
"# Data options",
"group",
"=",
"parser",
".",... | Parse command line arguments. | [
"Parse",
"command",
"line",
"arguments",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/train_glove.py#L59-L127 | train | Parse command line arguments. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/train_glove.py | get_train_data | def get_train_data(args):
"""Helper function to get training data."""
counter = dict()
with io.open(args.vocab, 'r', encoding='utf-8') as f:
for line in f:
token, count = line.split('\t')
counter[token] = int(count)
vocab = nlp.Vocab(counter, unknown_token=None, padding_t... | python | def get_train_data(args):
"""Helper function to get training data."""
counter = dict()
with io.open(args.vocab, 'r', encoding='utf-8') as f:
for line in f:
token, count = line.split('\t')
counter[token] = int(count)
vocab = nlp.Vocab(counter, unknown_token=None, padding_t... | [
"def",
"get_train_data",
"(",
"args",
")",
":",
"counter",
"=",
"dict",
"(",
")",
"with",
"io",
".",
"open",
"(",
"args",
".",
"vocab",
",",
"'r'",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"f",
":",
"for",
"line",
"in",
"f",
":",
"token",
",",... | Helper function to get training data. | [
"Helper",
"function",
"to",
"get",
"training",
"data",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/train_glove.py#L130-L161 | train | Helper function to get training data. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/train_glove.py | train | def train(args):
"""Training helper."""
vocab, row, col, counts = get_train_data(args)
model = GloVe(token_to_idx=vocab.token_to_idx, output_dim=args.emsize,
dropout=args.dropout, x_max=args.x_max, alpha=args.alpha,
weight_initializer=mx.init.Uniform(scale=1 / args.emsize... | python | def train(args):
"""Training helper."""
vocab, row, col, counts = get_train_data(args)
model = GloVe(token_to_idx=vocab.token_to_idx, output_dim=args.emsize,
dropout=args.dropout, x_max=args.x_max, alpha=args.alpha,
weight_initializer=mx.init.Uniform(scale=1 / args.emsize... | [
"def",
"train",
"(",
"args",
")",
":",
"vocab",
",",
"row",
",",
"col",
",",
"counts",
"=",
"get_train_data",
"(",
"args",
")",
"model",
"=",
"GloVe",
"(",
"token_to_idx",
"=",
"vocab",
".",
"token_to_idx",
",",
"output_dim",
"=",
"args",
".",
"emsize"... | Training helper. | [
"Training",
"helper",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/train_glove.py#L273-L357 | train | Train the GloVe model. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/train_glove.py | log | def log(args, kwargs):
"""Log to a file."""
logfile = os.path.join(args.logdir, 'log.tsv')
if 'log_created' not in globals():
if os.path.exists(logfile):
logging.error('Logfile %s already exists.', logfile)
sys.exit(1)
global log_created
log_created = sorte... | python | def log(args, kwargs):
"""Log to a file."""
logfile = os.path.join(args.logdir, 'log.tsv')
if 'log_created' not in globals():
if os.path.exists(logfile):
logging.error('Logfile %s already exists.', logfile)
sys.exit(1)
global log_created
log_created = sorte... | [
"def",
"log",
"(",
"args",
",",
"kwargs",
")",
":",
"logfile",
"=",
"os",
".",
"path",
".",
"join",
"(",
"args",
".",
"logdir",
",",
"'log.tsv'",
")",
"if",
"'log_created'",
"not",
"in",
"globals",
"(",
")",
":",
"if",
"os",
".",
"path",
".",
"ex... | Log to a file. | [
"Log",
"to",
"a",
"file",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/train_glove.py#L396-L416 | train | Log to a file. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/word_embeddings/train_glove.py | GloVe.hybrid_forward | def hybrid_forward(self, F, row, col, counts):
"""Compute embedding of words in batch.
Parameters
----------
row : mxnet.nd.NDArray or mxnet.sym.Symbol
Array of token indices for source words. Shape (batch_size, ).
row : mxnet.nd.NDArray or mxnet.sym.Symbol
... | python | def hybrid_forward(self, F, row, col, counts):
"""Compute embedding of words in batch.
Parameters
----------
row : mxnet.nd.NDArray or mxnet.sym.Symbol
Array of token indices for source words. Shape (batch_size, ).
row : mxnet.nd.NDArray or mxnet.sym.Symbol
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"row",
",",
"col",
",",
"counts",
")",
":",
"emb_in",
"=",
"self",
".",
"source_embedding",
"(",
"row",
")",
"emb_out",
"=",
"self",
".",
"context_embedding",
"(",
"col",
")",
"if",
"self",
".",
"_... | Compute embedding of words in batch.
Parameters
----------
row : mxnet.nd.NDArray or mxnet.sym.Symbol
Array of token indices for source words. Shape (batch_size, ).
row : mxnet.nd.NDArray or mxnet.sym.Symbol
Array of token indices for context words. Shape (batch_... | [
"Compute",
"embedding",
"of",
"words",
"in",
"batch",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/train_glove.py#L201-L235 | train | Compute the embedding of words in batch. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/metric/masked_accuracy.py | MaskedAccuracy.update | def update(self, labels, preds, masks=None):
# pylint: disable=arguments-differ
"""Updates the internal evaluation result.
Parameters
----------
labels : list of `NDArray`
The labels of the data with class indices as values, one per sample.
preds : list of `N... | python | def update(self, labels, preds, masks=None):
# pylint: disable=arguments-differ
"""Updates the internal evaluation result.
Parameters
----------
labels : list of `NDArray`
The labels of the data with class indices as values, one per sample.
preds : list of `N... | [
"def",
"update",
"(",
"self",
",",
"labels",
",",
"preds",
",",
"masks",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"labels",
",",
"preds",
"=",
"check_label_shapes",
"(",
"labels",
",",
"preds",
",",
"True",
")",
"masks",
"=",
"[",
"None... | Updates the internal evaluation result.
Parameters
----------
labels : list of `NDArray`
The labels of the data with class indices as values, one per sample.
preds : list of `NDArray`
Prediction values for samples. Each prediction value can either be the class in... | [
"Updates",
"the",
"internal",
"evaluation",
"result",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/metric/masked_accuracy.py#L232-L275 | train | Updates the internal evaluation result of the internal data structures. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/natural_language_inference/decomposable_attention.py | NLIModel.hybrid_forward | def hybrid_forward(self, F, sentence1, sentence2):
"""
Predict the relation of two sentences.
Parameters
----------
sentence1 : NDArray
Shape (batch_size, length)
sentence2 : NDArray
Shape (batch_size, length)
Returns
-------
... | python | def hybrid_forward(self, F, sentence1, sentence2):
"""
Predict the relation of two sentences.
Parameters
----------
sentence1 : NDArray
Shape (batch_size, length)
sentence2 : NDArray
Shape (batch_size, length)
Returns
-------
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"sentence1",
",",
"sentence2",
")",
":",
"feature1",
"=",
"self",
".",
"lin_proj",
"(",
"self",
".",
"word_emb",
"(",
"sentence1",
")",
")",
"feature2",
"=",
"self",
".",
"lin_proj",
"(",
"self",
"."... | Predict the relation of two sentences.
Parameters
----------
sentence1 : NDArray
Shape (batch_size, length)
sentence2 : NDArray
Shape (batch_size, length)
Returns
-------
pred : NDArray
Shape (batch_size, num_classes). num_cla... | [
"Predict",
"the",
"relation",
"of",
"two",
"sentences",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/natural_language_inference/decomposable_attention.py#L55-L78 | train | Predict the relation of two sentences. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/natural_language_inference/decomposable_attention.py | IntraSentenceAttention.hybrid_forward | def hybrid_forward(self, F, feature_a):
"""
Compute intra-sentence attention given embedded words.
Parameters
----------
feature_a : NDArray
Shape (batch_size, length, hidden_size)
Returns
-------
alpha : NDArray
Shape (batch_size... | python | def hybrid_forward(self, F, feature_a):
"""
Compute intra-sentence attention given embedded words.
Parameters
----------
feature_a : NDArray
Shape (batch_size, length, hidden_size)
Returns
-------
alpha : NDArray
Shape (batch_size... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"feature_a",
")",
":",
"tilde_a",
"=",
"self",
".",
"intra_attn_emb",
"(",
"feature_a",
")",
"e_matrix",
"=",
"F",
".",
"batch_dot",
"(",
"tilde_a",
",",
"tilde_a",
",",
"transpose_b",
"=",
"True",
")"... | Compute intra-sentence attention given embedded words.
Parameters
----------
feature_a : NDArray
Shape (batch_size, length, hidden_size)
Returns
-------
alpha : NDArray
Shape (batch_size, length, hidden_size) | [
"Compute",
"intra",
"-",
"sentence",
"attention",
"given",
"embedded",
"words",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/natural_language_inference/decomposable_attention.py#L98-L115 | train | Computes intra - sentence attention given embedded words. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/natural_language_inference/decomposable_attention.py | DecomposableAttention.hybrid_forward | def hybrid_forward(self, F, a, b):
"""
Forward of Decomposable Attention layer
"""
# a.shape = [B, L1, H]
# b.shape = [B, L2, H]
# extract features
tilde_a = self.f(a) # shape = [B, L1, H]
tilde_b = self.f(b) # shape = [B, L2, H]
# attention
... | python | def hybrid_forward(self, F, a, b):
"""
Forward of Decomposable Attention layer
"""
# a.shape = [B, L1, H]
# b.shape = [B, L2, H]
# extract features
tilde_a = self.f(a) # shape = [B, L1, H]
tilde_b = self.f(b) # shape = [B, L2, H]
# attention
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"a",
",",
"b",
")",
":",
"# a.shape = [B, L1, H]",
"# b.shape = [B, L2, H]",
"# extract features",
"tilde_a",
"=",
"self",
".",
"f",
"(",
"a",
")",
"# shape = [B, L1, H]",
"tilde_b",
"=",
"self",
".",
"f",
... | Forward of Decomposable Attention layer | [
"Forward",
"of",
"Decomposable",
"Attention",
"layer"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/natural_language_inference/decomposable_attention.py#L144-L166 | train | Forward implementation of the log - likelihood layer. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/utils.py | count_tokens | def count_tokens(tokens, to_lower=False, counter=None):
r"""Counts tokens in the specified string.
For token_delim='(td)' and seq_delim='(sd)', a specified string of two sequences of tokens may
look like::
(td)token1(td)token2(td)token3(td)(sd)(td)token4(td)token5(td)(sd)
Parameters
----... | python | def count_tokens(tokens, to_lower=False, counter=None):
r"""Counts tokens in the specified string.
For token_delim='(td)' and seq_delim='(sd)', a specified string of two sequences of tokens may
look like::
(td)token1(td)token2(td)token3(td)(sd)(td)token4(td)token5(td)(sd)
Parameters
----... | [
"def",
"count_tokens",
"(",
"tokens",
",",
"to_lower",
"=",
"False",
",",
"counter",
"=",
"None",
")",
":",
"if",
"to_lower",
":",
"tokens",
"=",
"[",
"t",
".",
"lower",
"(",
")",
"for",
"t",
"in",
"tokens",
"]",
"if",
"counter",
"is",
"None",
":",... | r"""Counts tokens in the specified string.
For token_delim='(td)' and seq_delim='(sd)', a specified string of two sequences of tokens may
look like::
(td)token1(td)token2(td)token3(td)(sd)(td)token4(td)token5(td)(sd)
Parameters
----------
tokens : list of str
A source list of tok... | [
"r",
"Counts",
"tokens",
"in",
"the",
"specified",
"string",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/utils.py#L92-L133 | train | r Counts the number of tokens in the specified string. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/utils.py | slice_sequence | def slice_sequence(sequence, length, pad_last=False, pad_val=C.PAD_TOKEN, overlap=0):
"""Slice a flat sequence of tokens into sequences tokens, with each
inner sequence's length equal to the specified `length`, taking into account the requested
sequence overlap.
Parameters
----------
sequence :... | python | def slice_sequence(sequence, length, pad_last=False, pad_val=C.PAD_TOKEN, overlap=0):
"""Slice a flat sequence of tokens into sequences tokens, with each
inner sequence's length equal to the specified `length`, taking into account the requested
sequence overlap.
Parameters
----------
sequence :... | [
"def",
"slice_sequence",
"(",
"sequence",
",",
"length",
",",
"pad_last",
"=",
"False",
",",
"pad_val",
"=",
"C",
".",
"PAD_TOKEN",
",",
"overlap",
"=",
"0",
")",
":",
"if",
"length",
"<=",
"overlap",
":",
"raise",
"ValueError",
"(",
"'length needs to be l... | Slice a flat sequence of tokens into sequences tokens, with each
inner sequence's length equal to the specified `length`, taking into account the requested
sequence overlap.
Parameters
----------
sequence : list of object
A flat list of tokens.
length : int
The length of each of... | [
"Slice",
"a",
"flat",
"sequence",
"of",
"tokens",
"into",
"sequences",
"tokens",
"with",
"each",
"inner",
"sequence",
"s",
"length",
"equal",
"to",
"the",
"specified",
"length",
"taking",
"into",
"account",
"the",
"requested",
"sequence",
"overlap",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/utils.py#L152-L187 | train | Slice a flat sequence of tokens into sequences tokens with length equal to the specified length. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/utils.py | _slice_pad_length | def _slice_pad_length(num_items, length, overlap=0):
"""Calculate the padding length needed for sliced samples in order not to discard data.
Parameters
----------
num_items : int
Number of items in dataset before collating.
length : int
The length of each of the samples.
overlap... | python | def _slice_pad_length(num_items, length, overlap=0):
"""Calculate the padding length needed for sliced samples in order not to discard data.
Parameters
----------
num_items : int
Number of items in dataset before collating.
length : int
The length of each of the samples.
overlap... | [
"def",
"_slice_pad_length",
"(",
"num_items",
",",
"length",
",",
"overlap",
"=",
"0",
")",
":",
"if",
"length",
"<=",
"overlap",
":",
"raise",
"ValueError",
"(",
"'length needs to be larger than overlap'",
")",
"step",
"=",
"length",
"-",
"overlap",
"span",
"... | Calculate the padding length needed for sliced samples in order not to discard data.
Parameters
----------
num_items : int
Number of items in dataset before collating.
length : int
The length of each of the samples.
overlap : int, default 0
The extra number of items in curre... | [
"Calculate",
"the",
"padding",
"length",
"needed",
"for",
"sliced",
"samples",
"in",
"order",
"not",
"to",
"discard",
"data",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/utils.py#L190-L217 | train | Calculate the padding length needed for a sliced dataset. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/utils.py | train_valid_split | def train_valid_split(dataset, valid_ratio=0.05):
"""Split the dataset into training and validation sets.
Parameters
----------
dataset : list
A list of training samples.
valid_ratio : float, default 0.05
Proportion of training samples to use for validation set
range: [0, 1]... | python | def train_valid_split(dataset, valid_ratio=0.05):
"""Split the dataset into training and validation sets.
Parameters
----------
dataset : list
A list of training samples.
valid_ratio : float, default 0.05
Proportion of training samples to use for validation set
range: [0, 1]... | [
"def",
"train_valid_split",
"(",
"dataset",
",",
"valid_ratio",
"=",
"0.05",
")",
":",
"if",
"not",
"0.0",
"<=",
"valid_ratio",
"<=",
"1.0",
":",
"raise",
"ValueError",
"(",
"'valid_ratio should be in [0, 1]'",
")",
"num_train",
"=",
"len",
"(",
"dataset",
")"... | Split the dataset into training and validation sets.
Parameters
----------
dataset : list
A list of training samples.
valid_ratio : float, default 0.05
Proportion of training samples to use for validation set
range: [0, 1]
Returns
-------
train : SimpleDataset
v... | [
"Split",
"the",
"dataset",
"into",
"training",
"and",
"validation",
"sets",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/utils.py#L236-L262 | train | Split the dataset into training and validation sets. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/utils.py | _load_pretrained_vocab | def _load_pretrained_vocab(name, root=os.path.join(get_home_dir(), 'models'), cls=None):
"""Load the accompanying vocabulary object for pre-trained model.
Parameters
----------
name : str
Name of the vocabulary, usually the name of the dataset.
root : str, default '$MXNET_HOME/models'
... | python | def _load_pretrained_vocab(name, root=os.path.join(get_home_dir(), 'models'), cls=None):
"""Load the accompanying vocabulary object for pre-trained model.
Parameters
----------
name : str
Name of the vocabulary, usually the name of the dataset.
root : str, default '$MXNET_HOME/models'
... | [
"def",
"_load_pretrained_vocab",
"(",
"name",
",",
"root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"get_home_dir",
"(",
")",
",",
"'models'",
")",
",",
"cls",
"=",
"None",
")",
":",
"file_name",
"=",
"'{name}-{short_hash}'",
".",
"format",
"(",
"name",... | Load the accompanying vocabulary object for pre-trained model.
Parameters
----------
name : str
Name of the vocabulary, usually the name of the dataset.
root : str, default '$MXNET_HOME/models'
Location for keeping the model parameters.
MXNET_HOME defaults to '~/.mxnet'.
cls... | [
"Load",
"the",
"accompanying",
"vocabulary",
"object",
"for",
"pre",
"-",
"trained",
"model",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/utils.py#L271-L318 | train | Load the accompanying vocabulary object for a pre - trained model. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/utils.py | _extract_archive | def _extract_archive(file, target_dir):
"""Extract archive file
Parameters
----------
file : str
Absolute path of the archive file.
target_dir : str
Target directory of the archive to be uncompressed
"""
if file.endswith('.gz') or file.endswith('.tar') or file.endswith('.tg... | python | def _extract_archive(file, target_dir):
"""Extract archive file
Parameters
----------
file : str
Absolute path of the archive file.
target_dir : str
Target directory of the archive to be uncompressed
"""
if file.endswith('.gz') or file.endswith('.tar') or file.endswith('.tg... | [
"def",
"_extract_archive",
"(",
"file",
",",
"target_dir",
")",
":",
"if",
"file",
".",
"endswith",
"(",
"'.gz'",
")",
"or",
"file",
".",
"endswith",
"(",
"'.tar'",
")",
"or",
"file",
".",
"endswith",
"(",
"'.tgz'",
")",
":",
"archive",
"=",
"tarfile",... | Extract archive file
Parameters
----------
file : str
Absolute path of the archive file.
target_dir : str
Target directory of the archive to be uncompressed | [
"Extract",
"archive",
"file"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/utils.py#L330-L348 | train | Extract the archive file to target_dir | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/utils.py | Counter.discard | def discard(self, min_freq, unknown_token):
"""Discards tokens with frequency below min_frequency and represents them
as `unknown_token`.
Parameters
----------
min_freq: int
Tokens whose frequency is under min_freq is counted as `unknown_token` in
the Cou... | python | def discard(self, min_freq, unknown_token):
"""Discards tokens with frequency below min_frequency and represents them
as `unknown_token`.
Parameters
----------
min_freq: int
Tokens whose frequency is under min_freq is counted as `unknown_token` in
the Cou... | [
"def",
"discard",
"(",
"self",
",",
"min_freq",
",",
"unknown_token",
")",
":",
"freq",
"=",
"0",
"ret",
"=",
"Counter",
"(",
"{",
"}",
")",
"for",
"token",
",",
"count",
"in",
"self",
".",
"items",
"(",
")",
":",
"if",
"count",
"<",
"min_freq",
... | Discards tokens with frequency below min_frequency and represents them
as `unknown_token`.
Parameters
----------
min_freq: int
Tokens whose frequency is under min_freq is counted as `unknown_token` in
the Counter returned.
unknown_token: str
T... | [
"Discards",
"tokens",
"with",
"frequency",
"below",
"min_frequency",
"and",
"represents",
"them",
"as",
"unknown_token",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/utils.py#L45-L75 | train | Discards tokens with frequency below min_frequency and represents them
as unknown_token. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/machine_translation/train_transformer.py | train | def train():
"""Training function."""
trainer = gluon.Trainer(model.collect_params(), args.optimizer,
{'learning_rate': args.lr, 'beta2': 0.98, 'epsilon': 1e-9})
train_data_loader, val_data_loader, test_data_loader \
= dataprocessor.make_dataloader(data_train, data_val, ... | python | def train():
"""Training function."""
trainer = gluon.Trainer(model.collect_params(), args.optimizer,
{'learning_rate': args.lr, 'beta2': 0.98, 'epsilon': 1e-9})
train_data_loader, val_data_loader, test_data_loader \
= dataprocessor.make_dataloader(data_train, data_val, ... | [
"def",
"train",
"(",
")",
":",
"trainer",
"=",
"gluon",
".",
"Trainer",
"(",
"model",
".",
"collect_params",
"(",
")",
",",
"args",
".",
"optimizer",
",",
"{",
"'learning_rate'",
":",
"args",
".",
"lr",
",",
"'beta2'",
":",
"0.98",
",",
"'epsilon'",
... | Training function. | [
"Training",
"function",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/machine_translation/train_transformer.py#L262-L408 | train | Train the model. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/highway.py | Highway.hybrid_forward | def hybrid_forward(self, F, inputs, **kwargs):
# pylint: disable=unused-argument
r"""
Forward computation for highway layer
Parameters
----------
inputs: NDArray
The input tensor is of shape `(..., input_size)`.
Returns
----------
out... | python | def hybrid_forward(self, F, inputs, **kwargs):
# pylint: disable=unused-argument
r"""
Forward computation for highway layer
Parameters
----------
inputs: NDArray
The input tensor is of shape `(..., input_size)`.
Returns
----------
out... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=unused-argument",
"current_input",
"=",
"inputs",
"for",
"layer",
"in",
"self",
".",
"hnet",
":",
"projected_input",
"=",
"layer",
"(",
"curr... | r"""
Forward computation for highway layer
Parameters
----------
inputs: NDArray
The input tensor is of shape `(..., input_size)`.
Returns
----------
outputs: NDArray
The output tensor is of the same shape with input tensor `(..., input_s... | [
"r",
"Forward",
"computation",
"for",
"highway",
"layer"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/highway.py#L102-L126 | train | r Forward computation for highway layer. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/bert_qa_model.py | BertForQA.forward | def forward(self, inputs, token_types, valid_length=None): # pylint: disable=arguments-differ
"""Generate the unnormalized score for the given the input sequences.
Parameters
----------
inputs : NDArray, shape (batch_size, seq_length)
Input words for the sequences.
... | python | def forward(self, inputs, token_types, valid_length=None): # pylint: disable=arguments-differ
"""Generate the unnormalized score for the given the input sequences.
Parameters
----------
inputs : NDArray, shape (batch_size, seq_length)
Input words for the sequences.
... | [
"def",
"forward",
"(",
"self",
",",
"inputs",
",",
"token_types",
",",
"valid_length",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"bert_output",
"=",
"self",
".",
"bert",
"(",
"inputs",
",",
"token_types",
",",
"valid_length",
")",
"output",
... | Generate the unnormalized score for the given the input sequences.
Parameters
----------
inputs : NDArray, shape (batch_size, seq_length)
Input words for the sequences.
token_types : NDArray, shape (batch_size, seq_length)
Token types for the sequences, used to i... | [
"Generate",
"the",
"unnormalized",
"score",
"for",
"the",
"given",
"the",
"input",
"sequences",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/bert_qa_model.py#L49-L69 | train | Generate the unnormalized score for the given input sequences. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/bilm_encoder.py | BiLMEncoder.hybrid_forward | def hybrid_forward(self, F, inputs, states=None, mask=None):
# pylint: disable=arguments-differ
# pylint: disable=unused-argument
"""Defines the forward computation for cache cell. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`.
Parameters
----------
... | python | def hybrid_forward(self, F, inputs, states=None, mask=None):
# pylint: disable=arguments-differ
# pylint: disable=unused-argument
"""Defines the forward computation for cache cell. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`.
Parameters
----------
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
",",
"states",
"=",
"None",
",",
"mask",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"# pylint: disable=unused-argument",
"states_forward",
",",
"states_backward",
"=",
"states",
"if",
... | Defines the forward computation for cache cell. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`.
Parameters
----------
inputs : NDArray
The input data layout='TNC'.
states : Tuple[List[List[NDArray]]]
The states. including:
s... | [
"Defines",
"the",
"forward",
"computation",
"for",
"cache",
"cell",
".",
"Arguments",
"can",
"be",
"either",
":",
"py",
":",
"class",
":",
"NDArray",
"or",
":",
"py",
":",
"class",
":",
"Symbol",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/bilm_encoder.py#L132-L205 | train | Defines the forward computation for cache cell. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/natural_language_inference/preprocess.py | main | def main(args):
"""
Read tokens from the provided parse tree in the SNLI dataset.
Illegal examples are removed.
"""
examples = []
with open(args.input, 'r') as fin:
reader = csv.DictReader(fin, delimiter='\t')
for cols in reader:
s1 = read_tokens(cols['sentence1_parse... | python | def main(args):
"""
Read tokens from the provided parse tree in the SNLI dataset.
Illegal examples are removed.
"""
examples = []
with open(args.input, 'r') as fin:
reader = csv.DictReader(fin, delimiter='\t')
for cols in reader:
s1 = read_tokens(cols['sentence1_parse... | [
"def",
"main",
"(",
"args",
")",
":",
"examples",
"=",
"[",
"]",
"with",
"open",
"(",
"args",
".",
"input",
",",
"'r'",
")",
"as",
"fin",
":",
"reader",
"=",
"csv",
".",
"DictReader",
"(",
"fin",
",",
"delimiter",
"=",
"'\\t'",
")",
"for",
"cols"... | Read tokens from the provided parse tree in the SNLI dataset.
Illegal examples are removed. | [
"Read",
"tokens",
"from",
"the",
"provided",
"parse",
"tree",
"in",
"the",
"SNLI",
"dataset",
".",
"Illegal",
"examples",
"are",
"removed",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/natural_language_inference/preprocess.py#L42-L58 | train | Read tokens from the provided parse tree in the SNLI dataset. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/parsing/common/k_means.py | KMeans._recenter | def _recenter(self):
"""
one iteration of k-means
"""
for split_idx in range(len(self._splits)):
split = self._splits[split_idx]
len_idx = self._split2len_idx[split]
if split == self._splits[-1]:
continue
right_split = self.... | python | def _recenter(self):
"""
one iteration of k-means
"""
for split_idx in range(len(self._splits)):
split = self._splits[split_idx]
len_idx = self._split2len_idx[split]
if split == self._splits[-1]:
continue
right_split = self.... | [
"def",
"_recenter",
"(",
"self",
")",
":",
"for",
"split_idx",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"_splits",
")",
")",
":",
"split",
"=",
"self",
".",
"_splits",
"[",
"split_idx",
"]",
"len_idx",
"=",
"self",
".",
"_split2len_idx",
"[",
"sp... | one iteration of k-means | [
"one",
"iteration",
"of",
"k",
"-",
"means"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/k_means.py#L108-L145 | train | Recenter the k - meansCOOKIE. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/parsing/common/k_means.py | KMeans._reindex | def _reindex(self):
"""
Index every sentence into a cluster
"""
self._len2split_idx = {}
last_split = -1
for split_idx, split in enumerate(self._splits):
self._len2split_idx.update(
dict(list(zip(list(range(last_split + 1, split)), [split_idx] ... | python | def _reindex(self):
"""
Index every sentence into a cluster
"""
self._len2split_idx = {}
last_split = -1
for split_idx, split in enumerate(self._splits):
self._len2split_idx.update(
dict(list(zip(list(range(last_split + 1, split)), [split_idx] ... | [
"def",
"_reindex",
"(",
"self",
")",
":",
"self",
".",
"_len2split_idx",
"=",
"{",
"}",
"last_split",
"=",
"-",
"1",
"for",
"split_idx",
",",
"split",
"in",
"enumerate",
"(",
"self",
".",
"_splits",
")",
":",
"self",
".",
"_len2split_idx",
".",
"update... | Index every sentence into a cluster | [
"Index",
"every",
"sentence",
"into",
"a",
"cluster"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/k_means.py#L147-L155 | train | Reindex the cluster by adding all the words into the cluster. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/machine_translation/gnmt.py | get_gnmt_encoder_decoder | def get_gnmt_encoder_decoder(cell_type='lstm', attention_cell='scaled_luong', num_layers=2,
num_bi_layers=1, hidden_size=128, dropout=0.0, use_residual=False,
i2h_weight_initializer=None, h2h_weight_initializer=None,
i2h_bias_initial... | python | def get_gnmt_encoder_decoder(cell_type='lstm', attention_cell='scaled_luong', num_layers=2,
num_bi_layers=1, hidden_size=128, dropout=0.0, use_residual=False,
i2h_weight_initializer=None, h2h_weight_initializer=None,
i2h_bias_initial... | [
"def",
"get_gnmt_encoder_decoder",
"(",
"cell_type",
"=",
"'lstm'",
",",
"attention_cell",
"=",
"'scaled_luong'",
",",
"num_layers",
"=",
"2",
",",
"num_bi_layers",
"=",
"1",
",",
"hidden_size",
"=",
"128",
",",
"dropout",
"=",
"0.0",
",",
"use_residual",
"=",... | Build a pair of GNMT encoder/decoder
Parameters
----------
cell_type : str or type
attention_cell : str or AttentionCell
num_layers : int
num_bi_layers : int
hidden_size : int
dropout : float
use_residual : bool
i2h_weight_initializer : mx.init.Initializer or None
h2h_weight... | [
"Build",
"a",
"pair",
"of",
"GNMT",
"encoder",
"/",
"decoder"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/machine_translation/gnmt.py#L407-L455 | train | Returns a GNMTEncoder and GNMTDecoder object for a single block of GNMT. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/machine_translation/gnmt.py | GNMTDecoder.init_state_from_encoder | def init_state_from_encoder(self, encoder_outputs, encoder_valid_length=None):
"""Initialize the state from the encoder outputs.
Parameters
----------
encoder_outputs : list
encoder_valid_length : NDArray or None
Returns
-------
decoder_states : list
... | python | def init_state_from_encoder(self, encoder_outputs, encoder_valid_length=None):
"""Initialize the state from the encoder outputs.
Parameters
----------
encoder_outputs : list
encoder_valid_length : NDArray or None
Returns
-------
decoder_states : list
... | [
"def",
"init_state_from_encoder",
"(",
"self",
",",
"encoder_outputs",
",",
"encoder_valid_length",
"=",
"None",
")",
":",
"mem_value",
",",
"rnn_states",
"=",
"encoder_outputs",
"batch_size",
",",
"_",
",",
"mem_size",
"=",
"mem_value",
".",
"shape",
"attention_v... | Initialize the state from the encoder outputs.
Parameters
----------
encoder_outputs : list
encoder_valid_length : NDArray or None
Returns
-------
decoder_states : list
The decoder states, includes:
- rnn_states : NDArray
- a... | [
"Initialize",
"the",
"state",
"from",
"the",
"encoder",
"outputs",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/machine_translation/gnmt.py#L224-L252 | train | Initialize the decoder states from the encoder outputs. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/machine_translation/gnmt.py | GNMTDecoder.decode_seq | def decode_seq(self, inputs, states, valid_length=None):
"""Decode the decoder inputs. This function is only used for training.
Parameters
----------
inputs : NDArray, Shape (batch_size, length, C_in)
states : list of NDArrays or None
Initial states. The list of init... | python | def decode_seq(self, inputs, states, valid_length=None):
"""Decode the decoder inputs. This function is only used for training.
Parameters
----------
inputs : NDArray, Shape (batch_size, length, C_in)
states : list of NDArrays or None
Initial states. The list of init... | [
"def",
"decode_seq",
"(",
"self",
",",
"inputs",
",",
"states",
",",
"valid_length",
"=",
"None",
")",
":",
"length",
"=",
"inputs",
".",
"shape",
"[",
"1",
"]",
"output",
"=",
"[",
"]",
"additional_outputs",
"=",
"[",
"]",
"inputs",
"=",
"_as_list",
... | Decode the decoder inputs. This function is only used for training.
Parameters
----------
inputs : NDArray, Shape (batch_size, length, C_in)
states : list of NDArrays or None
Initial states. The list of initial decoder states
valid_length : NDArray or None
... | [
"Decode",
"the",
"decoder",
"inputs",
".",
"This",
"function",
"is",
"only",
"used",
"for",
"training",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/machine_translation/gnmt.py#L254-L304 | train | This function decodes the input tensor and returns the decoder outputs. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/create_pretraining_data.py | transform | def transform(instance, tokenizer, max_seq_length, max_predictions_per_seq, do_pad=True):
"""Transform instance to inputs for MLM and NSP."""
pad = tokenizer.convert_tokens_to_ids(['[PAD]'])[0]
input_ids = tokenizer.convert_tokens_to_ids(instance.tokens)
input_mask = [1] * len(input_ids)
segment_ids... | python | def transform(instance, tokenizer, max_seq_length, max_predictions_per_seq, do_pad=True):
"""Transform instance to inputs for MLM and NSP."""
pad = tokenizer.convert_tokens_to_ids(['[PAD]'])[0]
input_ids = tokenizer.convert_tokens_to_ids(instance.tokens)
input_mask = [1] * len(input_ids)
segment_ids... | [
"def",
"transform",
"(",
"instance",
",",
"tokenizer",
",",
"max_seq_length",
",",
"max_predictions_per_seq",
",",
"do_pad",
"=",
"True",
")",
":",
"pad",
"=",
"tokenizer",
".",
"convert_tokens_to_ids",
"(",
"[",
"'[PAD]'",
"]",
")",
"[",
"0",
"]",
"input_id... | Transform instance to inputs for MLM and NSP. | [
"Transform",
"instance",
"to",
"inputs",
"for",
"MLM",
"and",
"NSP",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/create_pretraining_data.py#L163-L208 | train | Transform instance to inputs for MLM and NSP. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/create_pretraining_data.py | write_to_files_np | def write_to_files_np(features, tokenizer, max_seq_length,
max_predictions_per_seq, output_files):
# pylint: disable=unused-argument
"""Write to numpy files from `TrainingInstance`s."""
next_sentence_labels = []
valid_lengths = []
assert len(output_files) == 1, 'numpy format o... | python | def write_to_files_np(features, tokenizer, max_seq_length,
max_predictions_per_seq, output_files):
# pylint: disable=unused-argument
"""Write to numpy files from `TrainingInstance`s."""
next_sentence_labels = []
valid_lengths = []
assert len(output_files) == 1, 'numpy format o... | [
"def",
"write_to_files_np",
"(",
"features",
",",
"tokenizer",
",",
"max_seq_length",
",",
"max_predictions_per_seq",
",",
"output_files",
")",
":",
"# pylint: disable=unused-argument",
"next_sentence_labels",
"=",
"[",
"]",
"valid_lengths",
"=",
"[",
"]",
"assert",
"... | Write to numpy files from `TrainingInstance`s. | [
"Write",
"to",
"numpy",
"files",
"from",
"TrainingInstance",
"s",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/create_pretraining_data.py#L218-L242 | train | Write to numpy files from training instance s. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/create_pretraining_data.py | write_to_files_rec | def write_to_files_rec(instances, tokenizer, max_seq_length,
max_predictions_per_seq, output_files):
"""Create IndexedRecordIO files from `TrainingInstance`s."""
writers = []
for output_file in output_files:
writers.append(
mx.recordio.MXIndexedRecordIO(
... | python | def write_to_files_rec(instances, tokenizer, max_seq_length,
max_predictions_per_seq, output_files):
"""Create IndexedRecordIO files from `TrainingInstance`s."""
writers = []
for output_file in output_files:
writers.append(
mx.recordio.MXIndexedRecordIO(
... | [
"def",
"write_to_files_rec",
"(",
"instances",
",",
"tokenizer",
",",
"max_seq_length",
",",
"max_predictions_per_seq",
",",
"output_files",
")",
":",
"writers",
"=",
"[",
"]",
"for",
"output_file",
"in",
"output_files",
":",
"writers",
".",
"append",
"(",
"mx",... | Create IndexedRecordIO files from `TrainingInstance`s. | [
"Create",
"IndexedRecordIO",
"files",
"from",
"TrainingInstance",
"s",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/create_pretraining_data.py#L244-L266 | train | Create IndexedRecordIO files from TrainingInstance s. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/create_pretraining_data.py | create_training_instances | def create_training_instances(x):
"""Create `TrainingInstance`s from raw text."""
(input_files, out, tokenizer, max_seq_length, dupe_factor,
short_seq_prob, masked_lm_prob, max_predictions_per_seq, rng) = x
time_start = time.time()
logging.info('Processing %s', input_files)
all_documents = [[]]... | python | def create_training_instances(x):
"""Create `TrainingInstance`s from raw text."""
(input_files, out, tokenizer, max_seq_length, dupe_factor,
short_seq_prob, masked_lm_prob, max_predictions_per_seq, rng) = x
time_start = time.time()
logging.info('Processing %s', input_files)
all_documents = [[]]... | [
"def",
"create_training_instances",
"(",
"x",
")",
":",
"(",
"input_files",
",",
"out",
",",
"tokenizer",
",",
"max_seq_length",
",",
"dupe_factor",
",",
"short_seq_prob",
",",
"masked_lm_prob",
",",
"max_predictions_per_seq",
",",
"rng",
")",
"=",
"x",
"time_st... | Create `TrainingInstance`s from raw text. | [
"Create",
"TrainingInstance",
"s",
"from",
"raw",
"text",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/create_pretraining_data.py#L269-L351 | train | Create training instances from raw text. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/create_pretraining_data.py | create_instances_from_document | def create_instances_from_document(
all_documents, document_index, max_seq_length, short_seq_prob,
masked_lm_prob, max_predictions_per_seq, vocab_words, rng):
"""Creates `TrainingInstance`s for a single document."""
document = all_documents[document_index]
# Account for [CLS], [SEP], [SEP]
... | python | def create_instances_from_document(
all_documents, document_index, max_seq_length, short_seq_prob,
masked_lm_prob, max_predictions_per_seq, vocab_words, rng):
"""Creates `TrainingInstance`s for a single document."""
document = all_documents[document_index]
# Account for [CLS], [SEP], [SEP]
... | [
"def",
"create_instances_from_document",
"(",
"all_documents",
",",
"document_index",
",",
"max_seq_length",
",",
"short_seq_prob",
",",
"masked_lm_prob",
",",
"max_predictions_per_seq",
",",
"vocab_words",
",",
"rng",
")",
":",
"document",
"=",
"all_documents",
"[",
... | Creates `TrainingInstance`s for a single document. | [
"Creates",
"TrainingInstance",
"s",
"for",
"a",
"single",
"document",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/create_pretraining_data.py#L354-L472 | train | Creates training instance for a single document. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/create_pretraining_data.py | create_masked_lm_predictions | def create_masked_lm_predictions(tokens, masked_lm_prob,
max_predictions_per_seq, vocab_words, rng):
"""Creates the predictions for the masked LM objective."""
cand_indexes = []
for (i, token) in enumerate(tokens):
if token in ['[CLS]', '[SEP]']:
continu... | python | def create_masked_lm_predictions(tokens, masked_lm_prob,
max_predictions_per_seq, vocab_words, rng):
"""Creates the predictions for the masked LM objective."""
cand_indexes = []
for (i, token) in enumerate(tokens):
if token in ['[CLS]', '[SEP]']:
continu... | [
"def",
"create_masked_lm_predictions",
"(",
"tokens",
",",
"masked_lm_prob",
",",
"max_predictions_per_seq",
",",
"vocab_words",
",",
"rng",
")",
":",
"cand_indexes",
"=",
"[",
"]",
"for",
"(",
"i",
",",
"token",
")",
"in",
"enumerate",
"(",
"tokens",
")",
"... | Creates the predictions for the masked LM objective. | [
"Creates",
"the",
"predictions",
"for",
"the",
"masked",
"LM",
"objective",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/create_pretraining_data.py#L479-L530 | train | Creates the predictions for the masked LM objective. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/create_pretraining_data.py | truncate_seq_pair | def truncate_seq_pair(tokens_a, tokens_b, max_num_tokens, rng):
"""Truncates a pair of sequences to a maximum sequence length."""
while True:
total_length = len(tokens_a) + len(tokens_b)
if total_length <= max_num_tokens:
break
trunc_tokens = tokens_a if len(tokens_a) > len(... | python | def truncate_seq_pair(tokens_a, tokens_b, max_num_tokens, rng):
"""Truncates a pair of sequences to a maximum sequence length."""
while True:
total_length = len(tokens_a) + len(tokens_b)
if total_length <= max_num_tokens:
break
trunc_tokens = tokens_a if len(tokens_a) > len(... | [
"def",
"truncate_seq_pair",
"(",
"tokens_a",
",",
"tokens_b",
",",
"max_num_tokens",
",",
"rng",
")",
":",
"while",
"True",
":",
"total_length",
"=",
"len",
"(",
"tokens_a",
")",
"+",
"len",
"(",
"tokens_b",
")",
"if",
"total_length",
"<=",
"max_num_tokens",... | Truncates a pair of sequences to a maximum sequence length. | [
"Truncates",
"a",
"pair",
"of",
"sequences",
"to",
"a",
"maximum",
"sequence",
"length",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/create_pretraining_data.py#L533-L548 | train | Truncates a pair of sequences to a maximum sequence length. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/create_pretraining_data.py | main | def main():
"""Main function."""
time_start = time.time()
logging.info('loading vocab file from dataset: %s', args.vocab)
vocab_obj = nlp.data.utils._load_pretrained_vocab(args.vocab)
tokenizer = BERTTokenizer(
vocab=vocab_obj, lower='uncased' in args.vocab)
input_files = []
for inp... | python | def main():
"""Main function."""
time_start = time.time()
logging.info('loading vocab file from dataset: %s', args.vocab)
vocab_obj = nlp.data.utils._load_pretrained_vocab(args.vocab)
tokenizer = BERTTokenizer(
vocab=vocab_obj, lower='uncased' in args.vocab)
input_files = []
for inp... | [
"def",
"main",
"(",
")",
":",
"time_start",
"=",
"time",
".",
"time",
"(",
")",
"logging",
".",
"info",
"(",
"'loading vocab file from dataset: %s'",
",",
"args",
".",
"vocab",
")",
"vocab_obj",
"=",
"nlp",
".",
"data",
".",
"utils",
".",
"_load_pretrained... | Main function. | [
"Main",
"function",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/create_pretraining_data.py#L551-L607 | train | Main function. Loads pre - trained vocab and outputs and runs the workload. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/utils.py | convert_vocab | def convert_vocab(vocab_file):
"""GluonNLP specific code to convert the original vocabulary to nlp.vocab.BERTVocab."""
original_vocab = load_vocab(vocab_file)
token_to_idx = dict(original_vocab)
num_tokens = len(token_to_idx)
idx_to_token = [None] * len(original_vocab)
for word in original_vocab... | python | def convert_vocab(vocab_file):
"""GluonNLP specific code to convert the original vocabulary to nlp.vocab.BERTVocab."""
original_vocab = load_vocab(vocab_file)
token_to_idx = dict(original_vocab)
num_tokens = len(token_to_idx)
idx_to_token = [None] * len(original_vocab)
for word in original_vocab... | [
"def",
"convert_vocab",
"(",
"vocab_file",
")",
":",
"original_vocab",
"=",
"load_vocab",
"(",
"vocab_file",
")",
"token_to_idx",
"=",
"dict",
"(",
"original_vocab",
")",
"num_tokens",
"=",
"len",
"(",
"token_to_idx",
")",
"idx_to_token",
"=",
"[",
"None",
"]"... | GluonNLP specific code to convert the original vocabulary to nlp.vocab.BERTVocab. | [
"GluonNLP",
"specific",
"code",
"to",
"convert",
"the",
"original",
"vocabulary",
"to",
"nlp",
".",
"vocab",
".",
"BERTVocab",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/utils.py#L33-L83 | train | GluonNLP specific code to convert the original vocabulary to nlp. vocab.BERTVocab. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/utils.py | read_tf_checkpoint | def read_tf_checkpoint(path):
"""read tensorflow checkpoint"""
from tensorflow.python import pywrap_tensorflow
tensors = {}
reader = pywrap_tensorflow.NewCheckpointReader(path)
var_to_shape_map = reader.get_variable_to_shape_map()
for key in sorted(var_to_shape_map):
tensor = reader.get_... | python | def read_tf_checkpoint(path):
"""read tensorflow checkpoint"""
from tensorflow.python import pywrap_tensorflow
tensors = {}
reader = pywrap_tensorflow.NewCheckpointReader(path)
var_to_shape_map = reader.get_variable_to_shape_map()
for key in sorted(var_to_shape_map):
tensor = reader.get_... | [
"def",
"read_tf_checkpoint",
"(",
"path",
")",
":",
"from",
"tensorflow",
".",
"python",
"import",
"pywrap_tensorflow",
"tensors",
"=",
"{",
"}",
"reader",
"=",
"pywrap_tensorflow",
".",
"NewCheckpointReader",
"(",
"path",
")",
"var_to_shape_map",
"=",
"reader",
... | read tensorflow checkpoint | [
"read",
"tensorflow",
"checkpoint"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/utils.py#L97-L106 | train | read tensorflow checkpoint | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/utils.py | profile | def profile(curr_step, start_step, end_step, profile_name='profile.json',
early_exit=True):
"""profile the program between [start_step, end_step)."""
if curr_step == start_step:
mx.nd.waitall()
mx.profiler.set_config(profile_memory=False, profile_symbolic=True,
... | python | def profile(curr_step, start_step, end_step, profile_name='profile.json',
early_exit=True):
"""profile the program between [start_step, end_step)."""
if curr_step == start_step:
mx.nd.waitall()
mx.profiler.set_config(profile_memory=False, profile_symbolic=True,
... | [
"def",
"profile",
"(",
"curr_step",
",",
"start_step",
",",
"end_step",
",",
"profile_name",
"=",
"'profile.json'",
",",
"early_exit",
"=",
"True",
")",
":",
"if",
"curr_step",
"==",
"start_step",
":",
"mx",
".",
"nd",
".",
"waitall",
"(",
")",
"mx",
"."... | profile the program between [start_step, end_step). | [
"profile",
"the",
"program",
"between",
"[",
"start_step",
"end_step",
")",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/utils.py#L108-L123 | train | profile the program between start_step and end_step | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/bert/utils.py | load_vocab | def load_vocab(vocab_file):
"""Loads a vocabulary file into a dictionary."""
vocab = collections.OrderedDict()
index = 0
with io.open(vocab_file, 'r') as reader:
while True:
token = reader.readline()
if not token:
break
token = token.strip()
... | python | def load_vocab(vocab_file):
"""Loads a vocabulary file into a dictionary."""
vocab = collections.OrderedDict()
index = 0
with io.open(vocab_file, 'r') as reader:
while True:
token = reader.readline()
if not token:
break
token = token.strip()
... | [
"def",
"load_vocab",
"(",
"vocab_file",
")",
":",
"vocab",
"=",
"collections",
".",
"OrderedDict",
"(",
")",
"index",
"=",
"0",
"with",
"io",
".",
"open",
"(",
"vocab_file",
",",
"'r'",
")",
"as",
"reader",
":",
"while",
"True",
":",
"token",
"=",
"r... | Loads a vocabulary file into a dictionary. | [
"Loads",
"a",
"vocabulary",
"file",
"into",
"a",
"dictionary",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/utils.py#L125-L137 | train | Loads a vocabulary file into a dictionary. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/convolutional_encoder.py | ConvolutionalEncoder.hybrid_forward | def hybrid_forward(self, F, inputs, mask=None): # pylint: disable=arguments-differ
r"""
Forward computation for char_encoder
Parameters
----------
inputs: NDArray
The input tensor is of shape `(seq_len, batch_size, embedding_size)` TNC.
mask: NDArray
... | python | def hybrid_forward(self, F, inputs, mask=None): # pylint: disable=arguments-differ
r"""
Forward computation for char_encoder
Parameters
----------
inputs: NDArray
The input tensor is of shape `(seq_len, batch_size, embedding_size)` TNC.
mask: NDArray
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
",",
"mask",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"if",
"mask",
"is",
"not",
"None",
":",
"inputs",
"=",
"F",
".",
"broadcast_mul",
"(",
"inputs",
",",
"mask",
".",
"e... | r"""
Forward computation for char_encoder
Parameters
----------
inputs: NDArray
The input tensor is of shape `(seq_len, batch_size, embedding_size)` TNC.
mask: NDArray
The mask applied to the input of shape `(seq_len, batch_size)`, the mask will
... | [
"r",
"Forward",
"computation",
"for",
"char_encoder"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/convolutional_encoder.py#L135-L166 | train | r Forward computation for char_encoder
| Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | _position_encoding_init | def _position_encoding_init(max_length, dim):
"""Init the sinusoid position encoding table """
position_enc = np.arange(max_length).reshape((-1, 1)) \
/ (np.power(10000, (2. / dim) * np.arange(dim).reshape((1, -1))))
# Apply the cosine to even columns and sin to odds.
position_enc[:, ... | python | def _position_encoding_init(max_length, dim):
"""Init the sinusoid position encoding table """
position_enc = np.arange(max_length).reshape((-1, 1)) \
/ (np.power(10000, (2. / dim) * np.arange(dim).reshape((1, -1))))
# Apply the cosine to even columns and sin to odds.
position_enc[:, ... | [
"def",
"_position_encoding_init",
"(",
"max_length",
",",
"dim",
")",
":",
"position_enc",
"=",
"np",
".",
"arange",
"(",
"max_length",
")",
".",
"reshape",
"(",
"(",
"-",
"1",
",",
"1",
")",
")",
"/",
"(",
"np",
".",
"power",
"(",
"10000",
",",
"(... | Init the sinusoid position encoding table | [
"Init",
"the",
"sinusoid",
"position",
"encoding",
"table"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L46-L53 | train | Initialize the sinusoid position encoding table | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | get_transformer_encoder_decoder | def get_transformer_encoder_decoder(num_layers=2,
num_heads=8, scaled=True,
units=512, hidden_size=2048, dropout=0.0, use_residual=True,
max_src_length=50, max_tgt_length=50,
w... | python | def get_transformer_encoder_decoder(num_layers=2,
num_heads=8, scaled=True,
units=512, hidden_size=2048, dropout=0.0, use_residual=True,
max_src_length=50, max_tgt_length=50,
w... | [
"def",
"get_transformer_encoder_decoder",
"(",
"num_layers",
"=",
"2",
",",
"num_heads",
"=",
"8",
",",
"scaled",
"=",
"True",
",",
"units",
"=",
"512",
",",
"hidden_size",
"=",
"2048",
",",
"dropout",
"=",
"0.0",
",",
"use_residual",
"=",
"True",
",",
"... | Build a pair of Parallel Transformer encoder/decoder
Parameters
----------
num_layers : int
num_heads : int
scaled : bool
units : int
hidden_size : int
dropout : float
use_residual : bool
max_src_length : int
max_tgt_length : int
weight_initializer : mx.init.Initializer ... | [
"Build",
"a",
"pair",
"of",
"Parallel",
"Transformer",
"encoder",
"/",
"decoder"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L1123-L1177 | train | Returns a pair of Parallel Transformer encoder and decoder. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | transformer_en_de_512 | def transformer_en_de_512(dataset_name=None, src_vocab=None, tgt_vocab=None, pretrained=False,
ctx=cpu(), root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""Transformer pretrained model.
Embedding size is 400, and hidden layer size is 1150.
Parameters
----------
... | python | def transformer_en_de_512(dataset_name=None, src_vocab=None, tgt_vocab=None, pretrained=False,
ctx=cpu(), root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""Transformer pretrained model.
Embedding size is 400, and hidden layer size is 1150.
Parameters
----------
... | [
"def",
"transformer_en_de_512",
"(",
"dataset_name",
"=",
"None",
",",
"src_vocab",
"=",
"None",
",",
"tgt_vocab",
"=",
"None",
",",
"pretrained",
"=",
"False",
",",
"ctx",
"=",
"cpu",
"(",
")",
",",
"root",
"=",
"os",
".",
"path",
".",
"join",
"(",
... | r"""Transformer pretrained model.
Embedding size is 400, and hidden layer size is 1150.
Parameters
----------
dataset_name : str or None, default None
src_vocab : gluonnlp.Vocab or None, default None
tgt_vocab : gluonnlp.Vocab or None, default None
pretrained : bool, default False
... | [
"r",
"Transformer",
"pretrained",
"model",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L1200-L1251 | train | r Returns a new block that can be used to train a pre - trained model. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | BasePositionwiseFFN._get_activation | def _get_activation(self, act):
"""Get activation block based on the name. """
if isinstance(act, str):
if act.lower() == 'gelu':
return GELU()
else:
return gluon.nn.Activation(act)
assert isinstance(act, gluon.Block)
return act | python | def _get_activation(self, act):
"""Get activation block based on the name. """
if isinstance(act, str):
if act.lower() == 'gelu':
return GELU()
else:
return gluon.nn.Activation(act)
assert isinstance(act, gluon.Block)
return act | [
"def",
"_get_activation",
"(",
"self",
",",
"act",
")",
":",
"if",
"isinstance",
"(",
"act",
",",
"str",
")",
":",
"if",
"act",
".",
"lower",
"(",
")",
"==",
"'gelu'",
":",
"return",
"GELU",
"(",
")",
"else",
":",
"return",
"gluon",
".",
"nn",
".... | Get activation block based on the name. | [
"Get",
"activation",
"block",
"based",
"on",
"the",
"name",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L116-L124 | train | Get the activation block based on the name. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | BasePositionwiseFFN.hybrid_forward | def hybrid_forward(self, F, inputs): # pylint: disable=arguments-differ
# pylint: disable=unused-argument
"""Position-wise encoding of the inputs.
Parameters
----------
inputs : Symbol or NDArray
Input sequence. Shape (batch_size, length, C_in)
Returns
... | python | def hybrid_forward(self, F, inputs): # pylint: disable=arguments-differ
# pylint: disable=unused-argument
"""Position-wise encoding of the inputs.
Parameters
----------
inputs : Symbol or NDArray
Input sequence. Shape (batch_size, length, C_in)
Returns
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
")",
":",
"# pylint: disable=arguments-differ",
"# pylint: disable=unused-argument",
"outputs",
"=",
"self",
".",
"ffn_1",
"(",
"inputs",
")",
"if",
"self",
".",
"activation",
":",
"outputs",
"=",
"s... | Position-wise encoding of the inputs.
Parameters
----------
inputs : Symbol or NDArray
Input sequence. Shape (batch_size, length, C_in)
Returns
-------
outputs : Symbol or NDArray
Shape (batch_size, length, C_out) | [
"Position",
"-",
"wise",
"encoding",
"of",
"the",
"inputs",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L126-L149 | train | Position - wise encoding of the inputs. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | BaseTransformerEncoderCell.hybrid_forward | def hybrid_forward(self, F, inputs, mask=None): # pylint: disable=arguments-differ
# pylint: disable=unused-argument
"""Transformer Encoder Attention Cell.
Parameters
----------
inputs : Symbol or NDArray
Input sequence. Shape (batch_size, length, C_in)
mask... | python | def hybrid_forward(self, F, inputs, mask=None): # pylint: disable=arguments-differ
# pylint: disable=unused-argument
"""Transformer Encoder Attention Cell.
Parameters
----------
inputs : Symbol or NDArray
Input sequence. Shape (batch_size, length, C_in)
mask... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
",",
"mask",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"# pylint: disable=unused-argument",
"outputs",
",",
"attention_weights",
"=",
"self",
".",
"attention_cell",
"(",
"inputs",
",",... | Transformer Encoder Attention Cell.
Parameters
----------
inputs : Symbol or NDArray
Input sequence. Shape (batch_size, length, C_in)
mask : Symbol or NDArray or None
Mask for inputs. Shape (batch_size, length, length)
Returns
-------
enc... | [
"Transformer",
"Encoder",
"Attention",
"Cell",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L236-L267 | train | Transformer encoder encoder | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | TransformerDecoderCell.hybrid_forward | def hybrid_forward(self, F, inputs, mem_value, mask=None, mem_mask=None): #pylint: disable=unused-argument
# pylint: disable=arguments-differ
"""Transformer Decoder Attention Cell.
Parameters
----------
inputs : Symbol or NDArray
Input sequence. Shape (batch_size, ... | python | def hybrid_forward(self, F, inputs, mem_value, mask=None, mem_mask=None): #pylint: disable=unused-argument
# pylint: disable=arguments-differ
"""Transformer Decoder Attention Cell.
Parameters
----------
inputs : Symbol or NDArray
Input sequence. Shape (batch_size, ... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
",",
"mem_value",
",",
"mask",
"=",
"None",
",",
"mem_mask",
"=",
"None",
")",
":",
"#pylint: disable=unused-argument",
"# pylint: disable=arguments-differ",
"outputs",
",",
"attention_in_outputs",
"=",... | Transformer Decoder Attention Cell.
Parameters
----------
inputs : Symbol or NDArray
Input sequence. Shape (batch_size, length, C_in)
mem_value : Symbol or NDArrays
Memory value, i.e. output of the encoder. Shape (batch_size, mem_length, C_in)
mask : Symb... | [
"Transformer",
"Decoder",
"Attention",
"Cell",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L778-L823 | train | Transformer Decoder Attention Cell. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | TransformerDecoder.init_state_from_encoder | def init_state_from_encoder(self, encoder_outputs, encoder_valid_length=None):
"""Initialize the state from the encoder outputs.
Parameters
----------
encoder_outputs : list
encoder_valid_length : NDArray or None
Returns
-------
decoder_states : list
... | python | def init_state_from_encoder(self, encoder_outputs, encoder_valid_length=None):
"""Initialize the state from the encoder outputs.
Parameters
----------
encoder_outputs : list
encoder_valid_length : NDArray or None
Returns
-------
decoder_states : list
... | [
"def",
"init_state_from_encoder",
"(",
"self",
",",
"encoder_outputs",
",",
"encoder_valid_length",
"=",
"None",
")",
":",
"mem_value",
"=",
"encoder_outputs",
"decoder_states",
"=",
"[",
"mem_value",
"]",
"mem_length",
"=",
"mem_value",
".",
"shape",
"[",
"1",
... | Initialize the state from the encoder outputs.
Parameters
----------
encoder_outputs : list
encoder_valid_length : NDArray or None
Returns
-------
decoder_states : list
The decoder states, includes:
- mem_value : NDArray
- me... | [
"Initialize",
"the",
"state",
"from",
"the",
"encoder",
"outputs",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L905-L932 | train | Initialize the state from the encoder outputs. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | TransformerDecoder.decode_seq | def decode_seq(self, inputs, states, valid_length=None):
"""Decode the decoder inputs. This function is only used for training.
Parameters
----------
inputs : NDArray, Shape (batch_size, length, C_in)
states : list of NDArrays or None
Initial states. The list of deco... | python | def decode_seq(self, inputs, states, valid_length=None):
"""Decode the decoder inputs. This function is only used for training.
Parameters
----------
inputs : NDArray, Shape (batch_size, length, C_in)
states : list of NDArrays or None
Initial states. The list of deco... | [
"def",
"decode_seq",
"(",
"self",
",",
"inputs",
",",
"states",
",",
"valid_length",
"=",
"None",
")",
":",
"batch_size",
"=",
"inputs",
".",
"shape",
"[",
"0",
"]",
"length",
"=",
"inputs",
".",
"shape",
"[",
"1",
"]",
"length_array",
"=",
"mx",
"."... | Decode the decoder inputs. This function is only used for training.
Parameters
----------
inputs : NDArray, Shape (batch_size, length, C_in)
states : list of NDArrays or None
Initial states. The list of decoder states
valid_length : NDArray or None
Valid ... | [
"Decode",
"the",
"decoder",
"inputs",
".",
"This",
"function",
"is",
"only",
"used",
"for",
"training",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L934-L982 | train | Decode the inputs. This function is only used for training. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/model/transformer.py | ParallelTransformer.forward_backward | def forward_backward(self, x):
"""Perform forward and backward computation for a batch of src seq and dst seq"""
(src_seq, tgt_seq, src_valid_length, tgt_valid_length), batch_size = x
with mx.autograd.record():
out, _ = self._model(src_seq, tgt_seq[:, :-1],
... | python | def forward_backward(self, x):
"""Perform forward and backward computation for a batch of src seq and dst seq"""
(src_seq, tgt_seq, src_valid_length, tgt_valid_length), batch_size = x
with mx.autograd.record():
out, _ = self._model(src_seq, tgt_seq[:, :-1],
... | [
"def",
"forward_backward",
"(",
"self",
",",
"x",
")",
":",
"(",
"src_seq",
",",
"tgt_seq",
",",
"src_valid_length",
",",
"tgt_valid_length",
")",
",",
"batch_size",
"=",
"x",
"with",
"mx",
".",
"autograd",
".",
"record",
"(",
")",
":",
"out",
",",
"_"... | Perform forward and backward computation for a batch of src seq and dst seq | [
"Perform",
"forward",
"and",
"backward",
"computation",
"for",
"a",
"batch",
"of",
"src",
"seq",
"and",
"dst",
"seq"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/transformer.py#L1274-L1284 | train | Perform forward and backward computation for a batch of src seq and dst seq | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/natural_language_inference/main.py | parse_args | def parse_args():
"""
Parse arguments.
"""
parser = argparse.ArgumentParser()
parser.add_argument('--gpu-id', type=int, default=0,
help='GPU id (-1 means CPU)')
parser.add_argument('--train-file', default='snli_1.0/snli_1.0_train.txt',
help='traini... | python | def parse_args():
"""
Parse arguments.
"""
parser = argparse.ArgumentParser()
parser.add_argument('--gpu-id', type=int, default=0,
help='GPU id (-1 means CPU)')
parser.add_argument('--train-file', default='snli_1.0/snli_1.0_train.txt',
help='traini... | [
"def",
"parse_args",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'--gpu-id'",
",",
"type",
"=",
"int",
",",
"default",
"=",
"0",
",",
"help",
"=",
"'GPU id (-1 means CPU)'",
")",
"parser",... | Parse arguments. | [
"Parse",
"arguments",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/natural_language_inference/main.py#L53-L97 | train | Parse command line arguments. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/natural_language_inference/main.py | train_model | def train_model(model, train_data_loader, val_data_loader, embedding, ctx, args):
"""
Train model and validate/save every epoch.
"""
logger.info(vars(args))
# Initialization
model.hybridize()
model.collect_params().initialize(mx.init.Normal(0.01), ctx=ctx)
model.word_emb.weight.set_data... | python | def train_model(model, train_data_loader, val_data_loader, embedding, ctx, args):
"""
Train model and validate/save every epoch.
"""
logger.info(vars(args))
# Initialization
model.hybridize()
model.collect_params().initialize(mx.init.Normal(0.01), ctx=ctx)
model.word_emb.weight.set_data... | [
"def",
"train_model",
"(",
"model",
",",
"train_data_loader",
",",
"val_data_loader",
",",
"embedding",
",",
"ctx",
",",
"args",
")",
":",
"logger",
".",
"info",
"(",
"vars",
"(",
"args",
")",
")",
"# Initialization",
"model",
".",
"hybridize",
"(",
")",
... | Train model and validate/save every epoch. | [
"Train",
"model",
"and",
"validate",
"/",
"save",
"every",
"epoch",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/natural_language_inference/main.py#L99-L163 | train | Train a model on the data and validate every epoch. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | scripts/natural_language_inference/main.py | main | def main(args):
"""
Entry point: train or test.
"""
json.dump(vars(args), open(os.path.join(args.output_dir, 'config.json'), 'w'))
if args.gpu_id == -1:
ctx = mx.cpu()
else:
ctx = mx.gpu(args.gpu_id)
mx.random.seed(args.seed, ctx=ctx)
if args.mode == 'train':
t... | python | def main(args):
"""
Entry point: train or test.
"""
json.dump(vars(args), open(os.path.join(args.output_dir, 'config.json'), 'w'))
if args.gpu_id == -1:
ctx = mx.cpu()
else:
ctx = mx.gpu(args.gpu_id)
mx.random.seed(args.seed, ctx=ctx)
if args.mode == 'train':
t... | [
"def",
"main",
"(",
"args",
")",
":",
"json",
".",
"dump",
"(",
"vars",
"(",
"args",
")",
",",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"args",
".",
"output_dir",
",",
"'config.json'",
")",
",",
"'w'",
")",
")",
"if",
"args",
".",
"gpu... | Entry point: train or test. | [
"Entry",
"point",
":",
"train",
"or",
"test",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/natural_language_inference/main.py#L184-L231 | train | Entry point for NLI training or test. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
dmlc/gluon-nlp | src/gluonnlp/data/candidate_sampler.py | UnigramCandidateSampler.hybrid_forward | def hybrid_forward(self, F, candidates_like, prob, alias):
# pylint: disable=unused-argument
"""Draw samples from uniform distribution and return sampled candidates.
Parameters
----------
candidates_like: mxnet.nd.NDArray or mxnet.sym.Symbol
This input specifies the ... | python | def hybrid_forward(self, F, candidates_like, prob, alias):
# pylint: disable=unused-argument
"""Draw samples from uniform distribution and return sampled candidates.
Parameters
----------
candidates_like: mxnet.nd.NDArray or mxnet.sym.Symbol
This input specifies the ... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"candidates_like",
",",
"prob",
",",
"alias",
")",
":",
"# pylint: disable=unused-argument",
"flat_shape",
"=",
"functools",
".",
"reduce",
"(",
"operator",
".",
"mul",
",",
"self",
".",
"_shape",
")",
"id... | Draw samples from uniform distribution and return sampled candidates.
Parameters
----------
candidates_like: mxnet.nd.NDArray or mxnet.sym.Symbol
This input specifies the shape of the to be sampled candidates. #
TODO shape selection is not yet supported. Shape must be sp... | [
"Draw",
"samples",
"from",
"uniform",
"distribution",
"and",
"return",
"sampled",
"candidates",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/candidate_sampler.py#L105-L134 | train | Draw samples from uniform distribution and return sampled candidates. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.add | def add(
self,
sink,
*,
level=_defaults.LOGURU_LEVEL,
format=_defaults.LOGURU_FORMAT,
filter=_defaults.LOGURU_FILTER,
colorize=_defaults.LOGURU_COLORIZE,
serialize=_defaults.LOGURU_SERIALIZE,
backtrace=_defaults.LOGURU_BACKTRACE,
diagnose=_... | python | def add(
self,
sink,
*,
level=_defaults.LOGURU_LEVEL,
format=_defaults.LOGURU_FORMAT,
filter=_defaults.LOGURU_FILTER,
colorize=_defaults.LOGURU_COLORIZE,
serialize=_defaults.LOGURU_SERIALIZE,
backtrace=_defaults.LOGURU_BACKTRACE,
diagnose=_... | [
"def",
"add",
"(",
"self",
",",
"sink",
",",
"*",
",",
"level",
"=",
"_defaults",
".",
"LOGURU_LEVEL",
",",
"format",
"=",
"_defaults",
".",
"LOGURU_FORMAT",
",",
"filter",
"=",
"_defaults",
".",
"LOGURU_FILTER",
",",
"colorize",
"=",
"_defaults",
".",
"... | r"""Add a handler sending log messages to a sink adequately configured.
Parameters
----------
sink : |file-like object|_, |str|, |Path|, |function|_, |Handler| or |class|_
An object in charge of receiving formatted logging messages and propagating them to an
appropriate ... | [
"r",
"Add",
"a",
"handler",
"sending",
"log",
"messages",
"to",
"a",
"sink",
"adequately",
"configured",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L166-L843 | train | r Add a handler sending log messages to an anonymized endpoint. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.remove | def remove(self, handler_id=None):
"""Remove a previously added handler and stop sending logs to its sink.
Parameters
----------
handler_id : |int| or ``None``
The id of the sink to remove, as it was returned by the |add| method. If ``None``, all
handlers are rem... | python | def remove(self, handler_id=None):
"""Remove a previously added handler and stop sending logs to its sink.
Parameters
----------
handler_id : |int| or ``None``
The id of the sink to remove, as it was returned by the |add| method. If ``None``, all
handlers are rem... | [
"def",
"remove",
"(",
"self",
",",
"handler_id",
"=",
"None",
")",
":",
"with",
"self",
".",
"_lock",
":",
"handlers",
"=",
"self",
".",
"_handlers",
".",
"copy",
"(",
")",
"if",
"handler_id",
"is",
"None",
":",
"for",
"handler",
"in",
"handlers",
".... | Remove a previously added handler and stop sending logs to its sink.
Parameters
----------
handler_id : |int| or ``None``
The id of the sink to remove, as it was returned by the |add| method. If ``None``, all
handlers are removed. The pre-configured handler is guaranteed... | [
"Remove",
"a",
"previously",
"added",
"handler",
"and",
"stop",
"sending",
"logs",
"to",
"its",
"sink",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L845-L883 | train | Remove a previously added handler and stop sending logs to its sink. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.catch | def catch(
self,
exception=Exception,
*,
level="ERROR",
reraise=False,
message="An error has been caught in function '{record[function]}', "
"process '{record[process].name}' ({record[process].id}), "
"thread '{record[thread].name}' ({record[thread].id}):"... | python | def catch(
self,
exception=Exception,
*,
level="ERROR",
reraise=False,
message="An error has been caught in function '{record[function]}', "
"process '{record[process].name}' ({record[process].id}), "
"thread '{record[thread].name}' ({record[thread].id}):"... | [
"def",
"catch",
"(",
"self",
",",
"exception",
"=",
"Exception",
",",
"*",
",",
"level",
"=",
"\"ERROR\"",
",",
"reraise",
"=",
"False",
",",
"message",
"=",
"\"An error has been caught in function '{record[function]}', \"",
"\"process '{record[process].name}' ({record[pr... | Return a decorator to automatically log possibly caught error in wrapped function.
This is useful to ensure unexpected exceptions are logged, the entire program can be
wrapped by this method. This is also very useful to decorate |Thread.run| methods while
using threads to propagate errors to th... | [
"Return",
"a",
"decorator",
"to",
"automatically",
"log",
"possibly",
"caught",
"error",
"in",
"wrapped",
"function",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L885-L1011 | train | This is a non - recursive function that wraps a function and returns a context manager that logs unexpected exceptions. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.opt | def opt(self, *, exception=None, record=False, lazy=False, ansi=False, raw=False, depth=0):
r"""Parametrize a logging call to slightly change generated log message.
Parameters
----------
exception : |bool|, |tuple| or |Exception|, optional
If it does not evaluate as ``False`... | python | def opt(self, *, exception=None, record=False, lazy=False, ansi=False, raw=False, depth=0):
r"""Parametrize a logging call to slightly change generated log message.
Parameters
----------
exception : |bool|, |tuple| or |Exception|, optional
If it does not evaluate as ``False`... | [
"def",
"opt",
"(",
"self",
",",
"*",
",",
"exception",
"=",
"None",
",",
"record",
"=",
"False",
",",
"lazy",
"=",
"False",
",",
"ansi",
"=",
"False",
",",
"raw",
"=",
"False",
",",
"depth",
"=",
"0",
")",
":",
"return",
"Logger",
"(",
"self",
... | r"""Parametrize a logging call to slightly change generated log message.
Parameters
----------
exception : |bool|, |tuple| or |Exception|, optional
If it does not evaluate as ``False``, the passed exception is formatted and added to the
log message. It could be an |Excep... | [
"r",
"Parametrize",
"a",
"logging",
"call",
"to",
"slightly",
"change",
"generated",
"log",
"message",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L1013-L1079 | train | A function to parameterize a logging call to slightly change generated log message. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.bind | def bind(_self, **kwargs):
"""Bind attributes to the ``extra`` dict of each logged message record.
This is used to add custom context to each logging call.
Parameters
----------
**kwargs
Mapping between keys and values that will be added to the ``extra`` dict.
... | python | def bind(_self, **kwargs):
"""Bind attributes to the ``extra`` dict of each logged message record.
This is used to add custom context to each logging call.
Parameters
----------
**kwargs
Mapping between keys and values that will be added to the ``extra`` dict.
... | [
"def",
"bind",
"(",
"_self",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"Logger",
"(",
"{",
"*",
"*",
"_self",
".",
"_extra",
",",
"*",
"*",
"kwargs",
"}",
",",
"_self",
".",
"_exception",
",",
"_self",
".",
"_record",
",",
"_self",
".",
"_lazy... | Bind attributes to the ``extra`` dict of each logged message record.
This is used to add custom context to each logging call.
Parameters
----------
**kwargs
Mapping between keys and values that will be added to the ``extra`` dict.
Returns
-------
:c... | [
"Bind",
"attributes",
"to",
"the",
"extra",
"dict",
"of",
"each",
"logged",
"message",
"record",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L1081-L1123 | train | Create a new Logger that will log each logged message record. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.level | def level(self, name, no=None, color=None, icon=None):
"""Add, update or retrieve a logging level.
Logging levels are defined by their ``name`` to which a severity ``no``, an ansi ``color``
and an ``icon`` are associated and possibly modified at run-time. To |log| to a custom
level, you... | python | def level(self, name, no=None, color=None, icon=None):
"""Add, update or retrieve a logging level.
Logging levels are defined by their ``name`` to which a severity ``no``, an ansi ``color``
and an ``icon`` are associated and possibly modified at run-time. To |log| to a custom
level, you... | [
"def",
"level",
"(",
"self",
",",
"name",
",",
"no",
"=",
"None",
",",
"color",
"=",
"None",
",",
"icon",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"name",
",",
"str",
")",
":",
"raise",
"ValueError",
"(",
"\"Invalid level name, it should ... | Add, update or retrieve a logging level.
Logging levels are defined by their ``name`` to which a severity ``no``, an ansi ``color``
and an ``icon`` are associated and possibly modified at run-time. To |log| to a custom
level, you should necessarily use its name, the severity number is not linke... | [
"Add",
"update",
"or",
"retrieve",
"a",
"logging",
"level",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L1125-L1212 | train | Add or update or retrieve a logging level. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.configure | def configure(self, *, handlers=None, levels=None, extra=None, activation=None):
"""Configure the core logger.
It should be noted that ``extra`` values set using this function are available across all
modules, so this is the best way to set overall default values.
Parameters
--... | python | def configure(self, *, handlers=None, levels=None, extra=None, activation=None):
"""Configure the core logger.
It should be noted that ``extra`` values set using this function are available across all
modules, so this is the best way to set overall default values.
Parameters
--... | [
"def",
"configure",
"(",
"self",
",",
"*",
",",
"handlers",
"=",
"None",
",",
"levels",
"=",
"None",
",",
"extra",
"=",
"None",
",",
"activation",
"=",
"None",
")",
":",
"if",
"handlers",
"is",
"not",
"None",
":",
"self",
".",
"remove",
"(",
")",
... | Configure the core logger.
It should be noted that ``extra`` values set using this function are available across all
modules, so this is the best way to set overall default values.
Parameters
----------
handlers : |list| of |dict|, optional
A list of each handler to... | [
"Configure",
"the",
"core",
"logger",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L1255-L1330 | train | Configure the core logger. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.parse | def parse(file, pattern, *, cast={}, chunk=2 ** 16):
"""
Parse raw logs and extract each entry as a |dict|.
The logging format has to be specified as the regex ``pattern``, it will then be
used to parse the ``file`` and retrieve each entries based on the named groups present
in ... | python | def parse(file, pattern, *, cast={}, chunk=2 ** 16):
"""
Parse raw logs and extract each entry as a |dict|.
The logging format has to be specified as the regex ``pattern``, it will then be
used to parse the ``file`` and retrieve each entries based on the named groups present
in ... | [
"def",
"parse",
"(",
"file",
",",
"pattern",
",",
"*",
",",
"cast",
"=",
"{",
"}",
",",
"chunk",
"=",
"2",
"**",
"16",
")",
":",
"if",
"isinstance",
"(",
"file",
",",
"(",
"str",
",",
"PathLike",
")",
")",
":",
"should_close",
"=",
"True",
"fil... | Parse raw logs and extract each entry as a |dict|.
The logging format has to be specified as the regex ``pattern``, it will then be
used to parse the ``file`` and retrieve each entries based on the named groups present
in the regex.
Parameters
----------
file : |str|, |... | [
"Parse",
"raw",
"logs",
"and",
"extract",
"each",
"entry",
"as",
"a",
"|dict|",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L1359-L1450 | train | Parse the log file and extract each entry as a |dict|. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.log | def log(_self, _level, _message, *args, **kwargs):
r"""Log ``_message.format(*args, **kwargs)`` with severity ``_level``."""
logger = _self.opt(
exception=_self._exception,
record=_self._record,
lazy=_self._lazy,
ansi=_self._ansi,
raw=_self._ra... | python | def log(_self, _level, _message, *args, **kwargs):
r"""Log ``_message.format(*args, **kwargs)`` with severity ``_level``."""
logger = _self.opt(
exception=_self._exception,
record=_self._record,
lazy=_self._lazy,
ansi=_self._ansi,
raw=_self._ra... | [
"def",
"log",
"(",
"_self",
",",
"_level",
",",
"_message",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"logger",
"=",
"_self",
".",
"opt",
"(",
"exception",
"=",
"_self",
".",
"_exception",
",",
"record",
"=",
"_self",
".",
"_record",
","... | r"""Log ``_message.format(*args, **kwargs)`` with severity ``_level``. | [
"r",
"Log",
"_message",
".",
"format",
"(",
"*",
"args",
"**",
"kwargs",
")",
"with",
"severity",
"_level",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L1600-L1610 | train | r Log a message with severity _level. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.start | def start(self, *args, **kwargs):
"""Deprecated function to |add| a new handler.
Warnings
--------
.. deprecated:: 0.2.2
``start()`` will be removed in Loguru 1.0.0, it is replaced by ``add()`` which is a less
confusing name.
"""
warnings.warn(
... | python | def start(self, *args, **kwargs):
"""Deprecated function to |add| a new handler.
Warnings
--------
.. deprecated:: 0.2.2
``start()`` will be removed in Loguru 1.0.0, it is replaced by ``add()`` which is a less
confusing name.
"""
warnings.warn(
... | [
"def",
"start",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"warnings",
".",
"warn",
"(",
"\"The 'start()' method is deprecated, please use 'add()' instead\"",
",",
"DeprecationWarning",
")",
"return",
"self",
".",
"add",
"(",
"*",
"args",
... | Deprecated function to |add| a new handler.
Warnings
--------
.. deprecated:: 0.2.2
``start()`` will be removed in Loguru 1.0.0, it is replaced by ``add()`` which is a less
confusing name. | [
"Deprecated",
"function",
"to",
"|add|",
"a",
"new",
"handler",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L1624-L1636 | train | Deprecated function to add a new handler. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Delgan/loguru | loguru/_logger.py | Logger.stop | def stop(self, *args, **kwargs):
"""Deprecated function to |remove| an existing handler.
Warnings
--------
.. deprecated:: 0.2.2
``stop()`` will be removed in Loguru 1.0.0, it is replaced by ``remove()`` which is a less
confusing name.
"""
warnings.wa... | python | def stop(self, *args, **kwargs):
"""Deprecated function to |remove| an existing handler.
Warnings
--------
.. deprecated:: 0.2.2
``stop()`` will be removed in Loguru 1.0.0, it is replaced by ``remove()`` which is a less
confusing name.
"""
warnings.wa... | [
"def",
"stop",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"warnings",
".",
"warn",
"(",
"\"The 'stop()' method is deprecated, please use 'remove()' instead\"",
",",
"DeprecationWarning",
")",
"return",
"self",
".",
"remove",
"(",
"*",
"arg... | Deprecated function to |remove| an existing handler.
Warnings
--------
.. deprecated:: 0.2.2
``stop()`` will be removed in Loguru 1.0.0, it is replaced by ``remove()`` which is a less
confusing name. | [
"Deprecated",
"function",
"to",
"|remove|",
"an",
"existing",
"handler",
"."
] | 6571879c37904e3a18567e694d70651c6886b860 | https://github.com/Delgan/loguru/blob/6571879c37904e3a18567e694d70651c6886b860/loguru/_logger.py#L1638-L1650 | train | Deprecated function to remove an existing handler. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
graphql-python/graphene-django | graphene_django/settings.py | perform_import | def perform_import(val, setting_name):
"""
If the given setting is a string import notation,
then perform the necessary import or imports.
"""
if val is None:
return None
elif isinstance(val, six.string_types):
return import_from_string(val, setting_name)
elif isinstance(val,... | python | def perform_import(val, setting_name):
"""
If the given setting is a string import notation,
then perform the necessary import or imports.
"""
if val is None:
return None
elif isinstance(val, six.string_types):
return import_from_string(val, setting_name)
elif isinstance(val,... | [
"def",
"perform_import",
"(",
"val",
",",
"setting_name",
")",
":",
"if",
"val",
"is",
"None",
":",
"return",
"None",
"elif",
"isinstance",
"(",
"val",
",",
"six",
".",
"string_types",
")",
":",
"return",
"import_from_string",
"(",
"val",
",",
"setting_nam... | If the given setting is a string import notation,
then perform the necessary import or imports. | [
"If",
"the",
"given",
"setting",
"is",
"a",
"string",
"import",
"notation",
"then",
"perform",
"the",
"necessary",
"import",
"or",
"imports",
"."
] | 20160113948b4167b61dbdaa477bb301227aac2e | https://github.com/graphql-python/graphene-django/blob/20160113948b4167b61dbdaa477bb301227aac2e/graphene_django/settings.py#L47-L58 | train | Perform a necessary import or imports. | Pu7Z6IJCgH3a,vcEHXBQXuDuh,sHOWSIAKtU58,ZVWAAMjVVHHl,qRin5pdYOdbB,IySsVMyKT3tF,FwEHNICjJCy0,yISIa0MMKKfB,GAtvbI59wr0o,OmNM6rT0Sgul,gu1MSKhYvigU,S2TTo9DhhiSh,aaLV7ZjAfkcR,ker4pIJmdvxf,WaQEaQCVMQ03,xV97BFGi0hY9,YnM1HtHE4j7G,X5FyJb4ToTo6,jLmadlzMdunT,GGFwFLsDF9Fv,prtR0Uw1GMh5,oNamnshN4dFG,QZzQeAYvsoum,VHAt7CcYKC2T,cKsTbNGL... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.