Spaces:
No application file
No application file
Commit ·
7de47f1
1
Parent(s): 656d89a
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer
|
| 3 |
-
|
| 4 |
-
# Load the data
|
| 5 |
-
train_data = ... # load your training data here
|
| 6 |
-
eval_data = ... # load your evaluation data here
|
| 7 |
-
|
| 8 |
-
# Define the model architecture
|
| 9 |
-
model = AutoModelForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=8)
|
| 10 |
-
|
| 11 |
-
# Set up the training arguments
|
| 12 |
-
training_args = TrainingArguments(
|
| 13 |
-
output_dir='./results',
|
| 14 |
-
num_train_epochs=3,
|
| 15 |
-
per_device_train_batch_size=16,
|
| 16 |
-
per_device_eval_batch_size=64,
|
| 17 |
-
warmup_steps=500,
|
| 18 |
-
weight_decay=0.01,
|
| 19 |
-
logging_dir='./logs',
|
| 20 |
-
logging_first_step=True,
|
| 21 |
-
logging_steps=50,
|
| 22 |
-
save_total_limit=2,
|
| 23 |
-
save_steps=500,
|
| 24 |
-
eval_steps=500,
|
| 25 |
-
learning_rate=5e-5,
|
| 26 |
-
seed=42,
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
# Create the trainer
|
| 30 |
-
trainer = Trainer(
|
| 31 |
-
model=model,
|
| 32 |
-
args=training_args,
|
| 33 |
-
train_dataset=train_data,
|
| 34 |
-
eval_dataset=eval_data,
|
| 35 |
-
compute_metrics=lambda pred: {'accuracy': torch.tensor(pred).argmax().item()},
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
# Train the model
|
| 39 |
-
trainer.train()
|
| 40 |
-
|
| 41 |
-
# Evaluate the model
|
| 42 |
-
loss, metrics = trainer.evaluate()
|
| 43 |
-
print(f'Loss: {loss}')
|
| 44 |
-
print(f'Metrics: {metrics}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|