CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
google_embeddinggemma-300m_10.py58 linesDownload Raw Back to root
1# /// script2# requires-python = ">=3.12"3# dependencies = [4#     "torch",5#     "torchvision",6#     "transformers",7#     "accelerate",8#     "peft",9#     "slack-sdk",10# ]11# ///12 13try:14    model = SentenceTransformer(model_id, truncate_dim=256, similarity_fn_name="dot").to(device=device)15    embeddings = model.encode(words, prompt_name="STS", normalize_embeddings=True)16    17    for idx, embedding in enumerate(embeddings):18        print(f"Embedding {idx+1}: {embedding.shape}")19    20    print("-"*80)21    check_word_similarities()22    with open('google_embeddinggemma-300m_10.txt', 'w', encoding='utf-8') as f:23        f.write('Everything was good in google_embeddinggemma-300m_10.txt')24except Exception as e:25    import os26    from slack_sdk import WebClient27    client = WebClient(token=os.environ['SLACK_TOKEN'])28    client.chat_postMessage(29        channel='#exp-slack-alerts',30        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_embeddinggemma-300m_10.txt|google_embeddinggemma-300m_10.txt>',31    )32 33    with open('google_embeddinggemma-300m_10.txt', 'a', encoding='utf-8') as f:34        import traceback35        f.write('''```CODE: 36model = SentenceTransformer(model_id, truncate_dim=256, similarity_fn_name="dot").to(device=device)37embeddings = model.encode(words, prompt_name="STS", normalize_embeddings=True)38 39for idx, embedding in enumerate(embeddings):40    print(f"Embedding {idx+1}: {embedding.shape}")41 42print("-"*80)43check_word_similarities()44```45 46ERROR: 47''')48        traceback.print_exc(file=f)49    50finally:51    from huggingface_hub import upload_file52    upload_file(53        path_or_fileobj='google_embeddinggemma-300m_10.txt',54        repo_id='model-metadata/code_execution_files',55        path_in_repo='google_embeddinggemma-300m_10.txt',56        repo_type='dataset',57    )58