asahi417 commited on
Commit
1b10b57
1 Parent(s): c28734d

Update lm_finetuning.py

Browse files
Files changed (1) hide show
  1. lm_finetuning.py +34 -3
lm_finetuning.py CHANGED
@@ -40,6 +40,28 @@ logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', level=logg
40
 
41
  PARALLEL = bool(int(os.getenv("PARALLEL", 1)))
42
  RAY_RESULTS = os.getenv("RAY_RESULTS", "ray_results")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
 
45
  def internet_connection(host='http://google.com'):
@@ -105,6 +127,8 @@ def main():
105
  tokenizer = AutoTokenizer.from_pretrained(opt.model, local_files_only=not network)
106
  model = AutoModelForSequenceClassification.from_pretrained(
107
  opt.model,
 
 
108
  num_labels=len(dataset[opt.split_train]['label'][0]),
109
  local_files_only=not network,
110
  problem_type="multi_label_classification"
@@ -129,7 +153,8 @@ def main():
129
  eval_dataset=tokenized_datasets[opt.split_validation],
130
  compute_metrics=compute_metric_search,
131
  model_init=lambda x: AutoModelForSequenceClassification.from_pretrained(
132
- opt.model, return_dict=True, num_labels=len(dataset[opt.split_train]['label'][0]))
 
133
  )
134
  # parameter search
135
  if PARALLEL:
@@ -166,7 +191,10 @@ def main():
166
  best_model_path,
167
  num_labels=len(dataset[opt.split_train]['label'][0]),
168
  local_files_only=not network,
169
- problem_type="multi_label_classification")
 
 
 
170
  trainer = Trainer(
171
  model=model,
172
  args=TrainingArguments(
@@ -182,7 +210,10 @@ def main():
182
  return_dict=True,
183
  num_labels=len(dataset[opt.split_train]['label'][0]),
184
  local_files_only=not network,
185
- problem_type="multi_label_classification")
 
 
 
186
  )
187
  summary_file = pj(opt.output_dir, opt.summary_file)
188
  if not opt.skip_eval:
 
40
 
41
  PARALLEL = bool(int(os.getenv("PARALLEL", 1)))
42
  RAY_RESULTS = os.getenv("RAY_RESULTS", "ray_results")
43
+ LABEL2ID = {
44
+ "arts_&_culture": 0,
45
+ "business_&_entrepreneurs": 1,
46
+ "celebrity_&_pop_culture": 2,
47
+ "diaries_&_daily_life": 3,
48
+ "family": 4,
49
+ "fashion_&_style": 5,
50
+ "film_tv_&_video": 6,
51
+ "fitness_&_health": 7,
52
+ "food_&_dining": 8,
53
+ "gaming": 9,
54
+ "learning_&_educational": 10,
55
+ "music": 11,
56
+ "news_&_social_concern": 12,
57
+ "other_hobbies": 13,
58
+ "relationships": 14,
59
+ "science_&_technology": 15,
60
+ "sports": 16,
61
+ "travel_&_adventure": 17,
62
+ "youth_&_student_life": 18
63
+ }
64
+ ID2LABEL = {v: k for k, v in LABEL2ID.items()}
65
 
66
 
67
  def internet_connection(host='http://google.com'):
 
127
  tokenizer = AutoTokenizer.from_pretrained(opt.model, local_files_only=not network)
128
  model = AutoModelForSequenceClassification.from_pretrained(
129
  opt.model,
130
+ id2label=ID2LABEL,
131
+ label2id=LABEL2ID,
132
  num_labels=len(dataset[opt.split_train]['label'][0]),
133
  local_files_only=not network,
134
  problem_type="multi_label_classification"
 
153
  eval_dataset=tokenized_datasets[opt.split_validation],
154
  compute_metrics=compute_metric_search,
155
  model_init=lambda x: AutoModelForSequenceClassification.from_pretrained(
156
+ opt.model, return_dict=True, num_labels=len(dataset[opt.split_train]['label'][0])),
157
+ id2label=ID2LABEL, label2id=LABEL2ID,
158
  )
159
  # parameter search
160
  if PARALLEL:
 
191
  best_model_path,
192
  num_labels=len(dataset[opt.split_train]['label'][0]),
193
  local_files_only=not network,
194
+ problem_type="multi_label_classification",
195
+ id2label=ID2LABEL,
196
+ label2id=LABEL2ID
197
+ )
198
  trainer = Trainer(
199
  model=model,
200
  args=TrainingArguments(
 
210
  return_dict=True,
211
  num_labels=len(dataset[opt.split_train]['label'][0]),
212
  local_files_only=not network,
213
+ problem_type="multi_label_classification",
214
+ id2label=ID2LABEL,
215
+ label2id=LABEL2ID
216
+ )
217
  )
218
  summary_file = pj(opt.output_dir, opt.summary_file)
219
  if not opt.skip_eval: