Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions azimuth/modules/dataset_analysis/similarity_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# This source code is licensed under the Apache 2.0 license found in the LICENSE file
# in the root directory of this source tree.
import itertools
import os
from collections import defaultdict
from os.path import join as pjoin
from typing import Dict, List, Optional, Tuple

import numpy as np
Expand Down Expand Up @@ -37,10 +37,17 @@ def __init__(
self.encoder = None
super().__init__(dataset_split_name, config, mod_options)

def get_model_name_or_path(self):
model_name_or_path = self.config.similarity.faiss_encoder
if os.environ.get("TRANSFORMERS_OFFLINE"):
home = os.environ.get("SENTENCE_TRANSFORMERS_HOME")
model_name_or_path = os.path.join(home, f"sentence-transformers_{model_name_or_path}")
return model_name_or_path

def get_model(self):
if self.encoder is None:
with FileLock(pjoin(self.cache_dir, "st.lock")):
self.encoder = SentenceTransformer(self.config.similarity.faiss_encoder)
with FileLock(os.path.join(self.cache_dir, "st.lock")):
self.encoder = SentenceTransformer(self.get_model_name_or_path())
return self.encoder

def compute_on_dataset_split(self) -> List[FAISSResponse]: # type: ignore
Expand Down