Skip to content

Commit cc5cf4c

Browse files
Move uie to fd (PaddlePaddle#166)
* Move uie to fd * Add using namespace * remove fastdeploy::text:: Co-authored-by: Jason <[email protected]>
1 parent e85a4c4 commit cc5cf4c

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed

csrc/fastdeploy/text.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515

1616
#include "fastdeploy/core/config.h"
1717
#ifdef ENABLE_TEXT
18-
#include "fastdeploy/text/text_model.h"
18+
#include "fastdeploy/text/uie/model.h"
1919
#endif

examples/text/uie/cpp/uie.cc renamed to csrc/fastdeploy/text/uie/model.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "uie.h"
15+
#include "fastdeploy/text/uie/model.h"
1616
#include <algorithm>
1717
#include <codecvt>
1818
#include <locale>
@@ -22,6 +22,9 @@
2222
#include "faster_tokenizer/pretokenizers/pretokenizer.h"
2323
#include "faster_tokenizer/utils/utf8.h"
2424

25+
namespace fastdeploy {
26+
namespace text {
27+
2528
static std::string DBC2SBC(const std::string& content) {
2629
std::string result;
2730
size_t content_utf8_len = 0;
@@ -644,3 +647,6 @@ void UIEModel::Predict(
644647
}
645648
}
646649
}
650+
651+
} // namespace text
652+
} // namespace fastdeploy

examples/text/uie/cpp/uie.h renamed to csrc/fastdeploy/text/uie/model.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
#pragma once
1516

1617
#include <ostream>
@@ -24,7 +25,10 @@
2425

2526
using namespace paddlenlp;
2627

27-
struct UIEResult {
28+
namespace fastdeploy {
29+
namespace text {
30+
31+
struct FASTDEPLOY_DECL UIEResult {
2832
size_t start_;
2933
size_t end_;
3034
double probability_;
@@ -35,13 +39,14 @@ struct UIEResult {
3539
: start_(start), end_(end), probability_(probability), text_(text) {}
3640
};
3741

38-
std::ostream& operator<<(std::ostream& os, const UIEResult& result);
39-
std::ostream& operator<<(
42+
FASTDEPLOY_DECL std::ostream& operator<<(std::ostream& os,
43+
const UIEResult& result);
44+
FASTDEPLOY_DECL std::ostream& operator<<(
4045
std::ostream& os,
4146
const std::vector<std::unordered_map<std::string, std::vector<UIEResult>>>&
4247
results);
4348

44-
struct SchemaNode {
49+
struct FASTDEPLOY_DECL SchemaNode {
4550
std::string name_;
4651
std::vector<std::vector<std::string>> prefix_;
4752
std::vector<std::vector<UIEResult*>> relations_;
@@ -82,7 +87,7 @@ struct Schema {
8287
friend class UIEModel;
8388
};
8489

85-
struct UIEModel {
90+
struct FASTDEPLOY_DECL UIEModel {
8691
public:
8792
UIEModel(
8893
const std::string& model_file, const std::string& params_file,
@@ -154,3 +159,6 @@ struct UIEModel {
154159
float position_prob_;
155160
faster_tokenizer::tokenizers_impl::ErnieFasterTokenizer tokenizer_;
156161
};
162+
163+
} // namespace text
164+
} // namespace fastdeploy

examples/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ if(BUILD_EXAMPLES AND ENABLE_TEXT)
6969
if(EXISTS ${PROJECT_SOURCE_DIR}/examples/text)
7070
message(STATUS "")
7171
message(STATUS "*************FastDeploy Text Examples Summary**********")
72-
# TODO(zhoushunjie): will use add_fastdeploy_executable later
73-
add_executable(uie_infer_demo ${PROJECT_SOURCE_DIR}/examples/text/uie/cpp/infer.cc ${PROJECT_SOURCE_DIR}/examples/text/uie/cpp/uie.cc)
74-
target_link_libraries(uie_infer_demo PUBLIC fastdeploy)
72+
file(GLOB_RECURSE ALL_TEXT_EXAMPLE_SRCS ${PROJECT_SOURCE_DIR}/examples/text/*.cc)
73+
foreach(_CC_FILE ${ALL_TEXT_EXAMPLE_SRCS})
74+
add_fastdeploy_executable(text ${_CC_FILE})
75+
endforeach()
7576
message(STATUS " [FastDeploy Executable Path] : ${EXECUTABLE_OUTPUT_PATH}")
7677
endif()
7778
endif()

examples/text/uie/cpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
2121

2222
include_directories(${FASTDEPLOY_INCS})
2323

24-
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc ${PROJECT_SOURCE_DIR}/uie.cc)
24+
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
2525
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})

examples/text/uie/cpp/infer.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
// limitations under the License.
1414
#include <iostream>
1515
#include <sstream>
16+
#include <vector>
1617

17-
#include "fastdeploy/function/reduce.h"
18-
#include "fastdeploy/function/softmax.h"
1918
#include "fastdeploy/text.h"
20-
#include "faster_tokenizer/tokenizers/ernie_faster_tokenizer.h"
21-
#include "uie.h"
2219

2320
using namespace paddlenlp;
2421

@@ -48,9 +45,12 @@ int main(int argc, char* argv[]) {
4845
std::string model_path = model_dir + sep + "inference.pdmodel";
4946
std::string param_path = model_dir + sep + "inference.pdiparams";
5047
std::string vocab_path = model_dir + sep + "vocab.txt";
48+
using fastdeploy::text::SchemaNode;
49+
using fastdeploy::text::UIEResult;
5150

52-
auto predictor = UIEModel(model_path, param_path, vocab_path, 0.5, 128,
53-
{"时间", "选手", "赛事名称"}, option);
51+
auto predictor =
52+
fastdeploy::text::UIEModel(model_path, param_path, vocab_path, 0.5, 128,
53+
{"时间", "选手", "赛事名称"}, option);
5454
fastdeploy::FDINFO << "After init predictor" << std::endl;
5555
std::vector<std::unordered_map<std::string, std::vector<UIEResult>>> results;
5656
// Named Entity Recognition

0 commit comments

Comments
 (0)