Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tinker_cookbook/supervised/nll_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@


class NLLEvaluator(TrainingClientEvaluator):
def __init__(self, data: list[tinker.Datum]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually wouldn't it be better to make the name default to "test", and remove the prefixing of "test" from the training loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's better -- I thought the original code meant to always want "test/" to be the prefix of the log name but that's indeed a bit cumbersome.

def __init__(self, data: list[tinker.Datum], name: str | None = None):
self.name = name
self.data = data

async def __call__(self, training_client: tinker.TrainingClient) -> dict[str, float]:
Expand All @@ -16,9 +17,10 @@ async def __call__(self, training_client: tinker.TrainingClient) -> dict[str, fl
logprobs = [x["logprobs"] for x in result.loss_fn_outputs]
weights = [datum.loss_fn_inputs["weights"] for datum in self.data]
nll = compute_mean_nll(logprobs, weights)
return {"nll": nll}
key = "nll" if self.name is None else f"{self.name}/nll"
return {key: nll}

@classmethod
def from_dataset(cls, dataset: SupervisedDataset) -> "NLLEvaluator":
def from_dataset(cls, dataset: SupervisedDataset, name: str | None = None) -> "NLLEvaluator":
all_data = list(itertools.chain(*[dataset.get_batch(i) for i in range(len(dataset))]))
return cls(all_data)
return cls(all_data, name=name)
Loading