Language Model Action Set
Calculate Probabilities of n-Grams
This example is not available for the CAS programming language.
Calculate Probabilities of n-Grams
This example is not available for the Lua programming language.
Calculate Probabilities of n-Grams
This section contains Python code. For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
The following code shows how you can use the nGramCountToLm action to calculate probabilities of n-grams and generate a language model:
casOut = {"name": "langmodel_table"})
You need to modify values for the table and casOut parameters to fit the in-memory table of n-grams with count data and the output table, respectively, that you want to use.
The input of the nGramCountToLm action is the output of the nGramCount action. An example of a table that contains n-gram data is illustrated in Figure 12.
The output of the nGramCountToLm action contains three sections: probabilities, n-grams, and back-off weights. An example of the output is shown in Figure 13.
Figure 13: Sample Output Table

In this example, the first column contains the probabilities of n-grams. The next three columns contain various n-grams. The last column contains the back-off weights. The output table is the final language model that was trained.
Calculate Probabilities of n-Grams
This example is not available for the R programming language.