Пример #1
0
void SENNA_nn_temporal_convolution(float *output, int output_frame_size,
                                   float *weights, float *biases, float *input,
                                   int input_frame_size, int n_frames,
                                   int k_w) {
#ifdef USE_BLAS
  if (k_w == 1) {
    if (biases) {
      int t;
      for (t = 0; t < n_frames; t++)
        cblas_scopy(output_frame_size, biases, 1,
                    output + t * output_frame_size, 1);
    }
    cblas_sgemm(CblasColMajor, CblasTrans, CblasNoTrans, output_frame_size,
                n_frames, input_frame_size, 1.0, weights, input_frame_size,
                input, input_frame_size, (biases ? 1.0 : 0.0), output,
                output_frame_size);
  } else
#endif
  {
    int t;

    for (t = 0; t < n_frames - k_w + 1; t++)
      SENNA_nn_linear(output + t * output_frame_size, output_frame_size,
                      weights, biases, input + t * input_frame_size,
                      input_frame_size * k_w);
  }
}
Пример #2
0
int* SENNA_POS_forward(SENNA_POS *pos, const int *sentence_words, const int *sentence_caps, const int *sentence_suff, int sentence_size)
{
  int idx;
  //@AureDi sentence_size+pos->window_size-1: broad convolution			(pos->ll_word_size+pos->ll_caps_size+pos->ll_suff_size): feature length
  pos->input_state = SENNA_realloc(pos->input_state, sizeof(float), (sentence_size+pos->window_size-1)*(pos->ll_word_size+pos->ll_caps_size+pos->ll_suff_size));
  pos->output_state = SENNA_realloc(pos->output_state, sizeof(float), sentence_size*pos->output_state_size);
  
  SENNA_nn_lookup(pos->input_state,                                     pos->ll_word_size+pos->ll_caps_size+pos->ll_suff_size, pos->ll_word_weight, pos->ll_word_size, pos->ll_word_max_idx, sentence_words, sentence_size, pos->ll_word_padding_idx, (pos->window_size-1)/2);
  SENNA_nn_lookup(pos->input_state+pos->ll_word_size,                   pos->ll_word_size+pos->ll_caps_size+pos->ll_suff_size, pos->ll_caps_weight, pos->ll_caps_size, pos->ll_caps_max_idx, sentence_caps,  sentence_size, pos->ll_caps_padding_idx, (pos->window_size-1)/2);
  SENNA_nn_lookup(pos->input_state+pos->ll_word_size+pos->ll_caps_size, pos->ll_word_size+pos->ll_caps_size+pos->ll_suff_size, pos->ll_suff_weight, pos->ll_suff_size, pos->ll_suff_max_idx, sentence_suff,  sentence_size, pos->ll_suff_padding_idx, (pos->window_size-1)/2);

  for(idx = 0; idx < sentence_size; idx++)
  {
    SENNA_nn_linear(pos->hidden_state, pos->hidden_state_size, pos->l1_weight, pos->l1_bias, pos->input_state+idx*(pos->ll_word_size+pos->ll_caps_size+pos->ll_suff_size), pos->window_size*(pos->ll_word_size+pos->ll_caps_size+pos->ll_suff_size));
    SENNA_nn_hardtanh(pos->hidden_state, pos->hidden_state, pos->hidden_state_size);
    SENNA_nn_linear(pos->output_state+idx*pos->output_state_size, pos->output_state_size, pos->l2_weight, pos->l2_bias, pos->hidden_state, pos->hidden_state_size);
  }

  pos->labels = SENNA_realloc(pos->labels, sizeof(int), sentence_size);
  SENNA_nn_viterbi(pos->labels, pos->viterbi_score_init, pos->viterbi_score_trans, pos->output_state, pos->output_state_size, sentence_size);

  return pos->labels;
}