+ All Categories
Home > Software > Reactive Machine Learning On and Beyond the JVM

Reactive Machine Learning On and Beyond the JVM

Date post: 09-Jan-2017
Category:
Upload: jeff-smith
View: 502 times
Download: 0 times
Share this document with a friend
100
@jeffksmithjr @xdotai #Devoxx Reactive Machine Learning On and Beyond the JVM Jeff Smith x.ai
Transcript

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning On and Beyond the JVM

Jeff Smith x.ai

@jeffksmithjr @xdotai#Devoxx

Intro

@jeffksmithjr @xdotai#Devoxx

Bio

@jeffksmithjr @xdotai#Devoxx

x.ai @xdotai [email protected] New York, New York

@jeffksmithjr @xdotai#Devoxx

Reactive

@jeffksmithjr @xdotai#Devoxx

Reactive Systems

Responsive

Resilient Elastic

Message-Driven

@jeffksmithjr @xdotai#Devoxx

Responsive

@jeffksmithjr @xdotai#Devoxx

Resilient

@jeffksmithjr @xdotai#Devoxx

Elastic

@jeffksmithjr @xdotai#Devoxx

Message-Driven

@jeffksmithjr @xdotai#Devoxx

Reactive Systems

Responsive

Resilient Elastic

Message-Driven

@jeffksmithjr @xdotai#Devoxx

Reactive Strategies

Replication Containment Supervision

@jeffksmithjr @xdotai#Devoxx

Replication

@jeffksmithjr @xdotai#Devoxx

Containment

@jeffksmithjr @xdotai#Devoxx

Supervision

@jeffksmithjr @xdotai#Devoxx

Reactive Strategies

Replication Containment Supervision

@jeffksmithjr @xdotai#Devoxx

Machine Learning

@jeffksmithjr @xdotai#Devoxx

Artificial Intelligence

@jeffksmithjr @xdotai#Devoxx

Agents

Sensors

Actuators

Knowledge

Learning

Function

@jeffksmithjr @xdotai#Devoxx

Machine Learning

CollectingData

GeneratingFeatures

LearningModels

EvaluatingModels

PublishingModels

Acting

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning

Infinite Data

Laziness Functions

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning

Infinite Data Uncertain Data

Laziness Functions ImmutableFacts

PossibleWorlds

@jeffksmithjr @xdotai#Devoxx

JVM

@jeffksmithjr @xdotai#Devoxx

JVM Features

• Portability

• Garbage collection

• JIT Compilation

• Multithreading

@jeffksmithjr @xdotai#Devoxx

JVM for Everywhere

• Single backend servers

• Clusters

• Mobile

• Embedded

@jeffksmithjr @xdotai#Devoxx

JVM for Languages

• Generics

• Dynamic-type

• Lambdas

• Other languages

• Scala, Clojure, Groovy, Kotlin

@jeffksmithjr @xdotai#Devoxx

JVM for Concurrency & Distribution

• Futures

• Promises

• Tasks

• Software Transactional Memory

• Data Grids

• Actor Systems

• Resilient Distributed Datasets

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning On the JVM

@jeffksmithjr @xdotai#Devoxx

Fraud DetectionCorrect!

Fraud

Not Fraud

ModelTransaction

@jeffksmithjr @xdotai#Devoxx

Fraud Detection

Model

Fraud

Not Fraud

Wrong!

Transaction

@jeffksmithjr @xdotai#Devoxx

Fraud Detection

Model

Fraud

Not Fraud

Wrong!

Transaction

@jeffksmithjr @xdotai#Devoxx

val conf = new SparkConf().setAppName(“FraudModel") .setMaster("local[*]") val sc = new SparkContext(conf) val sqlContext = new SQLContext(sc)

import sqlContext.implicits._

Spark Setup

@jeffksmithjr @xdotai#Devoxx

val data = sqlContext.read.format(“libsvm") .load("src/main/resources/sample_libsvm_data.txt")

val Array(trainingData, testingData) = data.randomSplit(Array(0.8, 0.2))

val learningAlgo = new LogisticRegression()

val model = learningAlgo.fit(trainingData)

Data Preparation & Model Learning

@jeffksmithjr @xdotai#Devoxx

ROC Curve

True

Pos

itive

Rat

e

False Positive Rate

Good ModelAUC > 0.5

@jeffksmithjr @xdotai#Devoxx

ROC Curve

True

Pos

itive

Rat

e

False Positive Rate

Random ModelAUC = 0.5

@jeffksmithjr @xdotai#Devoxx

ROC Curve

True

Pos

itive

Rat

e

False Positive Rate

Bad ModelAUC < 0.5

@jeffksmithjr @xdotai#Devoxx

def betterThanRandom(model: LogisticRegressionModel) = { val trainingSummary = model.summary

val binarySummary = trainingSummary .asInstanceOf[BinaryLogisticRegressionSummary]

val auc = binarySummary.areaUnderROC

auc > 0.5 }

betterThanRandom(model)

Evaluating the Model

@jeffksmithjr @xdotai#Devoxx

Reactive Systems

Responsive

Resilient Elastic

Message-Driven

@jeffksmithjr @xdotai#Devoxx

Reactive Strategies

Replication Containment Supervision

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning

Infinite Data Uncertain Data

Laziness Functions ImmutableFacts

PossibleWorlds

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning Beyond the JVM

@jeffksmithjr @xdotai#Devoxx

Models of Love

@jeffksmithjr @xdotai#Devoxx

Deep Models of Artistic Style

@jeffksmithjr @xdotai#Devoxx

> python neural-art-tf.py -m vgg -mp ./vgg -c ./images/bear.jpg -s ./images/style.jpg -w 800

def produce_art(content_image_path, style_image_path, model_path, model_type, width, alpha, beta, num_iters):

Refactoring Command Line Tools

@jeffksmithjr @xdotai#Devoxx

class NeuralServer(object): def generate(self, content_image_path, style_image_path, model_path, model_type, width, alpha, beta, num_iters): produce_art(content_image_path, style_image_path, model_path, model_type, width, alpha, beta, num_iters) return True

Exposing a Service

@jeffksmithjr @xdotai#Devoxx

daemon = Pyro4.Daemon() ns = Pyro4.locateNS() uri = daemon.register(NeuralServer) ns.register("neuralserver", uri) daemon.requestLoop()

Starting the Service

@jeffksmithjr @xdotai#Devoxx

object ModelType extends Enumeration { type ModelType = Value val VGG = Value("VGG") val I2V = Value("I2V") }

Encoding Model Types

@jeffksmithjr @xdotai#Devoxx

case class JobConfiguration(contentPath: String, stylePath: String, modelPath: String, modelType: ModelType, width: Integer = 800, alpha: java.lang.Double = 1.0, beta: java.lang.Double = 200.0, iterations: Integer = 5000)

Encoding Valid Configuration

@jeffksmithjr @xdotai#Devoxx

val ns = NameServerProxy.locateNS(null) val remoteServer = new PyroProxy(ns.lookup("neuralserver"))

Finding the Service

@jeffksmithjr @xdotai#Devoxx

def callServer(remoteServer: PyroProxy, jobConfiguration: JobConfiguration) = {

Future.firstCompletedOf(List(timedOut, Future { remoteServer.call("generate", jobConfiguration.contentPath, jobConfiguration.stylePath, jobConfiguration.modelPath, jobConfiguration.modelType.toString, jobConfiguration.width, jobConfiguration.alpha,

jobConfiguration.beta, job Configuration.iterations) .asInstanceOf[Boolean]}))}

Calling the Service

@jeffksmithjr @xdotai#Devoxx

Profiles with Style

@jeffksmithjr @xdotai#Devoxx

Reactive Systems

Responsive

Resilient Elastic

Message-Driven

@jeffksmithjr @xdotai#Devoxx

Reactive Strategies

Replication Containment Supervision

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning

Infinite Data Uncertain Data

Laziness Functions ImmutableFacts

PossibleWorlds

@jeffksmithjr @xdotai#Devoxx

Elixir

• Functional Language

• Homoiconic Syntax

• Concurrency-oriented

• Runs on the BEAM (EVM)

@jeffksmithjr @xdotai#Devoxx

Agents

Sensors

Actuators

Knowledge

Learning

Function

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

AppDB

AppDB

AppDB

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

AppDB

AppDB

AppDB

id_123

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

AppDB

AppDB

AppDB

id_123 id_456

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

AppDB

AppDB

AppDB

id_123

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

@jeffksmithjr @xdotai#Devoxx

Reactive Knowledge Maintenance

@jeffksmithjr @xdotai#Devoxx

Reactive Systems

Responsive

Resilient Elastic

Message-Driven

@jeffksmithjr @xdotai#Devoxx

Reactive Strategies

Replication Containment Supervision

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning

Infinite Data Uncertain Data

Laziness Functions ImmutableFacts

PossibleWorlds

@jeffksmithjr @xdotai#Devoxx

Characterizing Intelligence

@jeffksmithjr @xdotai#Devoxx

Characterizing Intelligence

@jeffksmithjr @xdotai#Devoxx

Dialyzer

• Linter

• Applies type system

• Optional

@jeffksmithjr @xdotai#Devoxx

Ensemble Models

@jeffksmithjr @xdotai#Devoxx

Feature Generation

@jeffksmithjr @xdotai#Devoxx

Applying Models

@jeffksmithjr @xdotai#Devoxx

Parallel Function Mapping

@jeffksmithjr @xdotai#Devoxx

Ensemble Models

@jeffksmithjr @xdotai#Devoxx

Ensembling Models

@jeffksmithjr @xdotai#Devoxx

ml_system.ex:3: Function predict/1 has no local return ml_system.ex:6: The call 'Elixir.MLSystem':call_model_b(feature@1::number()) will never return since it differs in the 1st argument from the success typing arguments: (binary())

Dialyzer Output

@jeffksmithjr @xdotai#Devoxx

ml_system.ex:22: Invalid type specification for function 'Elixir.MLSystem':call_model_b/1. The success typing is (binary()) -> binary() ml_system.ex:23: Function call_model_b/1 has no local return ml_system.ex:24: The call 'Elixir.String':upcase(feature@1::number()) will never return since the success typing is (binary()) -> bitstring() and the contract is (t()) -> t()

Dialyzer Output

@jeffksmithjr @xdotai#Devoxx

ml_system.ex:38: Function ensemble/1 will never be called

Dialyzer Output

@jeffksmithjr @xdotai#Devoxx

Guarantees of Type Systems

StaticDynamic

@jeffksmithjr @xdotai#Devoxx

Guarantees of Type Systems

Scala

StaticDynamic

@jeffksmithjr @xdotai#Devoxx

Guarantees of Type Systems

ScalaJava

StaticDynamic

@jeffksmithjr @xdotai#Devoxx

Guarantees of Type Systems

ScalaJava

StaticDynamic

Elixir/Erlang

@jeffksmithjr @xdotai#Devoxx

Guarantees of Type Systems

ScalaJava

StaticDynamic

Elixir/Erlang

@jeffksmithjr @xdotai#Devoxx

Guarantees of Type Systems

ScalaJava

StaticDynamic

Elixir/Erlang

@jeffksmithjr @xdotai#Devoxx

Guarantees of Type Systems

ScalaClojure Java

StaticDynamic

Elixir/Erlang

@jeffksmithjr @xdotai#Devoxx

Guarantees of Type Systems

ScalaClojure Java

StaticDynamic

Elixir/Erlang

@jeffksmithjr @xdotai#Devoxx

Reactive Systems

Responsive

Resilient Elastic

Message-Driven

@jeffksmithjr @xdotai#Devoxx

Reactive Strategies

Replication Containment Supervision

@jeffksmithjr @xdotai#Devoxx

Reactive Machine Learning

Infinite Data Uncertain Data

Laziness Functions ImmutableFacts

PossibleWorlds

@jeffksmithjr @xdotai#Devoxx

The Future of Reactive Machine Learning

On the JVM

@jeffksmithjr @xdotai#Devoxx

Lead

• Concurrency and distribution

• Polyglot runtime

• Interoperation

@jeffksmithjr @xdotai#Devoxx

Learn

• Deep learning

• Simple concurrency

• Modularize

• Incremental type systems

@jeffksmithjr @xdotai#Devoxx

For Later

@jeffksmithjr @xdotai#Devoxx

x.ai @xdotai [email protected] New York, New York

@jeffksmithjr @xdotai#Devoxx

reactivemachinelearning.com@jeffksmithjr

Use the codectwdevbel for 40% off all Manning books!

@jeffksmithjr @xdotai#Devoxx

Thanks!


Recommended