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

Method split_chunk

funasr/models/scama/chunk_utilis.py:284–306  ·  view source on GitHub ↗

:param x: (b, t, d) :param x_length: (b) :param ind: int :return:

(self, x, x_len, chunk_outs)

Source from the content-addressed store, hash-verified

282 return self.chunk_outs
283
284 def split_chunk(self, x, x_len, chunk_outs):
285 """
286 :param x: (b, t, d)
287 :param x_length: (b)
288 :param ind: int
289 :return:
290 """
291 x = x[:, : x_len.max(), :]
292 b, t, d = x.size()
293 x_len_mask = (~make_pad_mask(x_len, maxlen=t)).to(x.device)
294 x *= x_len_mask[:, :, None]
295
296 x_add_mask = self.get_x_add_mask(chunk_outs, x.device, dtype=x.dtype)
297 x_len_chunk = self.get_x_len_chunk(chunk_outs, x_len.device, dtype=x_len.dtype)
298 pad = (0, 0, self.pad_left_cur, 0)
299 x = F.pad(x, pad, "constant", 0.0)
300 b, t, d = x.size()
301 x = torch.transpose(x, 1, 0)
302 x = torch.reshape(x, [t, -1])
303 x_chunk = torch.mm(x_add_mask, x)
304 x_chunk = torch.reshape(x_chunk, [-1, b, d]).transpose(1, 0)
305
306 return x_chunk, x_len_chunk
307
308 def remove_chunk(self, x_chunk, x_len_chunk, chunk_outs):
309 """Remove chunk.

Callers 1

forwardMethod · 0.80

Calls 3

get_x_add_maskMethod · 0.95
get_x_len_chunkMethod · 0.95
make_pad_maskFunction · 0.90

Tested by

no test coverage detected