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.

clue_op_test.cc 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <iostream>
  17. #include <memory>
  18. #include <vector>
  19. #include "minddata/dataset/core/client.h"
  20. #include "common/common.h"
  21. #include "utils/ms_utils.h"
  22. #include "gtest/gtest.h"
  23. #include "utils/log_adapter.h"
  24. #include "minddata/dataset/engine/datasetops/source/clue_op.h"
  25. #include "minddata/dataset/util/status.h"
  26. namespace common = mindspore::common;
  27. using namespace mindspore::dataset;
  28. using mindspore::MsLogLevel::INFO;
  29. using mindspore::ExceptionType::NoExceptionType;
  30. using mindspore::LogStream;
  31. class MindDataTestCLUEOp : public UT::DatasetOpTesting {
  32. };
  33. TEST_F(MindDataTestCLUEOp, TestCLUEBasic) {
  34. // Start with an empty execution tree
  35. auto tree = std::make_shared<ExecutionTree>();
  36. std::string dataset_path;
  37. dataset_path = datasets_root_path_ + "/testCLUE/afqmc/train.json";
  38. std::map<std::string, std::string> key_map;
  39. key_map["sentence1"] = "sentence1";
  40. key_map["sentence2"] = "sentence2";
  41. key_map["label"] = "label";
  42. std::shared_ptr<ClueOp> op;
  43. ClueOp::Builder builder;
  44. builder.SetClueFilesList({dataset_path})
  45. .SetRowsPerBuffer(16)
  46. .SetOpConnectorSize(2)
  47. .SetColsKeyMap(key_map);
  48. Status rc = builder.Build(&op);
  49. ASSERT_TRUE(rc.IsOk());
  50. rc = tree->AssociateNode(op);
  51. ASSERT_TRUE(rc.IsOk());
  52. rc = tree->AssignRoot(op);
  53. ASSERT_TRUE(rc.IsOk());
  54. MS_LOG(INFO) << "Launching tree and begin iteration.";
  55. rc = tree->Prepare();
  56. ASSERT_TRUE(rc.IsOk());
  57. rc = tree->Launch();
  58. ASSERT_TRUE(rc.IsOk());
  59. // Start the loop of reading tensors from our pipeline
  60. DatasetIterator di(tree);
  61. TensorRow tensor_list;
  62. rc = di.FetchNextTensorRow(&tensor_list);
  63. ASSERT_TRUE(rc.IsOk());
  64. int row_count = 0;
  65. while (!tensor_list.empty()) {
  66. // Display the tensor by calling the printer on it
  67. for (int i = 0; i < tensor_list.size(); i++) {
  68. std::ostringstream ss;
  69. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  70. MS_LOG(INFO) << "Tensor print: " << ss.str() << ".";
  71. }
  72. rc = di.FetchNextTensorRow(&tensor_list);
  73. ASSERT_TRUE(rc.IsOk());
  74. row_count++;
  75. }
  76. ASSERT_EQ(row_count, 3);
  77. }
  78. TEST_F(MindDataTestCLUEOp, TestTotalRows) {
  79. std::string tf_file1 = datasets_root_path_ + "/testCLUE/afqmc/train.json";
  80. std::string tf_file2 = datasets_root_path_ + "/testCLUE/afqmc/dev.json";
  81. std::vector<std::string> files;
  82. files.push_back(tf_file1);
  83. int64_t total_rows = 0;
  84. ClueOp::CountAllFileRows(files, &total_rows);
  85. ASSERT_EQ(total_rows, 3);
  86. files.clear();
  87. files.push_back(tf_file2);
  88. ClueOp::CountAllFileRows(files, &total_rows);
  89. ASSERT_EQ(total_rows, 3);
  90. files.clear();
  91. files.push_back(tf_file1);
  92. files.push_back(tf_file2);
  93. ClueOp::CountAllFileRows(files, &total_rows);
  94. ASSERT_EQ(total_rows, 6);
  95. files.clear();
  96. }