Text Classification
Transformers
Safetensors
llama
trl
reward-trainer
reward-model
creative-writing
text-embeddings-inference
Instructions to use SAA-Lab/Llama8B-CreativeWritingVerifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SAA-Lab/Llama8B-CreativeWritingVerifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="SAA-Lab/Llama8B-CreativeWritingVerifier")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("SAA-Lab/Llama8B-CreativeWritingVerifier") model = AutoModelForSequenceClassification.from_pretrained("SAA-Lab/Llama8B-CreativeWritingVerifier") - Notebooks
- Google Colab
- Kaggle
Document direct story scoring usage
Browse files
README.md
CHANGED
|
@@ -12,20 +12,12 @@ license: llama3.1
|
|
| 12 |
|
| 13 |
# Llama 8B Creative Writing Verifier
|
| 14 |
|
| 15 |
-
This model is a `LlamaForSequenceClassification` reward model for scoring creative-writing
|
| 16 |
|
| 17 |
|
| 18 |
## Usage
|
| 19 |
|
| 20 |
-
This is a reward model, not a text-generation model. Load it with `AutoModelForSequenceClassification` and score
|
| 21 |
-
|
| 22 |
-
```text
|
| 23 |
-
{prompt}
|
| 24 |
-
|
| 25 |
-
{story}
|
| 26 |
-
```
|
| 27 |
-
|
| 28 |
-
Do not apply a chat template for scoring. Higher scalar scores indicate the model's preferred story.
|
| 29 |
|
| 30 |
```python
|
| 31 |
import torch
|
|
@@ -44,10 +36,9 @@ if tokenizer.pad_token is None:
|
|
| 44 |
if model.config.pad_token_id is None:
|
| 45 |
model.config.pad_token_id = tokenizer.pad_token_id
|
| 46 |
|
| 47 |
-
def reward(
|
| 48 |
-
text = f"{prompt.strip()}\n\n{story.strip()}"
|
| 49 |
inputs = tokenizer(
|
| 50 |
-
|
| 51 |
return_tensors="pt",
|
| 52 |
truncation=True,
|
| 53 |
max_length=4096,
|
|
@@ -55,8 +46,8 @@ def reward(prompt: str, story: str) -> float:
|
|
| 55 |
with torch.inference_mode():
|
| 56 |
return model(**inputs).logits.squeeze(-1).float().item()
|
| 57 |
|
| 58 |
-
chosen_score = reward(
|
| 59 |
-
rejected_score = reward(
|
| 60 |
print(chosen_score > rejected_score)
|
| 61 |
```
|
| 62 |
|
|
|
|
| 12 |
|
| 13 |
# Llama 8B Creative Writing Verifier
|
| 14 |
|
| 15 |
+
This model is a `LlamaForSequenceClassification` reward model for scoring creative-writing stories. It should be used as a scalar verifier/reward model, not as a text-generation model.
|
| 16 |
|
| 17 |
|
| 18 |
## Usage
|
| 19 |
|
| 20 |
+
This is a reward model, not a text-generation model. Load it with `AutoModelForSequenceClassification` and score the story directly as raw text. Do not apply a chat template or wrap the story in a prompt.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
```python
|
| 23 |
import torch
|
|
|
|
| 36 |
if model.config.pad_token_id is None:
|
| 37 |
model.config.pad_token_id = tokenizer.pad_token_id
|
| 38 |
|
| 39 |
+
def reward(story: str) -> float:
|
|
|
|
| 40 |
inputs = tokenizer(
|
| 41 |
+
story.strip(),
|
| 42 |
return_tensors="pt",
|
| 43 |
truncation=True,
|
| 44 |
max_length=4096,
|
|
|
|
| 46 |
with torch.inference_mode():
|
| 47 |
return model(**inputs).logits.squeeze(-1).float().item()
|
| 48 |
|
| 49 |
+
chosen_score = reward(chosen_story)
|
| 50 |
+
rejected_score = reward(rejected_story)
|
| 51 |
print(chosen_score > rejected_score)
|
| 52 |
```
|
| 53 |
|