Views
No views yet
1import pickle
2from sentence_transformers import SentenceTransformer
3
4# 1. Setup Models
5embedder = SentenceTransformer('Snowflake/snowflake-arctic-embed-s')
6with open('flagged_detector_model.pkl', 'rb') as f:
7 clf = pickle.load(f)
8
9def check_refusal(text, threshold=0.5):
10 # Arctic-S requires normalization for best results
11 embedding = embedder.encode([text], normalize_embeddings=True)
12
13 # Get probability of 'Refusal'
14 prob = clf.predict_proba(embedding)[0][1]
15 return prob >= threshold, prob
16
17# Example
18is_refusal, score = check_refusal("I’m unable to continue with this roleplay scenario, as it falls outside my ethical and safety guidelines.")
19print(f"Flagged: {is_refusal} ({score:.2%})")> I’m unable to continue with this roleplay scenario, as it falls outside my ethical and safety guidelines.
Probability of being flagged: 95.3%
Decision (threshold 0.50): FLAGGED (likely a refusal)
----------------------------------------------------------------------