ml: Move tclib model file installation to tclib's ebuild.
We used to put the model installation in mlservice's ebuild because we
thought the unit test can not see the model files in the standard
location. It turns it can. So it is better to install the model files
in its own ebuild.
Now we do not need to load the model file in
`MachineLearningServiceImpl` and can put the model initialization all
in "text_classifier_impl.cc"
Also removed a unit test on testing non-exist model file for tclib
because it seems there is no such tests for all the other models.
BUG=none
TEST=FEATURES=test emerge-nocturne ml
Cq-Depend: 2472978
Change-Id: I4ac44446b99815705e2c82dc543b41170c7f7fb9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2473178
Reviewed-by: Andrew Moylan <amoylan@chromium.org>
Commit-Queue: Honglin Yu <honglinyu@chromium.org>
Tested-by: Honglin Yu <honglinyu@chromium.org>
diff --git a/ml/text_classifier_impl.cc b/ml/text_classifier_impl.cc
index d595050..090932f 100644
--- a/ml/text_classifier_impl.cc
+++ b/ml/text_classifier_impl.cc
@@ -30,6 +30,13 @@
using ::chromeos::machine_learning::mojom::TextLanguagePtr;
using ::chromeos::machine_learning::mojom::TextSuggestSelectionRequestPtr;
+constexpr char kTextClassifierModelFilePath[] =
+ "/opt/google/chrome/ml_models/mlservice-model-text_classifier_en-v711.fb";
+
+constexpr char kLanguageIdentificationModelFilePath[] =
+ "/opt/google/chrome/ml_models/"
+ "mlservice-model-language_identification-20190924.smfb";
+
// To avoid passing a lambda as a base::Closure.
void DeleteTextClassifierImpl(
const TextClassifierImpl* const text_classifier_impl) {
@@ -39,11 +46,18 @@
} // namespace
bool TextClassifierImpl::Create(
- std::unique_ptr<libtextclassifier3::ScopedMmap>* annotator_model_mmap,
- const std::string& langid_model_path,
mojo::PendingReceiver<TextClassifier> receiver) {
+ // Attempt to load model.
+ auto annotator_model_mmap = std::make_unique<libtextclassifier3::ScopedMmap>(
+ kTextClassifierModelFilePath);
+ if (!annotator_model_mmap->handle().ok()) {
+ LOG(ERROR) << "Failed to load the text classifier model file.";
+ return false;
+ }
+
auto text_classifier_impl = new TextClassifierImpl(
- annotator_model_mmap, langid_model_path, std::move(receiver));
+ &annotator_model_mmap, kLanguageIdentificationModelFilePath,
+ std::move(receiver));
if (text_classifier_impl->annotator_ == nullptr ||
text_classifier_impl->language_identifier_ == nullptr) {
// Fails to create annotator, return nullptr.