(self, text)
| 291 | param.requires_grad = False |
| 292 | |
| 293 | def forward(self, text): |
| 294 | batch_encoding = self.tokenizer(text, truncation=True, max_length=self.max_length, return_length=True, |
| 295 | return_overflowing_tokens=False, padding="max_length", return_tensors="pt") |
| 296 | tokens = batch_encoding["input_ids"].to(self.device) |
| 297 | |
| 298 | indices = tokens == self.modifier_token_id[-1] |
| 299 | for token_id in self.modifier_token_id: |
| 300 | indices |= tokens == token_id |
| 301 | |
| 302 | indices = (indices*1).unsqueeze(-1) |
| 303 | |
| 304 | input_shape = tokens.size() |
| 305 | tokens = tokens.view(-1, input_shape[-1]) |
| 306 | |
| 307 | hidden_states = self.transformer.text_model.embeddings(input_ids=tokens) |
| 308 | hidden_states = (1-indices)*hidden_states.detach() + indices*hidden_states |
| 309 | |
| 310 | z = self.custom_forward(hidden_states, tokens) |
| 311 | |
| 312 | return z |
| 313 | |
| 314 | def encode(self, text): |
| 315 | return self(text) |
nothing calls this directly
no test coverage detected