CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
google_embeddinggemma-300m_4.py84 linesDownload Raw Back to root
1# /// script2# requires-python = ">=3.12"3# dependencies = [4#     "torch",5#     "torchvision",6#     "transformers",7#     "diffusers",8#     "sentence-transformers",9#     "accelerate",10#     "peft",11#     "slack-sdk",12# ]13# ///14 15try:16    # The sentences to encode17    sentence_high = [18        "The chef prepared a delicious meal for the guests.",19        "A tasty dinner was cooked by the chef for the visitors."20    ]21    sentence_medium = [22        "She is an expert in machine learning.",23        "He has a deep interest in artificial intelligence."24    ]25    sentence_low = [26        "The weather in Tokyo is sunny today.",27        "I need to buy groceries for the week."28    ]29    30    for sentence in [sentence_high, sentence_medium, sentence_low]:31        print("๐Ÿ™‹โ€โ™‚๏ธ")32        print(sentence)33        embeddings = model.encode(sentence)34        similarities = model.similarity(embeddings[0], embeddings[1])35        print("`-> ๐Ÿค– score: ", similarities.numpy()[0][0])36    with open('google_embeddinggemma-300m_4.txt', 'w', encoding='utf-8') as f:37        f.write('Everything was good in google_embeddinggemma-300m_4.txt')38except Exception as e:39    import os40    from slack_sdk import WebClient41    client = WebClient(token=os.environ['SLACK_TOKEN'])42    client.chat_postMessage(43        channel='#hub-model-metadata-snippets-sprint',44        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_embeddinggemma-300m_4.txt|google_embeddinggemma-300m_4.txt>',45    )46 47    with open('google_embeddinggemma-300m_4.txt', 'a', encoding='utf-8') as f:48        import traceback49        f.write('''```CODE: 50# The sentences to encode51sentence_high = [52    "The chef prepared a delicious meal for the guests.",53    "A tasty dinner was cooked by the chef for the visitors."54]55sentence_medium = [56    "She is an expert in machine learning.",57    "He has a deep interest in artificial intelligence."58]59sentence_low = [60    "The weather in Tokyo is sunny today.",61    "I need to buy groceries for the week."62]63 64for sentence in [sentence_high, sentence_medium, sentence_low]:65    print("๐Ÿ™‹โ€โ™‚๏ธ")66    print(sentence)67    embeddings = model.encode(sentence)68    similarities = model.similarity(embeddings[0], embeddings[1])69    print("`-> ๐Ÿค– score: ", similarities.numpy()[0][0])70```71 72ERROR: 73''')74        traceback.print_exc(file=f)75    76finally:77    from huggingface_hub import upload_file78    upload_file(79        path_or_fileobj='google_embeddinggemma-300m_4.txt',80        repo_id='model-metadata/code_execution_files',81        path_in_repo='google_embeddinggemma-300m_4.txt',82        repo_type='dataset',83    )84