bulkLog

Call arize.bulkLog to publish the features, predicted label, actual, and SHAP for a single data point to Arize for monitoring, analysis, and explainability in bulk.

Overview

Use the initialized Arize client to call arize.bulkLog() with collections of predicted labels, observed actuals, their feature inputs, their shap values, and corresponding prediction ids. Once records are sent to Arize's platform, you'll be able to visualize and analyze data holistically or within aggregated slices.

arize.bulkLog() returns a Response. You can await on the Response to complete to ensure successful delivery of records.

When logging a prediction for the first time for a new model, we classify the model in the Arize platform based on the data type of the prediction.

For more information on model schema discovery, visit here:

What Is A Model Schema

API

<T> Response bulkLog( final String modelId, final String modelVersion, final List<String> predictionIds, final List<Map<String, ?>> features, final List<Map<String, ?>> tags, final List<Map<String, Embedding>> embeddingFeatures, final List<T> predictionLabels, final List<T> actualLabels, final List<Map<String, Double>> shapValues final List<Long> predictionTimestamps) throws IOException, IllegalArgumentException;

Important: If multiple iterable arguments (i.e prediction, actual, and explainability) are passed in the same call, they must be (1) the same length, (2) map to the same predictionIds by entry.

API Arguments

Paramater

Data Type

Description

modelId

String

The unique identifier for your model.

Required

modelVersion

String

Used to group together a subset of predictions and actuals for a given model_id.

Required for logging predictions. Optional for logging actuals or shap values.

predictionIds

List<Strings>

Unique identifiers for all your bulk predictions contained in a List<Strings>

Important: The values are used to match predictions to actual labels or feature importances (SHAP) in the Arize platform.

Required

features

List<Map<String, ?>>

Where value can be oneOf: String, int, long, short, double, float, boolean, List<String>

List of Maps containing human readable and debuggable model features. Keys must be Strings and values one of: String, int, long, short, double, float, boolean, List<String>

Optional

embeddingFeatures

Map<String, Embedding>

Map containing human readable and debuggable model embedding features. Map keys must be String and values Embedding

Optional

tags

Map<String, ?> Where value can be oneOf: String, int, long, short, double, float, boolean, List<String>

Map containing human readable and debuggable model features. Map keys must be String and values one of: String, int, long, short, double, float, boolean, List<String>

Optional

predictionLabels

List<T> where T is oneof String, boolean, int, long, short, float, double, ScoreCategorical

The predicted labels for your given model inputs contained in a List<T>

Important: If sent in as an argument, entries are matched respectively to the entries in prediction ids, feature values, and feature importances in the same index.

Important: Must have the same number of elements as feature, actuals, and importances is all sent together.

Optional

actualLabels

List<T> where T is oneof String, boolean, int, long, short, float, double, ScoreCategorical

The actual observed labels for a given model input.

Important: If passed together in a single call with predictionLabels, both inputs must have the same shape.

Important: If model is Score Categorical, Arize.ScoreCategorical object should be passed in with corresponding predictedLabel, probabilityScore.

Optional

shapValues

List<Map<String, Double>>

The SHAP value sets for a set of predictions.

SHAP value sets are correspond to the prediction ids with the same index.

Optional

predictionTimestamps

List<int>

List of int representing Unix epoch time in seconds, set to overwrite the timestamp for prediction.

If null, defaults to using the current timestamp.

Important: Future and Historical predictions are supported up to 1 year from current wall clock time.

Optional

Sample Code

import com.arize.ArizeClient;
import com.arize.Response;
import com.arize.types.Embedding;

// You only need to instantiate the client once
final ArizeClient arize = new ArizeClient(System.getenv("ARIZE_API_KEY"), System.getenv("ARIZE_SPACE_KEY"));
        
final List<Map<String, ?>> features = new ArrayList<Map<String, ?>>();
features.add(new HashMap<String, Object>() {{ put("days", 5); put("is_organic", 1);}});
features.add(new HashMap<String, Object>() {{ put("days", 3); put("is_organic", 0);}});
features.add(new HashMap<String, Object>() {{ put("days", 7); put("is_organic", 0);}});

final List<Map<String, Embedding>> embeddingFeatures = new ArrayList<Map<String, Embedding>>();
embeddingFeatures.add(new HashMap<String, Embedding>() {{ put("embedding_feature_1", new Embedding(Arrays.asList(1.0, 0.5), Arrays.asList("test", "token", "array"), "https://example.com/image.jpg")); put("embedding_feature_2", new Embedding(Arrays.asList(1.0, 0.8), Arrays.asList("this", "is"), "https://example.com/image_3.jpg"));}});
embeddingFeatures.add(new HashMap<String, Embedding>() {{ put("embedding_feature_1", new Embedding(Arrays.asList(0.0, 0.6), Arrays.asList("another", "example"), "https://example.com/image_2.jpg")); put("embedding_feature_2", new Embedding(Arrays.asList(0.1, 1.0), Arrays.asList("an", "example"), "https://example.com/image_4.jpg"));}});
embeddingFeatures.add(new HashMap<String, Embedding>() {{ put("embedding_feature_1", new Embedding(Arrays.asList(1.0, 0.8), Arrays.asList("third"), "https://example.com/image_3.jpg")); put("embedding_feature_2", new Embedding(Arrays.asList(1.0, 0.4), Arrays.asList("token", "array"), "https://example.com/image_5.jpg"));}});

final List<Map<String, ?>> tags = new ArrayList<Map<String, ?>>();
tags.add(new HashMap<String, Object>() {{ put("metadata", 5); put("my business metric", 1);}});
tags.add(new HashMap<String, Object>() {{ put("metadata", 3); put("my business metric", 0);}});
tags.add(new HashMap<String, Object>() {{ put("metadata", 7); put("my business metric", 8);}});

final List<Map<String, Double>> shapValues = new ArrayList<>();
shapValues.add(new HashMap<String, Double>(){{ put("days", 1.0); put("is_organic", -1.5);}});
shapValues.add(new HashMap<String, Double>(){{ put("days", 1.0); put("is_organic", -1.1);}});
shapValues.add(new HashMap<String, Double>(){{ put("days", 1.0); put("is_organic", -1.1);}});

final List<String> labels = new ArrayList<String>(Arrays.asList("pear", "banana", "apple"));
final List<String> predictionIds = new ArrayList<String>(Arrays.asList(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()));

final Response asyncResponse = arize.bulkLog("exampleModelId", "v1", predictionIds, features, embeddingFeatures, tags, labels, null, shapValues,null);

// This is a blocking call similar to future.get()
asyncResponse.resolve();

// Check that the API call was successful
switch (asyncResponse.getResponseCode()) {
    case OK:
        // TODO: Success!
        System.out.println("Success!!!");
        break;
    case AUTHENTICATION_ERROR:
        // TODO: Check to make sure your Arize API KEY and Space key are correct
        break;
    case BAD_REQUEST:
        // TODO: Malformed request
        System.out.println("Failure Reason: " + asyncResponse.getResponseBody());
    case NOT_FOUND:
        // TODO: API endpoint not found, client is likely malconfigured, make sure you
        // are not overwriting Arize's endpoint URI
        break;
    case UNEXPECTED_FAILURE:
        // TODO: Unexpected failure, check for a reason on response body
        System.out.println("Failure Reason: " + asyncResponse.getResponseBody());
        break;
}

System.out.println("Response Code: " + asyncResponse.getResponseCode());
System.out.println("Response Body: " + asyncResponse.getResponseBody());

// Don't forget to shutdown the client with your application shutdown hook.
arize.close();
System.out.println("Done");

Sample Code - Sending Data for Ranking Models

ArizeClient arize = new ArizeClient(System.getenv("ARIZE_API_KEY"), System.getenv("ARIZE_SPACE_KEY"));

final List<String> predictionIds =
        new ArrayList<>(
                Arrays.asList(
                        UUID.randomUUID().toString(),
                        UUID.randomUUID().toString(),
                        UUID.randomUUID().toString(),
                        UUID.randomUUID().toString(),
                        UUID.randomUUID().toString(),
                        UUID.randomUUID().toString()));


final List<ArizeClient.Ranking> predictionLabels =
        Arrays.asList(
                new ArizeClient.Ranking.RankingBuilder().setPredictionGroupId("XX").setPredictionScore(9.8).setRank(1).build(),
                new ArizeClient.Ranking.RankingBuilder().setPredictionGroupId("XX").setPredictionScore(9.5).setRank(2).build(),
                new ArizeClient.Ranking.RankingBuilder().setPredictionGroupId("XX").setPredictionScore(9.0).setRank(3).build(),
                new ArizeClient.Ranking.RankingBuilder().setPredictionGroupId("YY").setPredictionScore(9.7).setRank(1).build(),
                new ArizeClient.Ranking.RankingBuilder().setPredictionGroupId("YY").setPredictionScore(9.2).setRank(2).build(),
                new ArizeClient.Ranking.RankingBuilder().setPredictionGroupId("YY").setPredictionScore(8.0).setRank(3).build()
        );

final List<ArizeClient.Ranking> actualLabels =
        Arrays.asList(
                new ArizeClient.Ranking.RankingBuilder().setRelevanceScore(1).setRelevanceLabels(MultiValue.newBuilder().addAllValues(Arrays.asList("click", "purchase")).build()).build(),
                new ArizeClient.Ranking.RankingBuilder().setRelevanceScore(1).setRelevanceLabels(MultiValue.newBuilder().addAllValues(Collections.singletonList("click")).build()).build(),
                new ArizeClient.Ranking.RankingBuilder().setRelevanceScore(1).setRelevanceLabels(MultiValue.newBuilder().addAllValues(Collections.singletonList("no-event")).build()).build(),
                new ArizeClient.Ranking.RankingBuilder().setRelevanceScore(1).setRelevanceLabels(MultiValue.newBuilder().addAllValues(Collections.singletonList("click")).build()).build(),
                new ArizeClient.Ranking.RankingBuilder().setRelevanceScore(1).setRelevanceLabels(MultiValue.newBuilder().addAllValues(Collections.singletonList("no-event")).build()).build(),
                new ArizeClient.Ranking.RankingBuilder().setRelevanceScore(1).setRelevanceLabels(MultiValue.newBuilder().addAllValues(Arrays.asList("click", "purchase")).build()).build()

        );
final List<Map<String, ?>> tags = new ArrayList<>();
for (ArizeClient.Ranking predictionLabel : predictionLabels) {
    tags.add(new HashMap<String, Object>() {
        {
            put("Rank", predictionLabel.getRank());
        }
    });
}

final Response asyncResponse =
        arize.bulkLog(
                "exampleModelId",
                "v1",
                predictionIds,
                null,
                null,
                tags,
                predictionLabels,
                actualLabels,
                null,
                null);
                
// This is a blocking call similar to future.get()
asyncResponse.resolve();

Questions? Email us at support@arize.com or Slack us in the #arize-support channel

Last updated

Copyright © 2023 Arize AI, Inc