Views
No views yet
google/embeddinggemma-300m for embeddings and a custom classification head.pip install -r requirements.txt1import torch
2from sentence_transformers import SentenceTransformer
3from huggingface_hub import hf_hub_download
4from model import SummaryClassifier
5
6REPO_ID = "Prahaladha/summary-gemma-classifier"
7WEIGHTS_FILE = "summary_classifier_gemma.pth"
8
9print(f"Downloading model from {REPO_ID}...")
10model_path = hf_hub_download(repo_id=REPO_ID, filename=WEIGHTS_FILE)
11
12checkpoint = torch.load(model_path, map_location=torch.device('cpu'))
13
14embedder_name = checkpoint['embedder_name']
15num_classes = checkpoint['num_classes']
16dropout = checkpoint.get('dropout', 0.1)
17
18print(f"Loading model with embedder: {embedder_name}")
19print(f"Number of classes: {num_classes}")
20
21
22embedder = SentenceTransformer(embedder_name)
23
24model = SummaryClassifier(
25 embedder=embedder,
26 num_classes=num_classes,
27 dropout=dropout
28)
29
30model.head.load_state_dict(checkpoint['head_state_dict'])
31model.eval()
32
33device = 'cuda' if torch.cuda.is_available() else 'cpu'
34model.to(device)
35print(f"Model loaded and moved to {device}")
36
37test_summaries = ["A concise and accurate recap.", "This was a long and winding explanation."]
38with torch.no_grad():
39 logits = model(test_summaries)
40 probs = torch.softmax(logits, dim=-1)
41 predicted_class = torch.argmax(probs, dim=-1)
42
43 print("\n--- Inference Test ---")
44 print(f"Input: {test_summaries}")
45 print(f"Probs: {probs.cpu().numpy()}")
46 print(f"Predicted: {predicted_class.cpu().numpy()}")