text_model.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  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. #pragma once
  15. #include <memory>
  16. #include "ultra_infer/ultra_infer_model.h"
  17. #include "ultra_infer/utils/unique_ptr.h"
  18. namespace ultra_infer {
  19. namespace text {
  20. class Preprocessor;
  21. class Postprocessor;
  22. class Result;
  23. class PredictionOption;
  24. class ULTRAINFER_DECL TextModel : public UltraInferModel {
  25. public:
  26. virtual std::string ModelName() const { return "TextModel"; }
  27. virtual bool Predict(const std::string &raw_text, Result *result,
  28. const PredictionOption &option);
  29. virtual bool PredictBatch(const std::vector<std::string> &raw_text_array,
  30. Result *result, const PredictionOption &option);
  31. template <typename T, typename... Args> void SetPreprocessor(Args &&...args) {
  32. preprocessor_ = utils::make_unique<T>(std::forward<Args>(args)...);
  33. }
  34. template <typename T, typename... Args>
  35. void SetPostprocessor(Args &&...args) {
  36. postprocessor_ = utils::make_unique<T>(std::forward<Args>(args)...);
  37. }
  38. private:
  39. std::unique_ptr<Preprocessor> preprocessor_;
  40. std::unique_ptr<Postprocessor> postprocessor_;
  41. };
  42. } // namespace text
  43. } // namespace ultra_infer