Language Model Action Set

Transcribing Speech with a PyTorch Acoustic Model

This example is not available for the CAS programming language.

Transcribing Speech with a PyTorch Acoustic Model

This example is not available for the Lua programming language.

Transcribing Speech with a PyTorch Acoustic Model

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 transcribeSpeech action to convert speech to text by using a PyTorch acoustic model:

s.loadactionset(actionset='langModel')
s.langmodel.transcribespeech(
   acousticmodel  = {'model':{'name':'acoustic_model'}},
   casout         = {'name':'sample_output',
                     'replace':True},
   languagemodel  = {'model':{'name':'language_model'}},
   table          = {'name':'sample_input'}
)

You need to modify the value of the model subparameter in the acousticModel parameter to specify which input acoustic model table to use. The PyTorch acoustic model table must have at least two columns: one named Model and one named Weights. The Model column contains a JSON string that defines the model architecture. Here is an example:

{"model": {"model_name": "model1", "model_version": "1.0", "loss_function": "ctc", "space_label_idx": 27, "blank_label_idx": 28, "device": "cpu", "rnn_network": {"input_dim": 40, "output_dim": 29, "rnn_dim": 1024, "rnn_layers": 4, "feedforward_dim": 1024, "feedforward_layers": 3, "dropout": 0.5, "rnn_type": "bilstm", "activation": "relu" } }, "labels": {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", “", "&", " "} }

This JSON string describes a neural network model called "model1", which contains three feedforward layers and four bidirectional LSTM layers. The Weights column contains a string that is generated by converting the model into TorchScript format and then changing the result into Base64 encoding.

An example of the PyTorch acoustic model table is shown in Figure 18.

Figure 18: Sample PyTorch Acoustic Model Table

Sample PyTorch Acoustic Model Table


Transcribing Speech with a PyTorch Acoustic Model

This example is not available for the R programming language.

Last updated: March 12, 2026