Relative Content

Tag Archive for huggingface-transformers

trainer.train doesnt work I am using transformers package and it gives me error like this:

some trash for stackoverflow ai::him,” she said. “He is not nice to anyone. I don’t want to tell stories because they are horrendous. You know, you just don’t talk about it. There are kids and grandkids involved.” When asked to chat about Elon, Errol responded via e-mail: “Elon was a very independent and focused child at home with me. He loved computer science before anyone even knew what it was in South Africa and his ability was widely recognized by the time he was 12 years old. Elon and his brother Kimbal’s activities as children and young men were so many and //////////////////////////////////////////// raceback (most recent call last): File “C:UserstasDesktopKodpythonPDFEXTRACTORtrain22.py”, line 77, in <module> trainer.train() File “C:UserstasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0LocalCachelocal-packagesPython311site-packagestransformerstrainer.py”, line 1780, in train return inner_training_loop( ^^^^^^^^^^^^^^^^^^^^ File “C:UserstasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0LocalCachelocal-packagesPython311site-packagestransformerstrainer.py”, line 2085, in _inner_training_loop for step, inputs in enumerate(epoch_iterator): File “C:UserstasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0LocalCachelocal-packagesPython311site-packagesacceleratedata_loader.py”, line 452, in _iter_ current_batch = next(dataloader_iter) ^^^^^^^^^^^^^^^^^^^^^ File “C:UserstasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0LocalCachelocal-packagesPython311site-packagestorchutilsdatadataloader.py”, line 631, in _next_ data = self._next_data() ^^^^^^^^^^^^^^^^^ File “C:UserstasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0LocalCachelocal-packagesPython311site-packagestorchutilsdatadataloader.py”, line 675, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “C:UserstasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0LocalCachelocal-packagesPython311site-packagestorchutilsdata_utilsfetch.py”, line 51, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “C:UserstasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0LocalCachelocal-packagesPython311site-packagestorchutilsdata_utilsfetch.py”, line 51, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] ~~~~~~~~~~~~^^^^^ File “C:UserstasAppDataLocalPackagesPythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0LocalCachelocal-packagesPython311site-packagesdatasetsdataset_dict.py”, line 80, in _getitem_ raise KeyError( KeyError: “Invalid key: 0. Please first select a split. For example: `my_dataset_dictionary[‘train’][0]`. Available splits: [‘train’]” 0%| | 0/1 [00:00<?, ?it/s] &//////////////////////////////////////////////// varied that it’s difficult to name just one, as they travelled together with me extensively in S. Africa and the world at large, visiting all the continents regularly from the age of six onwards. Elon and his brother and sister were and continue to be exemplary, in every way a father could want. I’m very proud of what Elon’s accomplished.” //////////////////////////////////////////////////////////////////////// HERE is the code:::::::::::::::::::: from tokenizers import ByteLevelBPETokenizer from tokenizers.models import BPE from transformers import GPT2Config, GPT2LMHeadModel,GPT2Tokenizer,DataCollatorForLanguageModeling import torch from tokenizers import Tokenizer tokenizer = Tokenizer(BPE(unk_token=”[x]”)) from torch import nn from datasets import load_dataset from transformers import Trainer,TrainingArguments TRAIN_BASE = False import os paths = [“python_code_text_data.txt”] os.environ[“WANDB_DISABLED”] = “true” if TRAIN_BASE: tokenizer = ByteLevelBPETokenizer() tokenizer.train(files=paths, vocab_size=52_000, min_frequency=2, special_tokens=[ “<s>”, “<pad>”, “</s>”, “<unk>”, “<mask>”, ]) tokenizer.save_model(“tokenizer”) inp = ‘print(“Hello world!”)’ tokenizer = GPT2Tokenizer.from_pretrained(“tokenizer”) # Add special tokens if not already present (assuming tokenizer is loaded from “tokenizer” directory) special_tokens = { “eos_token”: “</s>”, “bos_token”: “<s>”, “unk_token”: “<unk>”, “pad_token”: “<pad>”, “mask_token”: “<mask>”, } if not all(t in tokenizer.get_vocab() for t in special_tokens.values()): tokenizer.add_special_tokens(special_tokens) t = tokenizer.encode(inp) print(t) print(tokenizer.decode(t)) config = GPT2Config( vocab_size=tokenizer.vocab_size, bos_token_id=tokenizer.bos_token_id, eos_token_id=tokenizer.eos_token_id, ) model = GPT2LMHeadModel(config) dataset = load_dataset(“text”, data_files=paths) def encode(lines): return tokenizer(lines[‘text’], add_special_tokens=True, truncation=True, max_length=512) # Corrected typo dataset.set_transform(encode) data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False, mlm_probability=0.15) training_args = TrainingArguments( output_dir=”GPyT”, overwrite_output_dir=True, num_train_epochs=1, per_device_train_batch_size=10, save_steps=100, save_total_limit=2, prediction_loss_only=True, remove_unused_columns=False, report_to=”tensorboard” ) trainer = Trainer( model=model, args=training_args, data_collator=data_collator, train_dataset=dataset, ) #sasa trainer.train() trainer.save_model(“GPyT”)