You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

eval.py 1.5 kB

4 years ago
12345678910111213141516171819202122232425262728293031323334
  1. # Copyright 2021 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Evaluation NAML."""
  16. from mindspore.common import set_seed
  17. from mindspore.train.serialization import load_checkpoint
  18. from src.naml import NAML, NAMLWithLossCell
  19. from src.option import get_args
  20. from src.dataset import MINDPreprocess
  21. from src.utils import NAMLMetric, get_metric
  22. if __name__ == '__main__':
  23. args = get_args("eval")
  24. set_seed(args.seed)
  25. net = NAML(args)
  26. net.set_train(False)
  27. net_with_loss = NAMLWithLossCell(net)
  28. load_checkpoint(args.checkpoint_path, net_with_loss)
  29. news_encoder = net.news_encoder
  30. user_encoder = net.user_encoder
  31. metric = NAMLMetric()
  32. mindpreprocess = MINDPreprocess(vars(args), dataset_path=args.eval_dataset_path)
  33. get_metric(args, mindpreprocess, news_encoder, user_encoder, metric)