sentence-transformers How to use benjamintli/modernbert-cosqa-hard-negatives with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("benjamintli/modernbert-cosqa-hard-negatives")
sentences = [
"python string to microseconds",
"def seconds_to_hms(seconds):\n \"\"\"\n Converts seconds float to 'hh:mm:ss.ssssss' format.\n \"\"\"\n hours = int(seconds / 3600.0)\n minutes = int((seconds / 60.0) % 60.0)\n secs = float(seconds % 60.0)\n return \"{0:02d}:{1:02d}:{2:02.6f}\".format(hours, minutes, secs)",
"def align_file_position(f, size):\n \"\"\" Align the position in the file to the next block of specified size \"\"\"\n align = (size - 1) - (f.tell() % size)\n f.seek(align, 1)",
"def timestamp_to_microseconds(timestamp):\n \"\"\"Convert a timestamp string into a microseconds value\n :param timestamp\n :return time in microseconds\n \"\"\"\n timestamp_str = datetime.datetime.strptime(timestamp, ISO_DATETIME_REGEX)\n epoch_time_secs = calendar.timegm(timestamp_str.timetuple())\n epoch_time_mus = epoch_time_secs * 1e6 + timestamp_str.microsecond\n return epoch_time_mus"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]