RabbitRedux / train_and_save_model.py
Canstralian's picture
Update train_and_save_model.py
787a425 verified
raw
history blame
1.59 kB
from datasets import load_dataset
from transformers import AutoAdapterModel, AutoTokenizer, Trainer, TrainingArguments
# Load datasets
dataset_pentesting = load_dataset("canstralian/pentesting-ai")
dataset_redpajama = load_dataset("togethercomputer/RedPajama-Data-1T")
# Tokenizer
tokenizer = AutoTokenizer.from_pretrained("canstralian/rabbitredeux")
def tokenize_function(examples):
return tokenizer(examples['text'], padding="max_length", truncation=True)
# Tokenize datasets
tokenized_dataset_pentesting = dataset_pentesting.map(tokenize_function, batched=True)
tokenized_dataset_redpajama = dataset_redpajama.map(tokenize_function, batched=True)
# Prepare datasets
train_dataset_pentesting = tokenized_dataset_pentesting["train"]
validation_dataset_pentesting = tokenized_dataset_pentesting["validation"]
# Load model and adapter
model = AutoAdapterModel.from_pretrained("canstralian/rabbitredeux")
model.load_adapter("Canstralian/RabbitRedux", set_active=True)
# Training arguments
training_args = TrainingArguments(
output_dir="./results",
num_train_epochs=3,
per_device_train_batch_size=8,
per_device_eval_batch_size=8,
warmup_steps=500,
weight_decay=0.01,
logging_dir="./logs",
logging_steps=10,
evaluation_strategy="epoch",
)
# Trainer setup
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset_pentesting,
eval_dataset=validation_dataset_pentesting,
)
# Training
trainer.train()
# Evaluate model
trainer.evaluate()
# Save the fine-tuned model
model.save_pretrained("./fine_tuned_model")