froggydood commited on
Commit
b53369f
·
1 Parent(s): b2643ce

Initial model output

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ outputs
config.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "microsoft/deberta-v3-base",
3
+ "architectures": [
4
+ "DebertaV2ForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 768,
10
+ "id2label": {
11
+ "0": "LABEL_0",
12
+ "1": "LABEL_1",
13
+ "2": "LABEL_2"
14
+ },
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 3072,
17
+ "label2id": {
18
+ "LABEL_0": 0,
19
+ "LABEL_1": 1,
20
+ "LABEL_2": 2
21
+ },
22
+ "layer_norm_eps": 1e-07,
23
+ "max_position_embeddings": 512,
24
+ "max_relative_positions": -1,
25
+ "model_type": "deberta-v2",
26
+ "norm_rel_ebd": "layer_norm",
27
+ "num_attention_heads": 12,
28
+ "num_hidden_layers": 12,
29
+ "pad_token_id": 0,
30
+ "pooler_dropout": 0,
31
+ "pooler_hidden_act": "gelu",
32
+ "pooler_hidden_size": 768,
33
+ "pos_att_type": [
34
+ "p2c",
35
+ "c2p"
36
+ ],
37
+ "position_biased_input": false,
38
+ "position_buckets": 256,
39
+ "relative_attention": true,
40
+ "share_att_key": true,
41
+ "torch_dtype": "float32",
42
+ "transformers_version": "4.38.2",
43
+ "type_vocab_size": 0,
44
+ "vocab_size": 128100
45
+ }
datasets/info.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ SemEval-2016 Task 6
2
+ https://alt.qcri.org/semeval2016/task6/index.php?id=data-and-tools
datasets/test.csv ADDED
The diff for this file is too large to render. See raw diff
 
datasets/train.csv ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc4eccd7fa0d493ce18a1f334c618566485321f1567c92f8f9170ace693badaf
3
+ size 737722356
rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf6d32b103197dc0b3210814748bc7af241646d83d0a4e8e33910d527c40122b
3
+ size 14244
scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd93ceae9b40717ccd5dcd1b77f775797992dd03971d180c878c64433e5e15d2
3
+ size 1064
test.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
2
+ import os
3
+ import numpy as np
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/deberta-v3-base")
6
+ model = AutoModelForSequenceClassification.from_pretrained(
7
+ os.path.realpath(os.path.join(__file__, "..", "./outputs/v2-deberta-100-max-71%-sep/checkpoint-1000/")),
8
+ local_files_only=True
9
+ )
10
+
11
+ text_against = "ai [SEP] I think ai is a waste of time. I don't understand why everyone is so obsessed with this subject, it makes no sense?"
12
+ text_for = "flowers [SEP] I think flowers are very useful and will become essential to society"
13
+ text_neutral = "Ai is a tool use by researchers and scientists to approximate functions"
14
+ encoded = tokenizer(text_for.lower(), max_length=100, padding="max_length", truncation=True, return_tensors="pt")
15
+
16
+ def normalize(arr: np.ndarray) -> np.ndarray:
17
+ min = arr.min()
18
+ arr = arr - min
19
+ return arr / arr.sum()
20
+
21
+ output = model(**encoded)
22
+ print(output.logits.detach().numpy()[0])
23
+ print(normalize(output.logits.detach().numpy()[0]))
train.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ from typing import TypedDict
3
+ import numpy as np
4
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
5
+ from datasets import load_dataset, Dataset
6
+ import pandas as pd
7
+ import evaluate
8
+ import os
9
+ import torch
10
+
11
+ data_files = {
12
+ "train": os.path.realpath(os.path.join(__file__, "..", "./datasets/train.csv")),
13
+ "test": os.path.realpath(os.path.join(__file__, "..", "./datasets/test.csv"))
14
+ }
15
+ output_dir = os.path.realpath(os.path.join(__file__, "..", "./outputs/v2-deberta-100-max"))
16
+
17
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/deberta-v3-base")
18
+
19
+ label_map = {
20
+ "FAVOR": 0,
21
+ "NONE": 1,
22
+ "AGAINST": 2
23
+ }
24
+
25
+ torch.cuda.empty_cache()
26
+
27
+ def tokenize(examples):
28
+ examples["label"] = [label_map[label] for label in examples["label"]]
29
+ examples["text"] = [examples["Target"][i] + " [SEP] " + text for i , text in enumerate(examples["text"])]
30
+ return tokenizer(examples["text"], padding="max_length", return_tensors='pt', truncation=True, max_length=100)
31
+
32
+
33
+ def load_dataset(path: str) -> Dataset:
34
+ dataframe = pd.read_csv(path)
35
+ dataframe = dataframe.drop("Opinion Towards", axis=1)
36
+ dataframe = dataframe.drop("Sentiment", axis=1)
37
+ dataset = Dataset.from_pandas(dataframe)
38
+ dataset = dataset.rename_column('Tweet', 'text')
39
+ dataset = dataset.rename_column("Stance", "label")
40
+
41
+ return dataset.map(tokenize, batched=True)
42
+
43
+ train_ds = load_dataset(data_files["train"])
44
+ test_ds = load_dataset(data_files["test"])
45
+
46
+ model = AutoModelForSequenceClassification.from_pretrained("microsoft/deberta-v3-base", num_labels=3)
47
+
48
+ metric = evaluate.load("accuracy")
49
+
50
+ def compute_metrics(eval_pred):
51
+ logits, labels = eval_pred
52
+ predictions = np.argmax(logits, axis=-1)
53
+ return metric.compute(predictions=predictions, references=labels)
54
+
55
+ training_args = TrainingArguments(output_dir=output_dir, evaluation_strategy="epoch")
56
+
57
+ trainer = Trainer(
58
+ model=model,
59
+ args=training_args,
60
+ train_dataset=train_ds,
61
+ eval_dataset=test_ds,
62
+ compute_metrics=compute_metrics
63
+ )
64
+ print("TRAINING")
65
+
66
+ trainer.train()
trainer_state.json ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 2.73972602739726,
5
+ "eval_steps": 500,
6
+ "global_step": 1000,
7
+ "is_hyper_param_search": false,
8
+ "is_local_process_zero": true,
9
+ "is_world_process_zero": true,
10
+ "log_history": [
11
+ {
12
+ "epoch": 1.0,
13
+ "eval_accuracy": 0.6820040899795501,
14
+ "eval_loss": 0.7493410706520081,
15
+ "eval_runtime": 6.4955,
16
+ "eval_samples_per_second": 301.132,
17
+ "eval_steps_per_second": 37.718,
18
+ "step": 365
19
+ },
20
+ {
21
+ "epoch": 1.37,
22
+ "grad_norm": 20.02265739440918,
23
+ "learning_rate": 2.71689497716895e-05,
24
+ "loss": 0.7495,
25
+ "step": 500
26
+ },
27
+ {
28
+ "epoch": 2.0,
29
+ "eval_accuracy": 0.7055214723926381,
30
+ "eval_loss": 0.7625377774238586,
31
+ "eval_runtime": 6.586,
32
+ "eval_samples_per_second": 296.992,
33
+ "eval_steps_per_second": 37.2,
34
+ "step": 730
35
+ },
36
+ {
37
+ "epoch": 2.74,
38
+ "grad_norm": 15.491150856018066,
39
+ "learning_rate": 4.337899543378996e-06,
40
+ "loss": 0.4253,
41
+ "step": 1000
42
+ }
43
+ ],
44
+ "logging_steps": 500,
45
+ "max_steps": 1095,
46
+ "num_input_tokens_seen": 0,
47
+ "num_train_epochs": 3,
48
+ "save_steps": 500,
49
+ "total_flos": 410505404868000.0,
50
+ "train_batch_size": 8,
51
+ "trial_name": null,
52
+ "trial_params": null
53
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16a839ef4391579a0a777fe359682af2af1f7b1340ab79e578d454375fa4556c
3
+ size 5048