Attend a 3-Day Introductory Deep Learning Workshop View Upcoming Workshops »

Deep Learning With Clojure

Deeplearning4j has been ported to Clojure with the DL4CLJ project. The present Github examples illustrate how to configure recurrent neural networks, word2vec and ParaVec based on Deeplearning4j. More details on the Clojar are here.

A Recurrent Neural Network in Clojure

Here’s what a recurrent neural network configuration looks like in Clojure with DL4CLJ:

  ;; Set up network configuration:
  (def conf (neural-net-configuration
             {:optimization-algo :stochastic-gradient-descent
              :iterations 1
              :learning-rate 0.1
              :rms-decay 0.95
              :seed 12345
              :regularization true
              :l2 0.001
              :list 3
              :layers {0 {:graves-lstm
                          {:n-in (input-columns iter)
                           :n-out lstm-layer-size
                           :updater :rmsprop
                           :activation :tanh
                           :weight-init :distribution
                           :dist {:uniform {:lower -0.08, :upper 0.08}}}}
                       1 {:graves-lstm
                          {:n-in lstm-layer-size
                           :n-out lstm-layer-size
                           :updater :rmsprop
                           :activation :tanh
                           :weight-init :distribution
                           :dist {:uniform {:lower -0.08, :upper 0.08}}}}
                       2 {:rnnoutput
                          {:loss-function :mcxent
                           :activation :softmax
                           :updater :rmsprop
                           :n-in lstm-layer-size
                           :n-out (total-outcomes iter)
                           :weight-init :distribution
                           :dist {:uniform {:lower -0.08, :upper 0.08}}}}}
              :pretrain false
              :backprop true}))
  (def net (multi-layer-network conf))
  (init net)
  ;; not yet implemented:
  ;; net.setListeners(new ScoreIterationListener(1));

  ;; Print the  number of parameters in the network (and for each layer)
  (dotimes [i (count (get-layers net))]
    (println "Number of parameters in layer "  i  ": "  (model/num-params (get-layer net i))))
  (println "Total number of network parameters: " (reduce + (map model/num-params (get-layers net))))

Clojure Resources

Those just beginning with Clojure may want to explore the resources below:

Other Deeplearning4j Languages

Deeplearning4j also offers APIs in Java, Scala and Python with Keras.

Chat with us on Gitter