Connecting via Modzy

Modzy is a platform for deploying, scaling, and managing machine learning models. bit.io integrates with Modzy as a data store, enabling model inference directly on records stored in bit.io.

Here, we'll demo this integration by running sentiment analysis on a r/wallstreetbets comment from the public bitdotio/stonks repository.

We'll use the below comment from the table comments_sample, which we expect to be classified on the positive side:

After creating a Modzy account and getting a Modzy API key, we can send this comment directly from bit.io to Modzy for classification using a pre-trained sentiment analysis model. We demonstrate with the Modzy Python SDK, but cURL, JavaScript, and Go are also supported.

You can install the Modzy Python SDK with pip install modzy-sdk

import json

from modzy import ApiClient
from modzy._util import file_to_bytes

DB_USER_NAME = "<your_username>"
# password from the connect menu, NOT login password
DB_PASSWORD = "<your_bit.io_password>"
DB_DBNAME = "bitdotio/stonks"
# from the "profile and API keys" menu on Modzy
MODZY_API_KEY = "<your_modzy_api_key>"

# Initialize your Modzy client
client = ApiClient(base_url="https://app.modzy.com/api", api_key=MODZY_API_KEY)

# Specify the desired sentiment analysis classifier
modzy_model_id = "ed542963de"
modzy_model_version = "1.0.1"

# Add database connection and query information
db_url = f"jdbc:postgresql://db.bit.io:5432/{DB_DBNAME}"
db_username = DB_USER_NAME
db_password = DB_PASSWORD
db_driver = "org.postgresql.Driver"
# We SELECT as "input.txt" becase that is the required input name for this model
db_query = """
    SELECT "body" as "input.txt"
    FROM "bitdotio/stonks"."comments_sample"
    WHERE id = 'h12ycrs';
"""

#Once you are ready, submit the job to v1.0.1 of the sentiment analysis model
job = client.jobs.submit_jdbc(
    modzy_model_id,
    modzy_model_version,
    db_url, db_username,
    db_password,
    db_driver,
    db_query
)

#Print the response from your job submission
print(json.dumps(job))

The json output from this script confirms the submission and provides other related information. Then, we can view the inference results in the Modzy dashboard. As expected, the sentiment of this comment was classified towards the positive side.

"result": {
        "classPredictions": [
          {
            "class": "positive",
            "score": 0.569
          },
          {
            "class": "neutral",
            "score": 0.431
          },
          {
            "class": "negative",
            "score": 0
          }
        ]
      }

Using bit.io and Modzy, we can share and/or publish datasets in actual connectable Postgres databases and run inference directly from the storage location.


Did this page help you?