sciencemj's picture
Upload folder using huggingface_hub
938a6ab verified
|
Raw
History Blame Contribute Delete
3.2 kB
---
license: cdla-sharing-1.0
language:
- en
library_name: pytorch
pipeline_tag: text-generation
datasets:
- roneneldan/TinyStories
tags:
- tinystories
- small-language-model
---
# tinyLLM 29M β€” TinyStories
1단계 μ‚¬μ „ν•™μŠ΅λ§Œ 거친 κ°€μ€‘μΉ˜. λŒ€ν™”λŠ” λͺ» ν•˜κ³  이야기λ₯Ό 이어쓴닀.
νŒŒλΌλ―Έν„° **29,577,728** 개. RTX 3060 Ti ν•œ λŒ€μ—μ„œ μ‚¬μ „ν•™μŠ΅ 3.06 μ‹œκ°„ + SFT 2.4 λΆ„.
ν•™μŠ΅ μ½”λ“œμ™€ 섀계 κ·Όκ±°: https://github.com/sciencemj/tinyLLM
val loss 1.3202 nats/token (perplexity 3.744, bits/char 0.4659)
## 이용 쑰건
**이용 μ œμ•½μ΄ μ—†λ‹€.** TinyStories λŠ” CDLA-Sharing-1.0 이고 Β§3.5 κ°€ λͺ…μ‹œν•œλ‹€ β€” *"This Agreement imposes no obligations or restrictions on Your Use or Publication of Results."* Β§1.11 μ—μ„œ Results λŠ” λ°μ΄ν„°μ˜ Computational Use 둜 얻은 μ‚°μΆœλ¬Όμ΄λ©°, 쑰건은 λ°μ΄ν„°μ˜ de minimis λΆ„λŸ‰ 이상을 ν¬ν•¨ν•˜μ§€ μ•ŠλŠ” 것이닀. 이 λͺ¨λΈμ€ train/val 격차가 0.03 이라 μ½”νΌμŠ€λ₯Ό μ™Έμš°κ³  μžˆμ§€ μ•Šλ‹€.
## μ“°λŠ” 법
`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("Once upon a time, there was a little girl named Lily.").ids])
out = model.generate(ids, 60, temperature=0.6, top_k=20)
print(tok.decode(out[0].tolist(), skip_special_tokens=True))
```
이 κ°€μ€‘μΉ˜λŠ” λŒ€ν™”λ₯Ό λͺ» ν•œλ‹€. μ§ˆλ¬Έμ„ μ£Όλ©΄ μ΄μ•ΌκΈ°μ˜ 첫 λ¬Έμž₯으둜 λ°›μ•„
계속 써 λ‚΄λ €κ°„λ‹€. λŒ€ν™”κ°€ ν•„μš”ν•˜λ©΄
[tinyllm-29m-chat](https://huggingface.co/sciencemj/tinyllm-29m-chat) 을 μ“΄λ‹€.
## ꡬ쑰
```
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}
}
```