Example #1
0
  def __init__(self, languages=None):
    """Constructs a Translation FeatureConnector.

    Args:
      languages: `list<string>` (optional), full list of language codes if known
        in advance.
    """
    # TODO(adarob): Add optional text encoders once `Sequence` adds support
    # for FixedVarLenFeatures.

    self._languages = set(languages) if languages else None
    super(TranslationVariableLanguages, self).__init__({
        "language": text_feature.Text(),
        "translation": text_feature.Text(),
    })
Example #2
0
    def __init__(self, languages, encoder=None, encoder_config=None):
        """Constructs a Translation FeatureConnector.

    Args:
      languages: `list<string>` Full list of languages codes.
      encoder: `tfds.deprecated.text.TextEncoder` or
        list<tfds.deprecated.text.TextEncoder> (optional), an encoder that can
        convert text to integer. One can be shared one per language provided. If
        None, the text will be utf-8 byte-encoded.
      encoder_config: `tfds.deprecated.text.TextEncoderConfig` or
        `list<tfds.deprecated.text.TextEncoderConfig>` (optional), needed
        if restoring from a file with `load_metadata`. One config can be shared
        or one per language can be provided.
    """
        # If encoder and encoder_config aren't lists, use the same values for all
        # languages.
        self._encoder = encoder
        self._encoder_config = encoder_config
        if not isinstance(encoder, collections_abc.Iterable):
            encoder = [encoder] * len(languages)
        if not isinstance(encoder_config, collections_abc.Iterable):
            encoder_config = [encoder_config] * len(languages)

        super(Translation, self).__init__({
            lang: text_feature.Text(enc, enc_conf)
            for lang, enc, enc_conf in zip(languages, encoder, encoder_config)
        })
Example #3
0
    def __init__(
        self,
        languages=None,
        *,
        doc: feature_lib.DocArg = None,
    ):
        """Constructs a Translation FeatureConnector.

    Args:
      languages: `list<string>` (optional), full list of language codes if known
        in advance.
      doc: Documentation of this feature (e.g. description).
    """
        # TODO(adarob): Add optional text encoders once `Sequence` adds support
        # for FixedVarLenFeatures.

        self._languages = set(languages) if languages else None
        super(TranslationVariableLanguages, self).__init__(feature={
            "language":
            text_feature.Text(),
            "translation":
            text_feature.Text(),
        },
                                                           doc=doc)