Problem in fitting multinomial HMM

tranformed parameters{ 
 { // Forward algorithm log p(z_t = j | x_{1:n})
    real accumulator[K];
    
    for (j in 1:K){
      logalpha[1,j] = log(pi1[j]) + multinomial_lpmf(y[1,] | B[j]);}

    for (n in 2:N) {
      for (j in 1:K) { // j = current (n)
        for (i in 1:K) { // i = previous (n-1)
                         // belief state      + transition prob + local evidence at n
          accumulator[i] = logalpha[n-1, i] + log(A[i, j]) + multinomial_lpmf(y[n,] | B[i]);
        }
        logalpha[n, j] = log_sum_exp(accumulator);
      }
    }
  } }

model {
  
  for(k in 1:K){
      B[k] ~ dirichlet(rep_vector(1, M));
  }
  
  target += log_sum_exp(logalpha[N]); // Note: update based only on last logalpha
}

I used this code to fit a HMM with multinomial emission. When I rise M, the size of the multinomial distribution to 50 and higher, the program returns very pool fit, and for a 2 state model, emission for one of the state is like 0.014,0.014,0.014… Could someone give me some help, please? Thank you very much