rasa icon indicating copy to clipboard operation
rasa copied to clipboard

Avoid unnecessarily retraining NLU model if only modified responses utterances in domain.

Open liuyuweitarek opened this issue 2 years ago • 2 comments

Proposed changes:

  • Avoid unnecessarily retraining NLU model if only modified responses utterances in domain.

Status (please check what you already did):

  • [ ] added some tests for the functionality
  • [ ] updated the documentation
  • [x] updated the changelog (please check changelog for instructions)
  • [x] reformat files using black (please check Readme for instructions)

liuyuweitarek avatar Sep 16 '22 11:09 liuyuweitarek

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 16 '22 11:09 CLAassistant

thanks for the PR, @liuyuweitarek ! I think there might be a piece of missing logic (tbf I haven't done a proper review yet).

If there is a response selector with use_text_as_label set to True, then the responses should be part of the fingerprint. You can check the migration notes here for more detail https://rasa.com/docs/rasa/2.x/migration-guide/#response-selectors

amn41 avatar Sep 16 '22 11:09 amn41

thanks for the PR, @liuyuweitarek ! I think there might be a piece of missing logic (tbf I haven't done a proper review yet).

If there is a response selector with use_text_as_label set to True, then the responses should be part of the fingerprint. You can check the migration notes here for more detail https://rasa.com/docs/rasa/2.x/migration-guide/#response-selectors

Thanks for your reply, @amn41 !Yes, you are right! After further researching, I found my real problem is it wrongly judges to retrain the NLU/CORE model while using the API:"model/train" belong to Rasa API server. Some slight changes, changing an utterance under responses (not belong to response selector), will retrain the NLU model.

The reason of this problem is because it put the whole request payload into the "single file" and send to the training method.


[ In rasa/server.py 1561~1584 ]
def _training_payload_from_yaml(
    request: Request, temp_dir: Path, file_name: Text = "data.yml"
) -> Dict[Text, Any]:
    logger.debug("Extracting YAML training data from request body.")

    decoded = request.body.decode(rasa.shared.utils.io.DEFAULT_ENCODING)
    _validate_yaml_training_payload(decoded)

    training_data = temp_dir / file_name
    rasa.shared.utils.io.write_text_file(decoded, training_data)              # Here write the whole payload into single file
    
    ...
    return dict(
        domain=str(training_data),             # Training data be put in single file
        config=str(training_data),
        training_files=str(temp_dir),
        output=model_output_directory,
        force_training=rasa.utils.endpoints.bool_arg(request, "force_training", False),
        core_additional_arguments=_extract_core_additional_arguments(request),
        nlu_additional_arguments=_extract_nlu_additional_arguments(request),
    )

[ Send to train ]
training_result = await train_async(**training_payload)

In the latest commit, I separated request payload into several files with standard architecture in the temp folder and made training API work properly as "rasa train" in command.

I use the data in 08-response-selection to test training api:

  1. It will retrain NLU model as we modified the utterance related to response selector.
  2. It will only update the model response without retraining Core/NLU models as we modified the simple utterance unrelated to response selector.

Here is the Postman config for the old /new request format.

Thanks for your time!

liuyuweitarek avatar Sep 25 '22 11:09 liuyuweitarek

@ancalita It's ok. I'm also too busy to add test case on this PR. 😭 I'll keep track on 3.3.x and check if it also needs this fixation. Thanks for your time! Please feel free to close this PR.

liuyuweitarek avatar Nov 17 '22 15:11 liuyuweitarek

@ancalita It's ok. I'm also too busy to add test case on this PR. 😭 I'll keep track on 3.3.x and check if it also needs this fixation. Thanks for your time! Please feel free to close this PR.

No worries, feel free to open a PR on the latest 3.x release branch whenever you'll be available, would be great to add this as a contribution in the future 💯

ancalita avatar Nov 18 '22 11:11 ancalita