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/model/train/cache.py | CacheCell.forward | def forward(self, inputs, target, next_word_history, cache_history, begin_state=None): # pylint: disable=arguments-differ
"""Defines the forward computation for cache cell. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`.
Parameters
----------
inputs: NDArray
... | python | def forward(self, inputs, target, next_word_history, cache_history, begin_state=None): # pylint: disable=arguments-differ
"""Defines the forward computation for cache cell. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`.
Parameters
----------
inputs: NDArray
... | [
"def",
"forward",
"(",
"self",
",",
"inputs",
",",
"target",
",",
"next_word_history",
",",
"cache_history",
",",
"begin_state",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"output",
",",
"hidden",
",",
"encoder_hs",
",",
"_",
"=",
"super",
"(... | Defines the forward computation for cache cell. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`.
Parameters
----------
inputs: NDArray
The input data
target: NDArray
The label
next_word_history: NDArray
The next word ... | [
"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/train/cache.py#L100-L161 | 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 | src/gluonnlp/utils/parallel.py | Parallel.put | def put(self, x):
"""Assign input `x` to an available worker and invoke
`parallizable.forward_backward` with x. """
if self._num_serial > 0 or len(self._threads) == 0:
self._num_serial -= 1
out = self._parallizable.forward_backward(x)
self._out_queue.put(out)
... | python | def put(self, x):
"""Assign input `x` to an available worker and invoke
`parallizable.forward_backward` with x. """
if self._num_serial > 0 or len(self._threads) == 0:
self._num_serial -= 1
out = self._parallizable.forward_backward(x)
self._out_queue.put(out)
... | [
"def",
"put",
"(",
"self",
",",
"x",
")",
":",
"if",
"self",
".",
"_num_serial",
">",
"0",
"or",
"len",
"(",
"self",
".",
"_threads",
")",
"==",
"0",
":",
"self",
".",
"_num_serial",
"-=",
"1",
"out",
"=",
"self",
".",
"_parallizable",
".",
"forw... | Assign input `x` to an available worker and invoke
`parallizable.forward_backward` with x. | [
"Assign",
"input",
"x",
"to",
"an",
"available",
"worker",
"and",
"invoke",
"parallizable",
".",
"forward_backward",
"with",
"x",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/utils/parallel.py#L130-L138 | train | Assign input x to an available worker and invoke
Taxonomy. forward_backward with x. | 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/vocab/bert.py | BERTVocab.from_json | def from_json(cls, json_str):
"""Deserialize BERTVocab object from json string.
Parameters
----------
json_str : str
Serialized json string of a BERTVocab object.
Returns
-------
BERTVocab
"""
vocab_dict = json.loads(json_str)
... | python | def from_json(cls, json_str):
"""Deserialize BERTVocab object from json string.
Parameters
----------
json_str : str
Serialized json string of a BERTVocab object.
Returns
-------
BERTVocab
"""
vocab_dict = json.loads(json_str)
... | [
"def",
"from_json",
"(",
"cls",
",",
"json_str",
")",
":",
"vocab_dict",
"=",
"json",
".",
"loads",
"(",
"json_str",
")",
"unknown_token",
"=",
"vocab_dict",
".",
"get",
"(",
"'unknown_token'",
")",
"bert_vocab",
"=",
"cls",
"(",
"unknown_token",
"=",
"unk... | Deserialize BERTVocab object from json string.
Parameters
----------
json_str : str
Serialized json string of a BERTVocab object.
Returns
-------
BERTVocab | [
"Deserialize",
"BERTVocab",
"object",
"from",
"json",
"string",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/vocab/bert.py#L174-L203 | train | Deserialize a BERTVocab object from a json 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/model/train/language_model.py | StandardRNN.forward | def forward(self, inputs, begin_state=None): # pylint: disable=arguments-differ
"""Defines the forward computation. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, b... | python | def forward(self, inputs, begin_state=None): # pylint: disable=arguments-differ
"""Defines the forward computation. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, b... | [
"def",
"forward",
"(",
"self",
",",
"inputs",
",",
"begin_state",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"encoded",
"=",
"self",
".",
"embedding",
"(",
"inputs",
")",
"if",
"not",
"begin_state",
":",
"begin_state",
"=",
"self",
".",
"be... | Defines the forward computation. Arguments can be either
:py:class:`NDArray` or :py:class:`Symbol`.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
begin_state : list
init... | [
"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/train/language_model.py#L238-L276 | train | Defines the forward computation. | 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/language_model.py | BigRNN.forward | def forward(self, inputs, label, begin_state, sampled_values): # pylint: disable=arguments-differ
"""Defines the forward computation.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
b... | python | def forward(self, inputs, label, begin_state, sampled_values): # pylint: disable=arguments-differ
"""Defines the forward computation.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
b... | [
"def",
"forward",
"(",
"self",
",",
"inputs",
",",
"label",
",",
"begin_state",
",",
"sampled_values",
")",
":",
"# pylint: disable=arguments-differ",
"encoded",
"=",
"self",
".",
"embedding",
"(",
"inputs",
")",
"length",
"=",
"inputs",
".",
"shape",
"[",
"... | Defines the forward computation.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
begin_state : list
initial recurrent state tensor with length equals to num_layers*2.
... | [
"Defines",
"the",
"forward",
"computation",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/train/language_model.py#L389-L427 | train | Defines the forward computation. | 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/model.py | SG.hybrid_forward | def hybrid_forward(self, F, center, context, center_words):
"""SkipGram forward pass.
Parameters
----------
center : mxnet.nd.NDArray or mxnet.sym.Symbol
Sparse CSR array of word / subword indices of shape (batch_size,
len(token_to_idx) + num_subwords). Embedding... | python | def hybrid_forward(self, F, center, context, center_words):
"""SkipGram forward pass.
Parameters
----------
center : mxnet.nd.NDArray or mxnet.sym.Symbol
Sparse CSR array of word / subword indices of shape (batch_size,
len(token_to_idx) + num_subwords). Embedding... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"center",
",",
"context",
",",
"center_words",
")",
":",
"# negatives sampling",
"negatives",
"=",
"[",
"]",
"mask",
"=",
"[",
"]",
"for",
"_",
"in",
"range",
"(",
"self",
".",
"_kwargs",
"[",
"'num_... | SkipGram forward pass.
Parameters
----------
center : mxnet.nd.NDArray or mxnet.sym.Symbol
Sparse CSR array of word / subword indices of shape (batch_size,
len(token_to_idx) + num_subwords). Embedding for center words are
computed via F.sparse.dot between the... | [
"SkipGram",
"forward",
"pass",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/word_embeddings/model.py#L101-L149 | train | Skip Gram forward pass. | 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/sentiment_analysis/finetune_lm.py | evaluate | def evaluate(dataloader):
"""Evaluate network on the specified dataset"""
total_L = 0.0
total_sample_num = 0
total_correct_num = 0
start_log_interval_time = time.time()
print('Begin Testing...')
for i, ((data, valid_length), label) in enumerate(dataloader):
data = mx.nd.transpose(dat... | python | def evaluate(dataloader):
"""Evaluate network on the specified dataset"""
total_L = 0.0
total_sample_num = 0
total_correct_num = 0
start_log_interval_time = time.time()
print('Begin Testing...')
for i, ((data, valid_length), label) in enumerate(dataloader):
data = mx.nd.transpose(dat... | [
"def",
"evaluate",
"(",
"dataloader",
")",
":",
"total_L",
"=",
"0.0",
"total_sample_num",
"=",
"0",
"total_correct_num",
"=",
"0",
"start_log_interval_time",
"=",
"time",
".",
"time",
"(",
")",
"print",
"(",
"'Begin Testing...'",
")",
"for",
"i",
",",
"(",
... | Evaluate network on the specified dataset | [
"Evaluate",
"network",
"on",
"the",
"specified",
"dataset"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/sentiment_analysis/finetune_lm.py#L237-L260 | train | Evaluate network on the specified 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/sentiment_analysis/finetune_lm.py | train | def train():
"""Training process"""
start_pipeline_time = time.time()
# Training/Testing
best_valid_acc = 0
stop_early = 0
for epoch in range(args.epochs):
# Epoch training stats
start_epoch_time = time.time()
epoch_L = 0.0
epoch_sent_num = 0
epoch_wc = 0... | python | def train():
"""Training process"""
start_pipeline_time = time.time()
# Training/Testing
best_valid_acc = 0
stop_early = 0
for epoch in range(args.epochs):
# Epoch training stats
start_epoch_time = time.time()
epoch_L = 0.0
epoch_sent_num = 0
epoch_wc = 0... | [
"def",
"train",
"(",
")",
":",
"start_pipeline_time",
"=",
"time",
".",
"time",
"(",
")",
"# Training/Testing",
"best_valid_acc",
"=",
"0",
"stop_early",
"=",
"0",
"for",
"epoch",
"in",
"range",
"(",
"args",
".",
"epochs",
")",
":",
"# Epoch training stats",... | Training process | [
"Training",
"process"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/sentiment_analysis/finetune_lm.py#L263-L340 | train | Train the node in the pipeline. | 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/sentiment_analysis/finetune_lm.py | AggregationLayer.hybrid_forward | def hybrid_forward(self, F, data, valid_length): # pylint: disable=arguments-differ
"""Forward logic"""
# Data will have shape (T, N, C)
if self._use_mean_pool:
masked_encoded = F.SequenceMask(data,
sequence_length=valid_length,
... | python | def hybrid_forward(self, F, data, valid_length): # pylint: disable=arguments-differ
"""Forward logic"""
# Data will have shape (T, N, C)
if self._use_mean_pool:
masked_encoded = F.SequenceMask(data,
sequence_length=valid_length,
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"data",
",",
"valid_length",
")",
":",
"# pylint: disable=arguments-differ",
"# Data will have shape (T, N, C)",
"if",
"self",
".",
"_use_mean_pool",
":",
"masked_encoded",
"=",
"F",
".",
"SequenceMask",
"(",
"dat... | Forward logic | [
"Forward",
"logic"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/sentiment_analysis/finetune_lm.py#L105-L118 | train | Forward logic for the base class. | 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/lstmpcellwithclip.py | LSTMPCellWithClip.hybrid_forward | def hybrid_forward(self, F, inputs, states, i2h_weight,
h2h_weight, h2r_weight, i2h_bias, h2h_bias):
r"""Hybrid forward computation for Long-Short Term Memory Projected network cell
with cell clip and projection clip.
Parameters
----------
inputs : input t... | python | def hybrid_forward(self, F, inputs, states, i2h_weight,
h2h_weight, h2r_weight, i2h_bias, h2h_bias):
r"""Hybrid forward computation for Long-Short Term Memory Projected network cell
with cell clip and projection clip.
Parameters
----------
inputs : input t... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
",",
"states",
",",
"i2h_weight",
",",
"h2h_weight",
",",
"h2r_weight",
",",
"i2h_bias",
",",
"h2h_bias",
")",
":",
"prefix",
"=",
"'t%d_'",
"%",
"self",
".",
"_counter",
"i2h",
"=",
"F",
"... | r"""Hybrid forward computation for Long-Short Term Memory Projected network cell
with cell clip and projection clip.
Parameters
----------
inputs : input tensor with shape `(batch_size, input_size)`.
states : a list of two initial recurrent state tensors, with shape
... | [
"r",
"Hybrid",
"forward",
"computation",
"for",
"Long",
"-",
"Short",
"Term",
"Memory",
"Projected",
"network",
"cell",
"with",
"cell",
"clip",
"and",
"projection",
"clip",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/lstmpcellwithclip.py#L100-L139 | train | r Hybrid forward computation for Long - Short Term Memory Projected network 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/utils/parameter.py | clip_grad_global_norm | def clip_grad_global_norm(parameters, max_norm, check_isfinite=True):
"""Rescales gradients of parameters so that the sum of their 2-norm is smaller than `max_norm`.
If gradients exist for more than one context for a parameter, user needs to explicitly call
``trainer.allreduce_grads`` so that the gradients ... | python | def clip_grad_global_norm(parameters, max_norm, check_isfinite=True):
"""Rescales gradients of parameters so that the sum of their 2-norm is smaller than `max_norm`.
If gradients exist for more than one context for a parameter, user needs to explicitly call
``trainer.allreduce_grads`` so that the gradients ... | [
"def",
"clip_grad_global_norm",
"(",
"parameters",
",",
"max_norm",
",",
"check_isfinite",
"=",
"True",
")",
":",
"def",
"_norm",
"(",
"array",
")",
":",
"if",
"array",
".",
"stype",
"==",
"'default'",
":",
"x",
"=",
"array",
".",
"reshape",
"(",
"(",
... | Rescales gradients of parameters so that the sum of their 2-norm is smaller than `max_norm`.
If gradients exist for more than one context for a parameter, user needs to explicitly call
``trainer.allreduce_grads`` so that the gradients are summed first before calculating
the 2-norm.
.. note::
T... | [
"Rescales",
"gradients",
"of",
"parameters",
"so",
"that",
"the",
"sum",
"of",
"their",
"2",
"-",
"norm",
"is",
"smaller",
"than",
"max_norm",
".",
"If",
"gradients",
"exist",
"for",
"more",
"than",
"one",
"context",
"for",
"a",
"parameter",
"user",
"needs... | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/utils/parameter.py#L28-L97 | train | Clip gradients of parameters so that the sum of their 2 - norm is smaller than max_norm. | 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/run_pretraining.py | train | def train(data_train, model, nsp_loss, mlm_loss, vocab_size, ctx, store):
"""Training function."""
mlm_metric = nlp.metric.MaskedAccuracy()
nsp_metric = nlp.metric.MaskedAccuracy()
mlm_metric.reset()
nsp_metric.reset()
lr = args.lr
optim_params = {'learning_rate': lr, 'epsilon': 1e-6, 'wd':... | python | def train(data_train, model, nsp_loss, mlm_loss, vocab_size, ctx, store):
"""Training function."""
mlm_metric = nlp.metric.MaskedAccuracy()
nsp_metric = nlp.metric.MaskedAccuracy()
mlm_metric.reset()
nsp_metric.reset()
lr = args.lr
optim_params = {'learning_rate': lr, 'epsilon': 1e-6, 'wd':... | [
"def",
"train",
"(",
"data_train",
",",
"model",
",",
"nsp_loss",
",",
"mlm_loss",
",",
"vocab_size",
",",
"ctx",
",",
"store",
")",
":",
"mlm_metric",
"=",
"nlp",
".",
"metric",
".",
"MaskedAccuracy",
"(",
")",
"nsp_metric",
"=",
"nlp",
".",
"metric",
... | Training function. | [
"Training",
"function",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/run_pretraining.py#L92-L215 | train | Train the model on the data_train and store the training context. | 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/run_pretraining.py | ParallelBERT.forward_backward | def forward_backward(self, x):
"""forward backward implementation"""
with mx.autograd.record():
(ls, next_sentence_label, classified, masked_id, decoded, \
masked_weight, ls1, ls2, valid_length) = forward(x, self._model, self._mlm_loss,
... | python | def forward_backward(self, x):
"""forward backward implementation"""
with mx.autograd.record():
(ls, next_sentence_label, classified, masked_id, decoded, \
masked_weight, ls1, ls2, valid_length) = forward(x, self._model, self._mlm_loss,
... | [
"def",
"forward_backward",
"(",
"self",
",",
"x",
")",
":",
"with",
"mx",
".",
"autograd",
".",
"record",
"(",
")",
":",
"(",
"ls",
",",
"next_sentence_label",
",",
"classified",
",",
"masked_id",
",",
"decoded",
",",
"masked_weight",
",",
"ls1",
",",
... | forward backward implementation | [
"forward",
"backward",
"implementation"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/run_pretraining.py#L77-L90 | train | forward backward implementation | 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/data.py | ParserVocabulary.log_info | def log_info(self, logger):
"""Print statistical information via the provided logger
Parameters
----------
logger : logging.Logger
logger created using logging.getLogger()
"""
logger.info('#words in training set: %d' % self._words_in_train_data)
logge... | python | def log_info(self, logger):
"""Print statistical information via the provided logger
Parameters
----------
logger : logging.Logger
logger created using logging.getLogger()
"""
logger.info('#words in training set: %d' % self._words_in_train_data)
logge... | [
"def",
"log_info",
"(",
"self",
",",
"logger",
")",
":",
"logger",
".",
"info",
"(",
"'#words in training set: %d'",
"%",
"self",
".",
"_words_in_train_data",
")",
"logger",
".",
"info",
"(",
"\"Vocab info: #words %d, #tags %d #rels %d\"",
"%",
"(",
"self",
".",
... | Print statistical information via the provided logger
Parameters
----------
logger : logging.Logger
logger created using logging.getLogger() | [
"Print",
"statistical",
"information",
"via",
"the",
"provided",
"logger"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L162-L171 | train | Print statistical information via the provided 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... |
dmlc/gluon-nlp | scripts/parsing/common/data.py | ParserVocabulary._add_pret_words | def _add_pret_words(self, pret_embeddings):
"""Read pre-trained embedding file for extending vocabulary
Parameters
----------
pret_embeddings : tuple
(embedding_name, source), used for gluonnlp.embedding.create(embedding_name, source)
"""
words_in_train_data ... | python | def _add_pret_words(self, pret_embeddings):
"""Read pre-trained embedding file for extending vocabulary
Parameters
----------
pret_embeddings : tuple
(embedding_name, source), used for gluonnlp.embedding.create(embedding_name, source)
"""
words_in_train_data ... | [
"def",
"_add_pret_words",
"(",
"self",
",",
"pret_embeddings",
")",
":",
"words_in_train_data",
"=",
"set",
"(",
"self",
".",
"_id2word",
")",
"pret_embeddings",
"=",
"gluonnlp",
".",
"embedding",
".",
"create",
"(",
"pret_embeddings",
"[",
"0",
"]",
",",
"s... | Read pre-trained embedding file for extending vocabulary
Parameters
----------
pret_embeddings : tuple
(embedding_name, source), used for gluonnlp.embedding.create(embedding_name, source) | [
"Read",
"pre",
"-",
"trained",
"embedding",
"file",
"for",
"extending",
"vocabulary"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L173-L186 | train | Read pre - trained embedding file for extending 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/parsing/common/data.py | ParserVocabulary.get_pret_embs | def get_pret_embs(self, word_dims=None):
"""Read pre-trained embedding file
Parameters
----------
word_dims : int or None
vector size. Use `None` for auto-infer
Returns
-------
numpy.ndarray
T x C numpy NDArray
"""
assert (... | python | def get_pret_embs(self, word_dims=None):
"""Read pre-trained embedding file
Parameters
----------
word_dims : int or None
vector size. Use `None` for auto-infer
Returns
-------
numpy.ndarray
T x C numpy NDArray
"""
assert (... | [
"def",
"get_pret_embs",
"(",
"self",
",",
"word_dims",
"=",
"None",
")",
":",
"assert",
"(",
"self",
".",
"_pret_embeddings",
"is",
"not",
"None",
")",
",",
"\"No pretrained file provided.\"",
"pret_embeddings",
"=",
"gluonnlp",
".",
"embedding",
".",
"create",
... | Read pre-trained embedding file
Parameters
----------
word_dims : int or None
vector size. Use `None` for auto-infer
Returns
-------
numpy.ndarray
T x C numpy NDArray | [
"Read",
"pre",
"-",
"trained",
"embedding",
"file"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L198-L221 | train | Read pre - trained embedding file and return the pre - trained embedding matrix. | 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/data.py | ParserVocabulary.get_word_embs | def get_word_embs(self, word_dims):
"""Get randomly initialized embeddings when pre-trained embeddings are used, otherwise zero vectors
Parameters
----------
word_dims : int
word vector size
Returns
-------
numpy.ndarray
T x C numpy NDArra... | python | def get_word_embs(self, word_dims):
"""Get randomly initialized embeddings when pre-trained embeddings are used, otherwise zero vectors
Parameters
----------
word_dims : int
word vector size
Returns
-------
numpy.ndarray
T x C numpy NDArra... | [
"def",
"get_word_embs",
"(",
"self",
",",
"word_dims",
")",
":",
"if",
"self",
".",
"_pret_embeddings",
"is",
"not",
"None",
":",
"return",
"np",
".",
"random",
".",
"randn",
"(",
"self",
".",
"words_in_train",
",",
"word_dims",
")",
".",
"astype",
"(",
... | Get randomly initialized embeddings when pre-trained embeddings are used, otherwise zero vectors
Parameters
----------
word_dims : int
word vector size
Returns
-------
numpy.ndarray
T x C numpy NDArray | [
"Get",
"randomly",
"initialized",
"embeddings",
"when",
"pre",
"-",
"trained",
"embeddings",
"are",
"used",
"otherwise",
"zero",
"vectors"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L223-L237 | train | Get randomly initialized embeddings when pre - trained embeddings are used otherwise zero vectors | 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/data.py | ParserVocabulary.get_tag_embs | def get_tag_embs(self, tag_dims):
"""Randomly initialize embeddings for tag
Parameters
----------
tag_dims : int
tag vector size
Returns
-------
numpy.ndarray
random embeddings
"""
return np.random.randn(self.tag_size, tag... | python | def get_tag_embs(self, tag_dims):
"""Randomly initialize embeddings for tag
Parameters
----------
tag_dims : int
tag vector size
Returns
-------
numpy.ndarray
random embeddings
"""
return np.random.randn(self.tag_size, tag... | [
"def",
"get_tag_embs",
"(",
"self",
",",
"tag_dims",
")",
":",
"return",
"np",
".",
"random",
".",
"randn",
"(",
"self",
".",
"tag_size",
",",
"tag_dims",
")",
".",
"astype",
"(",
"np",
".",
"float32",
")"
] | Randomly initialize embeddings for tag
Parameters
----------
tag_dims : int
tag vector size
Returns
-------
numpy.ndarray
random embeddings | [
"Randomly",
"initialize",
"embeddings",
"for",
"tag"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L239-L252 | train | Randomly initialize embeddings for tag
| 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/data.py | ParserVocabulary.word2id | def word2id(self, xs):
"""Map word(s) to its id(s)
Parameters
----------
xs : str or list
word or a list of words
Returns
-------
int or list
id or a list of ids
"""
if isinstance(xs, list):
return [self._word2... | python | def word2id(self, xs):
"""Map word(s) to its id(s)
Parameters
----------
xs : str or list
word or a list of words
Returns
-------
int or list
id or a list of ids
"""
if isinstance(xs, list):
return [self._word2... | [
"def",
"word2id",
"(",
"self",
",",
"xs",
")",
":",
"if",
"isinstance",
"(",
"xs",
",",
"list",
")",
":",
"return",
"[",
"self",
".",
"_word2id",
".",
"get",
"(",
"x",
",",
"self",
".",
"UNK",
")",
"for",
"x",
"in",
"xs",
"]",
"return",
"self",... | Map word(s) to its id(s)
Parameters
----------
xs : str or list
word or a list of words
Returns
-------
int or list
id or a list of ids | [
"Map",
"word",
"(",
"s",
")",
"to",
"its",
"id",
"(",
"s",
")"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L254-L269 | train | Map word to its id | 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/data.py | ParserVocabulary.id2word | def id2word(self, xs):
"""Map id(s) to word(s)
Parameters
----------
xs : int
id or a list of ids
Returns
-------
str or list
word or a list of words
"""
if isinstance(xs, list):
return [self._id2word[x] for x ... | python | def id2word(self, xs):
"""Map id(s) to word(s)
Parameters
----------
xs : int
id or a list of ids
Returns
-------
str or list
word or a list of words
"""
if isinstance(xs, list):
return [self._id2word[x] for x ... | [
"def",
"id2word",
"(",
"self",
",",
"xs",
")",
":",
"if",
"isinstance",
"(",
"xs",
",",
"list",
")",
":",
"return",
"[",
"self",
".",
"_id2word",
"[",
"x",
"]",
"for",
"x",
"in",
"xs",
"]",
"return",
"self",
".",
"_id2word",
"[",
"xs",
"]"
] | Map id(s) to word(s)
Parameters
----------
xs : int
id or a list of ids
Returns
-------
str or list
word or a list of words | [
"Map",
"id",
"(",
"s",
")",
"to",
"word",
"(",
"s",
")"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L271-L286 | train | Map id to word | 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/data.py | ParserVocabulary.rel2id | def rel2id(self, xs):
"""Map relation(s) to id(s)
Parameters
----------
xs : str or list
relation
Returns
-------
int or list
id(s) of relation
"""
if isinstance(xs, list):
return [self._rel2id[x] for x in xs]
... | python | def rel2id(self, xs):
"""Map relation(s) to id(s)
Parameters
----------
xs : str or list
relation
Returns
-------
int or list
id(s) of relation
"""
if isinstance(xs, list):
return [self._rel2id[x] for x in xs]
... | [
"def",
"rel2id",
"(",
"self",
",",
"xs",
")",
":",
"if",
"isinstance",
"(",
"xs",
",",
"list",
")",
":",
"return",
"[",
"self",
".",
"_rel2id",
"[",
"x",
"]",
"for",
"x",
"in",
"xs",
"]",
"return",
"self",
".",
"_rel2id",
"[",
"xs",
"]"
] | Map relation(s) to id(s)
Parameters
----------
xs : str or list
relation
Returns
-------
int or list
id(s) of relation | [
"Map",
"relation",
"(",
"s",
")",
"to",
"id",
"(",
"s",
")"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L288-L303 | train | Map relation to id | 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/data.py | ParserVocabulary.id2rel | def id2rel(self, xs):
"""Map id(s) to relation(s)
Parameters
----------
xs : int
id or a list of ids
Returns
-------
str or list
relation or a list of relations
"""
if isinstance(xs, list):
return [self._id2rel... | python | def id2rel(self, xs):
"""Map id(s) to relation(s)
Parameters
----------
xs : int
id or a list of ids
Returns
-------
str or list
relation or a list of relations
"""
if isinstance(xs, list):
return [self._id2rel... | [
"def",
"id2rel",
"(",
"self",
",",
"xs",
")",
":",
"if",
"isinstance",
"(",
"xs",
",",
"list",
")",
":",
"return",
"[",
"self",
".",
"_id2rel",
"[",
"x",
"]",
"for",
"x",
"in",
"xs",
"]",
"return",
"self",
".",
"_id2rel",
"[",
"xs",
"]"
] | Map id(s) to relation(s)
Parameters
----------
xs : int
id or a list of ids
Returns
-------
str or list
relation or a list of relations | [
"Map",
"id",
"(",
"s",
")",
"to",
"relation",
"(",
"s",
")"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L305-L320 | train | Map id to relation | 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/data.py | ParserVocabulary.tag2id | def tag2id(self, xs):
"""Map tag(s) to id(s)
Parameters
----------
xs : str or list
tag or tags
Returns
-------
int or list
id(s) of tag(s)
"""
if isinstance(xs, list):
return [self._tag2id.get(x, self.UNK) for... | python | def tag2id(self, xs):
"""Map tag(s) to id(s)
Parameters
----------
xs : str or list
tag or tags
Returns
-------
int or list
id(s) of tag(s)
"""
if isinstance(xs, list):
return [self._tag2id.get(x, self.UNK) for... | [
"def",
"tag2id",
"(",
"self",
",",
"xs",
")",
":",
"if",
"isinstance",
"(",
"xs",
",",
"list",
")",
":",
"return",
"[",
"self",
".",
"_tag2id",
".",
"get",
"(",
"x",
",",
"self",
".",
"UNK",
")",
"for",
"x",
"in",
"xs",
"]",
"return",
"self",
... | Map tag(s) to id(s)
Parameters
----------
xs : str or list
tag or tags
Returns
-------
int or list
id(s) of tag(s) | [
"Map",
"tag",
"(",
"s",
")",
"to",
"id",
"(",
"s",
")"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L322-L337 | train | Map tag or list of tags to id | 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/data.py | DataLoader.idx_sequence | def idx_sequence(self):
"""Indices of sentences when enumerating data set from batches.
Useful when retrieving the correct order of sentences
Returns
-------
list
List of ids ranging from 0 to #sent -1
"""
return [x[1] for x in sorted(zip(self._record... | python | def idx_sequence(self):
"""Indices of sentences when enumerating data set from batches.
Useful when retrieving the correct order of sentences
Returns
-------
list
List of ids ranging from 0 to #sent -1
"""
return [x[1] for x in sorted(zip(self._record... | [
"def",
"idx_sequence",
"(",
"self",
")",
":",
"return",
"[",
"x",
"[",
"1",
"]",
"for",
"x",
"in",
"sorted",
"(",
"zip",
"(",
"self",
".",
"_record",
",",
"list",
"(",
"range",
"(",
"len",
"(",
"self",
".",
"_record",
")",
")",
")",
")",
")",
... | Indices of sentences when enumerating data set from batches.
Useful when retrieving the correct order of sentences
Returns
-------
list
List of ids ranging from 0 to #sent -1 | [
"Indices",
"of",
"sentences",
"when",
"enumerating",
"data",
"set",
"from",
"batches",
".",
"Useful",
"when",
"retrieving",
"the",
"correct",
"order",
"of",
"sentences"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L431-L440 | train | Indices of sentences when enumerating data set from batches. | 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/data.py | DataLoader.get_batches | def get_batches(self, batch_size, shuffle=True):
"""Get batch iterator
Parameters
----------
batch_size : int
size of one batch
shuffle : bool
whether to shuffle batches. Don't set to True when evaluating on dev or test set.
Returns
------... | python | def get_batches(self, batch_size, shuffle=True):
"""Get batch iterator
Parameters
----------
batch_size : int
size of one batch
shuffle : bool
whether to shuffle batches. Don't set to True when evaluating on dev or test set.
Returns
------... | [
"def",
"get_batches",
"(",
"self",
",",
"batch_size",
",",
"shuffle",
"=",
"True",
")",
":",
"batches",
"=",
"[",
"]",
"for",
"bkt_idx",
",",
"bucket",
"in",
"enumerate",
"(",
"self",
".",
"_buckets",
")",
":",
"bucket_size",
"=",
"bucket",
".",
"shape... | Get batch iterator
Parameters
----------
batch_size : int
size of one batch
shuffle : bool
whether to shuffle batches. Don't set to True when evaluating on dev or test set.
Returns
-------
tuple
word_inputs, tag_inputs, arc_tar... | [
"Get",
"batch",
"iterator"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/common/data.py#L442-L473 | train | Get a batch iterator that returns a list of tuples each containing word_inputs tag_inputs arc_targets and rel_targets. | 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/text_classification/fasttext_word_ngram.py | create_ngram_set | def create_ngram_set(input_list, ngram_value=2):
"""
Extract a set of n-grams from a list of integers.
>>> create_ngram_set([1, 4, 9, 4, 1, 4], ngram_value=2)
{(4, 9), (4, 1), (1, 4), (9, 4)}
>>> create_ngram_set([1, 4, 9, 4, 1, 4], ngram_value=3)
[(1, 4, 9), (4, 9, 4), (9, 4, 1), (4, 1, 4)]
... | python | def create_ngram_set(input_list, ngram_value=2):
"""
Extract a set of n-grams from a list of integers.
>>> create_ngram_set([1, 4, 9, 4, 1, 4], ngram_value=2)
{(4, 9), (4, 1), (1, 4), (9, 4)}
>>> create_ngram_set([1, 4, 9, 4, 1, 4], ngram_value=3)
[(1, 4, 9), (4, 9, 4), (9, 4, 1), (4, 1, 4)]
... | [
"def",
"create_ngram_set",
"(",
"input_list",
",",
"ngram_value",
"=",
"2",
")",
":",
"return",
"set",
"(",
"zip",
"(",
"*",
"[",
"input_list",
"[",
"i",
":",
"]",
"for",
"i",
"in",
"range",
"(",
"ngram_value",
")",
"]",
")",
")"
] | Extract a set of n-grams from a list of integers.
>>> create_ngram_set([1, 4, 9, 4, 1, 4], ngram_value=2)
{(4, 9), (4, 1), (1, 4), (9, 4)}
>>> create_ngram_set([1, 4, 9, 4, 1, 4], ngram_value=3)
[(1, 4, 9), (4, 9, 4), (9, 4, 1), (4, 1, 4)] | [
"Extract",
"a",
"set",
"of",
"n",
"-",
"grams",
"from",
"a",
"list",
"of",
"integers",
".",
">>>",
"create_ngram_set",
"(",
"[",
"1",
"4",
"9",
"4",
"1",
"4",
"]",
"ngram_value",
"=",
"2",
")",
"{",
"(",
"4",
"9",
")",
"(",
"4",
"1",
")",
"("... | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L96-L104 | train | Extract a set of n - grams from a list of integers. | 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/text_classification/fasttext_word_ngram.py | add_ngram | def add_ngram(sequences, token_indice, ngram_range=2):
"""
Augment the input list of list (sequences) by appending n-grams values.
Example: adding bi-gram
>>> sequences = [[1, 3, 4, 5], [1, 3, 7, 9, 2]]
>>> token_indice = {(1, 3): 1337, (9, 2): 42, (4, 5): 2017}
>>> add_ngram(sequences, token_in... | python | def add_ngram(sequences, token_indice, ngram_range=2):
"""
Augment the input list of list (sequences) by appending n-grams values.
Example: adding bi-gram
>>> sequences = [[1, 3, 4, 5], [1, 3, 7, 9, 2]]
>>> token_indice = {(1, 3): 1337, (9, 2): 42, (4, 5): 2017}
>>> add_ngram(sequences, token_in... | [
"def",
"add_ngram",
"(",
"sequences",
",",
"token_indice",
",",
"ngram_range",
"=",
"2",
")",
":",
"new_sequences",
"=",
"[",
"]",
"for",
"input_list",
"in",
"sequences",
":",
"new_list",
"=",
"input_list",
"[",
":",
"]",
"for",
"i",
"in",
"range",
"(",
... | Augment the input list of list (sequences) by appending n-grams values.
Example: adding bi-gram
>>> sequences = [[1, 3, 4, 5], [1, 3, 7, 9, 2]]
>>> token_indice = {(1, 3): 1337, (9, 2): 42, (4, 5): 2017}
>>> add_ngram(sequences, token_indice, ngram_range=2)
[[1, 3, 4, 5, 1337, 2017], [1, 3, 7, 9, 2,... | [
"Augment",
"the",
"input",
"list",
"of",
"list",
"(",
"sequences",
")",
"by",
"appending",
"n",
"-",
"grams",
"values",
".",
"Example",
":",
"adding",
"bi",
"-",
"gram",
">>>",
"sequences",
"=",
"[[",
"1",
"3",
"4",
"5",
"]",
"[",
"1",
"3",
"7",
... | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L107-L131 | train | Augment the input list of list of list of lists by appending n - grams values. | 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/text_classification/fasttext_word_ngram.py | evaluate_accuracy | def evaluate_accuracy(data_iterator, net, ctx, loss_fun, num_classes):
"""
This function is used for evaluating accuracy of
a given data iterator. (Either Train/Test data)
It takes in the loss function used too!
"""
acc = mx.metric.Accuracy()
loss_avg = 0.
for i, ((data, length), label) ... | python | def evaluate_accuracy(data_iterator, net, ctx, loss_fun, num_classes):
"""
This function is used for evaluating accuracy of
a given data iterator. (Either Train/Test data)
It takes in the loss function used too!
"""
acc = mx.metric.Accuracy()
loss_avg = 0.
for i, ((data, length), label) ... | [
"def",
"evaluate_accuracy",
"(",
"data_iterator",
",",
"net",
",",
"ctx",
",",
"loss_fun",
",",
"num_classes",
")",
":",
"acc",
"=",
"mx",
".",
"metric",
".",
"Accuracy",
"(",
")",
"loss_avg",
"=",
"0.",
"for",
"i",
",",
"(",
"(",
"data",
",",
"lengt... | This function is used for evaluating accuracy of
a given data iterator. (Either Train/Test data)
It takes in the loss function used too! | [
"This",
"function",
"is",
"used",
"for",
"evaluating",
"accuracy",
"of",
"a",
"given",
"data",
"iterator",
".",
"(",
"Either",
"Train",
"/",
"Test",
"data",
")",
"It",
"takes",
"in",
"the",
"loss",
"function",
"used",
"too!"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L134-L156 | train | This function evaluates the accuracy of a given data iterator. | 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/text_classification/fasttext_word_ngram.py | read_input_data | def read_input_data(filename):
"""Helper function to get training data"""
logging.info('Opening file %s for reading input', filename)
input_file = open(filename, 'r')
data = []
labels = []
for line in input_file:
tokens = line.split(',', 1)
labels.append(tokens[0].strip())
... | python | def read_input_data(filename):
"""Helper function to get training data"""
logging.info('Opening file %s for reading input', filename)
input_file = open(filename, 'r')
data = []
labels = []
for line in input_file:
tokens = line.split(',', 1)
labels.append(tokens[0].strip())
... | [
"def",
"read_input_data",
"(",
"filename",
")",
":",
"logging",
".",
"info",
"(",
"'Opening file %s for reading input'",
",",
"filename",
")",
"input_file",
"=",
"open",
"(",
"filename",
",",
"'r'",
")",
"data",
"=",
"[",
"]",
"labels",
"=",
"[",
"]",
"for... | Helper function to get training data | [
"Helper",
"function",
"to",
"get",
"training",
"data"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L159-L169 | train | Helper function to get training data from 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/text_classification/fasttext_word_ngram.py | parse_args | def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description='Text Classification with FastText',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Computation options
group = parser.add_argument_group('Computation arguments')
group.add... | python | def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description='Text Classification with FastText',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Computation options
group = parser.add_argument_group('Computation arguments')
group.add... | [
"def",
"parse_args",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Text Classification with FastText'",
",",
"formatter_class",
"=",
"argparse",
".",
"ArgumentDefaultsHelpFormatter",
")",
"# Computation options",
"group",
"=... | Parse command line arguments. | [
"Parse",
"command",
"line",
"arguments",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L175-L214 | 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/text_classification/fasttext_word_ngram.py | get_label_mapping | def get_label_mapping(train_labels):
"""
Create the mapping from label to numeric label
"""
sorted_labels = np.sort(np.unique(train_labels))
label_mapping = {}
for i, label in enumerate(sorted_labels):
label_mapping[label] = i
logging.info('Label mapping:%s', format(label_mapping))
... | python | def get_label_mapping(train_labels):
"""
Create the mapping from label to numeric label
"""
sorted_labels = np.sort(np.unique(train_labels))
label_mapping = {}
for i, label in enumerate(sorted_labels):
label_mapping[label] = i
logging.info('Label mapping:%s', format(label_mapping))
... | [
"def",
"get_label_mapping",
"(",
"train_labels",
")",
":",
"sorted_labels",
"=",
"np",
".",
"sort",
"(",
"np",
".",
"unique",
"(",
"train_labels",
")",
")",
"label_mapping",
"=",
"{",
"}",
"for",
"i",
",",
"label",
"in",
"enumerate",
"(",
"sorted_labels",
... | Create the mapping from label to numeric label | [
"Create",
"the",
"mapping",
"from",
"label",
"to",
"numeric",
"label"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L217-L226 | train | Create the mapping from label to numeric label | 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/text_classification/fasttext_word_ngram.py | convert_to_sequences | def convert_to_sequences(dataset, vocab):
"""This function takes a dataset and converts
it into sequences via multiprocessing
"""
start = time.time()
dataset_vocab = map(lambda x: (x, vocab), dataset)
with mp.Pool() as pool:
# Each sample is processed in an asynchronous manner.
o... | python | def convert_to_sequences(dataset, vocab):
"""This function takes a dataset and converts
it into sequences via multiprocessing
"""
start = time.time()
dataset_vocab = map(lambda x: (x, vocab), dataset)
with mp.Pool() as pool:
# Each sample is processed in an asynchronous manner.
o... | [
"def",
"convert_to_sequences",
"(",
"dataset",
",",
"vocab",
")",
":",
"start",
"=",
"time",
".",
"time",
"(",
")",
"dataset_vocab",
"=",
"map",
"(",
"lambda",
"x",
":",
"(",
"x",
",",
"vocab",
")",
",",
"dataset",
")",
"with",
"mp",
".",
"Pool",
"... | This function takes a dataset and converts
it into sequences via multiprocessing | [
"This",
"function",
"takes",
"a",
"dataset",
"and",
"converts",
"it",
"into",
"sequences",
"via",
"multiprocessing"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L256-L268 | train | This function takes a dataset and converts it into sequences via multiprocessing. | 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/text_classification/fasttext_word_ngram.py | preprocess_dataset | def preprocess_dataset(dataset, labels):
""" Preprocess and prepare a dataset"""
start = time.time()
with mp.Pool() as pool:
# Each sample is processed in an asynchronous manner.
dataset = gluon.data.SimpleDataset(list(zip(dataset, labels)))
lengths = gluon.data.SimpleDataset(pool.ma... | python | def preprocess_dataset(dataset, labels):
""" Preprocess and prepare a dataset"""
start = time.time()
with mp.Pool() as pool:
# Each sample is processed in an asynchronous manner.
dataset = gluon.data.SimpleDataset(list(zip(dataset, labels)))
lengths = gluon.data.SimpleDataset(pool.ma... | [
"def",
"preprocess_dataset",
"(",
"dataset",
",",
"labels",
")",
":",
"start",
"=",
"time",
".",
"time",
"(",
")",
"with",
"mp",
".",
"Pool",
"(",
")",
"as",
"pool",
":",
"# Each sample is processed in an asynchronous manner.",
"dataset",
"=",
"gluon",
".",
... | Preprocess and prepare a dataset | [
"Preprocess",
"and",
"prepare",
"a",
"dataset"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L271-L281 | train | Preprocess and prepare a 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/text_classification/fasttext_word_ngram.py | get_dataloader | def get_dataloader(train_dataset, train_data_lengths,
test_dataset, batch_size):
""" Construct the DataLoader. Pad data, stack label and lengths"""
bucket_num, bucket_ratio = 20, 0.2
batchify_fn = gluonnlp.data.batchify.Tuple(
gluonnlp.data.batchify.Pad(axis=0, ret_length=True),
... | python | def get_dataloader(train_dataset, train_data_lengths,
test_dataset, batch_size):
""" Construct the DataLoader. Pad data, stack label and lengths"""
bucket_num, bucket_ratio = 20, 0.2
batchify_fn = gluonnlp.data.batchify.Tuple(
gluonnlp.data.batchify.Pad(axis=0, ret_length=True),
... | [
"def",
"get_dataloader",
"(",
"train_dataset",
",",
"train_data_lengths",
",",
"test_dataset",
",",
"batch_size",
")",
":",
"bucket_num",
",",
"bucket_ratio",
"=",
"20",
",",
"0.2",
"batchify_fn",
"=",
"gluonnlp",
".",
"data",
".",
"batchify",
".",
"Tuple",
"(... | Construct the DataLoader. Pad data, stack label and lengths | [
"Construct",
"the",
"DataLoader",
".",
"Pad",
"data",
"stack",
"label",
"and",
"lengths"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L284-L306 | train | Construct the DataLoader. | 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/text_classification/fasttext_word_ngram.py | train | def train(args):
"""Training function that orchestrates the Classification! """
train_file = args.input
test_file = args.validation
ngram_range = args.ngrams
logging.info('Ngrams range for the training run : %s', ngram_range)
logging.info('Loading Training data')
train_labels, train_data = r... | python | def train(args):
"""Training function that orchestrates the Classification! """
train_file = args.input
test_file = args.validation
ngram_range = args.ngrams
logging.info('Ngrams range for the training run : %s', ngram_range)
logging.info('Loading Training data')
train_labels, train_data = r... | [
"def",
"train",
"(",
"args",
")",
":",
"train_file",
"=",
"args",
".",
"input",
"test_file",
"=",
"args",
".",
"validation",
"ngram_range",
"=",
"args",
".",
"ngrams",
"logging",
".",
"info",
"(",
"'Ngrams range for the training run : %s'",
",",
"ngram_range",
... | Training function that orchestrates the Classification! | [
"Training",
"function",
"that",
"orchestrates",
"the",
"Classification!"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/text_classification/fasttext_word_ngram.py#L311-L416 | train | Train the n - grams in the 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/bert/staticbert/static_bert_qa_model.py | StaticBertForQA.hybrid_forward | def hybrid_forward(self, F, inputs, token_types, valid_length=None):
# pylint: disable=arguments-differ
# pylint: disable=unused-argument
"""Generate the unnormalized score for the given the input sequences.
Parameters
----------
inputs : NDArray, shape (batch_size, seq_... | python | def hybrid_forward(self, F, inputs, token_types, valid_length=None):
# pylint: disable=arguments-differ
# pylint: disable=unused-argument
"""Generate the unnormalized score for the given the input sequences.
Parameters
----------
inputs : NDArray, shape (batch_size, seq_... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
",",
"token_types",
",",
"valid_length",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"# pylint: disable=unused-argument",
"bert_output",
"=",
"self",
".",
"bert",
"(",
"inputs",
",",
"... | 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/staticbert/static_bert_qa_model.py#L50-L72 | train | This is the unnormalized score function that uses the BER algorithm to 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/bert/staticbert/static_bert_qa_model.py | BertForQALoss.hybrid_forward | def hybrid_forward(self, F, pred, label): # pylint: disable=arguments-differ
"""
Parameters
----------
pred : NDArray, shape (batch_size, seq_length, 2)
BERTSquad forward output.
label : list, length is 2, each shape is (batch_size,1)
label[0] is the star... | python | def hybrid_forward(self, F, pred, label): # pylint: disable=arguments-differ
"""
Parameters
----------
pred : NDArray, shape (batch_size, seq_length, 2)
BERTSquad forward output.
label : list, length is 2, each shape is (batch_size,1)
label[0] is the star... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"pred",
",",
"label",
")",
":",
"# pylint: disable=arguments-differ",
"pred",
"=",
"F",
".",
"split",
"(",
"pred",
",",
"axis",
"=",
"2",
",",
"num_outputs",
"=",
"2",
")",
"start_pred",
"=",
"pred",
... | Parameters
----------
pred : NDArray, shape (batch_size, seq_length, 2)
BERTSquad forward output.
label : list, length is 2, each shape is (batch_size,1)
label[0] is the starting position of the answer,
label[1] is the ending position of the answer.
R... | [
"Parameters",
"----------",
"pred",
":",
"NDArray",
"shape",
"(",
"batch_size",
"seq_length",
"2",
")",
"BERTSquad",
"forward",
"output",
".",
"label",
":",
"list",
"length",
"is",
"2",
"each",
"shape",
"is",
"(",
"batch_size",
"1",
")",
"label",
"[",
"0",... | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/staticbert/static_bert_qa_model.py#L85-L106 | train | A BERTSquad forward implementation of the log - likelihood. | 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/translation.py | NMTModel.encode | def encode(self, inputs, states=None, valid_length=None):
"""Encode the input sequence.
Parameters
----------
inputs : NDArray
states : list of NDArrays or None, default None
valid_length : NDArray or None, default None
Returns
-------
outputs : ... | python | def encode(self, inputs, states=None, valid_length=None):
"""Encode the input sequence.
Parameters
----------
inputs : NDArray
states : list of NDArrays or None, default None
valid_length : NDArray or None, default None
Returns
-------
outputs : ... | [
"def",
"encode",
"(",
"self",
",",
"inputs",
",",
"states",
"=",
"None",
",",
"valid_length",
"=",
"None",
")",
":",
"return",
"self",
".",
"encoder",
"(",
"self",
".",
"src_embed",
"(",
"inputs",
")",
",",
"states",
",",
"valid_length",
")"
] | Encode the input sequence.
Parameters
----------
inputs : NDArray
states : list of NDArrays or None, default None
valid_length : NDArray or None, default None
Returns
-------
outputs : list
Outputs of the encoder. | [
"Encode",
"the",
"input",
"sequence",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/translation.py#L129-L143 | train | Encode the input sequence. | 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/translation.py | NMTModel.decode_seq | def decode_seq(self, inputs, states, valid_length=None):
"""Decode given the input sequence.
Parameters
----------
inputs : NDArray
states : list of NDArrays
valid_length : NDArray or None, default None
Returns
-------
output : NDArray
... | python | def decode_seq(self, inputs, states, valid_length=None):
"""Decode given the input sequence.
Parameters
----------
inputs : NDArray
states : list of NDArrays
valid_length : NDArray or None, default None
Returns
-------
output : NDArray
... | [
"def",
"decode_seq",
"(",
"self",
",",
"inputs",
",",
"states",
",",
"valid_length",
"=",
"None",
")",
":",
"outputs",
",",
"states",
",",
"additional_outputs",
"=",
"self",
".",
"decoder",
".",
"decode_seq",
"(",
"inputs",
"=",
"self",
".",
"tgt_embed",
... | Decode given the input sequence.
Parameters
----------
inputs : NDArray
states : list of NDArrays
valid_length : NDArray or None, default None
Returns
-------
output : NDArray
The output of the decoder. Shape is (batch_size, length, tgt_word_... | [
"Decode",
"given",
"the",
"input",
"sequence",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/translation.py#L145-L168 | train | Decode given the input sequence. | 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/translation.py | NMTModel.decode_step | def decode_step(self, step_input, states):
"""One step decoding of the translation model.
Parameters
----------
step_input : NDArray
Shape (batch_size,)
states : list of NDArrays
Returns
-------
step_output : NDArray
Shape (batch_... | python | def decode_step(self, step_input, states):
"""One step decoding of the translation model.
Parameters
----------
step_input : NDArray
Shape (batch_size,)
states : list of NDArrays
Returns
-------
step_output : NDArray
Shape (batch_... | [
"def",
"decode_step",
"(",
"self",
",",
"step_input",
",",
"states",
")",
":",
"step_output",
",",
"states",
",",
"step_additional_outputs",
"=",
"self",
".",
"decoder",
"(",
"self",
".",
"tgt_embed",
"(",
"step_input",
")",
",",
"states",
")",
"step_output"... | One step decoding of the translation model.
Parameters
----------
step_input : NDArray
Shape (batch_size,)
states : list of NDArrays
Returns
-------
step_output : NDArray
Shape (batch_size, C_out)
states : list
step_additi... | [
"One",
"step",
"decoding",
"of",
"the",
"translation",
"model",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/translation.py#L170-L190 | train | One step decoding of the translation 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/translation.py | NMTModel.forward | def forward(self, src_seq, tgt_seq, src_valid_length=None, tgt_valid_length=None): #pylint: disable=arguments-differ
"""Generate the prediction given the src_seq and tgt_seq.
This is used in training an NMT model.
Parameters
----------
src_seq : NDArray
tgt_seq : NDArr... | python | def forward(self, src_seq, tgt_seq, src_valid_length=None, tgt_valid_length=None): #pylint: disable=arguments-differ
"""Generate the prediction given the src_seq and tgt_seq.
This is used in training an NMT model.
Parameters
----------
src_seq : NDArray
tgt_seq : NDArr... | [
"def",
"forward",
"(",
"self",
",",
"src_seq",
",",
"tgt_seq",
",",
"src_valid_length",
"=",
"None",
",",
"tgt_valid_length",
"=",
"None",
")",
":",
"#pylint: disable=arguments-differ",
"additional_outputs",
"=",
"[",
"]",
"encoder_outputs",
",",
"encoder_additional... | Generate the prediction given the src_seq and tgt_seq.
This is used in training an NMT model.
Parameters
----------
src_seq : NDArray
tgt_seq : NDArray
src_valid_length : NDArray or None
tgt_valid_length : NDArray or None
Returns
-------
... | [
"Generate",
"the",
"prediction",
"given",
"the",
"src_seq",
"and",
"tgt_seq",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/translation.py#L213-L241 | train | Generate the prediction given the src_seq and tgt_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 | src/gluonnlp/vocab/subwords.py | create_subword_function | def create_subword_function(subword_function_name, **kwargs):
"""Creates an instance of a subword function."""
create_ = registry.get_create_func(SubwordFunction, 'token embedding')
return create_(subword_function_name, **kwargs) | python | def create_subword_function(subword_function_name, **kwargs):
"""Creates an instance of a subword function."""
create_ = registry.get_create_func(SubwordFunction, 'token embedding')
return create_(subword_function_name, **kwargs) | [
"def",
"create_subword_function",
"(",
"subword_function_name",
",",
"*",
"*",
"kwargs",
")",
":",
"create_",
"=",
"registry",
".",
"get_create_func",
"(",
"SubwordFunction",
",",
"'token embedding'",
")",
"return",
"create_",
"(",
"subword_function_name",
",",
"*",... | Creates an instance of a subword function. | [
"Creates",
"an",
"instance",
"of",
"a",
"subword",
"function",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/vocab/subwords.py#L43-L47 | train | Creates an instance of a subword function. | 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/vocab/vocab.py | Vocab._index_special_tokens | def _index_special_tokens(self, unknown_token, special_tokens):
"""Indexes unknown and reserved tokens."""
self._idx_to_token = [unknown_token] if unknown_token else []
if not special_tokens:
self._reserved_tokens = None
else:
self._reserved_tokens = special_toke... | python | def _index_special_tokens(self, unknown_token, special_tokens):
"""Indexes unknown and reserved tokens."""
self._idx_to_token = [unknown_token] if unknown_token else []
if not special_tokens:
self._reserved_tokens = None
else:
self._reserved_tokens = special_toke... | [
"def",
"_index_special_tokens",
"(",
"self",
",",
"unknown_token",
",",
"special_tokens",
")",
":",
"self",
".",
"_idx_to_token",
"=",
"[",
"unknown_token",
"]",
"if",
"unknown_token",
"else",
"[",
"]",
"if",
"not",
"special_tokens",
":",
"self",
".",
"_reserv... | Indexes unknown and reserved tokens. | [
"Indexes",
"unknown",
"and",
"reserved",
"tokens",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/vocab/vocab.py#L163-L177 | train | Indexes unknown and reserved tokens. | 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/vocab/vocab.py | Vocab._index_counter_keys | def _index_counter_keys(self, counter, unknown_token, special_tokens, max_size,
min_freq):
"""Indexes keys of `counter`.
Indexes keys of `counter` according to frequency thresholds such as `max_size` and
`min_freq`.
"""
unknown_and_special_tokens = ... | python | def _index_counter_keys(self, counter, unknown_token, special_tokens, max_size,
min_freq):
"""Indexes keys of `counter`.
Indexes keys of `counter` according to frequency thresholds such as `max_size` and
`min_freq`.
"""
unknown_and_special_tokens = ... | [
"def",
"_index_counter_keys",
"(",
"self",
",",
"counter",
",",
"unknown_token",
",",
"special_tokens",
",",
"max_size",
",",
"min_freq",
")",
":",
"unknown_and_special_tokens",
"=",
"set",
"(",
"special_tokens",
")",
"if",
"special_tokens",
"else",
"set",
"(",
... | Indexes keys of `counter`.
Indexes keys of `counter` according to frequency thresholds such as `max_size` and
`min_freq`. | [
"Indexes",
"keys",
"of",
"counter",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/vocab/vocab.py#L179-L204 | train | Indexes keys of counter according to frequency thresholds such as max_size and min_freq. | 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/vocab/vocab.py | Vocab.set_embedding | def set_embedding(self, *embeddings):
"""Attaches one or more embeddings to the indexed text tokens.
Parameters
----------
embeddings : None or tuple of :class:`gluonnlp.embedding.TokenEmbedding` instances
The embedding to be attached to the indexed tokens. If a tuple of mu... | python | def set_embedding(self, *embeddings):
"""Attaches one or more embeddings to the indexed text tokens.
Parameters
----------
embeddings : None or tuple of :class:`gluonnlp.embedding.TokenEmbedding` instances
The embedding to be attached to the indexed tokens. If a tuple of mu... | [
"def",
"set_embedding",
"(",
"self",
",",
"*",
"embeddings",
")",
":",
"if",
"len",
"(",
"embeddings",
")",
"==",
"1",
"and",
"embeddings",
"[",
"0",
"]",
"is",
"None",
":",
"self",
".",
"_embedding",
"=",
"None",
"return",
"for",
"embs",
"in",
"embe... | Attaches one or more embeddings to the indexed text tokens.
Parameters
----------
embeddings : None or tuple of :class:`gluonnlp.embedding.TokenEmbedding` instances
The embedding to be attached to the indexed tokens. If a tuple of multiple embeddings
are provided, their... | [
"Attaches",
"one",
"or",
"more",
"embeddings",
"to",
"the",
"indexed",
"text",
"tokens",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/vocab/vocab.py#L281-L328 | train | Sets the embedding of the indexed text tokens. | 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/vocab/vocab.py | Vocab.to_tokens | def to_tokens(self, indices):
"""Converts token indices to tokens according to the vocabulary.
Parameters
----------
indices : int or list of ints
A source token index or token indices to be converted.
Returns
-------
str or list of strs
... | python | def to_tokens(self, indices):
"""Converts token indices to tokens according to the vocabulary.
Parameters
----------
indices : int or list of ints
A source token index or token indices to be converted.
Returns
-------
str or list of strs
... | [
"def",
"to_tokens",
"(",
"self",
",",
"indices",
")",
":",
"to_reduce",
"=",
"False",
"if",
"not",
"isinstance",
"(",
"indices",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"indices",
"=",
"[",
"indices",
"]",
"to_reduce",
"=",
"True",
"max_idx",
... | Converts token indices to tokens according to the vocabulary.
Parameters
----------
indices : int or list of ints
A source token index or token indices to be converted.
Returns
-------
str or list of strs
A token or a list of tokens according t... | [
"Converts",
"token",
"indices",
"to",
"tokens",
"according",
"to",
"the",
"vocabulary",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/vocab/vocab.py#L330-L360 | train | Converts token indices to tokens according to 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 | src/gluonnlp/vocab/vocab.py | Vocab.to_json | def to_json(self):
"""Serialize Vocab object to json string.
This method does not serialize the underlying embedding.
"""
if self._embedding:
warnings.warn('Serialization of attached embedding '
'to json is not supported. '
... | python | def to_json(self):
"""Serialize Vocab object to json string.
This method does not serialize the underlying embedding.
"""
if self._embedding:
warnings.warn('Serialization of attached embedding '
'to json is not supported. '
... | [
"def",
"to_json",
"(",
"self",
")",
":",
"if",
"self",
".",
"_embedding",
":",
"warnings",
".",
"warn",
"(",
"'Serialization of attached embedding '",
"'to json is not supported. '",
"'You may serialize the embedding to a binary format '",
"'separately using vocab.embedding.seria... | Serialize Vocab object to json string.
This method does not serialize the underlying embedding. | [
"Serialize",
"Vocab",
"object",
"to",
"json",
"string",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/vocab/vocab.py#L402-L420 | train | Serialize the Vocab object to json 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/vocab/vocab.py | Vocab.from_json | def from_json(cls, json_str):
"""Deserialize Vocab object from json string.
Parameters
----------
json_str : str
Serialized json string of a Vocab object.
Returns
-------
Vocab
"""
vocab_dict = json.loads(json_str)
unknown_t... | python | def from_json(cls, json_str):
"""Deserialize Vocab object from json string.
Parameters
----------
json_str : str
Serialized json string of a Vocab object.
Returns
-------
Vocab
"""
vocab_dict = json.loads(json_str)
unknown_t... | [
"def",
"from_json",
"(",
"cls",
",",
"json_str",
")",
":",
"vocab_dict",
"=",
"json",
".",
"loads",
"(",
"json_str",
")",
"unknown_token",
"=",
"vocab_dict",
".",
"get",
"(",
"'unknown_token'",
")",
"vocab",
"=",
"cls",
"(",
"unknown_token",
"=",
"unknown_... | Deserialize Vocab object from json string.
Parameters
----------
json_str : str
Serialized json string of a Vocab object.
Returns
-------
Vocab | [
"Deserialize",
"Vocab",
"object",
"from",
"json",
"string",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/vocab/vocab.py#L423-L449 | train | Deserialize a Vocab object from a json 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 | scripts/bert/run_pretraining_hvd.py | train | def train(data_train, model, nsp_loss, mlm_loss, vocab_size, ctx):
"""Training function."""
hvd.broadcast_parameters(model.collect_params(), root_rank=0)
mlm_metric = nlp.metric.MaskedAccuracy()
nsp_metric = nlp.metric.MaskedAccuracy()
mlm_metric.reset()
nsp_metric.reset()
logging.debug('C... | python | def train(data_train, model, nsp_loss, mlm_loss, vocab_size, ctx):
"""Training function."""
hvd.broadcast_parameters(model.collect_params(), root_rank=0)
mlm_metric = nlp.metric.MaskedAccuracy()
nsp_metric = nlp.metric.MaskedAccuracy()
mlm_metric.reset()
nsp_metric.reset()
logging.debug('C... | [
"def",
"train",
"(",
"data_train",
",",
"model",
",",
"nsp_loss",
",",
"mlm_loss",
",",
"vocab_size",
",",
"ctx",
")",
":",
"hvd",
".",
"broadcast_parameters",
"(",
"model",
".",
"collect_params",
"(",
")",
",",
"root_rank",
"=",
"0",
")",
"mlm_metric",
... | Training function. | [
"Training",
"function",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/run_pretraining_hvd.py#L71-L204 | train | Train the model on the data_train. | 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_finetune_squad.py | train | def train():
"""Training function."""
log.info('Loader Train data...')
if version_2:
train_data = SQuAD('train', version='2.0')
else:
train_data = SQuAD('train', version='1.1')
log.info('Number of records in Train data:{}'.format(len(train_data)))
train_data_transform, _ = prepr... | python | def train():
"""Training function."""
log.info('Loader Train data...')
if version_2:
train_data = SQuAD('train', version='2.0')
else:
train_data = SQuAD('train', version='1.1')
log.info('Number of records in Train data:{}'.format(len(train_data)))
train_data_transform, _ = prepr... | [
"def",
"train",
"(",
")",
":",
"log",
".",
"info",
"(",
"'Loader Train data...'",
")",
"if",
"version_2",
":",
"train_data",
"=",
"SQuAD",
"(",
"'train'",
",",
"version",
"=",
"'2.0'",
")",
"else",
":",
"train_data",
"=",
"SQuAD",
"(",
"'train'",
",",
... | Training function. | [
"Training",
"function",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/staticbert/static_finetune_squad.py#L301-L426 | train | Train the data in the base 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/bert/staticbert/static_finetune_squad.py | evaluate | def evaluate():
"""Evaluate the model on validation dataset.
"""
log.info('Loader dev data...')
if version_2:
dev_data = SQuAD('dev', version='2.0')
else:
dev_data = SQuAD('dev', version='1.1')
log.info('Number of records in Train data:{}'.format(len(dev_data)))
dev_dataset ... | python | def evaluate():
"""Evaluate the model on validation dataset.
"""
log.info('Loader dev data...')
if version_2:
dev_data = SQuAD('dev', version='2.0')
else:
dev_data = SQuAD('dev', version='1.1')
log.info('Number of records in Train data:{}'.format(len(dev_data)))
dev_dataset ... | [
"def",
"evaluate",
"(",
")",
":",
"log",
".",
"info",
"(",
"'Loader dev data...'",
")",
"if",
"version_2",
":",
"dev_data",
"=",
"SQuAD",
"(",
"'dev'",
",",
"version",
"=",
"'2.0'",
")",
"else",
":",
"dev_data",
"=",
"SQuAD",
"(",
"'dev'",
",",
"versio... | Evaluate the model on validation dataset. | [
"Evaluate",
"the",
"model",
"on",
"validation",
"dataset",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/staticbert/static_finetune_squad.py#L429-L517 | train | Evaluate the model on validation 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/batchify/batchify.py | _pad_arrs_to_max_length | def _pad_arrs_to_max_length(arrs, pad_axis, pad_val, use_shared_mem, dtype):
"""Inner Implementation of the Pad batchify
Parameters
----------
arrs : list
pad_axis : int
pad_val : number
use_shared_mem : bool, default False
Returns
-------
ret : NDArray
original_length : ND... | python | def _pad_arrs_to_max_length(arrs, pad_axis, pad_val, use_shared_mem, dtype):
"""Inner Implementation of the Pad batchify
Parameters
----------
arrs : list
pad_axis : int
pad_val : number
use_shared_mem : bool, default False
Returns
-------
ret : NDArray
original_length : ND... | [
"def",
"_pad_arrs_to_max_length",
"(",
"arrs",
",",
"pad_axis",
",",
"pad_val",
",",
"use_shared_mem",
",",
"dtype",
")",
":",
"if",
"isinstance",
"(",
"arrs",
"[",
"0",
"]",
",",
"mx",
".",
"nd",
".",
"NDArray",
")",
":",
"dtype",
"=",
"arrs",
"[",
... | Inner Implementation of the Pad batchify
Parameters
----------
arrs : list
pad_axis : int
pad_val : number
use_shared_mem : bool, default False
Returns
-------
ret : NDArray
original_length : NDArray | [
"Inner",
"Implementation",
"of",
"the",
"Pad",
"batchify"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/batchify/batchify.py#L29-L75 | train | This function pads the array to the maximum length of the object. | 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/parser/dep_parser.py | DepParser.train | def train(self, train_file, dev_file, test_file, save_dir, pretrained_embeddings=None, min_occur_count=2,
lstm_layers=3, word_dims=100, tag_dims=100, dropout_emb=0.33, lstm_hiddens=400,
dropout_lstm_input=0.33, dropout_lstm_hidden=0.33, mlp_arc_size=500, mlp_rel_size=100,
dropo... | python | def train(self, train_file, dev_file, test_file, save_dir, pretrained_embeddings=None, min_occur_count=2,
lstm_layers=3, word_dims=100, tag_dims=100, dropout_emb=0.33, lstm_hiddens=400,
dropout_lstm_input=0.33, dropout_lstm_hidden=0.33, mlp_arc_size=500, mlp_rel_size=100,
dropo... | [
"def",
"train",
"(",
"self",
",",
"train_file",
",",
"dev_file",
",",
"test_file",
",",
"save_dir",
",",
"pretrained_embeddings",
"=",
"None",
",",
"min_occur_count",
"=",
"2",
",",
"lstm_layers",
"=",
"3",
",",
"word_dims",
"=",
"100",
",",
"tag_dims",
"=... | Train a deep biaffine dependency parser
Parameters
----------
train_file : str
path to training set
dev_file : str
path to dev set
test_file : str
path to test set
save_dir : str
a directory for saving model and related met... | [
"Train",
"a",
"deep",
"biaffine",
"dependency",
"parser"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/parser/dep_parser.py#L44-L199 | train | Train a deep biaffine dependency 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/parsing/parser/dep_parser.py | DepParser.load | def load(self, path):
"""Load from disk
Parameters
----------
path : str
path to the directory which typically contains a config.pkl file and a model.bin file
Returns
-------
DepParser
parser itself
"""
config = _Config.lo... | python | def load(self, path):
"""Load from disk
Parameters
----------
path : str
path to the directory which typically contains a config.pkl file and a model.bin file
Returns
-------
DepParser
parser itself
"""
config = _Config.lo... | [
"def",
"load",
"(",
"self",
",",
"path",
")",
":",
"config",
"=",
"_Config",
".",
"load",
"(",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"'config.pkl'",
")",
")",
"config",
".",
"save_dir",
"=",
"path",
"# redirect root path to what user specified"... | Load from disk
Parameters
----------
path : str
path to the directory which typically contains a config.pkl file and a model.bin file
Returns
-------
DepParser
parser itself | [
"Load",
"from",
"disk"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/parser/dep_parser.py#L201-L224 | train | Loads the DepParser
from disk and returns the DepParser
object. | 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/parser/dep_parser.py | DepParser.evaluate | def evaluate(self, test_file, save_dir=None, logger=None, num_buckets_test=10, test_batch_size=5000):
"""Run evaluation on test set
Parameters
----------
test_file : str
path to test set
save_dir : str
where to store intermediate results and log
l... | python | def evaluate(self, test_file, save_dir=None, logger=None, num_buckets_test=10, test_batch_size=5000):
"""Run evaluation on test set
Parameters
----------
test_file : str
path to test set
save_dir : str
where to store intermediate results and log
l... | [
"def",
"evaluate",
"(",
"self",
",",
"test_file",
",",
"save_dir",
"=",
"None",
",",
"logger",
"=",
"None",
",",
"num_buckets_test",
"=",
"10",
",",
"test_batch_size",
"=",
"5000",
")",
":",
"parser",
"=",
"self",
".",
"_parser",
"vocab",
"=",
"self",
... | Run evaluation on test set
Parameters
----------
test_file : str
path to test set
save_dir : str
where to store intermediate results and log
logger : logging.logger
logger for printing results
num_buckets_test : int
number ... | [
"Run",
"evaluation",
"on",
"test",
"set"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/parser/dep_parser.py#L226-L256 | train | Evaluate on the test set and return the UAS and LAS. | 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/parser/dep_parser.py | DepParser.parse | def parse(self, sentence):
"""Parse raw sentence into ConllSentence
Parameters
----------
sentence : list
a list of (word, tag) tuples
Returns
-------
ConllSentence
ConllSentence object
"""
words = np.zeros((len(sentence) ... | python | def parse(self, sentence):
"""Parse raw sentence into ConllSentence
Parameters
----------
sentence : list
a list of (word, tag) tuples
Returns
-------
ConllSentence
ConllSentence object
"""
words = np.zeros((len(sentence) ... | [
"def",
"parse",
"(",
"self",
",",
"sentence",
")",
":",
"words",
"=",
"np",
".",
"zeros",
"(",
"(",
"len",
"(",
"sentence",
")",
"+",
"1",
",",
"1",
")",
",",
"np",
".",
"int32",
")",
"tags",
"=",
"np",
".",
"zeros",
"(",
"(",
"len",
"(",
"... | Parse raw sentence into ConllSentence
Parameters
----------
sentence : list
a list of (word, tag) tuples
Returns
-------
ConllSentence
ConllSentence object | [
"Parse",
"raw",
"sentence",
"into",
"ConllSentence"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/parser/dep_parser.py#L258-L285 | train | Parse a raw sentence into a ConllSentence object. | 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/utils.py | apply_weight_drop | def apply_weight_drop(block, local_param_regex, rate, axes=(),
weight_dropout_mode='training'):
"""Apply weight drop to the parameter of a block.
Parameters
----------
block : Block or HybridBlock
The block whose parameter is to be applied weight-drop.
local_param_rege... | python | def apply_weight_drop(block, local_param_regex, rate, axes=(),
weight_dropout_mode='training'):
"""Apply weight drop to the parameter of a block.
Parameters
----------
block : Block or HybridBlock
The block whose parameter is to be applied weight-drop.
local_param_rege... | [
"def",
"apply_weight_drop",
"(",
"block",
",",
"local_param_regex",
",",
"rate",
",",
"axes",
"=",
"(",
")",
",",
"weight_dropout_mode",
"=",
"'training'",
")",
":",
"if",
"not",
"rate",
":",
"return",
"existing_params",
"=",
"_find_params",
"(",
"block",
",... | Apply weight drop to the parameter of a block.
Parameters
----------
block : Block or HybridBlock
The block whose parameter is to be applied weight-drop.
local_param_regex : str
The regex for parameter names used in the self.params.get(), such as 'weight'.
rate : float
Fract... | [
"Apply",
"weight",
"drop",
"to",
"the",
"parameter",
"of",
"a",
"block",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/utils.py#L36-L114 | train | Applies weight drop to the parameter of a hybrid block. | 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/utils.py | _get_rnn_cell | def _get_rnn_cell(mode, num_layers, input_size, hidden_size,
dropout, weight_dropout,
var_drop_in, var_drop_state, var_drop_out,
skip_connection, proj_size=None, cell_clip=None, proj_clip=None):
"""create rnn cell given specs
Parameters
----------
m... | python | def _get_rnn_cell(mode, num_layers, input_size, hidden_size,
dropout, weight_dropout,
var_drop_in, var_drop_state, var_drop_out,
skip_connection, proj_size=None, cell_clip=None, proj_clip=None):
"""create rnn cell given specs
Parameters
----------
m... | [
"def",
"_get_rnn_cell",
"(",
"mode",
",",
"num_layers",
",",
"input_size",
",",
"hidden_size",
",",
"dropout",
",",
"weight_dropout",
",",
"var_drop_in",
",",
"var_drop_state",
",",
"var_drop_out",
",",
"skip_connection",
",",
"proj_size",
"=",
"None",
",",
"cel... | create rnn cell given specs
Parameters
----------
mode : str
The type of RNN cell to use. Options are 'lstmpc', 'rnn_tanh', 'rnn_relu', 'lstm', 'gru'.
num_layers : int
The number of RNN cells in the encoder.
input_size : int
The initial input size of in the RNN cell.
hid... | [
"create",
"rnn",
"cell",
"given",
"specs"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/utils.py#L162-L242 | train | Create a new rnn cell given the 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 | src/gluonnlp/model/utils.py | _get_rnn_layer | def _get_rnn_layer(mode, num_layers, input_size, hidden_size, dropout, weight_dropout):
"""create rnn layer given specs"""
if mode == 'rnn_relu':
rnn_block = functools.partial(rnn.RNN, activation='relu')
elif mode == 'rnn_tanh':
rnn_block = functools.partial(rnn.RNN, activation='tanh')
e... | python | def _get_rnn_layer(mode, num_layers, input_size, hidden_size, dropout, weight_dropout):
"""create rnn layer given specs"""
if mode == 'rnn_relu':
rnn_block = functools.partial(rnn.RNN, activation='relu')
elif mode == 'rnn_tanh':
rnn_block = functools.partial(rnn.RNN, activation='tanh')
e... | [
"def",
"_get_rnn_layer",
"(",
"mode",
",",
"num_layers",
",",
"input_size",
",",
"hidden_size",
",",
"dropout",
",",
"weight_dropout",
")",
":",
"if",
"mode",
"==",
"'rnn_relu'",
":",
"rnn_block",
"=",
"functools",
".",
"partial",
"(",
"rnn",
".",
"RNN",
"... | create rnn layer given specs | [
"create",
"rnn",
"layer",
"given",
"specs"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/utils.py#L245-L262 | train | create rnn layer given specs | 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/sampled_block.py | _SampledDenseHelper.hybrid_forward | def hybrid_forward(self, F, x, sampled_values, label, w_all, b_all):
"""Forward computation."""
sampled_candidates, expected_count_sampled, expected_count_true = sampled_values
# (num_sampled, in_unit)
w_sampled = w_all.slice(begin=(0, 0), end=(self._num_sampled, None))
w_true = ... | python | def hybrid_forward(self, F, x, sampled_values, label, w_all, b_all):
"""Forward computation."""
sampled_candidates, expected_count_sampled, expected_count_true = sampled_values
# (num_sampled, in_unit)
w_sampled = w_all.slice(begin=(0, 0), end=(self._num_sampled, None))
w_true = ... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"x",
",",
"sampled_values",
",",
"label",
",",
"w_all",
",",
"b_all",
")",
":",
"sampled_candidates",
",",
"expected_count_sampled",
",",
"expected_count_true",
"=",
"sampled_values",
"# (num_sampled, in_unit)",
... | Forward computation. | [
"Forward",
"computation",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/sampled_block.py#L52-L95 | train | Forward computation. | 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/sampled_block.py | _SampledDense.hybrid_forward | def hybrid_forward(self, F, x, sampled_values, label, weight, bias):
"""Forward computation."""
sampled_candidates, _, _ = sampled_values
# (batch_size,)
label = F.reshape(label, shape=(-1,))
# (num_sampled+batch_size,)
ids = F.concat(sampled_candidates, label, dim=0)
... | python | def hybrid_forward(self, F, x, sampled_values, label, weight, bias):
"""Forward computation."""
sampled_candidates, _, _ = sampled_values
# (batch_size,)
label = F.reshape(label, shape=(-1,))
# (num_sampled+batch_size,)
ids = F.concat(sampled_candidates, label, dim=0)
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"x",
",",
"sampled_values",
",",
"label",
",",
"weight",
",",
"bias",
")",
":",
"sampled_candidates",
",",
"_",
",",
"_",
"=",
"sampled_values",
"# (batch_size,)",
"label",
"=",
"F",
".",
"reshape",
"(... | Forward computation. | [
"Forward",
"computation",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/sampled_block.py#L169-L183 | train | Forward computation. | 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/sampled_block.py | _SparseSampledDense.forward | def forward(self, x, sampled_values, label):
"""Forward computation."""
sampled_candidates, _, _ = sampled_values
# (batch_size,)
label = label.reshape(shape=(-1,))
# (num_sampled+batch_size,)
ids = nd.concat(sampled_candidates, label, dim=0)
# lookup weights and ... | python | def forward(self, x, sampled_values, label):
"""Forward computation."""
sampled_candidates, _, _ = sampled_values
# (batch_size,)
label = label.reshape(shape=(-1,))
# (num_sampled+batch_size,)
ids = nd.concat(sampled_candidates, label, dim=0)
# lookup weights and ... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"sampled_values",
",",
"label",
")",
":",
"sampled_candidates",
",",
"_",
",",
"_",
"=",
"sampled_values",
"# (batch_size,)",
"label",
"=",
"label",
".",
"reshape",
"(",
"shape",
"=",
"(",
"-",
"1",
",",
")... | Forward computation. | [
"Forward",
"computation",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/sampled_block.py#L472-L487 | train | Forward computation. | 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/sequence_sampler.py | _extract_and_flatten_nested_structure | def _extract_and_flatten_nested_structure(data, flattened=None):
"""Flatten the structure of a nested container to a list.
Parameters
----------
data : A single NDArray/Symbol or nested container with NDArrays/Symbol.
The nested container to be flattened.
flattened : list or None
Th... | python | def _extract_and_flatten_nested_structure(data, flattened=None):
"""Flatten the structure of a nested container to a list.
Parameters
----------
data : A single NDArray/Symbol or nested container with NDArrays/Symbol.
The nested container to be flattened.
flattened : list or None
Th... | [
"def",
"_extract_and_flatten_nested_structure",
"(",
"data",
",",
"flattened",
"=",
"None",
")",
":",
"if",
"flattened",
"is",
"None",
":",
"flattened",
"=",
"[",
"]",
"structure",
"=",
"_extract_and_flatten_nested_structure",
"(",
"data",
",",
"flattened",
")",
... | Flatten the structure of a nested container to a list.
Parameters
----------
data : A single NDArray/Symbol or nested container with NDArrays/Symbol.
The nested container to be flattened.
flattened : list or None
The container thats holds flattened result.
Returns
-------
st... | [
"Flatten",
"the",
"structure",
"of",
"a",
"nested",
"container",
"to",
"a",
"list",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/sequence_sampler.py#L88-L119 | train | Flatten the structure of a nested container to a list. | 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/sequence_sampler.py | _reconstruct_flattened_structure | def _reconstruct_flattened_structure(structure, flattened):
"""Reconstruct the flattened list back to (possibly) nested structure.
Parameters
----------
structure : An integer or a nested container with integers.
The extracted structure of the container of `data`.
flattened : list or None
... | python | def _reconstruct_flattened_structure(structure, flattened):
"""Reconstruct the flattened list back to (possibly) nested structure.
Parameters
----------
structure : An integer or a nested container with integers.
The extracted structure of the container of `data`.
flattened : list or None
... | [
"def",
"_reconstruct_flattened_structure",
"(",
"structure",
",",
"flattened",
")",
":",
"if",
"isinstance",
"(",
"structure",
",",
"list",
")",
":",
"return",
"list",
"(",
"_reconstruct_flattened_structure",
"(",
"x",
",",
"flattened",
")",
"for",
"x",
"in",
... | Reconstruct the flattened list back to (possibly) nested structure.
Parameters
----------
structure : An integer or a nested container with integers.
The extracted structure of the container of `data`.
flattened : list or None
The container thats holds flattened result.
Returns
... | [
"Reconstruct",
"the",
"flattened",
"list",
"back",
"to",
"(",
"possibly",
")",
"nested",
"structure",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/sequence_sampler.py#L122-L145 | train | Reconstruct the flattened list back to ( possibly nested structure. | 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/sequence_sampler.py | _expand_to_beam_size | def _expand_to_beam_size(data, beam_size, batch_size, state_info=None):
"""Tile all the states to have batch_size * beam_size on the batch axis.
Parameters
----------
data : A single NDArray/Symbol or nested container with NDArrays/Symbol
Each NDArray/Symbol should have shape (N, ...) when stat... | python | def _expand_to_beam_size(data, beam_size, batch_size, state_info=None):
"""Tile all the states to have batch_size * beam_size on the batch axis.
Parameters
----------
data : A single NDArray/Symbol or nested container with NDArrays/Symbol
Each NDArray/Symbol should have shape (N, ...) when stat... | [
"def",
"_expand_to_beam_size",
"(",
"data",
",",
"beam_size",
",",
"batch_size",
",",
"state_info",
"=",
"None",
")",
":",
"assert",
"not",
"state_info",
"or",
"isinstance",
"(",
"state_info",
",",
"(",
"type",
"(",
"data",
")",
",",
"dict",
")",
")",
",... | Tile all the states to have batch_size * beam_size on the batch axis.
Parameters
----------
data : A single NDArray/Symbol or nested container with NDArrays/Symbol
Each NDArray/Symbol should have shape (N, ...) when state_info is None,
or same as the layout in state_info when it's not None.... | [
"Tile",
"all",
"the",
"states",
"to",
"have",
"batch_size",
"*",
"beam_size",
"on",
"the",
"batch",
"axis",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/sequence_sampler.py#L148-L211 | train | Expand all the states in data to have batch_size * beam_size on the batch axis. | 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/sequence_sampler.py | _SamplingStepUpdate.hybrid_forward | def hybrid_forward(self, F, samples, valid_length, outputs, scores, beam_alive_mask, states):
"""
Parameters
----------
F
samples : NDArray or Symbol
The current samples generated by beam search. Shape (batch_size, beam_size, L)
valid_length : NDArray or Symbo... | python | def hybrid_forward(self, F, samples, valid_length, outputs, scores, beam_alive_mask, states):
"""
Parameters
----------
F
samples : NDArray or Symbol
The current samples generated by beam search. Shape (batch_size, beam_size, L)
valid_length : NDArray or Symbo... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"samples",
",",
"valid_length",
",",
"outputs",
",",
"scores",
",",
"beam_alive_mask",
",",
"states",
")",
":",
"beam_size",
"=",
"self",
".",
"_beam_size",
"# outputs: (batch_size, beam_size, vocab_size)",
"out... | Parameters
----------
F
samples : NDArray or Symbol
The current samples generated by beam search. Shape (batch_size, beam_size, L)
valid_length : NDArray or Symbol
The current valid lengths of the samples
outputs: NDArray or Symbol
Decoder outp... | [
"Parameters",
"----------",
"F",
"samples",
":",
"NDArray",
"or",
"Symbol",
"The",
"current",
"samples",
"generated",
"by",
"beam",
"search",
".",
"Shape",
"(",
"batch_size",
"beam_size",
"L",
")",
"valid_length",
":",
"NDArray",
"or",
"Symbol",
"The",
"curren... | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/sequence_sampler.py#L377-L442 | train | This method is used to forward pass the state machine to the next beam search. | 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/sequence_sampler.py | HybridBeamSearchSampler.hybrid_forward | def hybrid_forward(self, F, inputs, states): # pylint: disable=arguments-differ
"""Sample by beam search.
Parameters
----------
F
inputs : NDArray or Symbol
The initial input of the decoder. Shape is (batch_size,).
states : Object that contains NDArrays or ... | python | def hybrid_forward(self, F, inputs, states): # pylint: disable=arguments-differ
"""Sample by beam search.
Parameters
----------
F
inputs : NDArray or Symbol
The initial input of the decoder. Shape is (batch_size,).
states : Object that contains NDArrays or ... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
",",
"states",
")",
":",
"# pylint: disable=arguments-differ",
"batch_size",
"=",
"self",
".",
"_batch_size",
"beam_size",
"=",
"self",
".",
"_beam_size",
"vocab_size",
"=",
"self",
".",
"_vocab_size... | Sample by beam search.
Parameters
----------
F
inputs : NDArray or Symbol
The initial input of the decoder. Shape is (batch_size,).
states : Object that contains NDArrays or Symbols
The initial states of the decoder.
Returns
-------
... | [
"Sample",
"by",
"beam",
"search",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/sequence_sampler.py#L605-L710 | train | A decoder that draws the state - structure of the state - structure. | 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/parameter.py | WeightDropParameter.data | def data(self, ctx=None):
"""Returns a copy of this parameter on one context. Must have been
initialized on this context before.
Parameters
----------
ctx : Context
Desired context.
Returns
-------
NDArray on ctx
"""
d = self._... | python | def data(self, ctx=None):
"""Returns a copy of this parameter on one context. Must have been
initialized on this context before.
Parameters
----------
ctx : Context
Desired context.
Returns
-------
NDArray on ctx
"""
d = self._... | [
"def",
"data",
"(",
"self",
",",
"ctx",
"=",
"None",
")",
":",
"d",
"=",
"self",
".",
"_check_and_get",
"(",
"self",
".",
"_data",
",",
"ctx",
")",
"if",
"self",
".",
"_rate",
":",
"d",
"=",
"nd",
".",
"Dropout",
"(",
"d",
",",
"self",
".",
"... | Returns a copy of this parameter on one context. Must have been
initialized on this context before.
Parameters
----------
ctx : Context
Desired context.
Returns
-------
NDArray on ctx | [
"Returns",
"a",
"copy",
"of",
"this",
"parameter",
"on",
"one",
"context",
".",
"Must",
"have",
"been",
"initialized",
"on",
"this",
"context",
"before",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/parameter.py#L59-L74 | train | Returns a copy of this parameter on one context. | 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/elmo.py | elmo_2x1024_128_2048cnn_1xhighway | def elmo_2x1024_128_2048cnn_1xhighway(dataset_name=None, pretrained=False, ctx=mx.cpu(),
root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""ELMo 2-layer BiLSTM with 1024 hidden units, 128 projection size, 1 highway layer.
Parameters
----------
dataset_name... | python | def elmo_2x1024_128_2048cnn_1xhighway(dataset_name=None, pretrained=False, ctx=mx.cpu(),
root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""ELMo 2-layer BiLSTM with 1024 hidden units, 128 projection size, 1 highway layer.
Parameters
----------
dataset_name... | [
"def",
"elmo_2x1024_128_2048cnn_1xhighway",
"(",
"dataset_name",
"=",
"None",
",",
"pretrained",
"=",
"False",
",",
"ctx",
"=",
"mx",
".",
"cpu",
"(",
")",
",",
"root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"get_home_dir",
"(",
")",
",",
"'models'",
... | r"""ELMo 2-layer BiLSTM with 1024 hidden units, 128 projection size, 1 highway layer.
Parameters
----------
dataset_name : str or None, default None
The dataset name on which the pre-trained model is trained.
Options are 'gbw'.
pretrained : bool, default False
Whether to load th... | [
"r",
"ELMo",
"2",
"-",
"layer",
"BiLSTM",
"with",
"1024",
"hidden",
"units",
"128",
"projection",
"size",
"1",
"highway",
"layer",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/elmo.py#L308-L349 | train | r Returns a pre - trained 2 - layer BiLSTM model with 1024 hidden units 128 projection size 1 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 | src/gluonnlp/model/elmo.py | ELMoCharacterEncoder.hybrid_forward | def hybrid_forward(self, F, inputs):
# pylint: disable=arguments-differ
"""
Compute context insensitive token embeddings for ELMo representations.
Parameters
----------
inputs : NDArray
Shape (batch_size, sequence_length, max_character_per_token)
... | python | def hybrid_forward(self, F, inputs):
# pylint: disable=arguments-differ
"""
Compute context insensitive token embeddings for ELMo representations.
Parameters
----------
inputs : NDArray
Shape (batch_size, sequence_length, max_character_per_token)
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
")",
":",
"# pylint: disable=arguments-differ",
"# the character id embedding",
"# (batch_size * sequence_length, max_chars_per_token, embed_dim)",
"character_embedding",
"=",
"self",
".",
"_char_embedding",
"(",
"i... | Compute context insensitive token embeddings for ELMo representations.
Parameters
----------
inputs : NDArray
Shape (batch_size, sequence_length, max_character_per_token)
of character ids representing the current batch.
Returns
-------
token_embe... | [
"Compute",
"context",
"insensitive",
"token",
"embeddings",
"for",
"ELMo",
"representations",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/elmo.py#L103-L131 | train | Compute context insensitive token embeddings for ELMo representations. | 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/elmo.py | ELMoBiLM.hybrid_forward | def hybrid_forward(self, F, inputs, states=None, mask=None):
# pylint: disable=arguments-differ
"""
Parameters
----------
inputs : NDArray
Shape (batch_size, sequence_length, max_character_per_token)
of character ids representing the current batch.
... | python | def hybrid_forward(self, F, inputs, states=None, mask=None):
# pylint: disable=arguments-differ
"""
Parameters
----------
inputs : NDArray
Shape (batch_size, sequence_length, max_character_per_token)
of character ids representing the current batch.
... | [
"def",
"hybrid_forward",
"(",
"self",
",",
"F",
",",
"inputs",
",",
"states",
"=",
"None",
",",
"mask",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"type_representation",
"=",
"self",
".",
"_elmo_char_encoder",
"(",
"inputs",
")",
"type_represen... | Parameters
----------
inputs : NDArray
Shape (batch_size, sequence_length, max_character_per_token)
of character ids representing the current batch.
states : (list of list of NDArray, list of list of NDArray)
The states. First tuple element is the forward laye... | [
"Parameters",
"----------",
"inputs",
":",
"NDArray",
"Shape",
"(",
"batch_size",
"sequence_length",
"max_character_per_token",
")",
"of",
"character",
"ids",
"representing",
"the",
"current",
"batch",
".",
"states",
":",
"(",
"list",
"of",
"list",
"of",
"NDArray"... | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/elmo.py#L243-L284 | train | This is the forward transformation for the current 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/language_model.py | awd_lstm_lm_1150 | def awd_lstm_lm_1150(dataset_name=None, vocab=None, pretrained=False, ctx=cpu(),
root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""3-layer LSTM language model with weight-drop, variational dropout, and tied weights.
Embedding size is 400, and hidden layer size is 1150.
Param... | python | def awd_lstm_lm_1150(dataset_name=None, vocab=None, pretrained=False, ctx=cpu(),
root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""3-layer LSTM language model with weight-drop, variational dropout, and tied weights.
Embedding size is 400, and hidden layer size is 1150.
Param... | [
"def",
"awd_lstm_lm_1150",
"(",
"dataset_name",
"=",
"None",
",",
"vocab",
"=",
"None",
",",
"pretrained",
"=",
"False",
",",
"ctx",
"=",
"cpu",
"(",
")",
",",
"root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"get_home_dir",
"(",
")",
",",
"'models'... | r"""3-layer LSTM language model with weight-drop, variational dropout, and tied weights.
Embedding size is 400, and hidden layer size is 1150.
Parameters
----------
dataset_name : str or None, default None
The dataset name on which the pre-trained model is trained.
Options are 'wikitex... | [
"r",
"3",
"-",
"layer",
"LSTM",
"language",
"model",
"with",
"weight",
"-",
"drop",
"variational",
"dropout",
"and",
"tied",
"weights",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/language_model.py#L181-L226 | train | r A basic LSTM language model with weight - drop variational dropout and tied weights. | 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/language_model.py | standard_lstm_lm_200 | def standard_lstm_lm_200(dataset_name=None, vocab=None, pretrained=False, ctx=cpu(),
root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""Standard 2-layer LSTM language model with tied embedding and output weights.
Both embedding and hidden dimensions are 200.
Parameters
... | python | def standard_lstm_lm_200(dataset_name=None, vocab=None, pretrained=False, ctx=cpu(),
root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""Standard 2-layer LSTM language model with tied embedding and output weights.
Both embedding and hidden dimensions are 200.
Parameters
... | [
"def",
"standard_lstm_lm_200",
"(",
"dataset_name",
"=",
"None",
",",
"vocab",
"=",
"None",
",",
"pretrained",
"=",
"False",
",",
"ctx",
"=",
"cpu",
"(",
")",
",",
"root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"get_home_dir",
"(",
")",
",",
"'mod... | r"""Standard 2-layer LSTM language model with tied embedding and output weights.
Both embedding and hidden dimensions are 200.
Parameters
----------
dataset_name : str or None, default None
The dataset name on which the pre-trained model is trained.
Options are 'wikitext-2'. If specifi... | [
"r",
"Standard",
"2",
"-",
"layer",
"LSTM",
"language",
"model",
"with",
"tied",
"embedding",
"and",
"output",
"weights",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/language_model.py#L276-L317 | train | r Standard LSTM language model with tied embedding and output weights. | 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/language_model.py | big_rnn_lm_2048_512 | def big_rnn_lm_2048_512(dataset_name=None, vocab=None, pretrained=False, ctx=cpu(),
root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""Big 1-layer LSTMP language model.
Both embedding and projection size are 512. Hidden size is 2048.
Parameters
----------
dataset_n... | python | def big_rnn_lm_2048_512(dataset_name=None, vocab=None, pretrained=False, ctx=cpu(),
root=os.path.join(get_home_dir(), 'models'), **kwargs):
r"""Big 1-layer LSTMP language model.
Both embedding and projection size are 512. Hidden size is 2048.
Parameters
----------
dataset_n... | [
"def",
"big_rnn_lm_2048_512",
"(",
"dataset_name",
"=",
"None",
",",
"vocab",
"=",
"None",
",",
"pretrained",
"=",
"False",
",",
"ctx",
"=",
"cpu",
"(",
")",
",",
"root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"get_home_dir",
"(",
")",
",",
"'mode... | r"""Big 1-layer LSTMP language model.
Both embedding and projection size are 512. Hidden size is 2048.
Parameters
----------
dataset_name : str or None, default None
The dataset name on which the pre-trained model is trained.
Options are 'gbw'. If specified, then the returned vocabular... | [
"r",
"Big",
"1",
"-",
"layer",
"LSTMP",
"language",
"model",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/language_model.py#L512-L553 | train | r Big 1 - layer LSTMP language 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/language_model.py | AWDRNN.forward | def forward(self, inputs, begin_state=None): # pylint: disable=arguments-differ
"""Implement forward computation.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
begin_state : list
... | python | def forward(self, inputs, begin_state=None): # pylint: disable=arguments-differ
"""Implement forward computation.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
begin_state : list
... | [
"def",
"forward",
"(",
"self",
",",
"inputs",
",",
"begin_state",
"=",
"None",
")",
":",
"# pylint: disable=arguments-differ",
"encoded",
"=",
"self",
".",
"embedding",
"(",
"inputs",
")",
"if",
"begin_state",
"is",
"None",
":",
"begin_state",
"=",
"self",
"... | Implement forward computation.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
begin_state : list
initial recurrent state tensor with length equals to num_layers.
the ... | [
"Implement",
"forward",
"computation",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/language_model.py#L74-L108 | train | Implement forward computation. | 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/language_model.py | BigRNN.forward | def forward(self, inputs, begin_state): # pylint: disable=arguments-differ
"""Implement forward computation.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
begin_state : list
... | python | def forward(self, inputs, begin_state): # pylint: disable=arguments-differ
"""Implement forward computation.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
begin_state : list
... | [
"def",
"forward",
"(",
"self",
",",
"inputs",
",",
"begin_state",
")",
":",
"# pylint: disable=arguments-differ",
"encoded",
"=",
"self",
".",
"embedding",
"(",
"inputs",
")",
"length",
"=",
"inputs",
".",
"shape",
"[",
"0",
"]",
"batch_size",
"=",
"inputs",... | Implement forward computation.
Parameters
-----------
inputs : NDArray
input tensor with shape `(sequence_length, batch_size)`
when `layout` is "TNC".
begin_state : list
initial recurrent state tensor with length equals to num_layers*2.
Fo... | [
"Implement",
"forward",
"computation",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/language_model.py#L479-L510 | train | Implement forward computation. | 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/seq2seq_encoder_decoder.py | _get_cell_type | def _get_cell_type(cell_type):
"""Get the object type of the cell by parsing the input
Parameters
----------
cell_type : str or type
Returns
-------
cell_constructor: type
The constructor of the RNNCell
"""
if isinstance(cell_type, str):
if cell_type == 'lstm':
... | python | def _get_cell_type(cell_type):
"""Get the object type of the cell by parsing the input
Parameters
----------
cell_type : str or type
Returns
-------
cell_constructor: type
The constructor of the RNNCell
"""
if isinstance(cell_type, str):
if cell_type == 'lstm':
... | [
"def",
"_get_cell_type",
"(",
"cell_type",
")",
":",
"if",
"isinstance",
"(",
"cell_type",
",",
"str",
")",
":",
"if",
"cell_type",
"==",
"'lstm'",
":",
"return",
"rnn",
".",
"LSTMCell",
"elif",
"cell_type",
"==",
"'gru'",
":",
"return",
"rnn",
".",
"GRU... | Get the object type of the cell by parsing the input
Parameters
----------
cell_type : str or type
Returns
-------
cell_constructor: type
The constructor of the RNNCell | [
"Get",
"the",
"object",
"type",
"of",
"the",
"cell",
"by",
"parsing",
"the",
"input"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/seq2seq_encoder_decoder.py#L30-L54 | train | Get the object type of the input cell_type by parsing the input
| 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/batchify/embedding.py | _get_context | def _get_context(center_idx, sentence_boundaries, window_size,
random_window_size, seed):
"""Compute the context with respect to a center word in a sentence.
Takes an numpy array of sentences boundaries.
"""
random.seed(seed + center_idx)
sentence_index = np.searchsorted(sentence... | python | def _get_context(center_idx, sentence_boundaries, window_size,
random_window_size, seed):
"""Compute the context with respect to a center word in a sentence.
Takes an numpy array of sentences boundaries.
"""
random.seed(seed + center_idx)
sentence_index = np.searchsorted(sentence... | [
"def",
"_get_context",
"(",
"center_idx",
",",
"sentence_boundaries",
",",
"window_size",
",",
"random_window_size",
",",
"seed",
")",
":",
"random",
".",
"seed",
"(",
"seed",
"+",
"center_idx",
")",
"sentence_index",
"=",
"np",
".",
"searchsorted",
"(",
"sent... | Compute the context with respect to a center word in a sentence.
Takes an numpy array of sentences boundaries. | [
"Compute",
"the",
"context",
"with",
"respect",
"to",
"a",
"center",
"word",
"in",
"a",
"sentence",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/batchify/embedding.py#L246-L274 | train | Compute the context with respect to a center word in a sentence. | 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/sentiment_analysis/text_cnn.py | model | def model(dropout, vocab, model_mode, output_size):
"""Construct the model."""
textCNN = SentimentNet(dropout=dropout, vocab_size=len(vocab), model_mode=model_mode,\
output_size=output_size)
textCNN.hybridize()
return textCNN | python | def model(dropout, vocab, model_mode, output_size):
"""Construct the model."""
textCNN = SentimentNet(dropout=dropout, vocab_size=len(vocab), model_mode=model_mode,\
output_size=output_size)
textCNN.hybridize()
return textCNN | [
"def",
"model",
"(",
"dropout",
",",
"vocab",
",",
"model_mode",
",",
"output_size",
")",
":",
"textCNN",
"=",
"SentimentNet",
"(",
"dropout",
"=",
"dropout",
",",
"vocab_size",
"=",
"len",
"(",
"vocab",
")",
",",
"model_mode",
"=",
"model_mode",
",",
"o... | Construct the model. | [
"Construct",
"the",
"model",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/sentiment_analysis/text_cnn.py#L40-L46 | train | Construct 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 | scripts/sentiment_analysis/text_cnn.py | init | def init(textCNN, vocab, model_mode, context, lr):
"""Initialize parameters."""
textCNN.initialize(mx.init.Xavier(), ctx=context, force_reinit=True)
if model_mode != 'rand':
textCNN.embedding.weight.set_data(vocab.embedding.idx_to_vec)
if model_mode == 'multichannel':
textCNN.embedding_... | python | def init(textCNN, vocab, model_mode, context, lr):
"""Initialize parameters."""
textCNN.initialize(mx.init.Xavier(), ctx=context, force_reinit=True)
if model_mode != 'rand':
textCNN.embedding.weight.set_data(vocab.embedding.idx_to_vec)
if model_mode == 'multichannel':
textCNN.embedding_... | [
"def",
"init",
"(",
"textCNN",
",",
"vocab",
",",
"model_mode",
",",
"context",
",",
"lr",
")",
":",
"textCNN",
".",
"initialize",
"(",
"mx",
".",
"init",
".",
"Xavier",
"(",
")",
",",
"ctx",
"=",
"context",
",",
"force_reinit",
"=",
"True",
")",
"... | Initialize parameters. | [
"Initialize",
"parameters",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/sentiment_analysis/text_cnn.py#L48-L60 | train | Initialize 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/bert/bert_qa_dataset.py | preprocess_dataset | def preprocess_dataset(dataset, transform, num_workers=8):
"""Use multiprocessing to perform transform for dataset.
Parameters
----------
dataset: dataset-like object
Source dataset.
transform: callable
Transformer function.
num_workers: int, default 8
The number of mult... | python | def preprocess_dataset(dataset, transform, num_workers=8):
"""Use multiprocessing to perform transform for dataset.
Parameters
----------
dataset: dataset-like object
Source dataset.
transform: callable
Transformer function.
num_workers: int, default 8
The number of mult... | [
"def",
"preprocess_dataset",
"(",
"dataset",
",",
"transform",
",",
"num_workers",
"=",
"8",
")",
":",
"worker_fn",
"=",
"partial",
"(",
"_worker_fn",
",",
"transform",
"=",
"transform",
")",
"start",
"=",
"time",
".",
"time",
"(",
")",
"pool",
"=",
"mp"... | Use multiprocessing to perform transform for dataset.
Parameters
----------
dataset: dataset-like object
Source dataset.
transform: callable
Transformer function.
num_workers: int, default 8
The number of multiprocessing workers to use for data preprocessing. | [
"Use",
"multiprocessing",
"to",
"perform",
"transform",
"for",
"dataset",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/bert/bert_qa_dataset.py#L56-L86 | train | Use multiprocessing to perform transform for 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/model/__init__.py | get_model | def get_model(name, dataset_name='wikitext-2', **kwargs):
"""Returns a pre-defined model by name.
Parameters
----------
name : str
Name of the model.
dataset_name : str or None, default 'wikitext-2'.
The dataset name on which the pre-trained model is trained.
For language mo... | python | def get_model(name, dataset_name='wikitext-2', **kwargs):
"""Returns a pre-defined model by name.
Parameters
----------
name : str
Name of the model.
dataset_name : str or None, default 'wikitext-2'.
The dataset name on which the pre-trained model is trained.
For language mo... | [
"def",
"get_model",
"(",
"name",
",",
"dataset_name",
"=",
"'wikitext-2'",
",",
"*",
"*",
"kwargs",
")",
":",
"models",
"=",
"{",
"'standard_lstm_lm_200'",
":",
"standard_lstm_lm_200",
",",
"'standard_lstm_lm_650'",
":",
"standard_lstm_lm_650",
",",
"'standard_lstm_... | Returns a pre-defined model by name.
Parameters
----------
name : str
Name of the model.
dataset_name : str or None, default 'wikitext-2'.
The dataset name on which the pre-trained model is trained.
For language model, options are 'wikitext-2'.
For ELMo, Options are 'gbw... | [
"Returns",
"a",
"pre",
"-",
"defined",
"model",
"by",
"name",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/__init__.py#L99-L151 | train | Returns a pre - defined model by 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/attention_cell.py | _masked_softmax | def _masked_softmax(F, att_score, mask, dtype):
"""Ignore the masked elements when calculating the softmax
Parameters
----------
F : symbol or ndarray
att_score : Symborl or NDArray
Shape (batch_size, query_length, memory_length)
mask : Symbol or NDArray or None
Shape (batch_siz... | python | def _masked_softmax(F, att_score, mask, dtype):
"""Ignore the masked elements when calculating the softmax
Parameters
----------
F : symbol or ndarray
att_score : Symborl or NDArray
Shape (batch_size, query_length, memory_length)
mask : Symbol or NDArray or None
Shape (batch_siz... | [
"def",
"_masked_softmax",
"(",
"F",
",",
"att_score",
",",
"mask",
",",
"dtype",
")",
":",
"if",
"mask",
"is",
"not",
"None",
":",
"# Fill in the masked scores with a very small value",
"neg",
"=",
"-",
"1e4",
"if",
"np",
".",
"dtype",
"(",
"dtype",
")",
"... | Ignore the masked elements when calculating the softmax
Parameters
----------
F : symbol or ndarray
att_score : Symborl or NDArray
Shape (batch_size, query_length, memory_length)
mask : Symbol or NDArray or None
Shape (batch_size, query_length, memory_length)
Returns
-------... | [
"Ignore",
"the",
"masked",
"elements",
"when",
"calculating",
"the",
"softmax"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/attention_cell.py#L33-L55 | train | Compute the softmax of the node - level elements in a 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 | src/gluonnlp/model/attention_cell.py | AttentionCell._read_by_weight | def _read_by_weight(self, F, att_weights, value):
"""Read from the value matrix given the attention weights.
Parameters
----------
F : symbol or ndarray
att_weights : Symbol or NDArray
Attention weights.
For single-head attention,
Shape (b... | python | def _read_by_weight(self, F, att_weights, value):
"""Read from the value matrix given the attention weights.
Parameters
----------
F : symbol or ndarray
att_weights : Symbol or NDArray
Attention weights.
For single-head attention,
Shape (b... | [
"def",
"_read_by_weight",
"(",
"self",
",",
"F",
",",
"att_weights",
",",
"value",
")",
":",
"output",
"=",
"F",
".",
"batch_dot",
"(",
"att_weights",
",",
"value",
")",
"return",
"output"
] | Read from the value matrix given the attention weights.
Parameters
----------
F : symbol or ndarray
att_weights : Symbol or NDArray
Attention weights.
For single-head attention,
Shape (batch_size, query_length, memory_length).
For mult... | [
"Read",
"from",
"the",
"value",
"matrix",
"given",
"the",
"attention",
"weights",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/model/attention_cell.py#L99-L120 | train | Read from the value matrix given the attention weights. | 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/translation.py | BeamSearchTranslator.translate | def translate(self, src_seq, src_valid_length):
"""Get the translation result given the input sentence.
Parameters
----------
src_seq : mx.nd.NDArray
Shape (batch_size, length)
src_valid_length : mx.nd.NDArray
Shape (batch_size,)
Returns
... | python | def translate(self, src_seq, src_valid_length):
"""Get the translation result given the input sentence.
Parameters
----------
src_seq : mx.nd.NDArray
Shape (batch_size, length)
src_valid_length : mx.nd.NDArray
Shape (batch_size,)
Returns
... | [
"def",
"translate",
"(",
"self",
",",
"src_seq",
",",
"src_valid_length",
")",
":",
"batch_size",
"=",
"src_seq",
".",
"shape",
"[",
"0",
"]",
"encoder_outputs",
",",
"_",
"=",
"self",
".",
"_model",
".",
"encode",
"(",
"src_seq",
",",
"valid_length",
"=... | Get the translation result given the input sentence.
Parameters
----------
src_seq : mx.nd.NDArray
Shape (batch_size, length)
src_valid_length : mx.nd.NDArray
Shape (batch_size,)
Returns
-------
samples : NDArray
Samples draw ... | [
"Get",
"the",
"translation",
"result",
"given",
"the",
"input",
"sentence",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/machine_translation/translation.py#L55-L82 | train | Translate the input sentence into a set of samples and scores. | 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/parser/evaluate/evaluate.py | evaluate_official_script | def evaluate_official_script(parser, vocab, num_buckets_test, test_batch_size, test_file, output_file,
debug=False):
"""Evaluate parser on a data set
Parameters
----------
parser : BiaffineParser
biaffine parser
vocab : ParserVocabulary
vocabulary built ... | python | def evaluate_official_script(parser, vocab, num_buckets_test, test_batch_size, test_file, output_file,
debug=False):
"""Evaluate parser on a data set
Parameters
----------
parser : BiaffineParser
biaffine parser
vocab : ParserVocabulary
vocabulary built ... | [
"def",
"evaluate_official_script",
"(",
"parser",
",",
"vocab",
",",
"num_buckets_test",
",",
"test_batch_size",
",",
"test_file",
",",
"output_file",
",",
"debug",
"=",
"False",
")",
":",
"if",
"output_file",
"is",
"None",
":",
"output_file",
"=",
"tempfile",
... | Evaluate parser on a data set
Parameters
----------
parser : BiaffineParser
biaffine parser
vocab : ParserVocabulary
vocabulary built from data set
num_buckets_test : int
size of buckets (cluster sentences into this number of clusters)
test_batch_size : int
batch... | [
"Evaluate",
"parser",
"on",
"a",
"data",
"set"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/parser/evaluate/evaluate.py#L28-L102 | train | Evaluate parser on a data set and save the result to output_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/parsing/parser/biaffine_parser.py | BiaffineParser.parameter_from_numpy | def parameter_from_numpy(self, name, array):
""" Create parameter with its value initialized according to a numpy tensor
Parameters
----------
name : str
parameter name
array : np.ndarray
initiation value
Returns
-------
mxnet.glu... | python | def parameter_from_numpy(self, name, array):
""" Create parameter with its value initialized according to a numpy tensor
Parameters
----------
name : str
parameter name
array : np.ndarray
initiation value
Returns
-------
mxnet.glu... | [
"def",
"parameter_from_numpy",
"(",
"self",
",",
"name",
",",
"array",
")",
":",
"p",
"=",
"self",
".",
"params",
".",
"get",
"(",
"name",
",",
"shape",
"=",
"array",
".",
"shape",
",",
"init",
"=",
"mx",
".",
"init",
".",
"Constant",
"(",
"array",... | Create parameter with its value initialized according to a numpy tensor
Parameters
----------
name : str
parameter name
array : np.ndarray
initiation value
Returns
-------
mxnet.gluon.parameter
a parameter object | [
"Create",
"parameter",
"with",
"its",
"value",
"initialized",
"according",
"to",
"a",
"numpy",
"tensor"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/parser/biaffine_parser.py#L122-L138 | train | Create a parameter with its value initialized according to a numpy tensor
. | 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/parser/biaffine_parser.py | BiaffineParser.parameter_init | def parameter_init(self, name, shape, init):
"""Create parameter given name, shape and initiator
Parameters
----------
name : str
parameter name
shape : tuple
parameter shape
init : mxnet.initializer
an initializer
Returns
... | python | def parameter_init(self, name, shape, init):
"""Create parameter given name, shape and initiator
Parameters
----------
name : str
parameter name
shape : tuple
parameter shape
init : mxnet.initializer
an initializer
Returns
... | [
"def",
"parameter_init",
"(",
"self",
",",
"name",
",",
"shape",
",",
"init",
")",
":",
"p",
"=",
"self",
".",
"params",
".",
"get",
"(",
"name",
",",
"shape",
"=",
"shape",
",",
"init",
"=",
"init",
")",
"return",
"p"
] | Create parameter given name, shape and initiator
Parameters
----------
name : str
parameter name
shape : tuple
parameter shape
init : mxnet.initializer
an initializer
Returns
-------
mxnet.gluon.parameter
a... | [
"Create",
"parameter",
"given",
"name",
"shape",
"and",
"initiator"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/parser/biaffine_parser.py#L140-L158 | train | Create a parameter given name shape and initiator. | 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/parser/biaffine_parser.py | BiaffineParser.forward | def forward(self, word_inputs, tag_inputs, arc_targets=None, rel_targets=None):
"""Run decoding
Parameters
----------
word_inputs : mxnet.ndarray.NDArray
word indices of seq_len x batch_size
tag_inputs : mxnet.ndarray.NDArray
tag indices of seq_len x batc... | python | def forward(self, word_inputs, tag_inputs, arc_targets=None, rel_targets=None):
"""Run decoding
Parameters
----------
word_inputs : mxnet.ndarray.NDArray
word indices of seq_len x batch_size
tag_inputs : mxnet.ndarray.NDArray
tag indices of seq_len x batc... | [
"def",
"forward",
"(",
"self",
",",
"word_inputs",
",",
"tag_inputs",
",",
"arc_targets",
"=",
"None",
",",
"rel_targets",
"=",
"None",
")",
":",
"is_train",
"=",
"autograd",
".",
"is_training",
"(",
")",
"def",
"flatten_numpy",
"(",
"ndarray",
")",
":",
... | Run decoding
Parameters
----------
word_inputs : mxnet.ndarray.NDArray
word indices of seq_len x batch_size
tag_inputs : mxnet.ndarray.NDArray
tag indices of seq_len x batch_size
arc_targets : mxnet.ndarray.NDArray
gold arc indices of seq_len ... | [
"Run",
"decoding"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/parser/biaffine_parser.py#L160-L302 | train | Run decoding and training on a set of 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/parsing/parser/biaffine_parser.py | BiaffineParser.save_parameters | def save_parameters(self, filename):
"""Save model
Parameters
----------
filename : str
path to model file
"""
params = self._collect_params_with_prefix()
if self.pret_word_embs: # don't save word embeddings inside model
params.pop('pret_... | python | def save_parameters(self, filename):
"""Save model
Parameters
----------
filename : str
path to model file
"""
params = self._collect_params_with_prefix()
if self.pret_word_embs: # don't save word embeddings inside model
params.pop('pret_... | [
"def",
"save_parameters",
"(",
"self",
",",
"filename",
")",
":",
"params",
"=",
"self",
".",
"_collect_params_with_prefix",
"(",
")",
"if",
"self",
".",
"pret_word_embs",
":",
"# don't save word embeddings inside model",
"params",
".",
"pop",
"(",
"'pret_word_embs.... | Save model
Parameters
----------
filename : str
path to model file | [
"Save",
"model"
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/scripts/parsing/parser/biaffine_parser.py#L304-L316 | train | Save model parameters to 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 | src/gluonnlp/data/dataloader.py | _worker_fn | def _worker_fn(samples, batchify_fn, dataset=None):
"""Function for processing data in worker process."""
# pylint: disable=unused-argument
# it is required that each worker process has to fork a new MXIndexedRecordIO handle
# preserving dataset as global variable can save tons of overhead and is safe i... | python | def _worker_fn(samples, batchify_fn, dataset=None):
"""Function for processing data in worker process."""
# pylint: disable=unused-argument
# it is required that each worker process has to fork a new MXIndexedRecordIO handle
# preserving dataset as global variable can save tons of overhead and is safe i... | [
"def",
"_worker_fn",
"(",
"samples",
",",
"batchify_fn",
",",
"dataset",
"=",
"None",
")",
":",
"# pylint: disable=unused-argument",
"# it is required that each worker process has to fork a new MXIndexedRecordIO handle",
"# preserving dataset as global variable can save tons of overhead ... | Function for processing data in worker process. | [
"Function",
"for",
"processing",
"data",
"in",
"worker",
"process",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/dataloader.py#L40-L52 | train | Function for processing data in worker process. | 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/dataloader.py | _thread_worker_fn | def _thread_worker_fn(samples, batchify_fn, dataset):
"""Threadpool worker function for processing data."""
if isinstance(samples[0], (list, tuple)):
batch = [batchify_fn([dataset[i] for i in shard]) for shard in samples]
else:
batch = batchify_fn([dataset[i] for i in samples])
return ba... | python | def _thread_worker_fn(samples, batchify_fn, dataset):
"""Threadpool worker function for processing data."""
if isinstance(samples[0], (list, tuple)):
batch = [batchify_fn([dataset[i] for i in shard]) for shard in samples]
else:
batch = batchify_fn([dataset[i] for i in samples])
return ba... | [
"def",
"_thread_worker_fn",
"(",
"samples",
",",
"batchify_fn",
",",
"dataset",
")",
":",
"if",
"isinstance",
"(",
"samples",
"[",
"0",
"]",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"batch",
"=",
"[",
"batchify_fn",
"(",
"[",
"dataset",
"[",
"i... | Threadpool worker function for processing data. | [
"Threadpool",
"worker",
"function",
"for",
"processing",
"data",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/data/dataloader.py#L54-L60 | train | Threadpool worker function for processing 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 | src/gluonnlp/embedding/token_embedding.py | create | def create(embedding_name, **kwargs):
"""Creates an instance of token embedding.
Creates a token embedding instance by loading embedding vectors from an externally hosted
pre-trained token embedding file, such as those of GloVe and FastText. To get all the valid
`embedding_name` and `source`, use :fun... | python | def create(embedding_name, **kwargs):
"""Creates an instance of token embedding.
Creates a token embedding instance by loading embedding vectors from an externally hosted
pre-trained token embedding file, such as those of GloVe and FastText. To get all the valid
`embedding_name` and `source`, use :fun... | [
"def",
"create",
"(",
"embedding_name",
",",
"*",
"*",
"kwargs",
")",
":",
"create_text_embedding",
"=",
"registry",
".",
"get_create_func",
"(",
"TokenEmbedding",
",",
"'token embedding'",
")",
"return",
"create_text_embedding",
"(",
"embedding_name",
",",
"*",
"... | Creates an instance of token embedding.
Creates a token embedding instance by loading embedding vectors from an externally hosted
pre-trained token embedding file, such as those of GloVe and FastText. To get all the valid
`embedding_name` and `source`, use :func:`gluonnlp.embedding.list_sources`.
Pa... | [
"Creates",
"an",
"instance",
"of",
"token",
"embedding",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L69-L97 | train | Creates an instance of token embedding. | 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 | list_sources | def list_sources(embedding_name=None):
"""Get valid token embedding names and their pre-trained file names.
To load token embedding vectors from an externally hosted pre-trained token embedding file,
such as those of GloVe and FastText, one should use
`gluonnlp.embedding.create(embedding_name, source)... | python | def list_sources(embedding_name=None):
"""Get valid token embedding names and their pre-trained file names.
To load token embedding vectors from an externally hosted pre-trained token embedding file,
such as those of GloVe and FastText, one should use
`gluonnlp.embedding.create(embedding_name, source)... | [
"def",
"list_sources",
"(",
"embedding_name",
"=",
"None",
")",
":",
"text_embedding_reg",
"=",
"registry",
".",
"get_registry",
"(",
"TokenEmbedding",
")",
"if",
"embedding_name",
"is",
"not",
"None",
":",
"embedding_name",
"=",
"embedding_name",
".",
"lower",
... | Get valid token embedding names and their pre-trained file names.
To load token embedding vectors from an externally hosted pre-trained token embedding file,
such as those of GloVe and FastText, one should use
`gluonnlp.embedding.create(embedding_name, source)`. This method returns all the
valid names... | [
"Get",
"valid",
"token",
"embedding",
"names",
"and",
"their",
"pre",
"-",
"trained",
"file",
"names",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L100-L139 | train | Get all the valid token embedding names and their pre - trained file names. | 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._load_embedding | def _load_embedding(self, pretrained_file_path, elem_delim,
encoding='utf8'):
"""Load embedding vectors from a pre-trained token embedding file.
Both text files and TokenEmbedding serialization files are supported.
elem_delim and encoding are ignored for non-text files.
... | python | def _load_embedding(self, pretrained_file_path, elem_delim,
encoding='utf8'):
"""Load embedding vectors from a pre-trained token embedding file.
Both text files and TokenEmbedding serialization files are supported.
elem_delim and encoding are ignored for non-text files.
... | [
"def",
"_load_embedding",
"(",
"self",
",",
"pretrained_file_path",
",",
"elem_delim",
",",
"encoding",
"=",
"'utf8'",
")",
":",
"pretrained_file_path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"pretrained_file_path",
")",
"if",
"not",
"os",
".",
"path"... | Load embedding vectors from a pre-trained token embedding file.
Both text files and TokenEmbedding serialization files are supported.
elem_delim and encoding are ignored for non-text files.
For every unknown token, if its representation `self.unknown_token` is encountered in the
pre-tr... | [
"Load",
"embedding",
"vectors",
"from",
"a",
"pre",
"-",
"trained",
"token",
"embedding",
"file",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L221-L253 | train | Load embedding vectors from a pre - trained token embedding 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 | src/gluonnlp/embedding/token_embedding.py | TokenEmbedding._load_embedding_txt | def _load_embedding_txt(self, pretrained_file_path, elem_delim, encoding='utf8'):
"""Load embedding vectors from a pre-trained token embedding file.
For every unknown token, if its representation `self.unknown_token` is encountered in the
pre-trained token embedding file, index 0 of `self.idx_t... | python | def _load_embedding_txt(self, pretrained_file_path, elem_delim, encoding='utf8'):
"""Load embedding vectors from a pre-trained token embedding file.
For every unknown token, if its representation `self.unknown_token` is encountered in the
pre-trained token embedding file, index 0 of `self.idx_t... | [
"def",
"_load_embedding_txt",
"(",
"self",
",",
"pretrained_file_path",
",",
"elem_delim",
",",
"encoding",
"=",
"'utf8'",
")",
":",
"vec_len",
"=",
"None",
"all_elems",
"=",
"[",
"]",
"tokens",
"=",
"set",
"(",
")",
"loaded_unknown_vec",
"=",
"None",
"with"... | Load embedding vectors from a pre-trained token embedding file.
For every unknown token, if its representation `self.unknown_token` is encountered in the
pre-trained token embedding file, index 0 of `self.idx_to_vec` maps to the pre-trained token
embedding vector loaded from the file; otherwise... | [
"Load",
"embedding",
"vectors",
"from",
"a",
"pre",
"-",
"trained",
"token",
"embedding",
"file",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L255-L321 | train | Load embedding vectors from a pre - trained text embedding 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 | src/gluonnlp/embedding/token_embedding.py | TokenEmbedding._load_embedding_serialized | def _load_embedding_serialized(self, pretrained_file_path):
"""Load embedding vectors from a pre-trained token embedding file.
For every unknown token, if its representation `self.unknown_token` is encountered in the
pre-trained token embedding file, index 0 of `self.idx_to_vec` maps to the pre... | python | def _load_embedding_serialized(self, pretrained_file_path):
"""Load embedding vectors from a pre-trained token embedding file.
For every unknown token, if its representation `self.unknown_token` is encountered in the
pre-trained token embedding file, index 0 of `self.idx_to_vec` maps to the pre... | [
"def",
"_load_embedding_serialized",
"(",
"self",
",",
"pretrained_file_path",
")",
":",
"deserialized_embedding",
"=",
"TokenEmbedding",
".",
"deserialize",
"(",
"pretrained_file_path",
")",
"if",
"deserialized_embedding",
".",
"unknown_token",
":",
"# Some .npz files on S... | Load embedding vectors from a pre-trained token embedding file.
For every unknown token, if its representation `self.unknown_token` is encountered in the
pre-trained token embedding file, index 0 of `self.idx_to_vec` maps to the pre-trained token
embedding vector loaded from the file; otherwise... | [
"Load",
"embedding",
"vectors",
"from",
"a",
"pre",
"-",
"trained",
"token",
"embedding",
"file",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L323-L380 | train | Load embedding vectors from a pre - trained token embedding 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 | src/gluonnlp/embedding/token_embedding.py | TokenEmbedding._check_vector_update | def _check_vector_update(self, tokens, new_embedding):
"""Check that tokens and embedding are in the format for __setitem__."""
assert self._idx_to_vec is not None, '`idx_to_vec` has not been initialized.'
if not isinstance(tokens, (list, tuple)) or len(tokens) == 1:
assert isinstan... | python | def _check_vector_update(self, tokens, new_embedding):
"""Check that tokens and embedding are in the format for __setitem__."""
assert self._idx_to_vec is not None, '`idx_to_vec` has not been initialized.'
if not isinstance(tokens, (list, tuple)) or len(tokens) == 1:
assert isinstan... | [
"def",
"_check_vector_update",
"(",
"self",
",",
"tokens",
",",
"new_embedding",
")",
":",
"assert",
"self",
".",
"_idx_to_vec",
"is",
"not",
"None",
",",
"'`idx_to_vec` has not been initialized.'",
"if",
"not",
"isinstance",
"(",
"tokens",
",",
"(",
"list",
","... | Check that tokens and embedding are in the format for __setitem__. | [
"Check",
"that",
"tokens",
"and",
"embedding",
"are",
"in",
"the",
"format",
"for",
"__setitem__",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L553-L576 | train | Check that tokens and embedding are in the format for __setitem__. | 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._check_source | def _check_source(cls, source_file_hash, source):
"""Checks if a pre-trained token embedding source name is valid.
Parameters
----------
source : str
The pre-trained token embedding source.
"""
embedding_name = cls.__name__.lower()
if source not in s... | python | def _check_source(cls, source_file_hash, source):
"""Checks if a pre-trained token embedding source name is valid.
Parameters
----------
source : str
The pre-trained token embedding source.
"""
embedding_name = cls.__name__.lower()
if source not in s... | [
"def",
"_check_source",
"(",
"cls",
",",
"source_file_hash",
",",
"source",
")",
":",
"embedding_name",
"=",
"cls",
".",
"__name__",
".",
"lower",
"(",
")",
"if",
"source",
"not",
"in",
"source_file_hash",
":",
"raise",
"KeyError",
"(",
"'Cannot find pre-train... | Checks if a pre-trained token embedding source name is valid.
Parameters
----------
source : str
The pre-trained token embedding source. | [
"Checks",
"if",
"a",
"pre",
"-",
"trained",
"token",
"embedding",
"source",
"name",
"is",
"valid",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L643-L657 | train | Checks if a pre - trained token embedding source name is valid. | 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.from_file | def from_file(file_path, elem_delim=' ', encoding='utf8', **kwargs):
"""Creates a user-defined token embedding from a pre-trained embedding file.
This is to load embedding vectors from a user-defined pre-trained token embedding file.
For example, if `elem_delim` = ' ', the expected format of a... | python | def from_file(file_path, elem_delim=' ', encoding='utf8', **kwargs):
"""Creates a user-defined token embedding from a pre-trained embedding file.
This is to load embedding vectors from a user-defined pre-trained token embedding file.
For example, if `elem_delim` = ' ', the expected format of a... | [
"def",
"from_file",
"(",
"file_path",
",",
"elem_delim",
"=",
"' '",
",",
"encoding",
"=",
"'utf8'",
",",
"*",
"*",
"kwargs",
")",
":",
"embedding",
"=",
"TokenEmbedding",
"(",
"*",
"*",
"kwargs",
")",
"embedding",
".",
"_load_embedding",
"(",
"file_path",... | Creates a user-defined token embedding from a pre-trained embedding file.
This is to load embedding vectors from a user-defined pre-trained token embedding file.
For example, if `elem_delim` = ' ', the expected format of a custom pre-trained token
embedding file may look like:
'hello ... | [
"Creates",
"a",
"user",
"-",
"defined",
"token",
"embedding",
"from",
"a",
"pre",
"-",
"trained",
"embedding",
"file",
"."
] | 4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba | https://github.com/dmlc/gluon-nlp/blob/4b83eb6bcc8881e5f1081a3675adaa19fac5c0ba/src/gluonnlp/embedding/token_embedding.py#L660-L694 | train | Creates a user - defined token embedding from a pre - trained token embedding 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.