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

[MXNET-624] Clojure Package Api Docs for the Website #11574

Merged
merged 11 commits into from
Jul 10, 2018
Prev Previous commit
Next Next commit
fix up tutorial example with right namespaces
- get rid of getting started since it shows up in codox docs
  • Loading branch information
gigasquid committed Jul 5, 2018
commit 2344191bcb1f3416e1a937b08e72754faed9f1b9
2 changes: 0 additions & 2 deletions contrib/clojure-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ Do `lein run` for the cpu version or `lein run :gpu` for gpu.

To generate api docs, run `lein codox`. The html docs will be generated in the target/docs directory.

_Note: There is an error thrown in the generated code due to some loading issues, but the docs are all still there._

## Code Coverage

To run the Code Coverage tool. Run `lein cloverage`.
Expand Down
5 changes: 0 additions & 5 deletions contrib/clojure-package/doc/getting-started/Archlinux.md

This file was deleted.

8 changes: 0 additions & 8 deletions contrib/clojure-package/doc/getting-started/Ubuntu.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

(def arr (ndarray/ones [2 3]))

arr ;=> #object[ml.dmlc.mxnet.NDArray 0x482401ab "ml.dmlc.mxnet.NDArray@d8902656"]
arr ;=> #object[org.apache.mxnet.NDArray 0x597d72e "org.apache.mxnet.NDArray@e35c3ba9"]

(ndarray/shape-vec arr) ;=> [2 3]

Expand Down
41 changes: 23 additions & 18 deletions contrib/clojure-package/examples/tutorial/src/tutorial/module.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
act2 (sym/activation "relu2" {:data fc2 :act-type "relu"})
fc3 (sym/fully-connected "fc3" {:data act2 :num-hidden 10})
out (sym/softmax-output "softmax" {:data fc3})]
out) ;=> #object[ml.dmlc.mxnet.Symbol 0x2c7b036b "ml.dmlc.mxnet.Symbol@2c7b036b"]
out) ;=>#object[org.apache.mxnet.Symbol 0x1f43a406 "org.apache.mxnet.Symbol@1f43a406"]

;; You can also use as-> for easier threading

Expand Down Expand Up @@ -94,17 +94,17 @@
;;Modules provide high-level APIs for training, predicting, and evaluating. To fit a module, call the `fit` function with some DataIters:

(def mod (m/fit (m/module out) {:train-data train-data :eval-data test-data :num-epoch 1}))
;; INFO ml.dmlc.mxnet.module.BaseModule: Epoch[0] Train-accuracy=0.12521666
;; INFO ml.dmlc.mxnet.module.BaseModule: Epoch[0] Time cost=7863
;; INFO ml.dmlc.mxnet.module.BaseModule: Epoch[0] Validation-accuracy=0.2227
;; Epoch 0 Train- [accuracy 0.12521666]
;; Epoch 0 Time cost- 8392
;; Epoch 0 Validation- [accuracy 0.2227]


;; You can pass in batch-end callbacks using batch-end-callback and epoch-end callbacks using epoch-end-callback in the `fit-params`. You can also set parameters using functions like in the fit-params like optimizer and eval-metric. To learn more about the fit-params, see the fit-param function options. To predict with a module, call `predict` with a DataIter:

(def results (m/predict mod {:eval-data test-data}))
(first results) ;=> #object[ml.dmlc.mxnet.NDArray 0x270236e5 "ml.dmlc.mxnet.NDArray@9180e594"]
(first results) ;=>#object[org.apache.mxnet.NDArray 0x3540b6d3 "org.apache.mxnet.NDArray@a48686ec"]

(first (ndarray/->vec (first results))) ;=> 0.099454574
(first (ndarray/->vec (first results))) ;=>0.08261358

;;The module collects and returns all of the prediction results. For more details about the format of the return values, see the documentation for the `predict` function.

Expand Down Expand Up @@ -136,15 +136,19 @@
]))
(m/save-checkpoint mod {:prefix save-prefix :epoch epoch-num :save-opt-states true})))

;; INFO ml.dmlc.mxnet.module.Module: Saved checkpoint to my-model-0000.params
;; INFO ml.dmlc.mxnet.module.Module: Saved optimizer state to my-model-0000.states
;; INFO ml.dmlc.mxnet.module.Module: Saved checkpoint to my-model-0001.params
;; INFO ml.dmlc.mxnet.module.Module: Saved optimizer state to my-model-0001.states
;; INFO org.apache.mxnet.module.Module: Saved checkpoint to my-model-0000.params
;; INFO org.apache.mxnet.module.Module: Saved optimizer state to my-model-0000.states
;; INFO org.apache.mxnet.module.Module: Saved checkpoint to my-model-0001.params
;; INFO org.apache.mxnet.module.Module: Saved optimizer state to my-model-0001.states
;; INFO org.apache.mxnet.module.Module: Saved checkpoint to my-model-0002.params
;; INFO org.apache.mxnet.module.Module: Saved optimizer state to my-model-0002.states


;;To load the saved module parameters, call the `load-checkpoint` function:

(def new-mod (m/load-checkpoint {:prefix "my-model" :epoch 1 :load-optimizer-states true}))
;=> #object[ml.dmlc.mxnet.module.Module 0x352c8590 "ml.dmlc.mxnet.module.Module@352c8590"]

new-mod ;=> #object[org.apache.mxnet.module.Module 0x5304d0f4 "org.apache.mxnet.module.Module@5304d0f4"]

;;To initialize parameters, Bind the symbols to construct executors first with bind function. Then, initialize the parameters and auxiliary states by calling `init-params` function.

Expand All @@ -160,23 +164,24 @@

;; {:arg-params
;; {"fc3_bias"
;; #object[ml.dmlc.mxnet.NDArray 0x4fcda4a0 "ml.dmlc.mxnet.NDArray@70276e89"],
;; #object[org.apache.mxnet.NDArray 0x39adc3b0 "org.apache.mxnet.NDArray@49caf426"],
;; "fc2_weight"
;; #object[ml.dmlc.mxnet.NDArray 0x33651972 "ml.dmlc.mxnet.NDArray@b2a396eb"],
;; #object[org.apache.mxnet.NDArray 0x25baf623 "org.apache.mxnet.NDArray@a6c8f9ac"],
;; "fc1_bias"
;; #object[ml.dmlc.mxnet.NDArray 0x3ad02326 "ml.dmlc.mxnet.NDArray@b4110d31"],
;; #object[org.apache.mxnet.NDArray 0x6e089973 "org.apache.mxnet.NDArray@9f91d6eb"],
;; "fc3_weight"
;; #object[ml.dmlc.mxnet.NDArray 0x4c088d9b "ml.dmlc.mxnet.NDArray@19399ebd"],
;; #object[org.apache.mxnet.NDArray 0x756fd109 "org.apache.mxnet.NDArray@2dd0fe3c"],
;; "fc2_bias"
;; #object[ml.dmlc.mxnet.NDArray 0x3cca519d "ml.dmlc.mxnet.NDArray@61012c"],
;; #object[org.apache.mxnet.NDArray 0x1dc69c8b "org.apache.mxnet.NDArray@d128f73d"],
;; "fc1_weight"
;; #object[ml.dmlc.mxnet.NDArray 0xea5d61c "ml.dmlc.mxnet.NDArray@b16841b4"]},
;; #object[org.apache.mxnet.NDArray 0x20abc769 "org.apache.mxnet.NDArray@b8e1c5e8"]},
;; :aux-params {}}


;;To assign parameter and aux state values, use `set-params` function.

(m/set-params new-mod {:arg-params (m/arg-params new-mod) :aux-params (m/aux-params new-mod)})
;=>#object[ml.dmlc.mxnet.module.Module 0x11f34e1 "ml.dmlc.mxnet.module.Module@11f34e1"]
;=> #object[org.apache.mxnet.module.Module 0x5304d0f4 "org.apache.mxnet.module.Module@5304d0f4"]

;;To resume training from a saved checkpoint, instead of calling `set-params`, directly call `fit`, passing the loaded parameters, so that `fit` knows to start from those parameters instead of initializing randomly:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
(sym/fully-connected "fc2" {:data data :num-hidden 64})
(sym/softmax-output "out" {:data data}))

net ;=> #object[ml.dmlc.mxnet.Symbol 0x38c72806 "ml.dmlc.mxnet.Symbol@38c72806"]
net ;=> #object[org.apache.mxnet.Symbol 0x5c78c8c2 "org.apache.mxnet.Symbol@5c78c8c2"]

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

Expand Down