chapter_preliminaries/lookup-api_origin.md
:begin_tab:mxnet
Due to constraints on the length of this book, we cannot possibly introduce every single MXNet function and class (and you probably would not want us to). The API documentation and additional tutorials and examples provide plenty of documentation beyond the book. In this section we provide you with some guidance to exploring the MXNet API.
:end_tab:
:begin_tab:pytorch
Due to constraints on the length of this book, we cannot possibly introduce every single PyTorch function and class (and you probably would not want us to). The API documentation and additional tutorials and examples provide plenty of documentation beyond the book. In this section we provide you with some guidance to exploring the PyTorch API.
:end_tab:
:begin_tab:tensorflow
Due to constraints on the length of this book, we cannot possibly introduce every single TensorFlow function and class (and you probably would not want us to). The API documentation and additional tutorials and examples provide plenty of documentation beyond the book. In this section we provide you with some guidance to exploring the TensorFlow API.
:end_tab:
In order to know which functions and classes can be called in a module, we
invoke the dir function. For instance, we can (query all properties in the
module for generating random numbers):
from mxnet import np
print(dir(np.random))
#@tab pytorch
import torch
print(dir(torch.distributions))
#@tab tensorflow
import tensorflow as tf
print(dir(tf.random))
Generally, we can ignore functions that start and end with __ (special objects in Python) or functions that start with a single _(usually internal functions). Based on the remaining function or attribute names, we might hazard a guess that this module offers various methods for generating random numbers, including sampling from the uniform distribution (uniform), normal distribution (normal), and multinomial distribution (multinomial).
For more specific instructions on how to use a given function or class, we can invoke the help function. As an example, let us [explore the usage instructions for tensors' ones function].
help(np.ones)
#@tab pytorch
help(torch.ones)
#@tab tensorflow
help(tf.ones)
From the documentation, we can see that the ones function creates a new tensor with the specified shape and sets all the elements to the value of 1. Whenever possible, you should (run a quick test) to confirm your interpretation:
np.ones(4)
#@tab pytorch
torch.ones(4)
#@tab tensorflow
tf.ones(4)
In the Jupyter notebook, we can use ? to display the document in another
window. For example, list? will create content that is almost
identical to help(list), displaying it in a new browser
window. In addition, if we use two question marks, such as
list??, the Python code implementing the function will also be
displayed.
dir and help functions, or ? and ?? in Jupyter notebooks.:begin_tab:mxnet
Discussions
:end_tab:
:begin_tab:pytorch
Discussions
:end_tab:
:begin_tab:tensorflow
Discussions
:end_tab: