/the-clean-transformer

A clean and structured implementation of Transformer with wandb and pytorch-lightning

Primary LanguagePython

The Clean Transformer

Open In Colab Language grade: Python

πŸ‡°πŸ‡· pytorch-lightningκ³Ό wandb둜 κΉ”λ”ν•˜κ²Œ κ΅¬ν˜„ν•΄λ³΄λŠ” 트랜슀포머

πŸ‡¬πŸ‡§ Transformer implemented with clean and structured code - much thanks to pytorch-lightning & wandb !

Quick Start

μš°μ„ , 리포λ₯Ό ν΄λ‘ ν•˜κ³  κ°€μƒν™˜κ²½μ„ κ΅¬μΆ•ν•©λ‹ˆλ‹€:

git clone https://github.com/eubinecto/the-clean-transformer.git
python3.9 -m venv venv
source venv/bin/activate
cd the-clean-transformer
pip3 install -r requirements.txt

이후 μ‚¬μ „ν•™μŠ΅λœ λͺ¨λΈμ„ λ‹€μš΄λ‘œλ“œν•˜κ³ , κ°„λ‹¨ν•œ ν•œκ΅­μ–΄ λ²ˆμ—­μ„ μ‹œλ„ν•΄λ³΄κΈ° μœ„ν•΄ main_infer.py 슀크립트λ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€. μ‚¬μ „ν•™μŠ΅λœ λͺ¨λΈμ„ λ‹€μš΄λ‘œλ“œ ν•˜κΈ° μœ„ν•΄μ„  λ°˜λ“œμ‹œ 첫번째 인자 (entity)둜 eubinectoλ₯Ό λ„£μ–΄μ•Ό ν•©λ‹ˆλ‹€. μΆ”κ°€λ‘œ μ˜μ–΄λ‘œ λ²ˆμ—­ν•˜κ³ μž ν•˜λŠ” ν•œκ΅­μ–΄ λ¬Έμž₯을 --kor 인자둜 λ„£μ–΄μ€λ‹ˆλ‹€.

python3 main_infer.py eubinecto --kor="μΉ΄νŽ˜μΈμ€ μ›λž˜ 컀피에 λ“€μ–΄μžˆλŠ” λ¬Όμ§ˆμ΄λ‹€."

μœ„ 슀크립트λ₯Ό μ‹€ν–‰ν•˜λ©΄, λ‹€μŒκ³Ό 같은 선택창이 λœΉλ‹ˆλ‹€:

wandb: (1) Create a W&B account
wandb: (2) Use an existing W&B account
wandb: (3) Don't visualize my results
wandb: Enter your choice: 

3을 μž…λ ₯ ν›„ μ—”ν„°λ₯Ό λˆŒλŸ¬μ£Όμ„Έμš”. 이후 μ‚¬μ „ν•™μŠ΅λœ 트랜슀포머 λͺ¨λΈμ΄ ./artifacts/transformer:overfit_small 에 λ‹€μš΄λ‘œλ“œλ˜λ©°, λ‹€μŒκ³Ό 같이 주어진 --kor λ¬Έμž₯을 μ˜μ–΄λ‘œ λ²ˆμ—­ν•©λ‹ˆλ‹€:

wandb: You chose 'Don't visualize my results'
wandb: Downloading large artifact transformer:overfit_small, 263.49MB. 1 files... Done. 0:0:0
카페 ##인은 μ›λž˜ 컀피 ##에 λ“€μ–΄ ##μžˆλŠ” 물질 ##이닀 . -> caf ##fe ##ine is a subst ##ance natural ##ly found in coffee .

Pretrained Models

overfit_small
데λͺ¨λ₯Ό μœ„ν•΄ ν•œκ΅­μ–΄-μ˜μ–΄ λ§λ­‰μΉ˜μ˜ μΌλΆ€λΆ„λ§Œμ„ κ³Όν•™μŠ΅ν•œ λͺ¨λΈ
image
ν•˜μ΄νΌνŒŒλΌλ―Έν„° / ν•™μŠ΅λ§λ­‰μΉ˜ / Weights & Biases ν•™μŠ΅λ‘œκ·Έ
use this in command: python3 main_infer.py eubinecto --ver=overfit_small

Project Structure

.                        # ROOT_DIR 
β”œβ”€β”€ main_build.py        # 주어진 λ§λ­‰μΉ˜μ— μ ν•©ν•œ huggingface ν† ν¬λ‚˜μ΄μ €λ₯Ό ν›ˆλ ¨μ‹œν‚¬ λ•Œ μ‚¬μš©ν•˜λŠ” 슀크립트
β”œβ”€β”€ main_train.py        # κ΅¬ν˜„λœ 트랜슀포머λ₯Ό ν›ˆλ ¨μ‹œν‚¬ λ•Œ μ‚¬μš©ν•˜λŠ” 슀크립트
β”œβ”€β”€ main_infer.py        # μ‚¬μ „ν•™μŠ΅λœ 트랜슀포머둜 μ˜ˆμΈ‘μ„ ν•΄λ³Ό λ•Œ μ‚¬μš©ν•˜λŠ” 슀크립트
β”œβ”€β”€ config.yaml          # main_build.py 와 main_train.py에 ν•„μš”ν•œ 인자λ₯Ό μ •μ˜ν•΄λ†“λŠ” μ„€μ •νŒŒμΌ
└── cleanformer          # main μŠ€ν¬λ¦½νŠΈμ— μ‚¬μš©λ  재료λ₯Ό μ •μ˜ν•˜λŠ” 파이썬 νŒ¨ν‚€μ§€
    β”œβ”€β”€ builders.py      # λ§λ­‰μΉ˜ -> μž…λ ₯ν…μ„œ, μ •λ‹΅ν…μ„œ λ³€ν™˜μ„ λ„μ™€μ£ΌλŠ” λΉŒλ” μ •μ˜
    β”œβ”€β”€ functional.py    # 트랜슀포머 κ΅¬ν˜„μ— ν•„μš”ν•œ ν…μ„œκ΅¬μΆ• ν•¨μˆ˜ μ •μ˜
    β”œβ”€β”€ datamodules.py   # ν•™μŠ΅μ— μ‚¬μš©ν•  train/val/test 데이터 μ •μ˜
    β”œβ”€β”€ models.py        # λͺ¨λ“  신경망 λͺ¨λΈ μ •μ˜
    β”œβ”€β”€ fetchers.py      # 데이터λ₯Ό λ‹€μš΄λ‘œλ“œ 및 λ‘œλ“œν•˜λŠ” ν•¨μˆ˜ μ •μ˜
    β”œβ”€β”€ paths.py         # fetchers.pyκ°€ 데이터λ₯Ό λ‹€μš΄λ‘œλ“œ 및 λ‘œλ“œν•  경둜 μ •μ˜
    └── __init__.py