Skip to content
Snippets Groups Projects
Commit 8ef10463 authored by kulcsar's avatar kulcsar
Browse files

document evaluate

parent 69c97729
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,19 @@ metric=evaluate.load("accuracy")
torch.cuda.empty_cache()
def evaluate_model(model, name,test_dataset, learning_rate, batch_size, imdb=False):
def evaluate_model(model, name,test_dataset, batch_size, imdb=False):
"""Evaluation for model. Iterates over test set and computes accuracy, f1, precision
and recall based on outputs of models and true labels.
Params:
model:mode -> model trained in train loop
name:str -> name of the model (for input format)
test_dataset: list of dictionaries -> test dataset
batch_size: int -> batch size for test dataset
imdb: bool -> whether or not imdb dataset is used
Returns: Accuracy, F1, Precision, Recall
"""
torch.cuda.empty_cache()
print("eval swp")
metric=evaluate.combine(["accuracy", "f1", "precision", "recall"])
......@@ -55,29 +67,28 @@ def evaluate_model(model, name,test_dataset, learning_rate, batch_size, imdb=Fal
'end_position': batch[3],
'labels': batch[4]}
outputs=model(**inputs)
print("len of outputs: ", len(outputs))
print("outputs 1: ", outputs[1].size())
print("labels size: ", batch[3].size())
prediction=torch.argmax(outputs[1], dim=-1)
print("prediciton sizes: ", prediction)
outputs=model(**inputs) #get logits
prediction=torch.argmax(outputs[1], dim=-1) #get predictions
if name[0] =="b":
if imdb==False:
metric.add_batch(predictions=prediction, references=batch[5])
else:
print("batch 3: ", batch[3])
metric.add_batch(predictions=prediction, references=batch[3])
if name[0] =="r":
metric.add_batch(predictions=prediction, references=batch[4])
res=metric.compute()
#print(f"learning rate {learning_rate}: ", res)
res=metric.compute()
return res
def compute_metrics(eval_pred):
print("eval salami")
""""Compute metrics function to apply predictions and references to
accuracy, f1, precision and recall, also used in salami train loop.
Params:
eval_pred: tuple ->(logits, labels)
Returns: Accuracy, F1, Precision, Recall"""
metric=evaluate.combine(["accuracy", "f1", "precision", "recall"])
logits, labels=eval_pred
predictions=np.argmax(logits, axis=-1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment