Kevin Fink commited on
Commit
6fdec3f
·
1 Parent(s): 41f77cb
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -38,8 +38,10 @@ def fine_tune_model(model, dataset_name, hub_id, api_key, num_epochs, batch_size
38
  preds = preds[0]
39
  # Replace -100s used for padding as we can't decode them
40
  preds = np.where(preds != -100, preds, tokenizer.pad_token_id)
 
41
  decoded_preds = tokenizer.batch_decode(preds, skip_special_tokens=True)
42
  labels = np.where(labels != -100, labels, tokenizer.pad_token_id)
 
43
  decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)
44
 
45
  result = metric.compute(predictions=decoded_preds, references=decoded_labels, use_stemmer=True)
@@ -47,7 +49,7 @@ def fine_tune_model(model, dataset_name, hub_id, api_key, num_epochs, batch_size
47
  prediction_lens = [np.count_nonzero(pred != tokenizer.pad_token_id) for pred in preds]
48
  result["gen_len"] = np.mean(prediction_lens)
49
  accuracy = accuracy_score(decoded_labels, decoded_preds)
50
- result["accuracy"] = round(accuracy * 100, 4)
51
  return result
52
 
53
  login(api_key.strip())
@@ -70,9 +72,9 @@ def fine_tune_model(model, dataset_name, hub_id, api_key, num_epochs, batch_size
70
  weight_decay=0.01,
71
  #gradient_accumulation_steps=int(grad),
72
  #max_grad_norm = 3.0,
73
- #load_best_model_at_end=True,
74
- #metric_for_best_model="accuracy",
75
- #greater_is_better=True,
76
  logging_dir='/data/logs',
77
  logging_steps=200,
78
  #push_to_hub=True,
@@ -207,8 +209,8 @@ def fine_tune_model(model, dataset_name, hub_id, api_key, num_epochs, batch_size
207
  #return 'RUN AGAIN TO LOAD REST OF DATA'
208
  dataset = load_dataset(dataset_name.strip())
209
  #dataset['train'] = dataset['train'].select(range(8000))
210
- dataset['train'] = dataset['train'].select(range(1000))
211
- dataset['validation'] = dataset['validation'].select(range(100))
212
  train_set = dataset.map(tokenize_function, batched=True)
213
  #valid_set = dataset['validation'].map(tokenize_function, batched=True)
214
 
 
38
  preds = preds[0]
39
  # Replace -100s used for padding as we can't decode them
40
  preds = np.where(preds != -100, preds, tokenizer.pad_token_id)
41
+ preds = np.array(preds)
42
  decoded_preds = tokenizer.batch_decode(preds, skip_special_tokens=True)
43
  labels = np.where(labels != -100, labels, tokenizer.pad_token_id)
44
+ labels = np.array(labels)
45
  decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)
46
 
47
  result = metric.compute(predictions=decoded_preds, references=decoded_labels, use_stemmer=True)
 
49
  prediction_lens = [np.count_nonzero(pred != tokenizer.pad_token_id) for pred in preds]
50
  result["gen_len"] = np.mean(prediction_lens)
51
  accuracy = accuracy_score(decoded_labels, decoded_preds)
52
+ result["eval_accuracy"] = round(accuracy * 100, 4)
53
  return result
54
 
55
  login(api_key.strip())
 
72
  weight_decay=0.01,
73
  #gradient_accumulation_steps=int(grad),
74
  #max_grad_norm = 3.0,
75
+ load_best_model_at_end=True,
76
+ metric_for_best_model="accuracy",
77
+ greater_is_better=True,
78
  logging_dir='/data/logs',
79
  logging_steps=200,
80
  #push_to_hub=True,
 
209
  #return 'RUN AGAIN TO LOAD REST OF DATA'
210
  dataset = load_dataset(dataset_name.strip())
211
  #dataset['train'] = dataset['train'].select(range(8000))
212
+ dataset['train'] = dataset['train'].select(range(4000))
213
+ dataset['validation'] = dataset['validation'].select(range(200))
214
  train_set = dataset.map(tokenize_function, batched=True)
215
  #valid_set = dataset['validation'].map(tokenize_function, batched=True)
216