19.7. d2l API Document
Open the notebook in Colab
Open the notebook in Colab
Open the notebook in Colab

The implementations of the following members of the d2l package and sections where they are defined and explained can be found in the source file.

class d2l.mxnet.Accumulator(n)[source]

For accumulating sums over n variables.

class d2l.mxnet.AddNorm(dropout, **kwargs)[source]
forward(X, Y)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.Animator(xlabel=None, ylabel=None, legend=None, xlim=None, ylim=None, xscale='linear', yscale='linear', fmts='-', 'm--', 'g-.', 'r:', nrows=1, ncols=1, figsize=3.5, 2.5)[source]

For plotting data in animation.

class d2l.mxnet.BERTEncoder(vocab_size, num_hiddens, ffn_num_hiddens, num_heads, num_layers, dropout, max_len=1000, **kwargs)[source]
forward(tokens, segments, valid_lens)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.BERTModel(vocab_size, num_hiddens, ffn_num_hiddens, num_heads, num_layers, dropout, max_len=1000)[source]
forward(tokens, segments, valid_lens=None, pred_positions=None)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.BPRLoss(weight=None, batch_axis=0, **kwargs)[source]
forward(positive, negative)[source]

Defines the forward computation. Arguments can be either NDArray or Symbol.

class d2l.mxnet.CTRDataset(data_path, feat_mapper=None, defaults=None, min_threshold=4, num_feat=34)[source]
class d2l.mxnet.Decoder(**kwargs)[source]

The base decoder interface for the encoder-decoder architecture.

forward(X, state)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.DotProductAttention(dropout, **kwargs)[source]
forward(query, key, value, valid_len=None)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.Encoder(**kwargs)[source]

The base encoder interface for the encoder-decoder architecture.

forward(X, *args)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.EncoderBlock(num_hiddens, ffn_num_hiddens, num_heads, dropout, use_bias=False, **kwargs)[source]
forward(X, valid_len)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.EncoderDecoder(encoder, decoder, **kwargs)[source]

The base class for the encoder-decoder architecture.

forward(enc_X, dec_X, *args)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.HingeLossbRec(weight=None, batch_axis=0, **kwargs)[source]
forward(positive, negative, margin=1)[source]

Defines the forward computation. Arguments can be either NDArray or Symbol.

class d2l.mxnet.MLPAttention(units, dropout, **kwargs)[source]
forward(query, key, value, valid_len)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.MaskLM(vocab_size, num_hiddens, **kwargs)[source]
forward(X, pred_positions)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.MaskedSoftmaxCELoss(axis=- 1, sparse_label=True, from_logits=False, weight=None, batch_axis=0, **kwargs)[source]
forward(pred, label, valid_len)[source]

Defines the forward computation. Arguments can be either NDArray or Symbol.

class d2l.mxnet.MultiHeadAttention(num_hiddens, num_heads, dropout, use_bias=False, **kwargs)[source]
forward(query, key, value, valid_len)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.NextSentencePred(**kwargs)[source]
forward(X)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.PositionWiseFFN(ffn_num_hiddens, pw_num_outputs, **kwargs)[source]
forward(X)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.PositionalEncoding(num_hiddens, dropout, max_len=1000)[source]
forward(X)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.RNNModel(rnn_layer, vocab_size, **kwargs)[source]
forward(inputs, state)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.RNNModelScratch(vocab_size, num_hiddens, ctx, get_params, init_state, forward)[source]

A RNN Model based on scratch implementations.

class d2l.mxnet.RandomGenerator(sampling_weights)[source]

Draw a random int in [0, n] according to n sampling weights.

class d2l.mxnet.Residual(num_channels, use_1x1conv=False, strides=1, **kwargs)[source]
forward(X)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.SNLIDataset(dataset, num_steps, vocab=None)[source]

A customized dataset to load the SNLI dataset.

class d2l.mxnet.Seq2SeqDecoder(vocab_size, embed_size, num_hiddens, num_layers, dropout=0, **kwargs)[source]
forward(X, state)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.Seq2SeqEncoder(vocab_size, embed_size, num_hiddens, num_layers, dropout=0, **kwargs)[source]
forward(X, *args)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.SeqDataLoader(batch_size, num_steps, use_random_iter, max_tokens)[source]

A iterator to load sequence data.

class d2l.mxnet.Timer[source]

Record multiple running times.

avg()[source]

Return the average time.

cumsum()[source]

Return the accumulated time.

start()[source]

Start the timer.

stop()[source]

Stop the timer and record the time in a list.

sum()[source]

Return the sum of time.

class d2l.mxnet.TokenEmbedding(embedding_name)[source]

Token Embedding.

class d2l.mxnet.TransformerEncoder(vocab_size, num_hiddens, ffn_num_hiddens, num_heads, num_layers, dropout, use_bias=False, **kwargs)[source]
forward(X, valid_len, *args)[source]

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*argslist of NDArray

Input tensors.

class d2l.mxnet.VOCSegDataset(is_train, crop_size, voc_dir)[source]

A customized dataset to load VOC dataset.

filter(imgs)[source]

Returns a new dataset with samples filtered by the filter function fn.

Note that if the Dataset is the result of a lazily transformed one with transform(lazy=False), the filter is eagerly applied to the transformed samples without materializing the transformed result. That is, the transformation will be applied again whenever a sample is retrieved after filter().

fncallable

A filter function that takes a sample as input and returns a boolean. Samples that return False are discarded.

Dataset

The filtered dataset.

d2l.mxnet.accuracy(y_hat, y)[source]

Compute the number of correct predictions.

d2l.mxnet.bbox_to_rect(bbox, color)[source]

Convert bounding box to matplotlib format.

d2l.mxnet.build_colormap2label()[source]

Build an RGB color to label mapping for segmentation.

d2l.mxnet.copyfile(filename, target_dir)[source]

Copy a file into a target directory.

d2l.mxnet.corr2d(X, K)[source]

Compute 2D cross-correlation.

class d2l.mxnet.defaultdict

defaultdict(default_factory[, …]) –> dict with default factory

The default factory is called without arguments to produce a new value when a key is not present, in __getitem__ only. A defaultdict compares equal to a dict with the same items. All remaining arguments are treated the same as if they were passed to the dict constructor, including keyword arguments.

copy() → a shallow copy of D.
default_factory

Factory for default value called by __missing__().

d2l.mxnet.download(name, cache_dir='../data')[source]

Download a file inserted into DATA_HUB, return the local filename.

d2l.mxnet.download_all()[source]

Download all files in the DATA_HUB

d2l.mxnet.download_extract(name, folder=None)[source]

Download and extract a zip/tar file.

d2l.mxnet.evaluate_accuracy(net, data_iter)[source]

Compute the accuracy for a model on a dataset.

d2l.mxnet.evaluate_loss(net, data_iter, loss)[source]

Evaluate the loss of a model on the given dataset.

d2l.mxnet.get_dataloader_workers()[source]

Use 4 processes to read the data expect for Windows.

d2l.mxnet.get_fashion_mnist_labels(labels)[source]

Return text labels for the Fashion-MNIST dataset.

d2l.mxnet.linreg(X, w, b)[source]

The linear regression model.

d2l.mxnet.load_array(data_arrays, batch_size, is_train=True)[source]

Construct a Gluon data iterator.

d2l.mxnet.load_data_fashion_mnist(batch_size, resize=None)[source]

Download the Fashion-MNIST dataset and then load it into memory.

d2l.mxnet.load_data_pikachu(batch_size, edge_size=256)[source]

Load the pikachu dataset.

d2l.mxnet.load_data_snli(batch_size, num_steps=50)[source]

Download the SNLI dataset and return data iterators and vocabulary.

d2l.mxnet.load_data_voc(batch_size, crop_size)[source]

Download and load the VOC2012 semantic dataset.

d2l.mxnet.masked_softmax(X, valid_len)[source]

Perform softmax by filtering out some elements.

d2l.mxnet.mkdir_if_not_exist(path)[source]

Make a directory if it does not exist.

d2l.mxnet.ones(shape, dtype=<class 'numpy.float32'>, order='C', ctx=None)

Return a new array of given shape and type, filled with ones. This function currently only supports storing multi-dimensional data in row-major (C-style).

shapeint or tuple of int

The shape of the empty array.

dtypestr or numpy.dtype, optional

An optional value type. Default is numpy.float32. Note that this behavior is different from NumPy’s ones function where float64 is the default value, because float32 is considered as the default data type in deep learning.

order{‘C’}, optional, default: ‘C’

How to store multi-dimensional data in memory, currently only row-major (C-style) is supported.

ctxContext, optional

An optional device context (default is the current default context).

outndarray

Array of ones with the given shape, dtype, and ctx.

>>> np.ones(5)
array([1., 1., 1., 1., 1.])
>>> np.ones((5,), dtype=int)
array([1, 1, 1, 1, 1], dtype=int64)
>>> np.ones((2, 1))
array([[1.],
       [1.]])
>>> s = (2,2)
>>> np.ones(s)
array([[1., 1.],
       [1., 1.]])
d2l.mxnet.plot(X, Y=None, xlabel=None, ylabel=None, legend=None, xlim=None, ylim=None, xscale='linear', yscale='linear', fmts='-', 'm--', 'g-.', 'r:', figsize=3.5, 2.5, axes=None)[source]

Plot data instances.

d2l.mxnet.predict_ch3(net, test_iter, n=6)[source]

Predict labels (defined in Chapter 3).

d2l.mxnet.read_csv_labels(fname)[source]

Read fname to return a name to label dictionary.

d2l.mxnet.read_snli(data_dir, is_train)[source]

Read the SNLI dataset into premises, hypotheses, and labels.

d2l.mxnet.read_time_machine()[source]

Load the time machine book into a list of sentences.

d2l.mxnet.read_voc_images(voc_dir, is_train=True)[source]

Read all VOC feature and label images.

d2l.mxnet.resnet18(num_classes)[source]

A slightly modified ResNet-18 model.

d2l.mxnet.set_axes(axes, xlabel, ylabel, xlim, ylim, xscale, yscale, legend)[source]

Set the axes for matplotlib.

d2l.mxnet.set_figsize(figsize=3.5, 2.5)[source]

Set the figure size for matplotlib.

d2l.mxnet.sgd(params, lr, batch_size)[source]

Minibatch stochastic gradient descent.

d2l.mxnet.show_bboxes(axes, bboxes, labels=None, colors=None)[source]

Show bounding boxes.

d2l.mxnet.show_images(imgs, num_rows, num_cols, titles=None, scale=1.5)[source]

Plot a list of images.

d2l.mxnet.show_trace_2d(f, results)[source]

Show the trace of 2D variables during optimization.

d2l.mxnet.split_batch(X, y, ctx_list)[source]

Split X and y into multiple devices specified by ctx.

d2l.mxnet.split_batch_multi_inputs(X, y, ctx_list)[source]

Split multi-input X and y into multiple devices.

d2l.mxnet.split_data_ml100k(data, num_users, num_items, split_mode='random', test_ratio=0.1)[source]

Split the dataset in random mode or seq-aware mode.

d2l.mxnet.squared_loss(y_hat, y)[source]

Squared loss.

d2l.mxnet.synthetic_data(w, b, num_examples)[source]

Generate y = Xw + b + noise.

d2l.mxnet.tokenize(lines, token='word')[source]

Split sentences into word or char tokens.

d2l.mxnet.train_2d(trainer, steps=20)[source]

Optimize a 2-dim objective function with a customized trainer.

d2l.mxnet.train_ch3(net, train_iter, test_iter, loss, num_epochs, updater)[source]

Train a model (defined in Chapter 3).

d2l.mxnet.train_epoch_ch3(net, train_iter, loss, updater)[source]

Train a model within one epoch (defined in Chapter 3).

d2l.mxnet.try_all_gpus()[source]

Return all available GPUs, or [cpu(),] if no GPU exists.

d2l.mxnet.try_gpu(i=0)[source]

Return gpu(i) if exists, otherwise return cpu().

d2l.mxnet.update_D(X, Z, net_D, net_G, loss, trainer_D)[source]

Update discriminator.

d2l.mxnet.update_G(Z, net_D, net_G, loss, trainer_G)[source]

Update generator.

d2l.mxnet.use_svg_display()[source]

Use the svg format to display a plot in Jupyter.

d2l.mxnet.voc_label_indices(colormap, colormap2label)[source]

Map an RGB color to a label.

d2l.mxnet.voc_rand_crop(feature, label, height, width)[source]

Randomly crop for both feature and label images.

d2l.mxnet.zeros(shape, dtype=<class 'numpy.float32'>, order='C', ctx=None)

Return a new array of given shape and type, filled with zeros. This function currently only supports storing multi-dimensional data in row-major (C-style).

shapeint or tuple of int

The shape of the empty array.

dtypestr or numpy.dtype, optional

An optional value type (default is numpy.float32). Note that this behavior is different from NumPy’s zeros function where float64 is the default value, because float32 is considered as the default data type in deep learning.

order{‘C’}, optional, default: ‘C’

How to store multi-dimensional data in memory, currently only row-major (C-style) is supported.

ctxContext, optional

An optional device context (default is the current default context).

outndarray

Array of zeros with the given shape, dtype, and ctx.

>>> np.zeros(5)
array([0., 0., 0., 0., 0.])
>>> np.zeros((5,), dtype=int)
array([0, 0, 0, 0, 0], dtype=int64)
>>> np.zeros((2, 1))
array([[0.],
       [0.]])
class d2l.torch.Accumulator(n)[source]

For accumulating sums over n variables.

class d2l.torch.Animator(xlabel=None, ylabel=None, legend=None, xlim=None, ylim=None, xscale='linear', yscale='linear', fmts='-', 'm--', 'g-.', 'r:', nrows=1, ncols=1, figsize=3.5, 2.5)[source]

For plotting data in animation.

class d2l.torch.Decoder(**kwargs)[source]

The base decoder interface for the encoder-decoder architecture.

forward(X, state)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class d2l.torch.DotProductAttention(dropout, **kwargs)[source]
forward(query, key, value, valid_len=None)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class d2l.torch.Encoder(**kwargs)[source]

The base encoder interface for the encoder-decoder architecture.

forward(X, *args)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class d2l.torch.EncoderDecoder(encoder, decoder, **kwargs)[source]

The base class for the encoder-decoder architecture.

forward(enc_X, dec_X, *args)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class d2l.torch.MLPAttention(key_size, query_size, units, dropout, **kwargs)[source]
forward(query, key, value, valid_len)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class d2l.torch.RNNModelScratch(vocab_size, num_hiddens, device, get_params, init_state, forward)[source]

A RNN Model based on scratch implementations.

class d2l.torch.Residual(input_channels, num_channels, use_1x1conv=False, strides=1)[source]
forward(X)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class d2l.torch.SeqDataLoader(batch_size, num_steps, use_random_iter, max_tokens)[source]

A iterator to load sequence data.

class d2l.torch.Timer[source]

Record multiple running times.

avg()[source]

Return the average time.

cumsum()[source]

Return the accumulated time.

start()[source]

Start the timer.

stop()[source]

Stop the timer and record the time in a list.

sum()[source]

Return the sum of time.

d2l.torch.accuracy(y_hat, y)[source]

Compute the number of correct predictions.

d2l.torch.corr2d(X, K)[source]

Compute 2D cross-correlation.

class d2l.torch.defaultdict

defaultdict(default_factory[, …]) –> dict with default factory

The default factory is called without arguments to produce a new value when a key is not present, in __getitem__ only. A defaultdict compares equal to a dict with the same items. All remaining arguments are treated the same as if they were passed to the dict constructor, including keyword arguments.

copy() → a shallow copy of D.
default_factory

Factory for default value called by __missing__().

d2l.torch.download(name, cache_dir='../data')[source]

Download a file inserted into DATA_HUB, return the local filename.

d2l.torch.download_all()[source]

Download all files in the DATA_HUB

d2l.torch.download_extract(name, folder=None)[source]

Download and extract a zip/tar file.

d2l.torch.evaluate_accuracy(net, data_iter)[source]

Compute the accuracy for a model on a dataset.

d2l.torch.evaluate_loss(net, data_iter, loss)[source]

Evaluate the loss of a model on the given dataset.

d2l.torch.get_dataloader_workers()[source]

Use 4 processes to read the data.

d2l.torch.get_fashion_mnist_labels(labels)[source]

Return text labels for the Fashion-MNIST dataset.

d2l.torch.linreg(X, w, b)[source]

The linear regression model.

d2l.torch.load_array(data_arrays, batch_size, is_train=True)[source]

Construct a PyTorch data iterator.

d2l.torch.load_data_fashion_mnist(batch_size, resize=None)[source]

Download the Fashion-MNIST dataset and then load it into memory.

d2l.torch.masked_softmax(X, valid_len)[source]

Perform softmax by filtering out some elements.

d2l.torch.mkdir_if_not_exist(path)[source]

Make a directory if it does not exist.

d2l.torch.ones(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor

Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size.

Args:
size (int…): a sequence of integers defining the shape of the output tensor.

Can be a variable number of arguments or a collection like a list or tuple.

out (Tensor, optional): the output tensor. dtype (torch.dtype, optional): the desired data type of returned tensor.

Default: if None, uses a global default (see torch.set_default_tensor_type()).

layout (torch.layout, optional): the desired layout of returned Tensor.

Default: torch.strided.

device (torch.device, optional): the desired device of returned tensor.

Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

requires_grad (bool, optional): If autograd should record operations on the

returned tensor. Default: False.

Example:

>>> torch.ones(2, 3)
tensor([[ 1.,  1.,  1.],
        [ 1.,  1.,  1.]])

>>> torch.ones(5)
tensor([ 1.,  1.,  1.,  1.,  1.])
d2l.torch.plot(X, Y=None, xlabel=None, ylabel=None, legend=None, xlim=None, ylim=None, xscale='linear', yscale='linear', fmts='-', 'm--', 'g-.', 'r:', figsize=3.5, 2.5, axes=None)[source]

Plot data instances.

d2l.torch.predict_ch3(net, test_iter, n=6)[source]

Predict labels (defined in Chapter 3).

d2l.torch.read_time_machine()[source]

Load the time machine book into a list of sentences.

d2l.torch.set_axes(axes, xlabel, ylabel, xlim, ylim, xscale, yscale, legend)[source]

Set the axes for matplotlib.

d2l.torch.set_figsize(figsize=3.5, 2.5)[source]

Set the figure size for matplotlib.

d2l.torch.sgd(params, lr, batch_size)[source]

Minibatch stochastic gradient descent.

d2l.torch.show_images(imgs, num_rows, num_cols, titles=None, scale=1.5)[source]

Plot a list of images.

d2l.torch.squared_loss(y_hat, y)[source]

Squared loss.

d2l.torch.synthetic_data(w, b, num_examples)[source]

Generate y = Xw + b + noise.

d2l.torch.tokenize(lines, token='word')[source]

Split sentences into word or char tokens.

d2l.torch.train_ch3(net, train_iter, test_iter, loss, num_epochs, updater)[source]

Train a model (defined in Chapter 3).

d2l.torch.train_ch6(net, train_iter, test_iter, num_epochs, lr, device=device(type='cuda', index=0))[source]

Train and evaluate a model with CPU or GPU.

d2l.torch.train_epoch_ch3(net, train_iter, loss, updater)[source]

The training loop defined in Chapter 3.

d2l.torch.try_all_gpus()[source]

Return all available GPUs, or [cpu(),] if no GPU exists.

d2l.torch.try_gpu(i=0)[source]

Return gpu(i) if exists, otherwise return cpu().

d2l.torch.use_svg_display()[source]

Use the svg format to display a plot in Jupyter.

d2l.torch.zeros(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor

Returns a tensor filled with the scalar value 0, with the shape defined by the variable argument size.

Args:
size (int…): a sequence of integers defining the shape of the output tensor.

Can be a variable number of arguments or a collection like a list or tuple.

out (Tensor, optional): the output tensor. dtype (torch.dtype, optional): the desired data type of returned tensor.

Default: if None, uses a global default (see torch.set_default_tensor_type()).

layout (torch.layout, optional): the desired layout of returned Tensor.

Default: torch.strided.

device (torch.device, optional): the desired device of returned tensor.

Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

requires_grad (bool, optional): If autograd should record operations on the

returned tensor. Default: False.

Example:

>>> torch.zeros(2, 3)
tensor([[ 0.,  0.,  0.],
        [ 0.,  0.,  0.]])

>>> torch.zeros(5)
tensor([ 0.,  0.,  0.,  0.,  0.])