Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- microsoft/deberta-v3-base
|
| 7 |
+
---
|
| 8 |
+
# Slop Classifier for Roleplay Characters
|
| 9 |
+
|
| 10 |
+
> This model can detect characters that are created using AI.
|
| 11 |
+
|
| 12 |
+
Part of [CharGen](https://huggingface.co/kubernetes-bad/chargen-v2) project - it is used to detect and filter out low-effort, LLM-made characters intended for role playing.
|
| 13 |
+
|
| 14 |
+
*Slop* refers to over-used phrases that models like GPT3.5 like to use very much and that do not add any value to the text. "Shivers down her spine", "enigma wrapped in mystery", "half-lidded eyes", etc. Classifier is trained on set of synthetic characters generated with GPT3.5 and GPT4, and a substet of CharGen dataset.
|
| 15 |
+
|
| 16 |
+
## Usage
|
| 17 |
+
|
| 18 |
+
```py
|
| 19 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 20 |
+
import torch
|
| 21 |
+
from litserve import LitAPI, LitServer
|
| 22 |
+
|
| 23 |
+
MODEL_NAME = "kubernetes-bad/character-slop-classifier"
|
| 24 |
+
|
| 25 |
+
class CHARLitAPI(LitAPI):
|
| 26 |
+
def setup(self, device):
|
| 27 |
+
self.tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 28 |
+
self.model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
|
| 29 |
+
self.model.to(device)
|
| 30 |
+
self.model.eval()
|
| 31 |
+
|
| 32 |
+
def decode_request(self, request):
|
| 33 |
+
if "text" in request:
|
| 34 |
+
inputs = self.tokenizer(request["text"], return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 35 |
+
elif "texts" in request:
|
| 36 |
+
inputs = self.tokenizer(request["texts"], return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 37 |
+
else:
|
| 38 |
+
raise ValueError("Invalid request format. Expected 'text' or 'texts' field.")
|
| 39 |
+
return inputs
|
| 40 |
+
|
| 41 |
+
def predict(self, inputs):
|
| 42 |
+
with torch.no_grad():
|
| 43 |
+
inputs = {k: v.to(self.model.device) for k, v in inputs.items()}
|
| 44 |
+
outputs = self.model(**inputs)
|
| 45 |
+
return outputs.logits
|
| 46 |
+
|
| 47 |
+
def encode_response(self, logits):
|
| 48 |
+
probabilities = torch.nn.functional.softmax(logits, dim=-1)
|
| 49 |
+
if probabilities.shape[0] == 1:
|
| 50 |
+
response = {
|
| 51 |
+
"positive": probabilities[:, 1].item(),
|
| 52 |
+
"negative": probabilities[:, 0].item()
|
| 53 |
+
}
|
| 54 |
+
else:
|
| 55 |
+
response = [
|
| 56 |
+
{
|
| 57 |
+
"positive": prob[1].item(),
|
| 58 |
+
"negative": prob[0].item()
|
| 59 |
+
}
|
| 60 |
+
for prob in probabilities
|
| 61 |
+
]
|
| 62 |
+
return response
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
if __name__ == "__main__":
|
| 66 |
+
api = CHARLitAPI()
|
| 67 |
+
server = LitServer(api, accelerator='cuda')
|
| 68 |
+
server.run(port=9000)
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
curl --location 'http://localhost:9000/predict' \
|
| 73 |
+
--header 'Content-Type: application/json' \
|
| 74 |
+
--data '{
|
| 75 |
+
"text": "Hermione, the seductive intellectual enchantress, is the secret sin of Hogwarts. Beneath her seemingly innocent scholarly facade lies a tantalizing world of forbidden desires. In the hallowed halls of the wizarding world, she conceals her lewd nature from her peers, maintaining a pristine reputation as the most brilliant witch of her age."
|
| 76 |
+
}'
|
| 77 |
+
```
|
| 78 |
+
Example response:
|
| 79 |
+
```json
|
| 80 |
+
{
|
| 81 |
+
"positive": 0.9975564479827881,
|
| 82 |
+
"negative": 0.0024435613304376602
|
| 83 |
+
}
|
| 84 |
+
```
|