k2-fsa / k2

FSA/FST algorithms, differentiable, with PyTorch compatibility.
https://k2-fsa.github.io/k2
Apache License 2.0
1.1k stars 214 forks source link

LG decoding,FSA is not safe for different utt #1235

Closed hmylk closed 1 year ago

hmylk commented 1 year ago

First , i encapsulate a c++ interface ,as following:

class K2_API {
public:
    K2_API() {};
    ~K2_API() {};
    //k2::FsaClassPtr LoadFsaClass(const std::string & filename,torch::Device map_location = torch::kCPU);
    void Init_Steams(int32_t vocab_size, k2::FsaClassPtr decoding_graph, float lm_weight = 0.07,
        int32_t context_size = 2, int beam = 40, int max_contexts = 6, int  max_states = 7000);
    void GetContext(k2::RaggedShapePtr& shape, torch::Tensor& contxt);
    void TerminateAndFlushRnntStreams();
    void AdvanceRnntStreams(torch::Tensor log_probs);
    k2::FsaClassPtr FormatOutput(std::vector<int32_t> num_frames,bool allow_partial = false);
    torch::Tensor GetBestPaths(k2::FsaClassPtr lattice, bool use_max, int32_t num_paths,float nbest_scale);
};

Then i use this interface to implement LG decoding, if the LoadFsaClass is in the class , and be called before very utt's decoding , the wer is better. if LoadFsaClass is a global interface (i think it is must be called for once for saving memory), the wer is worse.

so i want help for this problem ,thank you very much.

pkufool commented 1 year ago

I think FsaClassPtr is a shared_ptr, it should not be any difference whether it is a local or global instance. How do you implement and use these interfaces? could you give us more details ?

hmylk commented 1 year ago

Thank you for your reply !

The implemention codes are borrowed from torch_api.cc.
Before every utt's decoding , i called LoadFsaClass and Init_Steams , then AdvanceRnntStreams is called for every chunk, when wav data is end, call FormatOutput and GetBestPaths to output 1best result.

i can give you the interface code . But how?

pkufool commented 1 year ago

@hmylk you can send the code (text file) here if you could make it publicly, or you can send to me via email wkang.pku@gmail.com

hmylk commented 1 year ago

@pkufool thank you very much, i have send my code to you via gmail .

csukuangfj commented 1 year ago

How do you fix it? What's the problem?