NorGLM commited on
Commit
9755473
1 Parent(s): 52f5439

Update README.md

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