machine learning in java - callista enterprise€¢ why machine learning? -patterns are everywhere,...
TRANSCRIPT
![Page 1: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/1.jpg)
CADEC 2019.01.24 & 2019.01.30 | CALLISTAENTERPRISE.SE
MACHINE LEARNING IN JAVA
DAVID STRÖM
![Page 2: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/2.jpg)
TODAY'S QUESTIONS
• What is it? • Why use machine learning, and why
use Java? • How do we do it?
?
![Page 3: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/3.jpg)
WHAT?
![Page 4: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/4.jpg)
WHAT
DEEP LEARNING MACHINE LEARNINGARTIFICIAL INTELLIGENCE
![Page 5: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/5.jpg)
WHY?
![Page 6: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/6.jpg)
WHY
• Some things are almost impossible to solve without, e.g. - Image recognition
• While other things get (a lot) better - Natural language processing - Recommendations - Robotic process automation - Anomaly detection
• Patterns are everywhere - Ask what your data can tell you?
![Page 7: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/7.jpg)
WHY - NOW
![Page 8: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/8.jpg)
CHALLENGE: NEW SKILLS
DATA MODELING
PYTHON
TENSOR FLOWSCI-KIT
R
BIG DATA
STATISTICAL ANALYSIS SQL
JAVAC#
SYSTEM DESIGN
TDD
DDDDATA SCIENCE SOFTWARE ENGINEERING
![Page 9: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/9.jpg)
DEEPLEARNING4J
• Open source • Includes various tools for ML - ND4J - DataVec - Arbiter - Some visualization tools
• Import Keras models • Supports dataprocessing on CUDA*
enabled GPUs (Nvidia)
*CUDA: COMPUTE UNIFIED DEVICE ARCHITECTURE
![Page 10: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/10.jpg)
WHY JAVA
• Python is by far more common machine learning language, but... - Java is versatile with huge
ecosystem of tools - Great number of systems are built
in Java - Great number of software
engineers use Java primarily
![Page 11: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/11.jpg)
HOW?
![Page 12: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/12.jpg)
HOW BUILD - DEEPLEARNING4J
dependencies { compile("org.deeplearning4j:deeplearning4j-core:1.0.0-beta3") compile("org.nd4j:nd4j-native-platform:1.0.0-beta3") }
Alternatively:
dependencies { compile("org.deeplearning4j:deeplearning4j-core:1.0.0-beta3") compile("org.nd4j:nd4j-cuda-9.2:1.0.0-beta3") }
![Page 13: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/13.jpg)
THE PROCESS
FINAL HYPOTHESIS
BUSINESS TARGET
% AQUIRE RAW DATA
PRE PROCESSSELECT MODEL
VALIDATE RESULT
TRAIN
FINAL HYPOTHESIS
TRIM OR CHANGE MODEL
IMPLEMENT
![Page 14: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/14.jpg)
THE PROCESS
FINAL HYPOTHESIS
BUSINESS TARGET
% AQUIRE RAW DATA
PRE PROCESSSELECT MODEL
VALIDATE RESULT
TRAIN
FINAL HYPOTHESIS
TRIM OR CHANGE MODEL
IMPLEMENT
![Page 15: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/15.jpg)
BUSINESS TARGET
} "A"
![Page 16: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/16.jpg)
DATA
![Page 17: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/17.jpg)
HOW - INPUT DATA
SOUND
VIDEODOCUMENTS/TEXT
IMAGES
DATABASE/TABULAR DATA
![Page 18: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/18.jpg)
HOW - INPUT PREPROCESSING
INPUTS
}233, 123, 34.. .
233, 123, 34.. .
212, 12, 43.. .
123, 243, 221. . .
2, 87, 123.. .
233, 123, 34.. .
233, 123, 34.. .
![Page 19: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/19.jpg)
HOW - INPUT PREPROCESSING
// ... FileSplit fileSplit = new FileSplit(directory, {".png"}); ParentPathLabelGenerator labelMaker = new ParentPathLabelGenerator(); ImageRecordReader recordReader = new ImageRecordReader(28,28,1, labelMaker); recordReader.initialize(fileSplit); // ...
![Page 20: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/20.jpg)
MODEL
![Page 21: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/21.jpg)
MODEL - ARTIFICIAL NEURAL NETWORK ARCHITECTURE
• Three common types: - MLP (Multi layer perceptron) - CNN (Convolutional neural network) - RNN (Recurrent neural network)
• Hybrid networks: use layers or subnets of different types
![Page 22: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/22.jpg)
MODEL CHARACTERISTICS
![Page 23: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/23.jpg)
DEEP LEARNING - MULTI LAYER PERCEPTRON
• General purpose architecture • Particularly useful for tabular data,
e.g. csv-files.
DATABASE/TABULAR DATA
![Page 24: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/24.jpg)
DEEP LEARNING - CONVOLUTIONAL NEURAL NETWORK
• Useful to make generalisations of the input (has/has not)
• Particularly useful for identifying patterns in images
• Not good for anomaly detection
IMAGES
![Page 25: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/25.jpg)
DEEP LEARNING - RECURRENT NEURAL NETWORK
• Complex, often difficult to train • LSTM (Long-short term memory)
successful exception • Useful for time-series such as sound
or text
SOUNDDOCUMENTS/TEXT
![Page 26: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/26.jpg)
HOW TO BUILD?
![Page 27: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/27.jpg)
HOW BUILD - CONVOLUTIONAL NEURAL NETWORK
• We will build a convolutional neural network using Deeplearning4J
![Page 28: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/28.jpg)
AINPUT (400X400) DENSE
LAYER 150
CONVOLUTION 5X5
SUBSAMPLING 100
CONVOLUTION 5X5
SUBSAMPLING 50
OUTPUT LAYER 26 (A-Z)
"A"
![Page 29: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/29.jpg)
HOW BUILD - CONVOLUTIONAL NEURAL NETWORK
• We will build a convolutional neural network using Deeplearning4J • Use Deeplearning4J MultilayerConfiguration to build a MultiLayerNetwork
![Page 30: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/30.jpg)
HOW TO BUILD - MULTILAYERCONFIGURATION
// ... MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(132); .optimizationAlgo(STOCHASTIC_GRADIENT_DESCENT) .weightInit(XAVIER) .updater(new Nesterov(learningRate, momentum)) .list() .layer(0,new ConvolutionLayer.Builder(5,5) .nIn(1).nOut(100).activation(IDENTITY).build()) // ... More layers here .layer(5,new OutputLayer.Builder() .lossFunction(NEGATIVELOGLIKELIHOOD) .nOut(26).activation(SOFTMAX).build()) .backprop(true) .build(); // ...
![Page 31: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/31.jpg)
HOW TO BUILD - CONVOLUTIONAL NEURAL NETWORK
• We will build a convolutional neural network using Deeplearning4J • Use Deeplearning4J MultilayerConfiguration to build a MultiLayerNetwork • Use Deeplearning4J EarlyStoppingTrainer to train and save the network
![Page 32: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/32.jpg)
HOW TO BUILD - EARLYSTOPPINGTRAINER
private static EarlyStoppingTrainer trainer(DataSetIterator iter, MultiLayerNetwork model) { EarlyStoppingConfiguration conf = new EarlyStoppingConfiguration.Builder() .epochTerminationConditions(new MaxEpochsTerminationCondition(30)); .iterationTerminationConditions(new MaxTimeIterationTerminationCondition (2, HOURS)) .scoreCalculator(new ClassificationScoreCalculator(ACCURACY, iter)) .evaluateEveryNEpochs(1) .modelSaver(new LocalFileModelSaver(modelSaveDirectory) .build(); return new EarlyStoppingTrainer(conf, model, iter); }
![Page 33: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/33.jpg)
![Page 34: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/34.jpg)
![Page 35: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/35.jpg)
HOW TO USE?
![Page 36: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/36.jpg)
DEMO
![Page 37: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/37.jpg)
ALL THE ANSWERS
• What is it? - Self-adapting algorithms to identify patterns
• Why machine learning? - Patterns are everywhere, you probably have
patterns in your data, how can you use that? • Why use Java for machine learning? - Java has a great ecosystem of tools and
frameworks - Sheer force of numbers (systems and
developers) • How can we use Java for machine learning? - I think DL4J solves many of the problems
related to working with ML...
!
![Page 38: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/38.jpg)
SOME LINKS
• https://deeplearning4j.org/ • https://skymind.ai/wiki/ • https://archive.ics.uci.edu/ml/datasets.html • https://www.analyticsvidhya.com/blog/ • https://machinelearningmastery.com/blog/
![Page 39: MACHINE LEARNING IN JAVA - Callista Enterprise€¢ Why machine learning? -Patterns are everywhere, you probably have patterns in your data, how can you use that? • Why use Java](https://reader030.vdocuments.mx/reader030/viewer/2022040610/5ed37162b458607d8231cc0d/html5/thumbnails/39.jpg)
THANK YOU!
ALL CODE USED IN DEMOS: HTTPS://GITHUB.COM/CALLISTAENTERPRISE/CADEC-2019-DEEPLEARNING4J.GIT