from this code for question generation task 

# Split the data into train, test, and validation sets
train_data, test_data = train_test_split(df[:100000], test_size=0.2, random_state=42)
train_data, val_data = train_test_split(train_data, test_size=0.1, random_state=42)
​
# Convert the DataFrames to Hugging Face Datasets
train_dataset = Dataset.from_pandas(train_data)
val_dataset = Dataset.from_pandas(val_data)
test_dataset = Dataset.from_pandas(test_data)
add Codeadd Markdown
# Tokenizer for sequence-to-sequence models
#tokenizer = AutoTokenizer.from_pretrained("t5-small")
# Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers import GPT2Tokenizer, GPT2LMHeadModel
​
tokenizer = GPT2Tokenizer.from_pretrained("aubmindlab/aragpt2-base")
tokenizer.pad_token = tokenizer.eos_token  # Set EOS token as the padding token
model = GPT2LMHeadModel.from_pretrained("aubmindlab/aragpt2-base")
#tokenizer = AutoTokenizer.from_pretrained("UBC-NLP/AraT5-base")#flax-community/arabic-t5-small")
#model = AutoModelForSeq2SeqLM.from_pretrained("UBC-NLP/AraT5-base")#flax-community/arabic-t5-small")
add Codeadd Markdown
# Load model directly
#from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
​
#tokenizer = AutoTokenizer.from_pretrained("MIIB-NLP/Arabic-question-generation")
#model = AutoModelForSeq2SeqLM.from_pretrained("MIIB-NLP/Arabic-question-generation")
add Codeadd Markdown
#
# Define a preprocess function for the question generation task
def preprocess_function(examples):
    inputs = tokenizer(
        examples["positive"],
        max_length=128,
        truncation=True,
        padding="max_length",
        #return_offsets_mapping=True,
    )
    targets = tokenizer(
        examples["query"],
        max_length=64,  # Adjust as needed
        truncation=True,
        padding="max_length",
        #return_offsets_mapping=True,
    )
​
    inputs["labels"] = targets["input_ids"]
    inputs["decoder_attention_mask"] = targets["attention_mask"]
    return inputs
add Codeadd Markdown
# Apply preprocess function to train, val, and test datasets
tokenized_train_dataset = train_dataset.map(preprocess_function, batched=True)
tokenized_val_dataset = val_dataset.map(preprocess_function, batched=True)
tokenized_test_dataset = test_dataset.map(preprocess_function, batched=True)
100%
72/72 [01:20<00:00, 1.01ba/s]
100%
8/8 [00:07<00:00, 1.04ba/s]
100%
20/20 [00:19<00:00, 1.04ba/s]
add Codeadd Markdown
# Define data collator for sequence-to-sequence models
#data_collator = DataCollatorForSeq2Seq(tokenizer)#, model_type="t5"
from transformers import DataCollatorForLanguageModeling
​
data_collator = DataCollatorForLanguageModeling(
    tokenizer=tokenizer, mlm=False  # Set mlm to True if you are doing masked language modeling
)
​
add Codeadd Markdown
from transformers import GPT2LMHeadModel, GPT2Tokenizer, GPT2Config
from transformers import Trainer, TrainingArguments
from transformers import EarlyStoppingCallback
from torch.nn import CrossEntropyLoss
​
# Assuming you have defined your model, tokenizer, datasets, and data_collator
​
# Define your TrainingArguments
training_args = TrainingArguments(
    output_dir="./question_generation_model_aragpt_8",
    num_train_epochs=2,
    per_device_train_batch_size=8,
    per_device_eval_batch_size=8,
    save_total_limit=1,  # Save only the last checkpoint
    #learning_rate=5e-5,
    evaluation_strategy="epoch",  # Change evaluation strategy to "steps"
    report_to=[],  # Set report_to to an empty list to disable wandb logging
)
​
# Create the EarlyStoppingCallback
# early_stopping = EarlyStoppingCallback(early_stopping_patience=3, early_stopping_threshold=0.005)
​
# Model trainer
trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=tokenized_train_dataset,
    eval_dataset=tokenized_val_dataset,
    tokenizer=tokenizer,
    data_collator=data_collator,
    # callbacks=[early_stopping],  # Add the EarlyStoppingCallback if needed
)
​
add Codeadd Markdown
# Training loop without explicit train_step
for epoch in range(training_args.num_train_epochs):
    print(f"Epoch {epoch + 1}/{training_args.num_train_epochs}")
    for step, inputs in enumerate(trainer.get_train_dataloader()):
        print(
            f"Step {step}, Input Shape: {inputs['input_ids'].shape}, Target Shape: {inputs['labels'].shape}"
        )
        # Rest of your training code
        trainer.train()
​
# Finally, trigger evaluation after the training loop if needed
results = trainer.evaluate()
Epoch 1/2
Step 0, Input Shape: torch.Size([8, 128]), Target Shape: torch.Size([8, 128])

i get this result  [17193/18000 53:54 < 02:31, 5.31 it/s, Epoch 1.91/2]
Epoch	Training Loss	Validation Loss
1	4.295300	3.948071 
how to enhance result