MCPcopy Create free account
hub / github.com/modelscope/FunASR / score

Method score

funasr/models/language_model/rnn/decoders.py:1152–1207  ·  view source on GitHub ↗

Score. Args: yseq: TODO. state: TODO. x: TODO.

(self, yseq, state, x)

Source from the content-addressed store, hash-verified

1150 )
1151
1152 def score(self, yseq, state, x):
1153 # to support mutiple encoder asr mode, in single encoder mode,
1154 # convert torch.Tensor to List of torch.Tensor
1155 """Score.
1156
1157 Args:
1158 yseq: TODO.
1159 state: TODO.
1160 x: TODO.
1161 """
1162 if self.num_encs == 1:
1163 x = [x]
1164
1165 att_idx, z_list, c_list = state["workspace"]
1166 vy = yseq[-1].unsqueeze(0)
1167 ey = self.dropout_emb(self.embed(vy)) # utt list (1) x zdim
1168 if self.num_encs == 1:
1169 att_c, att_w = self.att[att_idx](
1170 x[0].unsqueeze(0),
1171 [x[0].size(0)],
1172 self.dropout_dec[0](state["z_prev"][0]),
1173 state["a_prev"],
1174 )
1175 else:
1176 att_w = [None] * (self.num_encs + 1) # atts + han
1177 att_c_list = [None] * (self.num_encs) # atts
1178 for idx in range(self.num_encs):
1179 att_c_list[idx], att_w[idx] = self.att[idx](
1180 x[idx].unsqueeze(0),
1181 [x[idx].size(0)],
1182 self.dropout_dec[0](state["z_prev"][0]),
1183 state["a_prev"][idx],
1184 )
1185 h_han = torch.stack(att_c_list, dim=1)
1186 att_c, att_w[self.num_encs] = self.att[self.num_encs](
1187 h_han,
1188 [self.num_encs],
1189 self.dropout_dec[0](state["z_prev"][0]),
1190 state["a_prev"][self.num_encs],
1191 )
1192 ey = torch.cat((ey, att_c), dim=1) # utt(1) x (zdim + hdim)
1193 z_list, c_list = self.rnn_forward(ey, z_list, c_list, state["z_prev"], state["c_prev"])
1194 if self.context_residual:
1195 logits = self.output(torch.cat((self.dropout_dec[-1](z_list[-1]), att_c), dim=-1))
1196 else:
1197 logits = self.output(self.dropout_dec[-1](z_list[-1]))
1198 logp = F.log_softmax(logits, dim=1).squeeze(0)
1199 return (
1200 logp,
1201 dict(
1202 c_prev=c_list[:],
1203 z_prev=z_list[:],
1204 a_prev=att_w,
1205 workspace=(att_idx, z_list, c_list),
1206 ),
1207 )
1208
1209

Callers

nothing calls this directly

Calls 3

rnn_forwardMethod · 0.95
outputMethod · 0.45
log_softmaxMethod · 0.45

Tested by

no test coverage detected