enterprise deep learning workflows with dl4j josh patterson strata singapore 2015

35
Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Upload: claud-briggs

Post on 19-Jan-2016

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Enterprise Deep Learning Workflows

With DL4JJosh Patterson

Strata Singapore 2015

Page 2: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Presenter: Josh Patterson

Past

Research in Swarm Algorithms: Real-time optimization techniques in mesh sensor networks

TVA / NERC: Smartgrid, Sensor Collection, and Big Data

Cloudera: Principal SA, Working with Fortune 500

Today

Patterson Consulting

Skymind (Advisor)

[email protected] / @jpatanoogaDL4J Co-creator, Co-Author on Upcoming Oreilly Book “Deep

Learning: A Practitioner’s Approach”

Page 3: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Topics

• What is Deep Learning?• Operating in the Enterprise• DL4J• Enterprise Grade Deep Learning Workflows

Page 4: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

WHAT IS DEEP LEARNING?

Page 5: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

We Want to be able to recognize Handwriting

This is a Hard Problem

Page 6: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Automated Feature Engineering

• Deep Learning can be thought of as workflows for automated feature construction– Where previously we’d consider each stage in the

workflow as unique technique• Many of the techniques have been around for

years– But now are being chained together in a way that

automates exotic feature engineering• As LeCun says:– “machines that learn to represent the world”

Page 7: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015
Page 8: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015
Page 9: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

These are the features learned at each neuron in a Restricted Boltzmann Machine (RBMS)

These features are passed to higher levels of RBMs to learn more complicated things.

Part of the “7” digit

Page 10: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Learning Progressive Layers

Page 11: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Deep Learning Architectures

• Deep Belief Networks– Most common architecture

• Convolutional Neural Networks– State of the art in image classification

• Recurrent Networks– Timeseries – Any sequence of input vectors

• Recursive Networks– Text / image– Can break down scenes

Page 12: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

ENTERPRISEOperating in the

Page 13: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Enterprise User Types• Data Businesspeople

– product and profit-focused– manager with a technical bent.– engineering degree paired with an MBA

• Data Creatives – jacks-of-all-trades– artists or hackers

• Data Developers– write software to do analytic, statistical, and machine learning tasks– computer science degrees, often work with so-called “big data”

• Data Researchers– PhDs - apply their scientific training,– Use of mathematical tools yields valuable insights and products

Page 14: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Python Island

The “Hotel California” of Enterprise Data Science

Page 15: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Issues in Machine Learning

• Data Gravity– We need to process the data in workflows where the data lives

• If you move data you don’t have big data

– Even if the data is not “big” we still want simpler workflows• Integration Issues

– Ingest, ETL, Vectorization, Modeling, Evaluation, and Deployment issues

– Most ML tools are built with previous generation architectures in mind

• Legacy Architectures– Parallel iterative algorithm architectures are not common

Page 16: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015
Page 17: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

So What Do We Need For the Enterprise?

• Ability to work with small and big data easily– Don’t want to change tooling because we moved to

Hadoop• Ability to not get caught up in things like

vectorization and ETL– Need to focus on better models, less on minutia– (Knowing data is still important)

• Ability to experiment with lots of models– Yet be able to take something to production without a

huge headache / re-write

Page 18: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

DL4JNext Generation Deep Learning with

Page 19: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

DL4J• “The Hadoop of Deep Learning”

– Command line driven– Java, Scala, and Python APIs– ASF 2.0 Licensed

• Java implementation– Parallelization (Yarn, Spark)– GPU support

• Also Supports multi-GPU per host

• Runtime Neutral– Local– Hadoop / YARN + Spark– AWS

• https://github.com/deeplearning4j/deeplearning4j

Page 20: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

DL4J Suite of Tools

• DL4J– Main library for deep learning

• Canova– Vectorization library

• ND4J– Linear Algebra framework – Swappable backends (JBLAS, GPUs):

• http://www.slideshare.net/agibsonccc/future-of-ai-on-the-jvm

• Arbiter– Model evaluation and testing platform

Page 21: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Github Stars• Caffe: 7,728• Theano: 2,502• DL4J: 1,663

Other Popular Projects• Mesos: 1,885• Kafka: 2,286

Page 22: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

DL4J API Example SVMLightRecordReader recordReader = new SVMLightRecordReader(); recordReader.initialize(svm_conf, new FileSplit( svmLightDemo )); DataSetIterator iterator = new RecordReaderDataSetIterator( recordReader, batchSize, 16, 2 );

SVMLightRecordReader recordReaderTestData = new SVMLightRecordReader(); recordReaderTestData.initialize(svm_conf, new FileSplit( new File( ”./data/full_balanced_svmlight_dataset.txt" ) ) ); DataSetIterator iterator_test = new RecordReaderDataSetIterator( recordReaderTestData, testbatchSize, 16, 2 ); DataSet next_test = iterator_test.next(); MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(123) .optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT) .iterations( iterations ) .list(3) .layer(0, new DenseLayer.Builder() .nIn( numColumns ).nOut(80) .weightInit(WeightInit.XAVIER) .activation("relu") .build()) .layer(1, new DenseLayer.Builder() .nIn( 80 ).nOut(60) .weightInit(WeightInit.XAVIER) .activation("relu") .build()) .layer(2, new org.deeplearning4j.nn.conf.layers.OutputLayer.Builder(LossFunctions.LossFunction.MCXENT) .nIn(60).nOut(2) .activation("softmax") .weightInit(WeightInit.XAVIER) .build()) .backprop(true) .build();

MultiLayerNetwork model = new MultiLayerNetwork(conf); model.init(); model.fit(iterator);

Page 23: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

DEEP LEARNING WORKFLOWSEnterprise Grade

Page 24: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Building Deep Learning Workflows

• Need to have flexibility where we build / apply the model– Local – AWS– Spark / Hadoop

• We need to get data from a raw format into a baseline raw vector– Model the data– Evaluate the Model

• Traditionally these are all tied together in one tool– But this is a monolithic pattern– We’d like to apply the unix principles here

• The DL4J Suite of Tools lets us do this

Page 25: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Loading Existing ModelsString jsonModelConf = loadTextFileFromDisk( pathToModelJSON );

MultiLayerConfiguration confFromJson = MultiLayerConfiguration.fromJson( jsonModelConf );

FSDataInputStream hdfsInputStream_ModelParams = hdfs.open(new Path( hdfsPathToModelParams ));

DataInputStream dis = new DataInputStream( hdfsInputStream_ModelParams );INDArray newParams = Nd4j.read( dis );dis.close();MultiLayerNetwork savedNetwork = new MultiLayerNetwork( confFromJson );savedNetwork.init();savedNetwork.setParameters(newParams);

Page 26: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

DL4J Spark JobMultiLayerConfiguration confFromJson = MultiLayerConfiguration.fromJson( jsonBuffer.toString() );MultiLayerNetwork savedNetwork = new MultiLayerNetwork( confFromJson );savedNetwork.init();

RDD<LabeledPoint> evaluate_svmLight_data_rdd = MLUtils.loadLibSVMFile( sc.sc(), hdfsFilesToTrainModel, true, parsedSVMLightFeatureColumns );

JavaRDD<LabeledPoint> evaluate_svmLight_data_JavaRDD = JavaRDD.fromRDD( evaluate_svmLight_data_rdd, ClassManifestFactory.fromClass(LabeledPoint.class) );

SparkDl4jMultiLayer trainLayerSpark = new SparkDl4jMultiLayer( sc.sc(), confFromJson );

MultiLayerNetwork trainedNetwork = trainLayerSpark.fit( sc, evaluate_svmLight_data_JavaRDD );

final SparkDl4jMultiLayer completedModelFromSparkToSave = new SparkDl4jMultiLayer(sc.sc(),trainedNetwork);

https://github.com/deeplearning4j/dl4j-spark-cdh5-examples

Page 27: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Turn on GPUs and Spark

<dependency> <groupId>org.deeplearning4j</groupId> <artifactId>dl4j-spark</artifactId> <version>${dl4j.version}</version> </dependency>

<dependency> <groupId>org.nd4j</groupId> <artifactId>nd4j-jcublas-7.0</artifactId> <version>${nd4j.version}</version> </dependency>

Page 28: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Modeling UCI Data: Iris

• We then need to build a deep learning model over the data– We can use the DL4J lib to do this

• We need to vectorize the data– Possibly with some per column transformations

Page 29: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Vectorizing Data5.1,3.5,1.4,0.2,Iris-setosa4.9,3.0,1.4,0.2,Iris-setosa4.7,3.2,1.3,0.2,Iris-setosa7.0,3.2,4.7,1.4,Iris-versicolor

Becomes

0.0 1:0.1666666666666665 2:1.0 3:0.021276595744680823 4:0.00.0 1:0.08333333333333343 2:0.5833333333333334 3:0.021276595744680823 4:0.00.0 1:0.0 2:0.7500000000000002 3:0.0 4:0.01.0 1:0.9583333333333335 2:0.7500000000000002 3:0.723404255319149 4:0.5217391304347826

Page 30: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015
Page 31: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Canova for Command Line Vectorization

• Library of tools to take – Audio– Video– Image– Text– CSV data

• And convert the input data into vectors in a standardized format (SVMLight, others)– Adaptable with custom input/output formats

• Open Source, ASF 2.0 Licensed– https://github.com/deeplearning4j/Canova– Part of DL4J suite

Page 32: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Workflow Configuration (iris_conf.txt)

canova.input.header.skip=falsecanova.input.statistics.debug.print=falsecanova.input.format=org.canova.api.formats.input.impl.LineInputFormat

canova.input.directory=src/test/resources/csv/data/uci_iris_sample.txtcanova.input.vector.schema=src/test/resources/csv/schemas/uci/iris.txtcanova.output.directory=/tmp/iris_unit_test_sample.txt

canova.output.format=org.canova.api.formats.output.impl.SVMLightOutputFormat

Page 33: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Iris Canova Vector Schema@RELATION UCIIrisDataset@DELIMITER ,

@ATTRIBUTE sepallength NUMERIC !NORMALIZE @ATTRIBUTE sepalwidth NUMERIC !NORMALIZE @ATTRIBUTE petallength NUMERIC !NORMALIZE @ATTRIBUTE petalwidth NUMERIC !NORMALIZE @ATTRIBUTE class STRING !LABEL

Page 34: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Model UCI Iris From CLI./bin/canova vectorize -conf /tmp/iris_conf.txt File path already exists, deleting the old file before proceeding...Output vectors written to: /tmp/iris_svmlight.txt

./bin/dl4j train –conf /tmp/iris_conf.txt

[ …log output… ]

./bin/arbiter evaluate –conf /tmp/iris_conf.txt

[ …log output… ]

Page 35: Enterprise Deep Learning Workflows With DL4J Josh Patterson Strata Singapore 2015

Questions?

Thank you for your time and attention

“Deep Learning: A Practitioner’s Approach” (Oreilly, Q2 2016)