CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
google_embeddinggemma-300m_9.py60 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    model = SentenceTransformer(model_id, truncate_dim=256, similarity_fn_name="dot").to(device=device)17    embeddings = model.encode(words, prompt_name="STS", normalize_embeddings=True)18    19    for idx, embedding in enumerate(embeddings):20        print(f"Embedding {idx+1}: {embedding.shape}")21    22    print("-"*80)23    check_word_similarities()24    with open('google_embeddinggemma-300m_9.txt', 'w', encoding='utf-8') as f:25        f.write('Everything was good in google_embeddinggemma-300m_9.txt')26except Exception as e:27    import os28    from slack_sdk import WebClient29    client = WebClient(token=os.environ['SLACK_TOKEN'])30    client.chat_postMessage(31        channel='#hub-model-metadata-snippets-sprint',32        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_embeddinggemma-300m_9.txt|google_embeddinggemma-300m_9.txt>',33    )34 35    with open('google_embeddinggemma-300m_9.txt', 'a', encoding='utf-8') as f:36        import traceback37        f.write('''```CODE: 38model = SentenceTransformer(model_id, truncate_dim=256, similarity_fn_name="dot").to(device=device)39embeddings = model.encode(words, prompt_name="STS", normalize_embeddings=True)40 41for idx, embedding in enumerate(embeddings):42    print(f"Embedding {idx+1}: {embedding.shape}")43 44print("-"*80)45check_word_similarities()46```47 48ERROR: 49''')50        traceback.print_exc(file=f)51    52finally:53    from huggingface_hub import upload_file54    upload_file(55        path_or_fileobj='google_embeddinggemma-300m_9.txt',56        repo_id='model-metadata/code_execution_files',57        path_in_repo='google_embeddinggemma-300m_9.txt',58        repo_type='dataset',59    )60