Spaces:
Runtime error
Runtime error
lachie0232
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import Trainer, TrainingArguments, DeepSeekForQuestionAnswering, DeepSeekTokenizer
|
2 |
+
from datasets import load_dataset
|
3 |
+
|
4 |
+
# Load the DeepSeek model and tokenizer
|
5 |
+
model = DeepSeekForQuestionAnswering.from_pretrained("DeepSeek/DeepSeek-v3")
|
6 |
+
tokenizer = DeepSeekTokenizer.from_pretrained("DeepSeek/DeepSeek-v3")
|
7 |
+
|
8 |
+
# Load dataset
|
9 |
+
dataset = load_dataset("json", data_files={"train": "your_dataset_train.json", "test": "your_dataset_test.json"})
|
10 |
+
|
11 |
+
# Tokenize the dataset
|
12 |
+
def tokenize_function(examples):
|
13 |
+
return tokenizer(examples['question'], examples['document'], truncation=True, padding=True)
|
14 |
+
|
15 |
+
tokenized_datasets = dataset.map(tokenize_function, batched=True)
|
16 |
+
|
17 |
+
# Set up the training arguments
|
18 |
+
training_args = TrainingArguments(
|
19 |
+
output_dir='./results',
|
20 |
+
evaluation_strategy="epoch",
|
21 |
+
learning_rate=2e-5,
|
22 |
+
per_device_train_batch_size=16,
|
23 |
+
per_device_eval_batch_size=16,
|
24 |
+
num_train_epochs=3,
|
25 |
+
weight_decay=0.01
|
26 |
+
)
|
27 |
+
|
28 |
+
# Initialize Trainer
|
29 |
+
trainer = Trainer(
|
30 |
+
model=model,
|
31 |
+
args=training_args,
|
32 |
+
train_dataset=tokenized_datasets['train'],
|
33 |
+
eval_dataset=tokenized_datasets['test']
|
34 |
+
)
|
35 |
+
|
36 |
+
# Start the fine-tuning
|
37 |
+
trainer.train()
|
38 |
+
|
39 |
+
# Save the model after fine-tuning
|
40 |
+
model.save_pretrained('./fine_tuned_deepseek')
|