Skip to content

Commit

Permalink
Add sample notebooks for vanilla Transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonwooSung committed Jul 16, 2022
1 parent db97326 commit 6bec5dd
Show file tree
Hide file tree
Showing 9 changed files with 64,954 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Transformers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Transformers의 성공 요소는 크게 Self-Supervision 과 Self-Attention 으

또 다른 성공 요소인 Self-Attention은 말 그대로 스스로 attention을 계산하는 것을 의미하며 CNN, RNN과 같이 inductive bias가 많이 들어가 있는 모델들과는 다르게 최소한의 inductive bias를 가정합니다. Self-Attention Layer를 통해 주어진 sequence에서 각 token set elements(ex, words in language or patches in an image)간의 관계를 학습하면서 광범위한 context를 고려할 수 있게 됩니다.

## Sample Codes

- [Using GPU example](./src/transformer_gpu.ipynb)
- [Training](./src/Training.ipynb)
- [Inference](./src/Inference.ipynb)

## Semi-Supervised Learning

Transformers typically undergo semi-supervised learning involving unsupervised pretraining followed by supervised fine-tuning.
Expand Down
37 changes: 37 additions & 0 deletions Transformers/src/Bad.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
en = And no one pours new wine into old wineskins. If he does, the new wine will burst the skins, the wine will run out and the wineskins will be ruined.
answer = 새 포도주를 낡은 가죽 부대에다가 넣는 사람은 없다. 그렇게 하면, 새 포도주가 그 가죽 부대를 터뜨려서, 포도주는 쏟아지고, 가죽 부대는 못 쓰게 된다.
ko = ['새 포도주는 새 가죽 부대에 담은 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과 가죽과']

en = "Say to the Levites: 'When you present the best part, it will be reckoned to you as the product of the threshing floor or the winepress.
answer = 너는 또 그들에게 말하여라. '너희가 가장 좋은 부분을 들어 올려 바칠 때에, 나는 그것을 레위 사람이 타작 마당이나 포도 짜는 틀에서 나온 것을 바치는 것처럼 여길 것이다.
ko = ['"너는 레위 사람에게 말하여라. \'너희가 여기에 있다. 내가 너희에게 준 대로, 너희가 타작 마당과 보리빵에 있는 타작 마당과 포도송이에 있는 타작 마당과 포도 짜는 틀에서 포도 짜는 틀에서 포도 짜는 틀에서 포도 짜는 틀에서 포도 짜는 틀에서 포도 짜는 틀에서 포도 짜는 틀에서 포도도 포도도 포도 짜는 틀에서 무화과처럼 풀을 뜯고,']


en = The next morning Jehu went out. He stood before all the people and said, "You are innocent. It was I who conspired against my master and killed him, but who killed all these?
answer = 아침이 되었을 때에, 예후는 나가서 모든 백성에게 말하였다. "나는 내 옛 주인에게 역모를 꾀하여, 그를 죽였습니다. 백성들에게는 아무 잘못이 없습니다. 그러나 여기에 있는 이 모든 사람은 누가 죽였습니까?
ko = ['다음날 아침에 일찍 일어나서, 그를 돌로 치고, 그 아이들은 그를 고발하는 말을 듣고, 그를 고발하는 것을 보고, 그를 고발하는구나.']


en = Terrifying sounds fill his ears; when all seems well, marauders attack him.
answer = 들리는 소식이라고는 다 두려운 소식뿐이고, 좀 평안해졌는가 하면 갑자기 파괴하는 자가 들이닥치는 것이다.
ko = ['미련한 사람은 수치를 당하고, 공포에 사로잡힌다.']

en = and saw the Lord speaking. 'Quick!' he said to me. 'Leave Jerusalem immediately, because they will not accept your testimony about me.'
answer = 주님을 보았습니다. 그는 내게 '서둘러서 예루살렘을 떠나라. 예루살렘 사람들이 나를 두고 한 네 증언을 받아들이지 않을 것이기 때문이다' 하고 말씀하셨습니다.
ko = ["주께서 나에게 말씀하셨다. '너는 나를 두고 맹세하여라. 내가 너희에게 말한다. 너는 나를 두고 맹세하지 말아라. 그들이 나를 두고 맹세하지 말아라."]

en = "Go down, sit in the dust, Virgin Daughter of Babylon; sit on the ground without a throne, Daughter of the Babylonians. No more will you be called tender or delicate.
answer = 처녀 딸 바빌론아, 내려와서 티끌에 앉아라. 딸 바빌로니아야, 보좌를 잃었으니, 땅에 주저앉아라. 너의 몸매가 유연하고 맵시가 있다고들 하였지만, 이제는 아무도 그런 말을 하지 않을 것이다.
ko = ['"너는 바빌론 도성 바빌론 도성아, 바빌론 도성아, 바빌론 도성 안에 있는 도성 안에 있는 네 오른손에는 칼이나 쳐라. 네 오른손에는 칼이나 기근이나 기근이나 기근이나 기근이나 기근이나 기근이나 기근이나 굶은 아니다.']

en = Obed-Edom also had sons: Shemaiah the firstborn, Jehozabad the second, Joah the third, Sacar the fourth, Nethanel the fifth,
answer = 오벳에돔의 아들은, 맏아들 스마야와, 둘째 여호사밧과, 셋째 요아와, 넷째 사갈과, 다섯째 느다넬과,
ko = ['오벳에돔과 아사의 아들 여호하난이 보수하였는데, 그 다음은 단에서부터 스바와 드라빔과 스바와 드라빔과 스바와 드라빔과 스바와 드라빔과 스바와 드라빔과 스바와 드라빔과 스바와 드라빔과 스바와 드라빔과 스바와 드라빔과 스바와 드라빔과 스바와 드라빔이다.']

en = Therefore we will not fear, though the earth give way and the mountains fall into the heart of the sea,
answer = 땅이 흔들리고 산이 무너져 바다 속으로 빠져 들어도, 우리는 두려워하지 않는다.
ko = ['그러므로 우리는 땅 위에 사는 사람들을 두려워하고, 바다 위로할 수 없는 것을 보고,']

en = He said to them, "If you are willing to let me bury my dead, then listen to me and intercede with Ephron son of Zohar on my behalf
answer = 그들에게 말하였다. "여러분이, 내가 나의 아내를 이 곳에다 묻을 수 있게 해주시려면, 나의 청을 들어 주시고, 나를 대신해서, 소할의 아들 에브론에게 말을 전해 주시기 바랍니다.
ko = ['예수께서 그들에게 말씀하셨다. "내가 내 말을 할 수 있는 이 말을 듣고, 나를 잘 듣고, 내 말을 잘 듣고, 내장군다.']
1 change: 1 addition & 0 deletions Transformers/src/Dataset.ipynb

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions Transformers/src/Good.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
en = The fear of the LORD is the beginning of wisdom; all who follow his precepts have good understanding. To him belongs eternal praise.
answer = 주님을 경외하는 것이 지혜의 근본이다. 이것을 실천하는 사람은 바른 깨달음을 얻으니, 영원토록 주님을 찬양할 일이다.
ko = ['주의 교훈은, 주의 법도를 따라 사는 모든 성도들이 다 지켰습니다. 주의 법도를 저버리는 모든 성도들이 주님을 찬양은, 주님을 찬양하겠습니다.']



en = What a wretched man I am! Who will rescue me from this body of death?
answer = 아, 나는 비참한 사람입니다. 누가 이 죽음의 몸에서 나를 건져 주겠습니까?
ko = ['누가 나를 누구며, 누가 나를 누구입니까? 누가 나를 건져 줄 수 있겠느냐?']

en = When Jehu came to Samaria, he killed all who were left there of Ahab's family; he destroyed them, according to the word of the LORD spoken to Elijah.
answer = 그리고 그는 사마리아에 이르러서, 거기에 남아 있는 아합의 지지자를 모두 죽였다. 이 모든 것은 주께서 엘리야에게 말씀하신 대로 이루어진 것이다.
ko = ["예후가 죽으니, 사마리아에 있는 그의 조상에게로 가서, 그를 죽였다. 주께서 그에게 '다윗 성' 하고 말씀하신 그대로 본받았다."]

en = " 'This is what the Sovereign LORD says: In the first month on the first day you are to take a young bull without defect and purify the sanctuary.
answer = "나 주 하나님이 말한다. 너는 첫째 달 초하루에는 언제나 소 떼 가운데서 흠 없는 수송아지 한 마리를 골라다가 성소를 정결하게 하여라.
ko = ['나 주 하나님이 말한다. 그 날에는 수송아지 일곱 마리와 숫양 두 마리와 일 년 된 어린 숫양 한 마리를 흠 없는 것으로 바쳐라.']

en = "Son of man, set your face against Sidon; prophesy against her
answer = "사람아, 너는 얼굴을 돌려 시돈을 바라보고, 그 성읍을 규탄하여 예언을 하여라.
ko = ['"사람아, 너는 네가 이렇게 전하여라. 너는 에돔을 규탄하여 예언하여라.']

en = Moses answered the people, "Do not be afraid. Stand firm and you will see the deliverance the LORD will bring you today. The Egyptians you see today you will never see again.
answer = 모세가 백성에게 대답하였다. "두려워하지 말아라. 너희는 가만히 서서, 주께서 오늘 너희를 어떻게 구원하시는지 지켜 보기만 하여라. 너희가 오늘 보는 이 이집트 사람을 다시는 볼 수 없을 것이다.
ko = ['모세가 백성에게 말하였다. "주께서 확실히 살아 계심을 두고 맹세합니다. 오늘 너희에게 재앙을 내리지 않을 것이다. 너희가 이집트 땅에서 너희가 어떻게 하시지 못할 것이다.']

en = then hear from heaven their prayer and their plea, and uphold their cause.
answer = 주께서는 하늘에서 그들의 기도와 간구를 들으시고, 그들의 사정을 살펴보아 주십시오.
ko = ['그러나 주님은, 하늘에서 그들의 기도와 간구를 들으시고, 그들의 사정을 살펴 주십시오.']

en = Say to the southern forest: 'Hear the word of the LORD. This is what the Sovereign LORD says: I am about to set fire to you, and it will consume all your trees, both green and dry. The blazing flame will not be quenched, and every face from south to north will be scorched by it.
answer = 너는 네겝의 숲에 말하여라. '너는 주의 말을 들어라. 나 주 하나님이 말한다. 내가 숲 속에 불을 지르겠다. 그 불은 숲 속에 있는 모든 푸른 나무와 모든 마른 나무를 태울 것이다. 활활 치솟는 그 불꽃이 꺼지지 않아서, 남쪽에서 북쪽까지 모든 사람의 얼굴이 그 불에 그으를 것이다.
ko = ['너는, 너는, 산들아, 너희는 나 주 하나님의 말이다. 내가 너희에게 말한다. 내가 너희에게 말한다. 내가 너를 치겠다. 내가 너를 치고, 네 모든 곳에서 불에 태워 버리겠다.']

en = The LORD said to Moses, "Chisel out two stone tablets like the first ones, and I will write on them the words that were on the first tablets, which you broke.
answer = 주께서 모세에게 말씀하셨다. "너는 돌판 두 개를 처음 것과 같이 깎아라. 그러면, 네가 깨뜨려 버린 처음 돌판 위에 쓴 그 말을, 내가 새 돌판에 다시 새겨 주겠다.
ko = ['주께서 모세에게 말씀하셨다. "너는 이 두 돌판에 휩싸여, 내가 너희에게 명한 대로, 그 두루마리를 펴겠다. 나는 너희에게 보여 주겠다.']

en = That night all the people of the community raised their voices and wept aloud.
answer = 온 회중이 소리 높여 아우성쳤다. 백성이 밤새도록 통곡하였다.
ko = ['그 날 밤에 온 백성이 모두 크게 통곡하였다. 백성은 모두 통곡하였다.']

en = The word of the LORD came to me:
answer = 주께서 나에게 말씀하셨다.
ko = ['주께서 나에게 말씀하셨다.']

n = Then he went in and stood before his master Elisha. "Where have you been, Gehazi?" Elisha asked. "Your servant didn't go anywhere," Gehazi answered.
answer = 그리고 그가 들어가서 주인 앞에 서자, 엘리사가 그에게 물었다. "게하시야, 어디를 갔다 오는 길이냐?" 그러자 그는 "어른의 종인 저는 아무데도 가지 않았습니다" 하고 말하였다.
ko = ['엘리사가 게하시가 그에게 말하였다. "선생님, 제가 여기에 있습니다." 엘리사가 말하였다. "저에게 무엇을 보러 나갔더냐?"']

en = Solomon reigned in Jerusalem over all Israel forty years.
answer = 솔로몬은 예루살렘에서 사십 년 동안 온 이스라엘을 다스렸다.
ko = ['솔로몬은 예루살렘에서 마흔 해 동안 다스렸다.']

en = from the tribe of Simeon 12,000, from the tribe of Levi 12,000, from the tribe of Issachar 12,000,
answer = 시므온 지파에서 일만 이천 명이요, 레위 지파에서 일만 이천 명이요, 잇사갈 지파에서 일만 이천 명이요,
ko = ['시므온 지파에서 일만 이천 명이요, 레위 지파에서 일만 이천 명이요, 잇사갈 지파에서 일만 이천 명이요,']
1 change: 1 addition & 0 deletions Transformers/src/Inference.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Transformers/src/Training.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 6bec5dd

Please sign in to comment.