T
- The output subclass that this model operates on.U
- The internal representation of features.V
- The internal representation of outputs.public abstract class ExternalModel<T extends Output<T>,U,V> extends Model<T>
Batch size defaults to DEFAULT_BATCH_SIZE
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BATCH_SIZE
Default batch size for external model batch predictions.
|
protected int[] |
featureBackwardMapping |
protected int[] |
featureForwardMapping |
ALL_OUTPUTS, BIAS_FEATURE, featureIDMap, generatesProbabilities, name, outputIDInfo, provenance, provenanceOutput
Modifier | Constructor and Description |
---|---|
protected |
ExternalModel(String name,
ModelProvenance provenance,
ImmutableFeatureMap featureIDMap,
ImmutableOutputInfo<T> outputIDInfo,
boolean generatesProbabilities,
Map<String,Integer> featureMapping) |
protected |
ExternalModel(String name,
ModelProvenance provenance,
ImmutableFeatureMap featureIDMap,
ImmutableOutputInfo<T> outputIDInfo,
int[] featureForwardMapping,
int[] featureBackwardMapping,
boolean generatesProbabilities) |
Modifier and Type | Method and Description |
---|---|
protected abstract U |
convertFeatures(SparseVector input)
Converts from a SparseVector using the external model's indices into
the ingestion format for the external model.
|
protected abstract U |
convertFeaturesList(List<SparseVector> input)
Converts from a list of SparseVector using the external model's indices
into the ingestion format for the external model.
|
protected abstract List<Prediction<T>> |
convertOutput(V output,
int[] numValidFeatures,
List<Example<T>> examples)
Converts the output of the external model into a list of
Prediction s. |
protected abstract Prediction<T> |
convertOutput(V output,
int numValidFeatures,
Example<T> example)
Converts the output of the external model into a
Prediction . |
protected static ImmutableFeatureMap |
createFeatureMap(Set<String> featureNames)
Creates an immutable feature map from a set of feature names.
|
protected static <T extends Output<T>> |
createOutputInfo(OutputFactory<T> factory,
Map<T,Integer> outputs)
Creates an output info from a set of outputs.
|
protected abstract V |
externalPrediction(U input)
Runs the external model's prediction function.
|
int |
getBatchSize()
Gets the current testing batch size.
|
Optional<Excuse<T>> |
getExcuse(Example<T> example)
By default third party models don't return excuses.
|
protected List<Prediction<T>> |
innerPredict(Iterable<Example<T>> examples)
Called by the base implementations of
Model.predict(Iterable) and Model.predict(Dataset) . |
Prediction<T> |
predict(Example<T> example)
Uses the model to predict the output for a single example.
|
void |
setBatchSize(int batchSize)
Sets a new batch size.
|
copy, copy, generatesProbabilities, getExcuses, getFeatureIDMap, getName, getOutputIDInfo, getProvenance, getTopFeatures, predict, predict, setName, toString, validate
public static final int DEFAULT_BATCH_SIZE
protected final int[] featureForwardMapping
protected final int[] featureBackwardMapping
protected ExternalModel(String name, ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, boolean generatesProbabilities, Map<String,Integer> featureMapping)
protected ExternalModel(String name, ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, int[] featureForwardMapping, int[] featureBackwardMapping, boolean generatesProbabilities)
public Prediction<T> predict(Example<T> example)
Model
predict does not mutate the example.
Throws IllegalArgumentException
if the example has no features
or no feature overlap with the model.
protected List<Prediction<T>> innerPredict(Iterable<Example<T>> examples)
Model
Model.predict(Iterable)
and Model.predict(Dataset)
.innerPredict
in class Model<T extends Output<T>>
examples
- The examples to predict.protected abstract U convertFeatures(SparseVector input)
input
- The features using external indices.protected abstract U convertFeaturesList(List<SparseVector> input)
input
- The features using external indices.protected abstract V externalPrediction(U input)
input
- The input in the external model's format.protected abstract Prediction<T> convertOutput(V output, int numValidFeatures, Example<T> example)
Prediction
.output
- The output of the external model.numValidFeatures
- The number of valid features in the input.example
- The input example, used to construct the Prediction.protected abstract List<Prediction<T>> convertOutput(V output, int[] numValidFeatures, List<Example<T>> examples)
Prediction
s.output
- The output of the external model.numValidFeatures
- An array with the number of valid features in each example.examples
- The input examples, used to construct the Predictions.public Optional<Excuse<T>> getExcuse(Example<T> example)
public int getBatchSize()
public void setBatchSize(int batchSize)
Throws IllegalArgumentException
if the batch size isn't positive.
batchSize
- The batch size to use.protected static ImmutableFeatureMap createFeatureMap(Set<String> featureNames)
Each feature is unobserved.
featureNames
- The names of the features to create.protected static <T extends Output<T>> ImmutableOutputInfo<T> createOutputInfo(OutputFactory<T> factory, Map<T,Integer> outputs)
T
- The type of the outputs.factory
- The output factory to use.outputs
- The outputs and ids to observe.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.