Skip to content

Commit 6656416

Browse files
lu-wang-gtflite-support-robot
authored andcommitted
Move Task QA into the root dir of task/text
Matching the directory structure of other domains, such as vision and audio PiperOrigin-RevId: 399232179
1 parent 4cfbd29 commit 6656416

File tree

13 files changed

+68
-85
lines changed

13 files changed

+68
-85
lines changed

tensorflow_lite_support/c/task/text/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ cc_library_with_tflite(
7373
"bert_question_answerer.h",
7474
],
7575
tflite_deps = [
76-
"//tensorflow_lite_support/cc/task/text/qa:bert_question_answerer",
77-
"//tensorflow_lite_support/cc/task/text/qa:question_answerer",
76+
"//tensorflow_lite_support/cc/task/text:bert_question_answerer",
77+
"//tensorflow_lite_support/cc/task/text:question_answerer",
7878
],
7979
)

tensorflow_lite_support/c/task/text/bert_question_answerer.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ limitations under the License.
1717

1818
#include <memory>
1919

20-
#include "tensorflow_lite_support/cc/task/text/qa/bert_question_answerer.h"
21-
#include "tensorflow_lite_support/cc/task/text/qa/question_answerer.h"
20+
#include "tensorflow_lite_support/cc/task/text/bert_question_answerer.h"
21+
#include "tensorflow_lite_support/cc/task/text/question_answerer.h"
2222

2323
namespace {
24-
using BertQuestionAnswererCpp = ::tflite::task::text::qa::BertQuestionAnswerer;
25-
using QaAnswerCpp = ::tflite::task::text::qa::QaAnswer;
24+
using BertQuestionAnswererCpp = ::tflite::task::text::BertQuestionAnswerer;
25+
using QaAnswerCpp = ::tflite::task::text::QaAnswer;
2626
} // namespace
2727

2828
#ifdef __cplusplus

tensorflow_lite_support/cc/task/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ answer question based on context.
1515
Use the C++ API to answer questions as follows:
1616

1717
```cc
18-
using tflite::task::text::qa::BertQuestionAnswerer;
19-
using tflite::task::text::qa::QaAnswer;
18+
using tflite::task::text::BertQuestionAnswerer;
19+
using tflite::task::text::QaAnswer;
2020
// Create API handler with Mobile Bert model.
2121
auto qa_client = BertQuestionAnswerer::CreateBertQuestionAnswererFromFile("/path/to/mobileBertModel", "/path/to/vocab");
2222
// Or create API handler with Albert model.

tensorflow_lite_support/cc/task/text/BUILD

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,46 @@ cc_library_with_tflite(
3939
"@org_tensorflow//tensorflow/lite/core/api",
4040
],
4141
)
42+
43+
cc_library_with_tflite(
44+
name = "question_answerer",
45+
hdrs = [
46+
"question_answerer.h",
47+
],
48+
tflite_deps = [
49+
"//tensorflow_lite_support/cc/task/core:base_task_api",
50+
"//tensorflow_lite_support/cc/task/core:tflite_engine",
51+
],
52+
)
53+
54+
cc_library_with_tflite(
55+
name = "bert_question_answerer",
56+
srcs = [
57+
"bert_question_answerer.cc",
58+
],
59+
hdrs = [
60+
"bert_question_answerer.h",
61+
],
62+
tflite_deps = [
63+
":question_answerer",
64+
"@org_tensorflow//tensorflow/lite/core/shims:builtin_ops",
65+
"//tensorflow_lite_support/cc/task/core:base_task_api",
66+
"//tensorflow_lite_support/cc/task/core:task_api_factory",
67+
"//tensorflow_lite_support/cc/task/core:tflite_engine",
68+
],
69+
deps = [
70+
"//tensorflow_lite_support/cc/port:status_macros",
71+
"//tensorflow_lite_support/cc/port:statusor",
72+
"//tensorflow_lite_support/cc/task/core:task_utils",
73+
"//tensorflow_lite_support/cc/task/text/proto:bert_question_answerer_options_proto_inc",
74+
"//tensorflow_lite_support/cc/text/tokenizers:bert_tokenizer",
75+
"//tensorflow_lite_support/cc/text/tokenizers:sentencepiece_tokenizer",
76+
"//tensorflow_lite_support/cc/text/tokenizers:tokenizer",
77+
"//tensorflow_lite_support/cc/text/tokenizers:tokenizer_utils",
78+
"//tensorflow_lite_support/metadata:metadata_schema_cc",
79+
"@com_google_absl//absl/base:core_headers",
80+
"@com_google_absl//absl/container:flat_hash_map",
81+
"@com_google_absl//absl/status",
82+
"@com_google_absl//absl/strings",
83+
],
84+
)

tensorflow_lite_support/cc/task/text/qa/bert_question_answerer.cc renamed to tensorflow_lite_support/cc/task/text/bert_question_answerer.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
#include "tensorflow_lite_support/cc/task/text/qa/bert_question_answerer.h"
16+
#include "tensorflow_lite_support/cc/task/text/bert_question_answerer.h"
1717

1818
#include "external/com_google_absl/absl/status/status.h"
1919
#include "external/com_google_absl/absl/strings/str_join.h"
@@ -28,7 +28,6 @@ limitations under the License.
2828
namespace tflite {
2929
namespace task {
3030
namespace text {
31-
namespace qa {
3231

3332
constexpr char kIdsTensorName[] = "ids";
3433
constexpr char kMaskTensorName[] = "mask";
@@ -409,7 +408,6 @@ void BertQuestionAnswerer::InitializeSentencepieceTokenizerFromBinary(
409408
spmodel_buffer_size);
410409
}
411410

412-
} // namespace qa
413411
} // namespace text
414412
} // namespace task
415413
} // namespace tflite

tensorflow_lite_support/cc/task/text/qa/bert_question_answerer.h renamed to tensorflow_lite_support/cc/task/text/bert_question_answerer.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
#ifndef TENSORFLOW_LITE_SUPPORT_CC_TASK_TEXT_QA_BERT_QUESTION_ANSWERER_H_
17-
#define TENSORFLOW_LITE_SUPPORT_CC_TASK_TEXT_QA_BERT_QUESTION_ANSWERER_H_
16+
#ifndef TENSORFLOW_LITE_SUPPORT_CC_TASK_QA_BERT_QUESTION_ANSWERER_H_
17+
#define TENSORFLOW_LITE_SUPPORT_CC_TASK_QA_BERT_QUESTION_ANSWERER_H_
1818

1919
#include "external/com_google_absl/absl/base/macros.h"
2020
#include "external/com_google_absl/absl/container/flat_hash_map.h"
@@ -24,14 +24,13 @@ limitations under the License.
2424
#include "tensorflow_lite_support/cc/task/core/task_api_factory.h"
2525
#include "tensorflow_lite_support/cc/task/core/tflite_engine.h"
2626
#include "tensorflow_lite_support/cc/task/text/proto/bert_question_answerer_options_proto_inc.h"
27-
#include "tensorflow_lite_support/cc/task/text/qa/question_answerer.h"
27+
#include "tensorflow_lite_support/cc/task/text/question_answerer.h"
2828
#include "tensorflow_lite_support/cc/text/tokenizers/bert_tokenizer.h"
2929
#include "tensorflow_lite_support/cc/text/tokenizers/sentencepiece_tokenizer.h"
3030

3131
namespace tflite {
3232
namespace task {
3333
namespace text {
34-
namespace qa {
3534

3635
// BertQA task API, performs tokenization for models (BERT, Albert, etc.) in
3736
// preprocess and returns most possible answers.
@@ -153,9 +152,8 @@ class BertQuestionAnswerer : public QuestionAnswerer {
153152
std::unique_ptr<BertQuestionAnswererOptions> options_;
154153
};
155154

156-
} // namespace qa
157155
} // namespace text
158156
} // namespace task
159157
} // namespace tflite
160158

161-
#endif // TENSORFLOW_LITE_SUPPORT_CC_TASK_TEXT_QA_BERT_QUESTION_ANSWERER_H_
159+
#endif // TENSORFLOW_LITE_SUPPORT_CC_TASK_QA_BERT_QUESTION_ANSWERER_H_

tensorflow_lite_support/cc/task/text/qa/BUILD

Lines changed: 0 additions & 52 deletions
This file was deleted.

tensorflow_lite_support/cc/task/text/qa/question_answerer.h renamed to tensorflow_lite_support/cc/task/text/question_answerer.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
#ifndef TENSORFLOW_LITE_SUPPORT_CC_TASK_TEXT_QA_QUESTION_ANSWERER_H_
17-
#define TENSORFLOW_LITE_SUPPORT_CC_TASK_TEXT_QA_QUESTION_ANSWERER_H_
16+
#ifndef TENSORFLOW_LITE_SUPPORT_CC_TASK_QA_QUESTION_ANSWERER_H_
17+
#define TENSORFLOW_LITE_SUPPORT_CC_TASK_QA_QUESTION_ANSWERER_H_
1818

1919
#include <string>
2020
#include <utility>
@@ -26,7 +26,6 @@ limitations under the License.
2626
namespace tflite {
2727
namespace task {
2828
namespace text {
29-
namespace qa {
3029

3130
// Struct for the Answer to QuestionAnswerer.
3231
struct QaAnswer {
@@ -57,9 +56,8 @@ class QuestionAnswerer
5756
const std::string& question) = 0;
5857
};
5958

60-
} // namespace qa
6159
} // namespace text
6260
} // namespace task
6361
} // namespace tflite
6462

65-
#endif // TENSORFLOW_LITE_SUPPORT_CC_TASK_TEXT_QA_QUESTION_ANSWERER_H_
63+
#endif // TENSORFLOW_LITE_SUPPORT_CC_TASK_QA_QUESTION_ANSWERER_H_

tensorflow_lite_support/examples/task/text/desktop/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cc_binary(
2121
"@com_google_absl//absl/status",
2222
"@com_google_absl//absl/strings:str_format",
2323
"//tensorflow_lite_support/cc/port:statusor",
24-
"//tensorflow_lite_support/cc/task/text/qa:bert_question_answerer",
24+
"//tensorflow_lite_support/cc/task/text:bert_question_answerer",
2525
] + select({
2626
"//tensorflow_lite_support/examples/task:darwinn_portable": [
2727
"//tensorflow_lite_support/acceleration/configuration:edgetpu_coral_plugin",

tensorflow_lite_support/examples/task/text/desktop/bert_question_answerer_demo.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020
#include "external/com_google_absl/absl/status/status.h"
2121
#include "external/com_google_absl/absl/strings/str_format.h"
2222
#include "tensorflow_lite_support/cc/port/statusor.h"
23-
#include "tensorflow_lite_support/cc/task/text/qa/bert_question_answerer.h"
23+
#include "tensorflow_lite_support/cc/task/text/bert_question_answerer.h"
2424

2525
ABSL_FLAG(std::string, model_path, "",
2626
"Absolute path to the '.tflite' bert question answerer model.");
@@ -34,7 +34,6 @@ ABSL_FLAG(bool, use_coral, false,
3434
namespace tflite {
3535
namespace task {
3636
namespace text {
37-
namespace qa {
3837

3938
namespace {
4039
using std::chrono::microseconds;
@@ -77,7 +76,6 @@ absl::Status Answer() {
7776
return absl::OkStatus();
7877
}
7978

80-
} // namespace qa
8179
} // namespace text
8280
} // namespace task
8381
} // namespace tflite
@@ -98,7 +96,7 @@ int main(int argc, char** argv) {
9896
return 1;
9997
}
10098
// Run the answerer.
101-
absl::Status status = tflite::task::text::qa::Answer();
99+
absl::Status status = tflite::task::text::Answer();
102100
if (status.ok()) {
103101
return 0;
104102
} else {

0 commit comments

Comments
 (0)