(self, text)
| 29 | param.requires_grad = False |
| 30 | |
| 31 | def forward(self, text): |
| 32 | batch_encoding = self.tokenizer( |
| 33 | text, |
| 34 | truncation=True, |
| 35 | max_length=self.max_length, |
| 36 | return_length=True, |
| 37 | return_overflowing_tokens=False, |
| 38 | padding="max_length", |
| 39 | return_tensors="pt", |
| 40 | ) |
| 41 | tokens = batch_encoding["input_ids"].to(self.device) |
| 42 | outputs = self.transformer(input_ids=tokens) |
| 43 | |
| 44 | z = outputs.last_hidden_state |
| 45 | return z |
| 46 | |
| 47 | def encode(self, text): |
| 48 | return self(text) |