Datasets:

Languages:
English
ArXiv:
License:
asahi417 commited on
Commit
9a436ff
1 Parent(s): cf0381f

Update lm_finetuning.py

Browse files
Files changed (1) hide show
  1. lm_finetuning.py +8 -6
lm_finetuning.py CHANGED
@@ -23,6 +23,7 @@ import argparse
23
  import json
24
  import logging
25
  import os
 
26
  import shutil
27
  import urllib.request
28
  import multiprocessing
@@ -49,6 +50,10 @@ def internet_connection(host='http://google.com'):
49
  return False
50
 
51
 
 
 
 
 
52
  def get_metrics():
53
  metric_accuracy = load_metric("accuracy", "multilabel")
54
  metric_f1 = load_metric("f1", "multilabel")
@@ -58,17 +63,14 @@ def get_metrics():
58
 
59
  def compute_metric_search(eval_pred):
60
  logits, labels = eval_pred
61
- print('metric')
62
- print(labels)
63
- print(logits)
64
- predictions = np.argmax(logits, axis=-1)
65
- print(predictions)
66
  print(labels.shape, logits.shape, predictions.shape)
67
  return metric_f1.compute(predictions=predictions, references=labels, average='micro')
68
 
69
  def compute_metric_all(eval_pred):
70
  logits, labels = eval_pred
71
- predictions = np.argmax(logits, axis=-1)
 
72
  return {
73
  'f1': metric_f1.compute(predictions=predictions, references=labels, average='micro')['f1'],
74
  'f1_macro': metric_f1.compute(predictions=predictions, references=labels, average='macro')['f1'],
 
23
  import json
24
  import logging
25
  import os
26
+ import math
27
  import shutil
28
  import urllib.request
29
  import multiprocessing
 
50
  return False
51
 
52
 
53
+ def sigmoid(x):
54
+ return 1 / (1 + math.exp(-x))
55
+
56
+
57
  def get_metrics():
58
  metric_accuracy = load_metric("accuracy", "multilabel")
59
  metric_f1 = load_metric("f1", "multilabel")
 
63
 
64
  def compute_metric_search(eval_pred):
65
  logits, labels = eval_pred
66
+ predictions = np.array([[int(sigmoid(j) > 0.5) for j in i] for i in logits])
 
 
 
 
67
  print(labels.shape, logits.shape, predictions.shape)
68
  return metric_f1.compute(predictions=predictions, references=labels, average='micro')
69
 
70
  def compute_metric_all(eval_pred):
71
  logits, labels = eval_pred
72
+ predictions = np.array([[int(sigmoid(j) > 0.5) for j in i] for i in logits])
73
+ print(labels.shape, logits.shape, predictions.shape)
74
  return {
75
  'f1': metric_f1.compute(predictions=predictions, references=labels, average='micro')['f1'],
76
  'f1_macro': metric_f1.compute(predictions=predictions, references=labels, average='macro')['f1'],