Evaluate
(env)
| 165 | |
| 166 | |
| 167 | def evaluate(env): |
| 168 | """Evaluate""" |
| 169 | args = env.args |
| 170 | puncts = dygraph.to_variable(env.puncts, zero_copy=False) |
| 171 | |
| 172 | logging.info("Load the dataset") |
| 173 | evaluates = Corpus.load(args.test_data_path, env.fields) |
| 174 | dataset = TextDataset(evaluates, env.fields, args.buckets) |
| 175 | # set the data loader |
| 176 | dataset.loader = batchify(dataset, args.batch_size) |
| 177 | |
| 178 | logging.info("{} sentences, ".format(len(dataset)) + "{} batches, ".format(len(dataset.loader)) + |
| 179 | "{} buckets".format(len(dataset.buckets))) |
| 180 | logging.info("Load the model") |
| 181 | model = load(args.model_path) |
| 182 | |
| 183 | logging.info("Evaluate the dataset") |
| 184 | start = datetime.datetime.now() |
| 185 | loss, metric = epoch_evaluate(args, model, dataset.loader, puncts) |
| 186 | total_time = datetime.datetime.now() - start |
| 187 | logging.info("Loss: {:.4f} {}".format(loss, metric)) |
| 188 | logging.info("{}s elapsed, {:.2f} Sents/s".format(total_time, len(dataset) / total_time.total_seconds())) |
| 189 | |
| 190 | |
| 191 | def predict(env): |
no test coverage detected