Upload folder using huggingface_hub
Browse files- app.py +3 -2
- model_trainer.py +5 -3
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
import shutil
|
| 4 |
import time
|
|
@@ -306,10 +307,10 @@ class HackerNewsFineTuner:
|
|
| 306 |
gr.Markdown("This project provides a set of tools to fine-tune [EmbeddingGemma](https://huggingface.co/google/embeddinggemma-300m) to understand your personal taste in Hacker News titles and then use it to score and rank new articles based on their \"vibe\". The core idea is to measure the \"vibe\" of a news title by calculating the semantic similarity between its embedding and the embedding of a fixed anchor phrase, **`MY_FAVORITE_NEWS`**.<br>See [README](https://huggingface.co/spaces/google/embeddinggemma-modkit/blob/main/README.md) for more details.")
|
| 307 |
with gr.Tab("🚀 Fine-Tuning & Evaluation"):
|
| 308 |
self._build_training_interface()
|
| 309 |
-
with gr.Tab("💡 News Vibe Check"):
|
| 310 |
-
self._build_vibe_check_interface()
|
| 311 |
with gr.Tab("📰 Hacker News Mood Reader"):
|
| 312 |
self._build_mood_reader_interface()
|
|
|
|
|
|
|
| 313 |
return demo
|
| 314 |
|
| 315 |
def _build_training_interface(self):
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
import os
|
| 4 |
import shutil
|
| 5 |
import time
|
|
|
|
| 307 |
gr.Markdown("This project provides a set of tools to fine-tune [EmbeddingGemma](https://huggingface.co/google/embeddinggemma-300m) to understand your personal taste in Hacker News titles and then use it to score and rank new articles based on their \"vibe\". The core idea is to measure the \"vibe\" of a news title by calculating the semantic similarity between its embedding and the embedding of a fixed anchor phrase, **`MY_FAVORITE_NEWS`**.<br>See [README](https://huggingface.co/spaces/google/embeddinggemma-modkit/blob/main/README.md) for more details.")
|
| 308 |
with gr.Tab("🚀 Fine-Tuning & Evaluation"):
|
| 309 |
self._build_training_interface()
|
|
|
|
|
|
|
| 310 |
with gr.Tab("📰 Hacker News Mood Reader"):
|
| 311 |
self._build_mood_reader_interface()
|
| 312 |
+
with gr.Tab("💡 Similarity Check"):
|
| 313 |
+
self._build_vibe_check_interface()
|
| 314 |
return demo
|
| 315 |
|
| 316 |
def _build_training_interface(self):
|
model_trainer.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from huggingface_hub import login
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
from datasets import Dataset
|
|
@@ -21,8 +22,8 @@ def load_embedding_model(model_name: str) -> SentenceTransformer:
|
|
| 21 |
"""Initializes the Sentence Transformer model."""
|
| 22 |
print(f"Loading Sentence Transformer model: {model_name}")
|
| 23 |
try:
|
| 24 |
-
model = SentenceTransformer(model_name)
|
| 25 |
-
print("Model loaded successfully.")
|
| 26 |
return model
|
| 27 |
except Exception as e:
|
| 28 |
print(f"Error loading Sentence Transformer model {model_name}: {e}")
|
|
@@ -71,6 +72,7 @@ class EvaluationCallback(TrainerCallback):
|
|
| 71 |
print(f"\n{self.search_fn()}\n")
|
| 72 |
|
| 73 |
|
|
|
|
| 74 |
def train_with_dataset(
|
| 75 |
model: SentenceTransformer,
|
| 76 |
dataset: List[List[str]],
|
|
@@ -129,4 +131,4 @@ def train_with_dataset(
|
|
| 129 |
# Save the final fine-tuned model
|
| 130 |
trainer.save_model()
|
| 131 |
|
| 132 |
-
print(f"Model saved locally to: {output_dir}")
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
from huggingface_hub import login
|
| 3 |
from sentence_transformers import SentenceTransformer, util
|
| 4 |
from datasets import Dataset
|
|
|
|
| 22 |
"""Initializes the Sentence Transformer model."""
|
| 23 |
print(f"Loading Sentence Transformer model: {model_name}")
|
| 24 |
try:
|
| 25 |
+
model = SentenceTransformer(model_name, model_kwargs={"device_map": "auto"})
|
| 26 |
+
print(f"Model loaded successfully. {model.device}")
|
| 27 |
return model
|
| 28 |
except Exception as e:
|
| 29 |
print(f"Error loading Sentence Transformer model {model_name}: {e}")
|
|
|
|
| 72 |
print(f"\n{self.search_fn()}\n")
|
| 73 |
|
| 74 |
|
| 75 |
+
@spaces.GPU
|
| 76 |
def train_with_dataset(
|
| 77 |
model: SentenceTransformer,
|
| 78 |
dataset: List[List[str]],
|
|
|
|
| 131 |
# Save the final fine-tuned model
|
| 132 |
trainer.save_model()
|
| 133 |
|
| 134 |
+
print(f"Model saved locally to: {output_dir}")
|