Run inference on input data. Args: data_in: Input data (audio samples, file paths, or text). data_lengths: Lengths of each input sample in the batch. key: Sample identifiers. tokenizer: Tokenizer instance for text e
(
self,
data_in,
data_lengths=None,
key: list = None,
tokenizer=None,
frontend=None,
**kwargs,
)
| 288 | return loss, stats, weight |
| 289 | |
| 290 | def inference( |
| 291 | self, |
| 292 | data_in, |
| 293 | data_lengths=None, |
| 294 | key: list = None, |
| 295 | tokenizer=None, |
| 296 | frontend=None, |
| 297 | **kwargs, |
| 298 | ): |
| 299 | """Run inference on input data. |
| 300 | |
| 301 | Args: |
| 302 | data_in: Input data (audio samples, file paths, or text). |
| 303 | data_lengths: Lengths of each input sample in the batch. |
| 304 | key: Sample identifiers. |
| 305 | tokenizer: Tokenizer instance for text encoding/decoding. |
| 306 | frontend: Audio frontend for feature extraction. |
| 307 | **kwargs: Additional keyword arguments. |
| 308 | """ |
| 309 | assert len(data_in) == 1 |
| 310 | if not data_in[0] or (isinstance(data_in[0], str) and not data_in[0].strip()): |
| 311 | meta_data = {"batch_data_time": -1} |
| 312 | return [{"key": key[0] if key else "", "text": "", "punc_array": None}], meta_data |
| 313 | text = load_audio_text_image_video(data_in, data_type=kwargs.get("kwargs", "text"))[0] |
| 314 | vad_indexes = kwargs.get("vad_indexes", None) |
| 315 | # text = data_in[0] |
| 316 | # text_lengths = data_lengths[0] if data_lengths is not None else None |
| 317 | split_size = kwargs.get("split_size", 20) |
| 318 | |
| 319 | tokens = split_words(text, jieba_usr_dict=self.jieba_usr_dict) |
| 320 | tokens_int = tokenizer.encode(tokens) |
| 321 | |
| 322 | mini_sentences = split_to_mini_sentence(tokens, split_size) |
| 323 | mini_sentences_id = split_to_mini_sentence(tokens_int, split_size) |
| 324 | assert len(mini_sentences) == len(mini_sentences_id) |
| 325 | cache_sent = [] |
| 326 | cache_sent_id = torch.from_numpy(np.array([], dtype="int32")) |
| 327 | new_mini_sentence = "" |
| 328 | new_mini_sentence_punc = [] |
| 329 | cache_pop_trigger_limit = 200 |
| 330 | results = [] |
| 331 | meta_data = {} |
| 332 | punc_array = None |
| 333 | for mini_sentence_i in range(len(mini_sentences)): |
| 334 | mini_sentence = mini_sentences[mini_sentence_i] |
| 335 | mini_sentence_id = mini_sentences_id[mini_sentence_i] |
| 336 | mini_sentence = cache_sent + mini_sentence |
| 337 | mini_sentence_id = np.concatenate((cache_sent_id, mini_sentence_id), axis=0) |
| 338 | data = { |
| 339 | "text": torch.unsqueeze(torch.from_numpy(mini_sentence_id), 0), |
| 340 | "text_lengths": torch.from_numpy(np.array([len(mini_sentence_id)], dtype="int32")), |
| 341 | } |
| 342 | data = to_device(data, kwargs["device"]) |
| 343 | # y, _ = self.wrapped_model(**data) |
| 344 | y, _ = self.punc_forward(**data) |
| 345 | _, indices = y.view(-1, y.shape[-1]).topk(1, dim=1) |
| 346 | punctuations = torch.squeeze(indices, dim=1) |
| 347 | assert punctuations.size()[0] == len(mini_sentence) |
nothing calls this directly
no test coverage detected