| 16 | use_space_char) |
| 17 | |
| 18 | def __call__(self, data): |
| 19 | text = data['label'] |
| 20 | text = self.encode(text) |
| 21 | if text is None: |
| 22 | return None |
| 23 | if len(text) > self.max_text_len: |
| 24 | return None |
| 25 | data['length'] = np.array(len(text)) |
| 26 | text_char = text + [104] * (self.max_text_len + 1 - len(text)) |
| 27 | text.insert(0, 2) |
| 28 | text.append(3) |
| 29 | text = text + [0] * (self.max_text_len + 2 - len(text)) |
| 30 | data['label'] = np.array(text) |
| 31 | data['label_char'] = np.array(text_char) |
| 32 | return data |
| 33 | |
| 34 | def add_special_char(self, dict_character): |
| 35 | dict_character = ['blank', '<unk>', '<s>', '</s>'] + dict_character |