Introducing Reactive Machine Learning
-
Upload
jeff-smith -
Category
Technology
-
view
801 -
download
3
Transcript of Introducing Reactive Machine Learning
Introducing Reactive Machine Learning
Jeff Smith @jeffksmithjr
x.ai is a personal assistant who schedules meetings for you
You
nom nom, the data dogScala & Python Spark & Akka Couchbase Machine Learning
Reactive + Machine Learning
Machine Learning Systems
Traits of Reactive Systems
Responsive
Resilient
Elastic
Message-Driven
Reactive Strategies
Reactive Machine Learning
Reactive Machine Learning
Collecting Data
Machine Learning Systems
Uncertainty Interval
27 33
Immutable Factscase class PreyReading(sensorId: Int, locationId: Int, timestamp: Long, animalsLowerBound: Double, animalsUpperBound: Double, percentZebras: Double)
implicit val preyReadingFormatter = Json.format[PreyReading]
Distributed Data Storage
Partition Tolerance
Distributed Data Storage
Immutable Factsval reading = PreyReading(36, 12, currentTimeMillis(), 12.0, 18.0, 0.60)
val setDoc = bucket.set[PreyReading](readingId(reading), reading)
Scaling with Distributed Databases
Almost Immutable Data Model{ "sensor_id": 123, "readings": [ { "sensor_id": 456, "timestamp": 1457403598289, "lower_bound": 12.0, "upper_bound": 18.0, "percent_zebras": 0.60 } ] }
Hot Key
Truly Immutable Data Model{ "sensor_id_reading_id": 123456, "timestamp": 1457403598289, "lower_bound": 12.0, "upper_bound": 18.0, "percent_zebras": 0.60 }
Generating Features
Machine Learning Systems
Feature Generation
Raw Data FeaturesFeature Generation Pipeline
Microblogging Data
Pipeline Failure
Raw Data FeaturesFeature Generation Pipeline
Raw Data FeaturesFeature Generation Pipeline
Supervising Feature Generation
Raw Data FeaturesFeature Generation Pipeline
Supervision
Original Features
object SquawkLength extends FeatureType[Int]
object Super extends LabelType[Boolean]
val originalFeatures: Set[FeatureType] = Set(SquawkLength)val label = Super
Basic Features
object PastSquawks extends FeatureType[Int]
val basicFeatures = originalFeatures + PastSquawks
More Features
object MobileSquawker extends FeatureType[Boolean]
val moreFeatures = basicFeatures + MobileSquawker
Feature Collections
case class FeatureCollection(id: Int, createdAt: DateTime, features: Set[_ <: FeatureType[_]], label: LabelType[_])
Feature Collectionsval earlierCollection = FeatureCollection(101, earlier, basicFeatures, label)
val latestCollection = FeatureCollection(202, now, moreFeatures, label)
val featureCollections = sc.parallelize( Seq(earlierCollection, latestCollection))
Fallback Collections
val FallbackCollection = FeatureCollection(404, beginningOfTime, originalFeatures, label)
Fallback Collectionsdef validCollection(collections: RDD[FeatureCollection], invalidFeatures: Set[FeatureType[_]]) = { val validCollections = collections.filter( fc => !fc.features .exists(invalidFeatures.contains)) .sortBy(collection => collection.id) if (validCollections.count() > 0) { validCollections.first() } else FallbackCollection}
Learning Models
Machine Learning Systems
Learning Models
Features ModelModel Learning Pipeline
Models of Love
Traits of Spark
Reactive Strategies in Spark
Data Preparationval labelIndexer = new StringIndexer() .setInputCol("label") .setOutputCol("indexedLabel") .fit(instances)
val featureIndexer = new VectorIndexer() .setInputCol("features") .setOutputCol("indexedFeatures") .fit(instances)
val Array(trainingData, testingData) = instances.randomSplit( Array(0.8, 0.2))
Learning a Modelval decisionTree = new DecisionTreeClassifier() .setLabelCol("indexedLabel") .setFeaturesCol("indexedFeatures")
val labelConverter = new IndexToString() .setInputCol("prediction") .setOutputCol("predictedLabel") .setLabels(labelIndexer.labels)
val pipeline = new Pipeline() .setStages(Array(labelIndexer, featureIndexer, decisionTree, labelConverter))
Evolving Modeling Strategiesval randomForest = new RandomForestClassifier() .setLabelCol("indexedLabel") .setFeaturesCol("indexedFeatures")
val revisedPipeline = new Pipeline() .setStages(Array(labelIndexer, featureIndexer, randomForest, labelConverter))
Deep Models of Artistic Style
Refactoring Command Line Tools> 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):
Exposing a Serviceclass 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
daemon = Pyro4.Daemon() ns = Pyro4.locateNS() uri = daemon.register(NeuralServer) ns.register("neuralserver", uri) daemon.requestLoop()
Encoding Model Types
object ModelType extends Enumeration { type ModelType = Value val VGG = Value("VGG") val I2V = Value("I2V") }
Encoding Valid Configurationcase 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)
Finding the Serviceval ns = NameServerProxy.locateNS(null) val remoteServer = new PyroProxy(ns.lookup("neuralserver"))
Calling the Servicedef 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, jobConfiguration.iterations).asInstanceOf[Boolean] }))}
Profiles with Style
Hybrid Model learning
Features ModelModel Learning Pipeline
Publishing Models
Machine Learning Systems
Publishing Models
Model Predictive ServicePublishing Process
Building Lineages
val rawData: RawData val featureSet: Set[FeatureType] val model: ClassificationModel val modelMetrics: BinaryClassificationMetrics
Predicting
Machine Learning Systems
Predicting
Client Predictive ServiceRequest> <Prediction
Models as Servicesdef predict(model: Features => Prediction) (features: Features): Future[Either[String, Prediction]] = { ??? }
Models as Servicesval routes = { pathPrefix("model") { (post & entity(as[PredictionRequest])) { context => complete { predict(model: Features => Prediction)(extractFeatures(context)) .map[ToResponseMarshallable] { case Right(prediction) => PredictionSummary(prediction) case Left(errorMessage) => BadRequest -> errorMessage } } } } }
Clojure Functions
Clojure Predictive Service
Predicting
Client Predictive ServiceRequest
Summary
Machine Learning Systems
Traits of Reactive Systems
Reactive Strategies
Reactive Machine Learning
For Later
manning.com reactivemachinelearning.com medium.com/data-engineering
M A N N I N G
Jeff SmithUse the code reactnymu for 39% off!
x.ai @xdotai [email protected] New York, New York
We’re hiring!
Thank You!
Code: reactnymu
Jeff Smith @jeffksmithjr reactivemachinelearning.com
M A N N I N G
Jeff Smith