init
Browse files
experiments/model_finetuning_topic.py
CHANGED
|
@@ -76,9 +76,6 @@ def main(
|
|
| 76 |
best_model_path = pj(output_dir, "best_model")
|
| 77 |
|
| 78 |
tokenizer = AutoTokenizer.from_pretrained(model)
|
| 79 |
-
model = AutoModelForSequenceClassification.from_pretrained(
|
| 80 |
-
model, id2label=ID2LABEL, label2id=LABEL2ID, num_labels=len(LABEL2ID), problem_type="multi_label_classification"
|
| 81 |
-
)
|
| 82 |
dataset = load_dataset(dataset, dataset_type)
|
| 83 |
tokenized_datasets = dataset.map(
|
| 84 |
lambda x: tokenizer(x["text"], padding="max_length", truncation=True, max_length=256), batched=True
|
|
@@ -150,15 +147,14 @@ def main(
|
|
| 150 |
else:
|
| 151 |
metric = {}
|
| 152 |
for single_test in test_split:
|
| 153 |
-
model = AutoModelForSequenceClassification.from_pretrained(
|
| 154 |
-
best_model_path,
|
| 155 |
-
num_labels=len(LABEL2ID),
|
| 156 |
-
problem_type="multi_label_classification",
|
| 157 |
-
id2label=ID2LABEL,
|
| 158 |
-
label2id=LABEL2ID
|
| 159 |
-
)
|
| 160 |
trainer = Trainer(
|
| 161 |
-
model=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
args=TrainingArguments(
|
| 163 |
output_dir=output_dir,
|
| 164 |
evaluation_strategy="no",
|
|
@@ -176,7 +172,7 @@ def main(
|
|
| 176 |
if not skip_upload:
|
| 177 |
logging.info("uploading to huggingface")
|
| 178 |
model_organization = "tweettemposhift"
|
| 179 |
-
|
| 180 |
best_model_path,
|
| 181 |
num_labels=len(LABEL2ID),
|
| 182 |
problem_type="multi_label_classification",
|
|
@@ -184,7 +180,7 @@ def main(
|
|
| 184 |
label2id=LABEL2ID
|
| 185 |
)
|
| 186 |
tokenizer = AutoTokenizer.from_pretrained(best_model_path)
|
| 187 |
-
|
| 188 |
tokenizer.push_to_hub(f"{model_organization}/{model_alias}", use_auth_token=True)
|
| 189 |
repo = Repository(model_alias, f"{model_organization}/{model_alias}")
|
| 190 |
for i in glob(f"{best_model_path}/*"):
|
|
|
|
| 76 |
best_model_path = pj(output_dir, "best_model")
|
| 77 |
|
| 78 |
tokenizer = AutoTokenizer.from_pretrained(model)
|
|
|
|
|
|
|
|
|
|
| 79 |
dataset = load_dataset(dataset, dataset_type)
|
| 80 |
tokenized_datasets = dataset.map(
|
| 81 |
lambda x: tokenizer(x["text"], padding="max_length", truncation=True, max_length=256), batched=True
|
|
|
|
| 147 |
else:
|
| 148 |
metric = {}
|
| 149 |
for single_test in test_split:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
trainer = Trainer(
|
| 151 |
+
model=AutoModelForSequenceClassification.from_pretrained(
|
| 152 |
+
best_model_path,
|
| 153 |
+
num_labels=len(LABEL2ID),
|
| 154 |
+
problem_type="multi_label_classification",
|
| 155 |
+
id2label=ID2LABEL,
|
| 156 |
+
label2id=LABEL2ID
|
| 157 |
+
),
|
| 158 |
args=TrainingArguments(
|
| 159 |
output_dir=output_dir,
|
| 160 |
evaluation_strategy="no",
|
|
|
|
| 172 |
if not skip_upload:
|
| 173 |
logging.info("uploading to huggingface")
|
| 174 |
model_organization = "tweettemposhift"
|
| 175 |
+
model_instance = AutoModelForSequenceClassification.from_pretrained(
|
| 176 |
best_model_path,
|
| 177 |
num_labels=len(LABEL2ID),
|
| 178 |
problem_type="multi_label_classification",
|
|
|
|
| 180 |
label2id=LABEL2ID
|
| 181 |
)
|
| 182 |
tokenizer = AutoTokenizer.from_pretrained(best_model_path)
|
| 183 |
+
model_instance.push_to_hub(f"{model_organization}/{model_alias}", use_auth_token=True)
|
| 184 |
tokenizer.push_to_hub(f"{model_organization}/{model_alias}", use_auth_token=True)
|
| 185 |
repo = Repository(model_alias, f"{model_organization}/{model_alias}")
|
| 186 |
for i in glob(f"{best_model_path}/*"):
|