Views
No views yet
| Text | Score |
|---|---|
| I am sorry, but I cannot answer that.... | 0.8938 |
| I cannot find the file you requested ... | 0.9128 |
| The boiling point of nitrogen is -195... | 0.0024 |
| I will not be able to attend the meet... | 0.9073 |
| I cannot wait to see you!... | 0.9073 |
| This is a strictly confidential docum... | 0.9184 |
| I'm sorry, I forgot to mention the de... | 0.9020 |
| I'm sorry, I cannot perform that calc... | 0.8936 |
| The system cannot allocate more than ... | 0.9146 |
| I apologize, but I am unable to assis... | 0.8926 |
| Division by zero cannot be performed ... | 0.0064 |
1import torch
2import torch.nn as nn
3from huggingface_hub import PyTorchModelHubMixin
4from sentence_transformers import SentenceTransformer
5
6device = "cuda" if torch.cuda.is_available() else "cpu"
7
8class RewardMLP(nn.Module, PyTorchModelHubMixin):
9 def __init__(self, input_dim=1024, hidden_dim=4096, num_layers=8):
10 super().__init__()
11 self.config = {
12 "input_dim": input_dim,
13 "hidden_dim": hidden_dim,
14 "num_layers": num_layers
15 }
16 self.layers = nn.ModuleList()
17 self.layers.append(nn.Linear(input_dim, hidden_dim))
18 for _ in range(num_layers - 1):
19 self.layers.append(nn.Linear(hidden_dim, hidden_dim))
20
21 self.activation = nn.GELU()
22 self.norm = nn.LayerNorm(hidden_dim)
23 self.dropout = nn.Dropout(0.4)
24 self.head = nn.Linear(hidden_dim, 1)
25 self.sigmoid = nn.Sigmoid()
26
27 def forward(self, x):
28 for layer in self.layers:
29 x = self.activation(self.norm(layer(x)))
30 x = self.dropout(x)
31 return self.sigmoid(self.head(x))
32
33encoder = SentenceTransformer('BAAI/bge-large-en-v1.5').to(device)
34model = RewardMLP.from_pretrained("alplusplus/vibecheck-v1-121M").to(device)
35model.eval()
36
37text = "The speed of light is a universal constant."
38with torch.no_grad():
39 emb = encoder.encode(f"query: {text}", convert_to_tensor=True).to(device)
40 score = model(emb.unsqueeze(0)).item()
41
42print(f"Refusal Probability: {score:.4f}")