CoolFace
Modelpublic

crarojasca/TaxonomyAugmentedCARDS

sourceHugging Facemitupdated 2y agoView on Hugging Face
2likes41downloads
Model Card

Taxonomy Augmented CARDS

Taxonomy

[image]

Metrics

**Category****CARDS****Augmented CARDS****Support**
00_70.981.51049
11_60.570.428
12_4044.420
13_3748.661
14_62.165.627
16_56.759.741
17_46.45289
21_68.169.4154
23_36.72522
31_38.534.88
32_6174.631
33_54.265.423
41_38.549.4103
42_37.628.661
44_30.854.546
45_19.739.450
51_32.838.296
52_38.653.5498
5.3-62.9200
Macro Average43.6953.572407

Code

To run the model, you need to first evaluate the binary classification model, as shown below:

python
# Models
MAX_LEN = 256
BINARY_MODEL_DIR = "crarojasca/BinaryAugmentedCARDS"
TAXONOMY_MODEL_DIR = "crarojasca/TaxonomyAugmentedCARDS"

# Loading tokenizer
tokenizer = AutoTokenizer.from_pretrained(
    BINARY_MODEL_DIR,
    max_length = MAX_LEN, padding = "max_length", 
    return_token_type_ids = True
)

# Loading Models
## 1. Binary Model
print("Loading binary model: {}".format(BINARY_MODEL_DIR))
config = AutoConfig.from_pretrained(BINARY_MODEL_DIR)
binary_model = AutoModelForSequenceClassification.from_pretrained(BINARY_MODEL_DIR, config=config)
binary_model.to(device)

## 2. Taxonomy Model
print("Loading taxonomy model: {}".format(TAXONOMY_MODEL_DIR))
config = AutoConfig.from_pretrained(TAXONOMY_MODEL_DIR)
taxonomy_model = AutoModelForSequenceClassification.from_pretrained(TAXONOMY_MODEL_DIR, config=config)
taxonomy_model.to(device)

# Load Dataset
id2label = {
    0: '1_1', 1: '1_2', 2: '1_3', 3: '1_4', 4: '1_6', 5: '1_7', 6: '2_1', 
    7: '2_3', 8: '3_1', 9: '3_2', 10: '3_3', 11: '4_1', 12: '4_2', 13: '4_4', 
    14: '4_5', 15: '5_1', 16: '5_2', 17: '5_3'
}


text = "Climate change is just a natural phenomenon"

tokenized_text = tokenizer(text, return_tensors = "pt")


# Running Binary Model
outputs = binary_model(**tokenized_text)
binary_score = outputs.logits.softmax(dim = 1)
binary_prediction = torch.argmax(outputs.logits, axis=1)
binary_predictions = binary_prediction.to('cpu').item()

# Running Taxonomy Model
outputs = taxonomy_model(**tokenized_text)
taxonomy_score = outputs.logits.softmax(dim = 1)
taxonomy_prediction = torch.argmax(outputs.logits, axis=1)
taxonomy_prediction = taxonomy_prediction.to('cpu').item()


prediction = "0_0" if binary_prediction==0 else id2label[taxonomy_prediction]
prediction