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
NDManager. In this class you will see all the functions
that can be called and any information or documentation regarding them.
To explore an example, if we were interested in functions that handled
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
ones function which takes a
Shape as a parameter.
From the documentation, we can see that the
ones function creates a
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:
// %mavenRepo snapshots https://oss.sonatype.org/content/repositories/snapshots/ %maven ai.djl:api:0.9.0 %maven org.slf4j:slf4j-api:1.7.26 %maven org.slf4j:slf4j-simple:1.7.26 %maven ai.djl.mxnet:mxnet-engine:0.9.0 %maven ai.djl.mxnet:mxnet-native-auto:1.7.0-backport import ai.djl.ndarray.*; import ai.djl.ndarray.types.Shape;
NDManager manager = NDManager.newBaseManager(); manager.ones(new Shape(4))
ND: (4) gpu(0) float32 [1., 1., 1., 1.]
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.
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?