labelFilter
labelFilter:* accepts or rejects an individual label based on the label's text. You can use label
filters to customize the processing inside label collectors as
well as label fetching stages, such as
labels:byPrefix
or
labels:embeddingNearestNeighbors.
You can use the following label filters in your analysis requests:
-
labelFilter:acceptAll -
Accepts all labels.
-
labelFilter:acceptLabels -
Accepts labels appearing in the set of labels provided by the referenced
labels:*source. -
labelFilter:autoStopLabels -
Rejects any meaningless labels Lingo4G automatically identified during indexing.
-
labelFilter:characterCount -
Accepts or rejects labels based on the number of characters they have.
-
labelFilter:complement -
Rejects labels that are accepted by another filter (inverts the result of another label filter).
-
labelFilter:composite -
Accepts labels if they are accepted by all or any of the label filters you provide.
-
labelFilter:dictionary -
Accepts labels matched by the label dictionary you provide.
-
labelFilter:hasEmbedding -
Accepts labels that have a multidimensional embedding vector available.
-
labelFilter:rejectLabels -
Rejects label appearing on the closed list you provide.
-
labelFilter:rejectTokens -
Rejects labels that contain words and prases present in the labels you provide.
-
labelFilter:surface -
Accepts labels based on their exact appearance (case-sensitive characters). You can configure this filter to remove all-uppercase, capitalized or acronym-like labels.
-
labelFilter:switch -
Enables or disables the label filter you provide.
-
labelFilter:tokenCount -
Accepts labels based on the number of words in the label.
labelFilter:reference-
References a
labelFilter:*component defined in the request or in the project's default components.
labelFilter:acceptAll
Accepts all labels.
{
"type": "labelFilter:acceptAll"
}labelFilter:acceptLabels
Accepts labels appearing in the set of labels provided by the referenced
labels:* source.
{
"type": "labelFilter:acceptLabels",
"labels": {
"type": "labels:reference",
"auto": true
}
}An example request below retrieves a list of top labels that appear in documents matching the query magnetic field, but limited to only those labels that also appear in documents that match the query pulsar. In effect, the result of this request is an intersection of label sets between these two document queries.
{
"name": "Retrieve document labels from documents matching 'magnetic field' but only appearing in documents matching 'pulsar'.",
"stages": {
"labels": {
"type": "labels:fromDocuments",
"maxLabels": {
"type": "labelCount:fixed",
"value": 10
},
"documents": {
"type": "documents:byQuery",
"query": {
"type": "query:string",
"query": "\"magnetic field\""
},
"limit": "unlimited"
},
"labelAggregator": {
"type": "labelAggregator:topWeight",
"labelCollector": {
"type": "labelCollector:topFromFeatureFields",
"labelFilter": {
"type": "labelFilter:acceptLabels",
"labels": {
"type": "labels:fromDocuments",
"documents": {
"type": "documents:byQuery",
"query": {
"type": "query:string",
"query": "pulsar"
},
"limit": "unlimited"
}
}
}
}
}
}
}
}
The result of the above request on the reference Arxiv project is shown below. Compare it to a similar request
using the
rejectLabels
component.
{
"result" : {
"labels" : {
"labels" : [
{
"label" : "quantum",
"weight" : 6804.0
},
{
"label" : "electron",
"weight" : 4625.0
},
{
"label" : "star",
"weight" : 4096.0
},
{
"label" : "solar",
"weight" : 3070.0
},
{
"label" : "plasma",
"weight" : 2651.0
},
{
"label" : "Hall",
"weight" : 2350.0
},
{
"label" : "jet",
"weight" : 2252.0
},
{
"label" : "equation",
"weight" : 2044.0
},
{
"label" : "magnetization",
"weight" : 1889.0
},
{
"label" : "superconducting",
"weight" : 1889.0
}
]
}
}
}labels
A reference source of labels to accept.
labelFilter:autoStopLabels
Rejects any meaningless labels Lingo4G automatically identified during indexing.
{
"type": "labelFilter:autoStopLabels",
"minCoverage": 0.4,
"removalStrength": 0.35
}minCoverage
Reject labels that appear in the
stop labels list and have the coverage lower
than minCoverage.
removalStrength
Reject labels that appear in the
stop labels list and have the score lower
than removalStrength.
labelFilter:characterCount
Accepts or rejects labels based on the number of characters they have.
{
"type": "labelFilter:characterCount",
"minCharacters": 4,
"minCharactersAveragePerToken": 2.9
}minCharacters
Rejects labels that have fewer than minCharacters Java characters (Unicode surrogate pairs count as
two characters).
minCharactersAveragePerToken
Rejects labels where: (label characters) / (word count) is smaller than
minCharactersAveragePerToken. This option can be used to prune automatically discovered labels with
very short tokens (for example repeated MathML expressions).
labelFilter:complement
Rejects labels that are accepted by another filter (inverts the result of another label filter).
{
"type": "labelFilter:complement",
"labelFilter": null
}labelFilter
The label filter whose results should be negated.
labelFilter:composite
Accepts labels if they are accepted by all or any of the label filters you provide.
{
"type": "labelFilter:composite",
"labelFilters": {},
"operator": "AND"
}The keys of nested composite label filters are used for information purposes only. For example, this request retrieves labels from documents matching the query magnetic field, but limits labels to multi-term phrases avoiding the use of any query terms.
{
"name": "Retrieve document labels from documents matching 'magnetic field' with composite filtering criteria.",
"stages": {
"labels": {
"type": "labels:fromDocuments",
"maxLabels": {
"type": "labelCount:fixed",
"value": 10
},
"documents": {
"type": "documents:byQuery",
"query": {
"type": "query:string",
"query": "\"magnetic field\""
},
"limit": "unlimited"
},
"labelAggregator": {
"type": "labelAggregator:topWeight",
"labelCollector": {
"type": "labelCollector:topFromFeatureFields",
"labelFilter": {
"type": "labelFilter:composite",
"labelFilters": {
"phrases-only": {
"type": "labelFilter:tokenCount",
"minTokens": 2,
"maxTokens": 5
},
"acronym-filters": {
"type": "labelFilter:surface",
"removeCapitalized": true,
"removeUppercase": true,
"removeAcronyms": true
},
"avoid-query-terms": {
"type": "labelFilter:dictionary",
"exclude": [
{
"type": "dictionary:glob",
"entries": [
"* magnetic *",
"* field *"
]
}
]
}
}
}
}
}
}
}
}The result of the above request on the reference Arxiv project is shown below.
{
"result" : {
"labels" : {
"labels" : [
{
"label" : "neutron star",
"weight" : 1259.0
},
{
"label" : "black hole",
"weight" : 1045.0
},
{
"label" : "quantum dot",
"weight" : 934.0
},
{
"label" : "cosmic rays",
"weight" : 839.0
},
{
"label" : "phase transition",
"weight" : 709.0
},
{
"label" : "ground state",
"weight" : 679.0
},
{
"label" : "solar wind",
"weight" : 582.0
},
{
"label" : "phase diagram",
"weight" : 532.0
},
{
"label" : "active region",
"weight" : 489.0
},
{
"label" : "angular momentum",
"weight" : 420.0
}
]
}
}
}labelFilters
A set of other named labelFilter:* components.
operator
Declares the way label filters from filters are combined. The operator property
supports the following values:
OR-
Creates a disjunction composite filter. A label is filtered if it occurs in any nested filters.
AND-
Creates a conjunction composite filter. A label is filtered if it occurs in all nested filters.
labelFilter:dictionary
Rejects labels that appear in any of the referenced dictionaries.
{
"type": "labelFilter:dictionary",
"exclude": []
}exclude
An array of one or more
dictionary:*
components.
labelFilter:hasEmbedding
Accepts only those labels that have a multidimensional label embedding vector available.
{
"type": "labelFilter:hasEmbedding"
}labelFilter:rejectLabels
Rejects labels appearing in the set of labels provided by the referenced
labels:* source.
{
"type": "labelFilter:rejectLabels",
"labels": {
"type": "labels:reference",
"auto": true
}
}The example request below retrieves a list of top labels that appear in documents matching the query magnetic field, removing any labels that also appear in documents that match the query pulsar. In effect, the result of this request is an intersection of label sets between these two document queries.
{
"name": "Retrieve document labels from documents matching 'magnetic field' but only appearing in documents matching 'pulsar'.",
"stages": {
"labels": {
"type": "labels:fromDocuments",
"maxLabels": {
"type": "labelCount:fixed",
"value": 10
},
"documents": {
"type": "documents:byQuery",
"query": {
"type": "query:string",
"query": "\"magnetic field\""
},
"limit": "unlimited"
},
"labelAggregator": {
"type": "labelAggregator:topWeight",
"labelCollector": {
"type": "labelCollector:topFromFeatureFields",
"labelFilter": {
"type": "labelFilter:rejectLabels",
"labels": {
"type": "labels:fromDocuments",
"documents": {
"type": "documents:byQuery",
"query": {
"type": "query:string",
"query": "pulsar"
},
"limit": "unlimited"
}
}
}
}
}
}
}
}
The result of the above request on the reference Arxiv project is shown below. Compare it to a similar request
using the
acceptLabels
component.
{
"result" : {
"labels" : {
"labels" : [
{
"label" : "magnetic",
"weight" : 22570.0
},
{
"label" : "field",
"weight" : 21930.0
},
{
"label" : "magnetic field",
"weight" : 15999.0
},
{
"label" : "model",
"weight" : 5156.0
},
{
"label" : "spin",
"weight" : 5057.0
},
{
"label" : "state",
"weight" : 4698.0
},
{
"label" : "energy",
"weight" : 3598.0
},
{
"label" : "effects",
"weight" : 3571.0
},
{
"label" : "phase",
"weight" : 2832.0
},
{
"label" : "temperature",
"weight" : 2815.0
}
]
}
}
}labels
A reference source of labels to reject.
labelFilter:rejectTokens
Rejects labels that contain words and prases present in the labels you provide.
{
"type": "labelFilter:rejectTokens",
"analyzer": "english",
"featureExtractor": "",
"labels": {
"type": "labels:reference",
"auto": true
},
"rejectContaining": "ANY_TOKEN",
"splitCompounds": false
}
Compared to dictionary-based filtering, this filter makes it easier to
filter out labels containing different surface forms of the same label. For example, when
looking for labels semantically-similar to the
AI label, you may want to exclude results that contain the AI token. Dictionary-based filtering
may only be partially effective here because certain labels, such as Artificial Intelligence (AI) contain
a different surface form ((AI)) of the token. The labelFilter:rejectTokens performs
surface-form-insensitive filtering, so providing in the
labels list the AI label will filter out
labels containing any surface form, such as (AI) or ai.
analyzer
The analyzer to use to tokenize the labels.
featureExtractor
Feature extractor to use to process the labels.
labels
The list of labels whose parts to filter out.
rejectContaining
Configures the filtering mode.
The rejectContaining property supports the following values:
ANY_TOKEN-
Removes labels that contain any token (word) present in any of the input
labels. This mode results in the strongest filtering. ALL_TOKENS-
Removes labels that contain all tokens (words) present in one (or more) of the input
labels, in any order. This mode filters out fewer labels than theANY_TOKENmode. EXACT_LABEL-
Removes labels that contain a subsequence equal to any of the input
labels. This mode filters out the fewest labels.
splitCompounds
If true, Lingo4G splits dash- and slash-based compounds, such as AI-based or
AI/ML, into separate tokens.
With compound splitting enabled, if the input
labels contains the AI-based label, the
ANY_TOKEN mode will reject any
label containing the AI or based word, regardless of their surface form.
labelFilter:surface
Accepts labels based on conditions applying to their exact surface appearance (case-sensitive characters). You can configure this filter to remove all-uppercase, capitalized or acronym-like labels.
{
"type": "labelFilter:surface",
"removeAcronyms": false,
"removeCapitalized": false,
"removeUppercase": false
}removeAcronyms
If code, reject labels that appear to be acronyms (more than one letter, capitalized to
non-capitalized letter count ratio >= 0.5).
removeCapitalized
If code, reject labels that are capitalized (first letter in uppercase, remaining letters in
lowercase).
removeUppercase
If code, reject labels with all-uppercase letters.
labelFilter:switch
Enables or disables the label filter you provide.
{
"type": "labelFilter:switch",
"enabled": true,
"labelFilter": null
}
You can use this filter to dynamically activate or deactivate any label filter based on the value of a boolean
variable passed to the
enabled property. Without the
labelFilter:switch component, the only way to deactivate a filter would be to remove the filter from
the request.
The following request shows how to control any label filter using a variable value. This requires three elements:
-
Defining a boolean variable, called
enableLabelFilteringin our request. -
Wrapping the filter to control with a
labelFilter:switchfilter. -
Referencing the boolean variable in the
enabledproperty of thelabelFilter:switchfilter.
{
"name": "Enabling / disabling a label filter using a variable.",
"variables": {
"enableLabelFiltering": {
"name": "Enable label filtering",
"value": false
}
},
"stages": {
"documents": {
"type": "documents:byQuery",
"query": {
"type": "query:string",
"query": "clustering"
},
"limit": 1000
},
"labels": {
"type": "labels:fromDocuments",
"labelAggregator": {
"type": "labelAggregator:topWeight",
"labelCollector": {
"type": "labelCollector:topFromFeatureFields",
"labelFilter": {
"type": "labelFilter:switch",
"enabled": {
"@var": "enableLabelFiltering"
},
"labelFilter": {
"type": "labelFilter:tokenCount",
"minTokens": 2,
"maxTokens": 5
}
}
}
}
}
}
}
With the labelFilter:switch you can dynamically control label filters without changing the structure
of the request. Additionally, boolean variables get represented as check boxes in the
request variable editor.
enabled
Enables or disables the label filter you provide.
If true, applies the
labelFilter
to all input labels. If false, does not apply any filtering and accepts all input labels.
labelFilter
The label filter to control.
labelFilter:tokenCount
Accepts labels based on the number of tokens (words) in the label.
{
"type": "labelFilter:tokenCount",
"maxTokens": 8,
"minTokens": 3
}maxTokens
Reject labels that have more than maxTokens words.
minTokens
Reject labels that have fewer than minTokens words.
Consumers of labelFilter:*
The following stages and components take labelFilter:* as
input: