Skip to content

Commit ded908c

Browse files
lu-wang-gtflite-support-robot
authored andcommitted
TextPreprocesor 2: TextPreprocesor for BertTokenizer
Extracted out the text preprocessing logic from BertNLClassifier and merged it into the TextPreprocessor. PiperOrigin-RevId: 410059736
1 parent 6f25185 commit ded908c

File tree

5 files changed

+257
-158
lines changed

5 files changed

+257
-158
lines changed

tensorflow_lite_support/cc/task/processor/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ cc_library_with_tflite(
115115
"//tensorflow_lite_support/cc/task/core:task_utils",
116116
"//tensorflow_lite_support/cc/text/tokenizers:regex_tokenizer",
117117
"//tensorflow_lite_support/cc/text/tokenizers:tokenizer",
118+
"//tensorflow_lite_support/cc/text/tokenizers:tokenizer_utils",
118119
"//tensorflow_lite_support/cc/utils:common_utils",
119120
"@com_google_absl//absl/memory",
120121
"@com_google_absl//absl/status",
122+
"@com_google_absl//absl/strings",
121123
"@com_google_absl//absl/strings:str_format",
122124
],
123125
)

tensorflow_lite_support/cc/task/processor/processor.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ limitations under the License.
1414
==============================================================================*/
1515
#include "tensorflow_lite_support/cc/task/processor/processor.h"
1616

17+
#include <iterator>
18+
#include <sstream>
19+
1720
namespace tflite {
1821
namespace task {
1922
namespace processor {
@@ -55,6 +58,13 @@ absl::Status Processor::SanityCheck(int num_expected_tensors,
5558
return absl::OkStatus();
5659
}
5760

61+
std::string Processor::GetTensorIndexString() {
62+
std::stringstream stream;
63+
std::copy(tensor_indices_.begin(), tensor_indices_.end(),
64+
std::ostream_iterator<int>(stream, " "));
65+
return stream.str();
66+
}
67+
5868
} // namespace processor
5969
} // namespace task
6070
} // namespace tflite

tensorflow_lite_support/cc/task/processor/processor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class Processor {
9494
return engine_->metadata_extractor();
9595
}
9696

97+
// Gets the tesnor indices in string format.
98+
std::string GetTensorIndexString();
99+
97100
core::TfLiteEngine* engine_;
98101
const std::vector<int> tensor_indices_;
99102

0 commit comments

Comments
 (0)