CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
google_embeddinggemma-300m_8.py58 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    embeddings = model.encode(words, truncate_dim=512, normalize_embeddings=True)17    18    for idx, embedding in enumerate(embeddings):19        print(f"Embedding {idx+1}: {embedding.shape}")20    21    print("-"*80)22    check_word_similarities()23    with open('google_embeddinggemma-300m_8.txt', 'w', encoding='utf-8') as f:24        f.write('Everything was good in google_embeddinggemma-300m_8.txt')25except Exception as e:26    import os27    from slack_sdk import WebClient28    client = WebClient(token=os.environ['SLACK_TOKEN'])29    client.chat_postMessage(30        channel='#hub-model-metadata-snippets-sprint',31        text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/google_embeddinggemma-300m_8.txt|google_embeddinggemma-300m_8.txt>',32    )33 34    with open('google_embeddinggemma-300m_8.txt', 'a', encoding='utf-8') as f:35        import traceback36        f.write('''```CODE: 37embeddings = model.encode(words, truncate_dim=512, 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_8.txt',54        repo_id='model-metadata/code_execution_files',55        path_in_repo='google_embeddinggemma-300m_8.txt',56        repo_type='dataset',57    )58