1
$\begingroup$

tl;dr
How do I use something like the tidypredict tool to move a neural network either textbook mlp, or deep, to SQL code?

Background:
This is an example that shows how to convert a linear model to SQL using tidypredict.

link:
https://tidypredict.tidymodels.org/reference/tidypredict_sql.html

Code:

library(dbplyr)
#> 
#> Attaching package: ‘dbplyr’
#> The following objects are masked from ‘package:dplyr’:
#> 
#>     ident, sql

model <- lm(mpg ~ wt + am + cyl, data = mtcars)
tidypredict_sql(model, simulate_dbi())
#> <SQL> 39.4179334351865 + (`wt` * -3.12514220026708) + (`am` * 0.176493157719668) + (`cyl` * -1.5102456624971)

Here is how to do the same for a randomforest:

link:
https://tidypredict.netlify.app/articles/randomforest/

code:

library(randomForest)
model <- randomForest(Species ~ .,data = iris ,ntree = 10, proximity = TRUE)

library(tidypredict)

tidypredict_sql(model, dbplyr::simulate_mssql())

Part of the backend is the dbplyr interface, and the "translate_sql" function.
https://dbplyr.tidyverse.org/articles/translation-function.html

Question:
How do I get this to work with a multilayer perceptron (dense) network? With a convolutional network?

Thoughts:

An old-school MLP neural network is an ensemble of parallel and series linear models with a nonlinear activation function, the nugget of which which is very clearly in-domain for tidymodels. The process of rolling over a standard format seems like it would be the only (?) gap.

Tensorflow converts the expressions into a graph formulation, then compiles on the graph to get a sizeable speedup. Part of that is the graph that, in theory, should be able to be translated to something like neo4j, a graph database. TF exports to SavedModel and TensorFlow Lite formats which allow transport, and might allow translation.

H2O.ai has POJO/MOJO formats that allow model transport and deployment including for neural networks.

CRAN has a "model deployment" but it doesn't seem to give a way to encode a NN into SQL.
https://cran.r-project.org/web/views/ModelDeployment.html

$\endgroup$
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.