Skip to main content

Track Your Java Model's Performance With Weights & Biases

This article gives an overview of our new [BETA] Java client library, from installing our latest Python client to tracking the outputs in W&B.
Created on September 16|Last edited on November 4
Similar to our Python library, we offer a Java client to instrument your machine learning model and track experiments. This library consists of two simple classes that are used as a wrapper around the Python Library.

Getting Started

  1. Install the latest version of the W&B Python client: pip install wandb[grpc] --upgrade
  2. Simply include the W&B jar file in your Java Project using maven:
    <dependency>
    <groupId>com.wandb.client</groupId>
    <artifactId>client-ng-java</artifactId>
    <version>1.0-SNAPSHOT</version>
    </dependency>

Features

The motivation for creating the Java client was to allow users who build and train models in java to easily integrate with the W&B tools. Adding the W&B jar file to your project will give you access to some of the features available in the python client:
  • Setup and create custom runs
  • Using the W&B log function
Currently, the client only supports logging of basic JSONObject, but we have plans to add support for more command datatypes!

Example

In this example, we will use the new Java Client to plot a sin function.
System.out.println("Hello from wandb in java!");

// Create custom config object for fun!
JSONObject config = new JSONObject();
config.put("configNumber", 100);
config.put("configString", "Config string value!");

// Using builder to create run object
System.out.println("Creating wandb run object.");
WandbRun run = new WandbRun.Builder()
.withConfig(config)
.build();

// Print out url to monitor run on wandb
run.printRunInfo();

// Compute and log values for a sin function
for(double i = 0.0; i < 2*Math.PI; i += 0.1) {
JSONObject log = new JSONObject();
double value = Math.sin(i);
log.put("x1", value);
log.put("x2", value*2);
run.log(log);
}

// Finish the wandb run (this is required to be called at the end of your run.)
run.finish();
For the full example, including the pom.xml configuration, check out this example in the examples repo.
In order to run this example, you must have Java JDK and Maven installed on your machine. You must also install the wandb[grpc] package and be authenticated by calling wandb login MY_API_KEY.
The outputs created from this example can be seen below:

Run set
38

Iterate on AI agents and models faster. Try Weights & Biases today.