Spaces:
Sleeping
Sleeping
Update train_model.py
Browse files- train_model.py +10 -4
train_model.py
CHANGED
|
@@ -2,10 +2,11 @@ from transformers import LayoutLMForTokenClassification, Trainer, TrainingArgume
|
|
| 2 |
from datasets import load_dataset
|
| 3 |
|
| 4 |
# Wczytanie przygotowanego zbioru danych
|
| 5 |
-
dataset = load_dataset("json", data_files="training_data.json")
|
|
|
|
| 6 |
|
| 7 |
# Ładowanie modelu LayoutLM do dostrajania
|
| 8 |
-
model = LayoutLMForTokenClassification.from_pretrained("microsoft/layoutlmv3-base", num_labels=
|
| 9 |
|
| 10 |
training_args = TrainingArguments(
|
| 11 |
output_dir="./layoutlmv3_finetuned",
|
|
@@ -13,7 +14,9 @@ training_args = TrainingArguments(
|
|
| 13 |
per_device_eval_batch_size=4,
|
| 14 |
num_train_epochs=5,
|
| 15 |
evaluation_strategy="epoch",
|
| 16 |
-
save_strategy="epoch"
|
|
|
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
trainer = Trainer(
|
|
@@ -25,5 +28,8 @@ trainer = Trainer(
|
|
| 25 |
|
| 26 |
trainer.train()
|
| 27 |
|
| 28 |
-
# Zapisanie modelu
|
| 29 |
model.save_pretrained("./layoutlmv3_finetuned")
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from datasets import load_dataset
|
| 3 |
|
| 4 |
# Wczytanie przygotowanego zbioru danych
|
| 5 |
+
dataset = load_dataset("json", data_files="training_data.json")["train"]
|
| 6 |
+
dataset = dataset.train_test_split(test_size=0.2) # Podział na trening i test
|
| 7 |
|
| 8 |
# Ładowanie modelu LayoutLM do dostrajania
|
| 9 |
+
model = LayoutLMForTokenClassification.from_pretrained("microsoft/layoutlmv3-base", num_labels=10)
|
| 10 |
|
| 11 |
training_args = TrainingArguments(
|
| 12 |
output_dir="./layoutlmv3_finetuned",
|
|
|
|
| 14 |
per_device_eval_batch_size=4,
|
| 15 |
num_train_epochs=5,
|
| 16 |
evaluation_strategy="epoch",
|
| 17 |
+
save_strategy="epoch",
|
| 18 |
+
logging_dir="./logs",
|
| 19 |
+
logging_steps=10
|
| 20 |
)
|
| 21 |
|
| 22 |
trainer = Trainer(
|
|
|
|
| 28 |
|
| 29 |
trainer.train()
|
| 30 |
|
| 31 |
+
# Zapisanie modelu lokalnie
|
| 32 |
model.save_pretrained("./layoutlmv3_finetuned")
|
| 33 |
+
|
| 34 |
+
# Wysłanie modelu do Hugging Face (tylko jeśli masz konto)
|
| 35 |
+
model.push_to_hub("twoj_username/layoutlmv3-finetuned")
|