Commit
β’
5f95d6e
1
Parent(s):
6a3ca31
add the trained bert model
Browse files- biobertALL_2epoch/config.json +27 -0
- biobertALL_2epoch/pytorch_model.bin +3 -0
- biobertALL_2epoch/training_args.bin +3 -0
- bluebertALL_2epoch/config.json +26 -0
- bluebertALL_2epoch/pytorch_model.bin +3 -0
- bluebertALL_2epoch/training_args.bin +3 -0
- clinicalbertALL_2epoch/config.json +26 -0
- clinicalbertALL_2epoch/pytorch_model.bin +3 -0
- clinicalbertALL_2epoch/training_args.bin +3 -0
- pubmedbertALL_2epoch/config.json +26 -0
- pubmedbertALL_2epoch/pytorch_model.bin +3 -0
- pubmedbertALL_2epoch/training_args.bin +3 -0
- ranking_responses.ipynb +406 -0
- scibertALL_2epoch/config.json +26 -0
- scibertALL_2epoch/pytorch_model.bin +3 -0
- scibertALL_2epoch/training_args.bin +3 -0
biobertALL_2epoch/config.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "dmis-lab/biobert-v1.1",
|
3 |
+
"architectures": [
|
4 |
+
"BertForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"gradient_checkpointing": false,
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.1,
|
11 |
+
"hidden_size": 768,
|
12 |
+
"initializer_range": 0.02,
|
13 |
+
"intermediate_size": 3072,
|
14 |
+
"layer_norm_eps": 1e-12,
|
15 |
+
"max_position_embeddings": 512,
|
16 |
+
"model_type": "bert",
|
17 |
+
"num_attention_heads": 12,
|
18 |
+
"num_hidden_layers": 12,
|
19 |
+
"pad_token_id": 0,
|
20 |
+
"position_embedding_type": "absolute",
|
21 |
+
"problem_type": "single_label_classification",
|
22 |
+
"torch_dtype": "float32",
|
23 |
+
"transformers_version": "4.24.0",
|
24 |
+
"type_vocab_size": 2,
|
25 |
+
"use_cache": true,
|
26 |
+
"vocab_size": 28996
|
27 |
+
}
|
biobertALL_2epoch/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3e43d39cd8ab7b074dc264efadcc533c4a0bc8e25ed40e1169db91a0f1964908
|
3 |
+
size 433318253
|
biobertALL_2epoch/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9fd95089f8d96b6e2eb676380bfb0f2e152c0958f53795c9d26684f86a1b15cb
|
3 |
+
size 3375
|
bluebertALL_2epoch/config.json
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "bionlp/bluebert_pubmed_mimic_uncased_L-12_H-768_A-12",
|
3 |
+
"architectures": [
|
4 |
+
"BertForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.1,
|
10 |
+
"hidden_size": 768,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"intermediate_size": 3072,
|
13 |
+
"layer_norm_eps": 1e-12,
|
14 |
+
"max_position_embeddings": 512,
|
15 |
+
"model_type": "bert",
|
16 |
+
"num_attention_heads": 12,
|
17 |
+
"num_hidden_layers": 12,
|
18 |
+
"pad_token_id": 0,
|
19 |
+
"position_embedding_type": "absolute",
|
20 |
+
"problem_type": "single_label_classification",
|
21 |
+
"torch_dtype": "float32",
|
22 |
+
"transformers_version": "4.24.0",
|
23 |
+
"type_vocab_size": 2,
|
24 |
+
"use_cache": true,
|
25 |
+
"vocab_size": 30522
|
26 |
+
}
|
bluebertALL_2epoch/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c5326fa9a67f154bfe9d9a1a9dbaedce7ff57e084db8d28807e519d8374a321e
|
3 |
+
size 438006125
|
bluebertALL_2epoch/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:acd211e3873a8f509ac9d21577c002397f9d5fb46c4f79660a9cd15e366c89db
|
3 |
+
size 3375
|
clinicalbertALL_2epoch/config.json
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "emilyalsentzer/Bio_ClinicalBERT",
|
3 |
+
"architectures": [
|
4 |
+
"BertForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.1,
|
10 |
+
"hidden_size": 768,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"intermediate_size": 3072,
|
13 |
+
"layer_norm_eps": 1e-12,
|
14 |
+
"max_position_embeddings": 512,
|
15 |
+
"model_type": "bert",
|
16 |
+
"num_attention_heads": 12,
|
17 |
+
"num_hidden_layers": 12,
|
18 |
+
"pad_token_id": 0,
|
19 |
+
"position_embedding_type": "absolute",
|
20 |
+
"problem_type": "single_label_classification",
|
21 |
+
"torch_dtype": "float32",
|
22 |
+
"transformers_version": "4.24.0",
|
23 |
+
"type_vocab_size": 2,
|
24 |
+
"use_cache": true,
|
25 |
+
"vocab_size": 28996
|
26 |
+
}
|
clinicalbertALL_2epoch/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c2b8c199354cdf3606d28dc93e71670d25f1578ba67d01e0f34688ccb9ea193e
|
3 |
+
size 433318253
|
clinicalbertALL_2epoch/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f405affa2b551e07a9d9af99be6aeb04f3b5cbe9c6f6527a18af82eecec495ee
|
3 |
+
size 3375
|
pubmedbertALL_2epoch/config.json
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext",
|
3 |
+
"architectures": [
|
4 |
+
"BertForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.1,
|
10 |
+
"hidden_size": 768,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"intermediate_size": 3072,
|
13 |
+
"layer_norm_eps": 1e-12,
|
14 |
+
"max_position_embeddings": 512,
|
15 |
+
"model_type": "bert",
|
16 |
+
"num_attention_heads": 12,
|
17 |
+
"num_hidden_layers": 12,
|
18 |
+
"pad_token_id": 0,
|
19 |
+
"position_embedding_type": "absolute",
|
20 |
+
"problem_type": "single_label_classification",
|
21 |
+
"torch_dtype": "float32",
|
22 |
+
"transformers_version": "4.24.0",
|
23 |
+
"type_vocab_size": 2,
|
24 |
+
"use_cache": true,
|
25 |
+
"vocab_size": 30522
|
26 |
+
}
|
pubmedbertALL_2epoch/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3c7f895c557f9748aab145e6f8e4f3727dfad0360ddd9482b607ec303a1e31d8
|
3 |
+
size 438006125
|
pubmedbertALL_2epoch/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c7b06c52d751e2b0e5bd6bc2e787ee7331e5f4b0793ca6f1a71fc878afea1cd4
|
3 |
+
size 3375
|
ranking_responses.ipynb
ADDED
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 4,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"# import the package\n",
|
10 |
+
"import numpy as np\n",
|
11 |
+
"import pandas as pd\n",
|
12 |
+
"import datasets\n",
|
13 |
+
"import evaluate\n",
|
14 |
+
"from datasets import DatasetDict, Dataset\n",
|
15 |
+
"from transformers import AutoTokenizer, Trainer, BertForSequenceClassification\n",
|
16 |
+
"import torch\n",
|
17 |
+
"from accelerate import Accelerator"
|
18 |
+
]
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"attachments": {},
|
22 |
+
"cell_type": "markdown",
|
23 |
+
"metadata": {},
|
24 |
+
"source": [
|
25 |
+
"# Attention: \n",
|
26 |
+
"\n",
|
27 |
+
"This file is used to ranking the response. It will calculate the probability for each sample_answer and return the most probability one and the index of it. \n",
|
28 |
+
"\n",
|
29 |
+
"The file only contains answers to one question is recommended or we need to split the dataframe manually.\n",
|
30 |
+
"\n",
|
31 |
+
"The input of the function is the path of the file and the file of the pretrained model and corresponding tokenizer."
|
32 |
+
]
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"cell_type": "code",
|
36 |
+
"execution_count": 14,
|
37 |
+
"metadata": {},
|
38 |
+
"outputs": [],
|
39 |
+
"source": [
|
40 |
+
"# load the data\n",
|
41 |
+
"\n",
|
42 |
+
"path = 'C:/Users/cxz55/Desktop/UCL/term2/COMP087/cw/data_nlp_porject' #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
|
43 |
+
"file_name = 'five_responses.csv' #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
|
44 |
+
"\n",
|
45 |
+
"def load_data(path,file_name):\n",
|
46 |
+
"\n",
|
47 |
+
" path = '/'.join([path,file_name])\n",
|
48 |
+
" test_response = pd.read_csv(path)\n",
|
49 |
+
" return test_response"
|
50 |
+
]
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"cell_type": "code",
|
54 |
+
"execution_count": 6,
|
55 |
+
"metadata": {},
|
56 |
+
"outputs": [
|
57 |
+
{
|
58 |
+
"name": "stderr",
|
59 |
+
"output_type": "stream",
|
60 |
+
"text": [
|
61 |
+
"Some weights of BertForSequenceClassification were not initialized from the model checkpoint at dmis-lab/biobert-v1.1 and are newly initialized: ['classifier.bias', 'classifier.weight']\n",
|
62 |
+
"You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
|
63 |
+
]
|
64 |
+
}
|
65 |
+
],
|
66 |
+
"source": [
|
67 |
+
"# give the model and corresponfing tokenizer\n",
|
68 |
+
"\n",
|
69 |
+
"# the base models we used are:\n",
|
70 |
+
"# \"emilyalsentzer/Bio_ClinicalBERT\" \n",
|
71 |
+
"# \"dmis-lab/biobert-v1.1\"\n",
|
72 |
+
"# \"microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext\"\n",
|
73 |
+
"# \"allenai/scibert_scivocab_uncased\"\n",
|
74 |
+
"# \"bionlp/bluebert_pubmed_mimic_uncased_L-12_H-768_A-12\"\n",
|
75 |
+
"\n",
|
76 |
+
"# model_name = 'dmis-lab/biobert-v1.1' #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
|
77 |
+
"# model = BertForSequenceClassification.from_pretrained(model_name, num_labels=2)\n",
|
78 |
+
"\n",
|
79 |
+
"# tokenizer_name = 'dmis-lab/biobert-v1.1' #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",
|
80 |
+
"# tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)"
|
81 |
+
]
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"cell_type": "code",
|
85 |
+
"execution_count": 18,
|
86 |
+
"metadata": {},
|
87 |
+
"outputs": [],
|
88 |
+
"source": [
|
89 |
+
"# def tokenize_function(data):\n",
|
90 |
+
"# return tokenizer(data['Question'],data['Answer'],padding='max_length',truncation=True,max_length=128)\n",
|
91 |
+
"\n",
|
92 |
+
"# def compute_metrics(eval_preds):\n",
|
93 |
+
"# metric = evaluate.load(\"accuracy\")\n",
|
94 |
+
"# x,y = eval_preds\n",
|
95 |
+
"# preds = np.argmax(x, -1)\n",
|
96 |
+
"# return metric.compute(predictions=preds, references=y)"
|
97 |
+
]
|
98 |
+
},
|
99 |
+
{
|
100 |
+
"cell_type": "code",
|
101 |
+
"execution_count": 8,
|
102 |
+
"metadata": {},
|
103 |
+
"outputs": [],
|
104 |
+
"source": [
|
105 |
+
"# # add device\n",
|
106 |
+
"# accelerator = Accelerator()\n",
|
107 |
+
"# device = accelerator.device"
|
108 |
+
]
|
109 |
+
},
|
110 |
+
{
|
111 |
+
"cell_type": "code",
|
112 |
+
"execution_count": 9,
|
113 |
+
"metadata": {},
|
114 |
+
"outputs": [],
|
115 |
+
"source": [
|
116 |
+
"# build the model\n",
|
117 |
+
"# trainer = Trainer(\n",
|
118 |
+
"# model=model.to(device),\n",
|
119 |
+
"# # args=training_args,\n",
|
120 |
+
"# # data_collator=data_collator,\n",
|
121 |
+
"# tokenizer=tokenizer,\n",
|
122 |
+
"# compute_metrics=compute_metrics,\n",
|
123 |
+
"# )"
|
124 |
+
]
|
125 |
+
},
|
126 |
+
{
|
127 |
+
"cell_type": "code",
|
128 |
+
"execution_count": 19,
|
129 |
+
"metadata": {},
|
130 |
+
"outputs": [],
|
131 |
+
"source": [
|
132 |
+
"# # dealing with data: from dataframe transform into DatasetDict\n",
|
133 |
+
"# data_set = load_data(path,file_name)\n",
|
134 |
+
"# data_dict = Dataset.from_pandas(data_set)\n",
|
135 |
+
"# data_dict_token = data_dict.map(tokenize_function, batched=8)\n",
|
136 |
+
"# # make prediction\n",
|
137 |
+
"# prediction = trainer.predict(data_dict_token)\n",
|
138 |
+
"# logits = torch.tensor(prediction.predictions)\n",
|
139 |
+
"# prob = torch.softmax(logits,dim=1)\n",
|
140 |
+
"# right_prob = prob[:,1]\n",
|
141 |
+
"# prob_list = right_prob.tolist()\n"
|
142 |
+
]
|
143 |
+
},
|
144 |
+
{
|
145 |
+
"cell_type": "code",
|
146 |
+
"execution_count": 29,
|
147 |
+
"metadata": {},
|
148 |
+
"outputs": [],
|
149 |
+
"source": [
|
150 |
+
"def prob_position(path, file_name, model_name,tokenizer_name):\n",
|
151 |
+
"\n",
|
152 |
+
" # the list of model name:\n",
|
153 |
+
" # the base models we used are:\n",
|
154 |
+
" # \"emilyalsentzer/Bio_ClinicalBERT\" \n",
|
155 |
+
" # \"dmis-lab/biobert-v1.1\"\n",
|
156 |
+
" # \"microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext\"\n",
|
157 |
+
" # \"allenai/scibert_scivocab_uncased\"\n",
|
158 |
+
" # \"bionlp/bluebert_pubmed_mimic_uncased_L-12_H-768_A-12\"\n",
|
159 |
+
"\n",
|
160 |
+
" model = BertForSequenceClassification.from_pretrained(model_name, num_labels=2)\n",
|
161 |
+
" tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)\n",
|
162 |
+
"\n",
|
163 |
+
" # define the tokenizing map and the metrics\n",
|
164 |
+
" def tokenize_function(data):\n",
|
165 |
+
" return tokenizer(data['Question'],data['Answer'],padding='max_length',truncation=True,max_length=128)\n",
|
166 |
+
" def compute_metrics(eval_preds):\n",
|
167 |
+
" metric = evaluate.load(\"accuracy\")\n",
|
168 |
+
" x,y = eval_preds\n",
|
169 |
+
" preds = np.argmax(x, -1)\n",
|
170 |
+
" return metric.compute(predictions=preds, references=y)\n",
|
171 |
+
"\n",
|
172 |
+
" # add device\n",
|
173 |
+
" accelerator = Accelerator()\n",
|
174 |
+
" device = accelerator.device\n",
|
175 |
+
"\n",
|
176 |
+
" # build trainer\n",
|
177 |
+
" trainer = Trainer(\n",
|
178 |
+
" model=model.to(device),\n",
|
179 |
+
" # args=training_args,\n",
|
180 |
+
" # data_collator=data_collator,\n",
|
181 |
+
" tokenizer=tokenizer,\n",
|
182 |
+
" compute_metrics=compute_metrics,\n",
|
183 |
+
" )\n",
|
184 |
+
"\n",
|
185 |
+
" # dealing with data: from dataframe transform into DatasetDict\n",
|
186 |
+
" data_set = load_data(path,file_name)\n",
|
187 |
+
" data_dict = Dataset.from_pandas(data_set)\n",
|
188 |
+
" data_dict_token = data_dict.map(tokenize_function, batched=8)\n",
|
189 |
+
" \n",
|
190 |
+
" # make prediction\n",
|
191 |
+
" prediction = trainer.predict(data_dict_token)\n",
|
192 |
+
"\n",
|
193 |
+
" # transform it into probability\n",
|
194 |
+
" logits = torch.tensor(prediction.predictions)\n",
|
195 |
+
" prob = torch.softmax(logits,dim=1)\n",
|
196 |
+
"\n",
|
197 |
+
" # the probability the answer is correct\n",
|
198 |
+
" right_prob = prob[:,1]\n",
|
199 |
+
" prob_list = right_prob.tolist()\n",
|
200 |
+
"\n",
|
201 |
+
" max_value = max(prob_list)\n",
|
202 |
+
" max_index = prob_list.index(max_value) + 1\n",
|
203 |
+
"\n",
|
204 |
+
" print(f'\\n##############RESULT####################\\nThe index of the most proper answer is: {max_index}\\nThe probability it is correct is: {max_value}')\n",
|
205 |
+
"\n",
|
206 |
+
" return max_value,max_index"
|
207 |
+
]
|
208 |
+
},
|
209 |
+
{
|
210 |
+
"cell_type": "code",
|
211 |
+
"execution_count": 30,
|
212 |
+
"metadata": {},
|
213 |
+
"outputs": [
|
214 |
+
{
|
215 |
+
"name": "stderr",
|
216 |
+
"output_type": "stream",
|
217 |
+
"text": [
|
218 |
+
"loading configuration file config.json from cache at C:\\Users\\cxz55/.cache\\huggingface\\hub\\models--dmis-lab--biobert-v1.1\\snapshots\\551ca18efd7f052c8dfa0b01c94c2a8e68bc5488\\config.json\n",
|
219 |
+
"Model config BertConfig {\n",
|
220 |
+
" \"architectures\": [\n",
|
221 |
+
" \"BertModel\"\n",
|
222 |
+
" ],\n",
|
223 |
+
" \"attention_probs_dropout_prob\": 0.1,\n",
|
224 |
+
" \"classifier_dropout\": null,\n",
|
225 |
+
" \"gradient_checkpointing\": false,\n",
|
226 |
+
" \"hidden_act\": \"gelu\",\n",
|
227 |
+
" \"hidden_dropout_prob\": 0.1,\n",
|
228 |
+
" \"hidden_size\": 768,\n",
|
229 |
+
" \"initializer_range\": 0.02,\n",
|
230 |
+
" \"intermediate_size\": 3072,\n",
|
231 |
+
" \"layer_norm_eps\": 1e-12,\n",
|
232 |
+
" \"max_position_embeddings\": 512,\n",
|
233 |
+
" \"model_type\": \"bert\",\n",
|
234 |
+
" \"num_attention_heads\": 12,\n",
|
235 |
+
" \"num_hidden_layers\": 12,\n",
|
236 |
+
" \"pad_token_id\": 0,\n",
|
237 |
+
" \"position_embedding_type\": \"absolute\",\n",
|
238 |
+
" \"transformers_version\": \"4.24.0\",\n",
|
239 |
+
" \"type_vocab_size\": 2,\n",
|
240 |
+
" \"use_cache\": true,\n",
|
241 |
+
" \"vocab_size\": 28996\n",
|
242 |
+
"}\n",
|
243 |
+
"\n",
|
244 |
+
"loading weights file pytorch_model.bin from cache at C:\\Users\\cxz55/.cache\\huggingface\\hub\\models--dmis-lab--biobert-v1.1\\snapshots\\551ca18efd7f052c8dfa0b01c94c2a8e68bc5488\\pytorch_model.bin\n",
|
245 |
+
"All model checkpoint weights were used when initializing BertForSequenceClassification.\n",
|
246 |
+
"\n",
|
247 |
+
"Some weights of BertForSequenceClassification were not initialized from the model checkpoint at dmis-lab/biobert-v1.1 and are newly initialized: ['classifier.bias', 'classifier.weight']\n",
|
248 |
+
"You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n",
|
249 |
+
"loading configuration file config.json from cache at C:\\Users\\cxz55/.cache\\huggingface\\hub\\models--dmis-lab--biobert-v1.1\\snapshots\\551ca18efd7f052c8dfa0b01c94c2a8e68bc5488\\config.json\n",
|
250 |
+
"Model config BertConfig {\n",
|
251 |
+
" \"_name_or_path\": \"dmis-lab/biobert-v1.1\",\n",
|
252 |
+
" \"architectures\": [\n",
|
253 |
+
" \"BertModel\"\n",
|
254 |
+
" ],\n",
|
255 |
+
" \"attention_probs_dropout_prob\": 0.1,\n",
|
256 |
+
" \"classifier_dropout\": null,\n",
|
257 |
+
" \"gradient_checkpointing\": false,\n",
|
258 |
+
" \"hidden_act\": \"gelu\",\n",
|
259 |
+
" \"hidden_dropout_prob\": 0.1,\n",
|
260 |
+
" \"hidden_size\": 768,\n",
|
261 |
+
" \"initializer_range\": 0.02,\n",
|
262 |
+
" \"intermediate_size\": 3072,\n",
|
263 |
+
" \"layer_norm_eps\": 1e-12,\n",
|
264 |
+
" \"max_position_embeddings\": 512,\n",
|
265 |
+
" \"model_type\": \"bert\",\n",
|
266 |
+
" \"num_attention_heads\": 12,\n",
|
267 |
+
" \"num_hidden_layers\": 12,\n",
|
268 |
+
" \"pad_token_id\": 0,\n",
|
269 |
+
" \"position_embedding_type\": \"absolute\",\n",
|
270 |
+
" \"transformers_version\": \"4.24.0\",\n",
|
271 |
+
" \"type_vocab_size\": 2,\n",
|
272 |
+
" \"use_cache\": true,\n",
|
273 |
+
" \"vocab_size\": 28996\n",
|
274 |
+
"}\n",
|
275 |
+
"\n",
|
276 |
+
"loading file vocab.txt from cache at C:\\Users\\cxz55/.cache\\huggingface\\hub\\models--dmis-lab--biobert-v1.1\\snapshots\\551ca18efd7f052c8dfa0b01c94c2a8e68bc5488\\vocab.txt\n",
|
277 |
+
"loading file tokenizer.json from cache at None\n",
|
278 |
+
"loading file added_tokens.json from cache at None\n",
|
279 |
+
"loading file special_tokens_map.json from cache at C:\\Users\\cxz55/.cache\\huggingface\\hub\\models--dmis-lab--biobert-v1.1\\snapshots\\551ca18efd7f052c8dfa0b01c94c2a8e68bc5488\\special_tokens_map.json\n",
|
280 |
+
"loading file tokenizer_config.json from cache at C:\\Users\\cxz55/.cache\\huggingface\\hub\\models--dmis-lab--biobert-v1.1\\snapshots\\551ca18efd7f052c8dfa0b01c94c2a8e68bc5488\\tokenizer_config.json\n",
|
281 |
+
"loading configuration file config.json from cache at C:\\Users\\cxz55/.cache\\huggingface\\hub\\models--dmis-lab--biobert-v1.1\\snapshots\\551ca18efd7f052c8dfa0b01c94c2a8e68bc5488\\config.json\n",
|
282 |
+
"Model config BertConfig {\n",
|
283 |
+
" \"_name_or_path\": \"dmis-lab/biobert-v1.1\",\n",
|
284 |
+
" \"architectures\": [\n",
|
285 |
+
" \"BertModel\"\n",
|
286 |
+
" ],\n",
|
287 |
+
" \"attention_probs_dropout_prob\": 0.1,\n",
|
288 |
+
" \"classifier_dropout\": null,\n",
|
289 |
+
" \"gradient_checkpointing\": false,\n",
|
290 |
+
" \"hidden_act\": \"gelu\",\n",
|
291 |
+
" \"hidden_dropout_prob\": 0.1,\n",
|
292 |
+
" \"hidden_size\": 768,\n",
|
293 |
+
" \"initializer_range\": 0.02,\n",
|
294 |
+
" \"intermediate_size\": 3072,\n",
|
295 |
+
" \"layer_norm_eps\": 1e-12,\n",
|
296 |
+
" \"max_position_embeddings\": 512,\n",
|
297 |
+
" \"model_type\": \"bert\",\n",
|
298 |
+
" \"num_attention_heads\": 12,\n",
|
299 |
+
" \"num_hidden_layers\": 12,\n",
|
300 |
+
" \"pad_token_id\": 0,\n",
|
301 |
+
" \"position_embedding_type\": \"absolute\",\n",
|
302 |
+
" \"transformers_version\": \"4.24.0\",\n",
|
303 |
+
" \"type_vocab_size\": 2,\n",
|
304 |
+
" \"use_cache\": true,\n",
|
305 |
+
" \"vocab_size\": 28996\n",
|
306 |
+
"}\n",
|
307 |
+
"\n",
|
308 |
+
"loading configuration file config.json from cache at C:\\Users\\cxz55/.cache\\huggingface\\hub\\models--dmis-lab--biobert-v1.1\\snapshots\\551ca18efd7f052c8dfa0b01c94c2a8e68bc5488\\config.json\n",
|
309 |
+
"Model config BertConfig {\n",
|
310 |
+
" \"_name_or_path\": \"dmis-lab/biobert-v1.1\",\n",
|
311 |
+
" \"architectures\": [\n",
|
312 |
+
" \"BertModel\"\n",
|
313 |
+
" ],\n",
|
314 |
+
" \"attention_probs_dropout_prob\": 0.1,\n",
|
315 |
+
" \"classifier_dropout\": null,\n",
|
316 |
+
" \"gradient_checkpointing\": false,\n",
|
317 |
+
" \"hidden_act\": \"gelu\",\n",
|
318 |
+
" \"hidden_dropout_prob\": 0.1,\n",
|
319 |
+
" \"hidden_size\": 768,\n",
|
320 |
+
" \"initializer_range\": 0.02,\n",
|
321 |
+
" \"intermediate_size\": 3072,\n",
|
322 |
+
" \"layer_norm_eps\": 1e-12,\n",
|
323 |
+
" \"max_position_embeddings\": 512,\n",
|
324 |
+
" \"model_type\": \"bert\",\n",
|
325 |
+
" \"num_attention_heads\": 12,\n",
|
326 |
+
" \"num_hidden_layers\": 12,\n",
|
327 |
+
" \"pad_token_id\": 0,\n",
|
328 |
+
" \"position_embedding_type\": \"absolute\",\n",
|
329 |
+
" \"transformers_version\": \"4.24.0\",\n",
|
330 |
+
" \"type_vocab_size\": 2,\n",
|
331 |
+
" \"use_cache\": true,\n",
|
332 |
+
" \"vocab_size\": 28996\n",
|
333 |
+
"}\n",
|
334 |
+
"\n",
|
335 |
+
"No `TrainingArguments` passed, using `output_dir=tmp_trainer`.\n",
|
336 |
+
"PyTorch: setting up devices\n",
|
337 |
+
"The default value for the training argument `--report_to` will change in v5 (from all installed integrations to none). In v5, you will need to use `--report_to all` to get the same behavior as now. You should start updating your code and make this info disappear :-).\n",
|
338 |
+
"The following columns in the test set don't have a corresponding argument in `BertForSequenceClassification.forward` and have been ignored: Unnamed: 0, Context, Label, Question, Answer. If Unnamed: 0, Context, Label, Question, Answer are not expected by `BertForSequenceClassification.forward`, you can safely ignore this message.\n",
|
339 |
+
"***** Running Prediction *****\n",
|
340 |
+
" Num examples = 300\n",
|
341 |
+
" Batch size = 8\n",
|
342 |
+
"You're using a BertTokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.\n",
|
343 |
+
"100%|ββββββββββ| 38/38 [00:01<00:00, 25.79it/s]"
|
344 |
+
]
|
345 |
+
},
|
346 |
+
{
|
347 |
+
"name": "stdout",
|
348 |
+
"output_type": "stream",
|
349 |
+
"text": [
|
350 |
+
"\n",
|
351 |
+
"##############RESULT####################\n",
|
352 |
+
"The index of the most proper answer is: 54\n",
|
353 |
+
"The probability it is correct is: 0.6013683676719666\n"
|
354 |
+
]
|
355 |
+
},
|
356 |
+
{
|
357 |
+
"name": "stderr",
|
358 |
+
"output_type": "stream",
|
359 |
+
"text": [
|
360 |
+
"\n"
|
361 |
+
]
|
362 |
+
},
|
363 |
+
{
|
364 |
+
"data": {
|
365 |
+
"text/plain": [
|
366 |
+
"(0.6013683676719666, 54)"
|
367 |
+
]
|
368 |
+
},
|
369 |
+
"execution_count": 30,
|
370 |
+
"metadata": {},
|
371 |
+
"output_type": "execute_result"
|
372 |
+
}
|
373 |
+
],
|
374 |
+
"source": [
|
375 |
+
"prob_position(path,file_name,\"dmis-lab/biobert-v1.1\",\"dmis-lab/biobert-v1.1\")"
|
376 |
+
]
|
377 |
+
}
|
378 |
+
],
|
379 |
+
"metadata": {
|
380 |
+
"kernelspec": {
|
381 |
+
"display_name": "pytorch",
|
382 |
+
"language": "python",
|
383 |
+
"name": "python3"
|
384 |
+
},
|
385 |
+
"language_info": {
|
386 |
+
"codemirror_mode": {
|
387 |
+
"name": "ipython",
|
388 |
+
"version": 3
|
389 |
+
},
|
390 |
+
"file_extension": ".py",
|
391 |
+
"mimetype": "text/x-python",
|
392 |
+
"name": "python",
|
393 |
+
"nbconvert_exporter": "python",
|
394 |
+
"pygments_lexer": "ipython3",
|
395 |
+
"version": "3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]"
|
396 |
+
},
|
397 |
+
"orig_nbformat": 4,
|
398 |
+
"vscode": {
|
399 |
+
"interpreter": {
|
400 |
+
"hash": "9cf8428aa180ee23632ed7df20f7a595edda7c60e668686876baf89d702ea1cf"
|
401 |
+
}
|
402 |
+
}
|
403 |
+
},
|
404 |
+
"nbformat": 4,
|
405 |
+
"nbformat_minor": 2
|
406 |
+
}
|
scibertALL_2epoch/config.json
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "allenai/scibert_scivocab_uncased",
|
3 |
+
"architectures": [
|
4 |
+
"BertForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.1,
|
10 |
+
"hidden_size": 768,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"intermediate_size": 3072,
|
13 |
+
"layer_norm_eps": 1e-12,
|
14 |
+
"max_position_embeddings": 512,
|
15 |
+
"model_type": "bert",
|
16 |
+
"num_attention_heads": 12,
|
17 |
+
"num_hidden_layers": 12,
|
18 |
+
"pad_token_id": 0,
|
19 |
+
"position_embedding_type": "absolute",
|
20 |
+
"problem_type": "single_label_classification",
|
21 |
+
"torch_dtype": "float32",
|
22 |
+
"transformers_version": "4.24.0",
|
23 |
+
"type_vocab_size": 2,
|
24 |
+
"use_cache": true,
|
25 |
+
"vocab_size": 31090
|
26 |
+
}
|
scibertALL_2epoch/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:861ed4e280274cc8cfddc100a4b77a755a7d9b9f7567c26a38eac8d5648a0c46
|
3 |
+
size 439751021
|
scibertALL_2epoch/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2ceac58d3a6093ccf62847cb3bcd606ae1d98eac1594624c7b8a81c4f324d251
|
3 |
+
size 3375
|