Documentation

: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:

Finding All the Functions and Classes in a Module

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):

```{.python .input n=1} from mxnet import np print(dir(np.random))

  1. ```{.python .input n=1}
  2. #@tab pytorch
  3. import torch
  4. print(dir(torch.distributions))

```{.python .input n=1}

@tab tensorflow

import tensorflow as tf print(dir(tf.random))

  1. 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`).
  2. ## Finding the Usage of Specific Functions and Classes
  3. 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**].
  4. ```{.python .input}
  5. help(np.ones)

```{.python .input}

@tab pytorch

help(torch.ones)

  1. ```{.python .input}
  2. #@tab tensorflow
  3. 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:

```{.python .input} np.ones(4)

  1. ```{.python .input}
  2. #@tab pytorch
  3. torch.ones(4)

```{.python .input}

@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.

Summary

  • The official documentation provides plenty of descriptions and examples that are beyond this book.
  • We can look up documentation for the usage of an API by calling the dir and help functions, or ? and ?? in Jupyter notebooks.

Exercises

  1. Look up the documentation for any function or class in the deep learning framework. Can you also find the documentation on the official website of the framework?

:begin_tab:mxnet Discussions :end_tab:

:begin_tab:pytorch Discussions :end_tab:

:begin_tab:tensorflow Discussions :end_tab: