User-Defined Function#

User-defined functions (UDFs) allow us to combine SQL with deep learning models. These functions wrap around deep learning models.

Here is an illustrative UDF for classifying MNIST images.

!wget -nc
cursor.execute("""DROP UDF IF EXISTS MnistImageClassifier;""")
response = cursor.fetch_all()

cursor.execute("""CREATE UDF IF NOT EXISTS MnistImageClassifier
                  INPUT  (data NDARRAY (3, 28, 28))
                  OUTPUT (label TEXT(2))
                  TYPE  Classification
                  IMPL  '';
response = cursor.fetch_all()

Run a query using the newly registered UDF!#

cursor.execute("""SELECT data, MnistImageClassifier(data).label
                  FROM MNISTVideoTable
                  WHERE id = 30;""")
response = cursor.fetch_all()

Visualize the output#

The output of the query is visualized in the notebook.