2

I have build a model in the R version of keras and deployed it through Google Cloud ML

The model is trained on numerical inputs which have been converted from strings

When It comes to making predictions, I convert the strings to numeric using a lookup table and then pass the numerical input to the model

This is simple to do on the local machine:

library(tidyverse)
library(cloudml)

# lookup table 
lookup <- tibble(int = c(1, 2, 3),
                 str = c('A1', 'B1', 'C1'))

# input strings
 a <- 'A1'
 b <- 'B1'

# convert to numeric 
a_ <- lookup %>% filter(str == a) %>% select(int) %>% pull()
b_ <- lookup %>% filter(str == b) %>% select(int) %>% pull()

# send to deployed model and receive predictions
cloudml_predict(
  instances = list(c(a_, b_)),
  name = "size_predictor",
  version = "a_1",
  verbose = T
)

However I can't work out where I need to put the lookup table on cloud ml. It is a few million rows long. Do I need to add another layer to the keras model at the beginning to do the conversion?

Alternatively can I store the lookup table in BigQuery and divert inputs through this beforehand?

The answers I have found so far apply only to python, for example this: Add Tensorflow pre-processing to existing Keras model (for use in Tensorflow Serving)

Shinobi_Atobe
  • 1,793
  • 1
  • 18
  • 35
  • Have you registered for this service? See: https://cloud.google.com/monitoring/ – IRTFM Jan 18 '19 at 04:53
  • Hello, would you mind explaining what this is and how I could use it to help? – Shinobi_Atobe Jan 18 '19 at 11:06
  • If you were just doing this with R you would need to include enough information to run the programs. Usually involves posting output of `library` calls and `sessionInfo()` Since you are doing this on a multi-platform basis you _should_ post even _more_ information about how you have the cloud account set up and what sort of login procedure you are following. We cannot vote to close for lack of code, but if this were not in the "extra attention" queue that's what I would have done. – IRTFM Jan 19 '19 at 03:48
  • @42- the output of `library` and `sessionInfo()` will in no way help answer this question – Shinobi_Atobe Jan 22 '19 at 11:15

1 Answers1

1

In your input function in Keras, can you use tf.gather() to convert the string that is received to an int? Then, it is part of the model, and will work transparently.

Lak
  • 3,876
  • 20
  • 34