/usr/local/lib/python3.6/site-packages/datasets/features/__pycache__
NameSizeModeActions
audio.cpython-36.pyc114730644editdlrm
features.cpython-36.pyc659380644editdlrm
image.cpython-36.pyc106000644editdlrm
translation.cpython-36.pyc51690644editdlrm
__init__.cpython-36.pyc5970644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/datasets/features/__pycache__/translation.cpython-36.pyc (5169B)
3 <%Eg@stddlmZmZddlmZmZmZmZmZm Z m Z ddl Z erLddl mZeGdddZeGdd d ZdS) ) dataclassfield) TYPE_CHECKINGAnyClassVarDictListOptionalUnionN) FeatureTypec@sveZdZUdZeedZeedZ e e dZ e e  e ddddZeddZedeedffd d d ZdS) Translationa`FeatureConnector` for translations with fixed languages per example. Here for compatiblity with tfds. Input: The Translate feature accepts a dictionary for each example mapping string language codes to string translations. Output: A dictionary mapping string language codes to translations as `Text` features. Example: ```python >>> # At construction time: >>> datasets.features.Translation(languages=['en', 'fr', 'de']) >>> # During data generation: >>> yield { ... 'en': 'the cat', ... 'fr': 'le chat', ... 'de': 'die katze' ... } ``` NdictF)defaultinitreprcCstjddt|jDS)NcSsi|]}tj|qS)pastring).0langrrG/usr/local/lib/python3.6/site-packages/datasets/features/translation.py ,sz(Translation.__call__..)rstructsorted languages)selfrrr__call__+szTranslation.__call__r )returncs$ddlmfddt|jDS)z2Flatten the Translation feature into a dictionary.r )Valuecsi|]}d|qS)rr)rk)rrrr2sz'Translation.flatten..)featuresrrr)rr)rrflatten.s zTranslation.flatten)__name__ __module__ __qualname____doc__rstrridr dtyperpa_typerr_typerr rr"rrrrr s    r c@seZdZUdZdZeedZeedZ ee  dZ e e  dZ e e eddddZe ddZdd Zd d Zed ee d ffd ddZdS)TranslationVariableLanguagesa``FeatureConnector` for translations with variable languages per example. Here for compatiblity with tfds. Input: The TranslationVariableLanguages feature accepts a dictionary for each example mapping string language codes to one or more string translations. The languages present may vary from example to example. Output: language: variable-length 1D tf.Tensor of tf.string language codes, sorted in ascending order. translation: variable-length 1D tf.Tensor of tf.string plain text translations, sorted to align with language codes. Example: ```python >>> # At construction time: >>> datasets.features.TranslationVariableLanguages(languages=['en', 'fr', 'de']) >>> # During data generation: >>> yield { ... 'en': 'the cat', ... 'fr': ['le chat', 'la chatte,'] ... 'de': 'die katze' ... } >>> # Tensor returned : >>> { ... 'language': ['en', 'de', 'fr', 'fr'], ... 'translation': ['the cat', 'die katze', 'la chatte', 'le chat'], ... } ``` NrF)rrrcCs<|jrtttt|jnd|_|jr2t|jnd|_dS)N)rlistrsetlen num_languages)rrrr __post_init___s"z*TranslationVariableLanguages.__post_init__cCs$tjtjtjtjtjdS)N)language translation)rrlist_r)rrrrrcsz%TranslationVariableLanguages.__call__cst|j}|jrJt||rJtddjtt||ddj|dg}xF|jD]:\}t|trz|j|fqX|j fdd|DqXWt t|\}}||dS)NzSome languages in example (z, z) are not in valid set (z).csg|] }|fqSrr)rel)rrr tsz?TranslationVariableLanguages.encode_example..)r2r3) r.r ValueErrorjoinritems isinstancer'appendextendzip)rZtranslation_dictZlang_setZtranslation_tuplestextrZ translationsr)rrencode_examplefs , z+TranslationVariableLanguages.encode_exampler )rcCs*ddlm}m}||d||ddS)zCFlatten the TranslationVariableLanguages feature into a dictionary.r )Sequencerr)r2r3)r!r@r)rr@rrrrr"{s z$TranslationVariableLanguages.flatten)r#r$r%r&rr rr0intr(r'r)rr*rrr+r1rr?r rr"rrrrr,5s      r,)Z dataclassesrrtypingrrrrrr r Zpyarrowrr!r r r,rrrrs $ *