Creating a translator but i have a question

hi, I wanna make a translater in rasa. I was thinking about how to make the examples in the nlu. can this be: hi can you translate: (hi how are you)[input] to (dutch)[input_language]

or is this wrong en do I need to do it another way?

You can’t take a whole sentence that could be anything in an entity (input in your case).

You can create a Form that gets triggered when the user says “I want to translate to (dutch)[language]” or “I want to translate”.

This form will ask for a language Slot if the user hasn’t given a language, then for an input slot.

The important difference here between the input entity and slot is that, as a slot, you can map it from text and thus does not require AI. As for the language, you should map it from entity.

hi Chris and the others,

this is my progress for now:

in the rules.yml i added:

  • rule: activate form

    step:

    • intent: request_translation_input

    • Action: Translation_input_form

    • Active_loop: Translation_input_form

    • rule: submit Form

      conditon:

      • active_loop: Translation_input_form

      steps:

      • Action: Translation_input_form

      • Active_loop: null

      • slot_was_set:

        • requested_slot: null
      • Action: translation_is

Then in the Actions.py class Validateinputtranslation(FormValidationAction):

def name(self) -> Text:

    return "validate_input_translation"

def validate_input_translation(

    self,

    slot_value: Any,

    dispatcher: CollectingDispatcher,

    tracker: Tracker,

    domain: DomainDict,

) -> Dict[Text, Any]:

    """valadate 'translation_input' value."""

return {"translation_input": slot_value}

this is what i have in my rules.yml

  • rule: activate form

    step:

    • intent: Translate_language

    • Action: Translation_input_form

    • Active_loop: Translation_input_form

    • rule: submit Form

      conditon:

      • active_loop: Translation_input_form

      steps:

      • Action: Translation_input_form

      • Active_loop: null

      • slot_was_set:

        • requested_slot: null
      • Action: translation_is

are there already things i need to change?

Everything looks good, I would suggest going like the following flow I create right now


In your case you had just one validate and one slot which can be done without a form but here, you will have 2 validate and one submit function which will translate given sentence/speech.
Which will give you a desired result in a flow
If you still have doubts or questions please feel free to add here

1 Like