Post on 09-Jan-2017
@jeffksmithjr @xdotai#Devoxx
Machine Learning
CollectingData
GeneratingFeatures
LearningModels
EvaluatingModels
PublishingModels
Acting
@jeffksmithjr @xdotai#Devoxx
Reactive Machine Learning
Infinite Data Uncertain Data
Laziness Functions ImmutableFacts
PossibleWorlds
@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
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
Random 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 Machine Learning
Infinite Data Uncertain Data
Laziness Functions ImmutableFacts
PossibleWorlds
@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
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
Reactive Machine Learning
Infinite Data Uncertain Data
Laziness Functions ImmutableFacts
PossibleWorlds
@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
ScalaClojure Java
StaticDynamic
Elixir/Erlang
@jeffksmithjr @xdotai#Devoxx
Guarantees of Type Systems
ScalaClojure Java
StaticDynamic
Elixir/Erlang
@jeffksmithjr @xdotai#Devoxx
Reactive Machine Learning
Infinite Data Uncertain Data
Laziness Functions ImmutableFacts
PossibleWorlds
@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
reactivemachinelearning.com@jeffksmithjr
Use the codectwdevbel for 40% off all Manning books!