Resource weights

In each recognition turn, ASRaaS uses a weighted mix of resources: the base language model plus any builtins, DLMs, and wordsets declared in the recognition request. Default weights are provided but you may override them for all resources.

The total weight of all resources is 1.0, made up of these components:

Component Weight
Base LM

By default, the base language model has a weight of 1.0 minus other components in the recognition turn, with a minimum of 0.1 (10%). If other resources exceed 0.9, their weight is reduced to allow the base LM a minimum weight of 0.1.

When RecognitionFlags: allow_zero_base_lm_weight is true, other resources may use the entire weight, with the base LM reduced to zero. In this case, the words in the base LM are still recognized, but with lower probability than words in the DLMs and other resources.

Builtins

The default weight of each declared builtin is 0.25, or MEDIUM. You may set a weight for each builtin with RecognitionResource: weight_enum or weight_value.

Domain LMs

The default weight of each declared DLM is 0.25, or MEDIUM. You may set a weight for each DLM with RecognitionResource: weight_enum or weight_value.

Wordsets

The default weight of all wordsets is 0.1, or LOW. You may set a weight for each wordset with RecognitionResource: weight_enum or weight_value, but the weight applies to all wordsets in the recognition.

If multiple wordsets are declared with different weights, the highest weight applies to the collection of wordsets. For example, if you declare two wordsets, one with a weight of 0.25 and the other with 0.1, these wordsets together have a weight of 0.25 in the recognition.

These are the resources used in recognition:

Resource weight

The image below shows the default weighting for one or more wordsets, two DLMs, and a builtin. It also includes a custom example in which wordsets have a weight of 0.25, one DLM is declared with 0.5 weight, and no builtins.

Weight example

Custom weights

To set a non-default weight, use either weight_enum or weight_value. For example:

# Declare DLM with weight_value
travel_dlm = RecognitionResource(
    external_reference = ResourceReference(
        type = 'DOMAIN_LM',
        uri = '...'
    ),
    weight_value = 0.5
)

# Declare a compiled wordset with weight_enum
places_compiled_ws = RecognitionResource(
    external_reference = ResourceReference(
        type = 'COMPILED_WORDSET',
        uri = '... '
    ),
    weight_enum = MEDIUM # Equivalent to weight_value 0.25
)

DLMs with 100% weight

If you wish to emphasize one or more DLMs at the expense of the base LM, give them a combined weight of 1.0 and enable the recognition flag, allow_zero_base_lm_weight. In this example, the base LM has little effect on recognition:

# Declare DLM with 100% weight
names_places_dlm = RecognitionResource(
    external_reference = ResourceReference(
        type = 'DOMAIN_LM',
        uri = 'urn:nuance-mix:tag:model/names-places/mix.asr?=language=eng-USA'
    ),
    reuse = 'HIGH_REUSE',
    weight_value = 1.0
)

# Set allow_zero_base_lm_weight to let DLM use all weight
RecognitionInitMessage(
    parameters = RecognitionParameters(
        language = 'en-US',
        topic = 'GEN',
        audio_format = AudioFormat(pcm=PCM(sample_rate_hz=wf.getframerate())),
        result_type = 'PARTIAL',
        utterance_detection_mode = 'MULTIPLE',
        recognition_flags = RecognitionFlags(allow_zero_base_lm_weight=True)
    )
)