Spaces:
Sleeping
Sleeping
ronald
commited on
Commit
·
9609d1c
1
Parent(s):
043db6a
coh mech
Browse files- ccl_win.py +10 -8
ccl_win.py
CHANGED
|
@@ -133,19 +133,21 @@ class ccl_win(evaluate.Measurement):
|
|
| 133 |
|
| 134 |
model = AutoModelForSequenceClassification.from_pretrained(os.path.join(BASEDIR,dataset))
|
| 135 |
model.to(device)
|
|
|
|
| 136 |
|
| 137 |
pred_list,len_by_sample = self.preprocess_adjacent_window(predictions)
|
| 138 |
|
| 139 |
scores = []
|
| 140 |
n_preds = len(pred_list)
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
| 149 |
results = []
|
| 150 |
offset = 0
|
| 151 |
for _len in len_by_sample:
|
|
|
|
| 133 |
|
| 134 |
model = AutoModelForSequenceClassification.from_pretrained(os.path.join(BASEDIR,dataset))
|
| 135 |
model.to(device)
|
| 136 |
+
model.eval()
|
| 137 |
|
| 138 |
pred_list,len_by_sample = self.preprocess_adjacent_window(predictions)
|
| 139 |
|
| 140 |
scores = []
|
| 141 |
n_preds = len(pred_list)
|
| 142 |
+
with torch.no_grad():
|
| 143 |
+
for b in range(0,n_preds,batch_size):
|
| 144 |
+
strides = [x.lower() for x in pred_list[b:b+batch_size]]
|
| 145 |
+
tinput = tokenizer(strides,padding=True,truncation=True,max_length=512,return_tensors="pt")
|
| 146 |
+
tinput = {k:v.to(device) for k,v in tinput.items()}
|
| 147 |
+
output = model(**tinput)
|
| 148 |
+
probs = torch.softmax(output.logits,dim=-1).detach().cpu().numpy()
|
| 149 |
+
scores.extend(probs[:,0].tolist())
|
| 150 |
+
#
|
| 151 |
results = []
|
| 152 |
offset = 0
|
| 153 |
for _len in len_by_sample:
|