train tokenizer
Browse files- .gitignore +164 -0
- requirements.in +5 -0
- scripts/TRAIN.md +15 -0
- scripts/train_tokenizer.py +163 -0
.gitignore
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ---> Python
|
2 |
+
# Byte-compiled / optimized / DLL files
|
3 |
+
__pycache__/
|
4 |
+
*.py[cod]
|
5 |
+
*$py.class
|
6 |
+
|
7 |
+
# C extensions
|
8 |
+
*.so
|
9 |
+
|
10 |
+
# Distribution / packaging
|
11 |
+
.Python
|
12 |
+
build/
|
13 |
+
develop-eggs/
|
14 |
+
dist/
|
15 |
+
downloads/
|
16 |
+
eggs/
|
17 |
+
.eggs/
|
18 |
+
lib/
|
19 |
+
lib64/
|
20 |
+
parts/
|
21 |
+
sdist/
|
22 |
+
var/
|
23 |
+
wheels/
|
24 |
+
share/python-wheels/
|
25 |
+
*.egg-info/
|
26 |
+
.installed.cfg
|
27 |
+
*.egg
|
28 |
+
MANIFEST
|
29 |
+
|
30 |
+
# PyInstaller
|
31 |
+
# Usually these files are written by a python script from a template
|
32 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
33 |
+
*.manifest
|
34 |
+
*.spec
|
35 |
+
|
36 |
+
# Installer logs
|
37 |
+
pip-log.txt
|
38 |
+
pip-delete-this-directory.txt
|
39 |
+
|
40 |
+
# Unit test / coverage reports
|
41 |
+
htmlcov/
|
42 |
+
.tox/
|
43 |
+
.nox/
|
44 |
+
.coverage
|
45 |
+
.coverage.*
|
46 |
+
.cache
|
47 |
+
nosetests.xml
|
48 |
+
coverage.xml
|
49 |
+
*.cover
|
50 |
+
*.py,cover
|
51 |
+
.hypothesis/
|
52 |
+
.pytest_cache/
|
53 |
+
cover/
|
54 |
+
|
55 |
+
# Translations
|
56 |
+
*.mo
|
57 |
+
*.pot
|
58 |
+
|
59 |
+
# Django stuff:
|
60 |
+
*.log
|
61 |
+
local_settings.py
|
62 |
+
db.sqlite3
|
63 |
+
db.sqlite3-journal
|
64 |
+
|
65 |
+
# Flask stuff:
|
66 |
+
instance/
|
67 |
+
.webassets-cache
|
68 |
+
|
69 |
+
# Scrapy stuff:
|
70 |
+
.scrapy
|
71 |
+
|
72 |
+
# Sphinx documentation
|
73 |
+
docs/_build/
|
74 |
+
|
75 |
+
# PyBuilder
|
76 |
+
.pybuilder/
|
77 |
+
target/
|
78 |
+
|
79 |
+
# Jupyter Notebook
|
80 |
+
.ipynb_checkpoints
|
81 |
+
|
82 |
+
# IPython
|
83 |
+
profile_default/
|
84 |
+
ipython_config.py
|
85 |
+
|
86 |
+
# pyenv
|
87 |
+
# For a library or package, you might want to ignore these files since the code is
|
88 |
+
# intended to run in multiple environments; otherwise, check them in:
|
89 |
+
# .python-version
|
90 |
+
|
91 |
+
# pipenv
|
92 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
93 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
94 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
95 |
+
# install all needed dependencies.
|
96 |
+
#Pipfile.lock
|
97 |
+
|
98 |
+
# poetry
|
99 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
100 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
101 |
+
# commonly ignored for libraries.
|
102 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
103 |
+
#poetry.lock
|
104 |
+
|
105 |
+
# pdm
|
106 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
107 |
+
#pdm.lock
|
108 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
109 |
+
# in version control.
|
110 |
+
# https://pdm.fming.dev/#use-with-ide
|
111 |
+
.pdm.toml
|
112 |
+
|
113 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
114 |
+
__pypackages__/
|
115 |
+
|
116 |
+
# Celery stuff
|
117 |
+
celerybeat-schedule
|
118 |
+
celerybeat.pid
|
119 |
+
|
120 |
+
# SageMath parsed files
|
121 |
+
*.sage.py
|
122 |
+
|
123 |
+
# Environments
|
124 |
+
.env
|
125 |
+
.venv
|
126 |
+
env/
|
127 |
+
venv/
|
128 |
+
ENV/
|
129 |
+
env.bak/
|
130 |
+
venv.bak/
|
131 |
+
|
132 |
+
# Spyder project settings
|
133 |
+
.spyderproject
|
134 |
+
.spyproject
|
135 |
+
|
136 |
+
# Rope project settings
|
137 |
+
.ropeproject
|
138 |
+
|
139 |
+
# mkdocs documentation
|
140 |
+
/site
|
141 |
+
|
142 |
+
# mypy
|
143 |
+
.mypy_cache/
|
144 |
+
.dmypy.json
|
145 |
+
dmypy.json
|
146 |
+
|
147 |
+
# Pyre type checker
|
148 |
+
.pyre/
|
149 |
+
|
150 |
+
# pytype static type analyzer
|
151 |
+
.pytype/
|
152 |
+
|
153 |
+
# Cython debug symbols
|
154 |
+
cython_debug/
|
155 |
+
|
156 |
+
# PyCharm
|
157 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
158 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
159 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
160 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
161 |
+
.idea/
|
162 |
+
|
163 |
+
.DS_Store
|
164 |
+
.ruff_cache
|
requirements.in
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tqdm
|
2 |
+
datasets
|
3 |
+
jinja2
|
4 |
+
transformers
|
5 |
+
jsonlines
|
scripts/TRAIN.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Train
|
2 |
+
|
3 |
+
## Environment
|
4 |
+
|
5 |
+
```bash
|
6 |
+
python -m venv venv
|
7 |
+
source venv/bin/activate
|
8 |
+
pip install -U -r requirements.in
|
9 |
+
```
|
10 |
+
|
11 |
+
## Tokenizer
|
12 |
+
|
13 |
+
```bash
|
14 |
+
python -B train_tokenizer.py
|
15 |
+
```
|
scripts/train_tokenizer.py
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import string
|
2 |
+
|
3 |
+
from datasets import load_dataset
|
4 |
+
from tokenizers import ByteLevelBPETokenizer
|
5 |
+
from transformers import PreTrainedTokenizerFast
|
6 |
+
|
7 |
+
|
8 |
+
# dataset_0 = (
|
9 |
+
# load_dataset('wikimedia/wikisource', lang, split='train')
|
10 |
+
# for lang in ['20231201.ar', '20231201.as', '20231201.az', '20231201.ban', '20231201.be', '20231201.bg', '20231201.bn', '20231201.br', '20231201.bs', '20231201.ca', '20231201.cs', '20231201.cy', '20231201.da', '20231201.de', '20231201.el', '20231201.en', '20231201.eo', '20231201.es', '20231201.et', '20231201.eu', '20231201.fa', '20231201.fi', '20231201.fo', '20231201.fr', '20231201.gl', '20231201.gu', '20231201.he', '20231201.hi', '20231201.hr', '20231201.hu', '20231201.hy', '20231201.id', '20231201.is', '20231201.it', '20231201.ja', '20231201.jv', '20231201.kn', '20231201.ko', '20231201.la', '20231201.li', '20231201.lij', '20231201.lt', '20231201.mk', '20231201.ml', '20231201.mr', '20231201.nap', '20231201.nl', '20231201.no', '20231201.or', '20231201.pa', '20231201.pl', '20231201.pms', '20231201.pt', '20231201.ro', '20231201.ru', '20231201.sa', '20231201.sah', '20231201.sk', '20231201.sl', '20231201.sr', '20231201.su', '20231201.sv', '20231201.ta', '20231201.te', '20231201.th', '20231201.tr', '20231201.uk', '20231201.vec', '20231201.vi', '20231201.wa', '20231201.yi', '20231201.zh', '20231201.zh-min-nan']
|
11 |
+
# )
|
12 |
+
|
13 |
+
dataset_1 = (
|
14 |
+
load_dataset('xu-song/cc100-samples', lang, split='train')
|
15 |
+
for lang in ['am', 'ar', 'as', 'az', 'be', 'bg', 'bn', 'bn_rom', 'br', 'bs', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'ff', 'fi', 'fr', 'fy', 'ga', 'gd', 'gl', 'gn', 'gu', 'ha', 'he', 'hi', 'hi_rom', 'hr', 'ht', 'hu', 'hy', 'id', 'ig', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'km', 'kn', 'ko', 'ku', 'ky', 'la', 'lg', 'li', 'ln', 'lo', 'lt', 'lv', 'mg', 'mk', 'ml', 'mn', 'mr', 'ms', 'my', 'my_zaw', 'ne', 'nl', 'no', 'ns', 'om', 'or', 'pa', 'pl', 'ps', 'pt', 'qu', 'rm', 'ro', 'ru', 'sa', 'si', 'sc', 'sd', 'sk', 'sl', 'so', 'sq', 'sr', 'ss', 'su', 'sv', 'sw', 'ta', 'ta_rom', 'te', 'te_rom', 'th', 'tl', 'tn', 'tr', 'ug', 'uk', 'ur', 'ur_rom', 'uz', 'vi', 'wo', 'xh', 'yi', 'yo', 'zh-Hans', 'zh-Hant', 'zu']
|
16 |
+
)
|
17 |
+
|
18 |
+
dataset_2 = (
|
19 |
+
load_dataset('csebuetnlp/xlsum', lang, split='train')
|
20 |
+
for lang in ['amharic', 'arabic', 'azerbaijani', 'bengali', 'burmese', 'chinese_simplified', 'chinese_traditional', 'english', 'french', 'gujarati', 'hausa', 'hindi', 'igbo', 'indonesian', 'japanese', 'kirundi', 'korean', 'kyrgyz', 'marathi', 'nepali', 'oromo', 'pashto', 'persian', 'pidgin', 'portuguese', 'punjabi', 'russian', 'scottish_gaelic', 'serbian_cyrillic', 'serbian_latin', 'sinhala', 'somali', 'spanish', 'swahili', 'tamil', 'telugu', 'thai', 'tigrinya', 'turkish', 'ukrainian', 'urdu', 'uzbek', 'vietnamese', 'welsh', 'yoruba']
|
21 |
+
)
|
22 |
+
|
23 |
+
# dataset_3 = load_dataset('recursal/SuperWikiNEXT-32B', split='train')
|
24 |
+
dataset_4 = load_dataset('m-a-p/CodeFeedback-Filtered-Instruction', split='train')
|
25 |
+
dataset_5 = load_dataset('nampdn-ai/tiny-codes', split='train')
|
26 |
+
# dataset_6 = load_dataset('ajibawa-2023/Maths-College', split='train')
|
27 |
+
dataset_7 = load_dataset('microsoft/orca-math-word-problems-200k', split='train')
|
28 |
+
dataset_8 = load_dataset('mlabonne/FineTome-100k', split='train')
|
29 |
+
dataset_9 = load_dataset('arcee-ai/agent-data', split='train')
|
30 |
+
dataset_10 = [
|
31 |
+
load_dataset('cognitivecomputations/SystemChat-2.0', data_files='SystemChat_filtered.jsonl', split='train'),
|
32 |
+
load_dataset('cognitivecomputations/SystemChat-2.0', data_files='SystemChat_multilingual.jsonl', split='train'),
|
33 |
+
]
|
34 |
+
dataset_11 = load_dataset('badrex/llm-emoji-dataset', split='train')
|
35 |
+
|
36 |
+
|
37 |
+
def batch_iterator():
|
38 |
+
# for d in dataset_0:
|
39 |
+
# for row in d['text']:
|
40 |
+
# yield row
|
41 |
+
# break
|
42 |
+
#
|
43 |
+
# break
|
44 |
+
|
45 |
+
for d in dataset_1:
|
46 |
+
for row in d['text']:
|
47 |
+
yield row
|
48 |
+
# break
|
49 |
+
|
50 |
+
# break
|
51 |
+
|
52 |
+
for d in dataset_2:
|
53 |
+
for row in d['text']:
|
54 |
+
yield row
|
55 |
+
# break
|
56 |
+
|
57 |
+
# break
|
58 |
+
|
59 |
+
# for row in dataset_3['text']:
|
60 |
+
# yield row
|
61 |
+
# break
|
62 |
+
|
63 |
+
for row in dataset_4:
|
64 |
+
yield row['query'] + '\n' + row['answer']
|
65 |
+
# break
|
66 |
+
|
67 |
+
for row in dataset_5:
|
68 |
+
yield row['prompt'] + '\n' + row['response']
|
69 |
+
# break
|
70 |
+
|
71 |
+
# for row in dataset_6:
|
72 |
+
# yield row['instruction'] + '\n' + row['output']
|
73 |
+
# break
|
74 |
+
|
75 |
+
for row in dataset_7:
|
76 |
+
yield row['question'] + '\n' + row['answer']
|
77 |
+
# break
|
78 |
+
|
79 |
+
for row in dataset_8['conversations']:
|
80 |
+
yield '\n'.join(n['value'] for n in row)
|
81 |
+
# break
|
82 |
+
|
83 |
+
for row in dataset_9['conversations']:
|
84 |
+
yield '\n'.join(n['value'] for n in row)
|
85 |
+
# break
|
86 |
+
|
87 |
+
for d in dataset_10:
|
88 |
+
for row in d['messages']:
|
89 |
+
yield '\n'.join(n['content'] for n in row)
|
90 |
+
# break
|
91 |
+
|
92 |
+
for row in dataset_11:
|
93 |
+
yield f'{row["character"]}\n{row["unicode"]}\n{row["short description"]}\n{row["tags"]}\n{row["LLM description"]}'
|
94 |
+
# break
|
95 |
+
|
96 |
+
|
97 |
+
# for row in batch_iterator():
|
98 |
+
# print(f'{row = }')
|
99 |
+
|
100 |
+
|
101 |
+
special_tokens = [
|
102 |
+
'<s>',
|
103 |
+
'</s>',
|
104 |
+
'<pad>',
|
105 |
+
'<unk>',
|
106 |
+
'<mask>',
|
107 |
+
'<|im_start|>',
|
108 |
+
'<|im_end|>',
|
109 |
+
'<tools>',
|
110 |
+
'</tools>',
|
111 |
+
'<tool_call>',
|
112 |
+
'</tool_call>',
|
113 |
+
'<tool_response>',
|
114 |
+
'</tool_response>',
|
115 |
+
'system',
|
116 |
+
'user',
|
117 |
+
'assistant',
|
118 |
+
*list(string.printable),
|
119 |
+
]
|
120 |
+
|
121 |
+
for i in range(64 - len(special_tokens)):
|
122 |
+
special_tokens.append(f'<|reserved_{i}|>')
|
123 |
+
|
124 |
+
ascii_chars = string.ascii_letters + string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation
|
125 |
+
|
126 |
+
tokenizer = ByteLevelBPETokenizer()
|
127 |
+
|
128 |
+
tokenizer.train_from_iterator(
|
129 |
+
[ascii_chars],
|
130 |
+
vocab_size=len(ascii_chars),
|
131 |
+
min_frequency=1,
|
132 |
+
special_tokens=[],
|
133 |
+
)
|
134 |
+
|
135 |
+
tokenizer.train_from_iterator(
|
136 |
+
batch_iterator(),
|
137 |
+
vocab_size=32064,
|
138 |
+
min_frequency=2,
|
139 |
+
special_tokens=special_tokens,
|
140 |
+
)
|
141 |
+
|
142 |
+
tokenizer.save_model('..')
|
143 |
+
|
144 |
+
CHATML_CHAT_TEMPLATE = (
|
145 |
+
"{% for message in messages %}"
|
146 |
+
"{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}"
|
147 |
+
"{% endfor %}"
|
148 |
+
"{% if add_generation_prompt %}"
|
149 |
+
"{{ '<|im_start|>assistant\n' }}"
|
150 |
+
"{% endif %}"
|
151 |
+
)
|
152 |
+
|
153 |
+
fast_tokenizer = PreTrainedTokenizerFast(
|
154 |
+
tokenizer_object=tokenizer,
|
155 |
+
chat_template=CHATML_CHAT_TEMPLATE,
|
156 |
+
bos_token='<s>',
|
157 |
+
eos_token='</s>',
|
158 |
+
unk_token='<unk>',
|
159 |
+
pad_token='<pad>',
|
160 |
+
mask_token='<mask>',
|
161 |
+
)
|
162 |
+
|
163 |
+
fast_tokenizer.save_pretrained('..')
|