Move uie to fd (#166)

* Move uie to fd

* Add using namespace

* remove fastdeploy::text::

Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
Jack Zhou
2022-08-29 21:31:09 +08:00
committed by GitHub
parent e85a4c4f5b
commit cc5cf4c2ef
6 changed files with 32 additions and 17 deletions

View File

@@ -15,5 +15,5 @@
#include "fastdeploy/core/config.h"
#ifdef ENABLE_TEXT
#include "fastdeploy/text/text_model.h"
#include "fastdeploy/text/uie/model.h"
#endif

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "uie.h"
#include "fastdeploy/text/uie/model.h"
#include <algorithm>
#include <codecvt>
#include <locale>
@@ -22,6 +22,9 @@
#include "faster_tokenizer/pretokenizers/pretokenizer.h"
#include "faster_tokenizer/utils/utf8.h"
namespace fastdeploy {
namespace text {
static std::string DBC2SBC(const std::string& content) {
std::string result;
size_t content_utf8_len = 0;
@@ -644,3 +647,6 @@ void UIEModel::Predict(
}
}
}
} // namespace text
} // namespace fastdeploy

View File

@@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <ostream>
@@ -24,7 +25,10 @@
using namespace paddlenlp;
struct UIEResult {
namespace fastdeploy {
namespace text {
struct FASTDEPLOY_DECL UIEResult {
size_t start_;
size_t end_;
double probability_;
@@ -35,13 +39,14 @@ struct UIEResult {
: start_(start), end_(end), probability_(probability), text_(text) {}
};
std::ostream& operator<<(std::ostream& os, const UIEResult& result);
std::ostream& operator<<(
FASTDEPLOY_DECL std::ostream& operator<<(std::ostream& os,
const UIEResult& result);
FASTDEPLOY_DECL std::ostream& operator<<(
std::ostream& os,
const std::vector<std::unordered_map<std::string, std::vector<UIEResult>>>&
results);
struct SchemaNode {
struct FASTDEPLOY_DECL SchemaNode {
std::string name_;
std::vector<std::vector<std::string>> prefix_;
std::vector<std::vector<UIEResult*>> relations_;
@@ -82,7 +87,7 @@ struct Schema {
friend class UIEModel;
};
struct UIEModel {
struct FASTDEPLOY_DECL UIEModel {
public:
UIEModel(
const std::string& model_file, const std::string& params_file,
@@ -154,3 +159,6 @@ struct UIEModel {
float position_prob_;
faster_tokenizer::tokenizers_impl::ErnieFasterTokenizer tokenizer_;
};
} // namespace text
} // namespace fastdeploy

View File

@@ -69,9 +69,10 @@ if(BUILD_EXAMPLES AND ENABLE_TEXT)
if(EXISTS ${PROJECT_SOURCE_DIR}/examples/text)
message(STATUS "")
message(STATUS "*************FastDeploy Text Examples Summary**********")
# TODO(zhoushunjie): will use add_fastdeploy_executable later
add_executable(uie_infer_demo ${PROJECT_SOURCE_DIR}/examples/text/uie/cpp/infer.cc ${PROJECT_SOURCE_DIR}/examples/text/uie/cpp/uie.cc)
target_link_libraries(uie_infer_demo PUBLIC fastdeploy)
file(GLOB_RECURSE ALL_TEXT_EXAMPLE_SRCS ${PROJECT_SOURCE_DIR}/examples/text/*.cc)
foreach(_CC_FILE ${ALL_TEXT_EXAMPLE_SRCS})
add_fastdeploy_executable(text ${_CC_FILE})
endforeach()
message(STATUS " [FastDeploy Executable Path] : ${EXECUTABLE_OUTPUT_PATH}")
endif()
endif()

View File

@@ -21,5 +21,5 @@ include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
include_directories(${FASTDEPLOY_INCS})
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc ${PROJECT_SOURCE_DIR}/uie.cc)
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})

View File

@@ -13,12 +13,9 @@
// limitations under the License.
#include <iostream>
#include <sstream>
#include <vector>
#include "fastdeploy/function/reduce.h"
#include "fastdeploy/function/softmax.h"
#include "fastdeploy/text.h"
#include "faster_tokenizer/tokenizers/ernie_faster_tokenizer.h"
#include "uie.h"
using namespace paddlenlp;
@@ -48,8 +45,11 @@ int main(int argc, char* argv[]) {
std::string model_path = model_dir + sep + "inference.pdmodel";
std::string param_path = model_dir + sep + "inference.pdiparams";
std::string vocab_path = model_dir + sep + "vocab.txt";
using fastdeploy::text::SchemaNode;
using fastdeploy::text::UIEResult;
auto predictor = UIEModel(model_path, param_path, vocab_path, 0.5, 128,
auto predictor =
fastdeploy::text::UIEModel(model_path, param_path, vocab_path, 0.5, 128,
{"时间", "选手", "赛事名称"}, option);
fastdeploy::FDINFO << "After init predictor" << std::endl;
std::vector<std::unordered_map<std::string, std::vector<UIEResult>>> results;