public class MultiLabel extends Object implements Classifiable<MultiLabel>
Multi-label classification is where a (possibly empty) set of labels is predicted for each example. For example, predicting that a Reuters article has both the Finance and Sports labels.
Both the labels in the set, and the MultiLabel itself may have optional
scores (which are not required to be probabilities). If the scores are
not present these are represented by Double.NaN
. This is most
common with ground-truth labels which usually do not supply scores.
Modifier and Type | Field and Description |
---|---|
static Label |
NEGATIVE_LABEL
A Label representing the binary negative label.
|
static String |
NEGATIVE_LABEL_STRING |
Constructor and Description |
---|
MultiLabel(Label label)
Builds a MultiLabel from a single Label.
|
MultiLabel(Set<Label> labels)
Builds a MultiLabel object from a Set of Labels.
|
MultiLabel(Set<Label> labels,
double score)
Builds a MultiLabel object from a Set of Labels,
when the whole set has a score as well as (optionally)
the individual labels.
|
MultiLabel(String label)
Builds a MultiLabel with a single String label.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(Label input)
Does this MultiLabel contain this Label?
|
boolean |
contains(String input)
Does this MultiLabel contain this string?
|
DenseVector |
convertToDenseVector(ImmutableOutputInfo<MultiLabel> info)
Converts this MultiLabel into a DenseVector using the indices from the output info.
|
SparseVector |
convertToSparseVector(ImmutableOutputInfo<MultiLabel> info)
Converts this MultiLabel into a SparseVector using the indices from the output info.
|
MultiLabel |
copy()
Deep copy of the output up to it's immutable state.
|
static MultiLabel |
createFromPairList(List<com.oracle.labs.mlrg.olcut.util.Pair<String,Boolean>> dimensions)
Creates a MultiLabel from a list of dimensions.
|
Label |
createLabel(Label otherLabel)
Creates a binary label from this multilabel.
|
boolean |
equals(Object o) |
boolean |
fullEquals(MultiLabel o)
Compares other to this output.
|
Set<Label> |
getLabelSet()
The set of labels contained in this multilabel.
|
String |
getLabelString()
Returns a comma separated string representing
the labels in this multilabel instance.
|
Set<String> |
getNameSet()
The set of strings that represent the labels in this multilabel.
|
double |
getScore()
The overall score for this set of labels.
|
String |
getSerializableForm(boolean includeConfidence)
For a MultiLabel with label set = {a, b, c}, outputs a string of the form:
|
int |
hashCode() |
static int |
intersectionSize(MultiLabel first,
MultiLabel second)
The number of labels present in both MultiLabels.
|
static double |
jaccardScore(MultiLabel first,
MultiLabel second)
The Jaccard score/index between the two MultiLabels.
|
static com.oracle.labs.mlrg.olcut.util.Pair<String,Boolean> |
parseElement(String s)
Parses a string of the form:
|
static MultiLabel |
parseString(String s)
Parses a string of the form:
dimension-name=output,...,dimension-name=output
where output must be readable by
Boolean.parseBoolean(String) . |
static MultiLabel |
parseString(String s,
char splitChar)
Parses a string of the form:
|
String |
toString() |
static int |
unionSize(MultiLabel first,
MultiLabel second)
The number of unique labels across both MultiLabels.
|
public static final String NEGATIVE_LABEL_STRING
public static final Label NEGATIVE_LABEL
public MultiLabel(Set<Label> labels)
Sets the whole set score to Double.NaN
.
labels
- A set of (possibly scored) labels.public MultiLabel(Set<Label> labels, double score)
labels
- A set of (possibly scored) labels.score
- An overall score for the set.public MultiLabel(String label)
The created Label
is unscored and used by MultiLabelInfo.
Sets the whole set score to Double.NaN
.
label
- The label.public MultiLabel(Label label)
Sets the whole set score to Double.NaN
.
label
- The label.public Label createLabel(Label otherLabel)
NEGATIVE_LABEL
otherwise.otherLabel
- The input label.public String getLabelString()
public double getScore()
public Set<Label> getLabelSet()
public Set<String> getNameSet()
public boolean contains(String input)
input
- A string representing a Label
.public boolean contains(Label input)
input
- A Label
.public boolean fullEquals(MultiLabel o)
Output
fullEquals
in interface Output<MultiLabel>
o
- Another output instance.public MultiLabel copy()
Output
copy
in interface Output<MultiLabel>
public String getSerializableForm(boolean includeConfidence)
"a=true,b=true,c=true"If includeConfidence is set to true, outputs a string of the form:
"a=true,b=true,c=true:0.5"where the last element after the colon is this label's score.
getSerializableForm
in interface Output<MultiLabel>
includeConfidence
- Include whatever confidence score the label contains, if known.public DenseVector convertToDenseVector(ImmutableOutputInfo<MultiLabel> info)
info
- The info to use for the ids.public SparseVector convertToSparseVector(ImmutableOutputInfo<MultiLabel> info)
info
- The info to use for the ids.public static MultiLabel parseString(String s)
Boolean.parseBoolean(String)
.s
- The string form of a multi-label example.MultiLabel
parsed from the input string.public static MultiLabel parseString(String s, char splitChar)
dimension-name=output<splitChar>...<splitChar>dimension-name=outputwhere output must be readable by
Boolean.parseBoolean(java.lang.String)
.s
- The string form of a multilabel output.splitChar
- The char to split on.MultiLabel
output parsed from the input string.public static com.oracle.labs.mlrg.olcut.util.Pair<String,Boolean> parseElement(String s)
class1=trueOR of the form:
class1In the first case, the value in the "key=value" pair must be parseable by
Boolean.parseBoolean(String)
.
TODO: Boolean.parseBoolean("1") returns false. We may want to think more carefully about this case.s
- The string form of a single dimension from a multilabel input.public static MultiLabel createFromPairList(List<com.oracle.labs.mlrg.olcut.util.Pair<String,Boolean>> dimensions)
dimensions
- The dimensions to use.public static int intersectionSize(MultiLabel first, MultiLabel second)
first
- The first MultiLabel.second
- The second MultiLabel.public static int unionSize(MultiLabel first, MultiLabel second)
first
- The first MultiLabel.second
- The second MultiLabel.public static double jaccardScore(MultiLabel first, MultiLabel second)
first
- The first MultiLabel.second
- The second MultiLabel.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.