<jupyter_start><jupyter_text>Токенизация + векторизация

Загрузим токенизатор для XLNet из HuggingFace Transformers.

Мы будем использовать предобученную модель [XLNet base cased](https://huggingface.co/xlnet-base-cased)<jupyter_code>from transformers import XLNetTokenizerFast
tokenizer = XLNetTokenizerFast.from_pretrained('xlnet-base-cased')<jupyter_output><empty_output><jupyter_text>Посмотрим, как работает быстрый токенизатор<jupyter_code>tokenizer('Hi! Have a nice day 👍')<jupyter_output><empty_output><jupyter_text>"Упакуем" наши сеты для обучения сети<jupyter_code>from transformers import LineByLineTextDataset, DataCollatorForLanguageModeling

def load_dataset(train_path, val_path, test_path, tokenizer):
    train_dataset = LineByLineTextDataset(
          tokenizer = tokenizer,
          file_path = train_path,
          block_size = 128)
     
    val_dataset = LineByLineTextDataset(
          tokenizer = tokenizer,
          file_path = val_path,
          block_size = 128)

    test_dataset = LineByLineTextDataset(
          tokenizer = tokenizer,
          file_path = test_path,
          block_size = 128)   
    
    data_collator = DataCollatorForLanguageModeling(
        tokenizer = tokenizer, mlm = False)

    return train_dataset, val_dataset, test_dataset, data_collator

train_dataset, val_dataset, test_dataset, data_collator = load_dataset('train.txt', 'val.txt', 'test.txt', tokenizer)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07718348002708192, 'fraction_numerical': 0.006093432633716994, 'mean_word_length': 4.259786476868327, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '559773', 'license': 'Apache-2.0', 'n_tokens_mistral': 509, 'n_tokens_neox': 499, 'n_words': 88, 'path': 'Tokenization_Vectorization.ipynb', 'repo_name': 'vifirsanova/XLNet-Text-Generation', 'size': '1477'}