Message Boards Message Boards

IoT Neural Net Machine Learning Instant API

I tested the Classify algo's on a big data set of text message conversations between users and business IoT devices. The Neral Net was fantastically more accurate than the rest.

It took a long time to run, which is fine. The problem I am facing is:

After uploading it to the cloud and creating API access, the API is slower than dirt. It times out even. However, when I classify samples in the notebook it is lightning fast as always.

My code:

Quiet[CloudDeploy[
  APIFunction[{"text" -> 
     "String" -> "Please turn off the lights at 10pm."}, 
   Get["BtNeuralNetwork"][#text] &], 
  Permissions -> "Public"]]

I used "CloudGet" and the result was even slower. Not sure how that makes any sense.

I even tried compressing it before deploying using:

With[{c = Compress[c]}, 
 CloudEvaluate[Put[Uncompress[c], "BtNeuralNetwork"]]]

Nothing really makes a difference. The API is slow in responding. When I was using Markov it replied instantly on notebook and cloud. The neural net is same speed on notebook but not cloud. Obviously, "BtNeuralNetwork" is just the arbitrary name I gave the model. The fact that it responses correctly "when" it does respond tells me it's working. I just can't figure out how to speed up the response time.

POSTED BY: David Johnston
7 Replies

Any updates? I am still stumped.

POSTED BY: David Johnston

I changed the code to this:

Quiet[CloudDeploy[
  APIFunction[{"text" -> 
     "String" -> 
      "Why are you texting this to me?"}, {Get[
       "BtNeuralNetwork"][#text],
     fileCount = FileByteCount["BtNeuralNetwork"],
     loadTiming = 
      Median[First@AbsoluteTiming[Get["BtNeuralNetwork"]]]} &], 
  Permissions -> "Public"]]

Here is the API response I get:

{"REQUEST FOR INTENT", 134214106, Median[9.905657]}
POSTED BY: David Johnston
Posted 9 years ago

What is FileByteCount["BtNeuralNetwork"]? And in an APIFunction, what is your Median First@AbsoluteTiming[Get["BtNeuralNetwork"]]?

POSTED BY: Joel Klein

Yes, I trained the data on my Macbook Pro and then PUT it locally and then also PUT it in cloud. When I GET it locally or GET it from Cloud, it performs lightning fast on my laptop. The problem only happens when I ask it via API.

POSTED BY: David Johnston

Okay, like this?

Sample of training data:

(Debug) In[499]:= RandomSample[data, 10]

(Debug) Out[499]= {"id like you to contact me concerning this now" -> 
  "REQUEST TO BE CONTACTED", 
 "put me on ur list i need to get your txt messages" -> 
  "OPTIN GENERAL CONSENT", 
 "never send spam text messages to our phone" -> "REQUEST TO OPTOUT", 
 "love ya to the moon and back" -> "INITIAL LOVE YOU", 
 "i need to speak with a administrator straight away" -> 
  "REQUEST TO BE CONTACTED", 
 "holla back as well back to you too" -> "RESPONSE TO GREETING", 
 "what company working hours would you have" -> 
  "REQUEST FOR HOURS OF OPERATION", 
 "what time is ur store opened" -> "REQUEST FOR HOURS OF OPERATION", 
 "why r you mailing me all these kinds of texts" -> 
  "REQUEST FOR INTENT", 
 "love you with all my heart too" -> "RESPONSE TO LOVE YOU"}

Loading trained Neural Net:

c = Get["BtNeuralNetwork"]

ClassifierInformation[c]

Association[
"Method" -> "Neural network", "Number of classes" -> 33, 
 "Number of features" -> 1, "Number of training examples" -> 87740, 
 "Number of extracted features" -> 300, 
 "L1 regularization coefficient" -> 0, 
 "L2 regularization coefficient" -> 0.1, 
 "Number of hidden layers" -> 2, 
 "Hidden nodes" -> Row[{900, 900}, ","], 
 "Hidden layer activation functions" -> Row[{
   "Rectified Linear", "Rectified Linear"}, ","]]

Example input and classify result:

(Debug) In[497]:= c["please tell me more about your company"]

(Debug) Out[497]= "REQUEST FOR INFORMATION"
POSTED BY: David Johnston

Is it possible to post a complete code including Classify and data? If not data - just Classify referring to a training set (with a byte size of dataset mentioned) ? I do not understand where do you train your net (desktop or cloud). The more complete the discription of the problem the better it is to go about it.

POSTED BY: Sam Carrettie

I also tried finding a way to not "Get" the model every time and use a variable. However, I spent many hours and found no good tutorials or documentation on writing a simple if statement for testing whether the model we loaded already or not.

I tried:

If[BtNearalNetwork=="",Get["BtNeuralNetwork"][#text],BtNeuralNetwork[#text]]
POSTED BY: David Johnston
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract