Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,45 @@
|
|
1 |
-
from transformers import AutoModelForSeq2SeqLM,
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Text2TextGenerationPipeline
|
2 |
+
from transformers import Trainer, TrainingArguments
|
3 |
+
from datasets import load_dataset
|
4 |
+
|
5 |
+
# Load your custom dataset
|
6 |
+
dataset = load_dataset("athirdpath/DPO_Pairs-Roleplay-Alpaca-NSFW")
|
7 |
+
|
8 |
+
# Load the pre-trained model and tokenizer
|
9 |
+
model_name = "facebook/bart-large-cnn"
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
12 |
+
|
13 |
+
# Define training arguments
|
14 |
+
training_args = TrainingArguments(
|
15 |
+
output_dir="./veo_small",
|
16 |
+
num_train_epochs=3,
|
17 |
+
per_device_train_batch_size=4,
|
18 |
+
save_steps=10_000,
|
19 |
+
save_total_limit=2,
|
20 |
+
)
|
21 |
+
|
22 |
+
# Define Trainer
|
23 |
+
trainer = Trainer(
|
24 |
+
model=model,
|
25 |
+
tokenizer=tokenizer,
|
26 |
+
train_dataset=dataset["train"],
|
27 |
+
args=training_args,
|
28 |
+
)
|
29 |
+
|
30 |
+
# Train the model
|
31 |
+
trainer.train()
|
32 |
+
|
33 |
+
# Save the fine-tuned model
|
34 |
+
model.save_pretrained("./veo_small")
|
35 |
+
tokenizer.save_pretrained("./veo_small")
|
36 |
+
|
37 |
+
# Use the fine-tuned model for generation
|
38 |
+
custom_model = AutoModelForSeq2SeqLM.from_pretrained("./veo_small")
|
39 |
+
custom_tokenizer = AutoTokenizer.from_pretrained("./veo_small")
|
40 |
+
generator = Text2TextGenerationPipeline(model=custom_model, tokenizer=custom_tokenizer)
|
41 |
+
|
42 |
+
# Example of model usage
|
43 |
+
prompt = "Hi"
|
44 |
+
output = generator(prompt, max_length=150, num_return_sequences=1)
|
45 |
+
print(output[0]["generated_text"])
|