Text Classification
Transformers
Safetensors
English
deberta-v2
character-analysis
plot-arc
narrative-analysis
deberta
Instructions to use Mitchins/deberta-v3-s-plot-arc-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Mitchins/deberta-v3-s-plot-arc-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Mitchins/deberta-v3-s-plot-arc-classifier")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Mitchins/deberta-v3-s-plot-arc-classifier") model = AutoModelForSequenceClassification.from_pretrained("Mitchins/deberta-v3-s-plot-arc-classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- .DS_Store +0 -0
- .gitattributes +1 -0
- README.md +188 -0
- added_tokens.json +3 -0
- config.json +50 -0
- evaluation_results.json +78 -0
- images/confusion_matrix.png +3 -0
- model.safetensors +3 -0
- requirements.txt +6 -0
- special_tokens_map.json +15 -0
- spm.model +3 -0
- test_model.py +71 -0
- tests/synthetic_tests.json +92 -0
- tokenizer_config.json +59 -0
- training_args.bin +3 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
images/confusion_matrix.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
# Model Card Metadata (YAML Front Matter)
|
| 3 |
+
license: mit
|
| 4 |
+
base_model: microsoft/deberta-v3-small
|
| 5 |
+
tags:
|
| 6 |
+
- text-classification
|
| 7 |
+
- character-analysis
|
| 8 |
+
- plot-arc
|
| 9 |
+
- narrative-analysis
|
| 10 |
+
- deberta
|
| 11 |
+
- transformers
|
| 12 |
+
language: en
|
| 13 |
+
datasets:
|
| 14 |
+
- custom/plot-arc-balanced-101k
|
| 15 |
+
metrics:
|
| 16 |
+
- accuracy
|
| 17 |
+
- f1
|
| 18 |
+
- precision
|
| 19 |
+
- recall
|
| 20 |
+
model_type: sequence-classification
|
| 21 |
+
pipeline_tag: text-classification
|
| 22 |
+
widget:
|
| 23 |
+
- text: "Sir Galahad embarks on a perilous quest to retrieve the stolen Crown of Ages."
|
| 24 |
+
example_title: "External Arc Example"
|
| 25 |
+
- text: "Maria struggles with crippling self-doubt after her mother's harsh words."
|
| 26 |
+
example_title: "Internal Arc Example"
|
| 27 |
+
- text: "Captain Torres must infiltrate enemy lines while battling his own cowardice."
|
| 28 |
+
example_title: "Both Arc Example"
|
| 29 |
+
- text: "A baker who makes bread every morning in his village shop."
|
| 30 |
+
example_title: "No Arc Example"
|
| 31 |
+
library_name: transformers
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
# Plot Arc Classifier - DeBERTa Small
|
| 35 |
+
|
| 36 |
+
A fine-tuned DeBERTa-v3-small model for classifying character plot arc types in narrative text.
|
| 37 |
+
|
| 38 |
+
## Model Details
|
| 39 |
+
|
| 40 |
+
### Model Description
|
| 41 |
+
|
| 42 |
+
This model classifies character descriptions into four plot arc categories:
|
| 43 |
+
- **NONE (0)**: No discernible character development or plot arc
|
| 44 |
+
- **INTERNAL (1)**: Character growth driven by internal conflict/psychology
|
| 45 |
+
- **EXTERNAL (2)**: Character arc driven by external events/missions
|
| 46 |
+
- **BOTH (3)**: Character arc with both internal conflict and external drivers
|
| 47 |
+
|
| 48 |
+
**Model Type:** Text Classification (Sequence Classification)
|
| 49 |
+
**Base Model:** microsoft/deberta-v3-small (~60M parameters)
|
| 50 |
+
**Language:** English
|
| 51 |
+
**License:** MIT
|
| 52 |
+
|
| 53 |
+
### Model Architecture
|
| 54 |
+
|
| 55 |
+
- **Base:** DeBERTa-v3-Small (60M parameters)
|
| 56 |
+
- **Task:** 4-class sequence classification
|
| 57 |
+
- **Input:** Character descriptions (max 512 tokens)
|
| 58 |
+
- **Output:** Classification logits + probabilities for 4 classes
|
| 59 |
+
|
| 60 |
+
## Training Data
|
| 61 |
+
|
| 62 |
+
### Dataset Statistics
|
| 63 |
+
- **Total Examples:** 101,348
|
| 64 |
+
- **Training Split:** 91,213 examples (90%)
|
| 65 |
+
- **Validation Split:** 10,135 examples (10%)
|
| 66 |
+
- **Perfect Class Balance:** 25,337 examples per class
|
| 67 |
+
|
| 68 |
+
### Data Sources
|
| 69 |
+
- Systematic scanning of 1.8M+ character descriptions
|
| 70 |
+
- LLM validation using Llama-3.2-3B for quality assurance
|
| 71 |
+
- SHA256-based deduplication to prevent data leakage
|
| 72 |
+
- Carefully curated and balanced dataset across all plot arc types
|
| 73 |
+
|
| 74 |
+
### Class Distribution
|
| 75 |
+
| Class | Count | Percentage |
|
| 76 |
+
|-------|-------|------------|
|
| 77 |
+
| NONE | 25,337 | 25% |
|
| 78 |
+
| INTERNAL | 25,337 | 25% |
|
| 79 |
+
| EXTERNAL | 25,337 | 25% |
|
| 80 |
+
| BOTH | 25,337 | 25% |
|
| 81 |
+
|
| 82 |
+
## Performance
|
| 83 |
+
|
| 84 |
+
### Key Metrics
|
| 85 |
+
- **Accuracy:** 0.7286
|
| 86 |
+
- **F1 (Weighted):** 0.7283
|
| 87 |
+
- **F1 (Macro):** 0.7275
|
| 88 |
+
|
| 89 |
+
### Per-Class Performance
|
| 90 |
+
| Class | Precision | Recall | F1-Score | Support |
|
| 91 |
+
|-------|-----------|--------|----------|---------|
|
| 92 |
+
| NONE | 0.697 | 0.613 | 0.653 | 2,495 |
|
| 93 |
+
| INTERNAL | 0.677 | 0.683 | 0.680 | 2,571 |
|
| 94 |
+
| EXTERNAL | 0.892 | 0.882 | 0.887 | 2,568 |
|
| 95 |
+
| BOTH | 0.652 | 0.732 | 0.690 | 2,501 |
|
| 96 |
+
|
| 97 |
+
### Training Details
|
| 98 |
+
- **Training Time:** 9.7 hours on Apple Silicon MPS
|
| 99 |
+
- **Final Training Loss:** 0.635
|
| 100 |
+
- **Epochs:** 3.86 (early stopping)
|
| 101 |
+
- **Batch Size:** 16 (effective: 32 with gradient accumulation)
|
| 102 |
+
- **Learning Rate:** 2e-5 with warmup
|
| 103 |
+
- **Optimizer:** AdamW with weight decay (0.01)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
## Confusion Matrix
|
| 107 |
+
|
| 108 |
+

|
| 109 |
+
|
| 110 |
+
## Usage
|
| 111 |
+
|
| 112 |
+
### Basic Usage
|
| 113 |
+
|
| 114 |
+
```python
|
| 115 |
+
from transformers import DebertaV2Tokenizer, DebertaV2ForSequenceClassification
|
| 116 |
+
import torch
|
| 117 |
+
|
| 118 |
+
# Load model and tokenizer
|
| 119 |
+
model_name = "plot-arc-classifier-deberta-small"
|
| 120 |
+
tokenizer = DebertaV2Tokenizer.from_pretrained(model_name)
|
| 121 |
+
model = DebertaV2ForSequenceClassification.from_pretrained(model_name)
|
| 122 |
+
|
| 123 |
+
# Example text
|
| 124 |
+
text = "Sir Galahad embarks on a perilous quest to retrieve the stolen Crown of Ages."
|
| 125 |
+
|
| 126 |
+
# Tokenize and predict
|
| 127 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
| 128 |
+
with torch.no_grad():
|
| 129 |
+
outputs = model(**inputs)
|
| 130 |
+
probabilities = torch.softmax(outputs.logits, dim=-1)
|
| 131 |
+
predicted_class = torch.argmax(probabilities, dim=-1)
|
| 132 |
+
|
| 133 |
+
# Class mapping
|
| 134 |
+
class_names = ['NONE', 'INTERNAL', 'EXTERNAL', 'BOTH']
|
| 135 |
+
prediction = class_names[predicted_class.item()]
|
| 136 |
+
confidence = probabilities[0][predicted_class].item()
|
| 137 |
+
|
| 138 |
+
print(f"Predicted class: {prediction} (confidence: {confidence:.3f})")
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
### Pipeline Usage
|
| 142 |
+
|
| 143 |
+
```python
|
| 144 |
+
from transformers import pipeline
|
| 145 |
+
|
| 146 |
+
classifier = pipeline(
|
| 147 |
+
"text-classification",
|
| 148 |
+
model="plot-arc-classifier-deberta-small",
|
| 149 |
+
return_all_scores=True
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
result = classifier("Captain Torres must infiltrate enemy lines while battling his own cowardice.")
|
| 153 |
+
print(result)
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
## Limitations
|
| 157 |
+
|
| 158 |
+
- **Domain:** Optimized for character descriptions in narrative fiction
|
| 159 |
+
- **Length:** Maximum 512 tokens (longer texts are truncated)
|
| 160 |
+
- **Language:** English only
|
| 161 |
+
- **Context:** Works best with character-focused descriptions rather than plot summaries
|
| 162 |
+
- **Ambiguity:** Some edge cases may be inherently ambiguous between INTERNAL/BOTH
|
| 163 |
+
|
| 164 |
+
## Ethical Considerations
|
| 165 |
+
|
| 166 |
+
- **Bias:** Training data may contain genre/cultural biases toward certain character archetypes
|
| 167 |
+
- **Interpretation:** Classifications reflect Western narrative theory; other storytelling traditions may not map perfectly
|
| 168 |
+
- **Automation:** Should complement, not replace, human literary analysis
|
| 169 |
+
|
| 170 |
+
## Citation
|
| 171 |
+
|
| 172 |
+
```bibtex
|
| 173 |
+
@model{plot_arc_classifier_2025,
|
| 174 |
+
title={Plot Arc Classifier - DeBERTa Small},
|
| 175 |
+
author={Claude Code Assistant},
|
| 176 |
+
year={2025},
|
| 177 |
+
url={https://github.com/your-org/plot-arc-classifier},
|
| 178 |
+
note={Fine-tuned DeBERTa-v3-small for character plot arc classification}
|
| 179 |
+
}
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
## Model Card Contact
|
| 183 |
+
|
| 184 |
+
For questions about this model, please open an issue in the repository or contact the maintainers.
|
| 185 |
+
|
| 186 |
+
---
|
| 187 |
+
|
| 188 |
+
*Model trained on 2025-09-02 using transformers library.*
|
added_tokens.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"[MASK]": 128000
|
| 3 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"DebertaV2ForSequenceClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"bos_token_id": 1,
|
| 7 |
+
"dtype": "float32",
|
| 8 |
+
"eos_token_id": 2,
|
| 9 |
+
"hidden_act": "gelu",
|
| 10 |
+
"hidden_dropout_prob": 0.1,
|
| 11 |
+
"hidden_size": 768,
|
| 12 |
+
"id2label": {
|
| 13 |
+
"0": "LABEL_0",
|
| 14 |
+
"1": "LABEL_1",
|
| 15 |
+
"2": "LABEL_2",
|
| 16 |
+
"3": "LABEL_3"
|
| 17 |
+
},
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"intermediate_size": 3072,
|
| 20 |
+
"label2id": {
|
| 21 |
+
"LABEL_0": 0,
|
| 22 |
+
"LABEL_1": 1,
|
| 23 |
+
"LABEL_2": 2,
|
| 24 |
+
"LABEL_3": 3
|
| 25 |
+
},
|
| 26 |
+
"layer_norm_eps": 1e-07,
|
| 27 |
+
"legacy": true,
|
| 28 |
+
"max_position_embeddings": 512,
|
| 29 |
+
"max_relative_positions": -1,
|
| 30 |
+
"model_type": "deberta-v2",
|
| 31 |
+
"norm_rel_ebd": "layer_norm",
|
| 32 |
+
"num_attention_heads": 12,
|
| 33 |
+
"num_hidden_layers": 6,
|
| 34 |
+
"pad_token_id": 0,
|
| 35 |
+
"pooler_dropout": 0,
|
| 36 |
+
"pooler_hidden_act": "gelu",
|
| 37 |
+
"pooler_hidden_size": 768,
|
| 38 |
+
"pos_att_type": [
|
| 39 |
+
"p2c",
|
| 40 |
+
"c2p"
|
| 41 |
+
],
|
| 42 |
+
"position_biased_input": false,
|
| 43 |
+
"position_buckets": 256,
|
| 44 |
+
"problem_type": "single_label_classification",
|
| 45 |
+
"relative_attention": true,
|
| 46 |
+
"share_att_key": true,
|
| 47 |
+
"transformers_version": "4.56.0",
|
| 48 |
+
"type_vocab_size": 0,
|
| 49 |
+
"vocab_size": 128100
|
| 50 |
+
}
|
evaluation_results.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_info": {
|
| 3 |
+
"base_model": "microsoft/deberta-v3-small",
|
| 4 |
+
"model_type": "sequence-classification",
|
| 5 |
+
"num_classes": 4,
|
| 6 |
+
"class_names": [
|
| 7 |
+
"NONE",
|
| 8 |
+
"INTERNAL",
|
| 9 |
+
"EXTERNAL",
|
| 10 |
+
"BOTH"
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
"performance": {
|
| 14 |
+
"accuracy": 0.7285643808584115,
|
| 15 |
+
"f1_weighted": 0.7283043705111875,
|
| 16 |
+
"f1_macro": 0.7275298614210632
|
| 17 |
+
},
|
| 18 |
+
"per_class_metrics": {
|
| 19 |
+
"NONE": {
|
| 20 |
+
"precision": 0.6973564266180492,
|
| 21 |
+
"recall": 0.6132264529058116,
|
| 22 |
+
"f1-score": 0.6525911708253359,
|
| 23 |
+
"support": 2495.0
|
| 24 |
+
},
|
| 25 |
+
"INTERNAL": {
|
| 26 |
+
"precision": 0.6770712909441233,
|
| 27 |
+
"recall": 0.6833916763905096,
|
| 28 |
+
"f1-score": 0.6802168021680217,
|
| 29 |
+
"support": 2571.0
|
| 30 |
+
},
|
| 31 |
+
"EXTERNAL": {
|
| 32 |
+
"precision": 0.8924773532886964,
|
| 33 |
+
"recall": 0.882398753894081,
|
| 34 |
+
"f1-score": 0.8874094380262385,
|
| 35 |
+
"support": 2568.0
|
| 36 |
+
},
|
| 37 |
+
"BOTH": {
|
| 38 |
+
"precision": 0.6522978268614179,
|
| 39 |
+
"recall": 0.7321071571371451,
|
| 40 |
+
"f1-score": 0.6899020346646572,
|
| 41 |
+
"support": 2501.0
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"confusion_matrix": [
|
| 45 |
+
[
|
| 46 |
+
1530,
|
| 47 |
+
388,
|
| 48 |
+
160,
|
| 49 |
+
417
|
| 50 |
+
],
|
| 51 |
+
[
|
| 52 |
+
323,
|
| 53 |
+
1757,
|
| 54 |
+
45,
|
| 55 |
+
446
|
| 56 |
+
],
|
| 57 |
+
[
|
| 58 |
+
131,
|
| 59 |
+
58,
|
| 60 |
+
2266,
|
| 61 |
+
113
|
| 62 |
+
],
|
| 63 |
+
[
|
| 64 |
+
210,
|
| 65 |
+
392,
|
| 66 |
+
68,
|
| 67 |
+
1831
|
| 68 |
+
]
|
| 69 |
+
],
|
| 70 |
+
"training_info": {
|
| 71 |
+
"total_examples": 101348,
|
| 72 |
+
"train_examples": 91213,
|
| 73 |
+
"val_examples": 10135,
|
| 74 |
+
"examples_per_class": 25337,
|
| 75 |
+
"training_time_hours": 9.7,
|
| 76 |
+
"final_epoch": 3.86
|
| 77 |
+
}
|
| 78 |
+
}
|
images/confusion_matrix.png
ADDED
|
Git LFS Details
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9344c35266b171e7f56af4f92b3a0cc28964da72beb685d5f4f11b56d895a86
|
| 3 |
+
size 567604704
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.0.0
|
| 2 |
+
transformers>=4.30.0
|
| 3 |
+
numpy>=1.21.0
|
| 4 |
+
scikit-learn>=1.0.0
|
| 5 |
+
matplotlib>=3.5.0
|
| 6 |
+
seaborn>=0.11.0
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "[CLS]",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"eos_token": "[SEP]",
|
| 5 |
+
"mask_token": "[MASK]",
|
| 6 |
+
"pad_token": "[PAD]",
|
| 7 |
+
"sep_token": "[SEP]",
|
| 8 |
+
"unk_token": {
|
| 9 |
+
"content": "[UNK]",
|
| 10 |
+
"lstrip": false,
|
| 11 |
+
"normalized": true,
|
| 12 |
+
"rstrip": false,
|
| 13 |
+
"single_word": false
|
| 14 |
+
}
|
| 15 |
+
}
|
spm.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c679fbf93643d19aab7ee10c0b99e460bdbc02fedf34b92b05af343b4af586fd
|
| 3 |
+
size 2464616
|
test_model.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script for plot arc classifier
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
import torch
|
| 8 |
+
from transformers import DebertaV2Tokenizer, DebertaV2ForSequenceClassification
|
| 9 |
+
|
| 10 |
+
def load_tests():
|
| 11 |
+
"""Load synthetic test cases"""
|
| 12 |
+
with open('tests/synthetic_tests.json', 'r') as f:
|
| 13 |
+
return json.load(f)
|
| 14 |
+
|
| 15 |
+
def run_tests():
|
| 16 |
+
"""Run all synthetic tests"""
|
| 17 |
+
print("Loading model...")
|
| 18 |
+
tokenizer = DebertaV2Tokenizer.from_pretrained('.')
|
| 19 |
+
model = DebertaV2ForSequenceClassification.from_pretrained('.')
|
| 20 |
+
|
| 21 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 22 |
+
model.to(device)
|
| 23 |
+
model.eval()
|
| 24 |
+
|
| 25 |
+
class_names = ['NONE', 'INTERNAL', 'EXTERNAL', 'BOTH']
|
| 26 |
+
class_to_idx = {name: idx for idx, name in enumerate(class_names)}
|
| 27 |
+
|
| 28 |
+
tests = load_tests()
|
| 29 |
+
|
| 30 |
+
correct = 0
|
| 31 |
+
total = len(tests)
|
| 32 |
+
|
| 33 |
+
print(f"Running {total} synthetic tests...\n")
|
| 34 |
+
|
| 35 |
+
for i, test in enumerate(tests, 1):
|
| 36 |
+
text = test['description']
|
| 37 |
+
expected = test['expected_class']
|
| 38 |
+
expected_idx = class_to_idx[expected]
|
| 39 |
+
|
| 40 |
+
# Predict
|
| 41 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
| 42 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
| 43 |
+
|
| 44 |
+
with torch.no_grad():
|
| 45 |
+
outputs = model(**inputs)
|
| 46 |
+
probabilities = torch.softmax(outputs.logits, dim=-1)
|
| 47 |
+
predicted_idx = torch.argmax(probabilities, dim=-1).item()
|
| 48 |
+
confidence = probabilities[0][predicted_idx].item()
|
| 49 |
+
|
| 50 |
+
predicted = class_names[predicted_idx]
|
| 51 |
+
is_correct = predicted == expected
|
| 52 |
+
|
| 53 |
+
if is_correct:
|
| 54 |
+
correct += 1
|
| 55 |
+
status = "✅ PASS"
|
| 56 |
+
else:
|
| 57 |
+
status = "❌ FAIL"
|
| 58 |
+
|
| 59 |
+
print(f"Test {i:2d}: {status}")
|
| 60 |
+
print(f" Text: {text[:100]}{'...' if len(text) > 100 else ''}")
|
| 61 |
+
print(f" Expected: {expected} | Predicted: {predicted} (conf: {confidence:.3f})")
|
| 62 |
+
print(f" Reasoning: {test['reasoning']}")
|
| 63 |
+
print()
|
| 64 |
+
|
| 65 |
+
accuracy = correct / total
|
| 66 |
+
print(f"Results: {correct}/{total} correct ({accuracy:.1%})")
|
| 67 |
+
|
| 68 |
+
return accuracy
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
run_tests()
|
tests/synthetic_tests.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"description": "A baker who makes bread every morning in his small village shop.",
|
| 4 |
+
"expected_class": "NONE",
|
| 5 |
+
"reasoning": "No character development or conflict indicated"
|
| 6 |
+
},
|
| 7 |
+
{
|
| 8 |
+
"description": "Sir Galahad embarks on a perilous quest to retrieve the stolen Crown of Ages from the dragon's lair.",
|
| 9 |
+
"expected_class": "EXTERNAL",
|
| 10 |
+
"reasoning": "Clear external mission/quest with specific objective"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"description": "Maria struggles with crippling self-doubt after her mother's harsh words echo in her mind daily.",
|
| 14 |
+
"expected_class": "INTERNAL",
|
| 15 |
+
"reasoning": "Internal psychological conflict, no external events"
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"description": "Captain Torres must infiltrate enemy lines while battling his own cowardice from past failures.",
|
| 19 |
+
"expected_class": "BOTH",
|
| 20 |
+
"reasoning": "External mission (infiltration) + internal conflict (overcoming cowardice)"
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"description": "Dr. Elise Chen, a brilliant neurosurgeon whose perfectionist nature stems from childhood trauma, must perform an experimental procedure to save her estranged brother while confronting the guilt that has haunted her for decades.",
|
| 24 |
+
"expected_class": "BOTH",
|
| 25 |
+
"reasoning": "Complex case: external medical crisis + deep internal psychological journey"
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"description": "The ancient librarian who has catalogued every book in the Grand Archive for three centuries, maintaining perfect order and silence.",
|
| 29 |
+
"expected_class": "NONE",
|
| 30 |
+
"reasoning": "Static character with no indicated change or conflict despite intriguing background"
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"description": "Commander Vex leads the final assault against the rebel stronghold, knowing that victory means destroying the city where his daughter lives.",
|
| 34 |
+
"expected_class": "BOTH",
|
| 35 |
+
"reasoning": "External military objective complicated by internal moral conflict"
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"description": "A merchant who travels between kingdoms, buying low and selling high, always seeking the next profitable deal.",
|
| 39 |
+
"expected_class": "NONE",
|
| 40 |
+
"reasoning": "Routine activity without character growth or meaningful conflict"
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"description": "Zara must decode the ancient prophecy before the lunar eclipse triggers the apocalypse, while wrestling with visions that make her question her own sanity.",
|
| 44 |
+
"expected_class": "BOTH",
|
| 45 |
+
"reasoning": "External time-pressure quest + internal psychological struggle"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"description": "The assassin who kills without emotion, following contracts with mechanical precision, never questioning orders or feeling remorse.",
|
| 49 |
+
"expected_class": "NONE",
|
| 50 |
+
"reasoning": "No internal conflict or character development despite dramatic profession"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"description": "Elena discovers her recurring nightmares are actually suppressed memories of witnessing her father's murder, forcing her to relive the trauma to identify the killer.",
|
| 54 |
+
"expected_class": "INTERNAL",
|
| 55 |
+
"reasoning": "Psychological journey of memory recovery and trauma processing, no external plot"
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"description": "Prince Aldric must unite the warring clans before the demon army arrives, though he secretly fears he's too weak to lead and will fail like his father.",
|
| 59 |
+
"expected_class": "BOTH",
|
| 60 |
+
"reasoning": "External political/military crisis + internal self-doubt and leadership anxiety"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"description": "A shape-shifting entity that observes human civilization across millennia, adapting its form but never truly understanding emotion or purpose.",
|
| 64 |
+
"expected_class": "INTERNAL",
|
| 65 |
+
"reasoning": "Subtle: the struggle to understand emotion/purpose is internal character development"
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"description": "Detective Morgan investigates a series of murders that mirror her own childhood trauma, each clue forcing her to confront buried memories while racing to catch the killer before he strikes again.",
|
| 69 |
+
"expected_class": "BOTH",
|
| 70 |
+
"reasoning": "External investigation/race against time + internal trauma processing"
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"description": "An immortal being who grants wishes to mortals, following cosmic rules without deviation or personal desire.",
|
| 74 |
+
"expected_class": "NONE",
|
| 75 |
+
"reasoning": "No change or conflict despite supernatural nature - purely functional role"
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"description": "The village healer who tends to every wound and illness with the same gentle care, asking nothing in return, content in her service to others.",
|
| 79 |
+
"expected_class": "NONE",
|
| 80 |
+
"reasoning": "Static, fulfilled character with no indicated conflict or growth arc"
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"description": "Kai realizes that saving the world requires sacrificing the one person he loves most, but cannot bring himself to make the choice that logic demands.",
|
| 84 |
+
"expected_class": "INTERNAL",
|
| 85 |
+
"reasoning": "Pure internal moral/emotional conflict - the external 'saving world' is context, not plot"
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"description": "The time-traveling historian who documents major events across eras, maintaining strict neutrality and never interfering with the timeline's natural course.",
|
| 89 |
+
"expected_class": "NONE",
|
| 90 |
+
"reasoning": "Observer role with no character development or conflict despite extraordinary circumstances"
|
| 91 |
+
}
|
| 92 |
+
]
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"1": {
|
| 12 |
+
"content": "[CLS]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"2": {
|
| 20 |
+
"content": "[SEP]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"3": {
|
| 28 |
+
"content": "[UNK]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": true,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"128000": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"bos_token": "[CLS]",
|
| 45 |
+
"clean_up_tokenization_spaces": false,
|
| 46 |
+
"cls_token": "[CLS]",
|
| 47 |
+
"do_lower_case": false,
|
| 48 |
+
"eos_token": "[SEP]",
|
| 49 |
+
"extra_special_tokens": {},
|
| 50 |
+
"mask_token": "[MASK]",
|
| 51 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"sp_model_kwargs": {},
|
| 55 |
+
"split_by_punct": false,
|
| 56 |
+
"tokenizer_class": "DebertaV2Tokenizer",
|
| 57 |
+
"unk_token": "[UNK]",
|
| 58 |
+
"vocab_type": "spm"
|
| 59 |
+
}
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f983cf6452d26be88ab8737aa8462f06399ec39bd8cd32e41bf985dbd6ba16e9
|
| 3 |
+
size 5777
|