Takes in text and turns it into text embeddings.
(self, text)
| 164 | |
| 165 | @functools.lru_cache() |
| 166 | def embed_text(self, text) -> torch.FloatTensor: |
| 167 | """ |
| 168 | Takes in text and turns it into text embeddings. |
| 169 | """ |
| 170 | text_input = self.tokenizer( |
| 171 | text, |
| 172 | padding="max_length", |
| 173 | max_length=self.tokenizer.model_max_length, |
| 174 | truncation=True, |
| 175 | return_tensors="pt", |
| 176 | ) |
| 177 | with torch.no_grad(): |
| 178 | embed = self.text_encoder(text_input.input_ids.to(self.device))[0] |
| 179 | return embed |
| 180 | |
| 181 | @functools.lru_cache() |
| 182 | def embed_text_weighted(self, text) -> torch.FloatTensor: |