Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages for installing extra [bert] when using a QuestionAnswerer #348

Open
murali1996 opened this issue Aug 2, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@murali1996
Copy link
Contributor

When a user tries to create a QuestionAnswerer without installing the extra [bert], the error message raised is ValueError: Invalid model configuration: Unknown embedder type 'bert'. This message is misleading as the user's input config might be correct but the bert requirements are not installed. Following is the example snippet that produces the error even when inputs are correct but the requirements are not satisfied:

from mindmeld import QuestionAnswerer

QUESTION_ANSWERER_CONFIG = {
   "model_type": "elasticsearch", 
   "model_settings": {
       "query_type": "embedder_text",
       "embedder_type": "bert",
       "pretrained_name_or_abspath": "bert-base-cased", 
       "bert_output_type": "mean",
       "quantize_model": False, 
       "embedding_fields": {
           # ...
       }
   }
}

qa = QuestionAnswerer(app_path="./blueprints/hr_assistant", config=QUESTION_ANSWERER_CONFIG)

Possible solution(s):

  • One way: Create a dict that identifies what extras are required for each key in EMBEDDER_MAP in helpers.py file. Check for those installs in create_embedder_model method.
  • Another way: Create a EmbedderModelFactory that holds such kind of validation checks before assigning the appropriate class-name to use. For backwards compatibility, keep supporting the method create_embedder_model but going forward, use something like EmbedderModelFactory.create_model(config=...)
@murali1996 murali1996 added the enhancement New feature or request label Aug 2, 2021
@murali1996
Copy link
Contributor Author

@vijay120

@murali1996 murali1996 self-assigned this Aug 2, 2021
@vijay120
Copy link
Contributor

vijay120 commented Aug 9, 2021

Could we do something analogous to this:

        GoogleTranslator._check_credential_exists()
        try:
            translate_v2 = importlib.import_module("google.cloud.translate_v2")
            return translate_v2.Client()
        except ModuleNotFoundError as error:
            raise ModuleNotFoundError(
                "Library not found: 'google-cloud'. Run 'pip install mindmeld[language_annotator]'"
                " to install."
            ) from error

@murali1996
Copy link
Contributor Author

Yeah. I'll add a solution like you suggested in the create_embedder_model method in componenets/helpers.py by caching the ImportError from the embedder_models.py classes. Will reflect this modification in PR #341

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants