Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding accessors to ClassifierChainModel and IndependentMultiLabelModel #302

Merged
merged 2 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ public List<Prediction<Label>> predict(SequenceExample<Label> examples) {
} else {
return viterbi(examples);
}
}

/**
* Returns the inner model used for sequence element predictions.
* @return The inner model.
*/
public Model<Label> getInnerModel() {
return model;
}

private List<Feature> extractFeatures(List<Label> labels) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ public static ClassifierChainModel deserializeFromProto(int version, String clas
return new ClassifierChainModel(carrier.name(),carrier.provenance(),carrier.featureDomain(),outputDomain,labelOrder,models);
}

/**
* Returns an unmodifiable view on the chain members.
* @return The chain members.
*/
public List<Model<Label>> getModels() {
return models;
}

@Override
public Prediction<MultiLabel> predict(Example<MultiLabel> example) {
Set<Label> predictedLabels = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ public static IndependentMultiLabelModel deserializeFromProto(int version, Strin
return new IndependentMultiLabelModel(carrier.name(),carrier.provenance(),carrier.featureDomain(),outputDomain,labels,models);
}

/**
* Returns an unmodifiable view on the binary model members.
* @return The binary model members.
*/
public List<Model<Label>> getModels() {
return Collections.unmodifiableList(models);
}

/**
* Returns the training label order.
* @return The training label order.
*/
public List<Label> getLabelOrder() {
return Collections.unmodifiableList(labels);
}

@Override
public Prediction<MultiLabel> predict(Example<MultiLabel> example) {
Set<Label> predictedLabels = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@

import com.oracle.labs.mlrg.olcut.config.Config;
import com.oracle.labs.mlrg.olcut.provenance.Provenance;
import java.util.Collections;
import org.tribuo.Dataset;
import org.tribuo.Example;
import org.tribuo.ImmutableFeatureMap;
Expand Down Expand Up @@ -120,7 +121,9 @@ public Model<MultiLabel> train(Dataset<MultiLabel> examples, Map<String, Provena
modelsList.add(innerTrainer.train(trainingData));
}

return new IndependentMultiLabelModel(labelList,modelsList,provenance,featureMap,labelInfo);
return new IndependentMultiLabelModel(Collections.unmodifiableList(labelList),
Collections.unmodifiableList(modelsList),
provenance,featureMap,labelInfo);
}

@Override
Expand Down