MCPcopy Create free account
hub / github.com/awslabs/gap-text2sql / _eval_model

Method _eval_model

rat-sql-gap/seq2struct/commands/train.py:216–237  ·  view source on GitHub ↗
(logger, model, last_step, eval_data_loader, eval_section, num_eval_items=None)

Source from the content-addressed store, hash-verified

214
215 @staticmethod
216 def _eval_model(logger, model, last_step, eval_data_loader, eval_section, num_eval_items=None):
217 stats = collections.defaultdict(float)
218 model.eval()
219 with torch.no_grad():
220 for eval_batch in eval_data_loader:
221 batch_res = model.eval_on_batch(eval_batch)
222 for k, v in batch_res.items():
223 stats[k] += v
224 if num_eval_items and stats['total'] > num_eval_items:
225 break
226 model.train()
227
228 # Divide each stat by 'total'
229 for k in stats:
230 if k != 'total':
231 stats[k] /= stats['total']
232 if 'total' in stats:
233 del stats['total']
234
235 logger.log("Step {} stats, {}: {}".format(
236 last_step, eval_section, ", ".join(
237 "{} = {}".format(k, v) for k, v in stats.items())))
238
239def add_parser():
240 parser = argparse.ArgumentParser()

Callers 1

trainMethod · 0.95

Calls 3

eval_on_batchMethod · 0.80
logMethod · 0.80
trainMethod · 0.45

Tested by

no test coverage detected