Documentation

Dive into Deep Learning · §1.7

APIs change; the skill of looking things up doesn’t
discover · inspect · read · verify.

You cannot memorize an API, so loop instead

Motivation

No book covers a whole framework, and the libraries keep changing under us. The durable skill is a four-move loop, run without leaving the notebook, repeated until the call does what you want.

The official docs remain the source of truth: bookmark your framework’s reference and tutorial pages.

Figuring out an unfamiliar API: a repeatable loopDiscoverdir() · TabInspecthelp() · ?Readdocs · source ??Verifyrun a quick teststill stuck? refine the query and loop

dir discovers what exists

Discover

Know roughly where a tool should live, but not its name? dir lists a module’s contents; the names alone sketch what is on offer:

print([name for name in dir(torch.distributions)
       if not name.startswith('_')][:20])
['AbsTransform', 'AffineTransform', 'Bernoulli', 'Beta', 'Binomial', 'CatTransform', 'Categorical', 'Cauchy', 'Chi2', 'ComposeTransform', ...

Skip the _-prefixed internals. In a notebook, module. + Tab gives the same list, filtered as you type, usually the fastest way to turn up a name.

help reads the signature; ?? reads the source

Inspect · read

help(...) prints the docstring: arguments, defaults, return value, often an example.

help(torch.ones)

In Jupyter, ones? opens the docstring in a side pane, and ones?? shows the source code: the final word when a docstring is terse or ambiguous.

A tiny run settles it

Verify

Docstrings drift out of date; a running call does not lie:

torch.ones(4)
tensor([1., 1., 1., 1.])

Exactly the promised shape and values. This discover → inspect → read → verify loop outlives every function in this book.

Coding assistants enter the same loop

Assistants

An assistant usually produces a plausible function and a working call in seconds. Treat the suggestion like a knowledgeable colleague’s tip: a good starting point that still gets a two-line check before you build on it.

Glance at the signature (help / ?), then run a small example. A suggestion that survives both is one you can rely on.

Recap

Wrap-up

  • Discover with dir (or Tab-completion).
  • Inspect with help / ?; read the source with ??.
  • Verify with a tiny run.
  • Assistant answers enter the same loop before you rely on them.