| 13 | """Base class for local embedding models with mean pooling.""" |
| 14 | |
| 15 | def __init__(self, model_name: str): |
| 16 | import torch |
| 17 | from transformers import AutoTokenizer, AutoModel |
| 18 | import torch.nn.functional as F |
| 19 | |
| 20 | self.torch = torch |
| 21 | self.F = F |
| 22 | |
| 23 | logger.info(f"[Embedding] Loading model: {model_name}") |
| 24 | self.tokenizer = AutoTokenizer.from_pretrained(model_name) |
| 25 | self.model = AutoModel.from_pretrained(model_name, device_map="auto") |
| 26 | self.model.eval() |
| 27 | |
| 28 | def _get_embedding(self, outputs, attention_mask): |
| 29 | """Override in subclass for different pooling strategies.""" |