Implement context biasing with a Aho Corasick automata (#145)
* Implement context graph * Modify the interface to support context biasing * Support context biasing in modified beam search; add python wrapper * Support context biasing in python api example * Minor fixes * Fix context graph * Minor fixes * Fix tests * Fix style * Fix style * Fix comments * Minor fixes * Add missing header * Replace std::shared_ptr with std::unique_ptr for effciency * Build graph in constructor * Fix comments * Minor fixes * Fix docs
This commit is contained in:
@@ -26,6 +26,7 @@ struct OfflineRecognizerConfig {
|
||||
|
||||
std::string decoding_method = "greedy_search";
|
||||
int32_t max_active_paths = 4;
|
||||
float context_score = 1.5;
|
||||
// only greedy_search is implemented
|
||||
// TODO(fangjun): Implement modified_beam_search
|
||||
|
||||
@@ -34,12 +35,13 @@ struct OfflineRecognizerConfig {
|
||||
const OfflineModelConfig &model_config,
|
||||
const OfflineLMConfig &lm_config,
|
||||
const std::string &decoding_method,
|
||||
int32_t max_active_paths)
|
||||
int32_t max_active_paths, float context_score)
|
||||
: feat_config(feat_config),
|
||||
model_config(model_config),
|
||||
lm_config(lm_config),
|
||||
decoding_method(decoding_method),
|
||||
max_active_paths(max_active_paths) {}
|
||||
max_active_paths(max_active_paths),
|
||||
context_score(context_score) {}
|
||||
|
||||
void Register(ParseOptions *po);
|
||||
bool Validate() const;
|
||||
@@ -58,6 +60,10 @@ class OfflineRecognizer {
|
||||
/// Create a stream for decoding.
|
||||
std::unique_ptr<OfflineStream> CreateStream() const;
|
||||
|
||||
/// Create a stream for decoding.
|
||||
std::unique_ptr<OfflineStream> CreateStream(
|
||||
const std::vector<std::vector<int32_t>> &context_list) const;
|
||||
|
||||
/** Decode a single stream
|
||||
*
|
||||
* @param s The stream to decode.
|
||||
|
||||
Reference in New Issue
Block a user