mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-14 04:44:00 +08:00
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:
@@ -15,5 +15,5 @@
|
|||||||
|
|
||||||
#include "fastdeploy/core/config.h"
|
#include "fastdeploy/core/config.h"
|
||||||
#ifdef ENABLE_TEXT
|
#ifdef ENABLE_TEXT
|
||||||
#include "fastdeploy/text/text_model.h"
|
#include "fastdeploy/text/uie/model.h"
|
||||||
#endif
|
#endif
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "uie.h"
|
#include "fastdeploy/text/uie/model.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
@@ -22,6 +22,9 @@
|
|||||||
#include "faster_tokenizer/pretokenizers/pretokenizer.h"
|
#include "faster_tokenizer/pretokenizers/pretokenizer.h"
|
||||||
#include "faster_tokenizer/utils/utf8.h"
|
#include "faster_tokenizer/utils/utf8.h"
|
||||||
|
|
||||||
|
namespace fastdeploy {
|
||||||
|
namespace text {
|
||||||
|
|
||||||
static std::string DBC2SBC(const std::string& content) {
|
static std::string DBC2SBC(const std::string& content) {
|
||||||
std::string result;
|
std::string result;
|
||||||
size_t content_utf8_len = 0;
|
size_t content_utf8_len = 0;
|
||||||
@@ -644,3 +647,6 @@ void UIEModel::Predict(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace text
|
||||||
|
} // namespace fastdeploy
|
@@ -11,6 +11,7 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@@ -24,7 +25,10 @@
|
|||||||
|
|
||||||
using namespace paddlenlp;
|
using namespace paddlenlp;
|
||||||
|
|
||||||
struct UIEResult {
|
namespace fastdeploy {
|
||||||
|
namespace text {
|
||||||
|
|
||||||
|
struct FASTDEPLOY_DECL UIEResult {
|
||||||
size_t start_;
|
size_t start_;
|
||||||
size_t end_;
|
size_t end_;
|
||||||
double probability_;
|
double probability_;
|
||||||
@@ -35,13 +39,14 @@ struct UIEResult {
|
|||||||
: start_(start), end_(end), probability_(probability), text_(text) {}
|
: start_(start), end_(end), probability_(probability), text_(text) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const UIEResult& result);
|
FASTDEPLOY_DECL std::ostream& operator<<(std::ostream& os,
|
||||||
std::ostream& operator<<(
|
const UIEResult& result);
|
||||||
|
FASTDEPLOY_DECL std::ostream& operator<<(
|
||||||
std::ostream& os,
|
std::ostream& os,
|
||||||
const std::vector<std::unordered_map<std::string, std::vector<UIEResult>>>&
|
const std::vector<std::unordered_map<std::string, std::vector<UIEResult>>>&
|
||||||
results);
|
results);
|
||||||
|
|
||||||
struct SchemaNode {
|
struct FASTDEPLOY_DECL SchemaNode {
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::vector<std::vector<std::string>> prefix_;
|
std::vector<std::vector<std::string>> prefix_;
|
||||||
std::vector<std::vector<UIEResult*>> relations_;
|
std::vector<std::vector<UIEResult*>> relations_;
|
||||||
@@ -82,7 +87,7 @@ struct Schema {
|
|||||||
friend class UIEModel;
|
friend class UIEModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UIEModel {
|
struct FASTDEPLOY_DECL UIEModel {
|
||||||
public:
|
public:
|
||||||
UIEModel(
|
UIEModel(
|
||||||
const std::string& model_file, const std::string& params_file,
|
const std::string& model_file, const std::string& params_file,
|
||||||
@@ -154,3 +159,6 @@ struct UIEModel {
|
|||||||
float position_prob_;
|
float position_prob_;
|
||||||
faster_tokenizer::tokenizers_impl::ErnieFasterTokenizer tokenizer_;
|
faster_tokenizer::tokenizers_impl::ErnieFasterTokenizer tokenizer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace text
|
||||||
|
} // namespace fastdeploy
|
@@ -69,9 +69,10 @@ if(BUILD_EXAMPLES AND ENABLE_TEXT)
|
|||||||
if(EXISTS ${PROJECT_SOURCE_DIR}/examples/text)
|
if(EXISTS ${PROJECT_SOURCE_DIR}/examples/text)
|
||||||
message(STATUS "")
|
message(STATUS "")
|
||||||
message(STATUS "*************FastDeploy Text Examples Summary**********")
|
message(STATUS "*************FastDeploy Text Examples Summary**********")
|
||||||
# TODO(zhoushunjie): will use add_fastdeploy_executable later
|
file(GLOB_RECURSE ALL_TEXT_EXAMPLE_SRCS ${PROJECT_SOURCE_DIR}/examples/text/*.cc)
|
||||||
add_executable(uie_infer_demo ${PROJECT_SOURCE_DIR}/examples/text/uie/cpp/infer.cc ${PROJECT_SOURCE_DIR}/examples/text/uie/cpp/uie.cc)
|
foreach(_CC_FILE ${ALL_TEXT_EXAMPLE_SRCS})
|
||||||
target_link_libraries(uie_infer_demo PUBLIC fastdeploy)
|
add_fastdeploy_executable(text ${_CC_FILE})
|
||||||
|
endforeach()
|
||||||
message(STATUS " [FastDeploy Executable Path] : ${EXECUTABLE_OUTPUT_PATH}")
|
message(STATUS " [FastDeploy Executable Path] : ${EXECUTABLE_OUTPUT_PATH}")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@@ -21,5 +21,5 @@ include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
|
|||||||
|
|
||||||
include_directories(${FASTDEPLOY_INCS})
|
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})
|
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
|
||||||
|
@@ -13,12 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "fastdeploy/function/reduce.h"
|
|
||||||
#include "fastdeploy/function/softmax.h"
|
|
||||||
#include "fastdeploy/text.h"
|
#include "fastdeploy/text.h"
|
||||||
#include "faster_tokenizer/tokenizers/ernie_faster_tokenizer.h"
|
|
||||||
#include "uie.h"
|
|
||||||
|
|
||||||
using namespace paddlenlp;
|
using namespace paddlenlp;
|
||||||
|
|
||||||
@@ -48,8 +45,11 @@ int main(int argc, char* argv[]) {
|
|||||||
std::string model_path = model_dir + sep + "inference.pdmodel";
|
std::string model_path = model_dir + sep + "inference.pdmodel";
|
||||||
std::string param_path = model_dir + sep + "inference.pdiparams";
|
std::string param_path = model_dir + sep + "inference.pdiparams";
|
||||||
std::string vocab_path = model_dir + sep + "vocab.txt";
|
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);
|
{"时间", "选手", "赛事名称"}, option);
|
||||||
fastdeploy::FDINFO << "After init predictor" << std::endl;
|
fastdeploy::FDINFO << "After init predictor" << std::endl;
|
||||||
std::vector<std::unordered_map<std::string, std::vector<UIEResult>>> results;
|
std::vector<std::unordered_map<std::string, std::vector<UIEResult>>> results;
|
||||||
|
Reference in New Issue
Block a user