Spaces:
Runtime error
Runtime error
| from sentence_transformers import SentenceTransformer | |
| import numpy as np | |
| from typing import List, Union | |
| class EnglishSentenceEncoder: | |
| def __init__(self, model_name: str = "all-MiniLM-L6-v2"): | |
| self.device = "cpu" | |
| self.model = SentenceTransformer(model_name, device=self.device) | |
| def encode(self, sentences: Union[str, List[str]]) -> np.ndarray: | |
| if isinstance(sentences, str): | |
| sentences = [sentences] | |
| return self.model.encode(sentences, convert_to_numpy=True) | |
| def __call__(self, sentences: Union[str, List[str]]) -> np.ndarray: | |
| return self.encode(sentences) |