CoolFace
Datasetpublic

model-metadata/code_python_files

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes13kdownloads
google_embeddinggemma-300m_6.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    labels = ["Billing Issue", "Technical Support", "Sales Inquiry"]17    18    sentence = [19        "Excuse me, the app freezes on the login screen. It won't work even when I try to reset my password.",20        "I would like to inquire about your enterprise plan pricing and features for a team of 50 people.",21    ]22    23    # Calculate embeddings by calling model.encode()24    label_embeddings = model.encode(labels, prompt_name="Classification")25    embeddings = model.encode(sentence, prompt_name="Classification")26    27    # Calculate the embedding similarities28    similarities = model.similarity(embeddings, label_embeddings)29    print(similarities)30    31    idx = similarities.argmax(1)32    print(idx)33    34    for example in sentence:35        print("๐Ÿ™‹โ€โ™‚๏ธ", example, "-> ๐Ÿค–", labels[idx[sentence.index(example)]])36    with open('google_embeddinggemma-300m_6.txt', 'w', encoding='utf-8') as f:37        f.write('Everything was good in google_embeddinggemma-300m_6.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_6.txt|google_embeddinggemma-300m_6.txt>',45    )46 47    with open('google_embeddinggemma-300m_6.txt', 'a', encoding='utf-8') as f:48        import traceback49        f.write('''```CODE: 50labels = ["Billing Issue", "Technical Support", "Sales Inquiry"]51 52sentence = [53    "Excuse me, the app freezes on the login screen. It won't work even when I try to reset my password.",54    "I would like to inquire about your enterprise plan pricing and features for a team of 50 people.",55]56 57# Calculate embeddings by calling model.encode()58label_embeddings = model.encode(labels, prompt_name="Classification")59embeddings = model.encode(sentence, prompt_name="Classification")60 61# Calculate the embedding similarities62similarities = model.similarity(embeddings, label_embeddings)63print(similarities)64 65idx = similarities.argmax(1)66print(idx)67 68for example in sentence:69    print("๐Ÿ™‹โ€โ™‚๏ธ", example, "-> ๐Ÿค–", labels[idx[sentence.index(example)]])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_6.txt',80        repo_id='model-metadata/code_execution_files',81        path_in_repo='google_embeddinggemma-300m_6.txt',82        repo_type='dataset',83    )84