(
self,
texts: List[str],
motion_tokens: Tensor,
lengths: List[int],
tasks: dict,
)
| 183 | return outputs |
| 184 | |
| 185 | def forward_dec( |
| 186 | self, |
| 187 | texts: List[str], |
| 188 | motion_tokens: Tensor, |
| 189 | lengths: List[int], |
| 190 | tasks: dict, |
| 191 | ): |
| 192 | self.tokenizer.padding_side = "right" |
| 193 | |
| 194 | # Tensor to string |
| 195 | motion_strings = self.motion_token_to_string(motion_tokens, lengths) |
| 196 | |
| 197 | # Supervised or unsupervised |
| 198 | condition = random.choice( |
| 199 | ['text', 'motion', 'supervised', 'supervised', 'supervised']) |
| 200 | |
| 201 | if condition == 'text': |
| 202 | labels = texts |
| 203 | elif condition == 'motion': |
| 204 | labels = motion_strings |
| 205 | else: |
| 206 | inputs, outputs = self.template_fulfill(tasks, lengths, |
| 207 | motion_strings, texts) |
| 208 | labels = [] |
| 209 | for i in range(len(inputs)): |
| 210 | labels.append(inputs[i] + ' \n ' + outputs[i] + |
| 211 | self.tokenizer.eos_token) |
| 212 | |
| 213 | # Tokenize |
| 214 | inputs = self.tokenizer(labels, |
| 215 | padding='max_length', |
| 216 | max_length=self.max_length, |
| 217 | truncation=True, |
| 218 | return_attention_mask=True, |
| 219 | return_tensors="pt") |
| 220 | |
| 221 | labels_input_ids = inputs.input_ids.to(motion_tokens.device) |
| 222 | lables_attention_mask = inputs.attention_mask.to(motion_tokens.device) |
| 223 | |
| 224 | # print(labels_input_ids[0:5]) |
| 225 | |
| 226 | outputs = self.language_model(input_ids=labels_input_ids, |
| 227 | attention_mask=lables_attention_mask, |
| 228 | labels=inputs["input_ids"]) |
| 229 | |
| 230 | return outputs |
| 231 | |
| 232 | def generate_direct(self, |
| 233 | texts: List[str], |
no test coverage detected