Extending SLMs with grammar classes

Grammar classes define common groups of words or phrases. A grammar class allows an SLM to assign probabilities to a class of phrases such as a date, a time, or any other spoken phrase that you can categorize. Class-based language models are especially useful when you have a limited amount of training data. In that case, certain important words or phrases may be rarely seen, and therefore have poorly estimated statistics.

Class-based SLMs let you leverage the built-in grammars for complex concepts such as time, date, and money amount. Furthermore, class-based SLMs let you dynamically modify the SLM vocabulary. For example, if the City class is a dynamic grammar, your application can dynamically change the entries in the City subgrammar at runtime without retraining or recompiling the SLM.

The need for a class becomes apparent in these training sentences:

I expect delivery on Friday.
I expect delivery on Thursday.
I expect delivery on Tuesday.

Without classes, the sentence would repeat seven times (once per day of week) for each sentence that contains a day of week. For sentences that include the time of day, these training sentences would require 21 repetitions:

I expect delivery on Friday.
I expect delivery on Wednesday afternoon.
I expect delivery on Tuesday, in the morning.

However, conceptually these training sentences look like this:

I expect delivery on DAY.
I expect delivery on DAY afternoon.
I expect delivery on DAY, in the morning.

So you can represent the days of the week as a class called DAY. The class is a <ruleref> to an external SRGS grammar (see The <ruleref> element (grammar classes)). The SLM treats the class as a single word. For example:

I expect delivery on <ruleref uri="#DAY"/> <ruleref="#DAYTIME"/>.

Using classes, you can select multi-word phrases and enhance their probability regardless of the n-gram order of the model. For example, a normal bigram does not provide a satisfactory model for a multi-word date phrase like “January the 14th”. But you can enhance the bigram with a date class, and the result is a model that predicts the increased probability of such phrases in general, because they are modeled with rules in the class SRGS.

For class grammar files, set swirec_normalize_to_probabilities to 1.

To ensure the swirec_normalize_to_probabilities value takes effect in a sub-grammar (that is, a grammar referred to by an SLM), precompile that sub-grammar and use it as a *.gram file. Set the parameter value for swirec_normalize_to_probabilities to 1 within the sub-grammar when you compile it.

This is not necessary for the main grammar. There, the swirec_normalize_to_probabilities parameter takes effect even if the grammar is not precompiled.