Skip to content

Commit 0e91d94

Browse files
authored
Merge branch 'main' into main
2 parents e99e931 + be54dee commit 0e91d94

File tree

4 files changed

+296
-34
lines changed

4 files changed

+296
-34
lines changed

BertScore_func.ipynb

+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 34,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
" C 드라이브의 볼륨에는 이름이 없습니다.\n",
13+
" 볼륨 일련 번호: FA0B-B857\n",
14+
"\n",
15+
" C:\\Users\\308_2\\jongeun 디렉터리\n",
16+
"\n",
17+
"2020-12-29 오후 10:27 <DIR> .\n",
18+
"2020-12-29 오후 10:27 <DIR> ..\n",
19+
"2020-12-29 오후 10:01 <DIR> .ipynb_checkpoints\n",
20+
"2020-12-29 오후 10:27 142,011 bert_score_test.ipynb\n",
21+
"2020-11-26 오후 11:39 <DIR> KoBERTScore\n",
22+
"2020-12-25 오후 04:02 <DIR> KoGPT2-FineTuning_test_dataset\n",
23+
"2020-12-25 오후 04:10 <DIR> KoGPT2-FineTuning_test_dataset2\n",
24+
"2020-12-29 오후 03:50 332,270 result2.csv\n",
25+
"2020-12-29 오후 09:31 8,805 Untitled.ipynb\n",
26+
" 3개 파일 483,086 바이트\n",
27+
" 6개 디렉터리 44,042,088,448 바이트 남음\n"
28+
]
29+
}
30+
],
31+
"source": [
32+
"!cd .."
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 35,
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"import pandas as pd\n",
42+
"data = pd.read_csv('result182.csv')"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": 36,
48+
"metadata": {},
49+
"outputs": [
50+
{
51+
"data": {
52+
"text/html": [
53+
"<div>\n",
54+
"<style scoped>\n",
55+
" .dataframe tbody tr th:only-of-type {\n",
56+
" vertical-align: middle;\n",
57+
" }\n",
58+
"\n",
59+
" .dataframe tbody tr th {\n",
60+
" vertical-align: top;\n",
61+
" }\n",
62+
"\n",
63+
" .dataframe thead th {\n",
64+
" text-align: right;\n",
65+
" }\n",
66+
"</style>\n",
67+
"<table border=\"1\" class=\"dataframe\">\n",
68+
" <thead>\n",
69+
" <tr style=\"text-align: right;\">\n",
70+
" <th></th>\n",
71+
" <th>lyrics</th>\n",
72+
" <th>bigram+low</th>\n",
73+
" <th>bigram+mid</th>\n",
74+
" <th>bigram+high</th>\n",
75+
" <th>trigram+low</th>\n",
76+
" <th>trigram+mid</th>\n",
77+
" <th>trigram+high</th>\n",
78+
" </tr>\n",
79+
" </thead>\n",
80+
" <tbody>\n",
81+
" <tr>\n",
82+
" <th>0</th>\n",
83+
" <td>우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다.</td>\n",
84+
" <td>우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다.</td>\n",
85+
" <td>우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다.</td>\n",
86+
" <td>우리는 지난 힘들었던 일을 빼곡히 편지지에 적은 다음해들을 만나본다.</td>\n",
87+
" <td>우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다.</td>\n",
88+
" <td>우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다.</td>\n",
89+
" <td>우리는 지난 힘들었던 일들을 빼곡히 편지지에 적어봐.</td>\n",
90+
" </tr>\n",
91+
" <tr>\n",
92+
" <th>1</th>\n",
93+
" <td>나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다.</td>\n",
94+
" <td>나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다.</td>\n",
95+
" <td>나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다.</td>\n",
96+
" <td>나는 매섭게 부는 바람에 흔들리는 강아지에 빗맞은 눈물을 찍어 사진을 찍고 있다.</td>\n",
97+
" <td>나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다.</td>\n",
98+
" <td>나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다.</td>\n",
99+
" <td>나는 매섭게 부는 바람과 훈훈함을 알아 차릴 것이다.</td>\n",
100+
" </tr>\n",
101+
" </tbody>\n",
102+
"</table>\n",
103+
"</div>"
104+
],
105+
"text/plain": [
106+
" lyrics \\\n",
107+
"0 우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다. \n",
108+
"1 나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다. \n",
109+
"\n",
110+
" bigram+low \\\n",
111+
"0 우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다. \n",
112+
"1 나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다. \n",
113+
"\n",
114+
" bigram+mid \\\n",
115+
"0 우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다. \n",
116+
"1 나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다. \n",
117+
"\n",
118+
" bigram+high \\\n",
119+
"0 우리는 지난 힘들었던 일을 빼곡히 편지지에 적은 다음해들을 만나본다. \n",
120+
"1 나는 매섭게 부는 바람에 흔들리는 강아지에 빗맞은 눈물을 찍어 사진을 찍고 있다. \n",
121+
"\n",
122+
" trigram+low \\\n",
123+
"0 우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다. \n",
124+
"1 나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다. \n",
125+
"\n",
126+
" trigram+mid trigram+high \n",
127+
"0 우리는 지난 힘들었던 일을 빼곡히 편지지에 적어본다. 우리는 지난 힘들었던 일들을 빼곡히 편지지에 적어봐. \n",
128+
"1 나는 매섭게 부는 바람에 흩날리는 잎파리를 보며 머리 속의 고민들을 날려보낸다. 나는 매섭게 부는 바람과 훈훈함을 알아 차릴 것이다. "
129+
]
130+
},
131+
"execution_count": 36,
132+
"metadata": {},
133+
"output_type": "execute_result"
134+
}
135+
],
136+
"source": [
137+
"data.head(2)"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": 44,
143+
"metadata": {},
144+
"outputs": [],
145+
"source": [
146+
"import numpy as np\n",
147+
"#reference 문장과 candidate 문장 컬럼 가져오기 \n",
148+
"reference_raw = np.asarray(data[['lyrics']])\n",
149+
"candidate_raw = np.asarray(data[['trigram+high']])"
150+
]
151+
},
152+
{
153+
"cell_type": "code",
154+
"execution_count": 51,
155+
"metadata": {},
156+
"outputs": [
157+
{
158+
"name": "stdout",
159+
"output_type": "stream",
160+
"text": [
161+
"Load beomi/kcbert-base with 4 layers\n"
162+
]
163+
}
164+
],
165+
"source": [
166+
"from KoBERTScore import BERTScore\n",
167+
"#from bokeh.plotting import show\n",
168+
"model_name = \"beomi/kcbert-base\"\n",
169+
"bertscore = BERTScore(model_name, best_layer=4)\n",
170+
"bs = []\n",
171+
"\n",
172+
"def bertScore(r,c):\n",
173+
" reference = []\n",
174+
" candidate = []\n",
175+
" for i in range(len(r)):\n",
176+
" reference.append(r[i][0])\n",
177+
" candidate.append(c[i][0])\n",
178+
" bs.append(bertscore(reference, candidate, batch_size=64))"
179+
]
180+
},
181+
{
182+
"cell_type": "code",
183+
"execution_count": 52,
184+
"metadata": {},
185+
"outputs": [
186+
{
187+
"name": "stderr",
188+
"output_type": "stream",
189+
"text": [
190+
"Calculating BERTScore: 0%| | 0/4 [00:00<?, ?it/s]\n",
191+
"Train IDF: 1it [00:00, 38.52it/s]\n",
192+
"Calculating BERTScore: 100%|█████████████████████████████████████████████████████████████| 4/4 [00:00<00:00, 13.46it/s]\n"
193+
]
194+
}
195+
],
196+
"source": [
197+
"bertScore(reference_raw, candidate_raw)\n",
198+
"#print(candidate)"
199+
]
200+
},
201+
{
202+
"cell_type": "code",
203+
"execution_count": 69,
204+
"metadata": {},
205+
"outputs": [],
206+
"source": [
207+
"import csv \n",
208+
"#reference 문장과 candidate 문장m bleu score csv저장\n",
209+
"bs_list = np.asarray(bs[0])\n",
210+
"row_list=[]\n",
211+
"row_list.append([\"reference\",\"candidate\",\"bert score\"])\n",
212+
"for i in range(len(reference_raw)):\n",
213+
" row_list.append([reference_raw[i][0], candidate_raw[i][0], bs_list[i]])\n",
214+
"\n",
215+
"with open('bertscore_tri+high.csv', 'w', newline='') as file:\n",
216+
" writer = csv.writer(file)\n",
217+
" writer.writerows(row_list)"
218+
]
219+
},
220+
{
221+
"cell_type": "code",
222+
"execution_count": null,
223+
"metadata": {},
224+
"outputs": [],
225+
"source": []
226+
}
227+
],
228+
"metadata": {
229+
"kernelspec": {
230+
"display_name": "joanne",
231+
"language": "python",
232+
"name": "joanne"
233+
},
234+
"language_info": {
235+
"codemirror_mode": {
236+
"name": "ipython",
237+
"version": 3
238+
},
239+
"file_extension": ".py",
240+
"mimetype": "text/x-python",
241+
"name": "python",
242+
"nbconvert_exporter": "python",
243+
"pygments_lexer": "ipython3",
244+
"version": "3.6.12"
245+
}
246+
},
247+
"nbformat": 4,
248+
"nbformat_minor": 4
249+
}

0 commit comments

Comments
 (0)