labelScorer
labelScorer:* components compute a numerical score for each label (such as document or term frequency).
You can use label scores to output additional information about labels for display or filtering purposes or to
recompute scores of a set of labels using information from different fields or document scopes.
You can use the following label scorers in your analysis requests:
-
labelScorer:byVectorSimilarity -
Computes the similarity between the label's embedding vector and another vector you provide.
-
labelScorer:byVectorsSimilarity -
Computes the similarity between the label's embedding vector and a set of vectors you provide.
-
labelScorer:composite -
Aggregates the scores computed by the scorers you provide into a single score.
-
labelScorer:df -
Computes the label's document frequency (DF).
-
labelScorer:identity -
Returns the label's original weight.
-
labelScorer:idf -
Computes the label's inverse document frequency (IDF).
-
labelScorer:probabilityRatio -
Computes the probability ratio coefficient, which you can use to identify labels that are more probable to appear in the subset of documents of your choice than in the whole collection.
-
labelScorer:tf -
Computes the label's term frequency (TF).
Here is an example where we use the
labels:scored stage to recompute the weights of
labels from the title field, using document frequencies retrieved from the abstract
field of the reference arXiv data set.
{
"stages": {
"documents": {
"type": "documents:byQuery",
"query": {
"type": "query:string",
"query": "photon"
},
"limit": 500
},
"tf": {
"type": "labels:scored",
"scorer": {
"type": "labelScorer:df",
"fields": {
"type": "featureFields:simple",
"fields": [
"abstract$phrases"
]
},
"scope": {
"type": "documents:reference",
"use": "documents"
}
},
"labels": {
"type": "labels:fromDocuments",
"documents": {
"type": "documents:reference",
"use": "documents"
},
"maxLabels": {
"type": "labelCount:fixed",
"value": 10
},
"labelAggregator": {
"type": "labelAggregator:topWeight",
"labelCollector": {
"type": "labelCollector:topFromFeatureFields",
"fields": {
"type": "featureFields:simple",
"fields": [
"title$phrases"
]
}
}
}
}
}
},
"output": {
"stages": [
"tf"
]
}
}The result of the above request, on the reference Arxiv index:
{
"result" : {
"tf" : {
"labels" : [
{
"label" : "single-photon",
"weight" : 1172.25
},
{
"label" : "entangled photons",
"weight" : 356.364
},
{
"label" : "photon-photon",
"weight" : 525.168
},
{
"label" : "two-photon",
"weight" : 759.618
},
{
"label" : "interference",
"weight" : 403.254
},
{
"label" : "collisions",
"weight" : 403.254
},
{
"label" : "detector",
"weight" : 637.704
},
{
"label" : "entanglement",
"weight" : 487.656
},
{
"label" : "dark photon",
"weight" : 187.56
}
]
}
}
}labelScorer:byVectorSimilarity
Computes the similarity between the label's embedding vector and another vector you provide.
{
"type": "labelScorer:byVectorSimilarity",
"failIfEmbeddingsNotAvailable": true,
"undefinedVectorScore": "ZERO",
"vector": {
"type": "vector:reference",
"auto": true
}
}failIfEmbeddingsNotAvailable
Determines the behavior of this stage if the index does not contain document embeddings.
If the index does not contain document embeddings and failIfEmbeddingsNotAvailable is:
true- this stage fails and logs an error.
false- this stage returns zero scores for all labels.
undefinedVectorScore
The score to assign to all labels when the
vector to compute the similarity against is
undefined.
The undefinedVectorScore property supports the following values:
ZERO-
The label's score is zero.
LABEL_WEIGHT-
The label keeps its original weight, as if scored by the
labelScorer:identityscorer. ONE-
The label's score is one. This is useful when the score is an input of a multiplicative aggregation, such as the geometric mean computed by the
labelScorer:compositescorer, where a zero score would zero out the aggregate.
vector
The vector against which to compute the similarity.
labelScorer:byVectorsSimilarity
Computes the similarity between the label's embedding vector and a set of vectors you provide.
{
"type": "labelScorer:byVectorsSimilarity",
"failIfEmbeddingsNotAvailable": true,
"minSimilarity": 0,
"undefinedVectorScore": "ZERO",
"vectors": {
"type": "vectors:reference",
"auto": true
},
"weightAggregation": "SUM"
}failIfEmbeddingsNotAvailable
Determines the behavior of this stage if the index does not contain document embeddings.
The label's score is an aggregate of the similarities against the vectors you provide, computed using the
weightAggregation function.
Similarity between the label's vector and the particular input vector is included in the score only when the
similarity is larger than minSimilarity.
If the index does not contain document embeddings and failIfEmbeddingsNotAvailable is:
true- this stage fails and logs an error.
false- this stage returns zero scores for all labels.
minSimilarity
The minimum similarity between the label's and input vector for the similarity to be included in the label's score.
undefinedVectorScore
The score to assign to all labels when all the
vectors to compute the similarities against
are undefined.
The undefinedVectorScore property supports the following values:
ZERO-
The label's score is zero.
LABEL_WEIGHT-
The label keeps its original weight, as if scored by the
labelScorer:identityscorer. ONE-
The label's score is one. This is useful when the score is an input of a multiplicative aggregation, such as the geometric mean computed by the
labelScorer:compositescorer, where a zero score would zero out the aggregate.
vectors
The vectors against which to compute the label's vector similarities.
weightAggregation
The aggregation function Lingo4G uses to compute the label's score based on the label's similarities to the
vectors you provide. If no similarity is larger than
minSimilarity, the label's score is zero.
See weightAggregation
documentation for the available options.
labelScorer:composite
Computes an aggregate score that is a geometric mean of values returned by the scorers you provide.
{
"type": "labelScorer:composite",
"scorers": []
}scorers
An array of scorers from which an aggregate should be computed.
labelScorer:df
Computes label document frequency (DF). Document frequency corresponds to the number of documents the label occurred in (contrary to the term frequency, multiple occurrences within a single document count as one).
{
"type": "labelScorer:df",
"fields": {
"type": "featureFields:reference",
"auto": true
},
"scope": {
"type": "documents:reference",
"auto": true
}
}fields
A reference to feature fields used to retrieve label statistics from.
scope
A reference to a set of documents used to compute label statistics from.
labelScorer:identity
This label scorer does not change the externally provided score of the label, it is an identity scorer.
{
"type": "labelScorer:identity"
}labelScorer:idf
Computes the inverse document frequency (IDF) for each label.
{
"type": "labelScorer:idf",
"fields": {
"type": "featureFields:reference",
"auto": true
},
"scope": {
"type": "documents:reference",
"auto": true
}
}The inverse document frequency is computed using the following formula:
where is the total number of unique documents in scope and is the number of documents with occurrences of the label.
fields
A reference to feature fields used to retrieve label statistics from.
scope
A reference to a set of documents used to compute label statistics from.
labelScorer:probabilityRatio
Computes label's probability ratio coefficient, which you can use to identify labels that are more probable to appear in the subset of documents of your choice than in the whole collection.
{
"type": "labelScorer:probabilityRatio",
"baseScope": {
"type": "documents:reference",
"auto": true
},
"fields": {
"type": "featureFields:reference",
"auto": true
},
"referenceScope": {
"type": "documents:sample",
"limit": 10000,
"query": {
"type": "query:all"
},
"randomSeed": 0,
"samplingRatio": 1
}
}
The probability ratio coefficient is computed as a ratio between the given label's probability of occurrence in
the base scope against the reference scope. Labels with higher probability of occurrence
in the baseScope (compared to their probability of occurrence in the referenceScope)
should receive higher scores:
The probability for each scope is computed using the following formula, where is equal to the number of unique labels being scored (a form of additive probability smoothing function):
baseScope
A reference to a set of documents providing the "focus" document scope.
fields
A reference to feature fields used to retrieve label statistics from.
referenceScope
A reference to a set of documents providing the "reference" scope.
labelScorer:tf
Computes the term frequency (TF) for each label. The term frequency is the number of times a given label occurred throughout the scope (including repetitions within the document's fields).
{
"type": "labelScorer:tf",
"fields": {
"type": "featureFields:reference",
"auto": true
},
"scope": {
"type": "documents:reference",
"auto": true
}
}fields
A reference to feature fields used to retrieve label statistics from.
scope
A reference to a set of documents used to compute label statistics from.
Consumers of labelScorer:*
The following stages and components take labelScorer:* as
input:
| Stage or component | Property |
|---|---|
labelScorer:composite | scorers |
labels:scored | scorer |