DocumentationAPI Reference📓 Tutorials🧑‍🍳 Cookbook🤝 Integrations💜 Discord🎨 Studio (Waitlist)
API Reference

Abstract class for Translators.

Module base

BaseTranslator

class BaseTranslator(BaseComponent)

Abstract class for a Translator component that translates either a query or a doc from language A to language B.

BaseTranslator.translate

@abstractmethod
def translate(
    results: Optional[List[Dict[str, Any]]] = None,
    query: Optional[str] = None,
    documents: Optional[Union[List[Document], List[Answer], List[str],
                              List[Dict[str, Any]]]] = None,
    dict_key: Optional[str] = None
) -> Union[str, List[Document], List[Answer], List[str], List[Dict[str, Any]]]

Translate the passed query or a list of documents from language A to B.

BaseTranslator.run

def run(results: Optional[List[Dict[str, Any]]] = None,
        query: Optional[str] = None,
        documents: Optional[Union[List[Document], List[Answer], List[str],
                                  List[Dict[str, Any]]]] = None,
        answers: Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] = None,
        dict_key: Optional[str] = None)

Method that gets executed when this class is used as a Node in a Haystack Pipeline.

Arguments:

  • results: Generated QA pairs to translate.
  • query: The query string to translate.
  • documents: The documents to translate.
  • answers: Passes the answers to the TranslationWrapperPipeline. See Haystack documentation for more details.
  • dict_key: If you pass a dictionary in documents, you can specify here the field which shall be translated.

BaseTranslator.run_batch

def run_batch(queries: Optional[List[str]] = None,
              documents: Optional[Union[List[Document], List[Answer],
                                        List[List[Document]],
                                        List[List[Answer]]]] = None,
              answers: Optional[Union[List[Answer],
                                      List[List[Answer]]]] = None,
              batch_size: Optional[int] = None)

Arguments:

  • queries: List of query strings to translate.
  • documents: The documents to translate.
  • answers:
  • batch_size: Number of records to process at a time.