forked from thiagorossener/jekflix-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
611 lines (315 loc) ยท 273 KB
/
atom.xml
File metadata and controls
611 lines (315 loc) ยท 273 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>EmjayAhn, DataScienceBook</title>
<link>https://emjayahn.github.io/</link>
<atom:link href="https://emjayahn.github.io/atom.xml" rel="self" type="application/rss+xml"/>
<description></description>
<pubDate>Wed, 26 Mar 2025 12:51:48 GMT</pubDate>
<generator>http://hexo.io/</generator>
<item>
<title>DeepSeek-V3 Technical Report ์ ๋ฆฌ</title>
<link>https://emjayahn.github.io/2025/03/24/DeepSeek-V3-Technical-Report-%EC%A0%95%EB%A6%AC/</link>
<guid>https://emjayahn.github.io/2025/03/24/DeepSeek-V3-Technical-Report-%EC%A0%95%EB%A6%AC/</guid>
<pubDate>Mon, 24 Mar 2025 14:58:55 GMT</pubDate>
<description><p>๋
ผ๋ฌธ DeepSeek-V3 Technical Report๋ฅผ ์ฝ๊ณ ์ฃผ์ contribution ๋ด์ฉ๊ณผ ๊ฐ์ธ์ ์ผ๋ก ๊ผญ ๊ธฐ์ตํ ๋ด์ฉ์ ์์ฝํ์ฌ ์ ๋ฆฌํด๋ณธ๋ค.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>๋
ผ๋ฌธ DeepSeek-V3 Technical Report๋ฅผ ์ฝ๊ณ ์ฃผ์ contribution ๋ด์ฉ๊ณผ ๊ฐ์ธ์ ์ผ๋ก ๊ผญ ๊ธฐ์ตํ ๋ด์ฉ์ ์์ฝํ์ฌ ์ ๋ฆฌํด๋ณธ๋ค.</p><span id="more"></span><h2 id="1-Introduction"><a href="#1-Introduction" class="headerlink" title="1. Introduction"></a>1. Introduction</h2><ul><li><p>Open Source ๋ชจ๋ธ, DeepSeek ์๋ฆฌ์ฆ, LLaMA ์๋ฆฌ์ฆ, Qwen ์๋ฆฌ์ฆ, Mistral ์๋ฆฌ์ฆ ๋ฑ ์คํ์์ค ๋ชจ๋ธ๊ณผ ๋น๊ณต๊ฐ ์์ค ๋ชจ๋ธ๋ค๊ณผ์ ๊ฒฉ์ฐจ๋ฅผ ์ค์ด๊ธฐ ์ํด ๋
ธ๋ ฅ์ค</p><ul><li>๋ณธ ๋
ผ๋ฌธ์์๋ ์คํ์์ค ๋ชจ๋ธ์ ๋์ฑ ํ์ฅํ๊ธฐ ์ํด ๋ชจ๋ธ ํฌ๊ธฐ ํ์ฅ (Scale up)ํ๊ณ , Mixture-of-Experts๋ฅผ ๋์
ํ๋ค.</li><li>Deepseek V3๋ ์ด 6710์ต(671B)๊ฐ์ ํ๋ผ๋ฏธํฐ๋ฅผ ๊ฐ์ง๊ณ ์์ผ๋ฉฐ, ๊ทธ ์ค 370์ต(37B) ๊ฐ๊ฐ ๊ฐ ํ ํฐ์ ๋ํด ํ์ฑํ ๋๋ค.</li></ul></li><li><p>์ฑ๋ฅ ํฅ์๋ ์ค์ํ์ง๋ง, ๋ชจ๋ธ ์ฑ๋ฅ๊ณผ ๊ฒฝ์ ์ ์ธ ๋น์ฉ์ ๋์์ ์ถ๊ตฌํ๊ณ ์๋ค.</p><ul><li>์ด๋ฅผ ์ํด ์ํคํ
์ณ ์ ์ผ๋ก,</li><li>ํจ์จ์ ์ธ ์ถ๋ก ์ ์ํด Multi-head Latent Attention (MLA) ๊ตฌ์กฐ๋ฅผ ์ฑํํ๊ณ </li><li>๋น์ฉ ํจ์จ์ ์ธ ํ์ต์ ์ํด DeepSeekMoE ๊ตฌ์กฐ๋ฅผ ์ฑํํ๊ณ ์๋ค.</li><li>์ด ๋๊ฐ์ง ์ํคํ
์ฒ๋ ์ด๋ฏธ DeepSeek V2์์ ๊ฒ์ฆ ๋์์</li><li>์ฌ๊ธฐ์ ๋ ๊ฐ์ง ์ถ๊ฐ ์ ๋ต์ ๋์
ํด V3๊ฐ ๋์ด<ul><li>Auxiliary Loss (๋ณด์กฐ ์์ค)์ด ์๋ ๋ถํ ๋ถ์ฐ ์ ๋ต (Auxiliary-loss-free load balancing)์ ์ ์ฉ - ๋ถํ ๋ถ์ฐ์ ์ ๋ํ๋ ๊ณผ์ ์์ ๋ฐ์ํ ์ ์๋ ๋ชจ๋ธ ์ฑ๋ฅ ์ ํ๋ฅผ ์ต์ํ ํ๋ ๊ฒ์ ๋ชฉํ๋กํจ<ul><li><strong>(์ถ๊ฐ์ค๋ช
)</strong> ์ผ๋ฐ์ ์ผ๋ก MoE์์๋ ๋ชจ๋ Expert๋ค์ ์์
์ ๊ณ ๋ฅด๊ฒ ๋ถ๋ฐฐํ๊ธฐ ์ํด ๋ณด์กฐ ์์ค์ ์ถ๊ฐํ์ง๋ง, ์ด๋ก ์ธํด ์ฑ๋ฅ ์ ํ ํ์์ด ์์๋ค. V3์์๋ ์ด๋ฌํ ๋ณด์กฐ ์์ค ์์ด๋ ๋ถํ ๋ถ์ฐ์ ๋ฌ์ฑํ๋ ค๋ ์๋ก์ด ์ ๋ต์ ์๋ํ๋ ๊ฒ</li></ul></li><li>Multi-token ์์ธก์ ํ์ต ๋ชฉํ๋ก ์ฌ์ฉ - ์ฌ๋ฌ ๋ฒค์น๋งํฌ์์ ์ ๋ฐ์ ์ธ ์ฑ๋ฅ ํฅ์ ๊ด์ธก<ul><li><strong>(์ถ๊ฐ์ค๋ช
)</strong> ํ ๋ฒ์ ํ๋์ ๋ค์ ๋จ์ด๋ฅผ ์์ธกํ๋ ๋ฐฉ์์ด ์๋๋ผ, ์ฌ๋ฌ ๊ฐ์ ํ ํฐ์ ๋์์ ์์ธกํ๋๋ก ํ์ต์ํค๋ ๋ฐฉ์. ์ด ๋ฐฉ๋ฒ์ ํตํด ๋ ๋น ๋ฅด๊ณ ์ ํํ ๋ฌธ์ฅ ์์ฑ์ ๊ฐ๋ฅํ๊ฒ ํ๋ฉฐ, ๊ฒฐ๊ตญ ์ ์ฒด์ ์ธ ์ฑ๋ฅ ํฅ์ (๋ฒค์น๋งํฌ ๋น๊ต)์ ๊ธฐ์ฌ</li></ul></li></ul></li></ul></li><li><p>ํจ์จ์ ์ธ ํ์ต์ ์ํด, FP8 mixed precision training์ ์ํํ๊ณ , ํ์ต ํ๋ ์์ํฌ ์ ๋ฐ์ ๊ฑธ์ณ ์ต์ ํ๋ฅผ ์ํ</p><ul><li>low -precision training์ ํจ์จ์ ์ธ ํ์ต์ ์ํด ์ข์ ํด๊ฒฐ์ฑ
์ผ๋ก ๋จ๊ณ ์์ผ๋ฉฐ, ์ด๋ ํ๋์จ์ด ์ฑ๋ฅ ํฅ์๊ณผ ๋ฐ์ ํ ๊ด๋ จ์ด ์์</li><li>V3์์๋ FP8 mixed precision ํ์ต ํ๋ ์์ํฌ๋ฅผ ๋์
ํ์๊ณ , ์ด๋ฅผ ์ด๊ฑฐ๋ ๋ชจ๋ธ์ ์ฒ์์ผ๋ก ์ ์ฉํ์ฌ ๊ทธ ํจ์จ์ฑ์ ์
์ฆํ์์.</li><li>FP8 ์ฐ์ฐ ๋ฐ ์ ์ฅ์ ์ง์ํจ์ผ๋ก์จ, ์ด๋ ํ์ต ์๋๋ฅผ ํฅ์์ํค๊ณ , ์ ์์์ GPU ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ํ์ต์ ์ํค๋๋ฐ ์ฑ๊ณตํ์์<ul><li><strong>(์ถ๊ฐ์ค๋ช
)</strong> FP8, FP16, BF16์ ๋ถ๋์์์ (Floating Point) ์ซ์๋ฅผ ํํํ๋ ๋ฐฉ์์ด๋ค. CS ๋ด์ฉ์ด์ง๋ง, ๊ฐ๋จํ๊ฒ ์ค๋ช
ํ๋ฉด<ul><li>FP 16<ul><li>FP 16์ ๊ตฌ์ฑ์ ์ด์ ๊ฐ๋ค. 1๋นํธ ๋ถํธ + 5๋นํธ ์ง์ + 10๋นํธ ๊ฐ์ = ์ด 16๋นํธ - ๊ฐ์ (์์ ๋ถ๋ถ์ ๋ปํ๋๊ฑฐ์์)</li><li>๊ธฐ์กด์ FP32์ ๋นํด ํํํ ์ ์๋ ์์ ๋ฒ์๊ฐ ์๋ค. ์์ ๋ฒ์๊ฐ ์๊ฒ ๋๋ฉด, ์ ๋ฐ๋(precision)๊ฐ ๋ฎ๋ค๊ณ ํํํ๋๋ฐ ์ด๋ ๋งค์ฐ ์์ ์๋ ๋งค์ฐ ํฐ ์๋ฅผ ์ ํํ๊ฒ ํํํ ์ ์๋ค๋ ๋ป์ด๋ค. ์ด๋ฐ ๊ฒ์ underflow (๋งค์ฐ ์์์) / overflow(๋งค์ฐ ํฐ์)ํ์์ด๋ผ๊ณ ํ๋ค.</li></ul></li><li>BF 16 (brain float 16)<ul><li>๊ตฌ์ฑ : 1๋นํธ ๋ถํธ + 8๋นํธ ์ง์ + 7 ๋นํธ ๊ฐ์ = ์ด 16๋นํธ</li><li>๊ตฌ๊ธ์์ ๊ฐ๋ฐํ๋๋ฐ, ๋ด๋ด ๋คํธ์ํฌ ํ์ต ๋ชฉ์ ์ผ๋ก ๋ง๋ ์๋ก์ด ์๋ฃํ์ด๋ค. ๋ชฉ์ ์ ์ง์ ๋นํธ์ ์๋ฅผ ํค์์ ์์ ํํ๋ฒ์๊ฐ FP32์ ๋์ผํ๊ฒ ๋ง๋๋ ค๊ณ ํ๋ ๊ฒ์ด๋ค.</li><li>๊ธฐ์กด์ FP 16์ ๋นํด ๊ฐ์ ๋นํธ์๋ฅผ ์ฌ์ฉํ๋ฉด์๋, ์์ ๋ฒ์๋ FP32์ ๊ฐ์ ์ซ์๋ฅผ ํํํ๊ธฐ ๋๋ฌธ์ ๋ ์ข์ ํํ๋ ฅ์ ๊ฐ์ง๊ณ ์์.</li><li>๋จ์ ์ผ๋ก๋ ๊ฐ์๊ฐ ์ ์ด์ ์ ๋ฐ๋๋ FP16์ ๋นํด ๋ฎ๋ค๊ณ ์๊ฐํ ์ ์์ง๋ง ์ค์ ์ฌ์ฉ์์๋ ํฐ ๋ฌธ์ ๊ฐ ์์</li></ul></li><li>FP 8<ul><li>1๋นํธ ๋ถํธ + 4๋นํธ ์ง์ + 3๋นํธ ๊ฐ์</li><li>๋น์ฐํ ์์ ๋ฒ์๊ฐ ์์ง๋ง ๋ฉ๋ชจ๋ฆฌ๋ ์ ๊ฒ ์ฐจ์งํ๋ ์ฅ์ ์ด ์์ง๋ง, ๋ด๋ด๋คํธ์ํฌ์์ ํด๋น ์ซ์๋ก ํํํ๋ฉด ๋๋ฌด ์์ด๋ฒ๋ฆฌ๋ ์ ๋ณด๊ฐ ๋ง์ด ์์</li><li>๊ทธ๋์ ์ด ๋
ผ๋ฌธ V3๊ฐ ์ฃผ์ฅํ๋ ๊ฒ์ FP8๋ก ํ์ต์์ผ๋ ์ถฉ๋ถํ๊ฒ ํํํ ์ ์๋ ๋ฐฉ๋ฒ์ ์ ์ํ๋ ๊ฒ์.</li></ul></li></ul></li></ul></li></ul></li><li><p>์ฌ์ ํ์ต(pre-training) 14.8์กฐ(14.8T)๊ฐ์ ๊ณ ํ์ง, ๋ค์์ฑ ์๋ ํ ํฐ๋ค๋ก ํ์ต์์ผฐ์</p><ul><li>์ฌ์ ํ์ต ๊ณผ์ ์ ๋งค์ฐ ์์ ์ ์ด์์ : ๋ณต๊ตฌ๋ถ๊ฐ๋ฅํ loss spike (์์ค ๊ธ์ฆ), roll back ํ ์ํฉ์ด ์์์</li><li>๊ทธ ๋ค์์ V3์ context ๊ธธ์ด๋ฅผ ๋ ๋จ๊ณ์ ๊ฑธ์ณ ํ์ฅํ๋ ์์
์ ์ํํ์<ul><li>1๋จ๊ณ : ์ต๋ context ๊ธธ์ด๋ฅผ 32000(32K) ํ ํฐ๊น์ง ํ์ฅ</li><li>2๋จ๊ณ : ์ด๋ฅผ 128000ํ ํฐ(128K)๊น์ง ๋ ํ์ฅํ์์</li></ul></li><li>์ดํ V3 base ๋ชจ๋ธ์ ๊ธฐ๋ฐ์ผ๋ก post-training (ํ์ ํ์ต)์ ์ํ.<ul><li>์ง๋ ํ์ต ๊ธฐ๋ฐ์ ๋ฏธ์ธ์กฐ์ (Supervised Fine Tuning, SFT)</li><li>๊ฐํ ํ์ต (Reinforcement Learning, RL)</li><li>distiliation</li></ul></li><li>์ด Post-training์ ๋ชจ๋ธ์ ์ธ๊ฐ์ ์ ํธ (human preferences)์ ๋ ์ ๋ง์ถ๊ณ , ๋ชจ๋ธ์ ์ ์ฌ๋ ฅ์ ๋์ฑ ๋์ด๋ด๊ธฐ ์ํจ</li><li>ํ์ ํ์ต ๋จ๊ณ์์๋ DeepSeek R1 ์๋ฆฌ์ฆ ๋ชจ๋ธ๋ก๋ถํฐ ์ถ๋ก ๋ฅ๋ ฅ (reasoning capability)์ distillationํ์๊ณ , ๋์์ ๋ชจ๋ธ์ ์ ํ๋์ ์์ฑ๋๋ ์๋ต ๊ธธ์ด ์ฌ์ด์ ๊ท ํ์ ์ ์งํ ์ ์๊ฒํ์๋ค. </li><li><strong>(์ถ๊ฐ์ค๋ช
)</strong> context length extension ์ด๋ context ๊ธธ์ด๋ ๋ชจ๋ธ์ด ํ ๋ฒ์ ์ฒ๋ฆฌํ ์ ์๋ ํ
์คํธ ๊ธธ์ด๋ฅผ ์๋ฏธ. ์๋ฅผ ๋ค์ด GPT 2,3๋ 2000~4000 token ๊ธธ์ด์ด๊ณ , GPT-4 Turbo๋ 128000(128K). (ํ์ธํ์) V3์์ 128K๊น์ง ํ์ฅํ๋ค๋ ๊ฒ์ ๋งค์ฐ ๊ธด ๋ฌธ์๋ฅผ ํ ๋ฒ์ ์ฒ๋ฆฌํ ์ ์๋ค๋ ๋ป</li><li><strong>(์ถ๊ฐ์ค๋ช
)</strong> Post-training SFT๋ ์ ๋ต์ด ์๋ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ ํํ ์๋ต์ ์์ฑํ๋๋ก ๋ฏธ์ธ ์กฐ์ ํ์ต. ๋ณดํต RL ์ด๋ผ๊ณ ํ๋ฉด, RLHF ๋ฅผ ์๋ฏธํ๋๋ฐ ์ฌ๊ธฐ์๋ ๋ค๋ฅธ ์๋ฏธ์ผ ์๋ ์์ (๋ ์ฝ์ด๋ด์ผํจ)</li><li><strong>(์ถ๊ฐ์ค๋ช
)</strong> Distillation ํฐ ๋ชจ๋ธ์ ์ ์๋์ผ๋ก ๋๊ณ ์ ์๋์ ๋ต์ ๋ฐ๋ผํ๋๋ก ์์ ๋ชจ๋ธ์ด ํ์ตํ๋ ๋ฐฉ๋ฒ</li></ul></li><li><p>V3 base ๋ชจ๋ธ์ ์คํ์์ค ๋ชจ๋ธ ์ค ๋ฒค์น๋งํฌ ์ฑ๋ฅ์ด ๊ฐ์ฅ ๋ฐ์ด๋ฌ์ผ๋ฉฐ, ์ฝ๋์ ์ํ ๋ถ์ผ์์ ํนํ ์ข์ ์ฑ๋ฅ์ ๋ณด์์</p><ul><li>V3 chat ๋ฒ์ ์ญ์ ๋ค๋ฅธ ์คํ์์ค ๋ชจ๋ธ๋ณด๋ค ๋ฐ์ด๋ ์ฑ๋ฅ์ ๋ณด์</li><li>GPT-4o, Claude 3.5 Sonnet๊ณผ ๊ฒฌ์ค ์ ์๋ ์ฑ๋ฅ, open-ended ๋ฒค์น๋งํฌ์์ ๋น์ทํ ์ฑ๋ฅ</li></ul></li><li><p>Deepseek V3๋ ํ์ต ๋น์ฉ๋ฉด์์ ๊ฒฝ์ ์ ์์ ๊ฐ์กฐ.</p><ul><li>์ฌ์ ํ์ต (pre-training) ๋จ๊ณ์์, V3๋ฅผ 1์กฐ (1T) ํ ํฐ์ ํ์ต์ํค๋ ๋ฐ 18๋ง(180K) ์๊ฐ์ H800 GPU ์๊ฐ์ด ํ์ํ์</li><li>์ด๋ 2048๊ฐ์ H800 GPU ํด๋ฌ์คํฐ ๊ธฐ์ค 3.7์ผ ๋ง์</li><li>๊ฒฐ๊ณผ์ ์ผ๋ก ์ ์ฒด ์ฌ์ ํ์ต์ ๋ ๋ฌ๋ ์๊ฑธ๋ฆฌ๊ฒ ์๋ฃ๋์์ผ๋ฉฐ, ์ด 266๋ง 4์ฒ (2.664M) GPU ์๊ฐ์ด ์์</li></ul></li><li><p>context length extension์๋ 11๋ง 9์ฒ (119K) GPU ์๊ฐ,</p></li><li><p>post-training์๋ 5์ฒ(5K) GPU ์๊ฐ์ด ๊ฑธ๋ฆผ</p></li><li><p>์ต์ข
์ ์ผ๋ก V3๋ฅผ ํ์ต์ ์์๋ ์ด ์๊ฐ์ 278๋ง 8์ฒ (2.788M) GPU ์๊ฐ</p></li><li><p>H800 GPU ์๋ ๋น์ฉ์ด ์๊ฐ๋น $2๋ก ๊ฐ์ ํ๋ฉด, ์ ์ฒด ํ์ต ๋น์ฉ์ ์ฝ 557๋ง 6์ฒ ๋ฌ๋ฌ ($5.576M)</p><ul><li>์ด ๋น์ฉ์ V3 ํ์ต๋ง ํฌํจ๋ ๊ฒ์ด๋ฉฐ, ์ํคํ
์ฒ, ์๊ณ ๋ฆฌ์ฆ, ๋ฐ์ดํฐ์ ๋ํ ์ฐ๊ตฌ, ์คํ์ ๋๋ ๋น์ฉ์ ํฌํจ๋์ง ์์</li></ul></li><li><p>์ดํ ๋ค๋ฃฐ ๋ด์ฉ</p></li></ul><ol><li>๋จผ์ , DeepSeek-V3 ๋ชจ๋ธ ์ํคํ
์ฒ์ ๋ํ ์์ธํ ์ค๋ช
์ ์ ์ํฉ๋๋ค (2์ฅ).</li><li>์ด์ด์, ์ฐ๋ฆฌ์ ์ธํ๋ผ ๊ตฌ์กฐ๋ฅผ ์๊ฐํฉ๋๋ค. ์ด์๋ ์ปดํจํ
ํด๋ฌ์คํฐ, ํ์ต ํ๋ ์์ํฌ, FP8 ํ์ต ์ง์, ์ถ๋ก ๋ฐฐํฌ ์ ๋ต, ๊ทธ๋ฆฌ๊ณ ๋ฏธ๋ ํ๋์จ์ด ์ค๊ณ์ ๋ํ ์ ์์ด ํฌํจ๋ฉ๋๋ค.</li><li>๋ค์์ผ๋ก, ์ฐ๋ฆฌ์ ์ฌ์ ํ์ต ๊ณผ์ ์ ์ค๋ช
ํฉ๋๋ค.<br>์ฌ๊ธฐ์๋ ํ์ต ๋ฐ์ดํฐ ๊ตฌ์ฑ, ํ์ดํผํ๋ผ๋ฏธํฐ ์ค์ , ๊ธด ๋ฌธ๋งฅ ์ฒ๋ฆฌ ๊ธฐ๋ฒ(long-context extension techniques), ๊ด๋ จ ํ๊ฐ ๋ฐ ๋
ผ์๊ฐ ํฌํจ๋ฉ๋๋ค (4์ฅ).</li><li>๊ทธ ๋ค์์ผ๋ก๋, ํ์ ํ์ต(post-training)์ ๊ดํ ์ค๋ช
์ด ์ด์ด์ง๋๋ค.<br>์ง๋ ๋ฏธ์ธ์กฐ์ (SFT), ๊ฐํ ํ์ต(RL), ๊ทธ์ ๋ฐ๋ฅธ ํ๊ฐ ๋ฐ ๋
ผ์๊ฐ ํฌํจ๋ฉ๋๋ค (5์ฅ).</li><li>๋ง์ง๋ง์ผ๋ก, ์ฐ๋ฆฌ๋ ๋ณธ ์ฐ๊ตฌ๋ฅผ ์ ๋ฆฌ(conclude)ํ๊ณ ,<br>DeepSeek-V3์ ํ์ฌ ํ๊ณ์ ์ ๋ํด ๋
ผ์ํ๋ฉฐ, ํฅํ ์ฐ๊ตฌ๋ฅผ ์ํ ๋ฐฉํฅ์ ์ ์ํฉ๋๋ค (6์ฅ).</li></ol><h2 id="2-Architecture"><a href="#2-Architecture" class="headerlink" title="2. Architecture"></a>2. Architecture</h2><ul><li>DeepSeek-V3 ๊ธฐ๋ณธ ์ํคํ
์ฒ ์๊ฐ<ul><li>ํจ์จ์ ์ธ Inference๋ฅผ ์ํ Multi-head Latent Attention (MLA)</li><li>๊ฒฝ์ ์ ์ธ Training์ ์ํ DeepSeekMoE</li><li>ํ์ต ๋ชฉํ(objective) : Multi-Token Prediction - ์ด๊ฑฐ ํด๋ดค๋๋ ๋ชจ๋ธ ์ฑ๋ฅ์ด ํฅ์๋๋๋ผ</li><li>๊ทธ ์ธ์ ์ค์ ๊ณผ ๊ตฌ์กฐ๋ V2๋ฅผ ๋ฐ๋ฆ</li></ul></li></ul><h3 id="2-1-Basic-Architecture"><a href="#2-1-Basic-Architecture" class="headerlink" title="2.1 Basic Architecture"></a>2.1 Basic Architecture</h3><ul><li>V3 ๊ธฐ๋ณธ unit์ ์ฌ์ ํ Transformer ๊ตฌ์กฐ๋ฅผ ์์ ์ฌ๋ฆฐ ๊ฒ</li><li>๋ค์ ํ๋ฒ ์ ๋ฆฌํ์ง๋ง, MLA์ DeepSeekMoE๋ V2์์ ๊ฒ์ฆ์ด ๋์์, V2์ ๋น๊ตํ์ ๋ ํ ๊ฐ์ง ์์ธ์ ์ธ ์ฐจ์ด์ ์ DeepSeekMoE์์ auxiliary-loss-free (๋ณด์กฐ ์์ค์ด ์๋) ๋ถํ ๋ถ์ฐ ์ ๋ต์ ์๋กญ๊ฒ ๋์
ํ์ฌ, load balance๋ฅผ ๋ง์ถ๋ ๊ณผ์ ์์ ๋ฐ์ํ ์ ์๋ ์ฑ๋ฅ ์ ํ๋ฅผ ์ํํ๊ณ ์ ํ์์<br><img src="/2025/03/24/DeepSeek-V3-Technical-Report-%EC%A0%95%EB%A6%AC/V3_1.png"></li></ul><h4 id="2-1-1-Multi-Head-Latent-Attention"><a href="#2-1-1-Multi-Head-Latent-Attention" class="headerlink" title="2.1.1 Multi-Head Latent Attention"></a>2.1.1 Multi-Head Latent Attention</h4><p>DeepSeek-V3๋ attention ๊ตฌ์กฐ๋ก MLA(Multi-head Latent Attention) ์ํคํ
์ฒ๋ฅผ ์ฑํํฉ๋๋ค.<br>โข $d$๋ ์๋ฒ ๋ฉ ์ฐจ์(embedding dimension),<br>โข $n_h$๋ attention head์ ๊ฐ์,<br>โข $d_h$๋ ๊ฐ head๋น ์ฐจ์,<br>โข $h_t \in \mathbb{R}^d$๋ ํด๋น attention layer์์ t๋ฒ์งธ ํ ํฐ์ ์
๋ ฅ ๋ฒกํฐ๋ฅผ ๋ํ๋
๋๋ค.</p><p>MLA์ ํต์ฌ์ attention key์ value๋ฅผ ์ํ ์ ์ฐจ์(low-rank) joint compression, ์ถ๋ก ์ Key-Value(KV) ์บ์ ์ฌ์ฉ๋์ ์ค์ด๋ ๋ฐ ๋ชฉ์ ์ด ์์ต๋๋ค<br>$$ \begin{aligned} c_{t}^{kv} = W^{DKV}h_{t} \ [k_{t,1}^{c};k_{t,2}^{c};โฆ;k_{t,n_{h}}^{c}]=k_{t}^{c}=W^{UK}c_{t}^{KV}, \ k_{t}^{R} = RoPE(W^{KR}h_{t}), \ k_{t,i} = [k_{t,i}^{C};k_{t}^{R}], \ [v_{t,1}^{C}; v_{t,2}^{C};โฆ;v_{t, n_{h}}^{C}] = v_{t}^{C} = W^{UV}c_{t}^{KV} \end{aligned} $$<br>โข ์ฌ๊ธฐ์ $c_t^{KV} \in \mathbb{R}^{d_c}$๋ key์ value์ ์์ถ๋ ์ ์ฌ ๋ฒกํฐ(latent vector)์
๋๋ค.<br>$d_c$๋ KV ์์ถ ์ฐจ์์ด๋ฉฐ, $d_h \cdot n_h$๋ณด๋ค ํจ์ฌ ์์ต๋๋ค ($d_c \ll d_h n_h$).<br>โข $W^{DKV} \in \mathbb{R}^{d_c \times d}$๋ ์
๋ ฅ ๋ฒกํฐ $h_t$๋ฅผ ์ ์ฐจ์์ผ๋ก ์์ถํ๋ ๋ค์ด ํ๋ก์ ์
ํ๋ ฌ์
๋๋ค.<br>โข $W^{UK}, W^{UV} \in \mathbb{R}^{d_h n_h \times d_c}$๋ ๊ฐ๊ฐ ์์ถ๋ ๋ฒกํฐ๋ฅผ ๋ค์ ํค์ ๋ฐธ๋ฅ๋ก ๋ณต์ํ๋ ์
ํ๋ก์ ์
ํ๋ ฌ์
๋๋ค.<br>โข $W^{KR} \in \mathbb{R}^{d_h^R \times d}$๋ RoPE์ฉ decoupled key๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ๋๋ ํ๋ ฌ์
๋๋ค.<br>โข $\text{RoPE}(\cdot)$๋ Rotary Positional Embedding์ ์ ์ฉํ๋ ์ฐ์ฐ์
๋๋ค.<br>โข $[\cdot ; \cdot]$์ ๋ฒกํฐ ํฉ์น๋ ๊ฒ(concatenation)์ ์๋ฏธํฉ๋๋ค.</p><p> ์ค์ํ ์ : MLA์์๋ ํ๋์ ๋ฐ์ค๋ก ๊ฐ์กฐ๋ ๋ฒกํฐ($c_t^{KV}$์ $k_t^R$)๋ง์ ์์ฑ ์ค์ ์บ์(cache)ํ๋ฉด ๋๋ฏ๋ก, ๊ธฐ์กด MHA๋ณด๋ค ์บ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ๊ธฐ์ ์ผ๋ก ์ ๊ฐํ๋ฉด์๋ ์ ์ฌํ ์ฑ๋ฅ์ ์ ์งํ ์ ์์ต๋๋ค.</p><p>MLA๊ตฌ์กฐ์์ Query์ ์ ์ฉ๋๋ ์ ์ฐจ์ ์์ถ (low-rank) compression ๋ฐฉ์๊ณผ ๊ทธ ์์์ ์ค๋ช
ํ๋ ๋ถ๋ถ์ด๋ค. Attention Query์ ๋ํด์๋ V3์์๋ low-rank compression์ ์ํํ๋ฉฐ ์ด๋ ํ์ต ์ค ํ์ฑํ๋๋ ๋ฉ๋ชจ๋ฆฌ (activation memeory)๋ฅผ ์ค์ผ ์ ์๋ค.</p><p>$$\begin{aligned} c_{t}^{Q} = W^{DQ}h_{t} \ [q_{t, 1}^{C};q_{t,2}^{C};โฆ;q_{t,n_{h}}^{R}] = q_{t}^{C}=W^{UQ}c_{t}^{Q},\ [q_{t, 1}^{R}; q_{t, 2}^{R};โฆ; q_{t, n_{h}}^{R}] = q_{t}^{R}=RoPE(W^{QR}c_{t}^{Q}), \ q_{t,i}=[q_{t,i}^{C}; q_{t,i}^{R}] \end{aligned}$$<br>โข ์ฌ๊ธฐ์ $c_t^Q \in \mathbb{R}^{d_c{\prime}}$๋ Query๋ฅผ ์ํ ์์ถ๋ ์ ์ฌ ๋ฒกํฐ(latent vector)์
๋๋ค.<br>โข $d_c{\prime} \ll d_h \cdot n_h$๋ Query ์์ถ ์ฐจ์์ ๋ํ๋ด๋ฉฐ, ์ ์ฒด Query ์ฐจ์๋ณด๋ค ํจ์ฌ ์์ต๋๋ค.<br>โข $W^{DQ} \in \mathbb{R}^{d_c{\prime} \times d}, W^{UQ} \in \mathbb{R}^{d_h n_h \times d_c{\prime}}$๋ ๊ฐ๊ฐ Query์ฉ ๋ค์ด ํ๋ก์ ์
๋ฐ ์
ํ๋ก์ ์
ํ๋ ฌ์
๋๋ค.<br>โข $W^{QR} \in \mathbb{R}^{d_h^R n_h \times d_c{\prime}}$๋ RoPE๋ฅผ ์ ์ฉํ decoupled Query๋ฅผ ์์ฑํ๋ ํ๋ ฌ์
๋๋ค.</p><p><strong>(์ถ๊ฐ์ค๋ช
)</strong> </p><ul><li>1๋จ๊ณ : ์์ถ (down-projection)<ul><li>$c_t^Q = W^{DQ} h_t$</li><li>์
๋ ฅ ๋ฒกํฐ $h_t \in \mathbb{R}^d$๋ฅผ Query ์ ์ฉ์ ์ ์ฐจ์ ๊ณต๊ฐ $d_c{\prime}$๋ก ์์ถํฉ๋๋ค.</li><li>๋ชฉ์ : ๋ฉ๋ชจ๋ฆฌ ์ ์ฝ ๋ฐ ์ฐ์ฐ ํจ์จ ํฅ์</li></ul></li><li>2๋จ๊ณ : Query ๋ฒกํฐ ์์ฑ<ul><li>$q_t^C = W^{UQ} c_t^Q$</li><li>์์ถ๋ latent vector $c_t^Q$๋ฅผ ํตํด Query vector๋ฅผ ๋ณต์(์
ํ๋ก์ ์
)ํฉ๋๋ค.</li><li>์์ฑ๋ $q_t^C \in \mathbb{R}^{d_h \cdot n_h}$๋ head๋ณ Query ์ปดํฌ๋ํธ๋ก ๋๋ฉ๋๋ค</li><li>$q_t^C = [q_{t,1}^C; q_{t,2}^C; \ldots; q_{t,n_h}^C]$</li></ul></li><li>3๋จ๊ณ : RoPE๋ฅผ ์ ์ฉ์ ์ํ Query ์์ฑ<ul><li>$q_t^R = \text{RoPE}(W^{QR} c_t^Q)$</li><li>์์น ์ ๋ณด๋ฅผ ๋ถ์ฌํ๊ธฐ ์ํด, ๊ฐ์ $c_t^Q$์ ๋ณ๋ ํ๋ ฌ $W^{QR}$์ ์ ์ฉํ๊ณ ,</li><li>๊ฒฐ๊ณผ์ RoPE(Rotary Positional Embedding)์ ์ ์ฉํ์ฌ ์์น ์ ๋ณด๋ฅผ ํฌํจํ Query $q_t^R$ ์์ฑ</li><li>๋ง์ฐฌ๊ฐ์ง๋ก head๋ณ๋ก ๋๋ ์ ์์:</li><li>$q_t^R = [q_{t,1}^R; q_{t,2}^R; \ldots; q_{t,n_h}^R]$</li></ul></li><li>4๋จ๊ณ : ์ต์ข
Query ๊ตฌ์ฑ<ul><li>$q_{t,i} = [q_{t,i}^C; q_{t,i}^R]$</li><li>๊ฐ head์ ์ต์ข
Query๋ ๋ด์ฉ ๊ธฐ๋ฐ ์ปดํฌ๋ํธ $q_{t,i}^C$์</li><li>์์น ์ ๋ณด ์ปดํฌ๋ํธ $q_{t,i}^R$๋ฅผ ๊ฒฐํฉ(concatenation)ํ ๋ฒกํฐ์
๋๋ค.</li></ul></li><li>์ ๋ฆฌํ๋ฉด, ๊ธฐ์กด Transformer์ $h_{t}$๋ก ๋ถํฐ Query, key, value๋ฅผ ์ง์ ๋ง๋ค์ง๋ง</li><li>MLA์์๋ ์ด๋ฅผ ์์ถํ๊ณ ๋ณต์ํจ์ผ๋ก์จ 1. ํ์ต ์ค ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ์ค์ด๊ณ , 2. ํจ์จ์ ๊ณ์ฐ ๊ตฌ์กฐ๋ฅผ ์ ์งํ๋ค. ํนํ Query๊น์ง ์์ถํ๋ ๊ฒ์ Training์ ์ค์ ์ ๋ ์ต์ ํ ๊ณผ์ ์ด๊ณ , Key, Value ์บ์ฑ์ Inference ํจ์จ์ฑ ํฅ์์ ์ค์ ์ด ์๋ค.<br><strong>(์ถ๊ฐ์ค๋ช
)</strong></li><li>RoPE๋?<ul><li>2023๋
Zhipu AI์์ ๋ฐํํ ๋
ผ๋ฌธ์ผ๋ก ROPEformer: Enhanced Transformer with Rotary Position Embedding ์ด๋ผ๋ ๋
ผ๋ฌธ์์ ์ฒ์ ๋ฑ์ฅ</li><li>transoformer์์ positional embedding ๋ฐฉ๋ฒ ์ค ํ๋๋ฉด์, ์ฌ์ค์ ํ์ค์ด ๋ ๋ฐฉ์</li><li>original transformer์์๋ absolute positional embedding (์์น ๋ฒกํฐ ์์ฒด)๋ฅผ ๋ํ๋ ๋ฐฉ์์ด์๋๋ฐ ์ด ๋ณด๋ค ์ฐ์ฐ์ ์ผ๋ก ์ ๋ฆฌํ ์ธก๋ฉด์ด ์์ผ๋ฉฐ ์์น๋ฅผ ํํํ๋๋ฐ ์ข๋ ์ ๊ตํ๋ค๋ ์ฅ์ ์ด ์์</li><li>๊ฐ์ฅ ํต์ฌ์ ๋ฒกํฐ์ ๊ฐ ์ฐจ์์ ์์น ์ ๋ณด์ธ ํ์ ํ๋ ฌ (rotation matrix)๋ก ์ฃผ์
ํ๋ ๊ฒ์ด๋ค. </li><li>๋ค์ ์ฝ๊ฒ ๋งํ๋ฉด, ์์น์ ๋ฐ๋ผ ์๋ฒ ๋ฉ ๋ฒกํฐ๋ฅผ ์ด์ง์ฉ ํ์ ์์ผ์ ์๋์ ์ธ ๊ฑฐ๋ฆฌ ์ ๋ณด๋ฅผ ๊ฐ์ ์ ์ผ๋ก ํํํ ์ ์๋๋ก ํ๋ ๊ฒ์ด๋ค.</li><li>$$\begin{aligned} x_{t,2i}^{\text{RoPE}} &= x_{2i} \cos(\theta_i t) - x_{2i+1} \sin(\theta_i t) \ x_{t,2i+1}^{\text{RoPE}} &= x_{2i} \sin(\theta_i t) + x_{2i+1} \cos(\theta_i t) \end{aligned}$$</li><li>๋ ์์ธํ ๋ด์ฉ์ <a href="https://medium.com/@hugmanskj/mastering-llama-rotary-positional-embedding-rope-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0-9b1963a22852">์ฌ๊ธฐ</a> ์ฐธ์กฐ</li></ul></li></ul><h4 id="2-1-2-DeepSeekMoE-with-Auxiliary-Loss-Free-Load-Balancing"><a href="#2-1-2-DeepSeekMoE-with-Auxiliary-Loss-Free-Load-Balancing" class="headerlink" title="2.1.2. DeepSeekMoE with Auxiliary-Loss-Free Load Balancing"></a>2.1.2. DeepSeekMoE with Auxiliary-Loss-Free Load Balancing</h4><h5 id="DeepSeekMoE์-๊ธฐ๋ณธ-์ํคํ
์ฒ"><a href="#DeepSeekMoE์-๊ธฐ๋ณธ-์ํคํ
์ฒ" class="headerlink" title="DeepSeekMoE์ ๊ธฐ๋ณธ ์ํคํ
์ฒ"></a>DeepSeekMoE์ ๊ธฐ๋ณธ ์ํคํ
์ฒ</h5><p>V3๋ FFN(Feed-Forward-Networks)์ ๋ํด DeepSeekMoE ์ํคํ
์ฒ๋ฅผ ์ฑํํ์๋ค. ๊ธฐ์กด์ MoE ๊ตฌ์กฐ์ธ GShard์ ๋น๊ตํ์ ๋ DeepSeekMoE๋ ์ธ๋ถํ๋ ์ ๋ฌธ๊ฐ(finer-grained experts)๋ฅผ ์ฌ์ฉํ๊ณ ์ผ๋ถ ์ ๋ฌธ๊ฐ๋ค์ ๊ณต์ ์ ๋ฌธ๊ฐ(shared experts)๋ก ๋
๋ฆฝ์ ์ผ๋ก ๊ตฌ๋ถํ์ฌ ์ฌ์ฉํ๋ค.</p><p>ํ ํฐ $t$์ ๋ํ FFN ์
๋ ฅ์ $u_{t}$ (์
๋ ฅ ์๋ฒ ๋ฉ)๋ผ ํ ๋, FFN์ ์ถ๋ ฅ $h_{t}^{โ}$๋ ๋ค์๊ณผ ๊ฐ์ด ๊ณ์ฐ๋๋ค.</p><p>$$h^{โ}<em>{t} = u</em>{t} + \Sigma_{i=1}^{N_{s}}FFN_{i}^{(s)}(u_{t}) +<br>\Sigma_{i=1}^{N_{r}}g_{i, t}FFN_{i}^{(r)}(u_{t})$$</p><ul><li>$h_{t}^{โ}$ : ์ต์ข
FFN ์ถ๋ ฅ</li><li>$u_{t}$ : ์
๋ ฅ ์๋ฒ ๋ฉ</li><li>$FFN_{i}^{(s)}$ : ๊ณต์ ์ ๋ฌธ๊ฐ (shared expert)</li><li>$FFN_{i}^{r}$ : routed ์ ๋ฌธ๊ฐ</li><li>$g_{i, t}$ : routed ์ ๋ฌธ๊ฐ $i$์ ๊ฒ์ดํ
๊ฐ (gating value) - weight ์ด๋ผ๊ณ ์๊ฐ</li><li><strong>(์ถ๊ฐ ์์ ์ค๋ช
)</strong> ์๋ ์
๋ ฅ + ๋ชจ๋ ๊ณต์ ์ ๋ฌธ๊ฐ์ ์ถ๋ ฅ + ๋ผ์ฐํ
๋ ์ ๋ฌธ๊ฐ์ ์ถ๋ ฅ์ ๊ฐ์คํฉ<br>$$g_{i, t} = \frac{g_{i, t}^{โ}}{\Sigma_{j=1}^{N_{r}}g_{j, t}^{โ}}$$</li><li><strong>(์ถ๊ฐ ์์ ์ค๋ช
)</strong> ์์ ๊ฒ์ดํ
์ ์ / ์ ๊ทํ๋ ์ต์ข
๊ฒ์ดํ
๊ฐ</li></ul><p>$$g_{i, t}^{โ} = s_{i, t}, \quad s_{i, t} \in Topk({s_{j, t}|1 \leq N_{r}, K_{r}}), \quad 0 \quad otherwise$$</p><ul><li>$s_{i,t}$โ: ํ ํฐ $t$์ ์ ๋ฌธ๊ฐ $i$์ ์นํ๋(affinity score)</li><li>$Topk(โ
,K_{r}โ)$: ๊ฐ์ฅ ์์ $K_r$โ๊ฐ์ ์ ๋ฌธ๊ฐ๋ง ์ ํ</li><li><strong>(์ถ๊ฐ ์์ ์ค๋ช
)</strong> ์ฆ ์์ $K_r$๊ฐ์ expert๋ง ์ ํํด $g_{i, t}^{โ}=s_{i,t}$ ์ด๊ณ ๋๋จธ์ง๋ 0</li></ul><p>$s_{i, t} = Sigmoid(u_{t}^{T}e_{i})$</p><ul><li>$e_{i}$ : ๋ผ์ฐํ
expert $i$์ ์ค์ฌ ๋ฒกํฐ (centroid vector)</li><li>$u_{t}^{T}e_{i}$ : ํ ํฐ๊ณผ expert ๊ฐ์ ๋ด์ (=์ ์ฌ๋)</li><li>Sigmoid๋ ๊ฒฐ๊ณผ๋ฅผ 0 ~ 1 ๋ฒ์๋ก ์กฐ์ </li><li><strong>(์ถ๊ฐ ์์ ์ค๋ช
)</strong> Affinity score s๋ ์
๋ ฅ ๋ฒกํฐ์ expert vector ๊ฐ์ ์ ์ฌ๋๋ฅผ sigmoid๋ก ๋ณํํ ๊ฐ</li></ul><p>์ฌ๊ธฐ์,</p><ul><li>$N_{s}$์ $N_{r}$์ ๊ฐ๊ฐ ๊ณต์ ์ ๋ฌธ๊ฐ์ ๋ผ์ฐํ
์ ๋ฌธ๊ฐ์ ๊ฐฏ์๋ฅผ ๋ํ๋ธ๋ค.</li><li>$FFN_{i}^{(s)}(\cdot)$ ์ $FFN_{i}^{(r)}(\cdot)$ ์ i ๋ฒ์งธ ๊ณต์ ์ ๋ฌธ๊ฐ์ i ๋ฒ์งธ ๋ผ์ฐํ
์ ๋ฌธ๊ฐ</li><li>$K_{r}$์ ํ์ฑํ๋๋ ๋ผ์ฐํ
์ ๋ฌธ๊ฐ์ ์๋ฅผ ์๋ฏธ</li><li>$Topk(\cdot, K)$๋ ํ ํฐ $t$์ ๋ํด ๊ณ์ฐ๋ ๋ชจ๋ ์นํ๋ ์ค์์ ์์ $K$๊ฐ์ ์ ์๋ก ์ด๋ฃจ์ด์ง ์งํฉ์ ์๋ฏธ</li></ul><h5 id="Auxiliary-Loss-Free-Load-Balancing"><a href="#Auxiliary-Loss-Free-Load-Balancing" class="headerlink" title="Auxiliary-Loss-Free Load Balancing"></a>Auxiliary-Loss-Free Load Balancing</h5><ul><li>MoE ๋ชจ๋ธ์์ Expert ๋ถํ balancing์ด ๋ถ๊ท ํํด์ง๋ฉด, routing collapse (๋ผ์ฐํ
๋ถ๊ดด)๊ฐ ๋ฐ์ํ์ฌ expert๊ฐ ๋ณ๋ ฌ ์ฒ๋ฆฌ ํ ๋ ๊ณ์ฐ ํจ์จ์ฑ์ด ์ ํ๋๊ฒ ๋๋ค.</li><li>๊ธฐ์กด์ ํด๊ฒฐ์ฑ
์ผ๋ก๋ auxiliary loss (๋ณด์กฐ ์์ค)์ ์์กดํ์ฌ ์ด๋ฌํ ๋ถ๊ท ํ์ ๋ฐฉ์งํ์์๋ค. ๊ทธ๋ฌ๋ ๋ณด์กฐ ์์ค์ด ๋๋ฌด ์ปค์ง๋ฉด ๋ชจ๋ธ์ ๋ณธ๋ ์ฑ๋ฅ์ ์ ํดํ ์ ์๋ค. V3์์๋ ์ฑ๋ฅ๊ณผ ๋ถํ balancing์ฌ์ด์ ๋ ๋์ ๋์์ ์ํด ๋ณด์กฐ ์์ค ์๋ ๋ถํ ๋ถ์ฐ ์ ๋ต์ ์๋กญ๊ฒ ์ ์ํ๋ค. ๊ตฌ์ฒด์ ์ผ๋ก ๊ฐ expert ๋ง๋ค bias (ํธํฅ) ํญ $b_{i}$๋ฅผ ๋์
ํ์ฌ, ์ด $b_{i}$๋ฅผ ๊ฐ ์ ๋ฌธ๊ฐ์ ์นํ๋ ์ ์ $s_{i, t}$์ ๋ํ ๋ค ์์ Top-K ๋ผ์ฐํ
์ ๊ฒฐ์ ํ๋ค.</li><li>$$g_{i, t}^{โ} = s_{i, t}, \quad s_{i, t}+b_{i} \in Topk({s_{j, t}+b_{j}|1 \leq j \leq N_{r}}, K_{r}), \quad 0 \quad otherwise$$</li><li>$s_{i,t}$: ํ ํฐ $t$๊ณผ expert $i$์ affinity score (๊ธฐ์กด๊ณผ ๋์ผ)</li><li>$b_{i}$ : expert $i$์ ๋ํ bias term (ํธํฅ๊ฐ) : ์ด ๊ฐ์ ํ์ต ๊ณผ์ ์์ ๋์ ์ผ๋ก ์
๋ฐ์ดํธ ๋จ</li><li>$g_{i, t}^{โ}$ : ์์ ๊ฒ์ดํ
์ ์ (Top-K) ์ ํ์ ์ฌ์ฉ<br>โ ์ฆ, ํธํญ์ด ์ ์ฉ๋ ์นํ๋ $s_{i,t} + b_{i}$๋ฅผ ๊ธฐ์ค์ผ๋ก Top-K expert๋ฅผ ์ ํํ๋, ์ ํ๋ ์ดํ ์ค์ ๊ฒ์ดํ
๊ฐ์ ์๋์ $s_{i,t}$๋ฅผ ์ฌ์ฉ.๊ฒฐ๊ตญ $b_{i}$๋ routing ์ฉ๋์๋ง ๊ฒฐ์ ์ ๋ฏธ์น๊ณ ์ค์ weighted sum์์๋ ์ฌ์ฉ๋์ง ์์</li></ul><p><strong>(์ถ๊ฐ ์ค๋ช
)</strong> bias (ํธํฅ) term $b_{i}$์ ์
๋ฐ์ดํธ ๋ฐฉ์</p><ul><li>๊ฐ ํ๋ จ ์คํ
๋ง๋ค ์ ์ฒด ๋ฐฐ์น์์ expert ๋ถํ๋ฅผ ๋ชจ๋ํฐ๋งํจ</li><li>ํน์ expert๊ฐ ๊ณผ๋ถํ (overloaded) ์ํ๋ผ๋ฉด โ $b_{i}$๋ฅผ ๊ฐ์</li><li>ํน์ expert๊ฐ ๊ณผ์ํ์ฉ (underloaded) ์ํ๋ผ๋ฉด โ $b_{i}$๋ฅผ ์ฆ๊ฐ</li><li>์ฆ ์ด๋ฅผ ์์์ผ๋ก ํํํ๋ฉด,<ul><li>$$\begin{aligned} b_{i} โ b_{i} - ฮณ, if \quad overloaded\ b_{i} โ b_{i} + ฮณ, if \quad underload \end{aligned}$$</li></ul></li><li>ฮณ : bias update speed ๋ผ๋ ํ์ดํผํ๋ผ๋ฏธํฐ์ด๋ค.</li></ul><h4 id="Complementary-Sequence-Wise-Auxiliary-Loss"><a href="#Complementary-Sequence-Wise-Auxiliary-Loss" class="headerlink" title="Complementary Sequence-Wise Auxiliary Loss"></a>Complementary Sequence-Wise Auxiliary Loss</h4><ul><li>์ํ์ค ๋จ์์ ๋ณด์กฐ์์ค</li><li>์ด ์์ค ํญ์ ๋ชจ๋ธ์ด ์ ์ฒด์ ์ผ๋ก auxiliary-loss-free ์ ๋ต์ ๋ฐ๋ฅด๋ ๊ฐ๋ณ ์ํ์ค ๋ด์์ ๋ถํ๊ฐ ์ ๋ฆฌ๋ ํ์์ ๋ฐฉ์งํ๊ณ ๋ณด์ํ๊ธฐ ์ํด ๋์
๋ ์์ค.</li><li>V3๋ expert load balancing์ ์ํด ๋ณด์กฐ ์์ค ์๋ ์ ๋ต (auxiliary-loss-free-strategy)์ ์์กดํ์ง๋ง ๊ฐ๋ณ ์ํ์ค ๋ด์์ ๋ฐ์ํ ์ ์๋ ๊ทน๋จ์ ์ธ ๋ถ๊ท ํ์ ๋ฐฉ์งํ๊ธฐ ์ํด ๋ณด์์ ์ผ๋ก ์ํ์ค ๋จ์์ ๋ถํ ๊ท ํ ์์ค(sequence-wise balance loss)๋ ํจ๊ป ์ฌ์ฉํ๋ค.</li><li><img src="/2025/03/24/DeepSeek-V3-Technical-Report-%EC%A0%95%EB%A6%AC/V3_2.png"></li><li>์์ (17) : Sequence ๋จ์ ๋ถํ ์์ค ์ ์<ul><li>$L_{Bal}$ : sequence-wise balance loss ๋ถํ ๊ท ํ ์์ค</li><li>$\alpha$ : ์์ค ํญ์ ๊ฐ์ค์น๋ฅผ ์กฐ์ ํ๋ ๋งค์ฐ ์์ ์์</li><li>$f_{c}$ : expert i์ ์ ํ ๋น์จ</li><li>$P_{i}$: Expert i์ ์๋์ ์ธ ์ค์๋</li><li><strong>(์ถ๊ฐ ์ค๋ช
)</strong> ์ฌ๊ธฐ์ ์์ค ํญ์ ๋ณด๋ฉด ๋ง์ด ์ ํ๋์๊ณ ์ค์ํ ์ญํ ์ ํ๋ Expert์๊ฒ ๋ ํฐ ํจ๋ํฐ๋ฅผ ๋ถ๊ณผํ์ฌ ๋ง์ด ์ฌ์ฉ๋๋, ์ฆ Overuse๋ฅผ ์ต์ ํ๋ ๊ฒ์ด๋ค. โ ๊ฒฐ๊ตญ balancing ์ ๊ฐ๊น๊ฒ ๋๋ ๊ฒ</li></ul></li><li>์์ (18)<ul><li>Expert๊ฐ ์ ํ๋๋ ๋น์จ, ํ๋ฅ $f_{i}$</li><li>$f_{i}$ : Expert i๊ฐ Top-K ๋ผ์ฐํ
์ ์ํด ์ ํ๋๋ ๋น์จ</li><li>$N_{r}$ : ๋ผ์ฐํ
๊ฐ๋ฅํ ์ ์ฒด Expert ์</li><li>$K_{r}$ : ํ ํ ํฐ๋น ์ ํ๋๋ Expert ์</li><li>$T$ : ์ํ์ค ๊ธธ์ด (ํ ํฐ ์)</li><li><strong>(์ถ๊ฐ ์ค๋ช
)</strong> ์ ๊ทํ๋ ํํ๋ก expert i๊ฐ ์ผ๋ง๋ ์์ฃผ ์ ํ๋์๋์ง๋ฅผ ์๋ฏธ</li></ul></li><li>์์ (19)<ul><li>์ ๊ทํ๋ affinity score </li><li>$s_{i, t}$ : ํ ํฐ t์ ๋ํ expert i์ affinity score</li><li>$s_{i, t}^{โ}$ : ์ ์ฒด Expert ์ค์์ ์๋์ ์ธ ๋น์ค</li><li><strong>(์ถ๊ฐ์ค๋ช
)</strong> ์ด ๊ฐ์ Expert i๊ฐ ํ ํ ํฐ์์ ์ผ๋ง๋ ์ค์ํ ์ญํ ์ ํ๋์ง ๋ํ๋ด๋ ๊ฐ</li></ul></li><li>์์ (20)<ul><li>ํ๊ท ์ค์๋ (?)</li><li>Expert i๊ฐ ์ํ์ค ์ ์ฒด์ ๊ฑธ์ณ ์ผ๋ง๋ ์ค์ํ ๊ธฐ์ฌ๋ฅผ ํ๋์ง์ ํ๊ท </li><li>$P_{i}$๊ฐ ํด์๋ก ํด๋น Expert๊ฐ ์ค์ํ ํ๋จ์ ์์ฃผ ์ฐธ์ฌํ๋ค๋ ๋ป<br><strong>(์ถ๊ฐ์ค๋ช
)</strong> V3๋ ์ ์ฒด์ ์ผ๋ก ๋ณด์กฐ ์์ค ์์ด ๋ถํ ๊ท ํ์ ๋ฌ์ฑํ์ง๋ง, ์ํ์ค ํ๋์์๋ผ๋ ๋ชจ๋ ํ ํฐ์ด ํน์ ์ ๋ฌธ๊ฐ๋ง ๊ณ์ ์ฐ๊ฒ๋๋ฉด ํ๋ จ์ด ์๊ณก๋ ์ ์๋ค. โ ์ด๋ฅผ ๋ง๊ธฐ ์ํด ์ ๋ฐํ๊ฒ ์กฐ์ ๋ ๋ณด์กฐ ์์ค ํญ์ ์ถ๊ฐํ์ฌ ๊ทน๋จ์ ์ธ ํธํฅ๋ง ์ ๊ฑฐํ๋ ํจ๊ณผ๋ฅผ ์ค๋ค.</li></ul></li></ul><h4 id="Node-Limited-Routing"><a href="#Node-Limited-Routing" class="headerlink" title="Node-Limited Routing"></a>Node-Limited Routing</h4><p>V2์์ ์ฌ์ฉ๋ device-limited routing ๋ฐฉ์๊ณผ ์ ์ฌํ๊ฒ V3 ์ญ์ ํ์ต ์ค ํต์ ๋น์ฉ์ ์ ํํ๊ธฐ ์ํด ์ ์ฝ๋ routing ๋ฉ์ปค๋์ฆ์ ์ฌ์ฉํ๋ค. ์ฆ ๊ฐ ํ ํฐ์ด ์ต๋ M๊ฐ์ ๋
ธ๋๋ก๋ง ๋ผ์ฐํ
๋๋๋ก ํ๋ ๊ฒ์ด๋ค. ์ฌ๊ธฐ์ ์ด ๋
ธ๋๋ค์ ๊ฐ ๋
ธ๋์ ๋ถ์ฐ๋ expert ์ค ๊ฐ์ฅ ๋์ $\frac{K_{r}}{M}$ ๊ฐ์ affinity score์ ํฉ์ ๊ธฐ์ค์ผ๋ก ์ ํ๋๋ค. ์ด๋ฌํ ์ ์ฝ์กฐ๊ฑด ํ์์ DeepSeekMoE ํ์ต ํ๋ ์์ํฌ๋ ์ฐ์ฐ๊ณผ ํต์ ์ ๊ฑฐ์ ๊ฒน์ณ์ (computation-communication overlap) ์ํํ ์ ์๋ค.<br><strong>(์ถ๊ฐ์ค๋ช
)</strong> MoE๋ ์ฌ๋ฌ Expert ๋ธ๋ก (FFN block)์ ์๋ก ๋ค๋ฅธ ๋
ธ๋ (GPU์๋ฒ ๋ฑ)์ ๋ถ์ฐ์์ผ๋๊ณ , ๊ฐ ํ ํฐ๋ง๋ค ์ ์ ํ expert๋ก routing ํ๋ ๋ฐฉ์์ด๋ค. ๊ทธ๋ฐ๋ฐ, ํ ํฐ๋ง๋ค ์ฌ๋ฌ ๋
ธ๋๋ก routing ๋๋ฉด โ GPU๊ฐ ํต์ ๋น์ฉ (์ ์ก๋, ๋๊ธฐ ์๊ฐ ๋ฑ)์ด ์ฆ๊ฐํ๊ฒ ๋๊ณ , ์ด๋ ๋๊ท๋ชจ์ ๋ถ์ฐ ํ์ต์์ ๋ณ๋ชฉ์ด ๋ ์ ์๋ค. ์ด์ ๋ํ ํด๊ฒฐ ์ฑ
์ผ๋ก Node-Limited Routing ์ด ์ํ๋๋ ๊ฒ์ด๋ค. ๋ค์ ์ ๋ฆฌํ๋ฉด ๊ฐ ํ ํฐ์ ์ต๋ $M$๊ฐ์ ๋
ธ๋๋ก๋ง ๋ผ์ฐํ
๋๋๋ก ์ ํ๋๋ค. ๋
ธ๋ ์ ํ ๊ธฐ์ค์ ๋ค์๊ณผ ๊ฐ๋ค.</p><ul><li>๊ฐ ๋
ธ๋๋ ์ฌ๋ฌ Expert๋ฅผ ํฌํจํ๊ณ ์์</li><li>๊ฐ ํ ํฐ์ ํด๋น ๋
ธ๋์ ์๋ Expert๋ค๊ณผ์ affinity score๋ฅผ ๊ณ์ฐ</li><li>๊ทธ ์ค ์์ $\frac{K_{r}}{M}$๊ฐ์ affinity๋ฅผ ์ ํํด ํฉ์ฐ</li><li>์ด ํฉ์ฐ ์ ์๊ฐ ๋์ ์์ $M$๊ฐ ๋
ธ๋๋ฅผ ์ ํ<br>์ฆ ํ ํฐ ๋น ์ ์ฒด Expert๋ฅผ ๊ณ ๋ คํ์ง ์๊ณ ์ด ๋
ธ๋์ ์๋ ์ ๋ฌธ๊ฐ๋ค ์ค์์ ์ ์ ํฉ์ด ๋์ ๊ณณ์ผ๋ก๋ง ๋ณด๋ด์๋ ๋ฐฉ์์ด๋ค.</li></ul><h4 id="No-Token-Dropping"><a href="#No-Token-Dropping" class="headerlink" title="No Token-Dropping"></a>No Token-Dropping</h4><ul><li>ํจ๊ณผ์ ์ธ ๋ถํ ๋ถ์ฐ ์ ๋ต ๋๋ถ์ V3๋ ์ ์ฒด ํ์ต ๊ณผ์ ์์ load balancing ๋ฉด์์ ์์ฃผ ์ํธํ ์ํ๋ฅผ ์ ์งํ ์ ์์๋ค. ๋ฐ๋ผ์ ํ์ต ์ค ์ด๋ค ํ ํฐ๋ dropํ์ง ์์๋ค. ๋ํ ์ถ๋ก ์ ๋ถํ ๊ท ํ์ ๋ณด์ฅํ๊ธฐ ์ํ ํน์ ๋ฐฐํฌ ์ ๋ต๋ ํจ๊ผ ๊ตฌํํ๊ธฐ ๋๋ฌธ์ ์ถ๋ก ๊ณผ์ ์์๋ token drop์ด ๋ฐ์ํ์ง ์์๋ค<br><strong>(์ถ๊ฐ์ค๋ช
)</strong> Token Dropping์ด๋, MoE ๊ตฌ์กฐ์์๋ ํน์ ์กฐ๊ฑด์์ ์ผ๋ถ ํ ํฐ์ ์ฒ๋ฆฌ๋ฅผ ์๋ตํ๋ ๊ฒฝ์ฐ (Drop)๊ฐ ์๋ค. ์ด๋ ์ฌ๋ฌ๊ฐ์ง ์ํฉ์์ ๋ฐ์ํ๊ฒ ๋๋๋ฐ ๋ํ์ ์ผ๋ก๋ 1. Expert ๋ถํ ๋ถ๊ท ํ์ด ๋ฐ์ํ์ฌ GPU ์์์ด ๋ถ์กฑํด์ง๊ฑฐ๋ 2. Routing์ ์คํจํ๊ฑฐ๋ ์๊ฐ๊ณผ ๋ฉ๋ชจ๋ฆฌ ์ต์ ํ๋ฅผ ์ํด ํฌ์ํ๋ ์ ํ</li></ul><h3 id="2-2-Multi-Token-Prediction"><a href="#2-2-Multi-Token-Prediction" class="headerlink" title="2.2 Multi-Token Prediction"></a>2.2 Multi-Token Prediction</h3><ul><li>ํ ๋ฒ์ ์ฌ๋ฌ ๊ฐ์ ํ ํฐ์ ์์ธกํ๋๋ก ํ์ตํ๋ ๋ฐฉ์</li><li>V3์์๋ MTP (Multi-Token-Prediction)์ ์ค์ ํ๊ณ ์ฐ๊ตฌํ์์</li><li>๊ฐ ์์น์์ ํ ๊ฐ ์ด์์ ํ ํฐ์ ์์ธกํ๋ ๋ฐฉ์์ผ๋ก ์์ธก๋ฒ์๋ฅผ ํ์ฅ<ul><li>MTP์ ํจ๊ณผ<ul><li>MTP๋ ํ์ต ์๊ทธ๋์ ๋ denseํ๊ฒ ๋ง๋ค๊ณ ์ด๋ฅผ ํตํด โ๋ฐ์ดํฐ ํจ์จ์ฑ์ ํฅ์์ํฌ ์ ์์</li><li>MTP๋ฅผ ์ ์ฉํ๋ฉด, ๋ชจ๋ธ์ด ํ ํฐ ์์ธก์ ์ํด ๋ฏธ๋ฆฌ ํํ์ ๊ณํ (pre-plan)ํ๋๋ก ์ ๋ํ๋ ํจ๊ณผ๊ฐ ์์<br><img src="/2025/03/24/DeepSeek-V3-Technical-Report-%EC%A0%95%EB%A6%AC/V3_3.png"></li></ul></li></ul></li><li>V3 MTP ๊ทธ๋ฆผ์ ๋ณด๋ฉด, <ul><li>์ด์ ๋ฐฉ์(Gloeckle)๋ค์ ๋
๋ฆฝ์ ์ธ ์ถ๋ ฅ ํค๋ (output heads)๋ฅผ ์ด์ฉํ์ฌ $D$ ๊ฐ์ ์ถ๊ฐ ํ ํฐ์ ๋ณ๋ ฌ์ ์ผ๋ก ์์ธก</li><li>V3๋ ์ถ๊ฐ ํ ํฐ๋ค์ ์์ฐจ์ ์ผ๋ก (sequentially) ์์ธกํ๋ฉฐ</li><li>๊ฐ prediction depth ์์ causal chain์ ์ ์งํ๋ค.</li></ul></li></ul><h4 id="MTP-Modules"><a href="#MTP-Modules" class="headerlink" title="MTP Modules"></a>MTP Modules</h4><ul><li>MTP๋ $D$๊ฐ์ ์์ฐจ์ ์ธ ๋ชจ๋์ ์ฌ์ฉํ์ฌ $D$๊ฐ์ ์ถ๊ฐ์ ์ธ ํ ํฐ์ ์์ธกํ๋ค.</li><li>k๋ฒ์งธ MTP ๋ชจ๋์ ๋ค์ ๊ตฌ์ฑ์์๋ก ์ด๋ฃจ์ด์ ธ์๋ค.<ul><li>๊ณต์ ์๋ฒ ๋ฉ ๊ณ์ธต $Emb(\cdot)$</li><li>๊ณต์ ์ถ๋ ฅ ํค๋ $OutHead(\cdot)$</li><li>ํธ๋์คํฌ๋จธ ๋ธ๋ก $TRM_{k}(\cdot)$</li><li>Projection Matrix $M_{k} \in R^{d \times 2d}$</li></ul></li><li>ํ ํฐ $t_{i}$์ ๋ํด ์์ธก depth k ์์ ๋ค์ ๋ ๋ฒกํฐ๋ฅผ ๊ฒฐํฉํ๋ค.<ul><li>$h_{i}^{k-1} \in R^{d}$ : (k-1)๋ฒ์งธ ๊น์ด์์์ ํ ํฐ i์ ํํ๋ฒกํฐ</li><li>$Emb(t_{i+k}) \in R^{d}$ : i+k๋ฒ์งธ ๋ฏธ๋ ํ ํฐ์ ์๋ฒ ๋ฉ</li></ul></li><li>์ (21)<ul><li>RMSNorm : ์
๋ ฅ ๋ฒกํฐ๋ฅผ ์ ๊ทํ (LayerNorm์ ๋์ฒดํ๋ ๊ฒ)</li><li><strong>(์ถ๊ฐ์ค๋ช
)</strong> k=1์ผ ๋๋ h๊ฐ ๋ฉ์ธ ๋ชจ๋ธ์ ์ถ๋ ฅ์</li></ul></li><li>์ (22)<ul><li>์ ์ฒด ํ ํฐ ์ํ์ค $1~T-k$์ ๋ํด ํฌ์๋ ๋ฒกํฐ $hโ^{k}$ ๋ฅผ ํธ๋์คํฌ๋จธ ๋ธ๋ก์ ํต๊ณผ์์ผ prediction depth k์์์ ์ต์ข
ํํ h๋ฅผ ์ป๋ ๊ฒ</li></ul></li><li>์ (23)<br><strong>(์ถ๊ฐ์ค๋ช
)</strong> ๊ฒฐ๊ตญ MTP ๊ตฌ์กฐ๋ฅผ ์์ฝํ๋ฉด</li></ul><ol><li>์
๋ ฅ : ๋ฉ์ธ ๋ชจ๋ธ์์ ๋์จ ํํ $h_{i}^{0}$</li><li>concat : ํด๋น ์์น์์์ ํํ + (i+k)๋ฒ ์งธ ๋ฏธ๋ ํ ํฐ ์๋ฒ ๋ฉ์ concatente</li><li>์ ๊ทํ + projection : RMSNorm + linear projection โ $h_{i}^{โk}$</li><li>ํธ๋์คํฌ๋จธ ํต๊ณผ โ $h^{k}$</li><li>๋ค์ ๋ฐ๋ณต $h^{k}$ ๊ฐ k+1๋ฒ์งธ ๋ชจ๋์ ์
๋ ฅ์ด ๋จ</li></ol><h4 id="MTP-in-Training-Objective"><a href="#MTP-in-Training-Objective" class="headerlink" title="MTP in Training Objective"></a>MTP in Training Objective</h4><ul><li>V3์ MTP์ loss function ์ ์ํ๋ ๋ถ๋ถ</li><li>์ (24)์ ๋ํ ์ค๋ช
<ul><li>$T$: ์
๋ ฅ ์ํ์ค์ ๊ธธ์ด</li><li>$t_{i}$: ์์น i์ ํด๋นํ๋ ์ ๋ต ํ ํฐ (ground-truth token)</li><li>$P_{i}^{k}[t_{i}]$: ๊น์ด k์ MTP ๋ชจ๋์ด ์์ธกํ ๋ถํฌ์์ ์ ๋ต ํ ํฐ $t_{i}$์ ํ๋ฅ </li><li><strong>(์ถ๊ฐ ์์ ์ค๋ช
)</strong> ์์ธก ๊น์ด k์์์ MTP ๋ชจ๋์ ์ํ์ค์ ๊ฐ ์์น $i=2+k$ ๋ถํฐ $T+1$๊น์ง ์ ๋ต ํ ํฐ $t_{i}$๋ฅผ ์์ธกํ๋ฉฐ ๊ทธ ์์ธก ํ๋ฅ ์ ๋ํด ํฌ๋ก์ค ์ํธ๋กํผ๋ฅผ ๊ณ์ฐํ๋ค.<ul><li>์ฆ MTP์ ๊ฐ depth๋ ์ ํด์ง ๋ฏธ๋ ํ ํฐ์ ์์ธกํ๋ ์์ ์ธ์ด ๋ชจ๋ธ์ฒ๋ผ ์๋ํ๊ณ , ๊ทธ ์์ธก์ด ์ผ๋ง๋ ์ ํํ์ง๋ฅผ ์ธก์ ํ๋ ์์ค์ ๊ณ์ฐํ๋ ๊ฒ</li></ul></li></ul></li><li>์ (25)<ul><li>์์๋ ๊ฐ ๋ชจ๋์ด๊ณ ์ด์ ์ ์ฒด MTP ์์ค์ ๋ณด๋ ๊ฒ</li><li>$D$ : ์์ธก ๊น์ด์ ์ (์ฆ, ๋ช๊ฐ์ ํ ํฐ์ ์์ธกํ๋์ง)</li><li>$\lambda$ : MTP ์์ค์ ๊ณฑํ๋ ๊ฐ์ค์น ๊ณ์ - ํ์ดํผํ๋ผ๋ฏธํฐ</li><li><strong>(์ถ๊ฐ ์์ ์ค๋ช
)</strong> ์ ์ฒด ์์ค์ ๋ชจ๋ ์์ธก ๊น์ด์ ๋ํ MTP ์์ค์ ํ๊ท ์ผ๋ก ๊ณ์ฐ๋๋ฉด์ ์ ์ฒด ํ์ต ์์ค์ ํตํฉํ๊ธฐ ์ํด $\lambda$๋ฅผ ๊ณฑํด ๊ฐ์ค์น๋ฅผ ์กฐ์ ํ๋ ๊ฒ</li></ul></li></ul><h4 id="MTP-in-Inference"><a href="#MTP-in-Inference" class="headerlink" title="MTP in Inference"></a>MTP in Inference</h4><ul><li>MTP๋ ๋ฉ์ธ ๋ชจ๋ธ์ ์ฑ๋ฅ ํฅ์์ ๋ชฉํ๋ก ํ๊ธฐ ๋๋ฌธ์ inference์์๋ MTP ๋ชจ๋์ ์๋ตํ๊ณ ๋ฉ์ธ ๋ชจ๋ธ๋ง์ผ๋ก ๋
๋ฆฝ์ ์ผ๋ก ๋์ํ ์ ์์. </li><li>์ด MTP ๋ชจ๋์ speculative decoding (์ถ์ธก ๊ธฐ๋ฐ์ ๋์ฝ๋ฉ)์ ์ํด ์ฌํ์ฉํ๊ฒ ๋๋ฉฐ latency ๋ฅผ ๋์ฑ ์ค์ด๋ ํจ๊ณผ๊ฐ ์์ ์ ์์</li><li><strong>(์ถ๊ฐ์ค๋ช
)</strong> Speculative Decoding์ด๋ ํ ๋ฒ์ ์ฌ๋ฌ ๊ฐ์ ํ ํฐ์ ์์ธกํ๊ณ , ๋์ค์ ์ด ์์ธก์ด ๋ง์๋์ง ํ์ธ โ ๋ง์์ผ๋ฉด ์์ฉํ๊ณ ํ๋ฆฌ๋ฉด ๋ค์ ๋์ฝ๋ฉ GPT-4 Turbo์๋ ์ฌ์ฉ๋ ๊ธฐ๋ฒ</li></ul>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Paper/">Paper</category>
<category domain="https://emjayahn.github.io/categories/Paper/LLM/">LLM</category>
<category domain="https://emjayahn.github.io/tags/LLM/">LLM</category>
<category domain="https://emjayahn.github.io/tags/DeepSeekV3/">DeepSeekV3</category>
<category domain="https://emjayahn.github.io/tags/Paper-Summary/">Paper Summary</category>
<comments>https://emjayahn.github.io/2025/03/24/DeepSeek-V3-Technical-Report-%EC%A0%95%EB%A6%AC/#disqus_thread</comments>
</item>
<item>
<title>DeepSeekMoE ์์ฝ</title>
<link>https://emjayahn.github.io/2025/03/19/DeepSeekMoE-%EC%9A%94%EC%95%BD/</link>
<guid>https://emjayahn.github.io/2025/03/19/DeepSeekMoE-%EC%9A%94%EC%95%BD/</guid>
<pubDate>Wed, 19 Mar 2025 12:05:59 GMT</pubDate>
<description><p>๋
ผ๋ฌธ DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models๋ฅผ ์ฝ๊ณ ์ฃผ์ contribution ๋ด์ฉ๊ณผ ๊ฐ์ธ์ ์ผ๋ก ๊ผญ ๊ธฐ์ตํ ๋ด์ฉ์ ์์ฝํ์ฌ ์ ๋ฆฌํด๋ณธ๋ค.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>๋
ผ๋ฌธ DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models๋ฅผ ์ฝ๊ณ ์ฃผ์ contribution ๋ด์ฉ๊ณผ ๊ฐ์ธ์ ์ผ๋ก ๊ผญ ๊ธฐ์ตํ ๋ด์ฉ์ ์์ฝํ์ฌ ์ ๋ฆฌํด๋ณธ๋ค.</p><span id="more"></span><h2 id="Abstract"><a href="#Abstract" class="headerlink" title="Abstract"></a>Abstract</h2><h3 id="๋ฌธ์ -์ ์"><a href="#๋ฌธ์ -์ ์" class="headerlink" title="๋ฌธ์ ์ ์"></a>๋ฌธ์ ์ ์</h3><ul><li>์ต๊ทผ LLM์ด ๋ฐ์ ํ๋ฉด์ ๋ ๋ง์ ํ๋ผ๋ฏธํฐ๋ฅผ ํ์ฉํ ์๋ก ์ฑ๋ฅ์ด ํฅ์ โ but, ๊ทธ์๋ฐ๋ฅธ ์ฐ์ฐ ๋น์ฉ ๊ธ๊ฒฉํ ์ฆ๊ฐ โ ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด Mixture-of-Experts (MoE) ์ํคํ
์ฒ ๋ฑ์ฅ</li><li>MoE: ์ฌ๋ฌ ๊ฐ์ <strong>์ ๋ฌธ๊ฐ ๋ชจ๋ธ (Experts)</strong> ์ ๋๊ณ , ์
๋ ฅ ๋ฐ์ดํฐ์ ๋ฐ๋ผ ์ผ๋ถ ์ ๋ฌธ๊ฐ๋ง ํ์ฑํํ์ฌ ๊ณ์ฐํ๋ ๋ฐฉ์<ul><li>์ด ๋ฐฉ์์ ์ ์ฒด ๋ชจ๋ธ ํฌ๊ธฐ๋ ์ฆ๊ฐํ ์๋ ์์ผ๋,</li><li>ํ ๋ฒ์ inference์์ ์ฌ์ฉ๋๋ ์ฐ์ฐ๋์ ์ค์ผ ์ ์๋ค.</li></ul></li><li>๊ธฐ์กด์ ๋ํ์ ์ธ MoE ์ํคํ
์ฒ GShard(๊ตฌ๊ธ) ๋ฐฉ์์ ๋ค์๊ณผ ๊ฐ์ ๋ฌธ์ ์ ์ด ์๋ค.<ul><li>Spicialization ๋ฌธ์ : GShard์์๋ N๊ฐ์ ์ ๋ฌธ๊ฐ(Experts) ์ค K๊ฐ๋ฅผ ์ ํ (Top-K Routing)ํ์ฌ ํ์ฑํํ์ง๋ง, ํน์ Expert ๋ค์ด ์ค๋ณต๋ ์ง์์ ํ์ตํ๋ ๋ฌธ์ ๊ฐ ์์ ์ ์๊ณ , ๊ฐ๊ฐ์ Expert๊ฐ ์ ๋ฌธํ(specialization)๋์ง ์๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์์</li><li>์ฆ, ๋ชจ๋ธ์ด ๊ฐ ์ ๋ฌธ๊ฐ๋ฅผ โ๊ณ ์ ํ, ํน๋ณํ ์ญํ โ์ ๊ฐ์ง ์ ๋ฌธ๊ฐ๋ก ๋ง๋ค์ง ๋ชปํ๊ณ ์ผ๋ถ ์ ๋ฌธ๊ฐ๊ฐ ๊ณผํ๊ฒ ์ค๋ณต๋ ์ญํ ์ ์ํํ๋ ๋นํจ์จ์ฑ์ด ์๋ค.</li></ul></li></ul><h3 id="Key-Idea"><a href="#Key-Idea" class="headerlink" title="Key Idea"></a>Key Idea</h3><ul><li>๋ณธ ๋
ผ๋ฌธ์์๋ DeepSeekMoE๋ผ๋ ์๋ก์ด MoE ๊ตฌ์กฐ๋ฅผ ์ ์</li><li>๋ชฉํ๋ ๊ฐ Expert๋ฅผ Specialization์ ๊ทน๋ํํ๊ธฐ ์ํจ<ul><li>๋ ๊ฐ์ง ํต์ฌ ์ ๋ต ์๊ฐ</li></ul><ol><li>Expert Segmenting(์ ๋ฌธ๊ฐ ์ธ๋ถํ) ๋ฐ Activation ๋ฐฉ์ ๊ฐ์ <ul><li>๊ธฐ์กด GShard๋ N๊ฐ์ ์ ๋ฌธ๊ฐ ์ค K ๊ฐ๋ง ์ ํํ๋ ๋ฐฉ์์ด์์ผ๋,</li><li>DeepSeekMoE์์๋ ๊ฐ ์ ๋ฌธ๊ฐ๋ฅผ ๋ ์์ ๋จ์๋ก ์ธ๋ถํ ($mN$๊ฐ ์ ๋ฌธ๊ฐ)ํ์ฌ, $mK$๊ฐ์ ์ ๋ฌธ๊ฐ๋ฅผ Activate ํ๋ ๋ฐฉ์์ ์ฌ์ฉ</li><li>์ด๋ฅผ ํตํด ๋ ๋ค์ํ ์กฐํฉ์ Expert๋ค์ ํ์ฑํํ ์ ์์ผ๋ฉฐ, Expert๊ฐ์ Knowledge ์ค๋ณต์ ์ค์ด๊ณ , ์ ์ฐํ ์กฐํฉ์ด ๊ฐ๋ฅ</li></ul></li><li>Shared Experts (๊ณต์ ์ ๋ฌธ๊ฐ(?)) ๋์
<ul><li>์ผ๋ถ Expert ($K_{s}$)๋ฅผ Shared Experts๋ก ๋ฐ๋ก ๋ถ๋ฆฌ</li><li>์ด Shared Expert๋ ์ผ๋ฐ ์์, ์ง์ (Common Knowledge) ํ์ต</li><li>๋๋จธ์ง Expert๋ค์ ํน์ ํ ์ญํ ์ ์ํํ๋ ๊ฒ์ผ๋ก ํนํ</li></ul></li></ol></li><li>์ด๋ ๊ฒ ํจ์ผ๋ก์จ ๊ฐ ์ ๋ฌธ๊ฐ๊ฐ ์ค๋ณต ์์ด ๊ณ ์ ํ ์ ๋ณด๋ฅผ ํ์ตํ ์ ์์ผ๋ฉฐ, ๋์์ ์ผ๋ฐ ์์์ Shared Expert๊ฐ ๋ด๋นํ๋ฏ๋ก ๋ถํ์ํ ์ค๋ณต ์ฐ์ฐ์ ์ค์ผ ์ ์๋ค.</li></ul><h3 id="Experiment"><a href="#Experiment" class="headerlink" title="Experiment"></a>Experiment</h3><ul><li>DeepSeekMoE์ ํจ๊ณผ์ฑ์ ๊ฒ์ฆํ๊ธฐ ์ํด, ๊ธฐ์กด ๋ชจ๋ธ๋ค๊ณผ ์ฑ๋ฅ ๋น๊ต</li></ul><ol><li>2B ํฌ๊ธฐ<ul><li>DeepSeekMoE 2B์ ๊ธฐ์กด Gshard 2.9B์ ๋น๊ตํ์ฌ 1.5๋ฐฐ ์ ์ Expert parameter์ ์ฐ์ฐ๋์ ์ฌ์ฉํ๋ฉด์๋ ๋์ผํ ์ฑ๋ฅ์ ๋ณด์</li></ul></li><li>16B ํฌ๊ธฐ<ul><li>DeepSeekMoE 16B๋ ๊ธฐ์กด์ llama2 7B์ ๋น์ทํ ์ฑ๋ฅ, but 40% ์ ๋์ ์ฐ์ฐ๋๋ง ์ฌ์ฉ</li><li>๋ ์ ์ ์ฐ์ฐ๋์ผ๋ก๋ ๋์ผํ ์ฑ๋ฅ์ ์ ์งํ ์ ์์์ ๋ณด์</li></ul></li><li>145B ํฌ๊ธฐ<ul><li>DeepSeekMoE 145B๋ Gshard ๋ณด๋ค ์ฐ์ํ ์ฑ๋ฅ, DeepSeek 67B ๋ชจ๋ธ๊ณผ ๋น๊ตํด์ ๋น์ทํ ์ฑ๋ฅ, but ์ฐ์ฐ๋์ DeepSeek 67Bdml 28.5%(ํน์ ์ต์ 18.2%)๋ง ์ฌ์ฉ</li><li>๋ง์ฐฌ๊ฐ์ง๋ก ๊ธฐ์กด ๋ฐฉ์ ๋๋น ์ฐ์ฐ๋์ ๋ํญ ์ค์ด๋ฉด์๋ ๋์ ์ฑ๋ฅ์ ์ ์งํ ์ ์์์ ๋ณด์</li></ul></li></ol><h2 id="Preliminaries-ํธ๋์คํฌ๋จธ์-MoE"><a href="#Preliminaries-ํธ๋์คํฌ๋จธ์-MoE" class="headerlink" title="Preliminaries: ํธ๋์คํฌ๋จธ์ MoE"></a>Preliminaries: ํธ๋์คํฌ๋จธ์ MoE</h2><ul><li><p>ํธ๋์คํฌ๋จธ ๊ธฐ๋ฐ์ ์ธ์ด ๋ชจ๋ธ์ ๊ธฐ๋ณธ์ ์ผ๋ก $L$๊ฐ์ standard transformer ๋ธ๋ก์ ์์์ ๊ตฌ์ฑ๋๋ค. ๊ฐ ๋ธ๋ก์ ๋ค์๊ณผ ๊ฐ์ด ํํ๋ ์ ์๋ค.<br>$$<br>u_{1:T}^{l} = Self-Att(h_{1:T}^{l-1}) + h_{1:T}^{l-1}<br>$$<br>$$<br>h_{t}^{l} = FFN(u_{t}^{l})+u_{tโ}^{l}<br>$$</p></li><li><p>์ ์์์ $T$๋ ์ํ์ค ๊ธธ์ด</p></li><li><p>$Slef-Att$ : ์
ํ ์ดํ
์
๋ชจ๋</p></li><li><p>$FFN(\cdot)$ : feed forward network</p></li><li><p>$u_{1:T}^{l} \in R^{T \times d}$ ๋ $l$ ๋ฒ์งธ ์ดํ
์
๋ชจ๋์ ๊ฑฐ์น ํ์ ๋ชจ๋ ํ ํฐ์ hidden state</p></li><li><p>$h_{t}^{l} \in R^{d}$ ๋ $l$ ๋ฒ์งธ ํธ๋์คํฌ๋จธ ๋ธ๋ก์ ํต๊ณผํ ํ $l$ ๋ฒ์งธ ํ ํฐ์ ์ถ๋ ฅ hidden state</p></li><li><p>์์์์ Layer Normalization์ ์๋ต</p></li><li><p>MoE ์ธ์ด ๋ชจ๋ธ์ ๊ตฌ์ฑํ๋ ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ์ ํธ๋์คํฌ๋จธ ๋ด์์ ํน์ ๊ฐ๊ฒฉ๋ง๋ค $FFN$ ์ MoE ๋ ์ด์ด๋ก ๋์ฒดํ๋ ๊ฒ</p></li><li><p>MoE ๋ ์ด์ด๋ ์ฌ๋ฌ Experts๋ก ๊ตฌ์ฑ๋๋ฉฐ, ๊ฐ Expert๋ ๊ตฌ์กฐ์ ์ผ๋ก Feed Forward Network์ ๋์ผํ ํํ๋ฅผ ๊ฐ๋๋ค.</p><ul><li>์ดํ ๊ฐ ํ ํฐ์ ํ๋์ Expert์ ํ ๋น ๋ ์๋ ์๊ณ , </li><li>๋ ๊ฐ์ Expert์ ํ ๋น๋ ์๋ ์๋ค.</li></ul></li><li><p>๋ง์ฝ $l$๋ฒ์งธ FFN ์ด MoE๋ ์ด์ด๋ก ๋์ฒด๋๋ค๋ฉด, ํด๋น ๋ ์ด์ด์์์ output hidden state $h_{t}^{l}$ ์ ๋ค์๊ณผ ๊ฐ์ผ ๊ณ์ฐ๋จ<br>$$<br>h_{t}^{l} = \Sigma_{i=1}^{N}(g_{i, t}FFN_{i}(u_{t}^{l})) + u_{t}^{l}<br>$$<br>์ด ์์ ์ถ๊ฐ์ ์ผ๋ก ์ค๋ช
ํ๋ฉด ๊ฐ Expert $FFN_{i}$ ๊ฐ ์
๋ ฅ $u_{t}^{l}$์ ์
๋ ฅ ๋ฐ์ ๊ฐ์ค์น g์ ๊ณฑํด์ ๋ํ๋ค. ์
๋ ฅ ut์ ๋ํ๋ ๊ฒ์ residual connection (์์ฐจ ์ฐ๊ฒฐ)๋ก ๋ณผ ์ ์์<br>$$<br>g_{i,t} = s_{i, t} \quad or \quad 0 \quad where \quad s_{i, t} \in Topk(<!โswig๏ฟผ0โ>e_{i}^{l})<br>$$<br>๊ฐ Expert์ ๋ํ ๊ฐ์ค์น $s_{i, t}$ ๊ฐ์ Softmax๋ก ๊ณ์ฐ๋จ.</p></li></ul><p><img src="/2025/03/19/DeepSeekMoE-%EC%9A%94%EC%95%BD/deepseek.png"><br>๊ทธ๋ฆผ (a)๋ Top-2 Routing ํ๋ moe ๋ ์ด์ด<br>๊ทธ๋ฆผ (b)๋ Fine-grained expert segmentation ์ ๋ต<br>๊ทธ๋ฆผ (c)๋ shared expert isolation ์ ๋ต, DeepSeekMoE ์ํคํ
์ฒ</p><h2 id="DeepSeekMoE-์ํคํ
์ฒ"><a href="#DeepSeekMoE-์ํคํ
์ฒ" class="headerlink" title="DeepSeekMoE ์ํคํ
์ฒ"></a>DeepSeekMoE ์ํคํ
์ฒ</h2><ul><li>DeepSeekMoE๋ 2๊ฐ์ง๋ฅผ ์ ์<ul><li>Fine-grained Expert Segmentation (์ธ๋ถํ๋ expert ๋ถํ )</li><li>Shared Expert Isolation (๊ณต์ ์ ๋ฌธ๊ฐ ๋ถ๋ฆฌ)</li></ul></li><li>์ด ๋๊ฐ์ง ์ ๋ต ๋ชจ๋ ๊ฐ๊ฐ์ Expert์ ์ ๋ฌธ์ฑ์ ๋์ฑ ๊ฐํํ๋ ๊ฒ์ ๋ชฉํ๋ก ํจ</li></ul><h3 id="Fine-Grained-Expert-Segmentation"><a href="#Fine-Grained-Expert-Segmentation" class="headerlink" title="Fine-Grained Expert Segmentation"></a>Fine-Grained Expert Segmentation</h3><ul><li>๊ธฐ์กด MoE ๊ตฌ์กฐ์์ ์ ๋ฌธ๊ฐ์ ์๊ฐ ์ ํ์ ์ด๋ฉด, ๊ฐ ์ ๋ฌธ๊ฐ์๊ฒ ํ ๋น๋ ํ ํฐ๋ค์ด ๋ค์ํ ์ข
๋ฅ์ ์ง์(Knowledge)์ ํฌํจํ ๊ฐ๋ฅ์ฑ์ด ๋์์ง</li><li>๊ฒฐ๊ณผ์ ์ผ๋ก, ํ๋์ ์ ๋ฌธ๊ฐ๊ฐ <strong>๋๋ฌด ๋ง์ ์ข
๋ฅ์ ์ง์์ ํ์ตํด์ผ ํ๋ฉฐ</strong>, ์ด๋ฌํ ์ง์๋ค์ ๋์์ ํจ๊ณผ์ ์ผ๋ก ํ์ฉ๋๊ธฐ๊ฐ ์ด๋ ค์</li><li>์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ๊ฐ ํ ํฐ์ด ๋ ๋ง์ ์ ๋ฌธ๊ฐ์๊ฒ ๋ผ์ฐํ
๋ ์ ์๋ค๋ฉด, ๊ฐ ์ ๋ฌธ๊ฐ๊ฐ ๋ ์ธ๋ถํ๋ ํน์ ์ง์๋ง์ ํ์ตํ ์ ์๋๋ก ์กฐ์ ํ ์ ์์</li><li>์ด๋ ๊ฒ ํ๋ฉด ์ ๋ฌธ๊ฐ๊ฐ <strong>๋์ฑ ์ง์ค๋(ํนํ๋) ์ง์์ ํ์ตํ ์ ์์ผ๋ฉฐ</strong>, ๊ฒฐ๊ณผ์ ์ผ๋ก <strong>๊ฐ ์ ๋ฌธ๊ฐ ๊ฐ์ ์ญํ ์ด ๋์ฑ ๋ช
ํํ๊ฒ ๋ถ๋ฐฐ</strong></li></ul><p>๊ตฌ์ฒด์ ์ผ๋ก, ๊ธฐ์กด MoE ์ํคํ
์ฒ(๊ทธ๋ฆผ (a))์์ <strong>๊ฐ ์ ๋ฌธ๊ฐ์ FFN์ ๐๊ฐ์ ๋ ์์ ์ ๋ฌธ๊ฐ๋ก ๋ถํ </strong>ํ๋ค.<br>์ด๋, ๊ฐ ์ ๋ฌธ๊ฐ์ FFN์ ์ค๊ฐ(hidden) ์ฐจ์์ ์๋ ํฌ๊ธฐ์ $\frac{1}{m}$๋ก ์ค์ธ๋ค. ๊ฐ ์ ๋ฌธ๊ฐ๊ฐ ์์์ง ๋งํผ, ํ์ฑํ๋๋ ์ ๋ฌธ๊ฐ์ ์๋ฅผ $๐$๋ฐฐ ์ฆ๊ฐ์์ผ, ์ ์ฒด ์ฐ์ฐ ๋น์ฉ์ <strong>๋์ผํ๊ฒ ์ ์ง</strong>ํ ์ ์๋๋ก ์กฐ์ ํฉ๋๋ค (๊ทธ๋ฆผ (b)).</p><h3 id="Shared-Expert-Isolation"><a href="#Shared-Expert-Isolation" class="headerlink" title="Shared Expert Isolation"></a>Shared Expert Isolation</h3><ul><li>๊ธฐ์กด์ ๋ผ์ฐํ
์ ๋ต์์๋, ์๋ก ๋ค๋ฅธ ์ ๋ฌธ๊ฐ์๊ฒ ํ ๋น๋ ํ ํฐ๋ค์ด ๊ณตํต์ ์ธ ์ง์์ด๋ ์ ๋ณด๋ฅผ ํ์๋ก ํ ์ ์์. ๊ทธ ๊ฒฐ๊ณผ, ์ฌ๋ฌ ์ ๋ฌธ๊ฐ๋ค์ด ๋์ผํ ์ง์์ ํ์ตํ๊ฒ ๋์ด ํ๋ผ๋ฏธํฐ ์ค๋ณต์ด ๋ฐ์ํจ.</li><li>๊ทธ๋ฌ๋, ํน์ ์ ๋ฌธ๊ฐ๋ฅผ ๊ณต์ ์ ๋ฌธ๊ฐ๋ก ์ง์ ํ์ฌ ์ฌ๋ฌ ๋ฌธ๋งฅ์์ ํ์ํ ๊ณตํต ์ง์์ ๋ด๋นํ๋๋ก ํ๋ฉด,๋ค๋ฅธ ์ ๋ฌธ๊ฐ๋ค์ ์ค๋ณต ํ์ต์ด ์ค์ด๋ค์ด ๋ชจ๋ธ์ด ๋์ฑ ํจ์จ์ ์ธ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง ์ ์์.</li><li>์ด๋ ์ ๋ฌธ๊ฐ specialization๋ฅผ ๊ฐํํ๊ณ , ๋ชจ๋ธ์ด ์ ์ ํ๋ผ๋ฏธํฐ๋ก๋ ํจ๊ณผ์ ์ธ ์ฑ๋ฅ์ ๋ด๋๋ก ๋ง๋ฆ.</li></ul><p>์ด๋ฅผ ์ํด, ์ธ๋ถํ๋ ์ ๋ฌธ๊ฐ ๋ถํ (Fine-Grained Expert Segmentation) ์ ๋ต๊ณผ ํจ๊ป $๐พโ$๊ฐ์ ์ ๋ฌธ๊ฐ๋ฅผ ๊ณต์ ์ ๋ฌธ๊ฐ๋ก ๋ฐ๋ก ๋ถ๋ฆฌํจ. ์ด๋,</p><ul><li>๋ผ์ฐํฐ ๋ชจ๋๊ณผ ๊ด๊ณ์์ด ๋ชจ๋ ํ ํฐ์ ํญ์ ์ด ๊ณต์ ์ ๋ฌธ๊ฐ๋ค์๊ฒ ๋ฐฐ์ ๋จ.</li><li>์ฐ์ฐ ๋น์ฉ์ ์ผ์ ํ๊ฒ ์ ์งํ๊ธฐ ์ํด, ๋ค๋ฅธ ์ ๋ฌธ๊ฐ๋ค์๊ฒ ๋ผ์ฐํ
๋๋ ํ์ฑ ์ ๋ฌธ๊ฐ ์๋ฅผ ๐พโ๋งํผ ๊ฐ์์ํด.</li><li>๊ทธ๋ฆผ (c) ์ฐธ๊ณ </li></ul>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Paper/">Paper</category>
<category domain="https://emjayahn.github.io/categories/Paper/LLM/">LLM</category>
<category domain="https://emjayahn.github.io/tags/LLM/">LLM</category>
<category domain="https://emjayahn.github.io/tags/Paper-Summary/">Paper Summary</category>
<category domain="https://emjayahn.github.io/tags/MoE/">MoE</category>
<category domain="https://emjayahn.github.io/tags/DeepSeekMoE/">DeepSeekMoE</category>
<comments>https://emjayahn.github.io/2025/03/19/DeepSeekMoE-%EC%9A%94%EC%95%BD/#disqus_thread</comments>
</item>
<item>
<title>[Study] Model-Free Prediction</title>
<link>https://emjayahn.github.io/2023/07/02/20230702-rl-model-free-prediction/</link>
<guid>https://emjayahn.github.io/2023/07/02/20230702-rl-model-free-prediction/</guid>
<pubDate>Sun, 02 Jul 2023 09:46:04 GMT</pubDate>
<description><p>๋ณธ ๊ธ์ David Silver์ ๊ฐ์๋ฅผ ๋ฃ๊ณ ์ ์ ๋ฆฌํ ๊ธ์ด๋ค. ์ด๋ฒ ๊ฐ์๋ model-free ๊ตฌ์กฐ๋ฅผ ์ดํด๋ณด๋ ๊ฐ์์ด๋ค.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>๋ณธ ๊ธ์ David Silver์ ๊ฐ์๋ฅผ ๋ฃ๊ณ ์ ์ ๋ฆฌํ ๊ธ์ด๋ค. ์ด๋ฒ ๊ฐ์๋ model-free ๊ตฌ์กฐ๋ฅผ ์ดํด๋ณด๋ ๊ฐ์์ด๋ค.</p><span id="more"></span><h3 id="model-free"><a href="#model-free" class="headerlink" title="model-free?"></a>model-free?</h3><p>์์ ๊ฐ์์์ state value๋ฅผ ๊ณ์ฐํ๋ ๊ฒ๋ค์ ๋ดค๋๋ฐ ์ด๋ฅผ ๊ณ์ฐํ ์ ์์๋ ์ด์ ๋ ์ฐ๋ฆฌ๊ฐ state transition probability๋ผ๋์ง, policy๋ผ๋์ง, reward๊ฐ ์ด๋ป๊ฒ ๋์ค๋์ง์ ๋ํ <code>probability</code>๋ฅผ ์๊ณ ์๊ธฐ ๋๋ฌธ์ ๊ฐ๋ฅํ๋ค.</p><p><strong>์ค๋ ๊ฐ์์์๋ ์ฐ๋ฆฌ๋ ์ฃผ์ด์ง environement์ ๋ํ ์ง์์ด ์๊ณ , ๊ทธ์ agent๊ฐ ๊ฒช๊ฒ ๋๋ experience(episode)๋ฅผ ํตํด ์ฃผ์ด์ง environement์ ๋ํ policy์ value๋ฅผ ์ถ์ธกํ๋ ๊ฒ์ด๋ค.</strong></p><h3 id="prediction"><a href="#prediction" class="headerlink" title="prediction?"></a>prediction?</h3><p>RL์์๋ ์ด๋์ ๋ evaluation๊ณผ interchangableํ๊ฒ ์ฐ์ด๋ ๊ฒ ๊ฐ๋ค.</p><p>๋ณดํต policy evaluation์ prediction problem์ ๋ฒ์ฃผ๋ก ๋ณธ๋ค.</p><aside>โ problem์ ๋ฒ์ฃผ๋ ๋ณดํต prediction, ๊ทธ๋ฆฌ๊ณ control๋ก ๋๋์ด์ง๋ค.</aside><h3 id="์ค๋-๋ฐฐ์ธ-๊ฒ๋ค"><a href="#์ค๋-๋ฐฐ์ธ-๊ฒ๋ค" class="headerlink" title="์ค๋ ๋ฐฐ์ธ ๊ฒ๋ค"></a>์ค๋ ๋ฐฐ์ธ ๊ฒ๋ค</h3><ul><li>Monte-Carlo (MC) Policy Evaluation</li><li>Temporal-Difference (TD) policy evaluation</li><li>TD($\lambda$) policy evaluation =โ MC์ TD(0)์ ์ฌ์ด</li><li>MC, TD, TD($\lambda$), ๊ทธ๋ฆฌ๊ณ DP์์ ๊ด๊ณ</li></ul><h2 id="Monte-Carlo-policy-evaluation"><a href="#Monte-Carlo-policy-evaluation" class="headerlink" title="Monte-Carlo policy evaluation"></a>Monte-Carlo policy evaluation</h2><h3 id="ํน์ง"><a href="#ํน์ง" class="headerlink" title="ํน์ง"></a>ํน์ง</h3><ul><li>์ํผ์๋๋ค๋ก๋ถํฐ ๋ฐฐ์ด๋ค. โ ๋ชจ๋ธ์ ์ ํํ ๋ชฐ๋ผ๋ ๊ด์ฐฎ๋ค.(Model-free)</li><li>Complete episode๋ค๋ก๋ถํฐ ๋ฐฐ์ด๋ค. (episode๊ฐ ์งํ๋๋ ๋์์ ๋ฐฐ์ฐ๋ ๊ฑด ์๋๋ค.)<ul><li>๋ฐ๋ผ์ episode๋ค์ terminate๋์ด์ผ ํ๋ค. (terminal state์ ์ํด์๋ , ์๋๋ฉด episode ์ต๋ ์ซ์๋ฅผ ํตํด์๋ )</li></ul></li><li><strong>์ฌ๋ฌ state transition์ ๊ฒช์ reward๋ค์ ๋ฐํ์ผ๋ก ๊ณ์ฐํ๋ ํ๊ท return์ ๋ฐํ์ผ๋ก value๋ฅผ ์ถ์ ํ๋ค.</strong></li></ul><h3 id="์ค์ -evaluation-๊ณผ์ "><a href="#์ค์ -evaluation-๊ณผ์ " class="headerlink" title="์ค์ evaluation ๊ณผ์ "></a>์ค์ evaluation ๊ณผ์ </h3><ul><li>์ฃผ์ด์ง policy์ ๋ฐ๋ผ agent๋ episode๋ฅผ ๊ฒฝํํ๊ฒ ๋๋ค.</li><li>์ด์ ์๋ ๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ณ ๋ คํด expected return์ ๊ตฌํ์๋ค๋ฉด, ์ง๊ธ์ model์ ๋ํ ์ง์์ด ์์ผ๋ ๊ฒฝํ์ ์์กดํด์๋ง expected return์ ๊ตฌํ๋ค.</li></ul><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled.png" alt="Untitled"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled1.png" alt="Untitled"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled2.png" alt="Untitled"></p><ol><li>์ผ๋จ episode๋ฅผ ์์ํ๊ณ , ์ฃผ์ด์ง policy์ ๋ฐ๋ผ action์ ์ทจํ๋ฉด์ reward๋ฅผ ์ป๊ณ , ์ด๋ฅผ ํตํด $G_t$๋ฅผ ๊ตฌํ ์ ์๋ค.</li><li>First-visit์ธ์ง, Every-visit์ธ์ง์ ๋ฐ๋ผ<ol><li>์ด๋ค state์ visitํ๋ฉด ํด๋น state์ count ๊ฐ(N(s))์ ์ฌ๋ฆฌ๊ณ , </li><li>visitํ ๋น์์ $G_t$๊ฐ์ S(s)์ ๋์ ํด ์ค๋ค.</li><li>(First-visit์ด๋ฉด ๋ง๊ทธ๋๋ก ์ฒ์ state์ ๋๋ฌํ์ ๋๋ง ์ ๊ณ์ฐ์ ํด์ค๋ค.)</li></ol></li><li>๋ชจ๋ episode์ ๋ํด ์์ ๊ฐ์ ๊ณ์ฐ์ ๋๋ง์ณ์ฃผ๊ณ ๋ ๋๋ค์ N(s)์ S(s)๋ฅผ ํตํด์ ํ๊ท ์ ๋ด์ค๋ค.</li></ol><h3 id="MC-Example"><a href="#MC-Example" class="headerlink" title="MC Example"></a>MC <strong>Example</strong></h3><p>State sequence๊ฐ ๋ค์๊ณผ ๊ฐ์ด ์ฃผ์ด์ก๋ค๊ณ ํ์. (action๊ณผ reward๋ ์๋ต)</p><p>s1 โ s2 โ s3 โ s4 โ s2 โ sF</p><p>์ฌ๊ธฐ์ s2์ state value๋ฅผ ๊ตฌํด๋ณด์.</p><p>First Visit์ ๊ฒฝ์ฐ</p><p>Gt: (s2, s3, s4, s2, sF)๋ฅผ ํตํด return์ ๊ตฌํ๋ค.</p><p>N(s2)=1</p><p>Every Visit:</p><p>Gt1: (s2, s3, s4, s2, sF)์ ํตํด return์ ๊ตฌํ๋ค.</p><p>Gt2 : (s2, sF)์ ํตํด return์ ๊ตฌํ๋ค.</p><p>s(s2) = Gt1 + Gt2</p><p>V(s2) = (Gt1 + Gt2)/2</p><h3 id="Blackjack-example"><a href="#Blackjack-example" class="headerlink" title="Blackjack example"></a>Blackjack example</h3><p>์์งํ ์ ๋นํ ์๋ผ๊ณ ๋ ์๊ฐ๋์ง ์์ง๋ง model-free์ ๋ํ ์์ ๋ก ์๊ฐํ๋ค.</p><h3 id="Incremental-MC-update"><a href="#Incremental-MC-update" class="headerlink" title="Incremental MC update"></a>Incremental MC update</h3><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled3.png" alt="Untitled"></p><ul><li>์ฐ๋ฆฌ๊ฐ ์ด๋ค ๊ฐ๋ค์ ํ๊ท ์ ๊ตฌํ ๋, ๋งจ ๋ง์ง๋ง์ ํ๊บผ๋ฒ์ ๊ตฌํ ์๋ ์์ง๋ง</li><li>์ด์ ์ ๊ตฌํด ๋์ ํ๊ท ์ ์ด์ฉํด์ ๊ตฌํ ์ ์๋ค.</li></ul><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled4.png" alt="Untitled"></p><ul><li>๋ง์ฐฌ๊ฐ์ง๋ก V(S) (return๋ค์ ํ๊ท )์ ๊ตฌํ ๋๋, ์ด์ ์ ๊ตฌํด ๋์ V(S) ๊ฐ๊ณผ ์๋กญ๊ฒ ์ป๊ฒ ๋ $G_t$๊ฐ์ ์ด์ฉํด ๊ตฌํ ์ ์๋ค.</li><li>์๋์ ๊ฐ์ด ํน์ ์์($\alpha$)๋ฅผ ์ด์ฉํด์ ์ด์ ์ ๊ตฌํด๋์ ํ๊ท ๊ณผ ์๋กญ๊ฒ ์ป๊ฒ ๋ ๊ฐ์ ์ด๋ค ์์ผ๋ก ์ด์ฉํ ๊ฒ์ธ์ง weight๋ฅผ ๊ณ ์ ํด์ ์ค ์ ์๋ค.</li></ul><h2 id="Temporal-difference-TD-policy-evaluation"><a href="#Temporal-difference-TD-policy-evaluation" class="headerlink" title="Temporal-difference (TD) policy evaluation"></a>Temporal-difference (TD) policy evaluation</h2><h3 id="ํน์ง-1"><a href="#ํน์ง-1" class="headerlink" title="ํน์ง"></a>ํน์ง</h3><ul><li>**(MC์ ๋์ผ)**์ํผ์๋๋ค๋ก๋ถํฐ ๋ฐฐ์ด๋ค. โ ๋ชจ๋ธ์ ์ ํํ ๋ชฐ๋ผ๋ ๊ด์ฐฎ๋ค.(Model-free)</li><li><strong>(MC์ ์์ด)</strong> incomplete episode๋ค๋ก๋ถํฐ ํ์ตํ ์ ์๋ค. (<code>bootstrapping</code>)</li></ul><h3 id="MC์-TD์-๋น๊ต"><a href="#MC์-TD์-๋น๊ต" class="headerlink" title="MC์ TD์ ๋น๊ต"></a>MC์ TD์ ๋น๊ต</h3><h3 id="MC"><a href="#MC" class="headerlink" title="MC"></a>MC</h3><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled5.png" alt="Untitled"></p><p>์ค์ complete episode๋ฅผ ํตํด ์๊ณ ์๋ $G_t$๋ฅผ ํตํด ์
๋ฐ์ดํธ ํ๋ค.</p><h3 id="TD-0"><a href="#TD-0" class="headerlink" title="TD(0)"></a>TD(0)</h3><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled6.png" alt="Untitled"></p><p>MC์ฒ๋ผ ์ง์ง $G_t$๊ฐ์ด ์๋ $G_t$์ estimator๋ผ๊ณ ํ ์ ์๋ $R_{t+1}+\gamma V(S_{t+1})$์ ์ฌ์ฉํ๋ค.</p><ul><li>$V(S_{t+1})$์ด ์ต์ข
์ ์ธ ๊ฐ์ด ์๋๊ธฐ ๋๋ฌธ์ estimate์ธ ๊ฒ์ด๋ค.</li><li>์์ $V(S_{t+1})$ ๊ฐ์ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์ ๊ผญ episode๋ฅผ completeํ์ง ์๋๋ผ๋ ๋ฐ๋ก๋ฐ๋ก ์
๋ฐ์ดํธํ ์ ์๋ค. (<code>online</code>)</li></ul><aside>โ TD์์ ๋นจ๊ฐ ๋ถ๋ถ์ TD ๋ค์ ๋ค์ด๊ฐ๋ ์ซ์์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋ค.</aside><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled7.png" alt="Untitled"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled8.png" alt="Untitled"></p><ul><li>State value๋ฅผ reward๊ฐ ์๋ ๊ทธ state์์๋ถํฐ ์ง๊น์ง ๊ฑธ๋ฆฌ๋ ์์ ์๊ฐ์ด๋ผ๊ณ ํ์.</li><li>MC ๊ฐ์ ๊ฒฝ์ฐ์๋ ๋ค์ state์์ ๋ญ๋ผ๊ณ ์๋กญ๊ฒ ์์ธกํ๋ ์๊ด์์ด ์ฒ์๋ถํฐ ๋๊น์ง ๋ค ๊ฐ๋ณธ ๋ค์, ์ค์ ์ง๊น์ง ๊ฑธ๋ฆฐ ์๊ฐ๊ณผ, ๊ทธ state์์ ์์ํ ๊ฑธ๋ฆฐ ์๊ฐ์ ์ฐจ๋ฅผ ๊ฐ์ง๊ณ ๊ณ์ฐํ๋ค.</li><li>TD ๊ฐ์ ๊ฒฝ์ฐ์๋ ์ด์ state value๋ฅผ ์
๋ฐ์ดํธํ ๋, ํ์ฌ state value๋ง์ ์ด์ฉํด์ ์
๋ฐ์ดํธํ๋ค.<ul><li>ํ์ฌ state value๊ฐ ์ค์ ๋ก ์ ํํ๋ ์๋๋ ์๊ด์ด ์๋ค. ๋ฐ๋ณตํ๋ค ๋ณด๋ฉด ๋ง์ ๊ฐํ
๋๊น</li></ul></li></ul><h3 id="MC-vs-TD-2"><a href="#MC-vs-TD-2" class="headerlink" title="MC vs TD (2)"></a>MC vs TD (2)</h3><h3 id="MC-1"><a href="#MC-1" class="headerlink" title="MC"></a>MC</h3><ul><li>์ํผ์๋๊ฐ ๋๋์ return์ ์์๋ผ ๋๊น์ง ๊ธฐ๋ค๋ ค์ผ ๋๋ค.</li><li>terminate๊ฐ ๊ผญ ํ์ํ๋ค.</li></ul><h3 id="TD"><a href="#TD" class="headerlink" title="TD"></a>TD</h3><ul><li>episode๊ฐ ๋๋์ง ์์๋ ๋งค step๋ง๋ค ์
๋ฐ์ดํธ๊ฐ ๊ฐ๋ฅ (online)</li><li>๋ฐ๋ก๋ฐ๋ก ๋ฐฐ์ธ ์ ์์ผ๋ฏ๋ก ๊ผญ episode๊ฐ ๋๋ ํ์๋ ์๋ค.</li></ul><h3 id="MC-vs-TD-3-Bias-x2F-Variance"><a href="#MC-vs-TD-3-Bias-x2F-Variance" class="headerlink" title="MC vs TD (3) - Bias/Variance"></a>MC vs TD (3) - Bias/Variance</h3><h3 id="MC-2"><a href="#MC-2" class="headerlink" title="MC"></a>MC</h3><ul><li>$G_t$=unbiased estimate of $v_{\pi}(S_t)$</li><li>Zero bias</li><li>$G_t$๋ ๋ค์ ๋ง์ random variable์ด ๋ฐ๋ผ์ค๋ฏ๋ก variance๊ฐ ๋๋ค.</li><li>initial value์ ๋ sensitiveํ๋ค.</li></ul><h3 id="TD-1"><a href="#TD-1" class="headerlink" title="TD"></a>TD</h3><ul><li>โTrueโ TD target = $R_{t+1}+\gamma v_\pi (S_{t+1})$=unbiased estimate of $v_\pi (S_t)$</li><li>TD target = $R_{t+1}+\gamma V (S_{t+1})$=biased estimate of $v_\pi (S_t)$</li><li>TD target์ ํ๊ฐ์ง action๊ฐ๊ณผ ์ด๋ฏธ ์ ํด์ง V๊ฐ์๋ง ์์กดํ๋ฏ๋ก variance๊ฐ ๋ฎ๋ค.</li><li>intial value์ sensitiveํ๋ค.</li></ul><h3 id="Random-walk-example"><a href="#Random-walk-example" class="headerlink" title="Random walk example"></a>Random walk example</h3><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled9.png" alt="Untitled"></p><ul><li>์ฒ์์ 0.5๋ก value๋ค์ด initialize๋์ด ์๋ค๊ฐ</li><li>๊ณ์ episode๊ฐ ๋์ด๋ ์๋ก true value(์๋ง๋ DP๋ก ๊ตฌํ์ ๋ฒํ)๋ก ์๋ ดํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.</li></ul><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled10.png" alt="Untitled"></p><ul><li>TD๊ฐ MC๋ณด๋ค ๋ ๋น ๋ฅด๊ฒ True value์ ์ ๊ทผํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.</li></ul><h2 id="Batch-MC-and-TD"><a href="#Batch-MC-and-TD" class="headerlink" title="Batch MC and TD"></a>Batch MC and TD</h2><ul><li>episode๋ฅผ ๋ฌดํํ ๋ง์ด ๋๋ฆฌ๋ฉด V(s)๊ฐ $v_{\pi}(s)$์ ๊ฐ๊น์ ์ง๊ฒ ์ง๋ง ์ค์ ๋ก๋ ๊ทธ๋ ๊ฒ ํ ์ ์๋ค.</li><li>๊ทธ๋์ finiteํ k๊ฐ์ episode ์ค์์ ๊ณ์ sampleํด์ MC๋ TD๋ฅผ ์ํํ๋ค.</li></ul><h3 id="AB-example"><a href="#AB-example" class="headerlink" title="AB example"></a>AB example</h3><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled11.png" alt="Untitled"></p><ul><li>๋ณด๋ฉด A์ ๊ฒฝ์ฐ์๋ B๊ฐ 0์ reward๋ฅผ ๋ฐ๋ episode ํ๊ฐ์ง๋ง ๊ฒช๊ณ ์๋ค.</li><li>MC์ TD๋ฅผ ๋๋ ธ์ ๋ V(A)์ V(B)๋ ์ด๋ป๊ฒ ๋ ๊น?</li></ul><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled12.png" alt="Untitled"></p><ul><li><p>MC ๊ฐ์ ๊ฒฝ์ฐ์๋ $G_t$์ ์๋ฌ, ์ฆ episode์ ์ ์ฒด trace์ ์๋ฌ๋ฅผ ์ค์ด๋ ค๋ ๋ฐฉํฅ์ผ๋ก solution์ ๋ง๋ ๋ค.</p><p> <img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled13.png" alt="Untitled"></p></li><li><p>TD ๊ฐ์ ๊ฒฝ์ฐ์๋ ๊ฐ state์ ์๋ฌ๋ฅผ ์ค์ด๋ ค๋ ๋ฐฉํฅ์ผ๋ก ์๋ ดํ๊ฒ ๋๋ค.</p><ul><li><p>Maximum-liklihood Markov model)์ ๋ง๋๋ ๊ฒ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ค. (state transition probability distribution๊ณผ reward probabilty๋ฅผ ๋ชจ๋ธ๋งํจ)</p><p> <img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled14.png" alt="Untitled"></p><p> <img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled15.png" alt="Untitled"></p></li><li><p>Markov property๋ฅผ ์ ๊ทน ์ด์ฉํ๋ ์
: V(A) ~ R(A)+$\gamma$V(B)</p></li></ul></li></ul><h2 id="Dynamic-programming-Monte-Carlo-and-Temproal-Difference"><a href="#Dynamic-programming-Monte-Carlo-and-Temproal-Difference" class="headerlink" title="Dynamic programming, Monte-Carlo, and Temproal-Difference"></a>Dynamic programming, Monte-Carlo, and Temproal-Difference</h2><p>policy evaluation process๋ฅผ 2๊ฐ์ง ์ธก๋ฉด์ผ๋ก ๋๋ ์ ์๊ฐํ ์ ์๋ค.</p><ul><li>Bootstrapping: estimate์ ์ด์ฉํด์ state value๋ฅผ updateํ ๊ฒ์ธ๊ฐ<ul><li>MC: ๋๊น์ง episode๋ฅผ ์งํํ ํ์ ๊ณ์ฐ์ด ๋๋ฏ๋ก estimate๋ฅผ ์ฐ์ง ์์ โ <strong>No bootstrapping</strong></li><li>DP, TD: ๋ค์ ๋ฒ state value esimtation์ ๊ฐ์ง๊ณ ํ์ฌ state value๋ฅผ update๋ฅผ ํ๋ค. โ <strong>Bootstrapping</strong></li></ul></li><li>Sampling: ๋์ฌ ์ ์๋ ๊ฒฝ์ฐ์ ์๋ฅผ ์ ๋ถ๋ค ์ธ ๊ฒ์ธ๊ฐ ๊ทธ ์ค ํ๋๋ง sampleํด์ ์ธ ๊ฒ์ธ๊ฐ<ul><li>MC, TD: ๋์ฌ ์ ์๋ ๋ชจ๋ state transition์ ๊ณ ๋ คํ๋ ๊ฒ์ด ์๋๋ผ episode์์ ์ค์ ๋ฐ์ํ ๊ฒ๋ง sampleํด์ ์ฐ๋ ๊ฒ์ด๋ฏ๋ก โ <strong>Sampling</strong></li><li>DP: ๋ชจ๋ state transition์ ๊ณ ๋ คํด์ updateํ๋ฏ๋ก โ <strong>No sampling</strong></li></ul></li></ul><table><thead><tr><th></th><th>Bootstrapping</th><th>No bootstrapping</th></tr></thead><tbody><tr><td>No sampling</td><td>DP</td><td></td></tr><tr><td>Sampling</td><td>TD</td><td>MC</td></tr></tbody></table><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled16.png" alt="Untitled"></p><h2 id="TD-lambda"><a href="#TD-lambda" class="headerlink" title="TD($\lambda$)"></a>TD($\lambda$)</h2><h3 id="n-step-prediction"><a href="#n-step-prediction" class="headerlink" title="n-step prediction"></a>n-step prediction</h3><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled17.png" alt="Untitled"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled18.png" alt="Untitled"></p><ul><li>์ง๊ธ๊น์ง ๋ดค๋ TD์ ๊ฒฝ์ฐ์๋ TD(0)๋ก์จ ๋ฑ ํ์ฌ์ step์ ๋ดค์ง๋ง</li><li>์ฌ๊ธฐ์ ๋ณํ์ ์ฃผ์ด์ <strong>n-step๊น์ง</strong> ํ์ฉํ๊ฒ ํ ์๋ ์๋ค.</li><li>์ด n์ ๋ฌดํ๋๋ก ๋๋ ค ๋์ ๊ฒ์ด Monte-Carlo์ด๋ค.</li></ul><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled19.png" alt="Untitled"></p><ul><li>์์ ๊ทธ๋ํ๋ ๋ค์ํ n-step์ ์ด์ฉํ์ ๋์ RMS์ ๋ณด์ฌ์ค๋ค.</li><li>1์ด TD์ด๊ณ , ์ซ์๊ฐ ์ปค์ง์๋ก MC๊ฐ ๋๋ค.</li><li><strong>์ฃผ๋ชฉํ ์ ์ ์๋ฌ๊ฐ ๊ฐ์ฅ ์์์ง๋ ํน์ ํ n์ด ์กด์ฌํ๋ค๋ ์ ์ด๋ค.</strong></li></ul><h3 id="Averaging-n-Step-returns"><a href="#Averaging-n-Step-returns" class="headerlink" title="Averaging n-Step returns"></a>Averaging n-Step returns</h3><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled20.png" alt="Untitled"></p><ul><li>๊ทธ๋ ๋ค๋ฉด ์ฐ๋ฆฌ๋ ์ด๋ค n์ ์จ์ผํ ๊น?</li><li>์ด๋ฌํ ์ ์ ํ์คํ ๋ชจ๋ฅด๊ธฐ ๋๋ฌธ์ ์ฐ๋ฆฌ๋ ์ฌ๋ฌ๊ฐ์ง n์ ํจ๊ป ์จ์ ํ๊ท ์ ๋ด๋ ๋ฐฉ๋ฒ์ผ๋ก optimal n์ ๋ชจ๋ฅด๋๋ผ๋ ์ ๋นํ ์ข์ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์๋ค.</li><li>์์ ์์ ์์๋ n=2์ n=4๋ฅผ ํจ๊ป ์ด์ฉํ์๋ค.</li><li><strong>๊ทธ๋ ๋ค๋ฉด ๋ช ๊ฐ์ n์ ์์ ๊ฒ์ด๋ฉฐ ์ด๋ค n๋ค์ ์์ ๊ฒ์ธ์ง ์ด๋ป๊ฒ ์ ํ ๊ฒ์ธ๊ฐ?</strong></li></ul><h3 id="TD-lambda-1"><a href="#TD-lambda-1" class="headerlink" title="TD($\lambda$)"></a>TD($\lambda$)</h3><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled21.png" alt="Untitled"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled22.png" alt="Untitled"></p><ul><li>$(1-\lambda), (1-\lambda)\lambda, (1-\lambda)\lambda^2, \cdots$์ฒ๋ผ weight๋ฅผ ๋ง๋ค์ด์</li><li>๊ฐ๊ฐ์ Return estimate($G_t^{(n)}$)์ ๊ณฑํด์ค๋ค.</li><li>๊ทธ๋ฌ๋ฉด ๋ช๊ฐ์ n-step์ ์์ด ๋ฃ๋ weight๋ค์ ํฉ์ด 1์ด ๋๊ฒ ๋๋ค.</li><li>(๋น์ฐํ 1-step return์ด ๊ฐ์ฅ ํฐ ๋น์ค์ ์ฐจ์งํ๊ฒ ๋ ๊ฒ์ด๋ค.)</li></ul><h3 id="Forward-view-and-backward-view-of-TD-lambda"><a href="#Forward-view-and-backward-view-of-TD-lambda" class="headerlink" title="Forward view and backward view of TD($\lambda$)"></a>Forward view and backward view of TD($\lambda$)</h3><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled23.png" alt="Untitled"></p><ul><li>๊ฒฐ๊ตญ MC์ ๋ง์ฐฌ๊ฐ์ง๋ก TD($\lambda$)๋ฅผ ๊ณ์ฐํ๊ธฐ ์ํด์๋ ๋ค์ state๋ค๊ณผ ๊ทธ์ ํด๋นํ๋ return๋ค์ด ํ์ํ๋ค.</li><li>๋ฐ๋ผ์ episode๊ฐ ๋๋์ผ์ง๋ง ๊ณ์ฐํ ์ ์๋ค. (์ด๋ก ์ ์ผ๋ก๋ ๊ทธ๋ ๋ค.)</li></ul><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled24.png" alt="Untitled"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled25.png" alt="Untitled"></p><ul><li>ํ์ง๋ง ์ค์ ๋ก TD($\lambda$)๋ฅผ ๊ตฌํํ ๋๋</li><li>Eligibility Trace๋ผ๋ ๊ฒ์ ๊ฐ state๋ง๋ค ๊ธฐ๋กํด์</li><li>ํ์ํ ์ ๋ณด๊ฐ ๋์จ ๊ณณ๊น์ง์ $G_t^{(\lambda)}$๊น์ง ๊ธฐ๋กํด์ค๋ค.</li></ul><p><img src="/2023/07/02/20230702-rl-model-free-prediction/Untitled26.png" alt="Untitled"></p><ul><li>Eligibility trace๋ผ๋ ๊ฒ์ ์์ ๊ฐ์ด ๊ณ์ฐํ ์ ์๋ค.</li><li>$\gamma$์ ์ํด์ episode๊ฐ ์งํ๋จ์ ๋ฐ๋ผ ๊ฐ์ด ์์ํ ์ค์ด๋ ๋ค. (์ต๊ทผ์ state visit์ ๋ ๊ฐ์ค์น๋ฅผ ์ฃผ๋ Recency heuristic)</li><li>๊ทธ๋ฆฌ๊ณ state visit๋ง๋ค 1์ฉ ๋ํด์ค๋ค. (์ผ๋ง๋ ์์ฃผ visitํ๋์ง์ ๊ฐ์ค์น๋ฅผ ์ฃผ๋ Frequency heuristic)</li></ul><p><img src="/2023/07/02/20230702-rl-model-free-prediction/lec4-td_lambda.001.jpeg" alt="lec4-td_lambda.001.jpeg"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/lec4-td_lambda.002.jpeg" alt="lec4-td_lambda.002.jpeg"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/lec4-td_lambda.003.jpeg" alt="lec4-td_lambda.003.jpeg"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/lec4-td_lambda.004.jpeg" alt="lec4-td_lambda.004.jpeg"></p><p><img src="/2023/07/02/20230702-rl-model-free-prediction/lec4-td_lambda.005.jpeg" alt="lec4-td_lambda.005.jpeg"></p><p><img src="/lec4-td_lambda.0011.jpeg" alt="lec4-td_lambda.001.jpeg"></p><h3 id="lambda-์-๋ฐ๋ฅธ-backward-view์-forward-view์์-๊ด๊ณ"><a href="#lambda-์-๋ฐ๋ฅธ-backward-view์-forward-view์์-๊ด๊ณ" class="headerlink" title="$\lambda$์ ๋ฐ๋ฅธ backward view์ forward view์์ ๊ด๊ณ"></a>$\lambda$์ ๋ฐ๋ฅธ backward view์ forward view์์ ๊ด๊ณ</h3><ul><li>๋น์ฐํ forward view๋ ๋ชจ๋ episode๊ฐ ๋๋์ผ ์์ฑ์ด ๋๊ณ , backward view์ ๊ฐ์์ง๋ฏ๋ก onlie update์ผ ๊ฒฝ์ฐ์๋ forward view โ backward view์ธ ์๊ฐ๋ค์ด ์๋ค.<ul><li>์์์ ์ด Eligibility trace๋ง๊ณ ๋ณํ์ ์ฌ์ฉํ๋ฉด online์ผ ๋๋ ๊ฐ๋ค๊ณ ํ๋ค.</li></ul></li><li>๊ทธ๋ฌ๋ ๊ธฐ๋ณธ์ ์ผ๋ก backward์ forward๋ ๊ฐ์์ผ ํ๊ณ , $\lambda=0$์ผ ๋๋ TD(0), $\lambda=1$์ผ ๋๋ every visit MC์ equivalentํ๋ค.</li></ul>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/DataScience/">DataScience</category>
<category domain="https://emjayahn.github.io/tags/Reinforcement-Learning/">Reinforcement Learning</category>
<comments>https://emjayahn.github.io/2023/07/02/20230702-rl-model-free-prediction/#disqus_thread</comments>
</item>
<item>
<title>[Study] Reinforcement Learning Basic</title>
<link>https://emjayahn.github.io/2023/06/04/20230604-rl-basic/</link>
<guid>https://emjayahn.github.io/2023/06/04/20230604-rl-basic/</guid>
<pubDate>Sun, 04 Jun 2023 06:42:41 GMT</pubDate>
<description><h1 id="Lec1-Intro-to-RL"><a href="#Lec1-Intro-to-RL" class="headerlink" title="Lec1 Intro to RL"></a>Lec1 Intro to RL</h1><h2 id="1-About-Reignforcement-Learning"><a href="#1-About-Reignforcement-Learning" class="headerlink" title="1. About Reignforcement Learning"></a>1. About Reignforcement Learning</h2><h3 id="1-1-๋ค์ํ-๋ถ์ผ์์์-๊ฐํํ์ต"><a href="#1-1-๋ค์ํ-๋ถ์ผ์์์-๊ฐํํ์ต" class="headerlink" title="1.1 ๋ค์ํ ๋ถ์ผ์์์ ๊ฐํํ์ต"></a>1.1 ๋ค์ํ ๋ถ์ผ์์์ ๊ฐํํ์ต</h3><p>๋ค์ํ ๋ถ์ผ์์ RL๊ณผ ๊ฐ์ ํน์ ๋น์ทํ ๊ฐ๋
์ ์ฐ๊ตฌ์ ์๋๊ฐ ๊ณ์ ๋๊ณ ์์ต๋๋ค. ์ฌ๊ธฐ์ ์๋ก ๋ค๋ฅธ ๋ถ์ผ๋ผ ํ ์ง๋ผ๋ ๊ณต์ ๋๋ ํต์ฌ Key Concept์ โDecision Makingโ ์
๋๋ค.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><h1 id="Lec1-Intro-to-RL"><a href="#Lec1-Intro-to-RL" class="headerlink" title="Lec1 Intro to RL"></a>Lec1 Intro to RL</h1><h2 id="1-About-Reignforcement-Learning"><a href="#1-About-Reignforcement-Learning" class="headerlink" title="1. About Reignforcement Learning"></a>1. About Reignforcement Learning</h2><h3 id="1-1-๋ค์ํ-๋ถ์ผ์์์-๊ฐํํ์ต"><a href="#1-1-๋ค์ํ-๋ถ์ผ์์์-๊ฐํํ์ต" class="headerlink" title="1.1 ๋ค์ํ ๋ถ์ผ์์์ ๊ฐํํ์ต"></a>1.1 ๋ค์ํ ๋ถ์ผ์์์ ๊ฐํํ์ต</h3><p>๋ค์ํ ๋ถ์ผ์์ RL๊ณผ ๊ฐ์ ํน์ ๋น์ทํ ๊ฐ๋
์ ์ฐ๊ตฌ์ ์๋๊ฐ ๊ณ์ ๋๊ณ ์์ต๋๋ค. ์ฌ๊ธฐ์ ์๋ก ๋ค๋ฅธ ๋ถ์ผ๋ผ ํ ์ง๋ผ๋ ๊ณต์ ๋๋ ํต์ฌ Key Concept์ โDecision Makingโ ์
๋๋ค.</p><span id="more"></span><p><img src="/2023/06/04/20230604-rl-basic/Untitled.png" alt="Untitled"></p><h3 id="1-2-๊ฐํํ์ต์-ํน์ง"><a href="#1-2-๊ฐํํ์ต์-ํน์ง" class="headerlink" title="1.2 ๊ฐํํ์ต์ ํน์ง"></a>1.2 ๊ฐํํ์ต์ ํน์ง</h3><ul><li>No supervisor, but <strong>reward signal</strong><ul><li>๋ง๋ถ์ด์๋ฉด, ํํ ์ง๋ํ์ต(supervised learning)์์๋ ์ฐ๋ฆฌ๊ฐ ์ ๊ณตํ๋ ์ ๋ต ๋ฐ์ดํฐ์ ์ค๊ณํ Loss Function์ ์ด์ฉํด ๋ชจ๋ธ์ Feedback์ ์ฃผ์ง๋ง, ๊ฐํํ์ต์์๋ ์ ๋ต์ด๋ผ๋ ๋ฐ์ดํฐ๋ฅผ ์ ๊ณตํ์ง ์์์ฑ, Agent ์ Action ์ ๋ํด โ์ค๊ตฌ ์ํ์ด 5์ โ, โ๊ทธ๊ฑด ์ข ๋ณ๋ก ๋ฐ? 1์ โ ๊ณผ ๊ฐ์ด reward ๋ก feedback ์ ์ ๊ณตํฉ๋๋ค.</li></ul></li><li>Delayed Feedback, Not instantaneous<ul><li>Agent ์ ์ง๊ธ์ ๊ฒฐ์ (action)์ด ์ข์๋์ง/๋๋นด๋์ง๊ฐ ๋ช ์คํ
ํ์ ๋์จ๋ค๋ ๊ฒ์ด ํน์ง์
๋๋ค.</li></ul></li><li>Sequential, not i.i.d data<ul><li>(FYI) i.i.d : independent identical distribution (Random Variable ์ ๋
๋ฆฝ, ๋์ผ ํ๋ฅ ๋ถํฌ)</li><li>๊ฐํํ์ต์ ๋ฐ์ดํฐ๋ ์๊ณ์ด์ ์ธ(Sequential) ๋ฐ์ดํฐ</li></ul></li><li>Agentโs actions affect the subsequent data<ul><li>Agent ์ ํ๋์ด reward์ received data ์ ์ํฅ์ ์ค๋๋ค.</li><li>EX) ๋ก๋ด์ด ์์ง์ผ ๋๋ง๋ค ๋ก๋ด์ด ๋ณด๋ ํ๋ฉด๊ณผ reward๊ฐ ๊ฐ๊ฐ ๋ฌ๋ผ์ง๋๋ค.</li></ul></li></ul><p><img src="/2023/06/04/20230604-rl-basic/Untitled01.png" alt="Untitled"></p><h2 id="2-The-Reinforcement-Learning-Problem"><a href="#2-The-Reinforcement-Learning-Problem" class="headerlink" title="2. The Reinforcement Learning Problem"></a>2. The Reinforcement Learning Problem</h2><h3 id="2-1-Rewards"><a href="#2-1-Rewards" class="headerlink" title="2.1 Rewards"></a>2.1 Rewards</h3><ul><li>reward $R_t$ : scalar feedback signal<ul><li>์๊ฐ t ์์ agent ์ action (or ์ ํ)์ด ์ผ๋ง๋ ์ ํ ๊ฒ์ธ์ง ๋ํ๋ด๋ ํผ๋๋ฐฑ ์ ํธ</li><li>agent์ ๋ชฉํ : ๋์ reward์ ์ต๋ํ (maximise cumulative reward)</li><li>RL ์ <code>reward hypothesis</code> ์์์ ์ด๋ฃจ์ด์ง๋ค</li></ul></li><li>Reward Hypothesis<ul><li>All goals can be described by the maximisation of expected cumulative reward</li><li><strong>๋ชจ๋ ๋ชฉํ๋ ๋์ reward์ ๊ธฐ๋๊ฐ์ ์ต๋ํ ํ๋ ๊ฒ์ผ๋ก ์ก์ ์ ์๋ค.</strong> (์์ง ๊ตฌ์ฒด์ ์ผ๋ก ๋๋์ ์ค์ง ์์.. ๊ณผ์ฐ ๊ทธ๋ฐ๊ฐ..?)</li></ul></li></ul><h3 id="2-2-Sequential-Decision-Making"><a href="#2-2-Sequential-Decision-Making" class="headerlink" title="2.2 Sequential Decision Making"></a>2.2 Sequential Decision Making</h3><ul><li>RL ์ ๊ฒฐ๊ตญ sequential decision making ์ด๋ผ๊ณ ํํ ๋ ์ ์๋ค.<ul><li>sequential : ๋งค ์๊ฐ t ์ ๋ํด์</li><li>decision making : agent ์ action ์ ์ ํํ๋ ๊ณผ์ </li></ul></li><li>Agent์ Action ์ ๊ทธ ๊ฒฐ๊ณผ๊ฐ ์ฆ์ ๋์ค์ง ์์ ์ ์๋ค. (may have long term consequences)</li><li>Action ์ ๋ํ Reward ์ญ์ ์ฆ์ ๋์ค์ง ์์ ์ ์๋ค. (reward ma be delayed)</li><li>์ง๊ธ, ์ด์๊ฐ์ reward๋ฅผ ํฌ๊ธฐํ๊ณ , long-term reward๋ฅผ ๋ ํฌ๊ฒ ํ๋ ๋ฐฉํฅ์ ์ ํ์ด ์ข์ ์ ์๋ค.</li><li>(Ex) Financial investment (take months to mature), refuelling a helipcopter (prevent a crash in several hours), blocking opponent moves (help winning chances many moves from now)</li></ul><h3 id="2-3-Agent-and-Environment"><a href="#2-3-Agent-and-Environment" class="headerlink" title="2.3 Agent and Environment"></a>2.3 Agent and Environment</h3><ul><li>โ๋โ๋ก ๋ฌ์ฌ๋๋ ๊ฒ์ด Agent</li><li>Our Goal: build on agent/algorithm<ul><li>Agent decides Action (EX: ๋ชจํฐ์ Torque๋ฅผ ์ด๋ป๊ฒ ์ค์ ํ ์ง, ๋ก๋ด์ด ์ด๋ป๊ฒ ์์ง์ผ์ง ๋ฑ)</li></ul></li></ul><p><img src="/2023/06/04/20230604-rl-basic/Untitled02.png" alt="Untitled"></p><ul><li>โ๏ธ๋งค Step t ๋ง๋คโ๏ธ<ol><li>Agent๋<ol><li>action $A_t$ ๋ฅผ ์ํ</li><li>observation $O_t$ ๋ฅผ ๋ฐ์</li><li>scalar reward $R_t$ ๋ฅผ ๋ฐ์</li></ol></li><li>Environment๋<ol><li>agent ๊ฐ ์ํํ action $A_t$๋ฅผ ๋ฐ์</li><li>a์ ๋ํด observation $O_{t+1}$ ๋ก ๋ฐ์</li><li>a์ ๋ํด scalar reward $R_{t+1}$ ๋ก ๋ฐ์</li></ol></li><li>t + 1๋ก ๋ค์ ์คํ
์ฆ๊ฐ</li></ol><h3 id="2-4-History-and-State"><a href="#2-4-History-and-State" class="headerlink" title="2.4 History and State"></a>2.4 History and State</h3><ol><li><p>HISTORY</p><ul><li>DEFINITION: observation ๊ณผ action, rewards์ sequence</li></ul><p> $$<br> H_{t}=O_{1}, R_{1}, A_{1},โฆ, A_{t-1}, O_t, R_t<br> $$</p><ul><li>โQโ: ์์ ์ ์์์ ๋ณด๋ฉด, $R_{t}, O_{t}$ ์ ๊ฒฝ์ฐ $A_{t}$์ ๋ํ reaction ์
๋๋ค. ๋ฐ๋ผ์ Ot, Rt๊ฐ ๋ํ๋๊ธฐ ์์์๋ At๊ฐ ๋ฐ๋์ ์ ํ๋์ด์ผ ํ๋๊ฒ ๊ฐ์๋ฐ, time step t ์์์ history Ht๋ At ๊ฐ ๋น ์ ธ์์ต๋๋ค. ์์ผ๊น์? Ot, Rt โ At ๊ฐ ์์์ด๋ฉด make sense ํ ๊ฒ ๊ฐ์ต๋๋ค๋ง;;</li><li>Next step by current history:<ul><li>agent์ action</li><li>environment ๊ฐ observation ๊ณผ reward๋ฅผ ๊ฒฐ์ </li></ul></li></ul></li><li><p>State</p><ul><li>DEFINITION: ๋ค์ step ์ ์ด๋ค ๊ฒ์ ํ ์ง ์ ํ๋ ์ ๋ณด</li><li>๋ณดํต, Function of History</li></ul><p> $$<br> S_{t} = f(H_{t})<br> $$</p></li></ol></li></ul><h3 id="2-5-State"><a href="#2-5-State" class="headerlink" title="2.5 State"></a>2.5 State</h3><ol><li>Environment State: $S_{t}^{e}$<ol><li>David Silver โInformation in the environment to determine what happens nextโ</li><li>Environmentโs private representation</li><li>๋ณดํต Environment State ๋ agent ์๊ฒ ๋ณด์ด์ง ์๋๋ค</li><li>Environment State ๊ฐ agent ์๊ฒ ๋ณด์ธ๋ค ํ ์ง๋ผ๋, irrelevant information ์ผ ๊ฐ๋ฅ์ฑ์ด ํฌ๋ค</li></ol></li><li>Agent State: $S_{t}^{a}$<ol><li>$S_{t}^{a} = f(H_t)$ : Funtion of History</li><li>RL algorithm์์ ์ฌ์ฉ๋ agent์ ๊ดํ ์ ๋ณด</li></ol></li><li>Information State (=aka Markov State)<ol><li><p>History ๋ก๋ถํฐ ์ป๊ฒ๋๋ ๋ชจ๋ ์ ์ฉํ ์ ๋ณด</p></li><li><p>A state $S_{t}$ is Markov:</p><p> Definition: </p><p> $$<br> P[S_{t+1}|S_{t}] = P[S_{t+1}|S_1, โฆ, S_{t}]<br> $$</p></li><li><p>Markov Property์ ํต์ฌ์ </p><ul><li>โ๋ฏธ๋์ State ๋ ํ์ฌ State์๋ง ์ํฅ์ ๋ฐ๋๋คโ</li><li>โ๋ฏธ๋์ State ๋ ๊ณผ๊ฑฐ ๋ชจ๋ State์ ๋ํด ๋
๋ฆฝ์ ์ด๋คโ</li><li>Store ONLY current State (ํ์ฌ์ State๊ฐ ์ด์ ์ history ์ ๋ณด๋ฅผ ๋ด๊ณ ์์ผ๋ฏ๋ก. RL ๊ณผ memory, Dynamic Programming ๊ณผ์ ์ฐ๊ด์ฑ์ intuitively ์ดํดํ ์ ์์)</li><li>ํฌ๋ฆฌ์ฝฅํฐ ์์ ) ํฌ๋ฆฌ์ฝฅํฐ๊ฐ ์ง๊ธ ๋ฐ๋์ ๋ง์ ๋, 10๋ถ์ ํฌ๋ฆฌ์ฝฅํฐ๊ฐ ์ด๋ค velocity ์ ์ด๋ค position ์ ์์๋์ง ์ค์ํ์ง ์๋ค</li></ul></li></ol></li></ol><h3 id="2-6-Fully-Observable-Environments-amp-Partially-Observable-Environments"><a href="#2-6-Fully-Observable-Environments-amp-Partially-Observable-Environments" class="headerlink" title="2.6 Fully Observable Environments & Partially Observable Environments"></a>2.6 Fully Observable Environments & Partially Observable Environments</h3><ol><li><p>Full observability : agent ๊ฐ directly environment state๋ฅผ ํ์ธ ํ ์ ์๋ ํ๊ฒฝ</p><ul><li>environment state = agent state = information state</li></ul><p> $$<br> O_t=S_{t}^{a}=S_{t}^{e}<br> $$</p><ul><li>๋ณดํต ์ state ๋ค์ Markov Decision Procee (MDP)</li></ul></li><li><p>Partial Observability : agent๊ฐ indirectly environment state ๋ฅผ ํ์ธ ํ ์ ์๋ ํ๊ฒฝ</p><ul><li>agent โ environment state</li><li>๋ณดํต ์ด๋ฅผ, Partially observable Markov Decision Process (POMDP) ๋ผ๊ณ ํ๋ค.</li><li>์ด ๊ฒฝ์ฐ, agent ๋ ์์ ์ state representation $S_t^{a}$ ๋ฅผ ์ ํด์ผํ๋ค. ๋ค์์ ๊ฒฝ์ฐ์ ๋ฐ๋ผ $S_t^{a}$๋ฅผ ์ ํ๋ ๋ฐฉ์์ด๋ค.<ul><li>Complete History ์ ๊ฒฝ์ฐ : $S_t^{a}=H_t$</li><li>Beliefs of environment state (Baysian Approach) : $S_t^{a} = (P[S_t^{e}]=s^1, โฆ, P[S_t^{e}]=s^n)$ - Vector Probability์ ์ํด agent ์ next step ์ด ๊ฒฐ์ ๋๋ค</li><li>Recurrent Neural Network (Probability๋ฅผ ์ฌ์ฉํ์ง ์๊ณ , ๋จ์ง agent์ ์ซ์๋ง ๋ฃ์ด์ฃผ๋ฉด ๋๋ค๋ ์๊ฐ์ผ๋ก network๋ฅผ ์ฌ์ฉํ ์ ๋ ์๋ค.) : $S_t^{a} = \sigma(S_{t-1}^{a}W_{s}+O_{t}W_{o})$</li></ul></li></ul></li></ol><p>MDP ์ POMDP ๋ฅผ ์ถํ์ ๋ณธ ๊ฐ์์์ ๋ค๋ฃฐ ์๋ ์๊ฒ ์ง๋ง, ๊ทธ ๋ด์ฉ์ ์ค์๋์ ๋ณธ ์์
์ ์งํ ๋ฐฉ์์ ๋ฐ๋ผ ์๋ ๊ฐ์๋ ํจ๊ป ์งํํด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. </p><p><a href="https://www.youtube.com/watch?v=uHEjez97BvE">https://www.youtube.com/watch?v=uHEjez97BvE</a></p><h2 id="3-Inside-an-RL-Agent"><a href="#3-Inside-an-RL-Agent" class="headerlink" title="3. Inside an RL Agent"></a>3. Inside an RL Agent</h2><h3 id="3-1-Major-Components-of-an-RL-Agent"><a href="#3-1-Major-Components-of-an-RL-Agent" class="headerlink" title="3.1 Major Components of an RL Agent"></a>3.1 Major Components of an RL Agent</h3><ol><li>Policy : Agent์ ํ๋ํจ์(behavior function)</li><li>Value function : ๊ฐ state ์ action ์ด ์ผ๋ง๋ ์ข์์ง ๋ํ๋ด๋ ํจ์ (how much reward do we expect to get)</li><li>Model : Agent ๊ด์ ์์ ๋ฐ๋ผ๋ณด๋ environment (agentโs representation)</li></ol><ul><li>์ ์ธ๊ฐ์ง๊ฐ ํญ์ ๋ชจ๋ ํ์ํ ๊ฒ์ ์๋๋๋ค. ๊ฒฝ์ฐ์ ๋ฐ๋ผ, ํ์์ ๋ฐ๋ผ ๊ตฌ์ฑํ๊ฒ ๋ฉ๋๋ค.</li></ul><h3 id="3-2-Policy"><a href="#3-2-Policy" class="headerlink" title="3.2 Policy"></a>3.2 Policy</h3><ul><li>Policy : Agent์ ํ๋ํจ์</li><li>Map from state to action</li><li>Policy ์ ์ข
๋ฅ<ol><li>Deterministic Policy: $a = \pi(s)$ - argmax</li><li>Stochastic Policy: $\pi(a|s) = P[A_{t}=a|S_{t}=s]$</li></ol></li></ul><h3 id="3-3-Value-Function"><a href="#3-3-Value-Function" class="headerlink" title="3.3 Value Function"></a>3.3 Value Function</h3><ul><li>Value Function : Prediction of future Reward</li><li>State 1 or 2 / Action 1 or 2 ๋ฅผ ์ ํํ ๋์ ๊ธฐ์ค์ด ๋ฉ๋๋ค.</li><li>$v_{\pi}(s)=E_{\pi}[R_{t+1}+\gamma R_{t+2}+\gamma^{2}R_{t+3}+โฆ|S_{t}=s]$ ($\gamma$: discount factor - ๋ ๋จผ ๋ฏธ๋์ ์์ธก reward ํจ๊ณผ๋ฅผ ๊ฐ์์ํค๊ธฐ ์ํจ)</li></ul><h3 id="3-4-Model"><a href="#3-4-Model" class="headerlink" title="3.4 Model"></a>3.4 Model</h3><ul><li><p>Model : Environment ์ ํ๋์ ์์ธก (Agent ์ ๊ด์ ์์์ ํ๋๋ฐฉ์์ด์ง, ์ค์ environment ์ ํ๋๋ฐฉ์์ด ์๋)</p></li><li><p>Transition Model $P$ : $P$ predicts the next <strong>state</strong></p><p> $$<br> P_{ssโ}^{a} = P[S_{t+1}=sโ|S_t=s, A_t=a]<br> $$</p></li><li><p>Reward Model $R$ : $R$ predicts the next (immediate) <strong>reward</strong></p></li></ul><p>$$<br>R_s^{a}=E[R_{t+1}|S_t=s, A_t=a]<br>$$</p><p>(Q) Trasition Model์ ๊ฒฝ์ฐ, Agent ๊ด์ ์์ (Environment? ) state ๋ฅผ ์์ธก ํ๋ ๊ฒ์ด๋ผ๋ฉด, Policy ์์ ์ญํ ์ฐจ์ด๋ ๋ฌด์์ผ๊น? Policy์ Value Function ์ ํตํด agent ์ action ์ด ๊ฒฐ์ ๋๊ณ , ๊ฒฐ์ ๋ ํ์ฌ action ์ ์ํด ๋ค์ state๊ฐ ๊ฒฐ์ ๋๋ค. ์ด๋ ๊ฒ ๋ณผ๋ Transition Model ๊ณผ Agent ๊ฐ์ ์ฐ๊ฒฐ๊ณ ๋ฆฌ? TransitionModel๊ณผ Policy ๊ฐ์ ๊ด๊ณ๊ฐ ์ด๋ป๊ฒ ๋๋์ง? Reward Model ๋ ๋ง์ฐฌ๊ฐ์ง.</p><h3 id="3-5-Maze-Example"><a href="#3-5-Maze-Example" class="headerlink" title="3.5 Maze Example"></a>3.5 Maze Example</h3><ol><li>Policy <ol><li>์๋ ๊ทธ๋ฆผ์์, ํ์ดํโ๋ฅผ Policy๋ผ ์๊ฐํ ์ ์์ต๋๋ค.</li><li>โฌ๏ธ ๋ฅผ state ๋ผ ์๊ฐํ ์ ์์ต๋๋ค.</li><li>Agent ๊ฐ ํน์ โฌ๏ธ ์ ๋์ฐฉํ์ ๋, โ ๋ฅผ ๋ฐ๋ผ ์ด๋ํ๋ ๊ฒ์ด Action ์ด๋ผ ์๊ฐํ ์ ์์ต๋๋ค.</li></ol></li></ol><p><img src="/2023/06/04/20230604-rl-basic/Untitled03.png" alt="Untitled"></p><ol><li>Value Function<ol><li>์๋ ๊ทธ๋ฆผ์, ๊ฐ state ๋ง๋ค value function ๊ฐ์ ์ ์ด๋์ ๊ฒ์
๋๋ค.</li><li>ํน์ โฌ๏ธ , ์ฆ state ์ ๋์ฐฉํ์ ๋, ๋ค์ state(๋ค์ action)์ ๊ฒฐ์ ์ง๋ ๊ธฐ์ค์ด ๋ฉ๋๋ค.</li><li>$v_{\pi}(s)$</li></ol></li></ol><p><img src="/2023/06/04/20230604-rl-basic/Untitled04.png" alt="Untitled"></p><ol><li>Model<ol><li>Agent๊ฐ Modeling ํ immediate reward (์ค์ environment ๊ฐ ์๋)</li><li>Dynamics : Action์ด State ๋ฅผ ์ด๋ป๊ฒ ๋ณํ ์ํค๋์ง (Q) ๊ฐ์๊ธฐ ์ด๋์ ํ์ด๋์จ terminology์ด์ฃ ? ๊ฐ์ ๋ถ๋ถ์์๋ ํฌ๊ฒ ์ธ๊ธ์ ์ํ์๋๋ฐ Definition ์ฒ๋ผ ํ๊ธฐ๋ฅผ ํด๋จ๋ค์. Model ์ ๋๊ฐ์ง๋ผ๋ฉฐโฆ</li><li>Rewards : ๊ฐ state๋ง๋ค ์ผ๋งํผ์ reward ๋ฅผ ๋ฐ๋์ง</li><li>** The Model may be IMPERFECT</li><li>Grid Layout : Transition Model $P_{ssโ}^{a}$</li><li>Numbers : Reward Model $R_s^{a}$</li></ol></li></ol><p><img src="/2023/06/04/20230604-rl-basic/Untitled05.png" alt="Untitled"></p><h3 id="3-6-Categorizing-RL-agents"><a href="#3-6-Categorizing-RL-agents" class="headerlink" title="3.6 Categorizing RL agents"></a>3.6 Categorizing RL agents</h3><p>[Category 1] : RL Components(RL ๊ตฌ์ฑ์์) ์ค Policy ์ Value์ ์ ์ฅ ์ฌ๋ถ์ ๋ฐ๋ผ ๋ค์๊ณผ ๊ฐ์ด ๋๋ฉ๋๋ค.</p><ol><li>Value Based<ol><li>No Policy </li><li>Stores only Value Function</li></ol></li><li>Policy Based<ol><li>Stores only Policy</li><li>No Value Function</li></ol></li><li>Actor Critic : Will cover Soon<ol><li>Stores both Policy and</li><li>Value Function</li></ol></li></ol><p>[Category 2] : RL Components(RL ๊ตฌ์ฑ์์) ์ค Model์ ์ ๋ฌด์ ๋ฐ๋ผ ๋ค์๊ณผ ๊ฐ์ด ๋๋ฉ๋๋ค.</p><ol><li>Model Free<ol><li>Policy and/or Value Function ์ ์ ๋ฌด๋ ํฌ๊ฒ ์ค์ํ์ง ์์ผ๋ (์ด๋ ํ๋๋ผ๋ ์์ผ๋ฉด ๋จ),</li><li>No Model</li></ol></li><li>Model Based<ol><li>Policy and/or Value Function์ ์ ๋ฌด๋ ํฌ๊ฒ ์ค์ํ์ง ์์ผ๋ (์ด๋ ํ๋๋ผ๋ ์์ผ๋ฉด ๋จ),</li><li>Model</li></ol></li></ol><p><img src="/2023/06/04/20230604-rl-basic/Untitled06.png" alt="Untitled"></p><h2 id="4-Problems-within-Reinforcement-Learning"><a href="#4-Problems-within-Reinforcement-Learning" class="headerlink" title="4. Problems within Reinforcement Learning"></a>4. Problems within Reinforcement Learning</h2><h3 id="4-1-Reinforcement-Learning-Problem-amp-Plannning-Problem"><a href="#4-1-Reinforcement-Learning-Problem-amp-Plannning-Problem" class="headerlink" title="4.1 Reinforcement Learning Problem & Plannning Problem"></a>4.1 Reinforcement Learning Problem & Plannning Problem</h3><ul><li>Sequential Decision Making์์ 2๊ฐ์ง Fundamental Problem์ด ์์ต๋๋ค.</li></ul><ol><li>Reinforcement Learning Problem<ol><li>Environment ์ ๋ํด ์์ง ๋ชปํจ (Agent ๋ ์๋ฌด๊ฒ๋ ๋ชจ๋ฅธ์ฑ ๊ทธ๋ฅ ๋์ ธ์ง)</li><li>Agent ๊ฐ environment ์ ์ํธ์์ฉ์ ํจ</li><li>์ด๋ฅผ ํตํด, Agent๊ฐ ์์ ์ Policy๋ฅผ ๋ฐ์ ์ํด</li></ol></li><li>Planning Problem<ol><li>Environment ์ Model ์ ์๊ณ ์์ ( Agent ๊ฐ ์ด model ์ ๋ณด๊ณ , Environment ์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ๋์ ธ์ง)</li><li>Agent ๋ ์ Model ์ ๋ํด computation ์ ์ํํจ (๊ทธ ์ด๋ค ๋ค๋ฅธ ์ํธ์์ฉ์ ํ์ง ์์์ฑ)</li><li>์ด๋ฅผ ํตํด, Agent๊ฐ ์์ ์ Policy ๋ฅผ ๋ฐ์ ์ํด</li><li>aka deliberation (deliberative RL์ ๊ฒ์ํ๋, ๊ฐ์ hierarchy์ behavior-based architecture(ํ์ ๊ธฐ๋ฐ ์์ด์ ํธ๊ตฌ์กฐ), deliberative agent architecture(์๊ณ ํ ์์ด์ ํธ ๊ตฌ์กฐ), hybrid agent architecture(ํผํฉํ ์์ด์ ํธ ๊ตฌ์กฐ)๊ฐ ์์ผ๋, deliberation ์ด ์ด๋ค ๊ฒ์ธ์ง๋ ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.) , reasoning, introspection, pondering, thought, search</li></ol></li></ol><p>Atari Game ์์ Reinforcement Learning Problem ์ผ๋ก ๋ฐ๋ผ๋ณผ ๋,</p><p><img src="/2023/06/04/20230604-rl-basic/Untitled07.png" alt="Untitled"></p><p>Atari Game ์์ Planning Problem ์ผ๋ก ๋ฐ๋ผ๋ณผ ๋, </p><p><img src="/2023/06/04/20230604-rl-basic/Untitled08.png" alt="Untitled"></p><ul><li><p>RL Problem ์ Agent์ Policy dependency ๊ฐ ๋๋ค</p><p> โ Model ์ ์์ํ์ง ์๊ณ , Agent๋ฅผ ๋ฐ์ ์ํค๋ ๋ฐฉํฅ</p></li><li><p>Planning Problem ์ Model dependency ๊ฐ ๋๋ค</p><p> โ Model์ ๋ฐ์ ์ํค๋ ๋ฐฉํฅ</p></li><li><p>๊ฒฐ๊ตญ ์ฌ๊ธฐ์, ์ป์ ์ ์๋ ๊ฒ์ ๊ฐ์ ๋ฌธ์ ๋ผ ํ ์ง๋ผ๋ ์ฐ๋ฆฌ๊ฐ ๋ฌธ์ ์ ์๋ฅผ ์ด๋ป๊ฒ ํ๋๋์ ๋ฐ๋ผ Reinforcement Learning ์ฐ์ฅ์ ์ฌ์ฉํ ๋๋ ๋ค์ํ๊ฒ ํด์๋๊ณ , ๋ค์ํ ๋ฌธ์ ํด๊ฒฐ๋ฐฉ์์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค.</p></li></ul><h3 id="4-2-Exploration-amp-Exploitation"><a href="#4-2-Exploration-amp-Exploitation" class="headerlink" title="4.2 Exploration & Exploitation"></a>4.2 Exploration & Exploitation</h3><ul><li>๊ฒฐ๊ตญ, RL ์ trial-and-error learning ์
๋๋ค.</li><li>The agent ๋ environment ์ ๋ํ ๊ฒฝํ์ ํตํด, Good Policy ๋ฅผ ์ฐพ๊ณ ๋ฐ์ ์์ผ์ผํฉ๋๋ค.</li><li>์ด ๋์ ์ ์ฝ ์กฐ๊ฑด์ ๋๋ฌด ์ค๋ ๊ฑธ๋ฆฌ์ง ์๋ ์๊ฐ๊ณผ reward step์ด๊ฒ ์ต๋๋ค.</li></ul><ol><li>Exploration : finds more information about the environment<ol><li>Environment ์ ๊ดํด ์๋ฌด๊ฒ๋ ์์ง ๋ชปํ๋ฏ๋ก, environment ๋ฅผ ํ์
ํ๊ธฐ ์ํ ์ ๋ณด๋ฅผ ์์งํฉ๋๋ค.</li></ol></li><li>Exploitation : exploits known information to maximise reward<ol><li>์ด๋ฏธ ์๊ณ ์๋ ์ ๋ณด (Environment ์ ๊ดํ ์ ๋ณด)๋ฅผ ๋ฐํ์ผ๋ก reward๋ฅผ ์ต๋ํํฉ๋๋ค.</li></ol></li></ol><p>์๋ ์ฌ์ง์ ๊ฐ ๋ฌธ์ ์ ๋ํด Exploitation ๊ด์ ๊ณผ Exploration ๊ด์ ์ผ๋ก ์ดํด๋ณด์์ ๋์ ๊ทธ ๋ฌธ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ๋ฌ๋ผ์ง๋ ์์์
๋๋ค.</p><p><img src="/2023/06/04/20230604-rl-basic/Untitled09.png" alt="Untitled"></p><h3 id="4-3-Prediction-and-Control"><a href="#4-3-Prediction-and-Control" class="headerlink" title="4.3 Prediction and Control"></a>4.3 Prediction and Control</h3><ul><li>Prediction : Evaluate the future<ul><li>Given a policy</li></ul></li><li>Control : Optimise the future<ul><li>Find the best policy</li></ul></li><li>Agent ๋ฅผ ๋น๋กฏํ RL system์ ๊ฒฐ๊ตญ Prediction ์์ Control ๋ฐฉํฅ์ผ๋ก ๋์ด๊ฐ๋ ๊ฐ๋ฐ๋จ๊ณ๋ฅผ ์ทจํ ์ ์์ต๋๋ค.</li></ul>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/DataScience/">DataScience</category>
<category domain="https://emjayahn.github.io/tags/Reinforcement-Learning/">Reinforcement Learning</category>
<comments>https://emjayahn.github.io/2023/06/04/20230604-rl-basic/#disqus_thread</comments>
</item>
<item>
<title>[Study] Markov Decision Process</title>
<link>https://emjayahn.github.io/2023/05/21/20230521-markov/</link>
<guid>https://emjayahn.github.io/2023/05/21/20230521-markov/</guid>
<pubDate>Sun, 21 May 2023 11:08:39 GMT</pubDate>
<description><p>๋ณธ ๊ธ์ David Silver์ ๊ฐ์๋ฅผ ๋ฃ๊ณ ์ ์ ๋ฆฌํ ๊ธ์ด๋ค. ๋งค์ฐ ์ค๋ ์ ์ ๊ณต๋ถํ ๋ง์ฝํ ์ด๋ก ์ ๋ค์ ํ ๋ฒ ์๊ธฐ์ํค๊ธฐ ์ํด ๊ธฐ์ด ๊ฐ์์ ํจ๊ป ๊ผผ๊ผผํ ์ ๋ฆฌํ๋ฉด์ ์๊ธฐ์์ผฐ๋ค. </p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>๋ณธ ๊ธ์ David Silver์ ๊ฐ์๋ฅผ ๋ฃ๊ณ ์ ์ ๋ฆฌํ ๊ธ์ด๋ค. ๋งค์ฐ ์ค๋ ์ ์ ๊ณต๋ถํ ๋ง์ฝํ ์ด๋ก ์ ๋ค์ ํ ๋ฒ ์๊ธฐ์ํค๊ธฐ ์ํด ๊ธฐ์ด ๊ฐ์์ ํจ๊ป ๊ผผ๊ผผํ ์ ๋ฆฌํ๋ฉด์ ์๊ธฐ์์ผฐ๋ค. </p><span id="more"></span><h2 id="1-Markov-Processes"><a href="#1-Markov-Processes" class="headerlink" title="1. Markov Processes"></a>1. Markov Processes</h2><h3 id="1-1-Introduction-to-MDPs"><a href="#1-1-Introduction-to-MDPs" class="headerlink" title="1.1 Introduction to MDPs"></a>1.1 Introduction to MDPs</h3><ul><li>Markov decision processes : ๊ฐํํ์ต์์ Environment ๋ฅผ ๋ฌ์ฌํ๋ ๋ฐฉ๋ฒ</li><li>์ด ๋, MDP ๋ก ๋ฌ์ฌํ๋ ๊ฒฝ์ฐ, environment ๋ ๊ด์ธก์ด ๊ฐ๋ฅํ environment ์ธ ์ํ์
๋๋ค. (fully observable)</li><li>๋๋ถ๋ถ์ RL problem์ MDP ๋ก ํํ์ด ๊ฐ๋ฅํฉ๋๋ค.<ul><li>Optimal control โ continuous MDPs</li><li>Partially observalble problems โ MDPs</li><li>Bandits โ MDPs with one state</li><li>์ฆ, ๋ชจ๋ RL problem์ ๊ธฐ๋ณธ์๋ฆฌ๋ฅผ ์ดํดํ๋ค๋ฉด, MDP๋ก ํํํ ์ ์๋ค๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.</li></ul></li></ul><h3 id="1-2-Markov-Property"><a href="#1-2-Markov-Property" class="headerlink" title="1.2 Markov Property"></a>1.2 Markov Property</h3><ul><li>The future is independent of the past given the present = ๋ฏธ๋๋ ํ์ฌ์๋ง ์ข
์์ ์ด๋ฉฐ, ๊ทธ ์ด์ ์ ๊ณผ๊ฑฐ์๋ ๋
๋ฆฝ์ ์
๋๋ค.</li></ul><p>$$<br>P[S_{t+1}|S_t] = P[S_{t+1}|S1, โฆ, S_{t}]<br>$$</p><h3 id="1-3-State-Transition-Matrix"><a href="#1-3-State-Transition-Matrix" class="headerlink" title="1.3 State Transition Matrix"></a>1.3 State Transition Matrix</h3><ul><li>current state $s$, successor state $sโ$, the state transition probability $P_{ssโ}$<ul><li>$P_{ssโ}$๋ ํ์ฌ s state ์์ $s_{t+1}=sโ$ ์ผ๋ก ๋ณ์ด ๋๋ ์กฐ๊ฑด๋ถ ํ๋ฅ </li></ul></li></ul><p>$$<br>P_{ssโ}=P[S_{t+1}=sโ|S_{t}=s]<br>$$</p><ul><li>State transition matrix $P$ : ์์ transition probability ๋ฅผ ๋ชจ๋ s โ sโ ์ ๋ํด ๋ชจ์ ๋์ ํ๋ ฌ<ul><li>transition probability matrix</li></ul></li></ul><p>$$<br>P = \begin{matrix}P_{11}โฆP_{1n}\.\.\.\P_{n1}โฆP_{nn}\end{matrix}<br>$$</p><p>$P_{1n}$ : ํ์ฌ state 1์์ โ Next state n๋ก ์ ์ด๋๋ ํ๋ฅ </p><p>๋ฐ๋ผ์, ๊ฐ ํ(row)์ ํฉ์ 1์ด๋ค. P11 + โฆ + P1n = 1, state 1์์ ๋ค๋ฅธ state ๋ก ๋ป์ด๋๊ฐ๋ ํ๋ฅ ์ ํ๋ฒ์ ํ ๊ฒฝ์ฐ์ ์๋ฐ์ ์์ผ๋ฏ๋ก ๋ชจ๋ ๊ฒฝ์ฐ์ ํ๋ฅ ์ ํฉ์ 1์
๋๋ค.</p><h3 id="1-4-Markov-Process"><a href="#1-4-Markov-Process" class="headerlink" title="1.4 Markov Process"></a>1.4 Markov Process</h3><ul><li>Markov process ๋ <strong>memoryless</strong> random process</li><li>Markov Process (or Markov Chain) ๋ <S, P> ๋ก ํํํฉ๋๋ค.<ul><li>S ๋ ์ ํํ state ๋ค์ ์งํฉ์
๋๋ค. (finite set of states)</li><li>P ๋ transition probability matrix</li></ul></li></ul><h3 id="1-5-Example-of-Markov-Chain"><a href="#1-5-Example-of-Markov-Chain" class="headerlink" title="1.5 Example of Markov Chain"></a>1.5 Example of Markov Chain</h3><p><img src="/2023/05/21/20230521-markov/Untitled.png" alt="Untitled"></p><p>์๋ ๊ทธ๋ฆผ์์ ์ฒ๋ผ, Class 2 State ์์ ๋ค์ state ๋ก ๋์ด๊ฐ ํ๋ฅ 0.2, 0.8 ์ ์ค๋ฅธ์ชฝ transition probability matrix ์์ ํ์ธ ํ ์ ์์ต๋๋ค. state 2 โ state 3 ์ผ๋ก ๊ฐ๋ ํ๋ฅ 0.8, state 2 โ state sleep 0.2 ๋ฅผ ํ์ธ ํ ์ ์์ต๋๋ค.</p><p><img src="/2023/05/21/20230521-markov/Untitled01.png" alt="Untitled"></p><h2 id="2-Markov-Reward-Processes"><a href="#2-Markov-Reward-Processes" class="headerlink" title="2. Markov Reward Processes"></a>2. Markov Reward Processes</h2><h3 id="2-1-MRP-Markov-Reward-Process"><a href="#2-1-MRP-Markov-Reward-Process" class="headerlink" title="2.1 MRP: Markov Reward Process"></a>2.1 MRP: Markov Reward Process</h3><ul><li>MRP๋? Markov chain ์ VALUE ๊ฐ ๋ํด์ง chain</li></ul><p>Expression: Markov Reward Process โ <S, P, R, $\gamma$></p><ul><li><p>S : states set</p></li><li><p>P: transition probability matrix</p><p> $P_{ssโ}=P[S_{t+1}=sโ|S_{t}=s]$</p></li><li><p>R: reward function , $R_{s}=E[R_{t+1}|S_{t}=s]$</p></li><li><p>$\gamma$: discount factor, 0โค$\gamma$โค1</p></li></ul><h3 id="2-2-Return"><a href="#2-2-Return" class="headerlink" title="2.2 Return"></a>2.2 Return</h3><p>$$<br>G_{t }=R_{t+1}+\gamma R_{t+2} + โฆ = \Sigma_{k=0}^{inf} \gamma ^k R_{t+k+1}<br>$$</p><ul><li><p>return Gt๋ ํ์ฌ t ์์๋ถํฐ, ๋ชจ๋ discount ๋ reward ์ ํฉ์
๋๋ค.</p></li><li><p>return ๊ณผ reward ํท๊ฐ๋ฆฌ์ง ๋ง์์ผํฉ๋๋ค! return ์ ์ง๊ธ๋ถํฐ ๋ฏธ๋๊น์ง ํฉ (๋จ, discount ๊ทธ ์๋ฏธ๋ ์ํ์ ๊ณ์ฐํธ์๋ ์์ง๋ง, ๋ฏธ๋์ ๊ฐ์ค์น๋ฅผ ์ผ๋ง๋ ๋๋๋์ ๋ฌธ์ ๋ ์์ต๋๋ค), reward ๋ ํ์ฌ state ์ action ์ด ํ๊ฒฝ์ผ๋ก ๋ฐ์ ๊ฐ</p></li><li><p>์ DISCOUNT ํ๋๊ฐ?</p></li></ul><p><img src="/2023/05/21/20230521-markov/Untitled02.png" alt="Untitled"></p><h3 id="2-3-Value-Function"><a href="#2-3-Value-Function" class="headerlink" title="2.3 Value Function"></a>2.3 Value Function</h3><ul><li>Value Function : $v(s)$ -โ total reward we will get. This is the value we care about โ<ul><li>RL ์์ ์ฐ๋ฆฌ๊ฐ ์ ๊ฒฝ์จ์ผํ๋ ์ต์ข
ํํ์ total reward function</li></ul></li></ul><p>$$<br>v(s)=E[G_{t}|S_{t}=s]<br>$$</p><ul><li>Example:</li></ul><p><img src="/2023/05/21/20230521-markov/Untitled03.png" alt="Untitled"></p><h3 id="2-4-Bellman-Equation-for-MRPs"><a href="#2-4-Bellman-Equation-for-MRPs" class="headerlink" title="2.4 Bellman Equation for MRPs"></a>2.4 Bellman Equation for MRPs</h3><ul><li>Value Function ์ ๋ค์๊ณผ ๊ฐ์ด ์ชผ๊ฐ ์ง ์ ์๋ค.<ul><li>immediate reward $R_{t+1}$</li><li>discounted value of successor state $\gamma v(S_{t+1})$</li><li>์ง๊ธ ํ์ฌ state ์์์ reward(immediate reward) + ๋ฏธ๋์ value(value where agent end up)</li></ul></li><li>$v(s) = R_{t+1}+\gamma v(S_{t+1})$</li></ul><p><img src="/2023/05/21/20230521-markov/Untitled04.png" alt="Untitled"></p><ul><li>Q) ์ R index ๊ฐ t+1 ์ธ๊ฐ? : agent ์ environment ์ฌ์ด์์์ ๊ฒฝ๊ณ๋ฌธ์ . agent ๊ฐ environment ์์ ํ๋ํ๋ ์๊ฐ time stamp ๊ฐ ์ง๋๊ฒ ๋จ. agent ์ ์ก์
์ดํ environment ๋ก๋ถํฐ ์ํฅ์ ๋ฐ๊ณ ๋์ค๋ฉด time stamp ๊ฐ ๊ทธ ๋ค์์ผ๋ก ์ฐํ๋๊ฑธ๋ก ์ ์ํ๊ธฐ์, R t+1 ์ด๋ผ indexing ํ๊ฒ๋จ. ์ถํ ๊ฐ์์์ ๋ ์์ธํ ์ค๋ช
. just convention</li></ul><p><img src="/2023/05/21/20230521-markov/Untitled05.png" alt="Untitled"></p><h3 id="2-5-Bellman-Equation-in-Matrix-Form"><a href="#2-5-Bellman-Equation-in-Matrix-Form" class="headerlink" title="2.5 Bellman Equation in Matrix Form"></a>2.5 Bellman Equation in Matrix Form</h3><ul><li>์ ์์ Matrix ํํ๋ก ํํ ํ ๊ฒ์
๋๋ค.</li><li>์๋์ ์์ ๊ฐ๊ฐ Vector ๋ผ๊ณ ์๊ฐํฉ๋๋ค</li></ul><p>$$<br>v = R +\gamma Pv<br>$$</p><p>, where v = [v(1) โฆ v(n)], R = [R1 โฆ Rn] , P = [P11 .. P1n โฆ P11 Pnn] (matrix)</p><p><img src="/2023/05/21/20230521-markov/Untitled06.png" alt="Untitled"></p><ul><li>Bellman Equation ์ ํ๊ธฐ ์ํด์๋, ์ค์ ์์ ์ฌ์ด์ฆ์์๋ linear equation ์ ํ๊ธฐ ์ฝ์ง๋ง, ํฐ ๊ท๋ชจ์ ๋ฌธ์ ์์ ์ค์ ๋ก๋ iterative methods ๋ฅผ ์ฌ์ฉํ๋ค.<ul><li>Dynamic programming</li><li>Monte-Carlo evaluation</li><li>Temporal-Difference learning</li></ul></li></ul><h3 id="2-6-Solving-the-Bellman-Equation"><a href="#2-6-Solving-the-Bellman-Equation" class="headerlink" title="2.6 Solving the Bellman Equation"></a>2.6 Solving the Bellman Equation</h3><ul><li>์ ์์ฒด๋ฅผ ํธ๋ ๊ฒ์ ์ด๋ ต์ง ์๋ค. linear equation. ์์ผ๋ก ํ๊ธฐ์.. ๊ทธ๋ฆฌ๊ณ ์ฐ์ฐ์ฅ์น๋ฅผ ์ด์ฉํ ์ฐ์ฐ ์ญ์ ์์ ์ฌ์ด์ฆ์์ ๋ฌธ์ ๋์ง ์๋๋ค. ๋ค๋ง, ์ฌ์ด์ฆ๊ฐ ํฌ๋ฉด ํด์๋ก ๊ฐ์ฅ ๋ง์ง๋ง ์์ ์ญํ๋ ฌ์ ๊ตฌํ ๋ ์ฐ์ฐ๋์ด ๋ง์ด ํ์ํ๋ค. ๋ฐ๋ผ์ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ด ํ์ํ๋ค.</li></ul><p>$$<br>v=R+\gamma Pv \ (I-\gamma P)v = R \ v = (I-\gamma P)^{-1}R<br>$$</p><ul><li>Computation์ ์ํด์ ์ธ๊ฐ์ง iterativeํ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ค<ul><li>Dynamic Programming</li><li>Monte-Carlo Evaluation</li><li>Temporal-Difference Learning</li><li>์ ์ธ๊ฐ์ง์ ์์ธํ ๋ด์ฉ์ ์ถํ์ ๋ฑ์ฅ ์์ </li></ul></li></ul><h2 id="3-Markov-Decision-Processes"><a href="#3-Markov-Decision-Processes" class="headerlink" title="3. Markov Decision Processes"></a>3. Markov Decision Processes</h2><ul><li>MDP๊ฐ ์ค์ ๋ก ์ฐ๋ฆฌ๊ฐ RL ์์ ์์ฃผ ์ฌ์ฉ๋ ๊ฐ๋
โActually Use in RLโ</li><li>MDP Expression: Markov Decision Process โ <S, A, P, R, $\gamma$></li></ul><p><img src="/2023/05/21/20230521-markov/Untitled07.png" alt="Untitled"></p><h3 id="3-1-Policy"><a href="#3-1-Policy" class="headerlink" title="3.1 Policy"></a>3.1 Policy</h3><ul><li>Policy ์ ์: Policy $\pi$๋ ์ฃผ์ด์ง ํ์ฌ state ์์ Action ์ ๋ํ ๋ถํฌ์ด๋ค.(ํ๊ตญ๋ง์ด ๋ ์ด๋ ต๊ธฐ์, distribution over actions given states)</li></ul><p>$$<br>\pi (a|s) = P[A_{t}=a | S_{t}=s]<br>$$</p><ul><li>Policy ๋ agent ์ ํ๋์ ๊ฒฐ์ ํ๋ค.</li><li>Policy ๋ ํ์ฌ state (current state)์ ์ํฅ์ ๋ฐ๋๋ค(depend on current state, not history)</li><li>Policy ๋ Stationary ๋ผ ๊ฐ์ ํ๋ค.(time-independent)</li></ul><p><img src="/2023/05/21/20230521-markov/Untitled08.png" alt="Untitled"></p><ul><li>MDP M = <S, A, P, R, $\gamma$ >, Policy = $\pi$ ์ผ ๋,<ul><li><p>State sequnce S1, S2, S3 โฆ : <S, $P^{\pi}$> ๋ Markov Process</p></li><li><p>State and Reward Sequence S1, R2, S2, R2 โฆ : <S, $P^{\pi}, R^{\pi}, \gamma$>๋ Markov Reward Process</p></li><li><p>where P์ R์ ๋ค์๊ณผ ๊ฐ๋ค</p><p> <img src="/2023/05/21/20230521-markov/Untitled09.png" alt="Untitled"></p></li></ul></li></ul><h3 id="3-2-Value-Function"><a href="#3-2-Value-Function" class="headerlink" title="3.2 Value Function"></a>3.2 Value Function</h3><ul><li>Value function ๊ณผ Action-Value function<ul><li>value fuction: how good in policy with state s</li><li>action-value function: how good in policy with state s, action a</li></ul></li></ul><p><img src="/2023/05/21/20230521-markov/Untitled10.png" alt="Untitled"></p><h3 id="3-3-Bellman-Expectation-Equation"><a href="#3-3-Bellman-Expectation-Equation" class="headerlink" title="3.3 Bellman Expectation Equation"></a>3.3 Bellman Expectation Equation</h3><p><img src="/2023/05/21/20230521-markov/Untitled11.png" alt="Untitled"></p><p><strong>์ด ๋ท ๋ด์ฉ๋ถํฐ๋ ์ค์ง์ ์ผ๋ก Equation ๊ณผ State Diagram ๋ฑ์ด ํผ๋ถ์ ์๋ฟ์ง๋ ์๋๋ค. ์ค์ ๋ก ๊ฐ์๊ฐ ์งํ๋๋ฉด์ application ์ด๋ ๋ณธ ๋ด์ฉ์ด ๋ด๊ธด problem์ ์ง์ ๋ง๋๋ณด๊ณ , ๊ฐ ๊ฒฝ์ฐ๊ฐ ์ด๊ฒ์ ์๋ฏธํ๋ ๊ฒ์ด๊ตฌ๋ ํ๋ฉฐ feedback ์ด ์์ด์ผ ๋์ฑ ์ ์ดํด๋ ๋ด์ฉ๋ค์ด๋ผ๊ณ ์๊ฐ๋๋ค</strong></p><h3 id="3-4-Bellman-Expectation-Equation-for-V-pi"><a href="#3-4-Bellman-Expectation-Equation-for-V-pi" class="headerlink" title="3.4 Bellman Expectation Equation for $V^{\pi}$"></a>3.4 Bellman Expectation Equation for $V^{\pi}$</h3><ul><li>์ด ์ง์ ์์ Policy ์ญ์ Distribution ํน์ Process(Sequence)์ ํํ๋ก ๊ฐ๋
์ ํ์ฅํด ๊ฐ๋ค. ๋ค๋ง ์์ value function ์ ๋ํ ์ ์์์ ํฌ๊ฒ ๋ฒ์ด๋์ง ์์ผ๋ฉฐ, ์ ์ฒด state๊ณผ action ์ dependent ํ๋ค.</li></ul><p><img src="/2023/05/21/20230521-markov/Untitled12.png" alt="Untitled"></p><h3 id="3-5-Bellman-Expectation-Equation-for-Q-pi"><a href="#3-5-Bellman-Expectation-Equation-for-Q-pi" class="headerlink" title="3.5 Bellman Expectation Equation for $Q^{\pi}$"></a>3.5 Bellman Expectation Equation for $Q^{\pi}$</h3><p><img src="/2023/05/21/20230521-markov/Untitled13.png" alt="Untitled"></p><h3 id="3-6-Bellman-Expectation-Equation-for-v-pi"><a href="#3-6-Bellman-Expectation-Equation-for-v-pi" class="headerlink" title="3.6 Bellman Expectation Equation for $v_{\pi}$"></a>3.6 Bellman Expectation Equation for $v_{\pi}$</h3><p><img src="/2023/05/21/20230521-markov/Untitled14.png" alt="Untitled"></p><h3 id="3-7-Bellman-Expectation-Equation-for-q-pi"><a href="#3-7-Bellman-Expectation-Equation-for-q-pi" class="headerlink" title="3.7 Bellman Expectation Equation for $q_{\pi}$"></a>3.7 Bellman Expectation Equation for $q_{\pi}$</h3><p><img src="/2023/05/21/20230521-markov/Untitled15.png" alt="Untitled"></p><h3 id="3-8-Bellman-Expectation-Equation-Matrix-Form"><a href="#3-8-Bellman-Expectation-Equation-Matrix-Form" class="headerlink" title="3.8 Bellman Expectation Equation (Matrix Form)"></a>3.8 Bellman Expectation Equation (Matrix Form)</h3><ul><li>Bellman expectation equation ์ญ์, ๋ค์๊ณผ ๊ฐ์ด ํํ๋ ์ ์๊ณ , ์ด์ ๊ดํ ํ์ด๋ฒ ์ญ์ linear equation ์ด๋ค.</li></ul><p>$$<br>v_{\pi}=R^{\pi} + \gamma P^{\pi}v_{\pi}<br>$$</p><p>$$<br>v_{\pi}=(I-\gamma P^{\pi})^{-1}R^{\pi}<br>$$</p><h3 id="3-9-Optimal-Value-Function"><a href="#3-9-Optimal-Value-Function" class="headerlink" title="3.9 Optimal Value Function"></a>3.9 Optimal Value Function</h3><ul><li>optimal state-value function ์ ๋ชจ๋ policy ์ ๋ํด์ maximum value function ์ ์ฐพ๋ ๋ฌธ์ ์ด๋ค</li></ul><p><img src="/2023/05/21/20230521-markov/Untitled16.png" alt="Untitled"></p><ul><li>optimal action-value function ์ญ์ ๋ชจ๋ policy ์ ๋ํด์ maximum action-value function ์ ์ฐพ๋ ๋ฌธ์ ์ด๋ค.</li></ul><p><img src="/2023/05/21/20230521-markov/Untitled17.png" alt="Untitled"></p><ul><li>Optimal value function ์ MDP์์ best possible performance ๋ฅผ ์ฐพ๋ ๋ฌธ์ ๋ผ๊ณ ๋ณผ์ ์๋ค.</li><li>์ฆ, MDP is โSOLVEDโ when we know the optimal value function (q*, v*)</li></ul><h3 id="3-9-Optimal-Policy"><a href="#3-9-Optimal-Policy" class="headerlink" title="3.9 Optimal Policy"></a>3.9 Optimal Policy</h3><ul><li>Optimal Policy ๋ฌธ์ ๋, Best Action to MDP ๋ฅผ ์ฐพ๋ ๋ฌธ์ ์ด๋ค.</li></ul><p><img src="/2023/05/21/20230521-markov/Untitled18.png" alt="Untitled"></p><p><img src="/2023/05/21/20230521-markov/Untitled19.png" alt="Untitled"></p><h3 id="3-10-Finding-an-Optimal-Policy"><a href="#3-10-Finding-an-Optimal-Policy" class="headerlink" title="3.10 Finding an Optimal Policy"></a>3.10 Finding an Optimal Policy</h3><p><img src="/2023/05/21/20230521-markov/Untitled20.png" alt="Untitled"></p><h3 id="3-11-Bellman-Optimality-Equation-for-v"><a href="#3-11-Bellman-Optimality-Equation-for-v" class="headerlink" title="3.11 Bellman Optimality Equation for $v_{*}$"></a>3.11 Bellman Optimality Equation for $v_{*}$</h3><p><img src="/2023/05/21/20230521-markov/Untitled21.png" alt="Untitled"></p><h3 id="3-12-Bellman-Optimality-Equation-for-Q"><a href="#3-12-Bellman-Optimality-Equation-for-Q" class="headerlink" title="3.12 Bellman Optimality Equation for $Q^{*}$"></a>3.12 Bellman Optimality Equation for $Q^{*}$</h3><p><img src="/2023/05/21/20230521-markov/Untitled22.png" alt="Untitled"></p><h3 id="3-13-Bellman-Optimality-Equation-for-V"><a href="#3-13-Bellman-Optimality-Equation-for-V" class="headerlink" title="3.13 Bellman Optimality Equation for V*"></a>3.13 Bellman Optimality Equation for V*</h3><p><img src="/2023/05/21/20230521-markov/Untitled23.png" alt="Untitled"></p><h3 id="3-14-Bellman-Optimality-Equation-for-Q"><a href="#3-14-Bellman-Optimality-Equation-for-Q" class="headerlink" title="3.14 Bellman Optimality Equation for Q*"></a>3.14 Bellman Optimality Equation for Q*</h3><p><img src="/2023/05/21/20230521-markov/Untitled24.png" alt="Untitled"></p><h3 id="3-15-Solving-the-Bellman-Optimality-Equation"><a href="#3-15-Solving-the-Bellman-Optimality-Equation" class="headerlink" title="3.15 Solving the Bellman Optimality Equation"></a>3.15 Solving the Bellman Optimality Equation</h3><ul><li>Bellman Optimality Equation ์ Non-linear ์ด๋ค</li><li>๋ฐ๋ผ์ Closed Form Solution ์ด ์๋ค</li><li>์ด ์ญ์ iterative solution ์ด ๊ทธ ํด๋ฒ<ul><li>Value Iteration</li><li>Policy Iteration</li><li>Q-learning</li><li>Sarsa</li></ul></li><li>์ solution ์ ๊ฐ ๋ด์ฉ ์ญ์, ์ถํ ๊ฐ์์์ ์งํ๋๋ฆฌ๋ผ ๊ธฐ๋ํ๋ค.</li></ul>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/DataScience/">DataScience</category>
<category domain="https://emjayahn.github.io/tags/Markov/">Markov</category>
<category domain="https://emjayahn.github.io/tags/Markov-Decision-Process/">Markov Decision Process</category>
<comments>https://emjayahn.github.io/2023/05/21/20230521-markov/#disqus_thread</comments>
</item>
<item>
<title>[FastAPI] FastAPI ์
๋ฌธ part2 - CRUD ์ดํ๋ฆฌ์ผ์ด์
๋ง๋ค๊ธฐ</title>
<link>https://emjayahn.github.io/2023/05/07/20230424-fast-api-2/</link>
<guid>https://emjayahn.github.io/2023/05/07/20230424-fast-api-2/</guid>
<pubDate>Sun, 07 May 2023 12:29:05 GMT</pubDate>
<description><p>์ง๋ part1์์ FastAPI๋ฅผ ํ์ฉํด ๊ฐ๋จํ โhello worldโ์ โroutingโ์ ์ดํด๋ณด์๋ค. ์ด๋ฒ ๊ธ์์๋ CRUD ๊ธฐ๋ฅ์ ์ํํ๋ ๊ฐ๋จํ ์ดํ๋ฆฌ์ผ์ด์
์ ๋ง๋ค์ด๋ณด๋ฉด์ FastAPI ํ๋ ์์ํฌ์ ์น์ํด์ ธ๋ณด์.</p>
<p>์๋์ ์ค์ต ๊ณผ์ ์ ์ง๋ part1 ๊ธ์์ ์ด์ด์ ํด๋ณด๋ ๊ฒ์ด๋ฏ๋ก, ์์ ๊ธ์ ๋จผ์ ์ฝ๊ณ ๋ฐ๋ผํด๋ณด๋ฉด ์ข๊ฒ ๋ค.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>์ง๋ part1์์ FastAPI๋ฅผ ํ์ฉํด ๊ฐ๋จํ โhello worldโ์ โroutingโ์ ์ดํด๋ณด์๋ค. ์ด๋ฒ ๊ธ์์๋ CRUD ๊ธฐ๋ฅ์ ์ํํ๋ ๊ฐ๋จํ ์ดํ๋ฆฌ์ผ์ด์
์ ๋ง๋ค์ด๋ณด๋ฉด์ FastAPI ํ๋ ์์ํฌ์ ์น์ํด์ ธ๋ณด์.</p><p>์๋์ ์ค์ต ๊ณผ์ ์ ์ง๋ part1 ๊ธ์์ ์ด์ด์ ํด๋ณด๋ ๊ฒ์ด๋ฏ๋ก, ์์ ๊ธ์ ๋จผ์ ์ฝ๊ณ ๋ฐ๋ผํด๋ณด๋ฉด ์ข๊ฒ ๋ค.</p><span id="more"></span><p>๐๐ป!์ฌ๊ธฐ์ ์ ๊น!๐๐ป</p><p>CRUD ๋ฅผ ๊ฐ๋จํ๊ฒ ์ค๋ช
ํ์๋ฉด, C: Create(์์ฑ), R: Read(์ฝ๊ธฐ), U: Update(๊ฐฑ์ ), Delete(์ญ์ )๋ฅผ ์ผ์ปซ๋ ๋ง์ด๋ค. API ๋ฅผ ๊ตฌ์ถํ ๋ ์ฌ์ฉ์ ํน์ ํด๋ผ์ด์ธํธ๊ฐ ์๊ตฌํ๋ ๊ธฐ๋ณธ์ ์ธ ๊ธฐ๋ฅ์ด๋ผ๊ณ ์ดํดํ๋ฉด ์ข๊ฒ ๋ค.</p><h2 id="1-Alarm-์ดํ๋ฆฌ์ผ์ด์
-๋ง๋ค๊ธฐ"><a href="#1-Alarm-์ดํ๋ฆฌ์ผ์ด์
-๋ง๋ค๊ธฐ" class="headerlink" title="1. Alarm ์ดํ๋ฆฌ์ผ์ด์
๋ง๋ค๊ธฐ"></a>1. Alarm ์ดํ๋ฆฌ์ผ์ด์
๋ง๋ค๊ธฐ</h2><p>์ง๊ธ๋ถํฐ ์ฐ๋ฆฌ๊ฐ ๊น๋จน๊ธฐ ์ฝ๊ณ ์๊ธฐ์์ผ์ผ ํ๋ ์๋๋ค์ ๋ฆฌ์คํธ๋ฅผ ๋ณด์ฌ์ฃผ๊ณ , ์ถ๊ฐํ๋ ๊ธฐ๋ฅ์ ๊ฐ๊ณ ์๋ ์ดํ๋ฆฌ์ผ์ด์
์ ๋ง๋ค์ด๋ณด๋ ค๊ณ ํ๋ค. ๋จผ์ ์ง๋ part1์์ ๋ง๋ค์๋ <a href="http://main.py/"><code>main.py</code></a>์ <code>routers/new_router.py</code>์ ์ฝ๋๋ฅผ ์ถ๊ฐํ๋ ํํ๋ก ์ด์ด๊ฐ๋ณด๋ ค๊ณ ํ๋ค. ๋จผ์ new_router.py์ ๋ค์๊ณผ ๊ฐ์ ์ฝ๋๋ฅผ ์ถ๊ฐํ์.</p><h3 id="1-1-์๋ก์ด-router-์ถ๊ฐ"><a href="#1-1-์๋ก์ด-router-์ถ๊ฐ" class="headerlink" title="1-1. ์๋ก์ด router ์ถ๊ฐ"></a>1-1. ์๋ก์ด router ์ถ๊ฐ</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># routers/new_router.py</span></span><br><span class="line"></span><br><span class="line">alarm_list = []</span><br><span class="line"></span><br><span class="line"><span class="meta">@router.get(<span class="params"><span class="string">"/alarm"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">show_alarm</span>() -> <span class="built_in">dict</span>:</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"alarms"</span>: alarm_list</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"><span class="meta">@router.post(<span class="params"><span class="string">"/alarm"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">add_alarm</span>(<span class="params">alarm: <span class="built_in">dict</span></span>) -> <span class="built_in">dict</span>:</span><br><span class="line"> alarm_list.append(alarm)</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Your ALARM added successfully."</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><p>์ ์ฝ๋๋ฅผ ์ดํด๋ณด๋ฉด, ๋จผ์ ์ ์ญ alarm_list๋ผ๋ ๋น ๋ฆฌ์คํธ๋ฅผ ์คํํด์ฃผ๊ณ , ํ ๊ฐ์ GET ๋ฉ์๋์ POST ๋ฉ์๋๋ฅผ ๋ง๋ค์ด ์ค๋ค. </p><p>GET๋ฉ์๋์ ์ฝ๋๋ถํฐ ์ดํด๋ณด๋ฉด, uri(<code>/alarm</code>)๊ฐ GET ๋ฉ์๋๋ก ๋ค์ด์ค๋ฉด, (์ฐ๋ฆฌ๊ฐ ๋ฏธ๋ฆฌ ์์ฑํ๋ ์ฝ๋์์ ์ฃผ์ํ ์ ์ ์ฐ๋ฆฌ๋ <code>new_router.py</code>๋ฅผ ๋ง๋ค ๋, prefix=โ/newโ ๋ผ๊ณ ์ฃผ์๋ค. ๋ฐ๋ผ์ ์ ์ฒด uri๋ /new/alarm์ด ๋๊ฒ ๋ค.) ์๋์ <code>show_alarm()</code>์ด ์คํ๋๋ค. ์ด ํจ์๋ ์ฐ๋ฆฌ๊ฐ ๋ฏธ๋ฆฌ ์ ์ธํด ๋์๋ <code>alarm_list</code>๋ฅผ ๋ฐํํ๋ ํจ์์ด๋ค.</p><p>POST๋ฉ์๋์ ์ฝ๋๋ฅผ ์ดํด๋ณด๋ฉด, uri(<code>/alarm</code>)๊ฐ POST ๋ฉ์๋๋ก ๋ค์ด์ค๋ฉด, ์๋์ <code>add_alarm()</code> ํจ์๊ฐ ์คํ๋๋ค. ์ด ํจ์๋ ์ธ์๋ก ๋ฐ์ <code>alarm</code>์ <code>alram_list</code>์ ์ถ๊ฐํ๊ณ , ์ฑ๊ณต์ ์ผ๋ก ์ถ๊ฐ ๋์๋ค๋ ๋ฉ์์ง๊น์ง ๋ฐํํ๋ ํจ์์ด๋ค.</p><h3 id="1-2-ํ
์คํธ-ํด๋ณด๊ธฐ"><a href="#1-2-ํ
์คํธ-ํด๋ณด๊ธฐ" class="headerlink" title="1-2. ํ
์คํธ ํด๋ณด๊ธฐ"></a>1-2. ํ
์คํธ ํด๋ณด๊ธฐ</h3><p>์ฌ๊ธฐ๊น์ง ์์ฑํ ์ฝ๋๋ฅผ ํ
์คํธ ํด ๋ณด์.</p><p>๋ค์์ ๋ช
๋ น์ด๋ก ์ฐ๋ฆฌ์ ์ดํ๋ฆฌ์ผ์ด์
์ ์คํํด๋ณด์.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">uvicorn main:app --port 8080 --reload</span><br></pre></td></tr></table></figure><p>์๋กญ๊ฒ ๋ง๋ uri ๋ก ํ
์คํธํ๊ธฐ ์ํด ๋ค์์ ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ๋ค. ๋จผ์ GET ๋ฉ์๋์ ๋ํด์๋,</p><p>(1) GET ๋ฉ์๋ ํ
์คํธ ๋ช
๋ น์ด</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'GET'</span> <span class="string">'http://localhost:8080/new/alarm'</span> -H <span class="string">'accept: application/json'</span></span><br></pre></td></tr></table></figure><p><img src="/2023/05/07/20230424-fast-api-2/Untitled.png" alt="Untitled"></p><p>์์ง ์ฐ๋ฆฌ์ alarm_list์ ์ถ๊ฐ๋ ๊ฒ์ด ์์ผ๋ฏ๋ก ๋น ๋ฆฌ์คํธ๋ก ๋์ค๋ ๊ฒ์ด ๋น์ฐํ๋ค.</p><p>(2) POST ๋ฉ์๋ ํ
์คํธ ๋ช
๋ น์ด</p><p>์ด์ ๋ค์์ ๋ช
๋ น์ด๋ฅผ ํตํด ์ฐ๋ฆฌ์ alarm_list์ ์๋ก์ด ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํด๋ณด์.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'POST'</span> <span class="string">'http://localhost:8080/new/alarm'</span> -H <span class="string">'accept: application/json'</span> -H <span class="string">'Content-Type: application/json'</span> -d <span class="string">'{"id": 1, "alarm": "You pushed the first alarm in your list!"}'</span></span><br></pre></td></tr></table></figure><p><img src="/2023/05/07/20230424-fast-api-2/Untitled_01.png" alt="Untitled"></p><p>์ฑ๊ณต์ ์ผ๋ก ์ถ๊ฐ๋ ๋ค์ ๋ค์ (1)์ GET๋ฉ์๋๋ฅผ ์คํํด๋ณด๋ฉด, ์ฒ์๊ณผ๋ ๋ค๋ฅด๊ฒ ๋ฐฉ๊ธ ์ถ๊ฐํ ๋ฉ์์ง๊ฐ ์ถ๋ ฅ๋๋ ๊ฒ์ ํ์ธ ํ ์ ์๋ค.</p><p>์ด๋ ๊ฒ ์ฐ๋ฆฌ๋ CRUD ์ค C, R์ ์ํํ๋ ๊ธฐ๋ฅ์ ๋ง๋ค์ด ๋ณด์๋ค.</p><h2 id="2-๋ฐ์ดํฐ-๊ฒ์ฆ-pydantic"><a href="#2-๋ฐ์ดํฐ-๊ฒ์ฆ-pydantic" class="headerlink" title="2. ๋ฐ์ดํฐ ๊ฒ์ฆ : pydantic"></a>2. ๋ฐ์ดํฐ ๊ฒ์ฆ : pydantic</h2><p>๋ฐ์ดํฐ๋ฅผ ์์ ํ๊ณ ์ง์ฐ๋ ๊ฒ์ API, ์ดํ๋ฆฌ์ผ์ด์
์
์ฅ์์๋ ๋งค์ฐ critical ํ ๊ธฐ๋ฅ์ด๋ค. ์๋ฒ๋ฅผ ์ด์ํ๊ณ ๊ฐ๋ฐํ๋ ์
์ฅ์์๋ ์์ง๋ ๋ฐ์ดํฐ๋ฅผ ๋ณ๊ฒฝํ๊ฑฐ๋ ์ญ์ ํ๋ ์ก์
์ด ์คํ๋๊ธฐ ๋๋ฌธ์ด๋ค. ๋ฐ๋ผ์ ์ฐ๋ฆฌ๋ ์์ ํ๋ ค๊ณ ํ๋ ์๋ก์ด ๋ฐ์ดํฐ๊ฐ ๊ธฐ์กด ํ์์ ์๋ง๊ฒ ์์ ๋๊ฑฐ๋ ์ญ์ ๋๋์ง ๊ฒ์ฆํด์ผํ๋ค. ์ด ์์
์ python ์์๋ โPydanticโ์ด๋ผ๊ณ ํ๋ ํธํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด ํด๋น ๋ฐ์ดํฐ๋ฅผ ๊ฒ์ฆํ๋ค.</p><h3 id="2-1-๋ชจ๋ธ-์ธ์ฐ๊ธฐ"><a href="#2-1-๋ชจ๋ธ-์ธ์ฐ๊ธฐ" class="headerlink" title="2-1. ๋ชจ๋ธ ์ธ์ฐ๊ธฐ."></a>2-1. ๋ชจ๋ธ ์ธ์ฐ๊ธฐ.</h3><p>Web Application ์์ ๋ฐ์ดํฐ๊ฐ ์ด๋ป๊ฒ ๊ตฌ์ฑ๋๊ณ ์ฒ๋ฆฌ๋์ด์ผ ํ๋์ง ๋ฏธ๋ฆฌ ์ ์ธํด ๋๋ ๊ฒ์ ๋ชจ๋ธ์ด๋ผ๊ณ ํ๋ค. ์ฐ๋ฆฌ ์ดํ๋ฆฌ์ผ์ด์
์๋ <a href="http://model.py/"><code>model.py</code></a>๋ฅผ ๋ง๋ค๊ณ ํด๋น ํ์ผ์ ๋ค์๊ณผ ๊ฐ์ด ์์ฑํ์.</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># model.py</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> pydantic <span class="keyword">import</span> BaseModel</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Alarm</span>(<span class="title class_ inherited__">BaseModel</span>):</span><br><span class="line"> <span class="built_in">id</span>: <span class="built_in">int</span></span><br><span class="line"> alarm: <span class="built_in">str</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">AlarmData</span>(<span class="title class_ inherited__">BaseModel</span>):</span><br><span class="line"> alarm: <span class="built_in">str</span></span><br></pre></td></tr></table></figure><p>์ฐ๋ฆฌ๊ฐ ๋ค๋ฃฐ Alarm์ด๋ผ๋ ํด๋์ค๋ id ์ alarm์ด๋ผ๋ ๋ด์ฉ์ผ๋ก ๊ตฌ์ฑ๋๊ณ ์ด ํ์์ ๋ง๊ฒ ๋ฐ์ดํฐ๊ฐ ๋ค์ด์์ผ ํ๋ค๋ ๊ฒ์ด๋ค. ๊ทธ ์๋ AlarmData๋ ๋ค์ด์ด ๋ฐ์ดํฐ ์
๋ฐ์ดํธ ๋ถ๋ถ์์ ํ์ฉ๋ ๋ด์ฉ์ด๋ค. ์์ ํ ๋ฐ์ดํฐ๊ฐ str ํ์์ผ๋ก ๋ค์ด์์ผ ๋จ์ ์๋ฏธํ๋ค.</p><h3 id="2-2-model-py๋ฅผ-ํ์ฉํ-์ฝ๋-์์ "><a href="#2-2-model-py๋ฅผ-ํ์ฉํ-์ฝ๋-์์ " class="headerlink" title="2-2. model.py๋ฅผ ํ์ฉํ ์ฝ๋ ์์ "></a>2-2. model.py๋ฅผ ํ์ฉํ ์ฝ๋ ์์ </h3><p>์์ <a href="http://model.py/">model.py</a> ๋ฅผ ๋ง๋ค์์ผ๋ฉด ์ฐ๋ฆฌ์ ๋ผ์ฐํฐ์๋ ํด๋น ๋ฐ์ดํฐ ๊ฒ์ฆ ์์
์ด ์ถ๊ฐ ๋ ์ ์๋๋ก ์ฝ๋๋ฅผ ์์ ํ์. ๋จผ์ ๋ฐ์ดํฐ๊ฐ ๊ฐ์ฅ ๋จผ์ ์ถ๊ฐ ๋๋ @router.post(โ/alarmโ)๋ถ๋ถ์ ํจ์ add_alarm(alarm: Alarm) ์ด๋ค.</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@router.post(<span class="params"><span class="string">"/alarm"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">add_alarm</span>(<span class="params">alarm: Alarm</span>) -> <span class="built_in">dict</span>:</span><br><span class="line"> alarm_list.append(alarm)</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Your ALARM added successfully."</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><p>์ด๋ ๊ฒ ๋๋ฉด POST ๋์ด ์ ๋ฌ๋๋ ๋ฐ์ดํฐ๊ฐ ์ฐ๋ฆฌ๊ฐ ๋ฏธ๋ฆฌ ์์ฑํด๋ ๋ชจ๋ธ(Alarm)์ id, alarm ์ด ๊ฐ๊ฐ int์ด๊ณ string ์ธ์ง ๊ฒ์ฆํ๊ณ ์คํ๋๊ฒ ๋๋ค.</p><h2 id="3-๋ฐ์ดํฐ-์์ "><a href="#3-๋ฐ์ดํฐ-์์ " class="headerlink" title="3. ๋ฐ์ดํฐ ์์ "></a>3. ๋ฐ์ดํฐ ์์ </h2><h3 id="3-1-์๋ก์ด-router-์ถ๊ฐ"><a href="#3-1-์๋ก์ด-router-์ถ๊ฐ" class="headerlink" title="3-1. ์๋ก์ด router ์ถ๊ฐ"></a>3-1. ์๋ก์ด router ์ถ๊ฐ</h3><p>์๋ก์ด ๋ผ์ฐํฐ๋ฅผ ์ถ๊ฐํ์ฌ ์ฐ๋ฆฌ๊ฐ ๊ฐ์ง๊ณ ์๋ alarm_list์ ๋ฐ์ดํฐ๋ฅผ ์์ ํด๋ณด์.</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@router.put(<span class="params"><span class="string">"/alarm/{alarm_id}"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">update_alarm</span>(<span class="params">alarm_data: AlarmData, alarm_id: <span class="built_in">int</span>=Path(<span class="params">..., title=<span class="string">"ID to be updated"</span></span>)</span>) -> <span class="built_in">dict</span>:</span><br><span class="line"> <span class="keyword">for</span> each_alarm <span class="keyword">in</span> alarm_list:</span><br><span class="line"> <span class="keyword">if</span> each_alarm.<span class="built_in">id</span> == alarm_id:</span><br><span class="line"> each_alarm.alarm = alarm_data.alarm</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Your Alarm is successfully updated."</span></span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"The ID which you gave doesn't exist."</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><p>PUT ๋ฉ์๋๋ก <code>/alarm/alarm_id</code> ํํ๋ก uri ๊ฐ ์ ๋ฌ ๋๋ฉด, ์๋์ <code>update_alarm()</code> ํจ์๊ฐ ์คํ๋๋ค. <code>update_alarm</code> ํจ์๋ <code>alarm_data</code>์ ๋ณ๊ฒฝํ๊ณ ์ ํ๋ <code>alarm_id</code> ๋ฅผ ์ธ์๋ก ๋ฐ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์๋์ ๋ก์ง์ ์ฐ๋ฆฌ๊ฐ ๋ฏธ๋ฆฌ ๊ฐ๊ณ ์๋ <code>alarm_list</code>๋ฅผ ์์๋๋ก ์กฐํํ๋ฉฐ ์ธ์๋ก ์ฃผ์ด์ง <code>alarm_id</code> ๊ฐ ์ฐ๋ฆฌ์ ๋ฆฌ์คํธ์ ์กด์ฌํ๋ค๋ฉด alarm ๋ฐ์ดํฐ๋ฅผ ๋ณ๊ฒฝํ๋ ๊ฒ์ด๋ค.</p><h3 id="3-2-ํ
์คํธ-ํด๋ณด๊ธฐ"><a href="#3-2-ํ
์คํธ-ํด๋ณด๊ธฐ" class="headerlink" title="3-2. ํ
์คํธ ํด๋ณด๊ธฐ"></a>3-2. ํ
์คํธ ํด๋ณด๊ธฐ</h3><p>๋จผ์ ์์ ๋์ผํ๊ฒ ์๋ฒ๋ฅผ ์คํํด์ฃผ๊ณ , ์๋ก์ด ๋ฐ์ดํฐ 2๊ฐ ๋ฅผ ์ถ๊ฐํ๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'POST'</span> <span class="string">'http://localhost:8080/new/alarm'</span> -H <span class="string">'accept: application/json'</span> -H <span class="string">'Content-Type: application/json'</span> -d <span class="string">'{"id": 1, "alarm": "You pushed the first alarm in your list!"}'</span></span><br></pre></td></tr></table></figure><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'POST'</span> <span class="string">'http://localhost:8080/new/alarm'</span> -H <span class="string">'accept: application/json'</span> -H <span class="string">'Content-Type: application/json'</span> -d <span class="string">'{"id": 2, "alarm": "You pushed the second alarm in your list!"}'</span></span><br></pre></td></tr></table></figure><p>๋ค์์ ๋ช
๋ น์ด๋ก ์ฒซ๋ฒ์งธ๋ก ์ถ๊ฐํ ๋ฐ์ดํฐ๋ฅผ ์์ ํด๋ณด์.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'PUT'</span> <span class="string">'http://localhost:8080/new/alarm/1'</span> -H <span class="string">'accept: application/json'</span> -H <span class="string">'Content-Type: application/json'</span> -d <span class="string">'{"alarm": "Your first Item is changed with this updated ONE!!!"}'</span></span><br></pre></td></tr></table></figure><p>์์ ํ ๋ค์ GET ๋ฉ์๋ ํ
์คํธ ๋ช
๋ น์ด๋ฅผ ์ํํด ๋ฐ์ดํฐ๊ฐ ์ ์์ ๋์๋์ง ํ์ธํด๋ณด์.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'GET'</span> <span class="string">'http://localhost:8080/new/alarm'</span> -H <span class="string">'accept: application/json'</span></span><br></pre></td></tr></table></figure><p><img src="/2023/05/07/20230424-fast-api-2/Untitled_02.png" alt="Untitled"></p><h2 id="4-๋ฐ์ดํฐ-์ญ์ "><a href="#4-๋ฐ์ดํฐ-์ญ์ " class="headerlink" title="4. ๋ฐ์ดํฐ ์ญ์ "></a>4. ๋ฐ์ดํฐ ์ญ์ </h2><h3 id="4-1-์๋ก์ด-router-์ถ๊ฐ"><a href="#4-1-์๋ก์ด-router-์ถ๊ฐ" class="headerlink" title="4-1. ์๋ก์ด router ์ถ๊ฐ"></a>4-1. ์๋ก์ด router ์ถ๊ฐ</h3><p>๋ง์ง๋ง์ผ๋ก ์ญ์ ์ ๋ํ ๊ธฐ๋ฅ์ ์ถ๊ฐํด๋ณด์. ๋ค์๊ณผ ๊ฐ์ด router์ ์ถ๊ฐํ๋ค.</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@router.delete(<span class="params"><span class="string">"/alarm/{alarm_id}"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">delete_alarm</span>(<span class="params">alarm_id: <span class="built_in">int</span></span>) -> <span class="type">Dict</span>:</span><br><span class="line"> <span class="keyword">for</span> each_index <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(alarm_list)):</span><br><span class="line"> alarm = alarm_list[each_index]</span><br><span class="line"> <span class="keyword">if</span> alarm.<span class="built_in">id</span> == alarm_id:</span><br><span class="line"> alarm_list.pop(each_index)</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Alarm is successfully deleted."</span></span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"The ID which you gave doesn't exist."</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><p>๋ก์ง์ ๊ฐ๋จํ๋ค. ์ ๋ฌ๋ id ๊ฐ๊ณผ ๊ธฐ์กด์ alarm_list ์ id ๊ฐ ๊ฐ์ผ๋ฉด ํด๋น ๋ฐ์ดํฐ๋ฅผ ๋ฆฌ์คํธ์์ ์ญ์ ํ๋ ๊ฒ์ด๋ค.</p><h3 id="4-2-ํ
์คํธ-ํด๋ณด๊ธฐ"><a href="#4-2-ํ
์คํธ-ํด๋ณด๊ธฐ" class="headerlink" title="4-2. ํ
์คํธ ํด๋ณด๊ธฐ."></a>4-2. ํ
์คํธ ํด๋ณด๊ธฐ.</h3><p>๋จผ์ ์์ ๋์ผํ๊ฒ ์๋ฒ๋ฅผ ์คํํด์ฃผ๊ณ , ์๋ก์ด ๋ฐ์ดํฐ 2๊ฐ ๋ฅผ ์ถ๊ฐํ๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'POST'</span> <span class="string">'http://localhost:8080/new/alarm'</span> -H <span class="string">'accept: application/json'</span> -H <span class="string">'Content-Type: application/json'</span> -d <span class="string">'{"id": 1, "alarm": "You pushed the first alarm in your list!"}'</span></span><br></pre></td></tr></table></figure><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'POST'</span> <span class="string">'http://localhost:8080/new/alarm'</span> -H <span class="string">'accept: application/json'</span> -H <span class="string">'Content-Type: application/json'</span> -d <span class="string">'{"id": 2, "alarm": "You pushed the second alarm in your list!"}'</span></span><br></pre></td></tr></table></figure><p>์ฒซ๋ฒ์งธ ๋ฐ์ดํฐ๋ฅผ ์ญ์ ํด๋ณด์.</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'DELETE'</span> <span class="string">'http://localhost:8080/new/alarm/1'</span> -H <span class="string">'accept: application/json'</span></span><br></pre></td></tr></table></figure><p>์ญ์ ํ ๋ค์ GET ๋ฉ์๋ ํ
์คํธ ๋ช
๋ น์ด๋ฅผ ์ํํด ๋ฐ์ดํฐ๊ฐ ์ ์์ ๋์๋์ง ํ์ธํด๋ณด์.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X <span class="string">'GET'</span> <span class="string">'http://localhost:8080/new/alarm'</span> -H <span class="string">'accept: application/json'</span></span><br></pre></td></tr></table></figure><p><img src="/2023/05/07/20230424-fast-api-2/Untitled_03.png" alt="Untitled"></p><h2 id="5-์ ๋ฆฌํ๊ธฐ"><a href="#5-์ ๋ฆฌํ๊ธฐ" class="headerlink" title="5. ์ ๋ฆฌํ๊ธฐ"></a>5. ์ ๋ฆฌํ๊ธฐ</h2><p>์ด๋ฒ ๊ธ์์๋ Pydantic์ ํตํ ๋ฐ์ดํฐ ๊ฒ์ฆ ๋ฐฉ๋ฒ๊ณผ CRUD ์ดํ๋ฆฌ์ผ์ด์
์ ๋ง๋ค์ด๋ณด๋ฉด์ FastAPI ํ๋ ์์ํฌ์ ํ๋จ๊ณ ์น์ํด์ง๋ ์ค์ต์ ํด๋ณด์๋ค. ๊ธ์ ๋ค์ ํ ๋ฒ ๋์ด์ผ๋ณด๋ฉด, ์ฐ๋ฆฌ๊ฐ ๊ธฐ๋ฅ์ ์ถ๊ฐํ ๋ ํ๋ ํ๋์ ๊ฐ๋จํ๋ค. ๋จ์ง Router ๋ง ์ถ๊ฐํ๋ฉด ๋๋ ๊ฒ์ด๋ค! ์ด๋ค uri (trigger)๊ฐ ์์ ๋, ์ด๋ค ๋์์ ํ๊ฒ๋ ํ๋ ๊ฒ์ด router์ด๋ค. ์ด router๊ฐ ๋์ํ๊ฒ๋ ํ๊ธฐ ์ํด ๋ถ์์ ์ธ model๊ณผ pydantic ๋ฑ์ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๊ธฐ๋ง ํ๋ฉด ๋๋ค. ๋ง์ง๋ง์ผ๋ก, ์ค๋์ ์ค์ต์ด ์ ๋์ํ์ง ์๋ ์ฌ๋๋ค ์ํด ์ฐ๋ฆฌ๊ฐ ์ค์ตํ ํ์ผ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ์ main, model, router ์ฝ๋ ์ ์ฒด๋ฅผ ์ฒจ๋ถํ๋ฉฐ ์ด๋ฒ ๊ธ์ ๋ง๋ฌด๋ฆฌ ํ๋ค.</p><h3 id="5-0-tree"><a href="#5-0-tree" class="headerlink" title="5-0. tree"></a>5-0. tree</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">./my_first_app</span><br><span class="line">โโโ main.py</span><br><span class="line">โโโ model.py</span><br><span class="line">โโโ routers</span><br><span class="line"> โโโ new_router.py</span><br></pre></td></tr></table></figure><h3 id="5-1-main-py"><a href="#5-1-main-py" class="headerlink" title="5-1. main.py"></a>5-1. main.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># main.py</span></span><br><span class="line"><span class="keyword">from</span> fastapi <span class="keyword">import</span> FastAPI</span><br><span class="line"><span class="keyword">from</span> typing <span class="keyword">import</span> <span class="type">Dict</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> routers.new_router <span class="keyword">import</span> router</span><br><span class="line"></span><br><span class="line">app = FastAPI()</span><br><span class="line"></span><br><span class="line">app.include_router(router)</span><br><span class="line"></span><br><span class="line"><span class="meta">@app.get(<span class="params"><span class="string">"/"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">helloworld</span>() -> <span class="type">Dict</span>:</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Hello World"</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h3 id="5-2-new-router-py"><a href="#5-2-new-router-py" class="headerlink" title="5-2. new_router.py"></a>5-2. new_router.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> fastapi <span class="keyword">import</span> APIRouter, Path</span><br><span class="line"><span class="keyword">from</span> typing <span class="keyword">import</span> <span class="type">Dict</span></span><br><span class="line"><span class="keyword">from</span> model <span class="keyword">import</span> Alarm, AlarmData</span><br><span class="line"></span><br><span class="line">router = APIRouter(</span><br><span class="line"> prefix=<span class="string">"/new"</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">alarm_list = []</span><br><span class="line"></span><br><span class="line"><span class="meta">@router.get(<span class="params"><span class="string">"/alarm"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">show_alarm</span>() -> <span class="type">Dict</span>:</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"alarms"</span>: alarm_list</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"><span class="meta">@router.post(<span class="params"><span class="string">"/alarm"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">add_alarm</span>(<span class="params">alarm: Alarm</span>) -> <span class="type">Dict</span>:</span><br><span class="line"> alarm_list.append(alarm)</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Your ALARM added successfully."</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"><span class="meta">@router.put(<span class="params"><span class="string">"/alarm/{alarm_id}"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">update_alarm</span>(<span class="params">alarm_data: AlarmData, alarm_id: <span class="built_in">int</span>=Path(<span class="params">..., title=<span class="string">"ID to be updated"</span></span>)</span>) -> <span class="type">Dict</span>:</span><br><span class="line"> <span class="keyword">for</span> each_alarm <span class="keyword">in</span> alarm_list:</span><br><span class="line"> <span class="keyword">if</span> each_alarm.<span class="built_in">id</span> == alarm_id:</span><br><span class="line"> each_alarm.alarm = alarm_data.alarm</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Your Alarm is successfully updated."</span></span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"The ID which you gave doesn't exist."</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"><span class="meta">@router.delete(<span class="params"><span class="string">"/alarm/{alarm_id}"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">delete_alarm</span>(<span class="params">alarm_id: <span class="built_in">int</span></span>) -> <span class="type">Dict</span>:</span><br><span class="line"> <span class="keyword">for</span> each_index <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(alarm_list)):</span><br><span class="line"> alarm = alarm_list[each_index]</span><br><span class="line"> <span class="keyword">if</span> alarm.<span class="built_in">id</span> == alarm_id:</span><br><span class="line"> alarm_list.pop(each_index)</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Alarm is successfully deleted."</span></span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"The ID which you gave doesn't exist."</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"><span class="meta">@router.get(<span class="params"><span class="string">"/test"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">helloworld_new</span>( ) -> <span class="type">Dict</span>:</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"new router Hello!"</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><h3 id="5-3-model-py"><a href="#5-3-model-py" class="headerlink" title="5-3. model.py"></a>5-3. model.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># model.py</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> pydantic <span class="keyword">import</span> BaseModel</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Alarm</span>(<span class="title class_ inherited__">BaseModel</span>):</span><br><span class="line"> <span class="built_in">id</span>: <span class="built_in">int</span></span><br><span class="line"> alarm: <span class="built_in">str</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">AlarmData</span>(<span class="title class_ inherited__">BaseModel</span>):</span><br><span class="line"> alarm: <span class="built_in">str</span></span><br></pre></td></tr></table></figure>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/FastAPI/">FastAPI</category>
<category domain="https://emjayahn.github.io/tags/FastAPI/">FastAPI</category>
<category domain="https://emjayahn.github.io/tags/API/">API</category>
<category domain="https://emjayahn.github.io/tags/%EC%9B%B9%EC%84%9C%EB%B2%84/">์น์๋ฒ</category>
<comments>https://emjayahn.github.io/2023/05/07/20230424-fast-api-2/#disqus_thread</comments>
</item>
<item>
<title>[FastAPI] FastAPI ์
๋ฌธ part1 - ์ค์น/๋ผ์ฐํ
</title>
<link>https://emjayahn.github.io/2023/04/23/20230423-fast-api-1/</link>
<guid>https://emjayahn.github.io/2023/04/23/20230423-fast-api-1/</guid>
<pubDate>Sun, 23 Apr 2023 11:22:56 GMT</pubDate>
<description><p>ํ์ฌ์์๋ ๊ทธ๋์ ๋ฐ์ดํฐ ํ์ดํ๋ผ์ธ์ ๋ง๋ค๊ณ ๋ชจ๋ธ์ ๋ง๋๋๋ฐ ์ด์คํ์๋ค. ๊ทธ๋ฆฌ๊ณ ๋ชจ๋ธ ๊ฐ๋ฐ์ด ์๋ฃ๋๊ณ , ์ด๋ฅผ ์๋น์คํ๊ธฐ ์ํด ๋ค์ํ ๋ฐฉ๋ฒ์ ๊ณ ๋ฏผํ์๋ค. ๋ฌผ๋ก ๋ชจ๋ธ ๊ฐ๋ฐ์ ๊ธฐํํ๊ธฐ์ ์๋น์ค๋ฅผ ์ด๋ป๊ฒ ํ ์ง ๊ตฌ์กฐ์ ๊ณํ์ ์ธ์ ์ผ๋, ๋ค์ํ ๋ด๋ถ์ ์ธ ์ด์๋ค์ด ์์๋ค. ์ค์๊ฐ์ฑ๊ณผ ๋น ๋ฅธ ์๋ต์ด ํ์ํ time-out ์ด์, ์ฅ๋น์ ๋
ธํํ ๋ฑ ์ฌ๋ฌ๊ฐ์ง ๋ฌธ์ ๋ฅผ ๋ง์ฃผํ์์๊ณ ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์ ์์ฒด ๊ฐ๋ฐํ API๊ฐ ํ์ํ๋ค๋ ๊ฒ์ด ๊ฒฐ๋ก ์ด์๋ค.</p>
<p>๋จธ์ ๋ฌ๋ ๋ชจ๋ธ์ ์๋น์คํ๊ณ ์ด์ํ๊ธฐ ์ํด MLOps๋ผ๋ ๋จ์ด๊ฐ ๋ฑ์ฅํ์๋ค. ๋ค์ํ ํ์ฌ์ ํ๋ซํผ์์ MLOps๋ฅผ ์ง์ํ๊ธฐ ์ํด ๋ง์ ์ ํ์ ๋ด๋๊ณ ์์ผ๋ ๋ด๊ฐ ์๋ ํ๊ฒฝ์ ๋ฑ ๋ค์ด ๋ง๋ ๊ฒ์ด ์์๋ค. ๊ทธ๋์ ์ด๋ฒ ๊ธฐํ์ FastAPI ๋ฅผ ์ด์ฉํด ์์ฒด API ๋ฅผ ๋ง๋ค์๋ค. ์ค์ ๋ฐฐํฌ๋์ด ์ด์๋๊ณ ์๋ ์ฝ๋๋ ํจ์ฌ ๋ณต์กํ ์๋ ์๊ฒ ์ง๋ง ๊ธฐ๋ณธ ๋ผ๋์ ๊ตฌ์กฐ๋ ๋ชจ๋ ๋์ผํ ๊ฒ์ด๋ค. ๊ธ์ ์ฐ๋ ๋ ์ญ์ FastAPI๋ฅผ ์ฒ์ ์ฌ์ฉํด๋ณธ ๊ฒ์ด๊ธฐ์ ์คํฐ๋ํ๋ฉด์ ๋ง๋ค์๋ค. ๊ทธ๊ฐ์ ์ฝ์ง๊ณผ ์ฌ์ ์ ํ๋ฒ ์ ๋ฆฌํด๋ณด๋ฉด์, ๋์ ๋น์ทํ ๊ณ ๋ฏผ์ ํ๋ ๋ถ๋ค์๊ฒ ์กฐ๊ธ์ด๋๋ง ๋์์ด ๋๊ธธ ๋ฐ๋๋ค.</p>
<p>(๋ํ, ์ด ์๋ฆฌ์ฆ๋ฅผ ์ฐ๋๋ฐ ๋๊ธฐ์ ์ฉ๊ธฐ๋ฅผ ์ค ๊ธ๋ ์ปคํผ๋๋ฐฑ ์กฐ์ ๋ ๋ถ์๊ฒ ๊ฐ์ฌํ๋ฉฐ ๊ธ์ ์จ๋ณธ๋ค. Shout out to ๋ฌธํ๊ท &amp; ๋ฐ๋ค์)</p>
<p>์ด ๊ธ์ FastAPI ์ ์ค์น์ ๊ทธ ์
๋ฌธ ๊ทธ๋ฆฌ๊ณ ๊ธฐ์ด์ ์ธ ๋ผ์ฐํ
๊น์ง์ ๋ด์ฉ์ ๋ด์๋ค. ์์ผ๋ก FastAPI์๋ฆฌ์ฆ๋ก ๋ด์ ๊ฒ์ด๊ณ ์๋ฆฌ์ฆ ์์ ๊ธ์ ์์์ ๋ชฉ์ฐจ๋ ๋ด๊ฐ API๋ฅผ ๊ตฌ์ฑํ๋ฉด์ ์คํฐ๋ํ ์์๋๋ก ๋ด์ผ๋ ค๊ณ ๋
ธ๋ ฅํ ๊ฒ์ด๋ค. </p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>ํ์ฌ์์๋ ๊ทธ๋์ ๋ฐ์ดํฐ ํ์ดํ๋ผ์ธ์ ๋ง๋ค๊ณ ๋ชจ๋ธ์ ๋ง๋๋๋ฐ ์ด์คํ์๋ค. ๊ทธ๋ฆฌ๊ณ ๋ชจ๋ธ ๊ฐ๋ฐ์ด ์๋ฃ๋๊ณ , ์ด๋ฅผ ์๋น์คํ๊ธฐ ์ํด ๋ค์ํ ๋ฐฉ๋ฒ์ ๊ณ ๋ฏผํ์๋ค. ๋ฌผ๋ก ๋ชจ๋ธ ๊ฐ๋ฐ์ ๊ธฐํํ๊ธฐ์ ์๋น์ค๋ฅผ ์ด๋ป๊ฒ ํ ์ง ๊ตฌ์กฐ์ ๊ณํ์ ์ธ์ ์ผ๋, ๋ค์ํ ๋ด๋ถ์ ์ธ ์ด์๋ค์ด ์์๋ค. ์ค์๊ฐ์ฑ๊ณผ ๋น ๋ฅธ ์๋ต์ด ํ์ํ time-out ์ด์, ์ฅ๋น์ ๋
ธํํ ๋ฑ ์ฌ๋ฌ๊ฐ์ง ๋ฌธ์ ๋ฅผ ๋ง์ฃผํ์์๊ณ ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์ ์์ฒด ๊ฐ๋ฐํ API๊ฐ ํ์ํ๋ค๋ ๊ฒ์ด ๊ฒฐ๋ก ์ด์๋ค.</p><p>๋จธ์ ๋ฌ๋ ๋ชจ๋ธ์ ์๋น์คํ๊ณ ์ด์ํ๊ธฐ ์ํด MLOps๋ผ๋ ๋จ์ด๊ฐ ๋ฑ์ฅํ์๋ค. ๋ค์ํ ํ์ฌ์ ํ๋ซํผ์์ MLOps๋ฅผ ์ง์ํ๊ธฐ ์ํด ๋ง์ ์ ํ์ ๋ด๋๊ณ ์์ผ๋ ๋ด๊ฐ ์๋ ํ๊ฒฝ์ ๋ฑ ๋ค์ด ๋ง๋ ๊ฒ์ด ์์๋ค. ๊ทธ๋์ ์ด๋ฒ ๊ธฐํ์ FastAPI ๋ฅผ ์ด์ฉํด ์์ฒด API ๋ฅผ ๋ง๋ค์๋ค. ์ค์ ๋ฐฐํฌ๋์ด ์ด์๋๊ณ ์๋ ์ฝ๋๋ ํจ์ฌ ๋ณต์กํ ์๋ ์๊ฒ ์ง๋ง ๊ธฐ๋ณธ ๋ผ๋์ ๊ตฌ์กฐ๋ ๋ชจ๋ ๋์ผํ ๊ฒ์ด๋ค. ๊ธ์ ์ฐ๋ ๋ ์ญ์ FastAPI๋ฅผ ์ฒ์ ์ฌ์ฉํด๋ณธ ๊ฒ์ด๊ธฐ์ ์คํฐ๋ํ๋ฉด์ ๋ง๋ค์๋ค. ๊ทธ๊ฐ์ ์ฝ์ง๊ณผ ์ฌ์ ์ ํ๋ฒ ์ ๋ฆฌํด๋ณด๋ฉด์, ๋์ ๋น์ทํ ๊ณ ๋ฏผ์ ํ๋ ๋ถ๋ค์๊ฒ ์กฐ๊ธ์ด๋๋ง ๋์์ด ๋๊ธธ ๋ฐ๋๋ค.</p><p>(๋ํ, ์ด ์๋ฆฌ์ฆ๋ฅผ ์ฐ๋๋ฐ ๋๊ธฐ์ ์ฉ๊ธฐ๋ฅผ ์ค ๊ธ๋ ์ปคํผ๋๋ฐฑ ์กฐ์ ๋ ๋ถ์๊ฒ ๊ฐ์ฌํ๋ฉฐ ๊ธ์ ์จ๋ณธ๋ค. Shout out to ๋ฌธํ๊ท & ๋ฐ๋ค์)</p><p>์ด ๊ธ์ FastAPI ์ ์ค์น์ ๊ทธ ์
๋ฌธ ๊ทธ๋ฆฌ๊ณ ๊ธฐ์ด์ ์ธ ๋ผ์ฐํ
๊น์ง์ ๋ด์ฉ์ ๋ด์๋ค. ์์ผ๋ก FastAPI์๋ฆฌ์ฆ๋ก ๋ด์ ๊ฒ์ด๊ณ ์๋ฆฌ์ฆ ์์ ๊ธ์ ์์์ ๋ชฉ์ฐจ๋ ๋ด๊ฐ API๋ฅผ ๊ตฌ์ฑํ๋ฉด์ ์คํฐ๋ํ ์์๋๋ก ๋ด์ผ๋ ค๊ณ ๋
ธ๋ ฅํ ๊ฒ์ด๋ค. </p><span id="more"></span><h2 id="1-FastAPI์-์๊ฐ-๋ฐ-์ค์น"><a href="#1-FastAPI์-์๊ฐ-๋ฐ-์ค์น" class="headerlink" title="1. FastAPI์ ์๊ฐ ๋ฐ ์ค์น"></a>1. FastAPI์ ์๊ฐ ๋ฐ ์ค์น</h2><p>Python ์ธ๊ณ์ ์น ํ๋ ์์ํฌ๋ ๋ค์ํ๋ค. ๊ฐ์ฅ ์ ๋ช
ํ ์ฅ๊ณ (Django)์ ํ๋ผ์คํฌ(Flask)๊ฐ ์์ง๋ง, ์ด ํ๋ ์์ํฌ๋ค์ ๊ทธ ์ ๋ช
ํ ๋งํผ ๋ค์ํ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค. ๋ฐ๋ฉด์ ๊ทธ ์ญ์ฌ์ ์ ํต์ ์๋ํ๋ ๊ฒ๊ณผ ๋น๋ก์ ๊ทธ ์๋๊ฐ ๋๋ฆฐ ๊ฒ์ด ๋จ์ ์ด๋ค. FastAPI ๋ ๊ทธ ์ด๋ฆ์์ ๋๋ ์ ์๋ ๊ฒ์ฒ๋ผ ๋น ๋ฅด๊ณ ๊ฐ๋ฒผ์ฐ๋ฉฐ, ๊ฐ๋จํ API ๋ฅผ ๋น๊ต์ ์ฝ๊ฒ ๋น๋ํ์ฌ ํ
์คํธ๋ฒ ๋๋ก ์ฌ์ฉํ ์ ์๋ค. </p><p>๋จผ์ FastAPI๋ฅผ ์ค์ตํ ์ ์๊ฒ ์ค์นํด๋ณด์.</p><h3 id="1-1-FastAPI-์ค์น"><a href="#1-1-FastAPI-์ค์น" class="headerlink" title="1-1. FastAPI ์ค์น"></a>1-1. FastAPI ์ค์น</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ pip install fastapi</span><br></pre></td></tr></table></figure><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ pip install uvicorn </span><br><span class="line"><span class="comment"># or</span></span><br><span class="line">$ pip install <span class="string">"uvicorn[standard]"</span></span><br><span class="line"><span class="comment"># or</span></span><br><span class="line">$ pip install gunicorn</span><br></pre></td></tr></table></figure><p>์ด๋ฒ ์ค์ต์ FastAPI ๋ง ์ค์นํด๋ ๋ฌด๋ํ๋ค. ํ์ง๋ง ์น ์ดํ๋ฆฌ์ผ์ด์
์ ์ค์ ๋ก ๋ฐฐํฌํ๊ณ ๋ค์ํ request ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํด ๋์ค์ ์น ์๋ฒ๊ฐ ํ์ํ ์ ์๋ค. ์ด๋ฅผ ์ํด unicorn์ด๋ gunicorn, nginx๋ฑ์ด ๋ง์ด ์ฌ์ฉ๋๋๋ฐ ์ด์ ๋ํด์๋ ๋์ค์ ์ข๋ ์์ธํ ์ดํด๋ณด์. ์ง๊ธ ๋จ๊ณ์์๋ fastapi, uvicorn ๋ง ์นํด๋ ์ค์ตํ๊ณ ๋ฐฐํฌํ๋๋ฐ ํฐ ๋ฌธ์ ๊ฐ ์๋ค.</p><h3 id="1-2-HelloWorld"><a href="#1-2-HelloWorld" class="headerlink" title="1-2. HelloWorld"></a>1-2. HelloWorld</h3><p>FastAPI ๋ฅผ ์ค์นํด๋ณด์์ผ๋, ๊ฐ๋จํ ์น ์ดํ๋ฆฌ์ผ์ด์
์ ๋น๋ํ์ฌ hello world ๋ฅผ ์ฐ์ด๋ณด์.</p><ol><li>my_first_app๋ผ๋ ํด๋๋ฅผ ๋ง๋ค๊ณ ๊ทธ ์์ <a href="http://app.py/">app.py</a> ๋ผ๋ ํ์ด์ฌ ํ์ผ์ ๋ง๋ค์.</li></ol><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">mkdir</span> my_first_app</span><br><span class="line">$ <span class="built_in">cd</span> my_first_app</span><br><span class="line">$ <span class="built_in">touch</span> app.py</span><br></pre></td></tr></table></figure><ol><li>main<a href="http://app.py/">.py</a> ์์ ๋ค์๊ณผ ๊ฐ์ด ์์ฑํ์.</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># my_first_app/main.py</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> fastapi <span class="keyword">import</span> FastAPI</span><br><span class="line"><span class="keyword">from</span> typing <span class="keyword">import</span> <span class="type">Dict</span></span><br><span class="line"></span><br><span class="line">app = FastAPI() <span class="comment">#1</span></span><br><span class="line"></span><br><span class="line"><span class="meta">@app.get(<span class="params"><span class="string">"/"</span></span>) </span><span class="comment">#2</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">helloworld</span>() -> <span class="type">Dict</span>: <span class="comment">#3</span></span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Hello World"</span> <span class="comment">#4</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><p>#1 : <code>app</code>์ด๋ผ๋ ๋ณ์์ FastAPI() ์๋ฒ์ ์ธ์คํด์ค๋ฅผ ์์ฑํ๋ค</p><p>#2: ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ์ด <code>app</code>์ ๋ผ์ฐํ
์ ์ค์ ํด์ค๋ค. REST API์ โ/โ๊ฒฝ๋ก๋ก GET ์ก์
์ด ๋ค์ด์์ ๋, ์คํ๋๋ ํจ์๋ฅผ ๋ฐ์ ์ ์ํ๋ค.</p><p>#3: <code>helloworld()</code> ๋ผ๋ ํจ์๋ฅผ ์ ๋ผ์ฐํธ๊ฐ ์์ ๋ ์คํ๋๋ ํจ์๋ช
์ด๊ณ ๊ทธ ๋ด์ฉ์ #4์ dictionary ๋ฅผ ๋ฆฌํดํ๋ค.</p><ol><li>๊ฐ๋จํ๊ฒ ๋ง๋ ์ฐ๋ฆฌ์ ์ฒซ ์ดํ๋ฆฌ์ผ์ด์
์ ์คํํด๋ณด์.</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ cd my_first_app</span><br><span class="line">$ uvicorn main:app --port <span class="number">8080</span> --reload</span><br></pre></td></tr></table></figure><p>์ ์คํ ๋ช
๋ น์ด๋ฅผ ์ดํด๋ณด๋ฉด,</p><p><code>uvicorn</code> : ASGI ์น ์๋ฒ ์ดํ๋ฆฌ์ผ์ด์
์ผ๋ก ์คํํ๋ค.</p><p><code>main</code> : ์ฐ๋ฆฌ๊ฐ ์คํ์ํค๋ ค๊ณ ํ๋ ๋ชจ๋ ์ด๋ฆ</p><p><code>app</code> : main ๋ชจ๋ ์์ uvicorn ์ด ๋ฐ๋ผ๋ณด๋ ์ธ์คํด์ค ์ด๋ฆ</p><p><code>โport</code> : ํฌํธ๋ฅผ ์ง์ ํ๋ค. ์ฌ๊ธฐ์๋ 8080</p><p><code>โreload</code> : reload ์ต์
์ ์ฃผ๋ฉด ์ฐ๋ฆฌ๊ฐ ๊ฐ๋ฐํ๋ ํ๋ก์ ํธ๋ด์์ ์ฝ๋ ๋ณ๊ฒฝ์ด ์ด๋ฃจ์ด ์ก์ ๋ ๋ค์ ์๋ฒ๋ฅผ ๊ตฌ๋ํ์ฌ ๋ณ๊ฒฝ๋ ์ฝ๋๋ฅผ ์ ์ฉํ๋ค. ๊ฐ๋ฐํ๋ ๋จ๊ณ์์ ์ ์ฌ์ฉํ๋ฉด ํธํ๋ค.</p><p>์ด๋ ๊ฒ ์ฌ์ฉํ๊ฒ ๋๋ฉด ํฐ๋ฏธ๋์์๋ ๋ค์๊ณผ ๊ฐ์ด ๊ฒฐ๊ณผ๊ฐ ๋ฌ๋ค.</p><p><img src="/2023/04/23/20230423-fast-api-1/Untitled.png" alt="Untitled"></p><p>์น์๋ฒ๊ฐ ์ ๋ด๋์ง ํ์ธํ๊ธฐ ์ํด ์์ฃผ ์ฌ์ฉํ๋ ํฌ๋กฌ์ด๋ ์ฌํ๋ฆฌ์ ๊ฐ์ ๋ธ๋ผ์ฐ์ ์์ ์ฐ๋ฆฌ๊ฐ ๋ฐฉ๊ธ ๋ง๋ ์น์๋ฒ์ ์ ์ํด๋ณด์.</p><p>url : <code>http://localhost:8080/</code></p><p><img src="/2023/04/23/20230423-fast-api-1/Untitled_01.png" alt="Untitled"></p><p>ํน์ ํฐ๋ฏธ๋์์ <code>curl localhost:8080</code></p><p><img src="/2023/04/23/20230423-fast-api-1/Untitled_02.png" alt="Untitled"></p><p>์ ์์ ์ผ๋ก ์ฐ๋ฆฌ์ ์ฒซ ์ดํ๋ฆฌ์ผ์ด์
์ ๋์ฐ๋๋ฐ ์ฑ๊ณตํ๋ค๋ฉด, ๊ทธ ์์์ด ๋งค์ฐ ๋ณด๋์ฐฐ ๊ฒ์ด๋ค. ๋ด ์์ผ๋ก ๋์ด ์นํต์ ์๋ฒ๋ผ๋.. ์ฌ์ค ์ด๊ฒ API์ ์ ๋ถ์ด๋ค. </p><p>์ ๊ฐ๋จํ ์ดํ๋ฆฌ์ผ์ด์
์ ๋์ ์๋ฆฌ๋ฅผ ๋ค์ ์ดํด๋ณด๋ฉด,</p><p>(1) ์ฐ๋ฆฌ๊ฐ URL ๋ก ์ ์ํ๋ค. ์ ํํ๋ ํธ์คํธ ์ฃผ์. ์ฌ๊ธฐ์๋ localhost:8080</p><p>(2) ๊ทธ๋ฆฌ๊ณ ์ ์ํ๊ณ ์ ํ๋ ๊ฒฝ๋ก๋ฅผ ํ์ธํ๋ค. ์ฌ๊ธฐ์๋ โ/โ</p><p>(3) ์ด request๋ฅผ ๋ฐ์ ์ฐ๋ฆฌ์ ์ธ์คํด์ค๋ ๋ผ์ฐํ
์ ํตํด โ/โ์ ํด๋นํ๋ ํจ์๋ฅผ ์ฐพ๋๋ค.</p><p>(4) helloworld()ํจ์๋ฅผ ์คํํ๊ณ ๊ทธ ํจ์์์ ์ ์ํ ๊ฒฐ๊ณผ๊ฐ์ ๋ฆฌํดํ๋ค. ์ฌ๊ธฐ์๋ {โmessageโ: โhello worldโ}</p><p>์ ์์ ์ผ๋ก ์๋ต์ ํ๋ค๋ฉด, ๋ค์๊ณผ ๊ฐ์ด 200 ์ฌ์ธ์ ์ค๋ค. ๊ทธ ๊ฒฐ๊ณผ๋ ์ฐ๋ฆฌ์ ์ฝ์์์๋ ํ์ธํ ์ ์๋ค.</p><p><img src="/2023/04/23/20230423-fast-api-1/Untitled_03.png" alt="Untitled"></p><h2 id="2-๋ผ์ฐํ
"><a href="#2-๋ผ์ฐํ
" class="headerlink" title="2. ๋ผ์ฐํ
"></a>2. ๋ผ์ฐํ
</h2><p>์์ ์ดํด๋ณธ ๋ผ์ฐํธ ์ฒ๋ฆฌ ๋ฐฉ๋ฒ์ ์ค์ ๋ก๋ ์ ์ฌ์ฉํ์ง ๋ชปํ๋ค. ์์ ๊ฐ์ ๋ฐฉ์์ ๋ผ์ฐํ
์ค์ ๋จ์ผ ๊ฒฝ๋ก๋ง ์ฒ๋ฆฌํ๊ฒ ๋๊ธฐ ๋๋ฌธ์ด๋ค. ์ด๋ uvicorn์ด ํ๋์ ์ํธ๋ฆฌ ํฌ์ธํธ๋ง ์คํํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค. ์ฌ๋ฌ ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ฐ์์ ์ด๊ณ ๋ค์ค์ ๋ผ์ฐํธ ์ฒ๋ฆฌ๋ FastAPI์ APIRouterํด๋์ค๋ฅผ ์ฌ์ฉํ์ฌ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐ ํ ์ ์๋ค.</p><p>์ค์ตํด๋ณด์!</p><ol><li>my_first_app ์์ routers ๋ผ๋ ํด๋๋ฅผ ๋ง๋ค๊ณ <a href="http://test.py/">test.py</a> ํ์ด์ฌ ํ์ผ์ ๋ง๋ค์.</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ cd my_first_app</span><br><span class="line">$ mkdir routers</span><br><span class="line">$ touch routers/test.py</span><br></pre></td></tr></table></figure><ol><li>new_router<a href="http://test.py/">.py</a> ์ ๋ค์๊ณผ ๊ฐ์ ์ฝ๋๋ฅผ ์์ฑํ์.</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> fastapi <span class="keyword">import</span> APIRouter</span><br><span class="line"><span class="keyword">from</span> typing <span class="keyword">import</span> <span class="type">Dict</span></span><br><span class="line"></span><br><span class="line">router = APIRouter(</span><br><span class="line"> prefix=<span class="string">"/new"</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="meta">@router.get(<span class="params"><span class="string">"/test"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">helloworld_new</span>( ) -> <span class="type">Dict</span>:</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"new router Hello!"</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><ol><li><a href="http://main.py/">main.py</a> ์ ๋ค์์ ์ถ๊ฐํ์.</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># main.py ์ ์ถ๊ฐ</span></span><br><span class="line"><span class="keyword">from</span> routers.new_router <span class="keyword">import</span> router</span><br><span class="line"></span><br><span class="line">app.include_router(router)</span><br></pre></td></tr></table></figure><ul><li>์ต์ข
์ ์ผ๋ก main.py์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค.</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> fastapi <span class="keyword">import</span> FastAPI</span><br><span class="line"><span class="keyword">from</span> typing <span class="keyword">import</span> <span class="type">Dict</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> routers.new_router <span class="keyword">import</span> router</span><br><span class="line"></span><br><span class="line">app = FastAPI()</span><br><span class="line"></span><br><span class="line">app.include_router(router)</span><br><span class="line"></span><br><span class="line"><span class="meta">@app.get(<span class="params"><span class="string">"/"</span></span>)</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">def</span> <span class="title function_">helloworld</span>() -> <span class="type">Dict</span>:</span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="string">"message"</span>: <span class="string">"Hello World"</span></span><br><span class="line"> }</span><br></pre></td></tr></table></figure><ol><li>๊ธฐ๋ฅํ์ธ</li></ol><p><a href="http://localhost:8080/dms">localhost:8080/</a>new/test ๋ผ๋ ์ฃผ์๋ฅผ ์
๋ ฅํ๋ฉด ์ฐ๋ฆฌ๊ฐ ์๋ก ์์ฑํ new router hello ๋ฉ์์ง๋ฅผ ๋ณผ ์ ์๋ค.</p><p><img src="/2023/04/23/20230423-fast-api-1/Untitled_04.png" alt="Untitled"></p><p>์ฐ๋ฆฌ๊ฐ ์ถ๊ฐํ new_router.py ๋ฅผ ์ดํด๋ณด์.</p><p>(1) APIRouter ํด๋์ค ์์ prefix๋ ์ฌ๊ธฐ์ ์ค์ ํ๋ router๋ /new ๋ค์ ์ค๋ ๊ฒฝ๋ก๋ฅผ ์ค์ ํ๊ฒ ๋ค๋ ์๋ฏธ์ด๋ค. ์ด๋ถ๋ถ์ ๊ณต๋์ผ๋ก ๋๋ฉด, <a href="http://localhost:8080/">localhost:8080</a>/ ๋ฃจํธ์ ๋ฐ๋ก ์ถ๊ฐ๋๋ ๊ฒฝ๋ก๊ฐ ๋ ๊ฒ์ด๋ค.</p><p>(2) /new ์๋์ /test๋ผ๋ ๊ฒฝ๋ก๊ฐ ๋ค์ด์ค๋ฉด ์๋ ํจ์๋ฅผ ์คํํ๊ฒ ๋ค๋ ๋ป์ด๋ค. ์ฌ๊ธฐ์๋ โnew router Helloโ๋ฅผ ๋ฆฌํดํ๋ค.</p><h2 id="3-์ ๋ฆฌ"><a href="#3-์ ๋ฆฌ" class="headerlink" title="3. ์ ๋ฆฌ"></a>3. ์ ๋ฆฌ</h2><p>์ด๋ฒ ๊ธ์์๋ FastAPI ๋ฅผ ์ด์ฉํ์ฌ ๊ฐ๋จํ๊ฒ ์ฒซ ์ดํ๋ฆฌ์ผ์ด์
์ ๋ง๋ค์ด ๋ณด์๊ณ , ๊ฑฐ๊ธฐ๋ค ๋ํด ๋ค์ค ๋ผ์ฐํ
์ ์ฒ๋ฆฌํ๊ธฐ ์ํ APIRouterํด๋์ค๋ ์ดํด๋ณด์๋ค. ์ด๋ฒ ๊ธ์์ ๋ฏธ์ฒ ์ค๋ช
ํ์ง ๋ชปํ ๋ถ๋ถ์ ํ๋ฒ ๊ฐ์ธ์ ์ผ๋ก ์ฐพ์๋ณด๋ฉด ์ข๊ฒ ๋ค. ํค์๋๋ก๋ RestAPI, HTTP ๋ฉ์๋์ค GET, POST, PUT, DELETE, Router ๋ฑ์ ํค์๋๋ก ๊ฐ์ธ์ ์ธ ๊ณต๋ถ๋ฅผ ํ๋ฉด ์์ผ๋ก ์
๋ก๋ํ๋ FastAPI์๋ฆฌ์ฆ๋ฅผ ์ฝ์ผ๋ฉฐ ์ข๋ ๋ง์ ๋์์ด ๋ ๊ฒ์ด๋ผ๊ณ ๋ฏฟ๋๋ค.</p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/FastAPI/">FastAPI</category>
<category domain="https://emjayahn.github.io/tags/FastAPI/">FastAPI</category>
<category domain="https://emjayahn.github.io/tags/API/">API</category>
<category domain="https://emjayahn.github.io/tags/%EC%9B%B9%EC%84%9C%EB%B2%84/">์น์๋ฒ</category>
<comments>https://emjayahn.github.io/2023/04/23/20230423-fast-api-1/#disqus_thread</comments>
</item>
<item>
<title>[Linux] screen์ ์ฌ์ฉํด๋ณด์</title>
<link>https://emjayahn.github.io/2023/04/09/20230409-screen-basic/</link>
<guid>https://emjayahn.github.io/2023/04/09/20230409-screen-basic/</guid>
<pubDate>Sun, 09 Apr 2023 08:58:57 GMT</pubDate>
<description><p>์ฐ๋ฆฌ๊ฐ ์๋ฒ์์ ์๊ฐ์ด ๋ง์ด ๋๋ ์์
์ ํ๋ค๊ณ ์๊ฐํด๋ณด์. ํ์๋ ๋ชจ๋ธ์ ํ์ต์ํจ๋ค๊ฑฐ๋ ํน์ ์ดํ๋ฆฌ์ผ์ด์
์ ๋น๋ํ ๋๋ฅผ ์๋ก ๋ค ์ ์๊ฒ ๋ค. (ํนํ ์ต๊ทผ์๋ gcc๋ฅผ ๋น๋ ํ ๋..) ํด๋น ์์
์ ํ๋ฉด์ ์ฝ์์ ์ฐํ๋ ์์ํ ๋ชจ๋ํฐ๋ง ๋ฑ๋ ํจ๊ป ํ์ํ๋ฉด ํนํ๋ ์๋ฒ์ ๋ถ์ ์ฐ๊ฒฐ์ ์ ์งํด์ผํ ํ์๊ฐ ์๋ค. ์ค๋์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ linux์ screen์ ์์๋ณด๊ณ ์ด ๊ธฐ๋ฅ ์ธ์๋ ๋ค์ํ๊ฒ ํ์ฉํ ์ ์๋ ์์ฉ ์์ ๋ค๋ ์ดํด๋ณด์.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>์ฐ๋ฆฌ๊ฐ ์๋ฒ์์ ์๊ฐ์ด ๋ง์ด ๋๋ ์์
์ ํ๋ค๊ณ ์๊ฐํด๋ณด์. ํ์๋ ๋ชจ๋ธ์ ํ์ต์ํจ๋ค๊ฑฐ๋ ํน์ ์ดํ๋ฆฌ์ผ์ด์
์ ๋น๋ํ ๋๋ฅผ ์๋ก ๋ค ์ ์๊ฒ ๋ค. (ํนํ ์ต๊ทผ์๋ gcc๋ฅผ ๋น๋ ํ ๋..) ํด๋น ์์
์ ํ๋ฉด์ ์ฝ์์ ์ฐํ๋ ์์ํ ๋ชจ๋ํฐ๋ง ๋ฑ๋ ํจ๊ป ํ์ํ๋ฉด ํนํ๋ ์๋ฒ์ ๋ถ์ ์ฐ๊ฒฐ์ ์ ์งํด์ผํ ํ์๊ฐ ์๋ค. ์ค๋์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ linux์ screen์ ์์๋ณด๊ณ ์ด ๊ธฐ๋ฅ ์ธ์๋ ๋ค์ํ๊ฒ ํ์ฉํ ์ ์๋ ์์ฉ ์์ ๋ค๋ ์ดํด๋ณด์.</p><span id="more"></span><h2 id="1-Screen์-๊ฐ๋
"><a href="#1-Screen์-๊ฐ๋
" class="headerlink" title="1. Screen์ ๊ฐ๋
"></a>1. Screen์ ๊ฐ๋
</h2><p>screen์ ํ์ฌ ์ ์ํด ์๋ ์ธ์
๊ณผ ์๊ด ์์ด ๊ฐ์์ ํฐ๋ฏธ๋์ ๋์์ฃผ๋ ๋ฆฌ๋
์ค ์ดํ๋ฆฌ์ผ์ด์
์ด๋ค. ํฐ๋ฏธ๋ ๋ฉํฐํ๋ ์๋ผ๊ณ ๋ ํ๋ค. ๊ฐ์์ ํฐ๋ฏธ๋์ ๋์์ฃผ๋ ๊ธฐ๋ฅ ๋๋ถ์ ์ฐ๋ฆฌ๊ฐ ssh ๋ก ๋ถ์ด ์๋ ์ธ์
์ด time-out ๋ฑ์ผ๋ก ์ข
๋ฃ๋๋๋ผ๋ ์ด๋ฏธ ๋์์ง screen ์ ์ธ์
์ ์ด์์๊ฒ ๋๋ค. ๋ฐ๋ผ์ ์์ ๋ด๊ฐ ๊ฒช์ ์์ฒ๋ผ ๋ชจ๋ธ ํ์ต์ด๋ ์ดํ๋ฆฌ์ผ์ด์
๋น๋๋ฅผ ์งํํ๋ ๋์ค ์ธ์
์ด ๋๊ธฐ๋๋ผ๋ ๊ทธ screen ์์์ ๋์ํ๋ ์์
๋ค์ ๊ณ์ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ๋์ํ๊ฒ ๋๋ค.</p><h2 id="2-Screen-์ค์น"><a href="#2-Screen-์ค์น" class="headerlink" title="2. Screen ์ค์น"></a>2. Screen ์ค์น</h2><p>screen์ ๋๋ถ๋ถ์ linux์์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ค์น๋์ด ์์ผ๋, ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ๊ทธ ๋ฒ์ ์ ํ์ธํด๋ณด๊ณ ์๋ค๋ฉด ์ค์นํด์ฃผ๋ฉด ๋๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ screen --version</span><br></pre></td></tr></table></figure><ul><li>Ubuntu ๊ณ์ด</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ (sudo) apt update</span><br><span class="line">$ (sudo) apt install screen</span><br></pre></td></tr></table></figure><ul><li>Fedora ๊ณ์ด ๋ฐ CentOS</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ (sudo) yum install screen</span><br></pre></td></tr></table></figure><h2 id="3-๊ฐ๋จ-Screen-์์"><a href="#3-๊ฐ๋จ-Screen-์์" class="headerlink" title="3. ๊ฐ๋จ Screen ์์"></a>3. ๊ฐ๋จ Screen ์์</h2><p>์ ๊ณผ์ ์ผ๋ก screen์ด ์ค๋น ๋์๋ค๋ฉด, ๊ฐ๋จํ๊ฒ screen์ ์ฌ์ฉํด ๋ณผ ์ ์๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ screen</span><br></pre></td></tr></table></figure><p><img src="/2023/04/09/20230409-screen-basic/Untitled.png" alt="Untitled"></p><p>screen์ ์
๋ ฅํด ์คํํ๋๋ผ๋, ํฐ๋ฏธ๋ ์์์ ๊ทธ ์ ๊ณผ ๋ค๋ฅด์ง ์๋ค๋ ๊ฒ์ ํ์ธ ํ ์ ์๋ค. ํ์ง๋ง <code>exit</code>์ผ๋ก screen์ ์ข
๋ฃํ๋ฉด ๋ค์๊ณผ ๊ฐ์ ๋ฌธ๊ตฌ๋ฅผ ํ์ธ ํ ์ ์๋ค.</p><p><img src="/2023/04/09/20230409-screen-basic/Untitled_01.png" alt="Untitled"></p><p>์ด๋ ๊ฒ ์ฐ๋ฆฌ๊ฐ ์ง๊ธ screen์ ์ฌ์ฉํ๋์ง ์ํ๋์ง, ์ด๋ค ์ฐฝ์ ์ฌ์ฉํ๊ณ ์๋์ง ๋ฑ์ ์ก์์ผ๋ก๋ ์ฝ๊ฒ ํ์ธ ํ ์ ์๊ธฐ ๋๋ฌธ์ screenrc ํ์ผ์ ์์ ํ์ฌ ์์๊ฒ(?) ์ฌ์ฉํ๋ค. ํฐ๋ฏธ๋๋ ์๋ป์ผ ์ผํ ๋ง์ด ๋๋ ๋จผ์ screenrc ๋ถํฐ ์์ ํด๋ณด์.</p><h2 id="4-screen์-์์ ์์ฌ๋ก-ํ์ฉํด๋ณด๊ธฐ"><a href="#4-screen์-์์ ์์ฌ๋ก-ํ์ฉํด๋ณด๊ธฐ" class="headerlink" title="4. screen์ ์์ ์์ฌ๋ก ํ์ฉํด๋ณด๊ธฐ"></a>4. screen์ ์์ ์์ฌ๋ก ํ์ฉํด๋ณด๊ธฐ</h2><p>screen์ ๋ค์ํ ์ต์
์ ์์๋ณด์. ์๊ธฐํ๋ฏ์ด ๋์ดํ๋ ๊ฒ๋ณด๋ค๋ ํ์๊ฐ ์ต๊ด์ฒ๋ผ ์์ฃผ ์ฌ์ฉํ๋ ๋ช
๋ น์ด ์์ผ๋ก ๋์ดํด๋ณด๊ฒ ๋ค.</p><h3 id="4-1-screen-S"><a href="#4-1-screen-S" class="headerlink" title="4-1. screen -S"></a>4-1. screen -S</h3><p>์์ screen๋ง ์
๋ ฅํ๊ฒ ๋๋ฉด, default ์ด๋ฆ์ด ๋ค์ด๊ฐ๊ฒ ๋๋ค. -S ์ต์
์ ์ฃผ๊ฒ ๋๋ฉด session ๋ง๋ค </p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ screen -S session_name</span><br></pre></td></tr></table></figure><h3 id="4-2-screen-ls"><a href="#4-2-screen-ls" class="headerlink" title="4-2. screen -ls"></a>4-2. screen -ls</h3><p>์์ฑํ ์ธ์
์ ๋ฆฌ์คํธ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ screen -<span class="built_in">ls</span></span><br></pre></td></tr></table></figure><p><img src="/2023/04/09/20230409-screen-basic/Untitled_02.png" alt="Untitled"></p><h3 id="4-3-์ธ์
-๋ค์-์ ์"><a href="#4-3-์ธ์
-๋ค์-์ ์" class="headerlink" title="4-3. ์ธ์
๋ค์ ์ ์"></a>4-3. ์ธ์
๋ค์ ์ ์</h3><p>์์ฑํ๋ ์ธ์
์ ๋ค์ ์ ์ํ๊ธฐ ์ํ ๋ช
๋ น์ด์ด๋ค. ๋์ผํ ์ด๋ฆ์ ์ธ์
์ด๋ฆ์ด ๋๊ฐ ์ด์์๋ค๋ฉด, ์์ ๋์์๋ ์ธ์
ID๊น์ง ๊ฐ์ด ์
๋ ฅํด์ฃผ์ด์ผ ํ๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ screen -r session_id_or_session_name</span><br><span class="line">$ screen -x session_id_or_session_name</span><br></pre></td></tr></table></figure><ul><li><p>screen -r ๊ณผ screen -x์ ์ฐจ์ด</p><ul><li><code>screen -r</code>: Single display mode</li><li><code>screen -x</code>: Multi display mode โ ๊ฐ์ ์คํฌ๋ฆฐ ์ธ์
์ ์ฌ๋ฌ๋ช
์ด ๋ค์ด๊ฐ์ ๋ ๋ชจ๋ ๋ช
๋ น์ด์ ํ๋์ด ํจ๊ป ๋ณด์</li><li>์๋ ์์์ฒ๋ผ ์๋ก ๋ค๋ฅธ ํฐ๋ฏธ๋์ ํ๊ณ , ๊ฐ์ ์คํฌ๋ฆฐ์ -x ์ต์
์ ์ฃผ์ด ์ ์ํ๋ฉด ํ์ชฝ์์ ์น๋ ๋ช
๋ น์ด์ ํ๋์ด ๋์ผํ๊ฒ ๋ณด์ธ๋ค</li></ul><p> <img src="/2023/04/09/20230409-screen-basic/Untitled_03.png" alt="Untitled"></p></li></ul><h3 id="4-4-์ธ์
-๋ด-์๋์ฐ-์์ฑ"><a href="#4-4-์ธ์
-๋ด-์๋์ฐ-์์ฑ" class="headerlink" title="4-4. ์ธ์
๋ด ์๋์ฐ ์์ฑ"></a>4-4. ์ธ์
๋ด ์๋์ฐ ์์ฑ</h3><p>์ธ์
๋ด์์ ์๋์ฐ๋ฅผ ์์ฑํ๋ ๊ฒ์ ์คํฌ๋ฆฐ์ ์ฃผ์ ๊ธฐ๋ฅ์ด๋ผ ํ ์ ์๋ค. ํ ์ธ์
๋ด์์ ์ฌ๋ฌ ์๋์ฐ๋ฅผ ์คํํ๊ณ ๊ฐ๊ฐ ๋ค๋ฅธ ์์
์ ์ํํ ์ ์๋ค. </p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ ctrl + a, c </span><br><span class="line"><span class="comment"># (create๋ผ ๊ธฐ์ต)</span></span><br></pre></td></tr></table></figure><h3 id="4-5-์ธ์
-detached"><a href="#4-5-์ธ์
-detached" class="headerlink" title="4-5. ์ธ์
detached"></a>4-5. ์ธ์
detached</h3><p>๋ค์์์ ๋์ค๋ ์ธ์
์ข
๋ฃ์๋ ๋ค๋ฅด๋ค. ํ์ฌ ์ฐ๊ฒฐ ๋์ด์๋ screen ๊ณผ์ ์ฐ๊ฒฐ๋ง ๋๋ ๊ฒ์ด๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ ctrl + a, d</span><br><span class="line"><span class="comment"># (detach๋ผ ๊ธฐ์ต)</span></span><br></pre></td></tr></table></figure><h3 id="4-6-์ธ์
-๋ด-์๋์ฐ-์ข
๋ฃ-amp-์ธ์
-์ข
๋ฃ"><a href="#4-6-์ธ์
-๋ด-์๋์ฐ-์ข
๋ฃ-amp-์ธ์
-์ข
๋ฃ" class="headerlink" title="4-6. ์ธ์
๋ด ์๋์ฐ ์ข
๋ฃ & ์ธ์
์ข
๋ฃ"></a>4-6. ์ธ์
๋ด ์๋์ฐ ์ข
๋ฃ & ์ธ์
์ข
๋ฃ</h3><p>์ธ์
์ ๋ด ๋ชจ๋ ์๋์ฐ๊ฐ ์ข
๋ฃ๋๋ฉด screen์ผ๋ก ์คํํ ์ธ์
๋ ์ข
๋ฃ๋๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">exit</span></span><br></pre></td></tr></table></figure><p>๋ค์ ๋ช
๋ น์ด๋ screen์ ์ข
๋ฃํ๋ฉด์ ๋น ์ ธ๋๊ฐ๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ ctrl + a, k </span><br></pre></td></tr></table></figure><h3 id="4-7-์ธ์
-๋ด-์๋์ฐ-๋ชฉ๋ก-๋ณด๊ธฐ"><a href="#4-7-์ธ์
-๋ด-์๋์ฐ-๋ชฉ๋ก-๋ณด๊ธฐ" class="headerlink" title="4-7. ์ธ์
๋ด ์๋์ฐ ๋ชฉ๋ก ๋ณด๊ธฐ"></a>4-7. ์ธ์
๋ด ์๋์ฐ ๋ชฉ๋ก ๋ณด๊ธฐ</h3><p>ํ ์ธ์
๋ด์์ ์ฌ๋ฌ ์๋์ฐ๊ฐ ์๋ ๊ฒฝ์ฐ ์๋์ฐ์ ๋ฆฌ์คํธ๋ฅผ ๋ณผ ์ ์๋ ๋ฐฉ๋ฒ์ด๋ค. ์๋ ๋ช
๋ น์ด๋ฅผ ์
๋ ฅํ๋ฉด ์๋์ฐ ๋ชฉ๋ก์ด ์ ์ ๋ํ๋ฌ๋ค๊ฐ ์ฌ๋ผ์ง๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ ctrl + a, w</span><br><span class="line"><span class="comment"># (์คํ๋๊ณ ์๋ window๋ผ ๊ธฐ์ต)</span></span><br><span class="line"></span><br><span class="line">$ ctrl + a, <span class="string">"</span></span><br></pre></td></tr></table></figure><p><img src="/2023/04/09/20230409-screen-basic/Untitled_04.png" alt="ctrl + a, w ํฐ๋ฏธ๋ ํ๋จ์ ๋ํ๋๋ ๊ฒฐ๊ณผ"></p><p>ctrl + a, w ํฐ๋ฏธ๋ ํ๋จ์ ๋ํ๋๋ ๊ฒฐ๊ณผ</p><p><img src="/2023/04/09/20230409-screen-basic/Untitled_05.png" alt="ctrl + a, โ ์๋์ฐ ๋ชฉ๋ก์ด ๋ณด์ด๊ณ , ๋ฐฉํฅํค๋ก ํด๋น ์๋์ฐ ์ ํ ๊ฐ๋ฅ"></p><p>ctrl + a, โ ์๋์ฐ ๋ชฉ๋ก์ด ๋ณด์ด๊ณ , ๋ฐฉํฅํค๋ก ํด๋น ์๋์ฐ ์ ํ ๊ฐ๋ฅ</p><h3 id="4-8-์ธ์
-๋ด-์๋์ฐ-์ด๋ํ๊ธฐ"><a href="#4-8-์ธ์
-๋ด-์๋์ฐ-์ด๋ํ๊ธฐ" class="headerlink" title="4-8. ์ธ์
๋ด ์๋์ฐ ์ด๋ํ๊ธฐ"></a>4-8. ์ธ์
๋ด ์๋์ฐ ์ด๋ํ๊ธฐ</h3><p>์ธ์
์์ ์๋์ฐ ๊ฐ์ ์ด๋์ ์๋์ฐ์ ๋ฒํธ๋ฅผ ๋๋ฅด๋ฉด ๋๋ค. ํน์ ์ด์ ์ฐฝ์ ๊ฒฝ์ฐ ๋ค์ ๋ช
๋ น์ด ์ ๊ฐ๋ค</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ ctrl + a, 0 <span class="comment"># 0๋ฒ์งธ ์๋์ฐ</span></span><br><span class="line">$ ctrl + a, 1 <span class="comment"># 1๋ฒ์งธ ์๋์ฐ</span></span><br><span class="line">$ ctrl + a, 2 <span class="comment"># 2๋ฒ์งธ ์๋์ฐ</span></span><br><span class="line"></span><br><span class="line">$ ctrl + a, a <span class="comment"># ์ด์ ์ฌ์ฉํ ์๋์ฐ</span></span><br></pre></td></tr></table></figure><h3 id="4-9-์๋์ฐ-ํ๋ฉด-๋ถํ "><a href="#4-9-์๋์ฐ-ํ๋ฉด-๋ถํ " class="headerlink" title="4-9. ์๋์ฐ ํ๋ฉด ๋ถํ "></a>4-9. ์๋์ฐ ํ๋ฉด ๋ถํ </h3><ul><li>๊ฐ๋ก ํ๋ฉด ๋ถํ </li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ ctrl + a, <span class="built_in">shift</span> + s</span><br></pre></td></tr></table></figure><ul><li>์ธ๋ก ํ๋ฉด ๋ถํ </li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ ctrl + a, <span class="built_in">shift</span> + \</span><br></pre></td></tr></table></figure><ul><li>๋ถํ ์๋์ฐ๊ฐ ์ด๋</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ ctrl + a, tab</span><br></pre></td></tr></table></figure><h2 id="5-๋ง๋ฌด๋ฆฌ"><a href="#5-๋ง๋ฌด๋ฆฌ" class="headerlink" title="5. ๋ง๋ฌด๋ฆฌ"></a>5. ๋ง๋ฌด๋ฆฌ</h2><p>์ด๋ฒ ๊ธ์ ํตํด screen ์ ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ ๋ํด ์์๋ณด์๋ค. ๋น๋๊ฐ ์ค๋๊ฑธ๋ฆฌ๋ ์ฌ๋ฌ๊ฐ์ง ์์
๋ค์ ๋์์ด ๋ ๊ฒ์ด๋ฉฐ, ๊ผญ ์ค๋๊ฑธ๋ฆฌ๋ ์์
์ด์ธ์๋ ํ ํ๋ฉด์ ๋ค์ํ ํ๋ฉด ๋ถํ ๊ธฐ๋ฅ์ผ๋ก ์์ฐ์ฑ์ด ์ฌ๋ผ๊ฐ ์ ์์ ๊ฒ์ด๋ค. ์ฌ์ฉ์์ ์
๋ง ๋๋ก <code>.screenrc</code>๋ฅผ ์์ฑํ์ฌ screen ์ ๊พธ๋ฉฐ ๋ณผ ์๋ ์๋ค. ํ ๋ฒ ์ฌ์ฉํด๋ณด์ธ์ ๐</p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/Linux/">Linux</category>
<category domain="https://emjayahn.github.io/tags/linux/">linux</category>
<category domain="https://emjayahn.github.io/tags/screen/">screen</category>
<category domain="https://emjayahn.github.io/tags/multiplexer/">multiplexer</category>
<category domain="https://emjayahn.github.io/tags/%EB%A9%80%ED%8B%B0%ED%94%8C%EB%A0%89%EC%84%9C/">๋ฉํฐํ๋ ์</category>
<category domain="https://emjayahn.github.io/tags/%EC%8A%A4%ED%81%AC%EB%A6%B0/">์คํฌ๋ฆฐ</category>
<comments>https://emjayahn.github.io/2023/04/09/20230409-screen-basic/#disqus_thread</comments>
</item>
<item>
<title>[Kubernetes] ์ฟ ๋ฒ๋คํฐ์ค ์
๋ฌธ</title>
<link>https://emjayahn.github.io/2023/03/26/20230326-basic-kubernetes/</link>
<guid>https://emjayahn.github.io/2023/03/26/20230326-basic-kubernetes/</guid>
<pubDate>Sun, 26 Mar 2023 11:51:26 GMT</pubDate>
<description><p>๋จธ์ ๋ฌ๋ ์๋น์ค๋ฅผ ๊ฐ๋ฐ, ๋ฐฐํฌ, ์ด์์ ์์ํ๋ฉด์ ๋์ปค์ ๋ํ ์ดํด์ ํ์์ฑ์ ๋๋ผ๋ฉฐ ๋์
์ ์ํด ๊ณต๋ถ๋ฅผ ์์ํ๋ค. ๋์ปค๋ฅผ ๊ณต๋ถํ๋ ๋์ ์ด์ ๋ ์ฟ ๋ฒ๋คํฐ์ค๋ฅผ ์์ํด๋ณด๋ ค๊ณ ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ฌํด ๋ง์๋ CKAD ๋ ๋์ ํด๋ณด๋ ค๊ณ ํ๋ค. Kubernetes๊ธ ์๋ฆฌ์ฆ์์๋ Kubernetes๋ฅผ ์ฒ์ ์์ํ๊ณ ๊ณต๋ถํ ๋ด์ฉ๋ค์ ์ ๋ฆฌํด๋ณด๋ฉฐ, ์ํ ์ค๋น๊ธฐ๊น์ง ์ ๋ฆฌํด๋ณด๋ ค๊ณ ํ๋ค. ์ํ์ ์ค์ ๋ก ๋์ ํ๊ธฐ์ ํ์ตํ๊ณ ์ค์ตํ ๋ด์ฉ๋ค์ ์ ๋ฆฌํ๋ ๊ธ์ด๋ค๋ณด๋ ๊ทธ ๋์ ์ํ์ ํฉ๊ฒฉํ ์ง๊น์ง ๊ด์ฌ์๊ฒ ์ง์ผ๋ด์ฃผ๋ฉด ์ข๊ฒ ๋ค. ์ํ ํฉ๊ฒฉ ์ฌ๋ถ์ ์๊ด์์ด, ์ด ๋
ธ๋ ฅ๊ณผ ๊ธ, ์ง์์ ๋ด ์์ ์์ผํ
๋ ๊ผผ๊ผผํ ๊ณต๋ถํด๋ณด๋ ค๊ณ ํ๋ค.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>๋จธ์ ๋ฌ๋ ์๋น์ค๋ฅผ ๊ฐ๋ฐ, ๋ฐฐํฌ, ์ด์์ ์์ํ๋ฉด์ ๋์ปค์ ๋ํ ์ดํด์ ํ์์ฑ์ ๋๋ผ๋ฉฐ ๋์
์ ์ํด ๊ณต๋ถ๋ฅผ ์์ํ๋ค. ๋์ปค๋ฅผ ๊ณต๋ถํ๋ ๋์ ์ด์ ๋ ์ฟ ๋ฒ๋คํฐ์ค๋ฅผ ์์ํด๋ณด๋ ค๊ณ ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ฌํด ๋ง์๋ CKAD ๋ ๋์ ํด๋ณด๋ ค๊ณ ํ๋ค. Kubernetes๊ธ ์๋ฆฌ์ฆ์์๋ Kubernetes๋ฅผ ์ฒ์ ์์ํ๊ณ ๊ณต๋ถํ ๋ด์ฉ๋ค์ ์ ๋ฆฌํด๋ณด๋ฉฐ, ์ํ ์ค๋น๊ธฐ๊น์ง ์ ๋ฆฌํด๋ณด๋ ค๊ณ ํ๋ค. ์ํ์ ์ค์ ๋ก ๋์ ํ๊ธฐ์ ํ์ตํ๊ณ ์ค์ตํ ๋ด์ฉ๋ค์ ์ ๋ฆฌํ๋ ๊ธ์ด๋ค๋ณด๋ ๊ทธ ๋์ ์ํ์ ํฉ๊ฒฉํ ์ง๊น์ง ๊ด์ฌ์๊ฒ ์ง์ผ๋ด์ฃผ๋ฉด ์ข๊ฒ ๋ค. ์ํ ํฉ๊ฒฉ ์ฌ๋ถ์ ์๊ด์์ด, ์ด ๋
ธ๋ ฅ๊ณผ ๊ธ, ์ง์์ ๋ด ์์ ์์ผํ
๋ ๊ผผ๊ผผํ ๊ณต๋ถํด๋ณด๋ ค๊ณ ํ๋ค.</p><span id="more"></span><h2 id="1-์ฟ ๋ฒ๋คํฐ์ค๋"><a href="#1-์ฟ ๋ฒ๋คํฐ์ค๋" class="headerlink" title="1. ์ฟ ๋ฒ๋คํฐ์ค๋?"></a>1. ์ฟ ๋ฒ๋คํฐ์ค๋?</h2><p>์ฟ ๋ฒ๋คํฐ์ค๋ ๋์ปค์ ๊ฐ์ ์ปจํ
์ด๋๋ฅผ ์์ฝ๊ฒ ๊ด๋ฆฌํ๋ ํ๋ซํผ์ด๋ค. ๋์ปค ์ปจํ
์ด๋๋ฅผ ์๋น์ค ํธ๋ํฝ์ ์๊ณผ ์ปจํ
์ด๋์ ์์ ๋ฐ๋ผ ๋ฐฐํฌํ๊ณ ํ์ฅํด์ผํ๋ ์ด์๊ฐ ์๊ธฐ๊ธฐ ๋ง๋ จ์ด๋ค. ์ด ๋ค์์ ์ปจํ
์ด๋๋ฅผ ๊ด๋ฆฌํ๊ณ ์ด๋ฅผ ์๋ํํ๋ ํ๋ซํผ์ด๋ค. ์์ด๋ณด์ด๋ ํํ์ผ๋ก๋ ์ปจํ
์ด๋ ์ค์ผ์คํธ๋ ์ด์
ํด์ด๋ผ๊ณ ์ ๋ฆฌํ ์ ์๊ฒ ๋ค.</p><p><img src="/2023/03/26/20230326-basic-kubernetes/Untitled_01.png" alt="Kubernetes"></p><h2 id="2-์ฟ ๋ฒ๋คํฐ์ค์-๊ตฌ์ฑ-์์"><a href="#2-์ฟ ๋ฒ๋คํฐ์ค์-๊ตฌ์ฑ-์์" class="headerlink" title="2. ์ฟ ๋ฒ๋คํฐ์ค์ ๊ตฌ์ฑ ์์"></a>2. ์ฟ ๋ฒ๋คํฐ์ค์ ๊ตฌ์ฑ ์์</h2><p>์ฟ ๋ฒ๋คํฐ์ค์ ๊ตฌ์ฑ์์๋ฅผ ์ ๋ฆฌํ๋ฉฐ, ๊ฐ ์์๋ค์ ๊ธฐ๋ฅ ๋ฐ ์ฉ์ด๋ฅผ ์ ๋ฆฌํด๋ณด์.</p><h3 id="2-1-ํ๋-Pod"><a href="#2-1-ํ๋-Pod" class="headerlink" title="2-1. ํ๋ : Pod"></a>2-1. ํ๋ : Pod</h3><p>ํ๋๋ ์ฟ ๋ฒ๋คํฐ์ค ๋ด์์ ์์ฑ๋๊ณ ๊ด๋ฆฌ๋๋ ๋ฐฐํฌ ๊ฐ๋ฅํ ๊ฐ์ฅ ์์ ์ปดํจํ
๋จ์์ด๋ค. ์ดํ๋ฆฌ์ผ์ด์
์ ๋จ์ผ ์ธ์คํด์ค๋ผ๊ณ ์ดํดํ ์ ์๋ค. ์ฆ, ํ๋๋ ํ๋ ์ด์์ ์ปจํ
์ด๋ ๊ทธ๋ฃน์ด๋ค. ํ๋ ๋ด์์๋ ๋ฉ๋ชจ๋ฆฌ, ๋คํธ์ํฌ๋ฅผ ๊ณต์ ํ๊ณ ํจ๊ป ์ค์ผ์ฅด๋ง๋๋ค.</p><h3 id="2-2-๋
ธ๋-Node"><a href="#2-2-๋
ธ๋-Node" class="headerlink" title="2-2. ๋
ธ๋ : Node"></a>2-2. ๋
ธ๋ : Node</h3><p>๋
ธ๋๋ ํด๋ฌ์คํฐ์ ๊ฐ์ ํน์ ๋ฌผ๋ฆฌ ๋จธ์ ์ ์๋ฏธํ๋ค. ๊ฐ ๋
ธ๋๋ ์๋์ ์ค๋ช
ํ ์ปจํธ๋กค ํ๋ ์ธ์ ์ํด ๊ด๋ฆฌ๋๊ณ , ํ๋๋ฅผ ์คํํ๋๋ฐ ํ์ํ ์๋น์ค๋ฅผ ํฌํจํ๋ค. ํด๋ฌ์คํฐ ๋ด์๋ ๋ค์์ ๋
ธ๋๊ฐ ์์ ์ ์๋ค. ๋ชจ๋ ํด๋ฌ์คํฐ๋ ์ต์ ํ ๊ฐ ์ด์์ ์์ปค ๋
ธ๋๋ฅผ ๊ฐ๊ฒ ๋๋ค. ์ดํ ์์ปค ๋
ธ๋๋ ๊ฐ ์ดํ๋ฆฌ์ผ์ด์
์ ๊ตฌ์ฑ์์์ธ ํ๋๋ฅผ ํธ์คํ
ํ๋ค. </p><h3 id="2-3-์ปจํ
์ด๋-๋ฐํ์-์์ง"><a href="#2-3-์ปจํ
์ด๋-๋ฐํ์-์์ง" class="headerlink" title="2-3. ์ปจํ
์ด๋ ๋ฐํ์ ์์ง"></a>2-3. ์ปจํ
์ด๋ ๋ฐํ์ ์์ง</h3><p><img src="/2023/03/26/20230326-basic-kubernetes/Untitled.png" alt="Docker"></p><p>์ปจํ
์ด๋๋ฅผ ๊ตฌ์ฑํ๊ณ ์คํํ๊ธฐ ์ํด ๊ฐ ๋
ธ๋ ์์๋ ์ปจํ
์ด๋ ๋ฐํ์ ์์ง์ด ์กด์ฌํ๋ค. ์ด ์ปจํ
์ด๋ ๋ฐํ์ ์์ง ๊ฐ๋
์ ํฌํจ๋๋ ํ๊ฐ์ง ์๊ฐ ๋ฐ๋ก ๋์ปค์ด๋ค. ์ฟ ๋ฒ๋คํฐ์ค๋ ๋์ปค๋ฟ๋ง์๋๋ผ rkt ์ ๊ฐ์ ์ปจํ
์ด๋์๋ ํธํ์ด ๊ฐ๋ฅํ๋ค. </p><h3 id="2-4-์ปจํธ๋กค-ํ๋ ์ธ-Control-Plane"><a href="#2-4-์ปจํธ๋กค-ํ๋ ์ธ-Control-Plane" class="headerlink" title="2-4. ์ปจํธ๋กค ํ๋ ์ธ : Control Plane"></a>2-4. ์ปจํธ๋กค ํ๋ ์ธ : Control Plane</h3><p>์ปจํธ๋กค ํ๋ ์ธ์ด๋ ์ปจํ
์ด๋์ ์ ์ฒด ๋ผ์ดํ ์ฌ์ดํด์ ์ ์ํ๊ณ , ๋ฐฐํฌํ๋ฉฐ, ๊ด๋ฆฌํ๊ธฐ ์ํ API ์ด๋ค. ์ปจํธ๋กค ํ๋ ์ธ์ ์์ปค ๋
ธ๋์ ํด๋ฌ์คํฐ ๋ด ํ๋๋ฅผ ๊ด๋ฆฌํ๊ฒ ๋๋ค. ์ปจํธ๋กค ํ๋ ์ธ์ ์์ ๋งํ ๋
ธ๋์ ํญ์ ์ฐ๊ฒฐ๋์ด ์์ด, ๋
ธ๋๊ฐ ์ ์ํ ์คํํ๊ฒฝ์ ๋ฐ๋ผ ์๋ก ํต์ ํ๊ฒ ๋๋ค.</p><p><img src="/2023/03/26/20230326-basic-kubernetes/Untitled_02.png" alt="Control Plane"><br>Control Plane - ์ถ์ฒ : <a href="https://www.redhat.com/ko/topics/containers/kubernetes-architecture">https://www.redhat.com/ko/topics/containers/kubernetes-architecture</a></p><h3 id="2-5-etcd"><a href="#2-5-etcd" class="headerlink" title="2-5. etcd"></a>2-5. etcd</h3><p>ํด๋ฌ์คํฐ ์ค์ ๋ฐ์ดํฐ์ ํด๋ฌ์คํฐ์ ์ํ๋ฅผ ์ ์ฅํ๋ key-value ๋ฐ์ดํฐ๋ฒ ์ด์ค์ด๋ค. ํด๋ฌ์คํฐ ๋ด์ ์ด๋ค ๋
ธ๋๊ฐ ๋ช ๊ฐ ์กด์ฌํ๋ฉฐ, ์ด๋ค ํ๋๊ฐ ๋์ํ๊ณ ์๋์ง์ ๊ดํ ์ ๋ณด๊ฐ etcd ์ ๊ธฐ๋ก๋๋ค. ์ด etcd์ ๋ํ ๋ฐฑ์
๊ณํ์ด ํ์์ผ ๊ฒ์ด๋ค. ์ด etcd ๋ฐ์ดํฐ ์ ์ค์ด ์ผ์ด๋๋ฉด ํด๋ฌ์คํฐ๊ฐ ์ฌ์ฉํ๋ ๋ฆฌ์์ค ์ ๋ณด๋ฅผ ๋ชจ๋ ์์ด๋ฒ๋ฆฌ๊ธฐ ๋๋ฌธ์ด๋ค.</p><p>์ด ์ธ์๋ kude-scheduler, kube-controller-manager, cloud-controller-manager, kube-proxy, kubelet ๋ฑ ์ฟ ๋ฒ๋คํฐ์ค์ ๊ธฐ๋ฅ๊ณผ ๊ด๋ จ๋ ๊ฐ๋
๊ณผ ์ฉ์ด๋๋ฆฌ ๋ง์ด ๋ฑ์ฅํ๋ค. ์ 5๊ฐ์ ๊ด๋ จ๋ ์ฉ์ด๋ ์ฟ ๋ฒ๋คํฐ์ค๋ฅผ ์ฒ์ ์์ํ๊ณ ์ค์ตํ๋๋ฐ ํ์ํ ๊ฐ๋
์ด๋ผ๋ฉด ์ดํ์ ๋์ค๋ ์ฉ์ด๋ค์ ๊ฐ๊ฐ์ ์ค์ต๊ณผ ๋์์ ๊ทธ ์ฉ์ด์ ๊ฐ๋
์ ์ ๋ฆฌํด๋ณด๋ ค๊ณ ํ๋ค.</p><p>๋ช๋
๋์ ์ค๊ณง ํซํ ํ๋ซํผ์ ํญ์ ์ฐ๋ ๊ธฐ๋ฅ๋ง ์ฐพ์์ ์จ์๋ค. ์ด์ ์์ ์์ธํ๊ฒ ๊ณต๋ถํ๋ ๊ฒ์ด ์กฐ๊ธ ๋ฆ์ ๊ฒ ๊ฐ์ ์์ฌ์ด ์ ์ด ๋ง์ง๋ง, ์ด ์์ฌ์์ ๋๊ธฐ ์ผ์ ์ด์ฌํ ๊ณต๋ถํด๋ณด๋ ค๊ณ ํ๋ค.</p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/Kubernetes/">Kubernetes</category>
<category domain="https://emjayahn.github.io/tags/Kubernetes/">Kubernetes</category>
<category domain="https://emjayahn.github.io/tags/%EC%BF%A0%EB%B2%84%EB%84%A4%ED%8B%B0%EC%8A%A4/">์ฟ ๋ฒ๋คํฐ์ค</category>
<category domain="https://emjayahn.github.io/tags/Data-Engineering/">Data Engineering</category>
<category domain="https://emjayahn.github.io/tags/CI-CD/">CI/CD</category>
<comments>https://emjayahn.github.io/2023/03/26/20230326-basic-kubernetes/#disqus_thread</comments>
</item>
<item>
<title>[๋
ผ๋ฌธ๋ฆฌ๋ทฐ] Real-time Attention Based Look-alike Model for Recommender System (Part 2)</title>
<link>https://emjayahn.github.io/2023/03/12/20230312-paper-RALM-2/</link>
<guid>https://emjayahn.github.io/2023/03/12/20230312-paper-RALM-2/</guid>
<pubDate>Sun, 12 Mar 2023 05:34:24 GMT</pubDate>
<description><p>๋ณธ ๊ธ์์๋ Real-time Attention Based Look-alike Model for Recommender System ๋
ผ๋ฌธ์ ํ๋ฐ๋ถ ์ฌ์ ์ดํด๋ณด๊ณ ์ ํ๋ค. ํนํ Online Processing, Online Serving ํํธ๋ฅผ ์ง์ค์ ์ผ๋ก ์ดํด๋ณด์.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>๋ณธ ๊ธ์์๋ Real-time Attention Based Look-alike Model for Recommender System ๋
ผ๋ฌธ์ ํ๋ฐ๋ถ ์ฌ์ ์ดํด๋ณด๊ณ ์ ํ๋ค. ํนํ Online Processing, Online Serving ํํธ๋ฅผ ์ง์ค์ ์ผ๋ก ์ดํด๋ณด์.</p><span id="more"></span><h3 id="Key-Features"><a href="#Key-Features" class="headerlink" title="Key Features"></a>Key Features</h3><p>๋ณธ ๋
ผ๋ฌธ์ ํต์ฌ์ 3๊ฐ์ง๋ก ๊ตฌ๋ถ๋๋ค. 1. User representation์ ํ์ตํ๋ offline train model 2. Seeds representation ์ ํ์ตํ๋ ๋น๋๊ธฐ online processing 3. user์ seed๊ฐ์ similarity๋ฅผ ๊ณ์ฐํ๊ณ , ์ ์๋ฅผ ๋งค๊ฒจ ์๋นํ๋ Online Serving</p><p>์ง๋ Part 1์์ User representation๊ณผ offline train model์ ์ดํด๋ณด์๋ค๋ฉด, ์ด๋ฒ ๊ธ์์๋ ๋น๋๊ธฐ online processing ๊ณผ Online serving ๋ถ๋ถ์ ๋ํด ์ดํด๋ณด์.</p><h3 id="1-Online-Asynchronous-Processing"><a href="#1-Online-Asynchronous-Processing" class="headerlink" title="1. Online Asynchronous Processing"></a>1. Online Asynchronous Processing</h3><p>๋น๋๊ธฐ ์จ๋ผ์ธ ํ๋ก์ธ์ฑ์์์ ํต์ฌ์ ์์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๊ฐ์ง๊ณ ์๋ ์ ์ pool์ ํํ ๋ฐฉ์ seeds representation์ ์ค์๊ฐ์ผ๋ก ์
๋ฐ์ดํธ ํ๋ ๊ฒ์ด๋ค. Seeds๋ ์์คํ
์ด ์ง์๋๊ณ , ๊ทธ pool์ด ๋์ด๋จ์ ๋ฐ๋ผ ๊ณ์ ์ถ์ ๋ ๊ฒ์ด๋ค. ๋ํ ๊ฐ์ง๊ณ ์๋ ์ ์ ๋ ๊ณ์ ๊ทธ ํ๋๊ณผ ํ์คํ ๋ฆฌ ๋ฐ์ดํฐ๋ฅผ ๋จ๊ธธ ๊ฒ์ด๊ณ ๊ทธ ๋ฐ์ดํฐ์ ๋ฐ๋ผ ์ ์ ๋ฅผ ํํํ๋ ๋ฐฉ์๋ ์ต์ ํ ๋์ด์ผ๋งํ๋ค. ๋ฐ๋ผ์ ์ด representation ์ ์ฃผ๊ธฐ์ ์ธ ์
๋ฐ์ดํธ๊ฐ ํ์ํ๊ณ , ์๋ง์ seeds๋ฅผ ํจ์จ์ ์ผ๋ก ๊ด๋ฆฌํ๊ณ ๋น์ทํ seeds๋ฅผ ๊ตฌ๋ถ ์ง๊ธฐ ์ํด ๊ตฐ์งํ๋ฅผ ์ํํ๋ค. ๋น๋๊ธฐ ์จ๋ผ์ธ ํ๋ก์ธ์ฑ์ ๋ค์ ๋ ๊ฐ์ง๋ก ๊ตฌ์ฑ๋๋ค.</p><p><strong>User feedback monitor</strong></p><p>Seed์ ํด๋ฆญ, ํ์ด์ง ๋ฐฉ๋ฌธ ๋ฑ ํ๋กํ์ผ ๋ฐ์ดํฐ๋ฅผ ๋ชจ๋ํฐ๋ง ํ๋ฉฐ, ๋ค์ ํด๋ฌ์คํฐ๋ง์ ์ํฅ์ ์ฃผ๊ฒ ๋๋ user profile ์ ์ค์๊ฐ์ผ๋ก ์
๋ฐ์ดํธํ๋ค. ์ด ๋
ผ๋ฌธ์์๋ 3๋ฐฑ๋ง์ click ๋ฐ์ดํฐ๋ฅผ ํ์ฉํ์ฌ seed๋ค์ profile์ ์
๋ฐ์ดํธ ํ๋ค.</p><p><strong>Seeds Clustering</strong></p><p>K-means ์๊ณ ๋ฆฌ์ฆ์ ์ด์ฉํด seed ๋ค์ k ๊ฐ์ ๊ตฐ์ง์ผ๋ก clustering ํ์๋ค. ๊ฐ cluster์ ์ค์ฌ์ ๊ณผ ์
๋ฐ์ดํธ ๋๋ ์ค์ฌ์ ์ ์ ์ฅํด ๋๊ณ , ์ด๋ฅผ seeds์ raw representation $R_{seeds}$ ๊ฐ๋
์ผ๋ก ๋ณด์๋ค.</p><p>$$<br>R_{seeds} = <!โswig๏ฟผ0โ>, E_{centroid_{2}}, E_{centroid_{3}} ,โฆ, E_{centroid_{k}}}}<br>$$</p><h3 id="2-Online-Serving"><a href="#2-Online-Serving" class="headerlink" title="2. Online Serving"></a>2. Online Serving</h3><p>์ด ์จ๋ผ์ธ ์๋น ๋ถ๋ถ์ ์ค์ ๊ตฌํํ๋ ๊ฐ ํ์ฌ๋ ๊ฐ์ธ์ ํ๊ฒฝ์ ๋ฐ๋ผ ๋ณธ ๋
ผ๋ฌธ์ ํํ์๋ ๋ค๋ฅผ ์ ์๊ฒ ๋ค. ํ์ง๋ง ๋ ์ญ์ ์ด ๋ถ๋ถ์ ์ดํด๋ฅผ ํ ๋๋ก ํ์ฌ์ ํ๊ฒฝ์ ๋ง๊ฒ ์์ฉํ์ฌ ์ ์ฉํ์์ผ๋ฏ๋ก ์ฐจ๋ถํ ์ดํด๋ณด์.</p><p>์ด ๋ชจ๋ธ์ด ์๋น์ด ๋ ๋, ๊ทธ input ๋ถํฐ ์ดํด๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.</p><ol><li>Current user โ Fetch look-alike embedding</li><li>Fetch the centroid embeddings</li><li>Predict global embedding (global attention unit)</li><li>Predict local embedding (local attention unit)</li><li>Calculate global similarity & local similarity</li></ol><p>์ ๋จ๊ณ๋ณ๋ก ๊ฑธ์ณ์ง global similarity์ local similarity๋ ๋ค์์ ์์ผ๋ก ํตํฉ๋๋ค.</p><p>$$<br>score_{u, s} = \alpha cosine(E_{u}, E_{global_{s}})+ \beta cosine(E_{u}, E_{local_{s}})<br>$$</p><ul><li>$E_{global_{s}}$ : seeds์ global embedding</li><li>$E_{local_{s}}$ : seeds์ local embedding</li><li>$\alpha , \beta$ : global similarity์ local similarity์ ๊ฐ ๊ฐ์ค์น (๋ณธ ๋
ผ๋ฌธ์์๋ $\alpha=0.3$, $\beta =0.7$๋ก ์ ์ฉํ๋ค.)</li></ul><p>์ด๋ ๊ฒ ์์ ๋ง๋ ๋ชจ๋ธ๋ค์ ๊ฐ ์ ๋์ input ๊ณผ cluster embedding ๊ฐ์ ์ ์ฌ๋ ๊ณ์ฐ์ ํตํด ์ต์ข
๊ณ์ฐ๋ ๋ณธ ์ ์ฌ๋๋ฅผ ํ์ฉํ์ฌ user extension ์ ๊ทธ๋ฃน์ ์ ํ ์ ์๋ค.</p><h3 id="3-๋ณธ-๋
ผ๋ฌธ-๋ฆฌ๋ทฐ๋ฅผ-๋ง์น๋ฉฐ"><a href="#3-๋ณธ-๋
ผ๋ฌธ-๋ฆฌ๋ทฐ๋ฅผ-๋ง์น๋ฉฐ" class="headerlink" title="3. ๋ณธ ๋
ผ๋ฌธ ๋ฆฌ๋ทฐ๋ฅผ ๋ง์น๋ฉฐ"></a>3. ๋ณธ ๋
ผ๋ฌธ ๋ฆฌ๋ทฐ๋ฅผ ๋ง์น๋ฉฐ</h3><p>ํ์ฌ์ ์
๋ฌด๋ก์จ ์ด ๋
ผ๋ฌธ์ ์ฒ์ ์ฝ์์ ๋๋ ๊ทธ๋ฆฌ ํฌ๊ฒ ๊ฐํํ์ง ๋ชปํ๋ค. ํ์ง๋ง ๋ณธ๊ฒฉ์ ์ผ๋ก ๊ตฌํํด๋ณด๋ฉด์, ๋ณธ ๋
ผ๋ฌธ์ ์ฃผ์ฅํ๋ ๋ฐ์ ๊ทธ ์ฃผ์ฅ์ด ๋
ผ๋ฆฌ์ ์ผ๋ก ๋ค๊ฐ์ ๋ด๊ฒ โAhaโํฌ์ธํธ๋ฅผ ์ฃผ์ด, ์ด ๋
ผ๋ฌธ์ ์ ๋ฆฌํ๊ณ ๊ณต์ ํด๋ณด๊ณ ์ถ์๋ค. ์ด ๋
ผ๋ฌธ์ ์ธ์ ๊น์ ์ ์ attention unit ์ ํตํ global , local ์ ์ ๊ฐ์ ์ ์ฌ๋๋ฅผ ์ป๋ ์์ด๋์ด ์๋ค. attention unit์ ์ ์ธํ๊ณ ์ด ๋ชจ๋ธ์ ์ดํด ๋ณด๋ฉด, linear regression์ ์ด์ฉํ user extension ๊ณผ ํฌ๊ฒ ๋ค๋ฅด์ง ์๋ค๋ ๊ฒ์ ์ ์ ์๋ค.</p><p>๋ค๋ฅธ ๋ถ์ผ(NLP)์ ์ ์ ๋ฌผ์ด๋ผ๊ณ ๋ง ๋๊ปด์๋ attention unit ์ ์ ์ฉํ๋ ์์ด๋์ด์ ๋ํด ๋ค์ ํ๋ฒ ๊ฐํํ๋ฉฐ ๋ ์ญ์ ๋ถ์ผ๋ฅผ ๊ฐ๋ฆฌ์ง ์๋ ์คํฐ๋๋ฅผ ํตํด ์ฐฝ์์ ์ธ ์๋๋ฅผ ๊ณ์ ํด๋ด์ผ๊ฒ ๋ค๋ ๋ค์ง์ ํ๋ค.</p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Paper/">Paper</category>
<category domain="https://emjayahn.github.io/tags/%EA%B8%80%EB%98%90/">๊ธ๋</category>
<category domain="https://emjayahn.github.io/tags/%EB%85%BC%EB%AC%B8%EB%A6%AC%EB%B7%B0/">๋
ผ๋ฌธ๋ฆฌ๋ทฐ</category>
<category domain="https://emjayahn.github.io/tags/%EC%B6%94%EC%B2%9C%EC%8B%9C%EC%8A%A4%ED%85%9C/">์ถ์ฒ์์คํ
</category>
<category domain="https://emjayahn.github.io/tags/Look-alike/">Look-alike</category>
<comments>https://emjayahn.github.io/2023/03/12/20230312-paper-RALM-2/#disqus_thread</comments>
</item>
<item>
<title>[๋
ผ๋ฌธ๋ฆฌ๋ทฐ] Real-time Attention Based Look-alike Model for Recommender System (Part 1)</title>
<link>https://emjayahn.github.io/2023/02/26/20230226-paper-RALM-1/</link>
<guid>https://emjayahn.github.io/2023/02/26/20230226-paper-RALM-1/</guid>
<pubDate>Sun, 26 Feb 2023 05:59:57 GMT</pubDate>
<description><p>๋ณธ ๊ธ์์๋ Real-time Attention Based Look-alike Model for Recommender System ๋
ผ๋ฌธ์ ํต์ฌ์ ์ดํด๋ณด๊ณ , ์ ๋
ผ๋ฌธ์ ๊ฐ ํํธ๋ฅผ ๊ตฌํํ๋ฉด์ ๋ง์ฃผํ ๋ฌธ์ ์ ๊ณ ๋ฏผ์ ๊ณต์ ํด๋ณด๊ณ ์ ํ๋ค. Part 1, 2๋ก ๋๋์ด User representation learning ํํธ์ Online Processing ํํธ๋ฅผ ๋๋์ด ์ดํด๋ณด์.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>๋ณธ ๊ธ์์๋ Real-time Attention Based Look-alike Model for Recommender System ๋
ผ๋ฌธ์ ํต์ฌ์ ์ดํด๋ณด๊ณ , ์ ๋
ผ๋ฌธ์ ๊ฐ ํํธ๋ฅผ ๊ตฌํํ๋ฉด์ ๋ง์ฃผํ ๋ฌธ์ ์ ๊ณ ๋ฏผ์ ๊ณต์ ํด๋ณด๊ณ ์ ํ๋ค. Part 1, 2๋ก ๋๋์ด User representation learning ํํธ์ Online Processing ํํธ๋ฅผ ๋๋์ด ์ดํด๋ณด์.</p><span id="more"></span><p>๊ด๊ณ ๋ฅผ ์ก์ถ ํ๋๋ฐ ์์ด, ์์ฆ ๋ด๊ฐ ํ๊ณ ์๋ ๋ฌธ์ ๋ โ์ค๋์ธ์ค์ ํ๋ณดโ์ด๋ค. ๊ด๊ณ ์ฃผ๋ง๋ค ํน์ KPI ๋ฅผ ๋ฌ์ฑํ๋๋ฐ ํ์ํ ์ค๋์ธ์ค๋ ์ ํด์ ธ์๋ค๊ณ ์ ์ ํ ๋, ๊ด๊ณ ์์คํ
์ ์ ์ฒด ์ค๋์ธ์ค ํ์์ ํน์ KPI๋ฅผ ๋ฌ์ฑํ๋๋ฐ ์ ๋ฆฌํ ์ค๋์ธ์ค๋ฅผ ์ฐพ์๋ด ํ๊ฒํ
, ๋ฆฌํ๊ฒํ
์ ์ ํด๋ด์ผ ํ๋ค. โ์ค๋์ธ์ค ํ๋ณดโ๋ฅผ ์ํด์ ๋ค์ํ ์์ด๋์ด์ ๊ทผ๊ฐํด ๊ฐ๋ฐ์ ํ๊ณ ์๊ณ , ์ฐ๋ฆฌ ๊ด๊ณ ์์คํ
์ ์คํ์ ํ๊ณ ์๋ค. ๊ทธ ์ค RecSys๋ถ์ผ์์ ์ฌ๋ฏธ์๊ฒ ์ฝ์ Attention based Look-alike Model ๋
ผ๋ฌธ์ ๋ฆฌ๋ทฐํด ๋ณธ๋ค. Look-alike Model ์ ํน์ ์บ ํ์ธ์์ ํจ์จ(๊ฐ๋จํ๊ฒ๋ CTR, CVR ๋ฑ)์ด ์ข์๋ N๋ช
์ ์ค๋์ธ์ค์ ํน์ง์ ์ฐพ๊ณ , ์ ์ฒด ์ค๋์ธ์ค ํ์์ N๋ช
๊ณผ ์ ์ฌํ M์ ์ฐพ๋ ๊ฒ์ด๋ค. </p><h3 id="Key-Features"><a href="#Key-Features" class="headerlink" title="Key Features"></a>Key Features</h3><p>๋ณธ ๋
ผ๋ฌธ์ ํต์ฌ์ 3๊ฐ์ง๋ก ๊ตฌ๋ถ๋๋ค. 1. User representation์ ํ์ตํ๋ offline train model 2. Seeds representation ์ ํ์ตํ๋ ๋น๋๊ธฐ online processing 3. user์ seed๊ฐ์ similarity๋ฅผ ๊ณ์ฐํ๊ณ , ์ ์๋ฅผ ๋งค๊ฒจ ์๋นํ๋ Online Serving</p><p>๋ณธ ๋
ผ๋ฌธ์ ์ง์ ๊ตฌํํ๋๋ฐ ์์ด ๊ฐ์ฅ ์ค์ํ ๊ฒ์ 1, 2๋ฒ์ ๋ชจ๋ธ๋ง ๋ฐฉ๋ฒ์ด๋ค. 3์ ๊ฒฝ์ฐ, ๊ฐ ํ์ฌ๋ ์์คํ
๋ง๋ค ์ ์ฉํ ์ ์๋ ๋ฐฉ๋ฒ์ ๋ค์ํ๊ฒ ์์ ๊ฒ์ด๋ค. ๋ณธ ๊ธ์์๋ 1๋ฒ์ ์ง์คํ์ฌ ํต์ฌ์ ํ์
ํด๋ณด์. ๋ค์๊ธ์์ 2๋ฒ ๋ชจ๋ธ์ ์์๋ณด์.</p><h3 id="1-User-Representation-Learning"><a href="#1-User-Representation-Learning" class="headerlink" title="1. User Representation Learning"></a>1. User Representation Learning</h3><p>์ ์ profile ๋ฐ์ดํฐ๋ ๋งค์ฐ ๋ค์ํ๊ฒ ์์ ๊ฒ์ด๋ค. ๊ธฐ๋ณธ์ ์ธ ๋ฉํ๋ฐ์ดํฐ๋ถํฐ ํน์ ๊ด๊ณ ์บ ํ์ธ์์์ ํด๋ฆญ์, ๋๋ฉ ํ์ด์ง, ๋๋ฉ ํ์ด์ง์์์ ํ๋ ๋ฑ. user ๋ฅผ ํํ ํ ์ ์๋ profile feature data ๋ ์ ์ ์ ๋์ด ์๋ค๋ ์ ์ ํ์ ๋ณธ ๋
ผ๋ฌธ์ด ์ ์ํ๋ user representation learning ๋ชจ๋ธ์ ์ดํด๋ณด์. </p><p><img src="/2023/02/26/20230226-paper-RALM-1/Untitled.png" alt="๊ทธ๋ฆผ : User representation learning Model Architecture"></p><p>๊ทธ๋ฆผ : User representation learning Model Architecture</p><p><strong>Sampling</strong></p><p>๋จผ์ , ๋ณธ ๋
ผ๋ฌธ์ user representation embedding ์ ํ์ต์ํค๊ธฐ ์ํด multi-class classification ๋ฌธ์ ๋ฅผ ๋ง๋ค์๋ค. ์ ์ ๋ง๋ค ํด๋ฆญํ๋ ์์ดํ
์ ์นดํ
๊ณ ๋ฆฌ๋ฅผ ๋ถ์ฌํ๊ณ , ๊ฐ ์นดํ
๊ณ ๋ฆฌ๋ก ๋ถ๋ฅํ๋ ๋ฌธ์ ์ด๋ค. ์ด ๋ ์ ๋ง์ ์นดํ
๊ณ ๋ฆฌ๊ฐ ์กด์ฌํ ๊ฒ์ด๊ณ , ์ ์ ์ ๋ถํฌ์ ์นดํ
๊ณ ๋ฆฌ ๋ง๋ค์ ๋ถํฌ๊ฐ ํ์ต์ํค๋๋ฐ ๋ถ๋ฆฌํ๋ฏ๋ก, ๋ค์๊ณผ ๊ฐ์ negative sampling ์ ํ์ฉํ๋ค.</p><p>$$<br>p(x_{i})= \frac {log(k+2)-log(k+1)}{log(D+1)}<br>$$</p><ul><li>$x_{i}$ : i๋ฒ์งธ ์์ดํ
</li><li>$k$ : i ๋ฒ์งธ ์์ดํ
์ ๋ญํฌ</li><li>$D$ : ์์ดํ
๋ญํฌ์ ์ต๋๊ฐ</li><li>$p(x_{i})$ : i๋ฒ์งธ ์์ดํ
์ด ๋ฝํ ํ๋ฅ </li></ul><p>๋ณธ ๋
ผ๋ฌธ์์๋ negative sampling ์์ poitive : negative ์ ๋น์จ์ 1:10์ผ๋ก ์ค์ ํ๋ค.</p><p><strong>๋ชจ๋ธ ๊ตฌ์กฐ</strong></p><p>๋ณธ ๋ชฌ๋ฌธ์์๋ ์์ multi-class classification ๋ฌธ์ ๋ฅผ ํ๊ธฐ ์ํด, ๋ชจ๋ธ ๊ตฌ์กฐ๋ ๋ค์๊ณผ ๊ฐ์ด ๊ฐ๋จํ๋ค.</p><ol><li>Embedding layer : (user, item)</li><li>(2-1) Concatenation layer : ๋ถ์ด์! or (2-2) Attention merge layer : ์ ๋ถ์ด์!</li><li>Multi layer perceptron</li><li>(optimizer) Adam optimizer</li></ol><p> ๋ง์ง๋ง Loss ๋ Cross Entropy Loss</p><p>$$<br>L = - \Sigma_{j \in X} y_ilogP(c=i| U, X_{i})<br>$$</p><ul><li>$X$: ์์ดํ
embedding ์งํฉ</li><li>$y_{i}$ : 0 or 1 ์ ๋ผ๋ฒจ</li></ul><p><strong>Attention Merge Layer</strong></p><p>๋ณธ ๋
ผ๋ฌธ์์๋ ๋จ์ concatenation layer ์ ์ฌ์ฉํ๋, ํน์ ์์ดํ
ํ๋์์ ์ค๋ฒํผํ
๋๋ ๋ฌธ์ ๊ฐ ์์ด, ๊ฐํ๊ณ ์ฝํ ์๊ด๊ด๊ณ๋ฅผ ๋ฌ์ฌํ๊ธฐ ์ํด ๋ค์๊ณผ ๊ฐ์ attention ์ ๋์ ์ฌ์ฉํ๋ค. </p><p>$$<br>u=tanh(W_{1}H)<br>$$</p><p>$$<br>a_{i} = \frac {e^{W_{2}u_{i}^{T}}}{\Sigma_{j}^{n}e^{W_{2}u_{j}^{T}}}<br>$$</p><ul><li>$h \in \mathbb {R}^m$, $H \in \mathbb {R^{n \times m}}$</li><li>$W_1 \in \mathbb{R}^{k \times n}$, $W_2 \in \mathbb {R}^{k}$</li><li>$u \in \mathbb{R}^n$ : activation ์ ๋</li><li>$a \in \mathbb{R}^{n}$ : attention weight</li><li>$k$ : attention ์ ๋ ์ฌ์ด์ฆ</li></ul><p>์ ์์ ๊ณ์ฐํ๊ณ , ์ต์ข
์ ์ผ๋ก concatenated layer ๋ฅผ ๋์ ํ๋ vector ๋ ๋ค์๊ณผ ๊ฐ์ด ๊ณ์ฐ๋๋ค.</p><p>$$<br>M=aH<br>$$</p><h3 id="2-User-Representation-Learning-๊ตฌํ์-์์ด์-๋ง์ฃผํ-๋ฌธ์ ๋ค"><a href="#2-User-Representation-Learning-๊ตฌํ์-์์ด์-๋ง์ฃผํ-๋ฌธ์ ๋ค" class="headerlink" title="2. User Representation Learning ๊ตฌํ์ ์์ด์ ๋ง์ฃผํ ๋ฌธ์ ๋ค."></a>2. User Representation Learning ๊ตฌํ์ ์์ด์ ๋ง์ฃผํ ๋ฌธ์ ๋ค.</h3><p><strong>2-1. User Profile Data</strong></p><p>์ฒ์๊ณผ ๋์ ๋ฐ์ดํฐ์์ ๋ชจ๋ ๋ฐ์ดํฐ์ฌ์ด์ธํฐ์คํธ๊ฐ ๊ฐ์ง๊ณ ์๋ ๊ณ ๋ฏผ์ด๋ค. ์์ง์ ๋ฐ์ดํฐ ์จ์ดํ์ฐ์ค๋ฅผ ๊ตฌ์ฑํ๋๊ฒ. ๋ณธ ๋
ผ๋ฌธ์ ๊ตฌํํ๊ณ ์์คํ
์ ํ
์คํธ ํ๋๋ฐ ์์ด ๊ฐ์ฅ ์ค๋ ์๊ฐ์ด ๊ฑธ๋ฆฐ ๊ฒ์ด ์
๋ ฅ ๋ฐ์ดํฐ ์จ์ดํ์ฐ์ค๋ฅผ ๊ตฌ์ฑํ๋ ๊ฒ์ด์๋ค. ๊ธฐ์กด์ ์ฌ์ฉํ๊ณ ์๋ ๋ฐ์ดํฐ์์ attention ํ์ต์ ์ํด ์๊ณ์ด์ ์ธ ํ์ต ๋ฐ์ดํฐ๋ฅผ ๊ตฌ์ฑํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ฌ์ ํ ์ถ๊ฐ๋๋ ์๋ก์ด feature์ ๋ํด์๋ ๊ณ ๋ฏผํ๊ณ ์๋ค. ๊ด๊ณ ํน์ฑ์ ๊ฐ ์์ฌ ๋ฐ ๋งค์ฒด๋ง๋ค ๋ถ๋ IAB ์นดํ
๊ณ ๋ฆฌ ๋ฟ๋ง ์๋๋ผ, ์ ์ ์ ํ๋์๋ ๊ฐ ์นดํ
๊ณ ๋ฆฌ ๊ฐ์ ์๊ณ์ด์ ์ผ๋ก ๋ด์๋ค. ๋ณธ ๋
ผ๋ฌธ์ ์์ด๋์ด๋ฅผ ์ฐจ์ฉํด, ์ผ์ ๊ธฐ๊ฐ ๋์ ํด๋ฆญ ๋ฐ ์ ํํ๋ IAB ์นดํ
๊ณ ๋ฆฌ ๋ด์์์ ๋ค๊ฑฐํฐ๋ธ ์ํ๋ง์ ์ ์ฉํ๋ค.</p><p><strong>2-2. Attention Merge Layer์ ํจ๊ณผ</strong></p><p>๋ณธ ๋
ผ๋ฌธ์ฒ๋ผ ๋ ์ญ์ base model์ ๋จ์ concatenated layer ๋ก ์ก์๋ค. (torch.concat ๋ง ํ๋ฉด ๋๋๊น..) ๋ฐ๋ฉด์ ๋
ผ๋ฌธ์์ ์๊ฐ๋ ๊ตฌ์กฐ๋ก attention layer๋ฅผ ์ถ๊ฐํ ๋ค์ ๋ชจ๋ธ์์๋ ํ์ต ์ํค๋๋ฐ ์ด๋ ค์์ด ์์๋ค. ํน์ attention weight ๋ง ์
๋ฐ์ดํธ ๋๋ ๋ฌธ์ ๋ฅผ ๋ฐ๊ฒฌํ๊ฒ ๋์๋ค. attention ๋ชฉ์ ์ ๋ง๋ ๊ธฐ๋ฅ์ ํ๊ธด ํ์ผ๋, ํน์ attention weight ๋ง ์
๋ฐ์ดํธ๊ฐ ๋๋ฉด์, ์ผ๋ถ item embedding ์ ๋ฐ์๋์ง ๋ชปํ๋ ํจ๊ณผ๊ฐ ์์๋ค. ์ด๋ฅผ ๋งํํ๊ธฐ ์ํด, ๋๋ attention merge layer ์ base ๋ชจ๋ธ์ concatenated layer ๊ตฌ์กฐ๋ฅผ z ์ถ์ผ๋ก ๋ถ์ฌ ํ์ต์ํค๊ธฐ๋ ํ์๋ค. ์์น์์ผ๋ก๋ ์ ์ ๋ ๊ตฌ์กฐ๋ณด๋ค ๋์ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์์ผ๋, ํด๋น ๊ตฌ์กฐ๊ฐ ๊ฐ๋ ์๋ฏธ์ ๊ธฐ๋ฅ์ ์กฐ๊ธ๋ ๊ณ ๋ฏผํด๋ณด์์ผ ํ๋ค.</p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Paper/">Paper</category>
<category domain="https://emjayahn.github.io/tags/%EA%B8%80%EB%98%90/">๊ธ๋</category>
<category domain="https://emjayahn.github.io/tags/%EB%85%BC%EB%AC%B8%EB%A6%AC%EB%B7%B0/">๋
ผ๋ฌธ๋ฆฌ๋ทฐ</category>
<category domain="https://emjayahn.github.io/tags/%EC%B6%94%EC%B2%9C%EC%8B%9C%EC%8A%A4%ED%85%9C/">์ถ์ฒ์์คํ
</category>
<category domain="https://emjayahn.github.io/tags/Look-alike/">Look-alike</category>
<comments>https://emjayahn.github.io/2023/02/26/20230226-paper-RALM-1/#disqus_thread</comments>
</item>
<item>
<title>[๊ธ๋] ๊ธ๋ 8๊ธฐ๋ฅผ ์์ํ๋ ๊ธ</title>
<link>https://emjayahn.github.io/2023/02/04/20230204-geultto-objective/</link>
<guid>https://emjayahn.github.io/2023/02/04/20230204-geultto-objective/</guid>
<pubDate>Sat, 04 Feb 2023 11:53:16 GMT</pubDate>
<description><h2 id="01-Greetings"><a href="#01-Greetings" class="headerlink" title="01. Greetings"></a>01. Greetings</h2><p>๊ธ๋ 8๊ธฐ๋ฅผ ์์ํ๋ฉฐ, ์์ผ๋ก ํ๋ํ๋ ๋์ ๋ชฉํํ๊ณ ์ ํ๋ ๋ฐ๋ฅผ ์ ๋ฆฌํด๋ณธ๋ค. </p>
<p>์๋
ํํด ๋์ ๋๋ฌด๋๋ ์ ์ ์๋ ํํด๋ฅผ ๋ณด๋๋ค. ํ์ฌ ๋ด์์ ๋จธ์ ๋ฌ๋ ํ๋ก์ ํธ 2๊ฑด์ ๋ํ ๊ธฐํ์์๋ถํฐ ETL, Data Pipeline, ๋ชจ๋ธ ์ฐ๊ตฌ ๊ฐ๋ฐ, ๋ชจ๋ธ ์๋น๊น์ง ์์
ํ๋ค. ํ ํด๋ฅผ ๋์๋ณด๋ฉด์ ์์ฌ์ ๋ ๋ถ๋ถ์ ์๋กญ๊ฒ ์๊ฒ๋ ๋ค์ํ ๊ธฐ์ (ํนํ, Data Engineering ๋ถ์ผ์ MLOps ๋ถ์ผ)๊ณผ ์๋ก ์ ํ๋ ๋
ผ๋ฌธ (Tabular Network, RecSys), ๊ทธ๋ฆฌ๊ณ ์์
ํ ์ฝ๋๋ค์ ๋จ๋ฐฑํ๊ฒ ์ ๋ฆฌํ์ง ๋ชปํ๋ ๊ฒ์ด๋ค.</p>
<p>์ด๋ฒ ํ๋์ ํตํด์, ์๊ณ ์ถ์ ๊ฒ๊ณผ ์๊ฒ ๋ ๊ฒ์ <strong>์ฒด๊ณ์ ์ด๊ณ ์๊ธฐ ์ฝ๊ฒ ์ ๋ฆฌํ๋ ๊ฒ</strong>์ด ๋์ ๋ชฉํ์ด๋ค.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><h2 id="01-Greetings"><a href="#01-Greetings" class="headerlink" title="01. Greetings"></a>01. Greetings</h2><p>๊ธ๋ 8๊ธฐ๋ฅผ ์์ํ๋ฉฐ, ์์ผ๋ก ํ๋ํ๋ ๋์ ๋ชฉํํ๊ณ ์ ํ๋ ๋ฐ๋ฅผ ์ ๋ฆฌํด๋ณธ๋ค. </p><p>์๋
ํํด ๋์ ๋๋ฌด๋๋ ์ ์ ์๋ ํํด๋ฅผ ๋ณด๋๋ค. ํ์ฌ ๋ด์์ ๋จธ์ ๋ฌ๋ ํ๋ก์ ํธ 2๊ฑด์ ๋ํ ๊ธฐํ์์๋ถํฐ ETL, Data Pipeline, ๋ชจ๋ธ ์ฐ๊ตฌ ๊ฐ๋ฐ, ๋ชจ๋ธ ์๋น๊น์ง ์์
ํ๋ค. ํ ํด๋ฅผ ๋์๋ณด๋ฉด์ ์์ฌ์ ๋ ๋ถ๋ถ์ ์๋กญ๊ฒ ์๊ฒ๋ ๋ค์ํ ๊ธฐ์ (ํนํ, Data Engineering ๋ถ์ผ์ MLOps ๋ถ์ผ)๊ณผ ์๋ก ์ ํ๋ ๋
ผ๋ฌธ (Tabular Network, RecSys), ๊ทธ๋ฆฌ๊ณ ์์
ํ ์ฝ๋๋ค์ ๋จ๋ฐฑํ๊ฒ ์ ๋ฆฌํ์ง ๋ชปํ๋ ๊ฒ์ด๋ค.</p><p>์ด๋ฒ ํ๋์ ํตํด์, ์๊ณ ์ถ์ ๊ฒ๊ณผ ์๊ฒ ๋ ๊ฒ์ <strong>์ฒด๊ณ์ ์ด๊ณ ์๊ธฐ ์ฝ๊ฒ ์ ๋ฆฌํ๋ ๊ฒ</strong>์ด ๋์ ๋ชฉํ์ด๋ค.</p><span id="more"></span><h2 id="02-Objective"><a href="#02-Objective" class="headerlink" title="02. Objective"></a>02. Objective</h2><p>์ด๋ฒ ๊ธ๋ 8๊ธฐ๋ฅผ ํ๋ํ๋ฉด์ ๋ชฉํํ๋ ๋ฐ๋ ๋ค์๊ณผ ๊ฐ๋ค.</p><ol><li>๊ธ ์ฐ๋ ์ต๊ด ๊ธฐ๋ฅด๊ธฐ<ul><li>ํ์ ๋
ผ๋ฌธ ์์ฝ๊ณผ ๊ธฐ์ ์ ๋ฆฌ๋ ๊ฐ์ธ์ ์ผ๋ก ์ ๋ฆฌํ๊ณ ์์ผ๋, ๋จ์๊ฒ ๊ณต๊ฐํ ๋งํผ โ๊ธโ๋ก ๋ฌ์ฌ ํ์ง ์๋๋ค. ์ด๋ฐ ์ ์ ์์ฑํ ๋๋ ํธํ์ง๋ง, ๋ค์ ๋ณผ ๋ ๊ธฐ์ต์ ๋์ด๋ฆฌ๋ ๋ฉด์์ ๋งค์ฐ ํฐ ์ฝ์ ์ ๊ฐ์ง๊ณ ์๋ค. ์ฌ์ง์ด๋ ๋
ผ๋ฌธ์ ๋ค์ ์ฝ์ ๋๋ ์๊ณ , ์ฝ๋ ์ ๋ฌธ์ ๋ค์ ๋ณผ ๋๋ ๋ง๋ค.</li><li>์ฃผ์ ๋ฅผ ์ ์ ํด, ๊ณต๊ฐํ๋ ๊ธ์ ๋ํด์๋ ์ต๋ํ ์์ธํ๊ณ ์น์ ํ ์ค๋ช
๊ณผ ์ ๋ฆฌ๋ฅผ ํ๊ฒ ๋ค.</li></ul></li><li>์ถ์ฒ์์คํ
, ํนํ CTR based / Audience Extension ์ถ์ฒ ์ ๋ฆฌ<ul><li>์์ฆ ๊ด์ฌ ์๋ ์ฃผ์ ๋ CTR based ์ถ์ฒ๊ณผ Audience Extension ์ ๋ํ ์ถ์ฒ์ ๊ด์ฌ์ด ๋ง๋ค.</li><li>์ก๊ณ ์๋ ๋
ผ๋ฌธ ์ค์ฌ์ผ๋ก ์ ๋ฆฌํ๋ฉฐ, ํ
์คํธ๋ฅผ ์งํํ ์ ์๋ ์ฝ๋๋ฅผ ์ง๋ ๊ฒ์ด ๋ชฉํ์ด๋ค.</li></ul></li><li>NiFi, Airflow ์ ๋ฆฌ<ul><li>์๋
๋ถํฐ nifi ๋ฅผ ํ์ฉํด ๋ฐ์ดํฐ ํ์ดํ๋ผ์ธ ๊ตฌ์ถ์ ์๋ฃํ๋ค. Nifi ๋ฅผ ํ์ฉํด ํ๋ ํ ์ ์๋ ๋ถ๋ถ์ ์๊ฒ ๋ ๋ ๋ง๋ค ์ ์ ๋ฆฌํ๊ณ ์ถ๋ค. ๋ํ ๋ค๋ฅธ ํ์ฌ์์๋ airflow ๋ฅผ ๋ง์ด ํ์ฉ ํ๊ณ ์๋ค๋ณด๋, nifi์์ ๊ณตํต์ /์ฐจ์ด์ ๋ค์ ์ดํด๋ณผ ํ์๊ฐ ์๊ฒ ๋ค๋ ์๊ฐ์ ํ๋ค. ํํํ airflow๋ถ๋ถ๋ ์ดํด๋ด์ผ๊ฒ ๋ค.</li></ul></li><li>๋ค๋ฅธ ๋ถ๋ค์ ๊ธ ์ฝ๊ธฐ / ์ปคํผ์ฑ ์ฐธ์ฌ<ul><li>๊ธ๋์ ์ ๋ง ๋ค์ํ ๋ถ์ผ์ ๊ณ์ ๋ถ๋ค์ด ๋ง๋ค. ๋จธ์ ๋ฌ๋/ai ์ ๊ด๋ จ๋ ๋ถ์ผ ๋ฟ๋ง ์๋๋ผ ๋ฐ์ดํฐ ์์ง๋์ด, ๋ฐ์ดํฐ ๋ถ์ ๋ถ์ผ์ ๊ธ์ ํํํ ์ฝ๊ณ ์ถ๋ค. ๋ ๊ด๊ณ ๋ถ์ผ์ ๊ณ์ ๋ถ๋ค๋ ์๋ ๊ฒ ๊ฐ์, ad-tech ๊ด๋ จ๋ ๊ธ๊ณผ ์ปค๋ฎค๋์ผ์ด์
๋ ๋ง์ด ํ ์ ์์ ๊ฒ ๊ฐ์ ๊ธฐ๋ ์ค์ด๋ค.</li></ul></li><li>๋ธ๋ก๊ทธ ํ๋ซํผ ์ด์ฌ<ul><li>ํ์ฌ github ๋ธ๋ก๊ทธ๋ฅผ ์ด์ฉ์ค์ด๋ค. ๊ทผ๋ฐ ์ด์ฌํ๊ณ ์ถ๋ค.</li><li>ํ์ฌ ํ๋ณด๋ tistory, oopy, medium.<ul><li>์๋ก์ด ํ๋ซํผ์ ํ์ฉํ๋ ค๋ฉด ๋ ์๊ฐ์ ๋ด์ด์ ํ๋ซํผ ํ์์ ํด์ผํ๊ธฐ ๋๋ฌธ์.. ๋งค๋ฒ ๊ธ์ ์
๋ก๋ ํ ๋๋ง๋ค github ์ธ์ ํ๊ตฐ๋ฐ์ฉ ์ฌ๋ ค๋ณด๊ณ , ์กฐ๊ธ์ฉ ๋ง์ ธ๋ณด๋ฉฐ ์ด์ฌ๋ฅผ ์ฒ์ฒํ ์ค๋นํ๋ ค๊ณ ํ๋ค.</li></ul></li></ul></li></ol><h2 id="03-Conclusion"><a href="#03-Conclusion" class="headerlink" title="03. Conclusion"></a>03. Conclusion</h2><p>๊ฐ๋ณ๊ฒ ์ฐ๊ธฐ ์์ํ ๋ชฉํ ์ ๋ฆฌ ๊ธ์ด ์ฐ๋ค๋ณด๋ ์ฅ๋ํด์ง ๊ฒ ๊ฐ๋ค. 6๊ฐ์์ด ์ง๋ ์์ ์ ํ๋์ ๋ง๋ฌด๋ฆฌ ํ๋ฉด์ ํํ ์๋ ์๊ฐ์ด ๋์์ผ๋ฉด ์ข๊ฒ ๋ค.</p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/%EA%B8%80%EB%98%90/">๊ธ๋</category>
<category domain="https://emjayahn.github.io/tags/%EA%B8%80%EB%98%90/">๊ธ๋</category>
<category domain="https://emjayahn.github.io/tags/%EB%AA%A9%ED%91%9C/">๋ชฉํ</category>
<comments>https://emjayahn.github.io/2023/02/04/20230204-geultto-objective/#disqus_thread</comments>
</item>
<item>
<title>[๊ธ๋] ์ถ์ ์ง๋</title>
<link>https://emjayahn.github.io/2023/01/14/20230114-geultto-map-of-life/</link>
<guid>https://emjayahn.github.io/2023/01/14/20230114-geultto-map-of-life/</guid>
<pubDate>Sat, 14 Jan 2023 14:25:26 GMT</pubDate>
<description><h2 id="00-๋ค์ด๊ฐ๋-๊ธ"><a href="#00-๋ค์ด๊ฐ๋-๊ธ" class="headerlink" title="00. ๋ค์ด๊ฐ๋ ๊ธ"></a>00. ๋ค์ด๊ฐ๋ ๊ธ</h2><p>๊ธ๋ 8๊ธฐ์ ์ง์ํ๋ฉฐ, <strong>์ถ์ ์ง๋</strong>๋ฅผ ๊ทธ๋ ค๋ณด๋ ์๊ฐ์ ๊ฐ์ก๋ค. ๊ณต์ง๋ฅผ ๋ณด๊ณ ์ผ์ฃผ์ผ์ด ์ง๋๋๋ก ์ด๋ป๊ฒ ๊ธ์ ์จ๋ด๋ ค๊ฐ์ผ ํ ์ง ์์ด ์์ง์ด์ง ์์๋ค. ๋ ์์ฒด๋ฅผ ๋์๋ณด๋ฉฐ, ๊ธ ์์ฒด๋ณด๋ค ๋๋ฅผ ๋์๋ณด๋ ์ด ์๊ฐ๋ค์ด ๋งค์ฐ ๊ฐ์ก๋ค. ๋๋ฅผ ์ด๋ฃจ๋ ๋ค์ํ ๋ฉด๋ค์ด ๋จ์ํ ํ๊ฐ์ง ์ฌ๊ฑด์์ ๋น๋กฏ๋์ง ์์๋ค๋ ๊ฒ์ ๊นจ๋ฌ์๊ณผ ๋์์ ๋ณต์กํ๊ฒ ์ฝํ ์๊ฐ๊ณผ ๊ฒฝํ์ ๊ธ๋ก ์จ๋ด๋ ค๊ฐ๋ฉฐ ์กฐ๊ธ์ฉ ์ ๋ฆฌ ๋๋ ๊ฒ๋ ๊ฒฝํํ๋ค. ์๋์ ์งง์ ๊ธ์ ํตํด์ ์กฐ๊ธ์ด๋๋ง ๋์๊ฒ ๊ด์ฌ ์๋ ์ฌ๋๋ค์๊ฒ ๋ด <strong>์ถ์ ์ง๋</strong>๊ฐ ์ ์ ๋ฌ๋์์ผ๋ฉด ํ๋ค. </p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><h2 id="00-๋ค์ด๊ฐ๋-๊ธ"><a href="#00-๋ค์ด๊ฐ๋-๊ธ" class="headerlink" title="00. ๋ค์ด๊ฐ๋ ๊ธ"></a>00. ๋ค์ด๊ฐ๋ ๊ธ</h2><p>๊ธ๋ 8๊ธฐ์ ์ง์ํ๋ฉฐ, <strong>์ถ์ ์ง๋</strong>๋ฅผ ๊ทธ๋ ค๋ณด๋ ์๊ฐ์ ๊ฐ์ก๋ค. ๊ณต์ง๋ฅผ ๋ณด๊ณ ์ผ์ฃผ์ผ์ด ์ง๋๋๋ก ์ด๋ป๊ฒ ๊ธ์ ์จ๋ด๋ ค๊ฐ์ผ ํ ์ง ์์ด ์์ง์ด์ง ์์๋ค. ๋ ์์ฒด๋ฅผ ๋์๋ณด๋ฉฐ, ๊ธ ์์ฒด๋ณด๋ค ๋๋ฅผ ๋์๋ณด๋ ์ด ์๊ฐ๋ค์ด ๋งค์ฐ ๊ฐ์ก๋ค. ๋๋ฅผ ์ด๋ฃจ๋ ๋ค์ํ ๋ฉด๋ค์ด ๋จ์ํ ํ๊ฐ์ง ์ฌ๊ฑด์์ ๋น๋กฏ๋์ง ์์๋ค๋ ๊ฒ์ ๊นจ๋ฌ์๊ณผ ๋์์ ๋ณต์กํ๊ฒ ์ฝํ ์๊ฐ๊ณผ ๊ฒฝํ์ ๊ธ๋ก ์จ๋ด๋ ค๊ฐ๋ฉฐ ์กฐ๊ธ์ฉ ์ ๋ฆฌ ๋๋ ๊ฒ๋ ๊ฒฝํํ๋ค. ์๋์ ์งง์ ๊ธ์ ํตํด์ ์กฐ๊ธ์ด๋๋ง ๋์๊ฒ ๊ด์ฌ ์๋ ์ฌ๋๋ค์๊ฒ ๋ด <strong>์ถ์ ์ง๋</strong>๊ฐ ์ ์ ๋ฌ๋์์ผ๋ฉด ํ๋ค. </p><span id="more"></span><h2 id="01-๋ชจํ๊ณผ-๋์ ์-์ฆ๊ธฐ๋-ํ์ฌ์-๋"><a href="#01-๋ชจํ๊ณผ-๋์ ์-์ฆ๊ธฐ๋-ํ์ฌ์-๋" class="headerlink" title="01. ๋ชจํ๊ณผ ๋์ ์ ์ฆ๊ธฐ๋ ํ์ฌ์ ๋"></a>01. ๋ชจํ๊ณผ ๋์ ์ ์ฆ๊ธฐ๋ ํ์ฌ์ ๋</h2><p>#2023 #๋ฐ์ดํฐ์ฌ์ด์ธํฐ์คํธ #ML์์ง๋์ด #๊ฐ์ฒ์ #๋์ </p><p>๋๋ ํ์ฌ ๋์ค๋ฏธ๋์ด ๋ฐ์ดํฐ์ฌ์ด์ธํฐ์คํธ๋ก ์ผ์ ํ๊ณ ์๋ค. ๋ฏธ๋์ด๋ ์ฌ์ด์ ๊ด๊ณ ํ๋ซํผ์ ์ด์ํ๊ณ ์๋ ๋์ค๋ฏธ๋์ด๋ ์จ๋ผ์ธ / ์คํ๋ผ์ธ ๊ด๊ณ ์์ฅ์์ 1์๋ฅผ ์ ์ ํ๊ณ ์๋ ํ์ฌ์ด๋ค. ์ด๊ณณ์ ๋ฐ์ดํฐ์ฌ์ด์ธํฐ์คํธ๋ก ์ผ์ ํ๋ฉด์ ๋ค์ํ ํ๋ก์ ํธ๋ฅผ ๋ฆฌ๋ฉํ๊ณ , ํ์ฌ๋ ๊ด๊ณ ์ถ์ฒ ์์คํ
์ ์ฐ๊ตฌํ๊ณ ์๋ค.</p><p>๋๋ ๋์ค๋ฏธ๋์ด ์ต์ด์ ๋ฐ์ดํฐ์ฌ์ด์ธํฐ์คํธ๋ก ์
์ฌํ๋ค. 2021๋
์ ๋ค์ด์์ ๋ ์ฐ๋ฆฌ ๋ฐ์ดํฐ์ฌ์ด์ธ์คํ์ ํ์์ด ํผ์์ธ 1์ธํ์ด์๊ณ , ํ์ฌ๋ 7๋ช
์ ํ์๋ค์ด ์๋ค. ์ฒ์ ํ์ฌ์ ๋ค์ด์์ ๋๋ ์ฐ๊ตฌ๊ฐ๋ฐ์ ์ํ ์ธํ๋ผ๋ ๋ถ์ฌํ๊ณ , ํ๋ฃจ ์์ต๊ฑด์ ํธ๋ํฝ ๋ฐ์ดํฐ๋ ๋จธ์ ๋ฌ๋/๋ฐ์ดํฐ๋ถ์์ ์ํ ํํ๋ก ์ ์ฌ๋์ง ์์๋ค. ์ฒ์ ์
์ฌํ์๋ง์ ๊ด๊ณ ๋๋ฉ์ธ์ ๋ํ ๋น์ง๋์ค ๊ณต๋ถ๋ฅผ ํจ๊ณผ ๋์์ ์ด๋ฐ ์ธํ๋ผ๋ฅผ ๊ตฌ์ถํ๋๋ฐ ํ์ ์ผ๋ค. </p><p>2021๋
์ ๋์ค๋ฏธ๋์ด์ ํฉ๋ฅํ ๋์ ๊ฒฐ์ ์ ๋์๋ณด๋, ๋๋ ๋ชจํ๊ณผ ๋์ ์ ์ข์ํ๋ ์ฌ๋์ด๋ค. ๋ํ ๋๋ฅผ ๊ฐ์ฅ ๋ค๋จ๊ฒ ํ๋ ๊ฒ์ ์ด๋ฐ ๋ชจํ๊ณผ ๋์ ์ ํ๋ ๊ณผ์ ์์ ๊ฒช๋ ์ํ์ฐฉ์ค์ ๊ทธ ์ํ์ฐฉ์ค ๋์ ์ป์ด์ง๋ ์งํ์ ์ง์์ ์ ๋ฆฌํ๊ณ ์์๊ฐ๋ ๊ณผ์ ์ ํฌ์ด์ ๋๋ผ๋ ์ฌ๋์ด๋ค. ์ง๊ธ๋ ๋ด๊ฐ ๋ชจ๋ฅด๋ ๊ฒ์ ๋ํ ํ๊ตฌ์ ์๋ ๊ฒ์ ์ ๋ฆฌํ์ฌ ๊ณต์ ํ ๋ ์ป์ด์ง๋ ๋ณด๋์ ํฅํด ๋ฌ๋ ค๊ฐ๊ณ ์๋ค. </p><h2 id="02-์ํ๊ธฐ-ํ์ฌ์-์ด์์ด๋-๊ณผ๊ฑฐ์-๋"><a href="#02-์ํ๊ธฐ-ํ์ฌ์-์ด์์ด๋-๊ณผ๊ฑฐ์-๋" class="headerlink" title="02. ์ํ๊ธฐ.. ํ์ฌ์ ์ด์์ด๋ ๊ณผ๊ฑฐ์ ๋"></a>02. ์ํ๊ธฐ.. ํ์ฌ์ ์ด์์ด๋ ๊ณผ๊ฑฐ์ ๋</h2><p>#201x #๊ณ ์์ #ํ์๋น #๋ฐ๊ฑฐ๋ฆ</p><p>์ง๊ธ์ ๋๋ฅผ ์ด๋ฃจ๊ณ ์๋ ์ฑ๊ฒฉ/์ง์/์ถ์ ๋ํ ํ๋๊ฐ ์ธ์ ๊ตฌ์ฑ๋์๋๊ฐ ๋์ด์ผ๋ณด๋, 21์ด์ ๋ด๊ฐ ๋ ์ฌ๋๋ค. ๋๋ ๋ํ์ ์
ํํ๊ณ , 21์ด๋ถํฐ ๊ณ ์์์ด ๋์๋ค. ๊ทธ๋ฆฌ๊ณ 5๋
์ ์ ๋ฆผ๋ ๊ณ ์์ด์์ ๊ณต๋ถํ๊ณ , ์ฒซ ์คํจ์ ํฌ๊ธฐ๋ผ๋ ๋จ์ด๋ฅผ ๋ง์ฃผํ๋ค. ์ฃผ๋ณ ์ง์ธ๋ค๊ณผ ๊ทธ ์์ ์ ํ์ํ๋ฉฐ ๋๋ โํ์๋น์ ๋์ ํ์ํ๋์ ์ ๋ฆผโ์ด๋ผ๋ ํํ์ ์์ฃผํ๋ค. ํ์ง๋ง ๊ทธ ๋์ ๊ฒฝํ์ ์ง๊ธ์ ๋๋ฅผ ์งํฑํ๋ ํฐ ๋ฐ๊ฑฐ๋ฆ์ด๋ค.</p><p><strong>๋์ . ์คํจ. ..๊ทธ๋ฆฌ๊ณ ๋ค์ ๋์ .</strong> </p><p>์ํ์ ๋์ ํ๊ณ , ๊ทธ๋ฆฌ๊ณ ๋์ ๊ณผ ๋์ ์ฌ์ด์๋ ๋ฐ๋์ ์คํจ๊ฐ ์กด์ฌํ๋ค. ๋น์์๋ ๋์ ์์ฒด์ ํฐ ์๋ฏธ๋ฅผ ๋์์ง๋ง, ์ง๊ธ์ ๋๋ ๊ทธ ์คํจ๋ฅผ ๋๊ณ ์ผ์ด์๋ ์์ธ์ ๋ํด ์ค์ํ๊ฒ ์๊ฐํ๋ค. ์ด๋ค ์ผ๊ณผ ๊ณํ์ด ๋ป๋๋ก ๋์ง ์์ ๋ ์ฐ๋ฆฌ๋ ์ด๋ฅผ ์คํจ๋ผ๊ณ ์ ์ ํ ์ ์๋ค. ํ์ง๋ง ์คํจ๋ ๋ค์ ์คํ๊ณผ ๊ณํ์ ์ค์ํ ๊ฒฝํ์ ์๊ฒ ํ๋ค. ์ด ๊ฐ์น๊ด์ ๊ณผ๊ฑฐ์ ๋ด๊ฐ ์ฌ๋ฌ์ฐจ๋ก์ ๋๋ฐฉ์ ๊ฒฝํํ๋ฉฐ ์ฒดํ๋ ๊ฐ์น๊ด์ด๋ค.</p><p><strong>์์ธ ์ง์. ์ปดํจํฐ, ๋ฐ์ดํฐ, ํ๋ก๊ทธ๋๋ฐ.</strong></p><p>๊ณ ์์ํ์ 5๋
ํ๋ฉด์, 5๋
๋์ 24์๊ฐ ๊ณต๋ถ๋ง ํ๊ฒ ๋๊ฐ. ์ํ๊ธฐ๊ฐ์๋ ํ์์ ๋ณด์ง๋ ์๋ ๋ด์ค๊ฐ ๊ทธ๋ ๊ฒ ์ฌ๋ฐ์์๊ฐ ์๋ค๋ ๊ฒ์ ๋ชจ๋๊ฐ ๊ณต๊ฐํ ๊ฒ์ด๋ค. ๋ ์ญ์ ํ๋ฃจ 12์๊ฐ ๊ณต๋ถ๋ฅผ ํ๊ณ ๋
น์ด๊ฐ ๋์ด ์ง์ ๋์์์ ๋ฒ์ ์ ๋ค์ ํด์ง ๋ชปํ๋ค. ๊ณ ์์ํ์ ์ ์ผํ ๋์ ๋ฐค์ ์์ ๋ณด๋ ์ดํ๊ฐ์ C์ธ์ด ์ฑ
๊ณผ C by Dissection ์ ๊ณต์ฑ
์ด์๋ค. ์ ๊ณต์๊ฐ ๋๋ ํ๋๋ ์ฌ๋ฏธ์์๋ ์ฑ
์ ์๋ฌด ์๊ฐ ์์ด(?) ์ฝ๋๋ฅผ ํ์ดํํ๋ฉด์ ๋ณด๋ด๋ ์๊ฐ์ ์ข์ํ์๋ค. ๋ค์๋ ์์นจ 6์์ ๋
์์ค์ ๋๊ฐ์ผํ๋๋ฐ, ์๋ฒฝ 3์๊น์ง ํ
ํธ๋ฆฌ์ค ๊ฒ์์ ์งค ๋๋ ์์๋ค. ๊ทธ ๋์ ๋ด์ง์ ์ง๊ธ์ ๋ฐ๊ฑฐ๋ฆ์ด ๋์๋ค.</p><table> <tr> <td> <figure> <img src="./IMG_9078.jpeg"> <figcaption>์ง๊ธ๋ ๊ฐ์งํ๊ณ ์๋ ๊ทธ ์์ ์ดํ๊ฐ์ C.<br>์์ฆ์ ํ์ง๊ฐ ๋ฐ๋์๋ค๋๋ฐ..</figcaption> </figure> </td> <td> <figure> <img src="./IMG_9079.jpeg" width=95%> <figcaption>์ง๊ธ๋ ๊ฐ์งํ๊ณ ์๋ ๊ทธ ์์ <br>C by Dissection ์ ๊ณต์ฑ
. </figcaption> </figure> </td> </tr></table> <!-- alt="๊ทธ ์์ ์ดํ๊ฐ์ C. ์์ฆ์ ํ์ง๊ฐ ๋ฐ๋์๋ค๋๋ฐ." --><!-- alt="์ง๊ธ๋ ๊ฐ์งํ๊ณ ์๋ ๊ทธ ์์ C by Dissection ์ ๊ณต์ฑ
" --><!-- ![[์ฌ์ง] ์ง๊ธ๋ ๊ฐ์งํ๊ณ ์๋ ๊ทธ ์์ C by Dissection ์ ๊ณต์ฑ
](IMG_9079.jpeg)<!-- ![[์ฌ์ง] ๊ทธ ์์ ์ดํ๊ฐ์ C. ์์ฆ์ ํ์ง๊ฐ ๋ฐ๋์๋ค๋๋ฐ.](IMG_9078.jpeg) --><h2 id="03-๋ฐ์ดํฐ์ฌ์ด์ธ์ค๋ก์-๋์ ํ๋-๋"><a href="#03-๋ฐ์ดํฐ์ฌ์ด์ธ์ค๋ก์-๋์ ํ๋-๋" class="headerlink" title="03. ๋ฐ์ดํฐ์ฌ์ด์ธ์ค๋ก์ ๋์ ํ๋ ๋"></a>03. ๋ฐ์ดํฐ์ฌ์ด์ธ์ค๋ก์ ๋์ ํ๋ ๋</h2><p>#๋ฅ๋ฌ๋ #์ํ๊ณ #๋ค์๋์ </p><p>2016๋
์ ๋ฆ์ ๋์ด๋ก ๊ตฐ์
๋๋ฅผ ํ ๋๋ ์ํ๊ณ ์ ์ด์ธ๋ ๋๊ตญ์ ๊ฒฝํํ๋ฉฐ, ๋ฅ๋ฌ๋์ด ๋ด์ค๋ฅผ ๋๋ฐฐํ๋ ์๊ธฐ๋ฅผ ๋ง์ฃผํ๋ค. ๋ฅ๋ฌ๋์ด๋ผ๋ ๋จ์ด๋ ์ด๋ฏธ์ง ํ๋ก์ธ์ฑ ์ ๊ณต ์์
๋ง์ง๋ง ์ฑํฐ์์ ์ ํ์ง๋ง, โ๋ํ์์ ์์ ๊ณต๋ถํ๋ผโ๋ ๊ต์๋์ ๋ง์๋ง ๊ธฐ์ต์ด ๋ ๋ฟ์๋ค. ์ ๊ณต์์
์์ ๋์๋ ๋จ์ด๊ฐ ๋ด์ค๋ฅผ ๋๋ฐฐํ๋, ์์ฐ์ค๋ ๊ด์ฌ์ด ๊ฐ๋ค. ์ด๋ฏธ์งํ๋ก์ธ์ฑ ๊ต๊ณผ์๋ฅผ ๋ค์ ํผ์ณ๋ณด๋ฉฐ, ๋ชจ๋ธ ์์ฃผ๋ก ๊ณต๋ถํ๋ ๋๋ ์ ์ฐจ ๋ฐ์ดํฐ ์์ ์ฃผ๊ธฐ์ ์์ผ๋ก ๊ด์ฌ์ด ๊ฐ๋ค. ์ด๋ค ๋ฐ์ดํฐ๊ฐ ์ด๋ป๊ฒ ์์ฑ๋๋ฉฐ, ์ ์ฌ๋๋ ๋ฐฉ๋ฒ๊ณผ ๊ด๋ฆฌํ๋ ์ฒด๊ณ์ ๊ด์ฌ์ด ๊ฐ๊ณ , ๋ถ์ํ๊ณ ๊ทธ ๋์ ๋ชจ๋ธ๋ง์ ํ๊ณ ์๋นํ๋ ๊ทธ ๊ณผ์ ์ ์ฒด๋ฅผ ๊ณต๋ถํ๊ธฐ ์์ํ๋ค.</p><p>์ง๊ธ๋ ์ด ๊ด์ฌ์ฌ๋ ์ฌ์ ํ๋ค. ๋ค์ํ ๊ธฐ์ ๊ณผ ์๋ก์ด ๋ฐฉ๋ฒ๋ก ์ ์ ํ ๋๋ง๋ค ๊ด์ฌ์ ๊ฐ๊ณ follow-up ํ๋ ค๋ ๋์ ๋
ธ๋ ฅ์ <strong>๊ณผ๊ฑฐ์ ๋์ ์กด์ฌ</strong>๋ค์ด ๋ง๋ค์ด์ค ์ข์ ์ต๊ด์ธ ๊ฒ ๊ฐ๋ค.</p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/%EA%B8%80%EB%98%90/">๊ธ๋</category>
<category domain="https://emjayahn.github.io/tags/%EA%B8%80%EB%98%90/">๊ธ๋</category>
<category domain="https://emjayahn.github.io/tags/%EC%A7%80%EC%9B%90%EC%84%9C/">์ง์์</category>
<category domain="https://emjayahn.github.io/tags/%ED%9A%8C%EA%B3%A0/">ํ๊ณ </category>
<comments>https://emjayahn.github.io/2023/01/14/20230114-geultto-map-of-life/#disqus_thread</comments>
</item>
<item>
<title>[MAC] xcrun: error: invalid active developer ์๋ฌ ํด๊ฒฐ๋ฐฉ๋ฒ</title>
<link>https://emjayahn.github.io/2022/12/12/20221212-mac-xcrunn-error-invalid-active-ddeveloper-error/</link>
<guid>https://emjayahn.github.io/2022/12/12/20221212-mac-xcrunn-error-invalid-active-ddeveloper-error/</guid>
<pubDate>Sun, 11 Dec 2022 16:24:43 GMT</pubDate>
<description><p>๋ฐฉ๊ธ ์ , MacOS Ventura 13.0.1๋ก ์
๊ทธ๋ ์ด๋ ํ๊ณ , flutter, python ๊ฐ๋ฐ ์ค ๋ค์ ๊ณผ ๊ฐ์ ์๋ฌ ์ฝ๋๋ฅผ ๋ด๋ฑ์ผ๋ฉฐ ์ ๋๋ ๊ฒ๋ค์ด ์๋๊ธฐ ์์ํ๋ค.<br>๊ฐ๋จํ git๋ถํฐ ์์ํด์, ๋งฅ ๋ด ํ๊ฒฝ๋ณ์๋ฅผ ํฌํจํ๋ ๋๋ถ๋ถ์ ๋ช
๋ น์ด์์ ๋ค์๊ณผ ๊ฐ์ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด๋๋ค. ๋ค์ ๊ธ์์ ๊ทธ ํด๊ฒฐ๋ฐฉ๋ฒ์ ์ ๋ฆฌํ๋ค.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>๋ฐฉ๊ธ ์ , MacOS Ventura 13.0.1๋ก ์
๊ทธ๋ ์ด๋ ํ๊ณ , flutter, python ๊ฐ๋ฐ ์ค ๋ค์ ๊ณผ ๊ฐ์ ์๋ฌ ์ฝ๋๋ฅผ ๋ด๋ฑ์ผ๋ฉฐ ์ ๋๋ ๊ฒ๋ค์ด ์๋๊ธฐ ์์ํ๋ค.<br>๊ฐ๋จํ git๋ถํฐ ์์ํด์, ๋งฅ ๋ด ํ๊ฒฝ๋ณ์๋ฅผ ํฌํจํ๋ ๋๋ถ๋ถ์ ๋ช
๋ น์ด์์ ๋ค์๊ณผ ๊ฐ์ ์๋ฌ ๋ฉ์์ง๋ฅผ ๋ณด๋๋ค. ๋ค์ ๊ธ์์ ๊ทธ ํด๊ฒฐ๋ฐฉ๋ฒ์ ์ ๋ฆฌํ๋ค.</p><span id="more"></span><h2 id="Error-Message"><a href="#Error-Message" class="headerlink" title="Error Message"></a>Error Message</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun</span><br></pre></td></tr></table></figure><p><img src="/2022/12/12/20221212-mac-xcrunn-error-invalid-active-ddeveloper-error/Untitled.png" alt="[Error Message] xcrun: error: invalid active developer"></p><p>[Error Message] xcrun: error: invalid active developer</p><p>์ด๋ฐ ํ์์ ๋งฅ OS๋ฅผ ์
๋ฐ์ดํธํ๋ฉด ์ข
์ข
๋ํ๋์์๋๋ฐ, M1์ผ๋ก ๋์ด์ค๊ณ ๋์๋ ์ฒ์ ๋ณด๋ ํ์์ด๊ธฐ์ ํด๊ฒฐ๋ฒ๋ ์ฌ์ ํ์ง ํ์ธํด๋ณด๋ฉฐ, ์ด ๊ธ์ ์ ๊ณ ์๋ค.</p><h2 id="ํด๊ฒฐ๋ฐฉ๋ฒ"><a href="#ํด๊ฒฐ๋ฐฉ๋ฒ" class="headerlink" title="ํด๊ฒฐ๋ฐฉ๋ฒ"></a>ํด๊ฒฐ๋ฐฉ๋ฒ</h2><p>๋งฅ์ ๊ฐ๋ฐ์ ๋๊ตฌ์ธ CommandLineTools๋ฅผ ์ฌ์ค์นํ์ฌ ํด๋น ์๋ฌ๋ฅผ ๊ณ ์น ์ ์๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ xcode-select --install</span><br></pre></td></tr></table></figure>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/Error-Solution/">Error&Solution</category>
<category domain="https://emjayahn.github.io/tags/error/">error</category>
<category domain="https://emjayahn.github.io/tags/solution/">solution</category>
<category domain="https://emjayahn.github.io/tags/mac/">mac</category>
<category domain="https://emjayahn.github.io/tags/xcrun/">xcrun</category>
<category domain="https://emjayahn.github.io/tags/commandlinetools/">commandlinetools</category>
<comments>https://emjayahn.github.io/2022/12/12/20221212-mac-xcrunn-error-invalid-active-ddeveloper-error/#disqus_thread</comments>
</item>
<item>
<title>[github] github token ์ค์ ๋ฐ ํค์ฒด์ธ ๋ฑ๋ก</title>
<link>https://emjayahn.github.io/2022/12/05/20221205-github-setting/</link>
<guid>https://emjayahn.github.io/2022/12/05/20221205-github-setting/</guid>
<pubDate>Mon, 05 Dec 2022 11:01:59 GMT</pubDate>
<description><p>์ต๊ทผ์ ๋งฅ๋ถ์ ์ฌ๊ณ , ์๋ก์ฐ ๋งฅ๋ถ์ ๊ฐ๋ฐํ๊ฒฝ์ ํ๋์ฉ ์
ํ
ํ๊ณ ์๋ค. ๊ทธ๋ฌ๋ฉด์ ์ค๋๋ง์ ๋ฑ๋กํ๋ github token๊ณผ ๋งค๋ฒ ๊ท์ฐฎ๊ฒ ๋น๋ฐ๋ฒํธ๋ฅผ ๊ธฐ์
ํ๋ ๊ฒ์ ๋ง๊ธฐ ์ํ ํค์ฒด์ธ ๋ฑ๋ก๊น์ง ์๋ฃํ์ฌ, ์ด ๋ถ๋ถ์ ์ ๋ฆฌํด ๊ธฐ๋กํ๋ค.</p>
<p>์ด๋ฒ ๊ธ์์ ์๊ฐํ๋ github ํ๊ฒฝ ์
ํ
์ ํฌ๊ฒ ๋ ๋จ๊ณ๋ก ๋๋๋ค.</p>
<ol>
<li>github token ๋ฐ๊ธ</li>
<li>macbook์ token ์ ์ฅ ๋ฐ git config ์์ </li>
</ol></description>
<content:encoded>< (ํค์ฒด์ธ ์ ๊ทผ)</code> ์ ๊ฒ์ํ์ฌ ๋ค์ด๊ฐ๋ค.</p><p>๊ฒ์์์ <a href="http://github.com/">github.com</a> ์ ๊ฒ์ํ๋ค.</p><p><img src="/2022/12/05/20221205-github-setting/Untitled_5.png" alt="Untitled"></p><p>๊ฒ์ ๊ฒฐ๊ณผ, ๋ฐฉ๊ธ ์์ฑํ token ์ด ๋ฑ๋ก ๋์ด ์์ผ๋ฉด ์๊ด์์ง๋ง ๋ง์ฝ ๋ฑ๋ก ๋์ด ์์ง ์๋ค๋ฉด, </p><p>์ด๋ฆ : github.com</p><p>๊ณ์ : ๋ณธ์ธ ๊นํ ์์ด๋</p><p>์ํธ : ๋ฐฉ๊ธ ์์ฑํ ํ ํฐ</p><p>์ ๋ด์ฉ์ผ๋ก ๋ฑ๋กํ๋ค.</p><h3 id="2-2-github-config-์-ํค์ฒด์ธ-๋ฑ๋ก"><a href="#2-2-github-config-์-ํค์ฒด์ธ-๋ฑ๋ก" class="headerlink" title="2-2. github config ์ ํค์ฒด์ธ ๋ฑ๋ก"></a>2-2. github config ์ ํค์ฒด์ธ ๋ฑ๋ก</h3><p>๊ธฐ๋ณธ terminal ํน์ iterm์์ github config ๋ฅผ ๋ฑ๋กํด์ค๋ค.</p><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git config --<span class="variable language_">global</span> credential.<span class="property">helper</span> oskeychain</span><br></pre></td></tr></table></figure><p>์ ๊ณผ์ ์ ํตํด, ๊นํ ๋น๋ฐ๋ฒํธ(ํ ํฐ) ๊ธฐ์
์์ด ์์ ๋กญ๊ฒ ํธ์ฌํ ์ ์๊ฒ ๋๋ค.</p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/Git/">Git</category>
<category domain="https://emjayahn.github.io/tags/git/">git</category>
<category domain="https://emjayahn.github.io/tags/development/">development</category>
<category domain="https://emjayahn.github.io/tags/%EA%B0%9C%EB%B0%9C%ED%99%98%EA%B2%BD/">๊ฐ๋ฐํ๊ฒฝ</category>
<category domain="https://emjayahn.github.io/tags/setting/">setting</category>
<comments>https://emjayahn.github.io/2022/12/05/20221205-github-setting/#disqus_thread</comments>
</item>
<item>
<title>[Linux] LightGBM GPU ๋ฒ์ ์ค์น ๋ฐ ํ๊ฒฝ์ค์ </title>
<link>https://emjayahn.github.io/2022/12/05/light-gbm-setting/</link>
<guid>https://emjayahn.github.io/2022/12/05/light-gbm-setting/</guid>
<pubDate>Sun, 04 Dec 2022 16:14:55 GMT</pubDate>
<description><p>LightGBM GPU ๋ฒ์ Install์ ๊ฒฝ์ฐ,<br>OpenCL ๊ธฐ๋ฐ์ LightGBM-GPU์ CUDA ๊ธฐ๋ฐ์ LightGBM-CUDA ๋ฒ์ ์ด ์๋ค.<br>๋ฆฌ๋
์ค ํ๊ฒฝ์์ LightGBM์ ์ค์น์ ํ๊ฒฝ์ค์ ์ ์์นซ ๊น๋ค๋ก์ธ ์ ์๋ค. ์ด๋ฒ ๊ธ์ ํตํด ์ ๋ฆฌํด๋ณด์.</p></description>
<content:encoded>< install</code> ์ ํ๋ ๊ฒฝ์ฐ, ๋ค์๊ณผ ๊ฐ์ ์๋ฌ๊ฐ ๋๋ค.</li></ul><p><img src="/2022/12/05/light-gbm-setting/Untitled.png" alt="Untitled"></p><ul><li><p>์ด๋ root์ ์๋ site-packages์ ํ์ฌ lightgbm ์ ์ค์นํ๋๋ฐ ์์ด, permission denied : ๊ถํ ์ค์ ์๋ฌ์ด๋ค.</p><ul><li>ํ์ฌ์ python์ ์ ๋ ๋ฃจํธ์์ ์์
ํ์ง ์๋ ์์น์ผ๋ก ํ๊ฒฝ์ ์ค์ ํ๊ณ , ์ด ์๋ฌ๋ ๋น์ฐํ๋ค.</li><li>๋ฐ๋ผ์ ํด๋น ๊ณ์ ํจํค์ง ๋งค๋์ ์ ์ ๊ณผ์ ์์ compile ๋ lightgbm์ ์ค์นํด ์ฃผ๋ฉด ๋๋ค.</li></ul></li><li><p>์ <code>[setup.py](http://setup.py)</code> ์คํ์ ํตํด ์ปดํ์ผ๋ ํ์ผ์ ์ด์ฉํ์ฌ, ๊ณ์ ํจํค์ง ๋งค๋์ ์ ์ค์นํด์ค๋ค.</p> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python3 -m pip install --install-option=--precompile --user .</span><br></pre></td></tr></table></figure></li></ul><h2 id="6-์ ์-์ค์น-ํ์ธ"><a href="#6-์ ์-์ค์น-ํ์ธ" class="headerlink" title="6. ์ ์ ์ค์น ํ์ธ"></a>6. ์ ์ ์ค์น ํ์ธ</h2><p><img src="/Untitled_01.png" alt="Untitled"></p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/Linux/">Linux</category>
<category domain="https://emjayahn.github.io/tags/setting/">setting</category>
<category domain="https://emjayahn.github.io/tags/linux/">linux</category>
<category domain="https://emjayahn.github.io/tags/lightgbm/">lightgbm</category>
<category domain="https://emjayahn.github.io/tags/machine-learning/">machine learning</category>
<category domain="https://emjayahn.github.io/tags/%ED%99%98%EA%B2%BD%EC%84%A4%EC%A0%95/">ํ๊ฒฝ์ค์ </category>
<comments>https://emjayahn.github.io/2022/12/05/light-gbm-setting/#disqus_thread</comments>
</item>
<item>
<title>ํ๊ท ๋ชจ๋ธ ์ฑ๋ฅํ๊ฐ์งํ : MAE, MSE, RMSE, R2 Score</title>
<link>https://emjayahn.github.io/2022/02/10/Regression-Score/</link>
<guid>https://emjayahn.github.io/2022/02/10/Regression-Score/</guid>
<pubDate>Thu, 10 Feb 2022 06:40:03 GMT</pubDate>
<description><ul>
<li>ํ๊ท๋ชจ๋ธ์ ๋ํ์ ์ธ ์ฑ๋ฅ ์งํ๋ฅผ ์์๋ณด๋ ๊ธ์
๋๋ค.</li>
<li>ํ๊ท ๋ชจ๋ธ์์๋ ์ผ๋ง๋ ์ ํํ๊ฒ ๊ทธ ๊ฐ์ ์์ธกํ๋ ์ง๊ฐ ์ค์ํฉ๋๋ค. y๊ฐ์ ํํ๋ ๋์ฐฐ๊ฐ๊ฒฉ์ฒ๋ผ ์ฐ์๋ ์ค์ํํ์ด๊ธฐ ๋๋ฌธ์, ๊ทธ ๊ฐ์ ์ ํํ๊ฒ ์์ธกํ๊ฑฐ๋ ๊ฐ์ฅ ๊ทผ์ฌ์น๋ก ์์ธกํ๋ ๊ฒ์ด ๊ฐ์ฅ ์ค์ํฉ๋๋ค. ๋ฐ๋ผ์ ํ๊ท๋ชจ๋ธ์์์ ์ฑ๋ฅํ๊ฐ ์งํ๋ ์ค์ y๊ฐ๊ณผ ์์ธกy๊ฐ์ ๋น๊ตํฉ๋๋ค.</li>
<li>๋ํ์ ์ธ ์ฑ๋ฅํ๊ฐ ์งํ์๋ ๋ค์๊ณผ ๊ฐ์ 4๊ฐ์ง ์ข
๋ฅ๊ฐ ์์ต๋๋ค.</li>
</ul>
<ol>
<li>MAE (Mean Absolute Error)</li>
<li>MSE (Mean Squared Error)</li>
<li>RMSE (Root Mean Squared Error)</li>
<li>R2 Score (Coefficient of Determination) : ๊ฒฐ์ ๊ณ์</li>
</ol></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><ul><li>ํ๊ท๋ชจ๋ธ์ ๋ํ์ ์ธ ์ฑ๋ฅ ์งํ๋ฅผ ์์๋ณด๋ ๊ธ์
๋๋ค.</li><li>ํ๊ท ๋ชจ๋ธ์์๋ ์ผ๋ง๋ ์ ํํ๊ฒ ๊ทธ ๊ฐ์ ์์ธกํ๋ ์ง๊ฐ ์ค์ํฉ๋๋ค. y๊ฐ์ ํํ๋ ๋์ฐฐ๊ฐ๊ฒฉ์ฒ๋ผ ์ฐ์๋ ์ค์ํํ์ด๊ธฐ ๋๋ฌธ์, ๊ทธ ๊ฐ์ ์ ํํ๊ฒ ์์ธกํ๊ฑฐ๋ ๊ฐ์ฅ ๊ทผ์ฌ์น๋ก ์์ธกํ๋ ๊ฒ์ด ๊ฐ์ฅ ์ค์ํฉ๋๋ค. ๋ฐ๋ผ์ ํ๊ท๋ชจ๋ธ์์์ ์ฑ๋ฅํ๊ฐ ์งํ๋ ์ค์ y๊ฐ๊ณผ ์์ธกy๊ฐ์ ๋น๊ตํฉ๋๋ค.</li><li>๋ํ์ ์ธ ์ฑ๋ฅํ๊ฐ ์งํ์๋ ๋ค์๊ณผ ๊ฐ์ 4๊ฐ์ง ์ข
๋ฅ๊ฐ ์์ต๋๋ค.</li></ul><ol><li>MAE (Mean Absolute Error)</li><li>MSE (Mean Squared Error)</li><li>RMSE (Root Mean Squared Error)</li><li>R2 Score (Coefficient of Determination) : ๊ฒฐ์ ๊ณ์</li></ol><span id="more"></span><h2 id="1-MAE-Mean-Absolute-Error"><a href="#1-MAE-Mean-Absolute-Error" class="headerlink" title="1. MAE (Mean Absolute Error)"></a>1. MAE (Mean Absolute Error)</h2><ul><li><p>MAE ๊ณ์ฐ ์์</p><ol><li>์ค์ฐจ = ์ค์ ๊ฐ - ์์ธก๊ฐ</li><li>์ ๋๊ฐ ์ค์ฐจ : |์ค์ฐจ|</li><li>๋ชจ๋ ๋ฐ์ดํฐ์ ์ค์ฐจ๋ฅผ ๊ตฌํด์ผ ํ๋ฏ๋ก ์๊ทธ๋ง๋ฅผ ์ทจํจ</li><li>์ค์ฐจ์ ์ ์ฒด ๋ถํฌ ํ์
์ ์ํด ํ๊ท ์ ์ทจํจ</li></ol></li><li><p>์ ๊ณ์ฐ ์์๋ฅผ ์์์ผ๋ก ํํํ๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.</p></li></ul><p>$$MAE = \frac { { \Sigma |y_{true}-y_{pred} | } } {n}$$</p><ul><li>MAE์ ํน์ง<ul><li>Error์ ์ ๋๊ฐ์ ์ทจํ๊ธฐ ๋๋ฌธ์, ์๋ฌ์ ํฌ๊ธฐ๊ฐ ๊ทธ๋๋ก ๋ฐ์๋จ</li><li>ํ๊ท ๊ฐ์ด๊ธฐ ๋๋ฌธ์, ๊ฐ๋ณ ๋ฐ์ดํฐ์ ์๋ฌ์ ํ๊ท ํต๊ณ๋์ ์๋ฏธ</li><li>์๋ฌ์ ๋ฐ๋ฅธ Loss ๊ฐ ์ ํ์ ์ผ๋ก ์ฌ๋ผ๊ฐ ๋ ์ ํฉ</li><li>์ด์์น๊ฐ ๋ง์ ๋ ์ฃผ๋ก ์ฌ์ฉ</li></ul></li></ul><h2 id="2-MSE-Mean-Squared-Error"><a href="#2-MSE-Mean-Squared-Error" class="headerlink" title="2. MSE (Mean Squared Error)"></a>2. MSE (Mean Squared Error)</h2><ul><li><p>MSE ์ ๊ณ์ฐ ์์</p><ol><li><p>์ค์ฐจ = ์ค์ ๊ฐ - ์์ธก๊ฐ</p></li><li><p>์ค์ฐจ์ ์ ๊ณฑ</p></li><li><p>๋ชจ๋ ๋ฐ์ดํฐ์ ์ค์ฐจ๋ฅผ ๊ตฌํด์ผํ๋ฏ๋ก ์๊ทธ๋ง๋ฅผ ์ทจํจ</p></li><li><p>์ค์ฐจ์ ์ ์ฒด ๋ถํฌ ํ์
์ ์ํด ํ๊ท ์ ์ทจํจ</p></li></ol></li><li><p>์์ ํํ</p><p> $$MSE = \frac { { \Sigma (y_{true}-y_{pred})^2 } } {n}$$</p></li><li><p>MSE ์ ํน์ง</p><ul><li>MAE ๋ Loss ์ ๋ํด ๊ทธ๋๋ก ๋ฐ์ํ๋ ๋ฐ๋ฉด, MSE ๋ ์๋ฌ์ ์ ๊ณฑ์ ํด์ฃผ๋ฏ๋ก, ํด๋น Loss ๋ฅผ ์ข๋ ๊ฐ๋ ฅํ ์ ์ฌํ๋ ํจ๊ณผ๋ฅผ ๊ฐ์ง๋๋ค.</li><li>๋ฐ๋ผ์ ์ด์์น๊ฐ ์๋ ๊ฒฝ์ฐ, ์๋ฌ๊ฐ ํฌ๊ฒ ์ธก์ ๋๋ ๊ฒฝํฅ ์ด๋ฅผ ๋ชจ๋ธ์ ํ์ฉ</li><li>๋ค๋ง ์ด ์๋ฌ์ ์ํฅ์ ํฌ๊ฒ ํ์ฌ, ๋ชจ๋ธ ์ฑ๋ฅ์ ๋์ด๋ ค๋ ๋ชฉ์ </li></ul></li></ul><h2 id="3-RMSE-Root-Mean-Squared-Error"><a href="#3-RMSE-Root-Mean-Squared-Error" class="headerlink" title="3. RMSE (Root Mean Squared Error)"></a>3. RMSE (Root Mean Squared Error)</h2><ul><li><p>RMSE ๊ณ์ฐ ์์</p><ol><li><p>์ค์ฐจ = ์ค์ ๊ฐ - ์์ธก๊ฐ</p></li><li><p>์ค์ฐจ์ ์ ๊ณฑ</p></li><li><p>๋ชจ๋ ๋ฐ์ดํฐ์ ์ค์ฐจ๋ฅผ ๊ตฌํด์ผํ๋ฏ๋ก ์๊ทธ๋ง๋ฅผ ์ทจํจ</p></li><li><p>์ค์ฐจ์ ์ ์ฒด ๋ถํฌ ํ์
์ ์ํด ํ๊ท ์ ์ทจํจ</p></li><li><p>ํ๊ท ๊ฐ์ ๋ฃจํธ</p></li></ol></li><li><p>์์ํํ</p><p> $$RMSE = \sqrt { \frac { {\Sigma (y_{true}-y_{pred})^2} } {n}}$$</p></li><li><p>RMSE ์ ํน์ง</p><ul><li>MSE ์ ๊ฐ์ ์ค์ฐจ๋ฅผ ์ ๊ณฑํด ๊ณ์ฐํ๋ ์์ผ๋ก, ๊ทธ ๊ฐ์ด ๋งค์ฐ ์ปค์ง๋ ๊ฒฝํฅ์ด ์์</li><li>์ด๋ฅผ ๋ณด์ํ๊ธฐ ์ํด, Root ๋ฅผ ์์</li><li>๋ํ ์ฑ๋ฅํ๊ฐ ์์น๊ฐ, y ์์ธก ๊ฐ๊ณผ ๊ทธ ๋จ์๊ฐ ๊ฐ์ผ๋ฏ๋ก ์ง๊ด์ ์ธ ์๋ฌ์์น</li><li>์๋ฌ์ ๋ฐ๋ฅธ Loss ๊ฐ ๊ธฐํ ๊ธ์์ ์ผ๋ก ์ฌ๋ผ๊ฐ๋ ์ํฉ์์ ์ฐ๊ธฐ ์ ํฉ</li><li>MAE ์ ํจ๊ป ๊ฐ์ฅ ์ผ๋ฐ์ ์ผ๋ก ๋ง์ด ์ฐ์ด๋ ํ๊ท๋ชจ๋ธ ์ฑ๋ฅ๋ถ์์งํ</li></ul></li></ul><h2 id="4-R2-Score-Coefficient-of-Determination-๊ฒฐ์ ๊ณ์"><a href="#4-R2-Score-Coefficient-of-Determination-๊ฒฐ์ ๊ณ์" class="headerlink" title="4. R2 Score (Coefficient of Determination : ๊ฒฐ์ ๊ณ์)"></a>4. R2 Score (Coefficient of Determination : ๊ฒฐ์ ๊ณ์)</h2><ul><li><p>R2 Score ๋ ์ค์ y์ ๋ณ๋๋ ๋๋น ๋ชจ๋ธ ์์ธก y์ ๋ณ๋๋์ ์๋ฏธ</p><ul><li>์ฆ, ์ค์ y๊ฐ์ ๋ถ์ฐ์ ๋นํด, ์์ธก y์ ๋ถ์ฐ์ด ์ผ๋งํผ์ธ์ง ๋น๊ต</li><li>ํด๋น ํ๊ท ๋ชจ๋ธ์ด ์ฃผ์ด์ง ๋ฐ์ดํฐ์ ์ผ๋ง๋ ์ ํฉํ์ง๋ฅผ ํ๊ฐํ๋ ์งํ</li><li>์๊ด๊ด๊ณ๊ฐ ๋์์๋ก 1์ ๊ฐ๊น์์ง</li><li>(ํด์ ์์) r2 score=0.4๋ผ๋ฉด, 40%์ ์ค๋ช
๋ ฅ์ ๊ฐ์ง๋ค๊ณ ํด์</li></ul></li><li><p>MAE, MSE, RMSE ๋ ์๋ฌ์ ๋ํ ์์น์ด๋ฏ๋ก, ๊ทธ ์์น๊ฐ ์์ ์๋ก ์ข์ ์งํ</p></li><li><p>R2 Score ๋ 1์ ๊ฐ๊น์ธ ์๋ก ์ฑ๋ฅ์ด ์ข์</p></li><li><p>R2 Score ๊ณ์ฐ</p><p> $$R^2 Score=1-\frac {SSE} {SST} = 1- \frac {MSE} {Var(y) }$$</p><p> $$SSE=\frac {1} {n} \Sigma (y_{true}-y_{pred})^2$$</p><p> $$SST=\frac {1} {n} \Sigma (y_{true}-y_{mean})^2$$</p></li></ul>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/DataScience/">DataScience</category>
<category domain="https://emjayahn.github.io/categories/DataScience/Regression/">Regression</category>
<comments>https://emjayahn.github.io/2022/02/10/Regression-Score/#disqus_thread</comments>
</item>
<item>
<title>[Linux] AWK ๊ฐ๋จ ์ ๋ฆฌ</title>
<link>https://emjayahn.github.io/2021/12/07/AWK-basics/</link>
<guid>https://emjayahn.github.io/2021/12/07/AWK-basics/</guid>
<pubDate>Tue, 07 Dec 2021 14:32:12 GMT</pubDate>
<description><ul>
<li>AWK ๋ ๋ฐ์ดํฐ๋ฅผ ๋ค๋ฃจ๋ ์ฌ๋๋ค์ด๋ผ๋ฉด ํ๋ฒ์ฉ์ ๊ทธ Command๋ฅผ ์ฌ์ฉํด๋ดค์ ๊ฒ์
๋๋ค.</li>
<li>์ ๋ ๊ณผ๊ฑฐ Dataframe ์ ์์ฑํด ๋ณธ๊ฒฉ์ ์ธ ๋ถ์ ๋ฐ ์ฐ๊ตฌ.๊ฐ๋ฐ ์์
์ด ๋ค์ด๊ฐ๊ธฐ ์ ์, AWK ๋ฅผ ํตํด ๊ฐ๋จํ ๋ฐ์ดํฐ ์ฒ๋ฆฌ๋ฅผ ํ๋ ๊ฒฝ์ฐ, Raw Data ํ์์ ๊ฐ๋จํ๊ฒ ์ ์ ํ์ฌ Database์ ์ ์ฌํ๋ ๊ฒฝ์ฐ์ ์ฌ์ฉํด ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ, ๋ง์ด ์ฌ์ฉํ๋ ๊ด์ฉ์ ์ธ ๊ตฌ๋ฌธ์ธ์๋ AWK ์์ฒด๋ฅผ ์ดํด๋ณผ ๊ธฐํ๊ฐ ์ ์์ต๋๋ค.</li>
<li>์ต๊ทผ ์ฌ๋ด์์ ๋ก๊ทธ ๋ฐ์ดํฐ์ ์ถ์ถ์ ์ํด AWK๋ฅผ ์ค๋๋ง์ ๋ค์ ์ฌ์ฉํ๊ฒ ๋๋ฉด์, ์์๋ AWK๋ฌธ๋ฒ์ ๋ค์ ํ ๋ฒ ์ดํด๋ณด๋ฉฐ, ์ด๋ฒ ๊ธฐํ์ AWK์ ๊ฐ๋จ ์ฌ์ฉ์์ ๋ถํฐ AWK ๋ฌธ๋ฒ ๋ช๊ฐ์ง๋ฅผ ์ ๋ฆฌํด๋ณด๊ณ ์ ํฉ๋๋ค.</li>
</ul></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><ul><li>AWK ๋ ๋ฐ์ดํฐ๋ฅผ ๋ค๋ฃจ๋ ์ฌ๋๋ค์ด๋ผ๋ฉด ํ๋ฒ์ฉ์ ๊ทธ Command๋ฅผ ์ฌ์ฉํด๋ดค์ ๊ฒ์
๋๋ค.</li><li>์ ๋ ๊ณผ๊ฑฐ Dataframe ์ ์์ฑํด ๋ณธ๊ฒฉ์ ์ธ ๋ถ์ ๋ฐ ์ฐ๊ตฌ.๊ฐ๋ฐ ์์
์ด ๋ค์ด๊ฐ๊ธฐ ์ ์, AWK ๋ฅผ ํตํด ๊ฐ๋จํ ๋ฐ์ดํฐ ์ฒ๋ฆฌ๋ฅผ ํ๋ ๊ฒฝ์ฐ, Raw Data ํ์์ ๊ฐ๋จํ๊ฒ ์ ์ ํ์ฌ Database์ ์ ์ฌํ๋ ๊ฒฝ์ฐ์ ์ฌ์ฉํด ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ, ๋ง์ด ์ฌ์ฉํ๋ ๊ด์ฉ์ ์ธ ๊ตฌ๋ฌธ์ธ์๋ AWK ์์ฒด๋ฅผ ์ดํด๋ณผ ๊ธฐํ๊ฐ ์ ์์ต๋๋ค.</li><li>์ต๊ทผ ์ฌ๋ด์์ ๋ก๊ทธ ๋ฐ์ดํฐ์ ์ถ์ถ์ ์ํด AWK๋ฅผ ์ค๋๋ง์ ๋ค์ ์ฌ์ฉํ๊ฒ ๋๋ฉด์, ์์๋ AWK๋ฌธ๋ฒ์ ๋ค์ ํ ๋ฒ ์ดํด๋ณด๋ฉฐ, ์ด๋ฒ ๊ธฐํ์ AWK์ ๊ฐ๋จ ์ฌ์ฉ์์ ๋ถํฐ AWK ๋ฌธ๋ฒ ๋ช๊ฐ์ง๋ฅผ ์ ๋ฆฌํด๋ณด๊ณ ์ ํฉ๋๋ค.</li></ul><span id="more"></span><h2 id="AWK-Aho-Weinberger-Kernighan-์คํฌ"><a href="#AWK-Aho-Weinberger-Kernighan-์คํฌ" class="headerlink" title="AWK (Aho Weinberger Kernighan ์คํฌ)"></a>AWK (Aho Weinberger Kernighan ์คํฌ)</h2><ul><li>์คํฌ๋ฆฝํธ ์ธ์ด</li><li>ํ
์คํธ ํ์ผ์ <strong>์กฐํ/ํํฐ๋ง/๊ฐ๊ณต</strong> ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ</li><li>์์คํฌ๋ฆฝํธ ์์์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ๋จํ ์ฒ๋ฆฌํ ์ ์๋ ํ์ ํ๋ก๊ทธ๋จ</li><li>๊ฐ row data๋ Enter(์ค๋ฐ๊ฟ, newline)๋ก ๊ตฌ๋ถ, column data๋ ๊ณต๋ฐฑ, tab์ผ๋ก ๊ตฌ๋ถ</li><li>๊ฐ row data, ์ค์ <strong>๋ ์ฝ๋(Record)</strong> ๋ผ ์ง์นญ</li><li>๊ฐ ๋ฐ์ดํฐ, column, ๋จ์ด ๋ฑ์ <strong>ํ๋(Field)</strong> ๋ผ ์ง์นญ</li></ul><h2 id="AWK-์-๋์๋ฐฉ์"><a href="#AWK-์-๋์๋ฐฉ์" class="headerlink" title="AWK ์ ๋์๋ฐฉ์"></a>AWK ์ ๋์๋ฐฉ์</h2><ol><li>ํ๋ ์ ์ฒด : <strong>$0</strong>, ํน์ ํ๋ ์ง์นญ : <strong>$1</strong> ~ (์ฃผ์ : 0๋ฒ์ด ์ฒซ๋ฒ์งธ๊ฐ ์๋!!)</li><li>๊ธฐ๋ณธ์ ์ธ default ๊ตฌ๋ถ์๋ **๊ณต๋ฐฑ(Space, Tab)**์ด๋, <strong>-F</strong> ์ต์
์ ์ค์ผ๋ก์จ ๊ตฌ๋ถ ๊ธฐํธ๋ฅผ ์ง์ ๊ฐ๋ฅ</li><li>AWK command ํ์ : <code>awk {pattern} {action} filename</code> <ol><li>pattern, action ๋ ์ค ํ ๊ฐ๋ง ์์ผ๋ฉด ๋จ</li></ol></li></ol><h2 id="AWK-์ฌ์ฉ์์ "><a href="#AWK-์ฌ์ฉ์์ " class="headerlink" title="AWK ์ฌ์ฉ์์ "></a>AWK ์ฌ์ฉ์์ </h2><h3 id="1-Column-data-์ถ์ถ"><a href="#1-Column-data-์ถ์ถ" class="headerlink" title="1. Column data ์ถ์ถ"></a>1. Column data ์ถ์ถ</h3><ul><li>๊ฐ Column ์ $1 ์ ๊ฐ์ ํํ๋ก ํ๋์ ์ ๊ทผํ์ฌ ์ถ์ถ ํ ์ ์์ต๋๋ค.</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># awk {action} filename ํ์</span></span><br><span class="line">awk <span class="string">'{print $1}'</span> ./file_you_want.log</span><br><span class="line"></span><br><span class="line"><span class="comment"># $0 ์ ์ฒด column ์ถ์ถ</span></span><br><span class="line">awk <span class="string">'{print $0}'</span> ./file_you_want.log</span><br></pre></td></tr></table></figure><h3 id="2-ํน์ -Pattern-์ ๊ทํํ์"><a href="#2-ํน์ -Pattern-์ ๊ทํํ์" class="headerlink" title="2. ํน์ Pattern : ์ ๊ทํํ์"></a>2. ํน์ Pattern : ์ ๊ทํํ์</h3><ul><li>๋ฌธ์์ด ์ค์ <code>ADID</code> ๋ผ๋ ๊ธ์จ๊ฐ ํฌํจ๋ ๋ ์ฝ๋๋ฅผ ์ถ๋ ฅํด์ฃผ๋ ์ปค๋งจ๋์
๋๋ค.</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">awk <span class="string">'/ADID/'</span> ./platform.log </span><br></pre></td></tr></table></figure><p>โ ์ถ๋ ฅ ์์ : 20211207 ADID1234556 123$456 device3 window</p><ul><li>AWK pattern์๋ ์ ๊ทํํ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.<ul><li>pattern๋ด์ ์ ๊ทํํ์ ๊ตฌ๋ถ์ <code>/regular expression/</code> (์ฌ๋์ฌ)๋ก ์ด๋ฃจ์ด์ง๋๋ค.</li></ul></li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ awk <span class="string">'/[A-Z][a-z]+/'</span> ./system.log</span><br></pre></td></tr></table></figure><h3 id="3-AWK-Command-if๊ตฌ๋ฌธ"><a href="#3-AWK-Command-if๊ตฌ๋ฌธ" class="headerlink" title="3. AWK Command : if๊ตฌ๋ฌธ"></a>3. AWK Command : if๊ตฌ๋ฌธ</h3><ul><li>ํน์ ์กฐ๊ฑด์ ๋ง๋ ๊ตฌ๋ฌธ์ ๋ฝ์ ๋, ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ ์ ์์ต๋๋ค.</li><li>๋ค์์ 3๋ฒ ํ๋์ ๊ฐ์ด 1๊ณผ ๊ฐ์ ๋ ์ ์ฒด ๋ ์ฝ๋๋ฅผ ๋ฝ๋ ์ปค๋งจ๋ ์
๋๋ค.</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">awk <span class="string">'{if ($3 == 1) print ($0)}'</span> ./system.log</span><br></pre></td></tr></table></figure><p>โ ์ถ๋ ฅ ์์ : </p><p>20211207 ADID123456 1 device3 window</p><p>20211207 ADID123654 1 device2 android</p><p>20211207 ADID654321 1 device1 ios</p><ul><li>๋ค์์ 1๋ฒ ํ๋๊ฐ 20211206๊ณผ ๊ฐ๊ณ 3๋ฒ ํ๋๊ฐ 2์ด์์ธ ์ ์ฒด ๋ ์ฝ๋๋ฅผ ๋ฝ๋ ์ปค๋งจ๋์
๋๋ค.<ul><li>์ด์ฒ๋ผ, if ๊ตฌ๋ฌธ ์์ ๋ค์ํ ์กฐ๊ฑด๋ค๊ณผ <code>&&</code>(and) <code>||</code>(or), <code>!</code>(not) ์ ํ์ฉํ ์ ์์ต๋๋ค.</li></ul></li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">awk <span class="string">'{if ($1 == 20211206 && $3 >= 2) print($0)}'</span> ./system.log</span><br></pre></td></tr></table></figure><p>โ ์ถ๋ ฅ ์์ :</p><p>20211206 ADID123456 2 device2 window</p><p>20211206 ADID654321 3 device3 ios</p><p>20211206 ADID432561 4 device2 android</p><ul><li><code>?</code> , <code>:</code> ์ ๊ธฐ๋ฅ : if-else ๊ตฌ๋ฌธ<ul><li>if ๊ตฌ๋ฌธ โ $1 else $2 ๋ผ๋ ๋ป์
๋๋ค.</li></ul></li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ awk <span class="string">'{์กฐ๊ฑด ? $1 : $2}'</span> ./system.log</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="4-AWK-Command-for-๊ตฌ๋ฌธ"><a href="#4-AWK-Command-for-๊ตฌ๋ฌธ" class="headerlink" title="4. AWK Command : for ๊ตฌ๋ฌธ"></a>4. AWK Command : for ๊ตฌ๋ฌธ</h3><ul><li>AWK ๊ตฌ๋ฌธ์์๋ ํ์์ ๋ค์๊ณผ ๊ฐ์ด for๋ฌธ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">awk <span class="string">'{</span></span><br><span class="line"><span class="string">for (i=0;i<2;i++)</span></span><br><span class="line"><span class="string">print()</span></span><br><span class="line"><span class="string">}'</span></span><br></pre></td></tr></table></figure><h3 id="5-AWK-BEGIN-END"><a href="#5-AWK-BEGIN-END" class="headerlink" title="5. AWK BEGIN, END"></a>5. AWK BEGIN, END</h3><ul><li>BEGIN๊ณผ END๋ AWK ๊ตฌ๋ฌธ์ด ์์๋๊ธฐ ์ , ๋ง์น ํ์ ์ํ๋๋ ์ปค๋งจ๋์
๋๋ค.</li><li>๋ค์ ์ปค๋งจ๋๋ <code>{count++}</code> ๊ฐ ์ํ๋๊ธฐ ์ ๊ณผ ํ์ Start, End ๋ฅผ ์๋ฆฌ๊ณ , Count ๋ฅผ ์ธ๋ ์ปค๋งจ๋ ์
๋๋ค.</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">awk <span class="string">'</span></span><br><span class="line"><span class="string">BEGIN {</span></span><br><span class="line"><span class="string">print("Begin Processing...")</span></span><br><span class="line"><span class="string">count = 0</span></span><br><span class="line"><span class="string">}</span></span><br><span class="line"><span class="string">{</span></span><br><span class="line"><span class="string">count++</span></span><br><span class="line"><span class="string">}</span></span><br><span class="line"><span class="string">END {</span></span><br><span class="line"><span class="string">print("COUNT: " count)</span></span><br><span class="line"><span class="string">print("End Processing")</span></span><br><span class="line"><span class="string">}'</span> ./system.log</span><br><span class="line"><span class="string">'</span></span><br></pre></td></tr></table></figure><h2 id="AWK-์ ์-๋ณ์"><a href="#AWK-์ ์-๋ณ์" class="headerlink" title="AWK ์ ์ ๋ณ์"></a>AWK ์ ์ ๋ณ์</h2><ul><li>AWK ์์๋ ์ฌ์ฉ์์ ํธ์๋ฅผ ์ํด ์์ฒด์ ์ผ๋ก ์ ์๋ ๋ณ์๊ฐ ๋ช๊ฐ์ง ์์ต๋๋ค. ๋ฏธ๋ฆฌ ์ ์๋ ๋ณ์๋ฅผ AWK command ์์์ ๋ค์ํ๊ฒ ํ์ฉํ ์ ์์ต๋๋ค. ๋ค์์ AWK์์ ์ ์๋ ๋ณ์๋ค์ค ๋ง์ด ์ฌ์ฉ๋๋ ๋ช๊ฐ์ง๋ฅผ ์ถ๋ ค๋ณด์์ต๋๋ค.</li></ul><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"> ARGV : command line argument ๋ฐฐ์ด</span><br><span class="line">ARGC : ARGV ๋ฐฐ์ด ์์์ ๊ฐฏ์</span><br><span class="line"> CONVFMT : ํฌ๋งทํ
ํ์ (example: ์ซ์ ํฌ๋งทํ
ํ์)</span><br><span class="line"> ENVIRON : ํ๊ฒฝ๋ณ์ ๋ฐฐ์ด</span><br><span class="line"> FILENAME : ํ์ผ ์ด๋ฆ (๊ฒฝ๋กํฌํจ)</span><br><span class="line"> FS : ํ๋ ๊ตฌ๋ถ์ (default: space)</span><br><span class="line"> NF : ํ๋์ ๊ฐฏ์</span><br><span class="line"> NR : ํ์ฌ ๋ ์ฝ๋์ ์์</span><br><span class="line"> OFMT : ๋ฌธ์์ด ์ถ๋ ฅ ํ์</span><br><span class="line"> OFS : ํ๋ ๊ตฌ๋ถ์ (default: space)</span><br><span class="line"> ORS : ๋ ์ฝ๋ ๊ตฌ๋ถ์ (default: newline)</span><br><span class="line"> RLENGTH : match ํจ์์ ์ํด ๋งค์นญ๋ ๋ฌธ์์ด์ ๊ธธ์ด</span><br><span class="line"> RS : ๋ ์ฝ๋ ๊ตฌ๋ถ ๋ฌธ์ (default: newline)</span><br></pre></td></tr></table></figure><h2 id="์ํ์ดํ-์์์์-AWK"><a href="#์ํ์ดํ-์์์์-AWK" class="headerlink" title="์ํ์ดํ ์์์์ AWK"></a>์ํ์ดํ ์์์์ AWK</h2><ul><li>์์ ์ฌ์ฉ์์ ๋ค์ฒ๋ผ Linux CLI ํ๊ฒฝ์์ AWK command์ ๊ฐ๋ ฅํจ์ ํ์ธ ํ ์ ์์์ต๋๋ค. ์ด ์ธ์๋ ์์คํฌ๋ฆฝํธ, ์ํ์ดํ ์์์ AWK ๋ฅผ ํ์ฉํ๊ณ , argument ๋ฅผ ์ ๋ฌํ๋์ง๋ ๋ค์์ ์์ ์์ ํ์ธ ํ ์ ์์ต๋๋ค.</li><li>AWK command ์์ argument๋ฅผ ๋๊ฒจ ์ค ๋๋ <strong>-v</strong> ์ต์
์ ์ฌ์ฉํ์ฌ ๋๊ฒจ ์ค ์ ์์ต๋๋ค.</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">test_variable=<span class="string">"hello"</span></span><br><span class="line">$ <span class="built_in">echo</span> | awk -v output=<span class="variable">$test_variable</span> <span class="string">'{ print "TEST VARIABLE : " output}'</span></span><br><span class="line">TEST VARIABLE : hello</span><br></pre></td></tr></table></figure><p><img src="/2021/12/07/AWK-basics/Untitled.png" alt="Untitled"></p><ul><li>AWK command ๋ฅผ ์์ธํ๊ฒ ์๊ณ ์ถ๋ค๋ฉด, ๊ทธ ๋์ ์๋ฆฌ์ ๊ตฌ์กฐ ๋ํ ์ดํด๋ณผ๊ฒ ๋ง์ด ์์ต๋๋ค. ๊ฐ์์ ํ์ฉ ์ ๋์ ๋ฐ๋ผ ๋์ฑ ํ์ํ ์์๋ฅผ ์๋ reference ๋ฑ์ ์๋ฃ๋ฅผ ํตํด ๊ณต๋ถํ ์ ์์ ๊ฒ์
๋๋ค.</li><li>์ด๋ฒ ๊ธฐํ๋ฅผ ํตํด ์งง๊ฒ๋๋ง AWK ๋ฅผ ์ ๋ฆฌ ํ ์ ์์๊ณ , ํ์ฉ snippet code ๋ฅผ ๋จ๊น์ผ๋ก์จ ๋ค์ ์ฌ์ฌ์ฉ์ ๋น ๋ฅด๊ฒ ํ์ฉํ ์ ์์ ๊ฒ์ผ๋ก ๊ธฐ๋๋ฉ๋๋ค.</li></ul><h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><ul><li>AWK ๋ด์ ์ ์๋ ํจ์์ ๋ณ์ ๋ฑ์ ์์ธํ ์๊ณ ์ถ๋ค๋ฉด, ๋ค์ documentation ์ ์ฐธ์กฐํ์ค ์ ์์ต๋๋ค.</li></ul><p><a href="https://www.gnu.org/software/gawk/manual/gawk.html">The GNU Awk Userโs Guide</a></p><p><a href="https://recipes4dev.tistory.com/171">๋ฆฌ๋
์ค awk ๋ช
๋ น์ด ์ฌ์ฉ๋ฒ. (Linux awk command) - ๋ฆฌ๋
์ค ํ์ผ ํ
์คํธ ๋ฐ์ดํฐ ๊ฒ์ฌ, ์กฐ์, ์ถ๋ ฅ.</a></p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/Linux/">Linux</category>
<category domain="https://emjayahn.github.io/tags/linux/">linux</category>
<category domain="https://emjayahn.github.io/tags/awk/">awk</category>
<comments>https://emjayahn.github.io/2021/12/07/AWK-basics/#disqus_thread</comments>
</item>
<item>
<title>Docker, ๊น๋ํ๊ณ ๋น ๋ฅธ ๋ถ์.์ฐ๊ตฌ.๊ฐ๋ฐ ํ๊ฒฝ ์ธํ
</title>
<link>https://emjayahn.github.io/2021/11/28/Docker/</link>
<guid>https://emjayahn.github.io/2021/11/28/Docker/</guid>
<pubDate>Sat, 27 Nov 2021 15:34:44 GMT</pubDate>
<description><h3 id="๋ถ์ -๋ฐ์ดํฐ์ฌ์ด์ธํฐ์คํธ์-๋์ปค-์ฌ์ฉ๊ธฐ"><a href="#๋ถ์ -๋ฐ์ดํฐ์ฌ์ด์ธํฐ์คํธ์-๋์ปค-์ฌ์ฉ๊ธฐ" class="headerlink" title="๋ถ์ : ๋ฐ์ดํฐ์ฌ์ด์ธํฐ์คํธ์ ๋์ปค ์ฌ์ฉ๊ธฐ"></a>๋ถ์ : ๋ฐ์ดํฐ์ฌ์ด์ธํฐ์คํธ์ ๋์ปค ์ฌ์ฉ๊ธฐ</h3><p><img src="/2021/11/28/Docker/docker-logo.png" alt="docker-logo.png"></p>
<ul>
<li>์ด๋ฒ ๊ธ์์๋ ์ ๋ฅผ ํฌํจํ์ฌ, ๋์ปค๋ฅผ ์ฒ์ ์ ํ๋ ์ฌ๋๋ค์ ์ํด ๋์ปค(Docker)์ ๋์ปค ์ด๋ฏธ์ง, ๋์ปค ์ปจํ
์ด๋์ ๊ฐ๋
์ ๋ํด ์ดํด๋ด
๋๋ค.</li>
<li>๊ฐ๋จํ ๋์ปคํ์ผ ์์ฑ ์์ ๋ฅผ ํตํด, ์์ ์๊ฒ ๋ง๋ ํ๊ฒฝ ์ธํ
์ ๋ฐ๋ผ ํด ๋ณผ ์ ์์ต๋๋ค.</description>
<content:encoded><"></p><p>์ด๋ฏธ์ง ์ถ์ฒ: <a href="https://kimck.tistory.com/entry/Docker-File-Docker-Image%EB%A5%BC-%EB%A7%8C%EB%93%A4%EA%B8%B0-%EC%9C%84%ED%95%9C-%EB%AA%85%EC%84%B8%EC%84%9C">https://kimck.tistory.com/entry/Docker-File-Docker-Image๋ฅผ-๋ง๋ค๊ธฐ-์ํ-๋ช
์ธ์</a></p><p>๋์ปค ์ด๋ฏธ์ง๋ <strong>๋์ปค ์ปจํ
์ด๋์ ์ค๊ณ๋</strong>์
๋๋ค. ๋์ปค ์ด๋ฏธ์ง๋ฅผ ํตํด ์ปจํ
์ด๋ ๋ด๋ถ์ ์ด๋ค ํ๊ฒฝ์ ํฌํจํ์ฌ ํจํค์ง ํ ๊ฒ์ธ์ง ๊ณํ์ ์ธ์๋๋ค. ๋์ปค ์ด๋ฏธ์ง ์์ฑ ๋ฐฉ๋ฒ์ (1) <a href="https://hub.docker.com/">DockerHub</a> ๋ฅผ ํ์ฉํด Github์ฒ๋ผ ๊ณต๊ฐ๋ ์ด๋ฏธ์ง ์์ค๋ฅผ ํ์ฉํ๋ ๋ฐฉ๋ฒ์ด ์๊ณ , (2) Dockerfile ์ ํตํด ๋์ปค ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋ค์ ์์ ์์ ๊ฐ๋จํ Dockerfile ์์ฑ์ ํตํด ์ด๋ฏธ์ง๋ฅผ ๋ง๋ค๊ณ Python๊ณผ jupyter ํ๊ฒฝ์ ์ปจํ
์ด๋ํ ํด๋ณด๊ฒ ์ต๋๋ค.</p><h2 id="4-์ผ๋จ-๋ง๋ค์ด๋ณด์"><a href="#4-์ผ๋จ-๋ง๋ค์ด๋ณด์" class="headerlink" title="4. ์ผ๋จ ๋ง๋ค์ด๋ณด์!"></a>4. ์ผ๋จ ๋ง๋ค์ด๋ณด์!</h2><p>๋์ปค๋ฅผ ์ค์นํ๋ ์์ธํ ๋ฐฉ๋ฒ์ ์ด ๊ธ์์๋ ์๋ตํ๋๋ก ํ๊ฒ ์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ์ฝ๊ฒ ์ค์น ํ ์ ์์ผ๋, ์์ ์ ํ๊ฒฝ์ ๋ง๊ฒ ์ค์นํ์๊ณ ๋ค์์ ์งํํด์ฃผ์ธ์!</p><p><code>Linux</code> : yum, apt ๋ฑ OS ์ ๋ง๋ ๋ฐฉ๋ฒ์ผ๋ก ์ค์นํด์ฃผ์ธ์.</p><p><code>Mac</code> : Intel chip๊ณผ Apple M1 chip ์ ๋ฐ๋ผ ๊ฐ๊ฐ ์ค์นํด์ฃผ์ธ์.</p><p><code>Window</code> : Docker Desktop for Windows ๋ฅผ ์ค์นํด์ฃผ์ธ์ (Window os ์ข
๋ฅ์ ๋ง๊ฒ WSL, Hyper-V ๊ธฐ๋ฐ์ ๋ง๋ docker ์ค์น๋ฅผ ์งํํด ์ฃผ์ธ์)</p><p>๋ณธ ์ค์ต ์์ ์ ๊ฒฐ๊ณผ๋ฌผ์ Docker ํ๊ฒฝ์์ (1) Python3.7 , (2) Jupyter Notebook , (3) Numpy, Pandas ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น (4) ํธ์คํธ ํ์ผ์์คํ
๊ณผ ๋์ปค ํ์ผ์์คํ
์ ์ฐ๊ฒฐ ์ค์ ๊น์ง ์ด๋ฃจ์ด์ง๊ฒ ์ต๋๋ค.</p><h3 id="4-1-๋์ปค-์คํ"><a href="#4-1-๋์ปค-์คํ" class="headerlink" title="4.1 ๋์ปค ์คํ"></a>4.1 ๋์ปค ์คํ</h3><ul><li>๋์ปค๊ฐ ์ ์์ ์ผ๋ก ์ค์น ๋์์ผ๋ฉด, ๋์ปค์ ์คํ ์ฌ๋ถ๋ฅผ ํ์ธํ๊ณ ๋์ปค๋ฅผ ์ผ๊ณ ๋๋ ๋ฐฉ๋ฒ์ ์์๋ด
๋๋ค.</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ๋์ปค ์คํ ์ฌ๋ถ ํ์ธ</span></span><br><span class="line">$ systemctl status docker</span><br><span class="line"></span><br><span class="line"><span class="comment"># ๋์ปค ์คํ</span></span><br><span class="line">$ sudo systemctl start docker</span><br><span class="line"></span><br><span class="line"><span class="comment"># ๋์ปค ์ข
๋ฃ</span></span><br><span class="line">$ sudo systemctl stop docker</span><br></pre></td></tr></table></figure><h3 id="4-2-Dockerfile-์์ฑ"><a href="#4-2-Dockerfile-์์ฑ" class="headerlink" title="4.2 Dockerfile ์์ฑ"></a>4.2 Dockerfile ์์ฑ</h3><p>๋จผ์ , ๋ค์๊ณผ ๊ฐ์ด ์์ฑํ๊ณ ํ์ฌ ์ค์ต ๋๋ ํ ๋ฆฌ์ <code>Dockerfile</code> ๋ก ์ ์ฅํด ์ค๋๋ค.</p><figure class="highlight docker"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Dockerfile</span></span><br><span class="line"><span class="keyword">FROM</span> python:<span class="number">3.7</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> pip install --upgrade pip</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> pip install jupyter</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> pip install numpy</span></span><br><span class="line"><span class="keyword">RUN</span><span class="language-bash"> pip install pandas</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">EXPOSE</span> <span class="number">8888</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">CMD</span><span class="language-bash"> <span class="built_in">tail</span> -f /dev/null</span></span><br></pre></td></tr></table></figure><ul><li><code>FROM</code> : <a href="https://hub.docker.com/">DockerHub</a> ์ ๊ณต๊ฐ๋์ด ์๋ ์คํ ์ด๋ฏธ์ง๋ฅผ ์ฐ๋ฆฌ ์ด๋ฏธ์ง์ base ๋ก ํ๋ ์๋ฏธ์
๋๋ค. python3.7 ๋ฒ์ ์ ์คํ ์ด๋ฏธ์ง๋ฅผ ๋ฐํ์ผ๋ก ์ฐ๋ฆฌ ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ ๊ฒ์
๋๋ค.</li><li><code>RUN</code> : ๋์ปค ์ด๋ฏธ์ง๊ฐ ๋น๋๋๊ณ , ์ํ๋๋ ๋ช
๋ น์ ์
๋๋ค. Python ๊ธฐ๋ฐ์ ๋ถ์, ๊ฐ๋ฐํ๊ฒฝ ์ธํ
์ ์ํ๋ ๊ฒ์ธ ๋งํผ pip๋ฅผ ํ์ฉํด ํด๋น ํจํค์ง๋ฅผ ์ค์นํด ์ค๋๋ค.</li><li><code>EXPOSE</code> : ์ฐ๋ฆฌ๋ jupyter ํ๊ฒฝ์ ์ค์นํ ์์ ์ด๋ฏ๋ก, jupyter ๊ฐ ์ฌ์ฉํ๋ 8888 ๋ฒ ํฌํธ๋ฅผ ๊ฐ๋ฐฉํด์ค๋๋ค.</li><li><code>CMD</code> : ์ปจํ
์ด๋ ๋ด๋ถ shell์์ ์ํ๋๋ ์ปค๋งจ๋์
๋๋ค. ๋ฐฐํฌ ๋ฐ ์ด์ฉ์ ์ํ ์ปจํ
์ด๋๋ผ๋ฉด CMD python3 ~~~.py ๋ฅผ ํด์ฃผ๊ฒ ์ฃ . ๋ค๋ง, ์ฐ๋ฆฌ๋ ์ปจํ
์ด๋๋ฅผ ๊ณ์ ์คํ๋ ์ํ์์ ๋ถ์ ๋ฐ ๊ฐ๋ฐ์ ์ํ ํ๊ฒฝ์ด๊ธฐ ๋๋ฌธ์ ์ปจํ
์ด๋ ๋์ ์ดํ ์ข
๋ฃ ๋์ง ์์์ผ ํฉ๋๋ค. ๋ฐ๋ผ์ /dev/null page ๋ฅผ ๊ณ์ ์ฝ์ด๋๋ฆฌ๋ ๋ช
๋ น์ ํตํด ํ๊ฒฝ ์ ์ง๋ฅผ ํ ์ ์์ต๋๋ค.</li></ul><h3 id="4-3-Docker-image-๋น๋"><a href="#4-3-Docker-image-๋น๋" class="headerlink" title="4.3 Docker image ๋น๋"></a>4.3 Docker image ๋น๋</h3><p>์์์ ์์ฑํ Dockerfile์ ๋ฐํ์ผ๋ก ์๋ ๋ช
๋ น์ด๋ฅผ ํตํด ๋์ปค ์ด๋ฏธ์ง๋ฅผ ๋น๋ํด ์ค๋๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># $ docker image builld -t ์ด๋ฏธ์ง๋ช
:ํ๊ทธ๋ช
Dockerfile๊ฒฝ๋ก</span></span><br><span class="line">$ docker image build -t python-jupyter:stable .</span><br></pre></td></tr></table></figure><ul><li><code>-t</code> : ์์ฑ๋ ์ด๋ฏธ์ง์ ํ๊ทธ๋ฅผ ๋ถ์ฌ์ค๋๋ค. ํ๊ทธ๋ฅผ ์๋ตํ๊ฒ ๋๋ฉด, :latest ๊ฐ default ๋ก ๋ถ์ต๋๋ค.</li><li>Dockerfile ๊ฒฝ๋ก : docker image build ๋ช
๋ น์ default ๋ก ํ์ฌ ๋๋ ํ ๋ฆฌ์ Dockerfile ์ ์ฐพ์ต๋๋ค. ํ์ผ ๋๋ ํ ๋ฆฌ์ ํ์ผ๋ช
์ด ๋ค๋ฅธ ๋์ปคํ์ผ์ ์ง์ ํ๊ณ ์ถ๋ค๋ฉด, <code>-f</code> ์ ํตํด ๊ฒฝ๋ก/ํ์ผ๋ช
์ ๋ค๋ฅด๊ฒ ์ค์ ํ ์ ์์ต๋๋ค.</li></ul><h3 id="4-4-Docker-container-์คํ"><a href="#4-4-Docker-container-์คํ" class="headerlink" title="4.4 Docker container ์คํ"></a>4.4 Docker container ์คํ</h3><p>Docker image ๋ฅผ ๋ฐํ์ผ๋ก ๋์ปค ์ปจํ
์ด๋๋ฅผ ์คํํด ์ค๋๋ค. ๋์ปค ์ปจํ
์ด๋ ์คํ์ ์ฃผ์ํ ์ ์ด ๋ช๊ฐ์ง ์์ต๋๋ค. ๋จผ์ ๋์ปค๋ ์์ ์ ์ธ ๋ฐฐํฌ์ ์ด์์ ์ํด ํ๋ฒ ์คํ๋ ์ปจํ
์ด๋์ ์ค์ ๊ณผ ํ๊ฒฝ์ ๋ณ๊ฒฝํ๊ธฐ ์ฝ์ง ์์ต๋๋ค. ์๋, ์ค์ ๊ณผ ํ๊ฒฝ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. (์๋ํ์ง ๋ง์ธ์. ์ ์ฒ๋ผ ๋๋ฌด๋ ๊ณ ์ํ๊ฒ ๋ฉ๋๋ค.) ๋ฐ๋ผ์ ์ปจํ
์ด๋๋ฅผ ์คํ ํ ๋, ๊ณ ๋ คํ๋ ์์๋ฅผ ๋ชจ๋ ํฌํจํ์ฌ ์คํ์์ผ์ฃผ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># $ docker run (๊ฐ ์ข
์ต์
) DockerImage๋ช
</span></span><br><span class="line">$ docker run -d --name python-jupyter-stable -p 8888:8888 -v \</span><br><span class="line">/home/user-name/workspace:/home/user-name/workspace python-jupyter:stable </span><br></pre></td></tr></table></figure><ul><li><code>-d</code> : Docker container ์คํ์ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํํ๋ ์ต์
์
๋๋ค. ๋์ปค๋ ์์ ์ ์ธ ์ด์์ ์ํด foreground ์คํ์ ํ๊ฒ ๋๋ฉด ์ปค๋งจ๋lock ์ด ๊ฑธ๋ฆฌ๊ฒ ๋ฉ๋๋ค.</li><li><code>โ-name</code> : ์คํ๋๋ ์ปจํ
์ด๋์ ์ด๋ฆ ์ค์ </li><li><code>-p</code> : ํธ์คํธ ์๋ฒ์ ํฌํธ์ ์ปจํ
์ด๋ ํฌํธ ์ฐ๊ฒฐ. ์ฐ๋ฆฌ๋ jupyter notebook ์ด ์ฌ์ฉํ 8888๋ฒ ํฌํธ๋ฅผ ์๋ก ์ฐ๊ฒฐํด ์ค๋๋ค.</li><li><code>-v</code> : ์ด ์ต์
์ ํตํด ์ปจํ
์ด๋ ๋ด๋ถ์์ ์ ์ฅ๋๋ ํ์ผ์์คํ
๊ณผ ํธ์คํธ ์๋ฒ์ ํ์ผ์์คํ
์ ์ฐ๊ฒฐํด ์ค๋๋ค. ํธ์คํธ ํ์ผ์์คํ
์ ์ปจํ
์ด๋์ ๋ง์ดํธ ์ํจ๋ค๋ ๊ฐ๋
์ผ๋ก ์๊ฐํฉ๋๋ค. <code>ํธ์คํธ์๋ฒํ์ผ์์คํ
:์ปจํ
์ด๋๋ด๋ถํ์ผ์์คํ
</code></li><li>python-jupyter:stable : ์์์ ์์ฑํ ์ด๋ฏธ์ง๋ช
:ํ๊ทธ</li></ul><h3 id="4-5-Docker-container-shell-์ ์"><a href="#4-5-Docker-container-shell-์ ์" class="headerlink" title="4.5 Docker container shell ์ ์"></a>4.5 Docker container shell ์ ์</h3><p>Docker container ๊ฐ ์ ์์ ์ผ๋ก ๋ง๋ค์ด์ก๋ค๋ฉด, container ๋ด๋ถ๋ก ๋ค์ด๊ฐ jupyter notebook ์ ์คํํด ์ฃผ์ด์ผ ํฉ๋๋ค. container ๋ด๋ถ shell ์ ์ ์ํ๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ docker <span class="built_in">exec</span> -it python-jupyter-stable bash</span><br></pre></td></tr></table></figure><p>์ ์ปค๋งจ๋๋ฅผ ์ด์ฉํด ์ปจํ
์ด๋ ๋ด๋ถ์ ์ ์ํด, jupyter notebook ์ ์คํํด๋ถ๋ฉด ๋ฉ๋๋ค.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ jupyter notebook --allow-root & <span class="comment">#background์์ jupyter notebook ์คํ</span></span><br></pre></td></tr></table></figure><h3 id="5-๋ง์น๋ฉฐ"><a href="#5-๋ง์น๋ฉฐ" class="headerlink" title="5. ๋ง์น๋ฉฐ"></a>5. ๋ง์น๋ฉฐ</h3><p>๊ฐ๋จํ ์ค์ต ์์ ๋ฅผ ํตํด ๋ค์ํ OS ํ๊ฒฝ์์๋ ๋์ผํ ๋ถ์ ๋ฐ ๊ฐ๋ฐ ํ๊ฒฝ ์ธํ
์ ๋ํด ์์๋ณด์์ต๋๋ค. ์์์ ์์ฑํ Dockerfile ๋ง ์๋ค๋ฉด, ์ ๊ฐ ์ด๋ ํ๊ฒฝ์์ ์์
ํ๋๋ผ๋ docker image build, docker run ์ ํตํด ์์ ์ ์ธ ๋ถ์๊ณผ ์ฐ๊ตฌ ๊ฐ๋ฐ์ ์งํ ํ ์ ์์ต๋๋ค. ๋ณธ ๊ธ์ ํตํด, ๋์ปค์ ํ์์ฑ๊ณผ ๋์ปค์ ๊ฐ๋
์ ์ดํดํ๊ณ , ๋์ปค๋ฅผ ์ฒ์ ์ ํ๋ ๋ถ๋ค์๊ฒ ๋ณธ๊ฒฉ์ ์ธ ๋์ปค์ ์๊ฐ๊ฐ ๋์์ผ๋ฉด ํ๋ ๋ฐ๋จ์
๋๋ค. ์ ์ญ์, ์์ผ๋ก ๋์ปค๋ฅผ ์ด์ฉํด ๋์ฑ Agileํ๊ณ ๊ณ ๊ธ ํ๊ฒฝ๊ตฌ์ถ์ ์๋ํด ๋ณผ ๊ฒ์ด๋ฉฐ, ์๋กญ๊ฒ ์๊ฒ ๋๋ ๋ด์ฉ๋ค์ ์๊ธฐ์ฝ๊ฒ ์ ๋ฆฌํ์ฌ ๋ณธ ๋ธ๋ก๊ทธ์ PAP ์ปค๋ฎค๋ํฐ๋ฅผ ํตํด ์๊ฐํด๋๋ฆด ์์ ์
๋๋ค.</p>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/Docker/">Docker</category>
<category domain="https://emjayahn.github.io/tags/Docker/">Docker</category>
<category domain="https://emjayahn.github.io/tags/%EB%8F%84%EC%BB%A4/">๋์ปค</category>
<comments>https://emjayahn.github.io/2021/11/28/Docker/#disqus_thread</comments>
</item>
<item>
<title>[C++] 2.์ฐ์ฐ์(Operators)</title>
<link>https://emjayahn.github.io/2021/10/14/C-%E1%84%8B%E1%85%A7%E1%86%AB%E1%84%89%E1%85%A1%E1%86%AB%E1%84%8C%E1%85%A1-Operators/</link>
<guid>https://emjayahn.github.io/2021/10/14/C-%E1%84%8B%E1%85%A7%E1%86%AB%E1%84%89%E1%85%A1%E1%86%AB%E1%84%8C%E1%85%A1-Operators/</guid>
<pubDate>Thu, 14 Oct 2021 09:51:33 GMT</pubDate>
<description><p>C์ C++์ด ํ์ํด, ์ ๋จธ๋ฆฟ์ ๋ฉ๋ชจ๋ฆฌ์ Recall ์ด ํ์ํ์ต๋๋ค. ์์ฆ์ ์ฃผ๋ก Python์ ์ฌ์ฉํ๋ค๋ณด๋, C, C++ ์ ๊ธฐ์ด๋ฌธ๋ฒ๊ณผ CodeStyle์ ๋ค์ ๋ ์ฌ๋ ค์ผํฉ๋๋ค. ํ์ ๋ ์ด์ฌํ ๊ณต๋ถํ์ผ๋ ๋ฐฉ๊ตฌ์ ํ์ผ ์ ๋จผ์ง ์์ธ ์ดํ๊ฐ์ C, C++์ฑ
๊ณผ ์ธํฐ๋ท์๋ฃ, ์ ํ๋ธ๋ฅผ ํตํด Remindํ๊ณ ๊ณต๋ถํ๋ ๋ด์ฉ์ ์์ฝ ์ ๋ฆฌํ๋ ค๊ณ ํฉ๋๋ค. ๋ณธ ๊ธ์์๋ C์ ๋ํ ๋ด์ฉ๋ณด๋ค C++ ๋ด์ฉ์ด ์ฃผ๋ฅผ ์ด๋ฃฐ ์์ ์
๋๋ค. </p>
<p>๋ชจ๋ ์ฐ์ฐ์์ ๋ํ ๋ฆฌ๋ทฐ๋ณด๋ค๋ ์กฐ๊ธ ๊น๋ค๋กญ๊ฑฐ๋, ์ฝ๊ฒ ์์ ์ ์๋ ์ฐ์ฐ์ ๋ฑ์ ์์ฃผ๋ก ์ ๋ฆฌํ๋ ค๊ณ ํฉ๋๋ค.</p></description>
<content:encoded><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>C์ C++์ด ํ์ํด, ์ ๋จธ๋ฆฟ์ ๋ฉ๋ชจ๋ฆฌ์ Recall ์ด ํ์ํ์ต๋๋ค. ์์ฆ์ ์ฃผ๋ก Python์ ์ฌ์ฉํ๋ค๋ณด๋, C, C++ ์ ๊ธฐ์ด๋ฌธ๋ฒ๊ณผ CodeStyle์ ๋ค์ ๋ ์ฌ๋ ค์ผํฉ๋๋ค. ํ์ ๋ ์ด์ฌํ ๊ณต๋ถํ์ผ๋ ๋ฐฉ๊ตฌ์ ํ์ผ ์ ๋จผ์ง ์์ธ ์ดํ๊ฐ์ C, C++์ฑ
๊ณผ ์ธํฐ๋ท์๋ฃ, ์ ํ๋ธ๋ฅผ ํตํด Remindํ๊ณ ๊ณต๋ถํ๋ ๋ด์ฉ์ ์์ฝ ์ ๋ฆฌํ๋ ค๊ณ ํฉ๋๋ค. ๋ณธ ๊ธ์์๋ C์ ๋ํ ๋ด์ฉ๋ณด๋ค C++ ๋ด์ฉ์ด ์ฃผ๋ฅผ ์ด๋ฃฐ ์์ ์
๋๋ค. </p><p>๋ชจ๋ ์ฐ์ฐ์์ ๋ํ ๋ฆฌ๋ทฐ๋ณด๋ค๋ ์กฐ๊ธ ๊น๋ค๋กญ๊ฑฐ๋, ์ฝ๊ฒ ์์ ์ ์๋ ์ฐ์ฐ์ ๋ฑ์ ์์ฃผ๋ก ์ ๋ฆฌํ๋ ค๊ณ ํฉ๋๋ค.</p><span id="more"></span><h3 id="์ฐ์ ์ฐ์ฐ์-x2F-x3D"><a href="#์ฐ์ ์ฐ์ฐ์-x2F-x3D" class="headerlink" title="์ฐ์ ์ฐ์ฐ์(+, -, *, /, %, +=)"></a>์ฐ์ ์ฐ์ฐ์(+, -, *, /, %, +=)</h3><p>/ : ๋๋๊ธฐ,</p><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// ์ด ๋, ์ ์์ ์ ์๊ฐ์ ์ฐ์ฐ์ result ์๋ 2๊ฐ ์ ์ฅ๋จ</span></span><br><span class="line"><span class="type">int</span> result = <span class="number">7</span> / <span class="number">3</span>;</span><br><span class="line"><span class="comment">// ์ด ๋, ๋๋จธ์ง๋ ๋ชจ๋๋ฌ์ค ์ฐ์ฐ์๋ก ๊ณ์ฐ</span></span><br><span class="line"><span class="type">int</span> remain = <span class="number">7</span> % <span class="number">3</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// ์ด ๊ฒฝ์ฐ๋, ์๋ฌ๋ ๋ฐ์์ํค์ง ์์ผ๋ warning sign ์ ํ์ธํ ์ ์์.</span></span><br><span class="line"><span class="comment">// int type์ result์ float ํน์ double ํํ์ ์ฐ์ฐ๊ฐ์ ์ ์ฅํ๊ธฐ์ warning sign ๋ฐ์</span></span><br><span class="line"><span class="type">int</span> result = <span class="number">7.0</span> / <span class="number">3.0</span>;</span><br><span class="line"><span class="comment">// ์ด๋ฅผ ๋ง๊ธฐ์ํด ์์ฑ์์ ์๋๋ฅผ ๋ด์ TypeCasting ์ ํด์ฃผ๋ ๊ฒ์ ์ถ์ฒ</span></span><br><span class="line"><span class="type">int</span> result = (<span class="type">int</span>)(<span class="number">7.0</span> / <span class="number">3.0</span>);</span><br></pre></td></tr></table></figure><p>% : Modulus ๋๋จธ์ง ์ฐ์ฐ์, Modulus๋ argument ๊ฐ ๋ชจ๋ ์ ์์ฌ์ผ ๊ณ์ฐ ๊ฐ๋ฅ. ์ค์๊ฐ์ Modulus๊ณ์ฐ์ ์๋ฌ</p><p>+= : a += 10 โ a = a + 10</p><h3 id="์ฆ๊ฐ์ฐ์ฐ์-โ"><a href="#์ฆ๊ฐ์ฐ์ฐ์-โ" class="headerlink" title="์ฆ๊ฐ์ฐ์ฐ์(++, โ)"></a>์ฆ๊ฐ์ฐ์ฐ์(++, โ)</h3><p>์ฆ๊ฐ์ฐ์ฐ์๋ ์ ์์ ๊ฒฝ์ฐ 1์ ๋ํ๊ฑฐ๋ ๋นผ๋ ๊ฒฝ์ฐ์ด์ง๋ง, ํฌ์ธํฐ์์๋ ๋ฉ๋ชจ๋ฆฌ ๋จ์๋ก ์ฆ๊ฐํ๋ ๊ฒ.</p><p>์ฆ, ์ฆ๊ฐ์ฐ์ฐ์๋ unit ๋จ์๋ก ์ฆ๊ฐ ๋๋ ๊ฐ์ ํ๋ ์ฐ์ฐ</p><p>++ : a++ โ a = a + 1, ++a โ a = a + 1</p><p>โ : aโ โ a = a - 1, โa โ a = a-1</p><p>์์ ๋ถ๋ ๊ฒฝ์ฐ(์ ์น)์ ๋ค์ ๋ถ๋ ๊ฒฝ์ฐ(ํ์น)๋ ์ฐ์ฐ์ ์ฐ์ ์์๊ฐ ๋ณํ. ํ์๋ ์ฐ์ ์์๊ฐ ๊ฐ์ฅ ๋ง์ง๋ง, ์ ์๋ ์ฐ์ ์์๊ฐ ๋จผ์ ์ํ.</p><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> result = <span class="number">10</span>;</span><br><span class="line"><span class="type">int</span> a = <span class="number">0</span>;</span><br><span class="line">a = result++; <span class="comment">// a=10, result=11</span></span><br><span class="line"></span><br><span class="line">result = <span class="number">10</span>;</span><br><span class="line">a = <span class="number">0</span>;</span><br><span class="line">a = ++result; <span class="comment">// a=11, result=11</span></span><br></pre></td></tr></table></figure><h3 id="๋
ผ๋ฆฌ์ฐ์ฐ์-Booleans-not-amp-amp-and-or"><a href="#๋
ผ๋ฆฌ์ฐ์ฐ์-Booleans-not-amp-amp-and-or" class="headerlink" title="๋
ผ๋ฆฌ์ฐ์ฐ์(Booleans), !(not), &&(and), ||(or)"></a>๋
ผ๋ฆฌ์ฐ์ฐ์(Booleans), !(not), &&(and), ||(or)</h3><p>true: 0์ด ์๋ ๋ชจ๋ ๊ฐ, ์ผ๋ฐ์ ์ผ๋ก 1</p><p>false: 0</p><p>boolean ์๋ฃํ: <code>bool</code> (true, false)</p><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">bool</span> istrue = <span class="literal">true</span>; <span class="comment">// isture -> true</span></span><br><span class="line"><span class="type">int</span> istrue_integer = <span class="literal">true</span>; <span class="comment">//istrue_integer -> 1</span></span><br></pre></td></tr></table></figure><h3 id="๋น๊ต์ฐ์ฐ์-x3D-x3D-โ -lt-gt-โค-โฅ"><a href="#๋น๊ต์ฐ์ฐ์-x3D-x3D-โ -lt-gt-โค-โฅ" class="headerlink" title="๋น๊ต์ฐ์ฐ์(==, โ , <,>, โค,โฅ)"></a>๋น๊ต์ฐ์ฐ์(==, โ , <,>, โค,โฅ)</h3><p>== : equal</p><p>! =: not equal</p><h3 id="์ผํญ์ฐ์ฐ์"><a href="#์ผํญ์ฐ์ฐ์" class="headerlink" title="์ผํญ์ฐ์ฐ์"></a>์ผํญ์ฐ์ฐ์</h3><p>๊ฐ๋จํ if-else ๋ฌธ์ ํ์ค ํํ</p><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> a = <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line">a == <span class="number">10</span> ? a = <span class="literal">true</span> : a = <span class="literal">false</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//์ ๊ฒฐ๊ณผ๋ฅผ if else ๋ฌธ์ผ๋ก ํํํ๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.</span></span><br><span class="line"><span class="keyword">if</span> (a == <span class="number">10</span>){</span><br><span class="line">a=<span class="literal">true</span>;</span><br><span class="line">}</span><br><span class="line"><span class="keyword">else</span>{</span><br><span class="line">a=<span class="literal">false</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content:encoded>
<category domain="https://emjayahn.github.io/categories/Development/">Development</category>
<category domain="https://emjayahn.github.io/categories/Development/C/">C++</category>
<category domain="https://emjayahn.github.io/tags/Language/">Language</category>
<category domain="https://emjayahn.github.io/tags/C/">C++</category>
<category domain="https://emjayahn.github.io/tags/C/">C</category>
<comments>https://emjayahn.github.io/2021/10/14/C-%E1%84%8B%E1%85%A7%E1%86%AB%E1%84%89%E1%85%A1%E1%86%AB%E1%84%8C%E1%85%A1-Operators/#disqus_thread</comments>
</item>
</channel>
</rss>