Upload 7 files
Browse files- config.json +54 -0
- example_usage.py +68 -0
- model.safetensors +3 -0
- special_tokens_map.json +7 -0
- tokenizer_config.json +58 -0
- vocab.txt +0 -0
config.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"BertForSequenceClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"classifier_dropout": null,
|
| 7 |
+
"dtype": "float32",
|
| 8 |
+
"gradient_checkpointing": false,
|
| 9 |
+
"hidden_act": "gelu",
|
| 10 |
+
"hidden_dropout_prob": 0.1,
|
| 11 |
+
"hidden_size": 768,
|
| 12 |
+
"id2label": {
|
| 13 |
+
"0": "Cog-Evaluate",
|
| 14 |
+
"1": "Cog-Explain",
|
| 15 |
+
"2": "Cog-Generate",
|
| 16 |
+
"3": "Cog-Reason",
|
| 17 |
+
"4": "Meta-Monitor",
|
| 18 |
+
"5": "Meta-Orient",
|
| 19 |
+
"6": "Meta-Plan",
|
| 20 |
+
"7": "Socio-Coordinate",
|
| 21 |
+
"8": "Socio-Encourage",
|
| 22 |
+
"9": "Socio-Feedback",
|
| 23 |
+
"10": "TE-Act",
|
| 24 |
+
"11": "TE-Report"
|
| 25 |
+
},
|
| 26 |
+
"initializer_range": 0.02,
|
| 27 |
+
"intermediate_size": 3072,
|
| 28 |
+
"label2id": {
|
| 29 |
+
"Cog-Evaluate": 0,
|
| 30 |
+
"Cog-Explain": 1,
|
| 31 |
+
"Cog-Generate": 2,
|
| 32 |
+
"Cog-Reason": 3,
|
| 33 |
+
"Meta-Monitor": 4,
|
| 34 |
+
"Meta-Orient": 5,
|
| 35 |
+
"Meta-Plan": 6,
|
| 36 |
+
"Socio-Coordinate": 7,
|
| 37 |
+
"Socio-Encourage": 8,
|
| 38 |
+
"Socio-Feedback": 9,
|
| 39 |
+
"TE-Act": 10,
|
| 40 |
+
"TE-Report": 11
|
| 41 |
+
},
|
| 42 |
+
"layer_norm_eps": 1e-12,
|
| 43 |
+
"max_position_embeddings": 512,
|
| 44 |
+
"model_type": "bert",
|
| 45 |
+
"num_attention_heads": 12,
|
| 46 |
+
"num_hidden_layers": 12,
|
| 47 |
+
"pad_token_id": 0,
|
| 48 |
+
"position_embedding_type": "absolute",
|
| 49 |
+
"problem_type": "multi_label_classification",
|
| 50 |
+
"transformers_version": "4.57.6",
|
| 51 |
+
"type_vocab_size": 2,
|
| 52 |
+
"use_cache": true,
|
| 53 |
+
"vocab_size": 30522
|
| 54 |
+
}
|
example_usage.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Regulatory Capacity Classifier - Usage Example
|
| 3 |
+
|
| 4 |
+
This script demonstrates how to use the trained model for inference.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
| 9 |
+
|
| 10 |
+
# Configuration
|
| 11 |
+
MODEL_PATH = "./final_model"
|
| 12 |
+
LABELS = ['Cog-Evaluate', 'Cog-Explain', 'Cog-Generate', 'Cog-Reason', 'Meta-Monitor', 'Meta-Orient', 'Meta-Plan', 'Socio-Coordinate', 'Socio-Encourage', 'Socio-Feedback', 'TE-Act', 'TE-Report']
|
| 13 |
+
|
| 14 |
+
def load_model():
|
| 15 |
+
"""Load the trained model and tokenizer."""
|
| 16 |
+
tokenizer = BertTokenizer.from_pretrained(MODEL_PATH)
|
| 17 |
+
model = BertForSequenceClassification.from_pretrained(MODEL_PATH)
|
| 18 |
+
model.eval()
|
| 19 |
+
return tokenizer, model
|
| 20 |
+
|
| 21 |
+
def predict(text, tokenizer, model, threshold=0.5):
|
| 22 |
+
"""Predict regulatory capacity labels for a given text."""
|
| 23 |
+
# Tokenize
|
| 24 |
+
inputs = tokenizer(
|
| 25 |
+
text,
|
| 26 |
+
return_tensors="pt",
|
| 27 |
+
truncation=True,
|
| 28 |
+
max_length=128,
|
| 29 |
+
padding=True
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Predict
|
| 33 |
+
with torch.no_grad():
|
| 34 |
+
outputs = model(**inputs)
|
| 35 |
+
probs = torch.sigmoid(outputs.logits)
|
| 36 |
+
predictions = (probs > threshold).int()
|
| 37 |
+
|
| 38 |
+
# Map to labels
|
| 39 |
+
predicted_labels = [LABELS[i] for i in range(len(LABELS)) if predictions[0][i] == 1]
|
| 40 |
+
confidences = {LABELS[i]: float(probs[0][i]) for i in range(len(LABELS))}
|
| 41 |
+
|
| 42 |
+
return predicted_labels, confidences
|
| 43 |
+
|
| 44 |
+
def main():
|
| 45 |
+
print("Loading model...")
|
| 46 |
+
tokenizer, model = load_model()
|
| 47 |
+
|
| 48 |
+
# Example texts
|
| 49 |
+
test_texts = [
|
| 50 |
+
"I think we should evaluate our approach before moving forward.",
|
| 51 |
+
"Let's coordinate our tasks and divide the work equally.",
|
| 52 |
+
"Good job everyone! We're making great progress.",
|
| 53 |
+
"Can you explain why you chose that option?",
|
| 54 |
+
"I'll write down our conclusions in the report."
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
print("\n" + "="*60)
|
| 58 |
+
print("Regulatory Capacity Predictions")
|
| 59 |
+
print("="*60)
|
| 60 |
+
|
| 61 |
+
for text in test_texts:
|
| 62 |
+
labels, confidences = predict(text, tokenizer, model)
|
| 63 |
+
print(f"\nText: {text}")
|
| 64 |
+
print(f"Predicted Labels: {labels}")
|
| 65 |
+
print(f"Top Confidences: {{k: f'{v:.3f}' for k, v in sorted(confidences.items(), key=lambda x: -x[1])[:3]}}")
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
main()
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71978a2b7d8de081978379d2b0cb6d3170ab88f3554ae95bf9f4d73532022efc
|
| 3 |
+
size 437989408
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
"100": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"101": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"102": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"103": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": true,
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "[MASK]",
|
| 50 |
+
"model_max_length": 512,
|
| 51 |
+
"never_split": null,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"strip_accents": null,
|
| 55 |
+
"tokenize_chinese_chars": true,
|
| 56 |
+
"tokenizer_class": "BertTokenizer",
|
| 57 |
+
"unk_token": "[UNK]"
|
| 58 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|