/// <summary>
        /// Enable decoding using beam scoring with a KenLM language model.
        /// </summary>
        /// <param name="aAlphabetConfigPath">The path to the configuration file specifying the alphabet used by the network.</param>
        /// <param name="aLMPath">The path to the language model binary file.</param>
        /// <param name="aTriePath">The path to the trie file build from the same vocabulary as the language model binary.</param>
        /// <param name="aLMAlpha">The alpha hyperparameter of the CTC decoder. Language Model weight.</param>
        /// <param name="aLMBeta">The beta hyperparameter of the CTC decoder. Word insertion weight.</param>
        /// <exception cref="ArgumentException">Thrown when the native binary failed to enable decoding with a language model.</exception>
        public unsafe void EnableDecoderWithLM(string aAlphabetConfigPath,
                                               string aLMPath, string aTriePath,
                                               float aLMAlpha, float aLMBeta)
        {
            string exceptionMessage = null;

            if (string.IsNullOrWhiteSpace(aTriePath))
            {
                exceptionMessage = "Path to the trie file cannot be empty.";
            }
            if (!File.Exists(aTriePath))
            {
                exceptionMessage = $"Cannot find the trie file: {aTriePath}";
            }

            if (exceptionMessage != null)
            {
                throw new FileNotFoundException(exceptionMessage);
            }

            var resultCode = NativeImp.DS_EnableDecoderWithLM(_modelStatePP,
                                                              aAlphabetConfigPath,
                                                              aLMPath,
                                                              aTriePath,
                                                              aLMAlpha,
                                                              aLMBeta);

            EvaluateResultCode(resultCode);
        }
예제 #2
0
        /// <summary>
        /// Enable decoding using beam scoring with a KenLM language model.
        /// </summary>
        /// <param name="aAlphabetConfigPath">The path to the configuration file specifying the alphabet used by the network.</param>
        /// <param name="aLMPath">The path to the language model binary file.</param>
        /// <param name="aTriePath">The path to the trie file build from the same vocabulary as the language model binary.</param>
        /// <param name="aLMWeight">The weight to give to the language model results when scoring.</param>
        /// <param name="aValidWordCountWeight">The weight (bonus) to give to beams when adding a new valid word to the decoding.</param>
        /// <returns>Zero on success, non-zero on failure (invalid arguments).</returns>
        public unsafe int EnableDecoderWithLM(string aAlphabetConfigPath,
                                              string aLMPath, string aTriePath,
                                              float aLMWeight, float aValidWordCountWeight)
        {
            string exceptionMessage = null;

            if (string.IsNullOrWhiteSpace(aTriePath))
            {
                exceptionMessage = "Path to the trie file cannot be empty.";
            }
            if (!File.Exists(aTriePath))
            {
                exceptionMessage = $"Cannot find the trie file: {aTriePath}";
            }

            if (exceptionMessage != null)
            {
                throw new FileNotFoundException(exceptionMessage);
            }

            return(NativeImp.DS_EnableDecoderWithLM(_modelStatePP,
                                                    aAlphabetConfigPath,
                                                    aLMPath,
                                                    aTriePath,
                                                    aLMWeight,
                                                    aValidWordCountWeight));
        }