| --- |
| license: cc-by-nc-sa-4.0 |
| language: |
| - en |
| library_name: pytorch |
| pipeline_tag: text-generation |
| datasets: |
| - roneneldan/TinyStories |
| - li2017dailydialog/daily_dialog |
| tags: |
| - tinystories |
| - small-language-model |
| --- |
| |
| # tinyLLM 29M β Chat |
|
|
| TinyStories μ¬μ νμ΅ ν DailyDialog λ‘ SFT ν κ°μ€μΉ. μ§§μ λνλ₯Ό μ£Όκ³ λ°λλ€. |
|
|
| νλΌλ―Έν° **29,577,728** κ°. RTX 3060 Ti ν λμμ μ¬μ νμ΅ 3.06 μκ° + SFT 2.4 λΆ. |
| νμ΅ μ½λμ μ€κ³ κ·Όκ±°: https://github.com/sciencemj/tinyLLM |
|
|
| val loss 2.3975 (DailyDialog), μ’
λ£ ν ν° μ€μμ¨ 100% |
|
|
| ## μ΄μ© 쑰건 |
|
|
| **λΉμμ
μ μ©μ΄λ€.** DailyDialog κ° CC BY-NC-SA 4.0 μ΄κ³ λ°μ΄ν°μ
μΉ΄λμ "Dataset provided for research purposes only" λΌκ³ μ ν μλ€. μ λ£ μλΉμ€, κ΄κ³ κ° λΆμ λ°λͺ¨, μ¬λ΄ μ ν μ΄λμλ μΈ μ μλ€. μ¬λ°°ν¬ν λλ μΆμ²λ₯Ό νμνκ³ λμΌ μ‘°κ±΄μΌλ‘ 곡κ°ν΄μΌ νλ€. |
|
|
| μμ
μ μ΄μ©μ΄ νμνλ©΄ μ μ½μ΄ μλ μ¬μ νμ΅ κ°μ€μΉ([tinyllm-29m-tinystories](https://huggingface.co/sciencemj/tinyllm-29m-tinystories))μμ μμν΄ 2 λ¨κ³ λ°μ΄ν°λ§ νμ©μ λΌμ΄μ μ€λ‘ κ΅μ²΄νλ©΄ λλ€. SFT λ 2.4 λΆμ΄λ€. |
|
|
| ## μ°λ λ² |
|
|
| `transformers` λ₯Ό μ°μ§ μλλ€. μ΄ μ μ₯μμ `modeling_tinyllm.py` νλλ©΄ λλ€. |
|
|
| ```python |
| import torch |
| from tokenizers import Tokenizer |
| from modeling_tinyllm import TinyLM |
| |
| model = TinyLM.from_pretrained(".") |
| tok = Tokenizer.from_file("tokenizer.json") |
| |
| ids = torch.tensor([tok.encode("<|user|>Hi, how are you today?<|eot|><|assistant|>").ids]) |
| out = model.generate(ids, 60, temperature=0.6, top_k=20, stop_id=3) |
| print(tok.decode(out[0].tolist(), skip_special_tokens=True)) |
| ``` |
|
|
| λνλ ν΄ νμκ° νμνλ€. λͺ¨λΈμ΄ μ€μ λ‘ μ½λ κ²μ λκΈ°μ§ μλ ν μ€μ΄λ€: |
|
|
| ``` |
| <|user|>Hi, how are you today?<|eot|><|assistant|> |
| ``` |
|
|
| λμ `<|assistant|>` κ° μμ΄μΌ λͺ¨λΈμ΄ μ΄μΌκΈ°λ₯Ό μ΄μ΄μ°λ λμ μκΈ° μ°¨λ‘λ‘ λ΅νλ€. |
| νΉμ ν ν° id λ `<|endoftext|>`=0, `<|user|>`=1, `<|assistant|>`=2, `<|eot|>`=3 μ΄λ€. |
|
|
| ## ꡬ쑰 |
|
|
| ``` |
| ids (B, 512) |
| β nn.Embedding(8000, 512) + nn.Embedding(512, 512) |
| β nn.TransformerEncoder( |
| nn.TransformerEncoderLayer(512, nhead=8, dim_feedforward=2048, |
| activation="gelu", norm_first=True, |
| batch_first=True), |
| num_layers=8, norm=nn.RMSNorm(512)) |
| β nn.Linear(512, 8000, bias=False) # token embedding κ³Ό tying |
| ``` |
|
|
| decoder-only λ₯Ό `TransformerEncoderLayer` λ‘ λ§λ λ€. `TransformerDecoderLayer` λ |
| cross-attention μ© `memory` λ₯Ό νμλ‘ μꡬν΄μ λ§μ§ μλλ€. |
|
|
| ν ν¬λμ΄μ λ TinyStories μ DailyDialog ν©μ§ν©μμ νμ΅ν μ체 8k byte-level BPE λ€. |
| **κ°μ΄ λ°μ `tokenizer.json` μ λ°λμ μ¨μΌ νλ€.** λ€λ₯Έ ν ν¬λμ΄μ λ‘λ λμνμ§ μλλ€. |
|
|
| ## νκ³ |
|
|
| **λλ€** β λ¬Έλ², ꡬλμ , λ°μ΄ν λν νμ, λ¬Έλ¨ λλκΈ°, μΈλ¬Ό μ΄λ¦ μ μ§, μΈκ³Ό μ°κ²°. |
|
|
| **μ λλ€** β ν΄ κ° κΈ°μ΅, μ§λ¬Έμ λν μ§μ λ΅λ³, μ¬μ€μ±, λ¬Έμ₯ μ λ°λ³΅, λ
Όλ¦¬ μΌκ΄μ±. |
| μμ΄λ§ μλ€. μ¬μ€ μ 보λ₯Ό μ»λ μ©λλ‘ μ°λ©΄ μ λλ€. |
|
|
| μμΈν κ²μ [MODEL_CARD.md](https://github.com/sciencemj/tinyLLM/blob/main/MODEL_CARD.md). |
|
|
| ## μΈμ© |
|
|
| ```bibtex |
| @article{eldan2023tinystories, |
| title={TinyStories: How Small Can Language Models Be and Still Speak Coherent English?}, |
| author={Eldan, Ronen and Li, Yuanzhi}, |
| journal={arXiv preprint arXiv:2305.07759}, |
| year={2023} |
| } |
| |
| @InProceedings{li2017dailydialog, |
| author = {Li, Yanran and Su, Hui and Shen, Xiaoyu and Li, Wenjie and Cao, Ziqiang and Niu, Shuzi}, |
| title = {DailyDialog: A Manually Labelled Multi-turn Dialogue Dataset}, |
| booktitle = {Proceedings of The 8th International Joint Conference on Natural Language Processing (IJCNLP 2017)}, |
| year = {2017} |
| } |
| ``` |
|
|