示例#1
0
  ThreadArg(AttentionEncDec& attentionEncDec_):
    attentionEncDec(attentionEncDec_), loss(0.0)
  {
    this->grad.lstmSrcGrad = LSTM::Grad(this->attentionEncDec.enc);
    this->grad.lstmTgtGrad = LSTM::Grad(this->attentionEncDec.dec);
    if (!this->attentionEncDec.useBlackOut) {
      this->grad.softmaxGrad = SoftMax::Grad(this->attentionEncDec.softmax);
    }
    else{
      this->grad.blackOutState = BlackOut::State(this->attentionEncDec.blackOut);
    }
    this->grad.Wst = MatD::Zero(this->attentionEncDec.Wst.rows(), this->attentionEncDec.Wst.cols());
    this->grad.bs = VecD::Zero(this->attentionEncDec.bs.size());
    this->grad.Wcs = MatD::Zero(this->attentionEncDec.Wcs.rows(), this->attentionEncDec.Wcs.cols());
    this->grad.Wgeneral = MatD::Zero(this->attentionEncDec.Wgeneral.rows(), this->attentionEncDec.Wgeneral.cols());

    for (int i = 0; i< 100; ++i) {
      this->blackOutState.push_back(new BlackOut::State);
    }
    if (this->attentionEncDec.inputFeeding) {
      for (int i = 0; i< 100; ++i) {
	this->s_tilde.push_back(VecD());
	this->del_stilde.push_back(VecD());
      }
    }
  };
示例#2
0
  ThreadArg(AttentionTreeEncDec& attentionTreeEncDec_):
    attentionTreeEncDec(attentionTreeEncDec_), loss(0.0)
  {
    this->grad.lstmSrcGrad = LSTM::Grad(this->attentionTreeEncDec.enc);
    this->grad.lstmTgtGrad = LSTM::Grad(this->attentionTreeEncDec.dec);
    this->grad.treeLstmEncGrad = TreeLSTM::Grad(this->attentionTreeEncDec.encTree);
    this->grad.treeLstmInitDecGrad = TreeLSTM::Grad(this->attentionTreeEncDec.initDecTree);
    if (!this->attentionTreeEncDec.useBlackOut) {
      this->grad.softmaxGrad = SoftMax::Grad(this->attentionTreeEncDec.softmax);
    }
    else{
      this->grad.blackOutState = BlackOut::State(this->attentionTreeEncDec.blackOut);
    }
    this->grad.Wst = MatD::Zero(this->attentionTreeEncDec.Wst.rows(), this->attentionTreeEncDec.Wst.cols());
    this->grad.bs = VecD::Zero(this->attentionTreeEncDec.bs.size());
    this->grad.Wct = MatD::Zero(this->attentionTreeEncDec.Wct.rows(), this->attentionTreeEncDec.Wct.cols());
    this->grad.WgeneralTree = MatD::Zero(this->attentionTreeEncDec.WgeneralTree.rows(), this->attentionTreeEncDec.WgeneralTree.cols());
    this->grad.WcellSeq = MatD::Zero(this->attentionTreeEncDec.WcellSeq.rows(), this->attentionTreeEncDec.WcellSeq.cols());
    this->grad.WcellTree = MatD::Zero(this->attentionTreeEncDec.WcellTree.rows(), this->attentionTreeEncDec.WcellTree.cols());
    this->grad.WhSeq = MatD::Zero(this->attentionTreeEncDec.WhSeq.rows(), this->attentionTreeEncDec.WhSeq.cols());
    this->grad.WhTree = MatD::Zero(this->attentionTreeEncDec.WhTree.rows(), this->attentionTreeEncDec.WhTree.cols());

    int max = this->attentionTreeEncDec.maxGeneNum; 

    for (int i = 0; i < max; ++i) {
      this->blackOutState.push_back(new BlackOut::State);
    }
    if (this->attentionTreeEncDec.inputFeeding) {
      for (int i = 0; i < max; ++i) {
	this->s_tilde.push_back(VecD());
	this->del_stilde.push_back(VecD());
	this->contextTreeList.push_back(VecD());
      }
    }
  };