Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Reactive Machine Learning On and Beyond the JVM

848 views

Published on

Presented at Devoxx Belgium 2016: https://devoxx.be/
Video: https://youtu.be/akPLphTykwI

Published in: Software

Reactive Machine Learning On and Beyond the JVM

  1. 1. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning On and Beyond the JVM Jeff Smith x.ai
  2. 2. @jeffksmithjr @xdotai#Devoxx Intro
  3. 3. @jeffksmithjr @xdotai#Devoxx Bio
  4. 4. @jeffksmithjr @xdotai#Devoxx x.ai @xdotai hello@human.x.ai New York, New York
  5. 5. @jeffksmithjr @xdotai#Devoxx Reactive
  6. 6. @jeffksmithjr @xdotai#Devoxx Reactive Systems Responsive Resilient Elastic Message-Driven
  7. 7. @jeffksmithjr @xdotai#Devoxx Responsive
  8. 8. @jeffksmithjr @xdotai#Devoxx Resilient
  9. 9. @jeffksmithjr @xdotai#Devoxx Elastic
  10. 10. @jeffksmithjr @xdotai#Devoxx Message-Driven
  11. 11. @jeffksmithjr @xdotai#Devoxx Reactive Systems Responsive Resilient Elastic Message-Driven
  12. 12. @jeffksmithjr @xdotai#Devoxx Reactive Strategies Replication Containment Supervision
  13. 13. @jeffksmithjr @xdotai#Devoxx Replication
  14. 14. @jeffksmithjr @xdotai#Devoxx Containment
  15. 15. @jeffksmithjr @xdotai#Devoxx Supervision
  16. 16. @jeffksmithjr @xdotai#Devoxx Reactive Strategies Replication Containment Supervision
  17. 17. @jeffksmithjr @xdotai#Devoxx Machine Learning
  18. 18. @jeffksmithjr @xdotai#Devoxx Artificial Intelligence
  19. 19. @jeffksmithjr @xdotai#Devoxx Agents Sensors Actuators Knowledge Learning Function
  20. 20. @jeffksmithjr @xdotai#Devoxx Machine Learning Collecting Data Generating Features Learning Models Evaluating Models Publishing Models Acting
  21. 21. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning
  22. 22. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning Infinite Data Laziness Functions
  23. 23. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning Infinite Data Uncertain Data Laziness Functions Immutable Facts Possible Worlds
  24. 24. @jeffksmithjr @xdotai#Devoxx JVM
  25. 25. @jeffksmithjr @xdotai#Devoxx JVM Features • Portability • Garbage collection • JIT Compilation • Multithreading
  26. 26. @jeffksmithjr @xdotai#Devoxx JVM for Everywhere • Single backend servers • Clusters • Mobile • Embedded
  27. 27. @jeffksmithjr @xdotai#Devoxx JVM for Languages • Generics • Dynamic-type • Lambdas • Other languages • Scala, Clojure, Groovy, Kotlin
  28. 28. @jeffksmithjr @xdotai#Devoxx JVM for Concurrency & Distribution • Futures • Promises • Tasks • Software Transactional Memory • Data Grids • Actor Systems • Resilient Distributed Datasets
  29. 29. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning On the JVM
  30. 30. @jeffksmithjr @xdotai#Devoxx Fraud Detection Correct! Fraud Not Fraud ModelTransaction
  31. 31. @jeffksmithjr @xdotai#Devoxx Fraud Detection Model Fraud Not Fraud Wrong! Transaction
  32. 32. @jeffksmithjr @xdotai#Devoxx Fraud Detection Model Fraud Not Fraud Wrong! Transaction
  33. 33. @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
  34. 34. @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
  35. 35. @jeffksmithjr @xdotai#Devoxx ROC Curve TruePositiveRate False Positive Rate Good Model AUC > 0.5
  36. 36. @jeffksmithjr @xdotai#Devoxx ROC Curve TruePositiveRate False Positive Rate Random Model AUC = 0.5
  37. 37. @jeffksmithjr @xdotai#Devoxx ROC Curve TruePositiveRate False Positive Rate Bad Model AUC < 0.5
  38. 38. @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
  39. 39. @jeffksmithjr @xdotai#Devoxx Reactive Systems Responsive Resilient Elastic Message-Driven
  40. 40. @jeffksmithjr @xdotai#Devoxx Reactive Strategies Replication Containment Supervision
  41. 41. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning Infinite Data Uncertain Data Laziness Functions Immutable Facts Possible Worlds
  42. 42. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning Beyond the JVM
  43. 43. @jeffksmithjr @xdotai#Devoxx Models of Love
  44. 44. @jeffksmithjr @xdotai#Devoxx Deep Models of Artistic Style
  45. 45. @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
  46. 46. @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
  47. 47. @jeffksmithjr @xdotai#Devoxx daemon = Pyro4.Daemon() ns = Pyro4.locateNS() uri = daemon.register(NeuralServer) ns.register("neuralserver", uri) daemon.requestLoop() Starting the Service
  48. 48. @jeffksmithjr @xdotai#Devoxx object ModelType extends Enumeration { type ModelType = Value val VGG = Value("VGG") val I2V = Value("I2V") } Encoding Model Types
  49. 49. @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
  50. 50. @jeffksmithjr @xdotai#Devoxx val ns = NameServerProxy.locateNS(null) val remoteServer = new PyroProxy(ns.lookup("neuralserver")) Finding the Service
  51. 51. @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
  52. 52. @jeffksmithjr @xdotai#Devoxx Profiles with Style
  53. 53. @jeffksmithjr @xdotai#Devoxx Reactive Systems Responsive Resilient Elastic Message-Driven
  54. 54. @jeffksmithjr @xdotai#Devoxx Reactive Strategies Replication Containment Supervision
  55. 55. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning Infinite Data Uncertain Data Laziness Functions Immutable Facts Possible Worlds
  56. 56. @jeffksmithjr @xdotai#Devoxx Elixir • Functional Language • Homoiconic Syntax • Concurrency-oriented • Runs on the BEAM (EVM)
  57. 57. @jeffksmithjr @xdotai#Devoxx Agents Sensors Actuators Knowledge Learning Function
  58. 58. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance App DB App DB App DB
  59. 59. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance App DB App DB App DB id_123
  60. 60. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance App DB App DB App DB id_123 id_456
  61. 61. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance App DB App DB App DB id_123
  62. 62. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance
  63. 63. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance
  64. 64. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance
  65. 65. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance
  66. 66. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance
  67. 67. @jeffksmithjr @xdotai#Devoxx Reactive Knowledge Maintenance
  68. 68. @jeffksmithjr @xdotai#Devoxx Reactive Systems Responsive Resilient Elastic Message-Driven
  69. 69. @jeffksmithjr @xdotai#Devoxx Reactive Strategies Replication Containment Supervision
  70. 70. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning Infinite Data Uncertain Data Laziness Functions Immutable Facts Possible Worlds
  71. 71. @jeffksmithjr @xdotai#Devoxx Characterizing Intelligence
  72. 72. @jeffksmithjr @xdotai#Devoxx Characterizing Intelligence
  73. 73. @jeffksmithjr @xdotai#Devoxx Dialyzer • Linter • Applies type system • Optional
  74. 74. @jeffksmithjr @xdotai#Devoxx Ensemble Models
  75. 75. @jeffksmithjr @xdotai#Devoxx Feature Generation
  76. 76. @jeffksmithjr @xdotai#Devoxx Applying Models
  77. 77. @jeffksmithjr @xdotai#Devoxx Parallel Function Mapping
  78. 78. @jeffksmithjr @xdotai#Devoxx Ensemble Models
  79. 79. @jeffksmithjr @xdotai#Devoxx Ensembling Models
  80. 80. @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
  81. 81. @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
  82. 82. @jeffksmithjr @xdotai#Devoxx ml_system.ex:38: Function ensemble/1 will never be called Dialyzer Output
  83. 83. @jeffksmithjr @xdotai#Devoxx Guarantees of Type Systems StaticDynamic
  84. 84. @jeffksmithjr @xdotai#Devoxx Guarantees of Type Systems Scala StaticDynamic
  85. 85. @jeffksmithjr @xdotai#Devoxx Guarantees of Type Systems ScalaJava StaticDynamic
  86. 86. @jeffksmithjr @xdotai#Devoxx Guarantees of Type Systems ScalaJava StaticDynamic Elixir/Erlang
  87. 87. @jeffksmithjr @xdotai#Devoxx Guarantees of Type Systems ScalaJava StaticDynamic Elixir/Erlang
  88. 88. @jeffksmithjr @xdotai#Devoxx Guarantees of Type Systems ScalaJava StaticDynamic Elixir/Erlang
  89. 89. @jeffksmithjr @xdotai#Devoxx Guarantees of Type Systems ScalaClojure Java StaticDynamic Elixir/Erlang
  90. 90. @jeffksmithjr @xdotai#Devoxx Guarantees of Type Systems ScalaClojure Java StaticDynamic Elixir/Erlang
  91. 91. @jeffksmithjr @xdotai#Devoxx Reactive Systems Responsive Resilient Elastic Message-Driven
  92. 92. @jeffksmithjr @xdotai#Devoxx Reactive Strategies Replication Containment Supervision
  93. 93. @jeffksmithjr @xdotai#Devoxx Reactive Machine Learning Infinite Data Uncertain Data Laziness Functions Immutable Facts Possible Worlds
  94. 94. @jeffksmithjr @xdotai#Devoxx The Future of Reactive Machine Learning On the JVM
  95. 95. @jeffksmithjr @xdotai#Devoxx Lead • Concurrency and distribution • Polyglot runtime • Interoperation
  96. 96. @jeffksmithjr @xdotai#Devoxx Learn • Deep learning • Simple concurrency • Modularize • Incremental type systems
  97. 97. @jeffksmithjr @xdotai#Devoxx For Later
  98. 98. @jeffksmithjr @xdotai#Devoxx x.ai @xdotai hello@human.x.ai New York, New York
  99. 99. @jeffksmithjr @xdotai#Devoxx reactivemachinelearning.com @jeffksmithjr Use the code ctwdevbel for 40% off all Manning books!
  100. 100. @jeffksmithjr @xdotai#Devoxx Thanks!

×