from transformers import T5ForConditionalGeneration, T5Tokenizer, Trainer, TrainingArguments
from datasets import load_dataset

# Load the pre-trained T5 model and tokenizer
model_name = 't5-base'
tokenizer = T5Tokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)

# Load and prepare the dataset
# For demonstration, we'll use the 'wikisplit' dataset
dataset = load_dataset('wikisplit')

train_data = dataset['train']
val_data = dataset['validation']

def preprocess_data(examples):
    inputs = ["simplify: " + sentence for sentence in examples['input']]
    targets = examples['output']
    model_inputs = tokenizer(inputs, max_length=512, truncation=True, padding='max_length')
    labels = tokenizer(targets, max_length=512, truncation=True, padding='max_length')

    model_inputs['labels'] = labels['input_ids']
    return model_inputs

tokenized_train = train_data.map(preprocess_data, batched=True)
tokenized_val = val_data.map(preprocess_data, batched=True)

# Define training arguments
training_args = TrainingArguments(
    output_dir='./t5-simplification',
    evaluation_strategy='epoch',
    learning_rate=2e-5,
    per_device_train_batch_size=4,
    per_device_eval_batch_size=4,
    num_train_epochs=3,
    weight_decay=0.01,
    save_total_limit=2,
    save_steps=500,
    logging_steps=100,
    fp16=True,  # Enable for faster training if using GPU
)

# Initialize the Trainer
trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=tokenized_train,
    eval_dataset=tokenized_val,
)

# Start Training
trainer.train()

# Save the fine-tuned model
trainer.save_model('./t5-simplification')
tokenizer.save_pretrained('./t5-simplification')

---------------------------------------------------------------------------
DatasetNotFoundError                      Traceback (most recent call last)
Cell In[4], line 11
      7 model = T5ForConditionalGeneration.from_pretrained(model_name)
      9 # Load and prepare the dataset
     10 # For demonstration, we'll use the 'wikisplit' dataset
---> 11 dataset = load_dataset('wikisplit')
     13 train_data = dataset['train']
     14 val_data = dataset['validation']

File /opt/conda/lib/python3.10/site-packages/datasets/load.py:2074, in load_dataset(path, name, data_dir, data_files, split, cache_dir, features, download_config, download_mode, verification_mode, keep_in_memory, save_infos, revision, token, streaming, num_proc, storage_options, trust_remote_code, **config_kwargs)
   2069 verification_mode = VerificationMode(
   2070     (verification_mode or VerificationMode.BASIC_CHECKS) if not save_infos else VerificationMode.ALL_CHECKS
   2071 )
   2073 # Create a dataset builder
-> 2074 builder_instance = load_dataset_builder(
   2075     path=path,
   2076     name=name,
   2077     data_dir=data_dir,
   2078     data_files=data_files,
   2079     cache_dir=cache_dir,
   2080     features=features,
   2081     download_config=download_config,
   2082     download_mode=download_mode,
   2083     revision=revision,
   2084     token=token,
   2085     storage_options=storage_options,
   2086     trust_remote_code=trust_remote_code,
   2087     _require_default_config_name=name is None,
   2088     **config_kwargs,
   2089 )
   2091 # Return iterable dataset in case of streaming
   2092 if streaming:

File /opt/conda/lib/python3.10/site-packages/datasets/load.py:1795, in load_dataset_builder(path, name, data_dir, data_files, cache_dir, features, download_config, download_mode, revision, token, storage_options, trust_remote_code, _require_default_config_name, **config_kwargs)
   1793     download_config = download_config.copy() if download_config else DownloadConfig()
   1794     download_config.storage_options.update(storage_options)
-> 1795 dataset_module = dataset_module_factory(
   1796     path,
   1797     revision=revision,
   1798     download_config=download_config,
   1799     download_mode=download_mode,
   1800     data_dir=data_dir,
   1801     data_files=data_files,
   1802     cache_dir=cache_dir,
   1803     trust_remote_code=trust_remote_code,
   1804     _require_default_config_name=_require_default_config_name,
   1805     _require_custom_configs=bool(config_kwargs),
   1806 )
   1807 # Get dataset builder class from the processing script
   1808 builder_kwargs = dataset_module.builder_kwargs

File /opt/conda/lib/python3.10/site-packages/datasets/load.py:1659, in dataset_module_factory(path, revision, download_config, download_mode, dynamic_modules_path, data_dir, data_files, cache_dir, trust_remote_code, _require_default_config_name, _require_custom_configs, **download_kwargs)
   1657     raise ConnectionError(f"Couldn't reach the Hugging Face Hub for dataset '{path}': {e1}") from None
   1658 if isinstance(e1, (DataFilesNotFoundError, DatasetNotFoundError, EmptyDatasetError)):
-> 1659     raise e1 from None
   1660 if isinstance(e1, FileNotFoundError):
   1661     if trust_remote_code:

File /opt/conda/lib/python3.10/site-packages/datasets/load.py:1597, in dataset_module_factory(path, revision, download_config, download_mode, dynamic_modules_path, data_dir, data_files, cache_dir, trust_remote_code, _require_default_config_name, _require_custom_configs, **download_kwargs)
   1593     raise DatasetNotFoundError(
   1594         f"Revision '{revision}' doesn't exist for dataset '{path}' on the Hub."
   1595     ) from e
   1596 except RepositoryNotFoundError as e:
-> 1597     raise DatasetNotFoundError(f"Dataset '{path}' doesn't exist on the Hub or cannot be accessed.") from e
   1598 if dataset_info.gated:
   1599     try:

DatasetNotFoundError: Dataset 'wikisplit' doesn't exist on the Hub or cannot be accessed.