|
import string |
|
|
|
from datasets import load_dataset |
|
from tokenizers import ByteLevelBPETokenizer |
|
from transformers import PreTrainedTokenizerFast |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataset_1 = ( |
|
load_dataset('xu-song/cc100-samples', lang, split='train') |
|
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'] |
|
) |
|
|
|
dataset_2 = ( |
|
load_dataset('csebuetnlp/xlsum', lang, split='train') |
|
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'] |
|
) |
|
|
|
|
|
dataset_4 = load_dataset('m-a-p/CodeFeedback-Filtered-Instruction', split='train') |
|
dataset_5 = load_dataset('nampdn-ai/tiny-codes', split='train') |
|
|
|
dataset_7 = load_dataset('microsoft/orca-math-word-problems-200k', split='train') |
|
dataset_8 = load_dataset('mlabonne/FineTome-100k', split='train') |
|
dataset_9 = load_dataset('arcee-ai/agent-data', split='train') |
|
dataset_10 = [ |
|
load_dataset('cognitivecomputations/SystemChat-2.0', data_files='SystemChat_filtered.jsonl', split='train'), |
|
load_dataset('cognitivecomputations/SystemChat-2.0', data_files='SystemChat_multilingual.jsonl', split='train'), |
|
] |
|
dataset_11 = load_dataset('badrex/llm-emoji-dataset', split='train') |
|
|
|
|
|
def batch_iterator(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for d in dataset_1: |
|
for row in d['text']: |
|
yield row |
|
|
|
|
|
|
|
|
|
for d in dataset_2: |
|
for row in d['text']: |
|
yield row |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for row in dataset_4: |
|
yield row['query'] + '\n' + row['answer'] |
|
|
|
|
|
for row in dataset_5: |
|
yield row['prompt'] + '\n' + row['response'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
for row in dataset_7: |
|
yield row['question'] + '\n' + row['answer'] |
|
|
|
|
|
for row in dataset_8['conversations']: |
|
yield '\n'.join(n['value'] for n in row) |
|
|
|
|
|
for row in dataset_9['conversations']: |
|
yield '\n'.join(n['value'] for n in row) |
|
|
|
|
|
for d in dataset_10: |
|
for row in d['messages']: |
|
yield '\n'.join(n['content'] for n in row) |
|
|
|
|
|
for row in dataset_11: |
|
yield f'{row["character"]}\n{row["unicode"]}\n{row["short description"]}\n{row["tags"]}\n{row["LLM description"]}' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
special_tokens = [ |
|
'<s>', |
|
'</s>', |
|
'<pad>', |
|
'<unk>', |
|
'<mask>', |
|
'<|im_start|>', |
|
'<|im_end|>', |
|
'<tools>', |
|
'</tools>', |
|
'<tool_call>', |
|
'</tool_call>', |
|
'<tool_response>', |
|
'</tool_response>', |
|
'system', |
|
'user', |
|
'assistant', |
|
*list(string.printable), |
|
] |
|
|
|
for i in range(64 - len(special_tokens)): |
|
special_tokens.append(f'<|reserved_{i}|>') |
|
|
|
ascii_chars = string.ascii_letters + string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation |
|
|
|
tokenizer = ByteLevelBPETokenizer() |
|
|
|
tokenizer.train_from_iterator( |
|
[ascii_chars], |
|
vocab_size=len(ascii_chars), |
|
min_frequency=1, |
|
special_tokens=[], |
|
) |
|
|
|
tokenizer.train_from_iterator( |
|
batch_iterator(), |
|
vocab_size=32064, |
|
min_frequency=2, |
|
special_tokens=special_tokens, |
|
) |
|
|
|
tokenizer.save_model('..') |
|
|
|
CHATML_CHAT_TEMPLATE = ( |
|
"{% for message in messages %}" |
|
"{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}" |
|
"{% endfor %}" |
|
"{% if add_generation_prompt %}" |
|
"{{ '<|im_start|>assistant\n' }}" |
|
"{% endif %}" |
|
) |
|
|
|
fast_tokenizer = PreTrainedTokenizerFast( |
|
tokenizer_object=tokenizer, |
|
chat_template=CHATML_CHAT_TEMPLATE, |
|
bos_token='<s>', |
|
eos_token='</s>', |
|
unk_token='<unk>', |
|
pad_token='<pad>', |
|
mask_token='<mask>', |
|
) |
|
|
|
fast_tokenizer.save_pretrained('..') |
|
|