Run this notebook online:Binder or Colab: Colab

2.7. Documentation

Due to constraints on the length of this book, we cannot possibly introduce every single DJL 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 DJL API.

2.7.1. Finding All the Functions and Classes in a Module

In order to know which functions and classes can be called, we can go to the javadocs for DJL which can be seen here: https://javadoc.io/doc/ai.djl/api/latest/index.html

There we can search for the class that we are interested in exploring. For instance, we can go to the All Classes box on the left and search for NDManager. In this class you will see all the functions that can be called and any information or documentation regarding them.

https://javadoc.io/doc/ai.djl/api/latest/ai/djl/ndarray/NDManager.html

To explore an example, if we were interested in functions that handled generating NDArrays with random numbers, we could search for the functions that start with random or that contain random in their description. By doing this, we can see that there are a few functions that actually do what we want. To mention a few: - randomInteger(long low, long high, Shape shape, DataType dataType) - randomMultinomial(int n, NDArray pValues) - randomMultinomial(int n, NDArray pValues, Shape shape) - randomNormal(float loc, float scale, Shape shape, DataType dataType) - randomUniform(float low, float high, Shape shape)

2.7.2. Finding the Usage of Specific Functions and Classes

For more specific instructions on how to use a given function or class, we can click the desired function or go to it directly by scrolling down and searching for it. As an example, let us explore the usage instructions for NDManager’s ones function which takes a Shape as a parameter.

https://javadoc.io/static/ai.djl/api/0.20.0/ai/djl/ndarray/NDManager.html#ones(ai.djl.ndarray.types.Shape)

From the documentation, we can see that the ones function creates a new NDArray 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:

%load ../utils/djl-imports
NDManager manager = NDManager.newBaseManager();
manager.ones(new Shape(4))
ND: (4) gpu(0) float32
[1., 1., 1., 1.]

2.7.3. 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 accessing the javadoc directly.

2.7.4. Exercises

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