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.

text.h 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_TEXT_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_TEXT_H_
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include "minddata/dataset/core/constants.h"
  22. #include "minddata/dataset/include/transforms.h"
  23. #include "minddata/dataset/text/vocab.h"
  24. #include "minddata/dataset/util/status.h"
  25. #include "mindspore/ccsrc/minddata/dataset/core/data_type.h"
  26. namespace mindspore {
  27. namespace dataset {
  28. namespace api {
  29. // Transform operations for text
  30. namespace text {
  31. // Text Op classes (in alphabetical order)
  32. class LookupOperation;
  33. /// \brief Lookup operator that looks up a word to an id.
  34. /// \param[in] vocab a Vocab object.
  35. /// \param[in] unknown_token word to use for lookup if the word being looked up is out of Vocabulary (oov).
  36. /// If unknown_token is oov, runtime error will be thrown.
  37. /// \param[in] DataType type of the tensor after lookup, typically int32.
  38. /// \return Shared pointer to the current TensorOperation.
  39. std::shared_ptr<LookupOperation> Lookup(const std::shared_ptr<Vocab> &vocab, const std::string &unknown_token,
  40. const mindspore::dataset::DataType &data_type = DataType("int32"));
  41. /* ####################################### Derived TensorOperation classes ################################# */
  42. class LookupOperation : public TensorOperation {
  43. public:
  44. explicit LookupOperation(const std::shared_ptr<Vocab> &vocab, const std::string &unknown_token,
  45. const DataType &data_type);
  46. ~LookupOperation() = default;
  47. std::shared_ptr<TensorOp> Build() override;
  48. Status ValidateParams() override;
  49. private:
  50. std::shared_ptr<Vocab> vocab_;
  51. std::string unknown_token_;
  52. int32_t default_id_;
  53. DataType data_type_;
  54. };
  55. } // namespace text
  56. } // namespace api
  57. } // namespace dataset
  58. } // namespace mindspore
  59. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_INCLUDE_TEXT_H_