Translate text using N/machineTranslation Module

Use the N/machineTranslation module to translate text into supported languages using generative AI. This module uses the Oracle Cloud Infrastructure (OCI) Language service to translate text in documents you provide.

You can also use the N/llm Module to translate text by providing a suitable prompt when calling generative AI methods (such as llm.generateText(options)). However, using the N/machineTranslation module provides several benefits that make it a better choice for most translation use cases:

  • Reduced cost – The N/machineTranslation module supports unlimited translation requests, while the N/llm module provides only a limited number of LLM requests per month. When using the N/machineTranslation module, you don’t need to provide Oracle Cloud Infrastructure (OCI) credentials to get unlimited usage, which helps to reduce the cost of your solutions.

  • No prompt engineering required – When you use the N/machineTranslation module, you don’t need to write a prompt to generate translations. The module detects the source language automatically and translates provided documents into the language you specify in your request.

  • More straightforward limits – The N/machineTranslation module limits the length of each provided document to 5,000 characters, and it also limits the total length of all provided documents to 20,000 characters. The N/llm module provides limits that are based on tokens and the context window of the LLM you use, which can be more difficult to estimate.

  • More supported languages – The N/machineTranslation module can translate text into additional languages that may not be supported by LLMs and the N/llm module.

  • More reliable translations – The N/machineTranslation module uses the OCI Language service, which is designed for specific natural language processing (NLP) tasks, including translation. It uses pretrained models that can offer more predictable and reliable translation results compared to the N/llm module. The N/llm module uses the OCI Generative AI service, which is designed for content generation and may provide more varied translation results compared to a dedicated translation service.

Sample code:

const myDocument1 = machineTranslation.createDocument({
    id: 'myDoc1',
    text: 'This is a document to be translated.'
});

const myDocument2 = machineTranslation.createDocument({
    id: 'myDoc2',
    text: 'This is another document to be translated.'
});

const translationResults = machineTranslation.translate({
    documents: [myDocument1, myDocument2],
    targetLanguage: machineTranslation.Language.CZECH
});

Leave a comment

Your email address will not be published. Required fields are marked *