Browse
 
Tools
Rss Categories

Using Precompiled Grammars

Reference Number: AA-01618 Views: 14606 0 Rating/ Voters

With the introduction of LumenVox Version 11.0, a new mechanism of producing precompiled grammars was introduced. This allows users to produce binary, compiled versions of grammars. These precompiled grammars can be saved to the file system, and can be loaded and used without requiring a subsequent compilation phase, which for large and/or complex grammars can be time consuming. Please see the Compiling Grammars article to see which tools can be used to generate precompiling grammars.


Naming Precompiled Grammars

Although there is no hard restriction on the naming convention used for precompiled grammars, we recommend using the  .lvgram  file suffix, so that humans can more easily identify the difference between these binary files and other grammar files.


When to use Precompiled Grammars

The use of precompiled grammars is purely optional, and is never needed to obtain functionality. The use of precompiled grammars in a number of specific scenarios, however, can be beneficial, depending on your needs.

Precompiling grammars outside of the production ASR server environment can be very useful to offload the CPU and memory intensive grammar compilation task to other machines. After these precompiled grammars have been generated (using the GrammarLoader tool, or the Speech Tuner tool), they can be moved to an HTTP server that hosts grammar files so that they can be fetched by URI reference as needed, or the precompiled grammar files can be physically copied to the production ASR machines as needed.

An additional benefit of using precompiled grammars may be to allow you to distribute grammars in compiled format to end-users in a way that their contents is obfuscated. End-users will be able to use such precompiled grammars, but they would not be able to see the raw grammar that was used to generate it.  This specific feature has been requested a number of times by several customers, so that they can distribute their specialized grammars in a way that cannot be easily reverse-engineered.

Large and/or complex grammars will benefit particularly well from using precompiled grammars on a non-production machine, since these can take significant amounts of time as well as CPU and memory resources to compile. Using a non-production machine does not tie up the main production machines for this task.


When NOT to use Precompiled Grammars

The regular LumenVox grammar compiler within the ASR has been highly tuned to run optimally for most customers, so if you are using a large number of small/simple grammars that change frequently, then the benefits of precompiling grammar are reduced, however there is also no negative impact of creating and using precompiled grammars over raw grammars (although you have to track two files instead of one, so may add to your logistical overhead).


Loading Precompiled Grammars

When needed in production, these grammars will be referenced on an HTTP server that hosts grammar files, and can be fetched via URI, or the precompiled grammars can be simply copied to the ASR production machines as needed, then loaded from a local file system reference, and as of LumenVox version 11.2.100, users may also specify resources located on secure HTTPS servers. Which of these options to use will depend on your implementation, however there are minimal difference between these approaches.

Whenever the ASR encounters a request to load a grammar (either from an MRCP request or from a direct API request), it realizes that the grammar does not need to be further compiled, so will be available for use instantly. This auto-detection of precompiled grammars is done automatically, so you do not need to change your method(s) of loading and activating grammars in order to begin using precompiled grammars.

Note that while these precompiled grammars can be referenced and used directly by recognizers, they should should not be referenced from within other SRGS grammars.

Important: For very large grammars, we recommend serving the compiled grammar from an HTTP server 

When the compiled grammar needs to be fetched, the use of a HTTP server increases the speed of loading, as the built-in caching functionality of HTTP calls can be used.  When loaded directly from disk, the file must be loaded each time to compare hashes.  For small compiled grammars, this is trivial, but for compiled grammars greater than 1MB or so, this can take a noticeable time.
Any web server, supporting HTTP or HTTPS, that also supports cache control is recommended.