Text Generation
PyTorch
Safetensors
English
tinyllm
tinystories
small-language-model
File size: 3,872 Bytes
515688a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
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}
}
```