アプリケーションへのモデルのインポート Import models into your application
この記事では、 DATABRICKS ML モデルエクスポート ワークフローのインポートとスコアリングの部分について説明します。ワークフローのエクスポート部分については APACHE SPARK ML モデルとパイプラインのエクスポート に関するセクションを参照してください。This article discusses the import and scoring parts of a Databricks ML Model Export workflow; see Export Apache Spark ML models and pipelines for the export part of the workflow.
Databricks ML モデルエクスポートを使用してエクスポートされたモデルを使用するには、ライブラリで Api を呼び出し dbml-local
ます。To use models exported via Databricks ML Model Export, you call APIs in the library dbml-local
.
このライブラリには、モデルをインポートし、待機時間の短いスコア付け (予測または推論) を実行するための、拡張性のある Java Api が用意されています。This library provides Scala and Java APIs for importing models and performing low latency scoring (prediction or inference).
Java アプリケーションでの保存されたモデルの使用Using saved models in Java applications
ロジスティック回帰パイプラインをエクスポートし、に保存したと my_models/lr_pipeline
します。Suppose that you have exported a logistic regression pipeline and saved it under my_models/lr_pipeline
. を使用すると、 ModelFactory
LocalModel
保存されているモデルのディレクトリからを作成し、新しいデータに対してスコア付けを実行できます。You can use ModelFactory
to create a LocalModel
from the saved model’s directory and perform scoring on new data.
// Load exported model
String modelPath = "my_models/lr_pipeline";
LocalModel model = ModelFactory.loadModel(modelPath);
// The model input is a standard JSON string.
// The input schema here is: [origLabel: Double, features: Vector].
String input =
"{\"origLabel\":-1.0," +
"\"features\":{\"type\":0,\"size\":13," +
"\"indices\":[0,2,3,4,6,7,8,9,10,11,12]," +
"\"values\":[74.0,2.0,120.0,269.0,2.0,121.0,1.0,0.2,1.0,1.0,3.0]}" +
"}";
// The model output is also a standard JSON string, with the expected output fields.
String output = model.transform(input);
この入力では、メソッドを使用して Apache Spark データセットと DataFrames よって生成される同じ JSON 形式が受け入れられ Dataset.toJSON
ます (「 Dataset API ドキュメント」を参照してください)。The input accepts the same JSON format produced by Apache Spark Datasets and DataFrames using the Dataset.toJSON
method (see Dataset API docs).
詳細については、「 dbml-ローカル API ドキュメント 」を参照してください。See the dbml-local API docs for more details.
dbml-local
Maven でライブラリの依存関係を指定するSpecifying the dbml-local
library dependency in Maven
dbml-local
Maven 座標を使用して、他の依存関係と同様に、アプリケーションに対してライブラリの依存関係を指定します。You specify the dbml-local
library dependency to an application just like any other dependency, with a Maven coordinate. 次のコードスニペットは、Maven プロジェクトビルドファイルにを含める例を示して dbml-local
pom.xml
います。The following code snippet gives an example of including dbml-local
in a Maven project pom.xml
build file.
<!-- Add repository for dbml-local dependency -->
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-databricks-maven</id>
<name>bintray</name>
<url>https://dl.bintray.com/databricks/maven</url>
</repository>
</repositories>
<dependencies>
<!-- Main dependency for Model Scoring -->
<dependency>
<groupId>com.databricks</groupId>
<artifactId>dbml-local</artifactId>
<version>0.2.2-spark2.2</version>
</dependency>
</dependencies>
Jar のダウンロード dbml-local
Downloading dbml-local
JARs
この dbml-local
jar は bintrayから入手できます。The dbml-local
JARs are available from bintray.
dbml-local
使用dbml-local
license
dbml-local
ライブラリはMIT ライセンスの下で公開されます。The dbml-local
library is published under the MIT license.
サンプル アプリケーションExample application
Databricks ML モデルエクスポートコンパニオンライブラリを使用する方法を示す非常に単純なサンプルアプリケーションについては、 dbml-local
Databricks Github リポジトリを参照してください。You can view a very simple example application that shows how to use the Databricks ML Model Export companion library dbml-local
in the databricks-ml-examples Github repository.
このデモには、MLlib モデルをトレーニングおよびエクスポートするための Databricks notebook が含まれています。This demo includes Databricks notebooks for training and exporting MLlib models.
これらのノートブックは、モデルをインポートして予測を行う方法を示す単純な Java アプリケーションとペアになっています。These notebooks are paired with simple Java applications that show how to import models and make predictions.