File size: 1,516 Bytes
26f9dad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "torch",
# "torchvision",
# "transformers",
# "accelerate",
# "peft",
# ]
# ///
try:
# The sentences to encode
sentence_high = [
"The chef prepared a delicious meal for the guests.",
"A tasty dinner was cooked by the chef for the visitors."
]
sentence_medium = [
"She is an expert in machine learning.",
"He has a deep interest in artificial intelligence."
]
sentence_low = [
"The weather in Tokyo is sunny today.",
"I need to buy groceries for the week."
]
for sentence in [sentence_high, sentence_medium, sentence_low]:
print("🙋♂️")
print(sentence)
embeddings = model.encode(sentence)
similarities = model.similarity(embeddings[0], embeddings[1])
print("`-> 🤖 score: ", similarities.numpy()[0][0])
with open('google_embeddinggemma-300m_2.txt', 'w', encoding='utf-8') as f:
f.write('Everything was good in google_embeddinggemma-300m_2.txt')
except Exception as e:
with open('google_embeddinggemma-300m_2.txt', 'w', encoding='utf-8') as f:
import traceback
traceback.print_exc(file=f)
finally:
from huggingface_hub import upload_file
upload_file(
path_or_fileobj='google_embeddinggemma-300m_2.txt',
repo_id='model-metadata/code_execution_files',
path_in_repo='google_embeddinggemma-300m_2.txt',
repo_type='dataset',
)
|