NorGLM commited on
Commit
46d82e0
1 Parent(s): de6ec20

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +93 -0
README.md CHANGED
@@ -1,3 +1,96 @@
1
  ---
2
  license: cc-by-nc-sa-4.0
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-nc-sa-4.0
3
+ language:
4
+ - 'no'
5
  ---
6
+
7
+
8
+ # Model Card
9
+
10
+ NorGPT-369M-NO-QNLI-peft is trained on top of [NorGPT-369M](https://huggingface.co/NorGLM/NorGPT-369M) model on [NO-QNLI](https://huggingface.co/datasets/NorGLM/NO-QNLI) dataset.
11
+
12
+ Data format:
13
+ ```
14
+ input: {premise}[SEP]{hypothesis}
15
+ label: {entailment, not_entailment} -> {1,0}
16
+ ```
17
+
18
+ ## Run the Model
19
+ ```python
20
+ from peft import PeftModel, PeftConfig
21
+ from transformers import AutoModelForCausalLM, AutoTokenizer
22
+ import torch
23
+
24
+ torch_device = "cuda" if torch.cuda.is_available() else "cpu"
25
+
26
+ source_model_id = "NbAiLab/nb-gpt-j-6B"
27
+ peft_model_id = "NorGLM/NorGPT-369M-NO-QNLI-peft"
28
+
29
+ config = PeftConfig.from_pretrained(peft_model_id)
30
+ model = AutoModelForCausalLM.from_pretrained(source_model_id, device_map='balanced')
31
+
32
+ tokenizer_max_len = 2048
33
+ tokenizer_config = {'pretrained_model_name_or_path': source_model_id,
34
+ 'max_len': tokenizer_max_len}
35
+ tokenizer = tokenizer = AutoTokenizer.from_pretrained(**tokenizer_config)
36
+ tokenizer.pad_token = tokenizer.eos_token
37
+
38
+ model = PeftModel.from_pretrained(model, peft_model_id)
39
+ ```
40
+
41
+ ## Inference Example
42
+ Load the model to evaluate on the validation set:
43
+ ```python
44
+
45
+ def getDataSetFromFiles(df):
46
+ # convert dataset
47
+ df["text"] = df[["premise", "hypothesis"]].apply(lambda x: " [SEP] ".join(x.astype(str)), axis =1)
48
+ df = df.drop(["idx", "premise", "hypothesis"], axis=1)
49
+ #df['label'] = df['label'].replace({1:'contradiction', -1:'entailment', 0:'neutral'})
50
+ df["label"] = df.label.map({"not_entailment": 0, "entailment": 1})
51
+ return Dataset.from_pandas(df)
52
+
53
+ print("--LOADING EVAL DATAS---")
54
+ eval_data = load_dataset("NorGLM/NO-BoolQ", data_files="val.jsonl")
55
+ eval_data = getDataSetFromFiles(eval_data["train"].to_pandas())
56
+
57
+ print("--MAKING PREDICTIONS---")
58
+ model.eval()
59
+
60
+ y_true = []
61
+ y_pred = []
62
+ count = 0
63
+
64
+ for data in eval_data:
65
+ count = count + 1
66
+ if count % 100 == 0:
67
+ print(count)
68
+ inputs = tokenizer(data['text'], return_tensors="pt").to(torch_device)
69
+
70
+ with torch.no_grad():
71
+ logits = model(**inputs).logits
72
+ #print(logits)
73
+
74
+ predicted_class_id = logits.argmax().item()
75
+
76
+ y_true.append(data['label'])
77
+ y_pred.append(predicted_class_id)
78
+
79
+ print(y_pred)
80
+
81
+ print(f"Lenght of true_values: {len(y_true)}")
82
+ print(f"Lenght of predicted_values: {len(y_pred)}")
83
+
84
+ y_true = np.array(y_true)
85
+ y_pred = np.array(y_pred)
86
+
87
+ F_score = f1_score(y_true, y_pred, average="macro")
88
+ print(f"F1 score: {F_score}")
89
+
90
+ accuracy = accuracy_score(y_true, y_pred)
91
+ print(f"Accuracy: {accuracy}")
92
+
93
+ ```
94
+
95
+ ## Note
96
+ More training details will be released soon!