Spaces:
Running
Running
Bram van Es
commited on
Commit
·
297638b
1
Parent(s):
80323f9
added config.y
Browse files
config.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Configuration file for PerplexityViewer
|
| 2 |
+
|
| 3 |
+
# Default models for different types
|
| 4 |
+
DEFAULT_MODELS = {
|
| 5 |
+
"decoder": [
|
| 6 |
+
"gpt2",
|
| 7 |
+
"distilgpt2",
|
| 8 |
+
"microsoft/DialoGPT-small",
|
| 9 |
+
"microsoft/DialoGPT-medium",
|
| 10 |
+
"openai-gpt"
|
| 11 |
+
],
|
| 12 |
+
"encoder": [
|
| 13 |
+
"bert-base-uncased",
|
| 14 |
+
"bert-base-cased",
|
| 15 |
+
"distilbert-base-uncased",
|
| 16 |
+
"roberta-base",
|
| 17 |
+
"albert-base-v2"
|
| 18 |
+
"UMCU/CardioMedRoBERTa.nl",
|
| 19 |
+
"UMCU/CardioBERTa_base.nl",
|
| 20 |
+
"UMCU/CardioBERTa.nl_clinical",
|
| 21 |
+
"UMCU/CardioDeBERTa.nl",
|
| 22 |
+
"UMCU/CardioDeBERTa.nl_clinical",
|
| 23 |
+
"CLTL/MedRoBERTa.nl",
|
| 24 |
+
"DTAI-KULeuven/robbert-2023-dutch-base",
|
| 25 |
+
"DTAI-KULeuven/robbert-2023-dutch-large"
|
| 26 |
+
]
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
# Model display settings
|
| 30 |
+
MODEL_SETTINGS = {
|
| 31 |
+
"max_length": 512,
|
| 32 |
+
"torch_dtype": "float16",
|
| 33 |
+
"device_map": "auto"
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# Visualization settings
|
| 37 |
+
VIZ_SETTINGS = {
|
| 38 |
+
"max_perplexity_display": 50.0, # Cap visualization at this perplexity value
|
| 39 |
+
"color_scheme": {
|
| 40 |
+
"low_perplexity": {"r": 46, "g": 204, "b": 113}, # Green for low perplexity (confident)
|
| 41 |
+
"medium_perplexity": {"r": 241, "g": 196, "b": 15}, # Yellow for medium perplexity
|
| 42 |
+
"high_perplexity": {"r": 231, "g": 76, "b": 60}, # Red for high perplexity (uncertain)
|
| 43 |
+
"background_alpha": 0.7, # Background transparency
|
| 44 |
+
"border_alpha": 0.9 # Border transparency
|
| 45 |
+
},
|
| 46 |
+
"thresholds": {
|
| 47 |
+
"low_threshold": 0.3, # Below this is low perplexity (green)
|
| 48 |
+
"high_threshold": 0.7 # Above this is high perplexity (red)
|
| 49 |
+
},
|
| 50 |
+
"displacy_options": {
|
| 51 |
+
"ents": ["PP"],
|
| 52 |
+
"colors": {}
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
# Processing settings
|
| 57 |
+
PROCESSING_SETTINGS = {
|
| 58 |
+
"epsilon": 1e-10, # Small value to avoid log(0)
|
| 59 |
+
"default_mask_probability": 0.15,
|
| 60 |
+
"min_mask_probability": 0.05,
|
| 61 |
+
"max_mask_probability": 0.5,
|
| 62 |
+
"default_min_samples": 10,
|
| 63 |
+
"min_samples_range": (5, 50)
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
# UI settings
|
| 67 |
+
UI_SETTINGS = {
|
| 68 |
+
"theme": "soft",
|
| 69 |
+
"title": "📈 Perplexity Viewer",
|
| 70 |
+
"description": """
|
| 71 |
+
Visualize per-token perplexity using color gradients.
|
| 72 |
+
- **Red**: High perplexity (model is uncertain)
|
| 73 |
+
- **Green**: Low perplexity (model is confident)
|
| 74 |
+
|
| 75 |
+
Choose between decoder models (like GPT) for true perplexity or encoder models (like BERT) for pseudo-perplexity via MLM.
|
| 76 |
+
""",
|
| 77 |
+
"examples": [
|
| 78 |
+
{
|
| 79 |
+
"text": "The quick brown fox jumps over the lazy dog.",
|
| 80 |
+
"model": "gpt2",
|
| 81 |
+
"type": "decoder",
|
| 82 |
+
"mask_prob": 0.15,
|
| 83 |
+
"min_samples": 10
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"text": "The capital of France is Paris.",
|
| 87 |
+
"model": "bert-base-uncased",
|
| 88 |
+
"type": "encoder",
|
| 89 |
+
"mask_prob": 0.15,
|
| 90 |
+
"min_samples": 10
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"text": "Quantum entanglement defies classical physics intuition completely.",
|
| 94 |
+
"model": "distilgpt2",
|
| 95 |
+
"type": "decoder",
|
| 96 |
+
"mask_prob": 0.15,
|
| 97 |
+
"min_samples": 10
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"text": "Machine learning requires large datasets for training.",
|
| 101 |
+
"model": "distilbert-base-uncased",
|
| 102 |
+
"type": "encoder",
|
| 103 |
+
"mask_prob": 0.2,
|
| 104 |
+
"min_samples": 15
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"text": "Artificial intelligence transforms modern computing paradigms.",
|
| 108 |
+
"model": "bert-base-uncased",
|
| 109 |
+
"type": "encoder",
|
| 110 |
+
"mask_prob": 0.1,
|
| 111 |
+
"min_samples": 20
|
| 112 |
+
}
|
| 113 |
+
]
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
# Error messages
|
| 117 |
+
ERROR_MESSAGES = {
|
| 118 |
+
"empty_text": "Please enter some text to analyze.",
|
| 119 |
+
"model_load_error": "Error loading model {model_name}: {error}",
|
| 120 |
+
"processing_error": "Error processing text: {error}",
|
| 121 |
+
"no_tokens_masked": "No tokens were masked during MLM processing.",
|
| 122 |
+
"invalid_model_type": "Invalid model type. Must be 'encoder' or 'decoder'."
|
| 123 |
+
}
|