Docs

Adapt to Instructions

Lara supports instructions to adjust translation tone, style, and behavior. This ensures translations align with specific contexts and audiences.

What Are Instructions?

Instructions are directives that guide Lara's translation process. They can specify formality, tone, or domain-specific terminology, allowing for precise adjustments to match your needs. Lara supports any instruction written in natural language, like instructions about formality, tone and specific terminology.


To use instructions, include them as a parameter in your SDK call. Here, the instruction ensures a formal tone in Italian:

res = lara.translate('Hello, how are you?', source='en-US', target='it-IT', 
                     instructions=['Be formal'])

print(res.translation)

# Lara's translation: Salve, come sta?
const res = await lara.translate('Hello, how are you?', 'en-US', 'it-IT', {
    instructions: ['Be formal']
})

console.log(res.translation)

// Lara's translation: Salve, come sta?
TranslateOptions options = new TranslateOptions().setInstructions("Be formal");
TextResult res = lara.translate("Hello, how are you?", "en-US", "it-IT", options);

System.out.println(res.getTranslation());

// Lara's translation: Salve, come sta?
$options = new TranslateOptions(['instructions' => array('Be formal')]);
$res = $lara->translate('Hello, how are you?', 'en-US', 'it-IT', $options);

echo $res->getTranslation();

// Lara's translation: Salve, come sta?

Multiple instructions can be used at the same time:

res = lara.translate('Could you send me the report by tomorrow morning 9 PST?', 
                     source='en-US', target='it-IT',
                     instructions=[
                         'Use a professional tone',
                         'Ensure clarity in deadlines and time zones'
                     ])

print(res.translation)

# Lara's translation: Potrebbe inviarmi il rapporto entro le ore 9:00 di domani, ora del Pacifico?
const res = await lara.translate('Could you send me the report by tomorrow morning 9 PST?',
    'en-US', 'it-IT', {
        instructions: [
            'Use a professional tone',
            'Ensure clarity in deadlines and time zones'
        ]
    }
);

console.log(res.translation);

// Lara's translation: Potrebbe inviarmi il rapporto entro le ore 9:00 di domani, ora del Pacifico?
TranslateOptions options = new TranslateOptions().setInstructions(
        "Use a professional tone", 
        "Ensure clarity in deadlines and time zones"
);
TextResult result = lara.translate("Could you send me the report by tomorrow morning 9 PST", 
        "en-US", "it-IT", options);

System.out.println(result.getTranslation());

// Lara's translation: Potrebbe inviarmi il rapporto entro le ore 9:00 di domani, ora del Pacifico?
$options = new TranslateOptions(['instructions' => array(
    'Use a professional tone', 
    'Ensure clarity in deadlines and time zones'
)]);
$res = $lara->translate('Could you send me the report by tomorrow morning 9 PST?', 
    'en-US', 'it-IT', $options);

echo $res->getTranslation();

// Lara's translation: Potrebbe inviarmi il rapporto entro le ore 9:00 di domani, ora del Pacifico?

👍

Best Practices

  • Be Specific: Clear instructions like "Translate formally".
  • Avoid Conflicts: Don’t combine contradictory instructions. The output is unpredictable.
  • Leverage Defaults When Unsure: If no instruction is provided, Lara intelligently defaults to general-purpose instructions for translations. Avoid instructions if they are vague or you are not sure what text is translated. The default behavior of Lara is suitable for most use cases.

Common Use Cases

Here some examples we tested from English to Italian. Feel free to try and explore other use cases!

Formal Response

  • Source Text: Thank you for your prompt response.
  • Instructions: Translate formally.
  • Lara’s Translation: La ringraziamo per la sua tempestiva risposta.

Specific Tone

  • Source Text: This is not just a product; it’s a lifestyle.
  • Instructions: Use a creative and concise tone.
  • Lara’s Translation: Non è solo un prodotto, è uno stile di vita.

Price Masking

  • Source Text: The price is $250 per night.
  • Instructions: Mask any price with the [price] placeholder.
  • Lara’s Translation: Il prezzo è di [price] a notte.

Avoiding Informal Expressions

  • Source Text: What’s up? How can I help ya?
  • Instructions: Avoid regional, slang, or too informal expressions.
  • Lara’s Translation: Come va? Come posso aiutarti?

Abbreviating Measures

  • Source Text: The train leaves in 15 minutes.
  • Instructions: Use ‘min’ to translate minutes.
  • Lara’s Translation: Il treno parte tra 15 min.

Quotations

  • Source Text: She said, “It’s a beautiful day.”
  • Instructions: Use quotation marks (« ») for quotations.
  • Lara’s Translation: Ha detto: «È una bella giornata».

Removing Phone Numbers

  • Source Text: Call us at 123-456-7890.
  • Instructions: The translations must not contain any telephone number. Use [phone] instead.
  • Lara’s Translation: Chiamaci al numero [phone].

Formatting Numbers

  • Source Text: The total is 1250000 units.
  • Instructions: Use a thousand separator for numbers with more than 5 digits.
  • Lara’s Translation: Il totale è di 1.250.000 unità.

Gender-Neutral Language

  • Source Text: Every employee must bring his laptop to the meeting.
  • Instructions: Make the translation gender-neutral.
  • Lara’s Translation: Ogni dipendente deve portare il proprio laptop alla riunione.

Currency Adjustments

  • Source Text: The item costs $45.67.
  • Instructions:
    • Switch the $/£ signs for € but do not convert the amount.
    • Use a comma as a decimal separator.
  • Lara’s Translation: L’articolo costa 45,67 €.