/* RNN-T greedy decoding and piece-to-text assembly for one head. */ #ifndef GA_DECODER_H #define GA_DECODER_H #include "ga_weights.h" typedef struct ga_head { const char *name; int vocab; /* classes including blank */ int blank; int hidden; /* prediction network width */ int joint; int enc; int max_symbols; const float *embed; const float *lstm_w, *lstm_r, *lstm_b; /* ONNX gate order i, o, f, c */ const float *enc_w, *enc_b, *pred_w, *pred_b, *out_w, *out_b; const char **pieces; int n_pieces; } ga_head; typedef struct ga_head_state { int last; /* last emitted token, blank before the first */ int have_pred; float *h, *c, *h_next, *c_next; float *pred, *gates, *joint, *logits; float *enc; /* [max_frames, joint] */ char *text; size_t text_len, text_cap, text_taken; int *tokens; size_t n_tokens, cap_tokens; } ga_head_state; int ga_head_init(ga_head *h, ga_weights *w, const char *name, int index, int enc_dim); int ga_head_state_init(const ga_head *h, ga_head_state *s, int max_frames); void ga_head_state_reset(const ga_head *h, ga_head_state *s); void ga_head_state_free(ga_head_state *s); /* Decode encoded[frames, enc]; returns 0 or -1 on allocation failure. */ int ga_head_decode(const ga_head *h, ga_head_state *s, const float *encoded, int frames); #endif