Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... ·...

24
Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG

Transcript of Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... ·...

Page 1: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Maschinelles Lernen in der JVM

Erik Rohkohl HTWK Leipzig/itemis AG

Page 2: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Outline

• Perceptron

• Multi-Layer-Perceptron (MLP) a.k.a. künstliches neuronales Netz

• Daten-Extraktion und Aufbereitung

• Model mit Deeplearning4J

• Training und Testen

https://github.com/erohkohl 2JUG Saxony Camp 2018

Page 3: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Perceptron

3https://github.com/erohkohlJUG Saxony Camp 2018

Page 4: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

XOR-Problem

4https://github.com/erohkohlJUG Saxony Camp 2018

Page 5: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

XOR-Problem

5

f(x, y) (x, y, z)

https://github.com/erohkohlJUG Saxony Camp 2018

Page 6: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

TensorFlow Playground

6https://github.com/erohkohlJUG Saxony Camp 2018

Page 7: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Problemstellung

7https://github.com/erohkohlJUG Saxony Camp 2018

Page 8: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Merkmalsvektor

8https://github.com/erohkohlJUG Saxony Camp 2018

Page 9: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Vereinfachter Merkmalsvektor

9https://github.com/erohkohlJUG Saxony Camp 2018

Page 10: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

One-hot Encoding

10https://github.com/erohkohlJUG Saxony Camp 2018

Page 11: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Input Vektor

11https://github.com/erohkohlJUG Saxony Camp 2018

Page 12: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

12https://github.com/erohkohlJUG Saxony Camp 2018

Page 13: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

One vs. All

13https://github.com/erohkohlJUG Saxony Camp 2018

Page 14: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Daten-Extraktion

14

HTML zeigen

https://github.com/erohkohlJUG Saxony Camp 2018

Page 15: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Daten-Extraktion

15

Document doc = Jsoup.parse(html); String[] s = doc.getElementsByClass("meals").eachText().get(0).split(","); Meal fastPlate = null; for (int i = 0; i < s.length; i++) { if (s[i].trim().equals(MenuType.FastPlate.getName())) { fastPlate = Meal.getType(s[i + 19].toString().trim()); break; } }

DateTimeFormatter formatter = DateTimeFormatter.ofPattern(„yyyy-MM-dd"); String dateStr = p.getFileName().toString().subSequence(0, 10); LocalDate date = LocalDate.parse(dateStr, formatter);

return new Menu(fastPlate, date);

https://github.com/erohkohlJUG Saxony Camp 2018

Page 16: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Trainings Daten

16

INDArray input = Nd4j.zeros(trainNbr, inputSize); // row x col INDArray labels = Nd4j.zeros(trainNbr, targetSize);

for (int row = 0; row < trainNbr; row++) { int[][] menuVec = menusVec[row]; for (int col = 0; col < inputSize; col++) { input.putScalar(new int[]{row, col}, menuVec[0][col]); } for (int col = 0; col < targetSize; col++) { labels.putScalar(new int[]{row, col}, menuVec[1][col]); } }

DataSet ds = new DataSet(input, labels);

https://github.com/erohkohlJUG Saxony Camp 2018

Page 17: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

MLP-Konfiguration

17

MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .iterations(20000) .learningRate(0.01) .seed(123) .optimizationAlgo(OptimizationAlgorithm.LINE_GRADIENT_DESCENT) .biasInit(0) .list() .layer(0, new DenseLayer.Builder() .nIn(11) .nOut(32) .activation(Activation.RELU) .build())

. . . .layer(2, new OutputLayer.Builder(LossFunctions.LossFunction.SQUARED_LOSS) .nIn(32) .nOut(3) .activation(Activation.SOFTMAX) .build()) .build();

https://github.com/erohkohlJUG Saxony Camp 2018

Page 18: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Training

18

MultiLayerNetwork net = new MultiLayerNetwork(conf); net.init(); net.fit(ds);

https://github.com/erohkohlJUG Saxony Camp 2018

Page 19: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Evaluation

19

INDArray output = net.output(ds.getFeatureMatrix());

Evaluation eval = new Evaluation(targetSize); eval.eval(ds.getLabels(), output); System.out.println(eval.stats());

https://github.com/erohkohlJUG Saxony Camp 2018

Page 20: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Testen

20

DataSet testDs = new DataSet(input, labels);

List<String> names = new ArrayList<>(); names.add(0, "Huehnchen"); names.add(1, "Schwein"); names.add(2, "Rind"); testDs.setLabelNames(names);

MultiLayerNetwork net = model.getNet(); List<String> prediction = net.predict(testDs);

https://github.com/erohkohlJUG Saxony Camp 2018

Page 21: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

21https://github.com/erohkohlJUG Saxony Camp 2018

Page 22: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Ausblick

22

Rekurrente neuronale Netze LSTM Netze

https://github.com/erohkohlJUG Saxony Camp 2018

Page 23: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

Quellen

23

• YouTube: Artificial Intelligence Courses, 7. Multiclass Classification One vs All • Deeplearning4J Documentation, A Beginner’s Guide to Multilayer Perceptron • Studentenwerk Leipzig, Mensa am Park Speiseplan • xkcd, AI Research

https://github.com/erohkohlJUG Saxony Camp 2018

Page 24: Maschinelles Lernen in der JVM - leipzig.jugsaxony.camp › wp-content › uploads › ... · Maschinelles Lernen in der JVM Erik Rohkohl HTWK Leipzig/itemis AG . Outline

24

Deep learning in Java's virtual machine https://github.com/erohkohl/ml-jvm

https://github.com/erohkohlJUG Saxony Camp 2018

Tagging Stack-Overflow questions with deep neural networks https://github.com/erohkohl/question-tagging