Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Revise Symbol tutorial #15343

Merged
merged 5 commits into from Jul 5, 2019
Merged

Conversation

Ishitori
Copy link
Contributor

Description

Revise and improve Symbol tutorial. Added section on weight tying and more links to the documentation.

@Ishitori Ishitori requested a review from szha as a code owner June 24, 2019 22:23
Copy link
Contributor

@thomelane thomelane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the updates @Ishitori. Apart from low-level suggestion, would want this tutorial to automatically determine context. And would add a short section on how to obtain a Symbol from Gluon Block to give the reader a better understanding of how these APIs work together.

@@ -71,20 +42,14 @@ To complete this tutorial, we need:
```
pip install jupyter
```
- GPUs - A section of this tutorial uses GPUs. If you don't have GPUs on your machine, simply
set the variable gpu_device to mx.cpu().
- GPUs (optional). A section of this tutorial uses GPUs. If you don't have GPUs on your machine, simply set the variable `gpu_device` to `mx.cpu()`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should automatically change context depending on whether a GPU is available or not.

Operators take symbol (or NDArray) as inputs and might also additionally accept
other hyperparameters such as the number of hidden neurons (*num_hidden*) or the
activation type (*act_type*) and produce the output.
Each symbol takes a unique string name. `NDArray` and `Symbol` both represent a single tensor. *Operators* represent the computation between tensors. Operators take `symbol` or `NDArray` as inputs and might also additionally accept other hyperparameters such as the number of hidden neurons (`num_hidden`) or the activation type (`act_type`) and produce the output.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symbol -> Symbol. Change other cases (but not non-code versions).

@@ -188,14 +144,9 @@ composed = net2(data2=net1, name='composed')
composed.list_arguments()
```

In this example, *net2* is used as a function to apply to an existing symbol *net1*,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

netx -> netx (for 1 and 2)

Finally, we can obtain the whole network by chaining multiple inception
modules. See a complete example
[here](https://github.com/dmlc/mxnet/blob/master/example/image-classification/symbols/inception-bn.py).
Finally, we can obtain the whole network by chaining multiple inception modules. See a [complete example](https://github.com/dmlc/mxnet/blob/master/example/image-classification/symbols/inception-bn.py).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo this change. Or if you wanted a larger link could include 'complete example' in the link.

# infers output type given the type of input arguments
arg_type, out_type, _ = c.infer_type(a='float32', b='float32')
{'input' : dict(zip(arg_name, arg_shape)),
'output' : dict(zip(out_name, out_shape))}
'output' : dict(zip(out_name, out_shape))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would say the original style is better.

are inputs/outputs of operators. We can either serialize a `Symbol` object by
using `pickle`, or by using `save` and `load` methods directly as we discussed in
[NDArray tutorial](http://mxnet.io/tutorials/basic/ndarray.html#serialize-from-to-distributed-filesystems).
Logically symbols correspond to NDArrays. They both represent a tensor. They both are inputs/outputs of operators. We can either serialize a `Symbol` object by using `pickle`, or by using `save` and `load` methods directly as it is explained in [NDArray tutorial](http://mxnet.io/tutorials/basic/ndarray.html#serialize-from-to-distributed-filesystems).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explained in [NDArray tutorial] -> explained in [this NDArray tutorial]

using any front-end language such as Python. It often makes the developing and
debugging much easier. To implement an operator in Python, refer to
[How to create new operators](http://mxnet.io/faq/new_op.html).
Most operators such as [mx.sym.Convolution](https://mxnet.incubator.apache.org/api/python/symbol/symbol.html#mxnet.symbol.Convolution) and [mx.sym.Reshape](https://mxnet.incubator.apache.org/api/python/symbol/symbol.html#mxnet.symbol.reshape) are implemented in C++ for better performance. MXNet also allows users to write new operators using any front-end language such as Python. It often makes the developing and debugging much easier. To implement an operator in Python, refer to [How to create new operators](http://mxnet.io/faq/new_op.html).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the in-line code rendering? (e.g. code)? Can still add a link to the in-line code.

ex = b.bind(ctx=mx.cpu(), args={'a':data, 'b':data})
ex.forward()
ex.outputs[0].asnumpy()
```

### Weight tying

You can use same principle to tie weights of different layers. In the example below two `FullyConnected` layers share same weights and biases, but process different data. Find a full example below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain a little more about where to look or what's going on? It's quite a long code block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful example though!


- Learn how to [use Module API to train neural network](https://mxnet.incubator.apache.org/versions/master/tutorials/basic/module.html)

- Explore ways you can [load data from disk](https://mxnet.incubator.apache.org/versions/master/tutorials/basic/data.html)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would link to a hybridization tutorial instead.


## Recommended Next Steps

- Learn how to [use Module API to train neural network](https://mxnet.incubator.apache.org/versions/master/tutorials/basic/module.html)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add . at end of sentences.

@thomelane
Copy link
Contributor

Cheers for the updates. I think the weight tying example description should go above the code block. Or even better can the code be broken into some sections, and the descriptions be inserted at the correct places. It's a long example.

@thomelane
Copy link
Contributor

Yep, looks a lot better, thanks. LGTM.

@anirudhacharya
Copy link
Member

@mxnet-label-bot add [pr-awaiting-review]

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Jun 28, 2019
@ThomasDelteil ThomasDelteil merged commit 728b8db into apache:master Jul 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants