GithubHelp home page GithubHelp logo

hswick / jutsu.ai Goto Github PK

View Code? Open in Web Editor NEW
99.0 12.0 10.0 98 KB

Clojure wrapper for deeplearning4j

License: Eclipse Public License 1.0

Clojure 100.00%
deeplearning4j clojure machine-learning jutsu

jutsu.ai's Introduction

jutsu.ai

Clojure wrapper for deeplearning4j with some added syntactic sugar.

What if I told you that you could do machine learning on the JVM without wanting to cry or set your hair on fire? The goal of this library is to be the most syntactically elegant machine learning library for Clojure/Java ecosystem. jutsu.ai uses Clojure specific code idioms, like Data as Code, to create an aesthetic and declarative api.

jutsu.ai makes use of my laziest but cleverest achievement which is that the network configuration translates clojure keywords into java method calls. The implication of this is that the majority of the config options provided by deeplearning4j are accessible with this library.

The best of all, no more snakes!

alt text

Currently this project is a work in progress. However, no drastic API changes are expected. Configurations have been tested on basic feedforward nets, RNN's, and CNN's. If you can't seem to find a configuration feature you are looking for submit an issue and I'll do my best to help.

If you have any suggestions or fixes please feel free to submit a PR as well!

Currently need help documenting the different configuration options. However, deeplearning4j has a very good resource that I recommend checking out.

Usage

Install jutsu.ai by including this in your project dependencies:

[hswick/jutsu.ai "0.1.5"]

You will also need to include a ND4J backend:

For CPU:

[org.nd4j/nd4j-native-platform "1.0.0-beta"]

For GPU:

[org.nd4j/nd4j-cuda-8.0-platform "1.0.0-beta"]

Here is a toy example demonstrating classifying the well known iris dataset.

(ns skynet.core
  (:require [jutsu.ai.core :as ai]))

;;Example configuration of a simple multilayer feedforward neural network architecture
;;classifying the iris dataset.
(def iris-net-config
	[:layers 
		[[:dense [:n-in 4 :n-out 10 :activation :relu]]
	 	 [:dense [:n-in 10 :n-out 10 :activation :relu]]
	 	 [:output :negative-log-likelihood [:n-in 10 :n-out 3 :activation :softmax]]]])

(def iris-net
	(-> iris-net-config
		ai/network
		ai/initialize-net))

(defn iris-train []
  (let [iris-iterator (ai/classification-csv-iterator "iris.csv" 150 4 3)]
    (-> iris-net
	(ai/train-net! 200 iris-iterator)
	(ai/save-model "iris-model"))
  (.reset iris-iterator)
  (println (ai/evaluate iris-net iris-iterator))))

(iris-train)

Documentation

Make sure to take a look at the wiki for more documentation.

Here is a video tutorial I made demonstrating the use of jutsu.ai.

Additional Resources

Here is a list of libraries that I have created to be used with jutsu.ai:

  • jutsu.matrix Clojure wrapper around ND4J to make it easier to work with the underlying matrices in DL4J.
  • jutsu.nlp Clojure wrapper around DL4J's NLP features. Provides useful abstractions for Word Vectors.
  • jutsu.ai.ui GUI for visualizing DL4J training
  • jutsu Simple web based graphing tool for Clojure

Here is a list of libraries that I've found useful when working with jutsu.ai:

  • claypoole Juiced up clojure functions like pmap. Very useful when working with big data sets.
  • tablesaw Table slicing tool for Java. Nice API and extremely performant.

Dev

Run boot night to startup nightlight and begin editing the project in a browser.

Contributing

When changing project dependencies or project version number, make sure to update this in the build.boot file. The Travis build uses boot, and will not pass the checks unless you update it.

The project.clj file is simple there to make it easier for other developers to contribute.

License

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

jutsu.ai's People

Contributors

delayedchoice avatar enragedginger avatar hswick avatar tiagodalloca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jutsu.ai's Issues

"boot night" not working

boot night from terminal at the project root prints the following stacktrace:

                                                  Boot.main                          Boot.java:  257
                                                        ...                                         
   jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke  DelegatingMethodAccessorImpl.java:   43
       jdk.internal.reflect.NativeMethodAccessorImpl.invoke      NativeMethodAccessorImpl.java:   62
      jdk.internal.reflect.NativeMethodAccessorImpl.invoke0       NativeMethodAccessorImpl.java     
                                              boot.App.main                           App.java:  491
                                           boot.App.runBoot                           App.java:  399
org.projectodd.shimdandy.impl.ClojureRuntimeShimImpl.invoke        ClojureRuntimeShimImpl.java:  150
org.projectodd.shimdandy.impl.ClojureRuntimeShimImpl.invoke        ClojureRuntimeShimImpl.java:  159
                                                        ...                                         
                                            boot.main/-main                           main.clj:  216
                                         boot.main/-main/fn                           main.clj:  216
                                   clojure.core/load-string                           core.clj: 3959
                                   clojure.core/load-reader                           core.clj: 3957
                                                        ...                                         
                                    boot.user$eval99.invoke                                   :   34
                              boot.user$eval99.invokeStatic                                   :   34
                                                        ...                                         
                                       clojure.core/require                           core.clj: 5796 (repeats 2 times)
                                         clojure.core/apply                           core.clj:  648
                                                        ...                                         
                                     clojure.core/load-libs                           core.clj: 5758
                                     clojure.core/load-libs                           core.clj: 5774
                                         clojure.core/apply                           core.clj:  648
                                                        ...                                         
                                      clojure.core/load-lib                           core.clj: 5717
                                      clojure.core/load-lib                           core.clj: 5736
                                   clojure.core/load-lib/fn                           core.clj: 5737
                                      clojure.core/load-one                           core.clj: 5697
                                                        ...                                         
                                          clojure.core/load                           core.clj: 5876
                                          clojure.core/load                           core.clj: 5892
                                       clojure.core/load/fn                           core.clj: 5893
                                                        ...                                         
                                    nightlight.boot/eval105                           boot.clj:    1
                    nightlight.boot/eval105/loading--auto--                           boot.clj:    1
                                                        ...                                         
                                       clojure.core/require                           core.clj: 5796 (repeats 2 times)
                                         clojure.core/apply                           core.clj:  648
                                                        ...                                         
                                     clojure.core/load-libs                           core.clj: 5758
                                     clojure.core/load-libs                           core.clj: 5774
                                         clojure.core/apply                           core.clj:  648
                                                        ...                                         
                                      clojure.core/load-lib                           core.clj: 5717
                                      clojure.core/load-lib                           core.clj: 5736
                                   clojure.core/load-lib/fn                           core.clj: 5737
                                      clojure.core/load-one                           core.clj: 5697
                                                        ...                                         
                                          clojure.core/load                           core.clj: 5876
                                          clojure.core/load                           core.clj: 5892
                                       clojure.core/load/fn                           core.clj: 5893
                                                        ...                                         
                                    nightlight.core/eval111                           core.clj:    1
                    nightlight.core/eval111/loading--auto--                           core.clj:    1
                                                        ...                                         
                                       clojure.core/require                           core.clj: 5796 (repeats 2 times)
                                         clojure.core/apply                           core.clj:  648
                                                        ...                                         
                                     clojure.core/load-libs                           core.clj: 5758
                                     clojure.core/load-libs                           core.clj: 5774
                                         clojure.core/apply                           core.clj:  648
                                                        ...                                         
                                      clojure.core/load-lib                           core.clj: 5717
                                      clojure.core/load-lib                           core.clj: 5736
                                   clojure.core/load-lib/fn                           core.clj: 5737
                                      clojure.core/load-one                           core.clj: 5697
                                                        ...                                         
                                          clojure.core/load                           core.clj: 5876
                                          clojure.core/load                           core.clj: 5892
                                       clojure.core/load/fn                           core.clj: 5893
                                                        ...                                         
                                   nightlight.repl/eval1595                           repl.clj:    1
                   nightlight.repl/eval1595/loading--auto--                           repl.clj:    1
                                                        ...                                         
                                       clojure.core/require                           core.clj: 5796 (repeats 2 times)
                                         clojure.core/apply                           core.clj:  648
                                                        ...                                         
                                     clojure.core/load-libs                           core.clj: 5758
                                     clojure.core/load-libs                           core.clj: 5774
                                         clojure.core/apply                           core.clj:  648
                                                        ...                                         
                                      clojure.core/load-lib                           core.clj: 5717
                                      clojure.core/load-lib                           core.clj: 5736
                                   clojure.core/load-lib/fn                           core.clj: 5737
                                      clojure.core/load-one                           core.clj: 5697
                                                        ...                                         
                                          clojure.core/load                           core.clj: 5876
                                          clojure.core/load                           core.clj: 5892
                                       clojure.core/load/fn                           core.clj: 5893
                                                        ...                                         
                                org.httpkit.server/eval1601                         server.clj:    1
                org.httpkit.server/eval1601/loading--auto--                         server.clj:    1
                                                        ...                                         
                                    java.lang.Class.forName                         Class.java:  375
                                   java.lang.Class.forName0                          Class.java     
                            java.lang.ClassLoader.loadClass                   ClassLoader.java:  496
                                                        ...                                         
                            java.lang.ClassLoader.loadClass                   ClassLoader.java:  563
                                                        ...                                         
                          java.net.URLClassLoader.findClass                URLClassLoader.java:  466
java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
      clojure.lang.ExceptionInfo: javax.xml.bind.DatatypeConverter
    line: 1

Example code not picking one of the classes

When I run your example code unchanged, I get the following output:
========================Evaluation Metrics========================

of classes: 3

Accuracy: 0.6667
Precision: 0.7124 (1 class excluded from average)
Recall: 0.6667
F1 Score: 0.8189 (1 class excluded from average)
Precision, recall & F1: macro-averaged (equally weighted avg. of 3 classes)

Warning: 1 class was never predicted by the model and was excluded from average precision
Classes excluded from average precision: [1]

=========================Confusion Matrix=========================
0 1 2

50 0 0 | 0 = 0
6 0 44 | 1 = 1
0 0 50 | 2 = 2

Confusion matrix format: Actual (rowClass) predicted as (columnClass) N times

Here is my code ( a copy of your with a different namespace and a -main function)

(ns clj-tf2.core
(:require [jutsu.ai.core :as ai]))

;;Example configuration of a simple multilayer feedforward neural network architecture
;;classifying the iris dataset.
(def iris-net-config
[:layers
[[:dense [:n-in 4 :n-out 10 :activation :relu]]
[:dense [:n-in 10 :n-out 10 :activation :relu]]
[:output :negative-log-likelihood [:n-in 10 :n-out 3 :activation :softmax]]]])

(def iris-net
(-> iris-net-config
ai/network
ai/initialize-net))

(defn iris-train []
(let [iris-iterator (ai/classification-csv-iterator "iris.csv" 150 4 3)]
(-> iris-net
(ai/train-net! 200 iris-iterator)
(ai/save-model "iris-model"))
(.reset iris-iterator)
(println (ai/evaluate iris-net iris-iterator))))

(defn -main []
(iris-train))

DL4J version seems to be 0.8.0 (still)

I was having a series of bugs in apparently related to unmatching versions of DL4J, even though using [hswick/jutsu.ai "0.1.1"] which should use the latest version 0.9.1.

Searching through maven downloaded dependencies, I found what a suspected:

~/.m2/repository/hswick/jutsu.ai/0.1.1/jutsu.ai-0.1.1.pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>hswick</groupId>
  <artifactId>jutsu.ai</artifactId>
  <version>0.1.1</version>
  <name>jutsu.ai</name>
  <description>Clojure wrapper for deeplearning4j intended to make machine learning on the JVM simpler</description>
  <url>https://github.com/author/jutsu.ai</url>
  <licenses/>
  <packaging>jar</packaging>
  <dependencies>
    <dependency>
      <groupId>org.clojure</groupId>
      <artifactId>clojure</artifactId>
      <version>1.8.0</version>
      <scope>compile</scope>
      <exclusions/>
    </dependency>
    <dependency>
      <groupId>nightlight</groupId>
      <artifactId>nightlight</artifactId>
      <version>1.7.2</version>
      <scope>test</scope>
      <exclusions/>
    </dependency>
    <dependency>
      <groupId>adzerk</groupId>
      <artifactId>boot-test</artifactId>
      <version>1.2.0</version>
      <scope>test</scope>
      <exclusions/>
    </dependency>
    <dependency>
      <groupId>org.nd4j</groupId>
      <artifactId>nd4j-native-platform</artifactId>
      <version>0.8.0</version>
      <scope>compile</scope>
      <exclusions/>
    </dependency>
    <dependency>
      <groupId>org.deeplearning4j</groupId>
      <artifactId>deeplearning4j-core</artifactId>
      <version>0.8.0</version>
      <scope>compile</scope>
      <exclusions/>
    </dependency>
    <dependency>
      <groupId>org.nd4j</groupId>
      <artifactId>nd4j-api</artifactId>
      <version>0.8.0</version>
      <scope>compile</scope>
      <exclusions/>
    </dependency>
    <dependency>
      <groupId>hswick</groupId>
      <artifactId>jutsu.matrix</artifactId>
      <version>0.0.14</version>
      <scope>test</scope>
      <exclusions/>
    </dependency>
    <dependency>
      <groupId>org.datavec</groupId>
      <artifactId>datavec-api</artifactId>
      <version>0.8.0</version>
      <scope>compile</scope>
      <exclusions/>
    </dependency>
  </dependencies>
</project>

Note that version 0.8.0 is still in use.

How can you load data from a vector

Hi!

Awesome library. I'm trying to test out some different data sets and I'd like to just load a data set from memory or pull it from a different database and evaluate it in the repl without converting it to a CSV first. Is this possible?

Convert clojure data -> NDArrayWritable

See here for a discussion on the desired feature.

In summary: It would be great to have a way to input plain clojure data into a model to train.

Seems like the best way to do this is to go from clojure vectors to NDArray to NDArrayWritable. jutsu.matrix already provides a way to go from clojure vectors to NDArrays, so the next step would to convert the NDArray to a NDArrayWritable.

Im posting this as a separate issue because I think this would be a great first issue for someone to tackle, and would be very helpful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.