def transformer(model='base', **kwargs): """ Load Malaya transformer encoder-decoder model to generate a paraphrase given a string. Parameters ---------- model : str, optional (default='base') Model architecture supported. Allowed values: * ``'malaya-small'`` - Malaya Transformer SMALL parameters. * ``'malaya-base'`` - Malaya Transformer BASE parameters. Returns ------- result: malaya.model.tf.PARAPHRASE class """ model = model.lower() if model not in _transformer_availability: raise ValueError( 'model not supported, please check supported models from malaya.paraphrase.available_transformer()' ) from malaya.model.tf import PARAPHRASE return transformer_load.load_lm( path=PATH_PARAPHRASE['transformer'], s3_path=S3_PATH_PARAPHRASE['transformer'], model=model, model_class=PARAPHRASE, **kwargs, )
def transformer(model: str = 't2t', quantized: bool = False, **kwargs): """ Load Malaya transformer encoder-decoder model to generate a paraphrase given a string. Parameters ---------- model : str, optional (default='t2t') Model architecture supported. Allowed values: * ``'t2t'`` - Malaya Transformer BASE parameters. * ``'small-t2t'`` - Malaya Transformer SMALL parameters. * ``'t5'`` - T5 BASE parameters. * ``'small-t5'`` - T5 SMALL parameters. quantized : bool, optional (default=False) if True, will load 8-bit quantized model. Quantized model not necessary faster, totally depends on the machine. Returns ------- result: model List of model classes: * if `t2t` in model, will return `malaya.model.tf.Paraphrase`. * if `t5` in model, will return `malaya.model.t5.Paraphrase`. """ model = model.lower() if model not in _transformer_availability: raise ValueError( 'model not supported, please check supported models from `malaya.paraphrase.available_transformer()`.' ) if 't2t' in model: return transformer_load.load_lm( module='paraphrase', model=model, model_class=TF_Paraphrase, quantized=quantized, **kwargs, ) if 't5' in model: return t5_load.load( module='paraphrase', model=model, model_class=T5_Paraphrase, quantized=quantized, **kwargs, )
def transformer(model: str = 'base', **kwargs): model = model.lower() if model not in _transformer_availability: raise ValueError( 'model not supported, please check supported models from malaya.summarization.abstractive.available_transformer()' ) from malaya.model.tf import SUMMARIZATION return transformer_load.load_lm( path = PATH_SUMMARIZE['transformer'], s3_path = S3_PATH_SUMMARIZE['transformer'], model = model, model_class = SUMMARIZATION, **kwargs, )
def transformer(model: str = 'base', quantized: bool = False, **kwargs): """ Load Malaya transformer encoder-decoder model to generate a paraphrase given a string. Parameters ---------- model : str, optional (default='base') Model architecture supported. Allowed values: * ``'small'`` - Malaya Transformer SMALL parameters. * ``'base'`` - Malaya Transformer BASE parameters. quantized : bool, optional (default=False) if True, will load 8-bit quantized model. Quantized model not necessary faster, totally depends on the machine. Returns ------- result: malaya.model.tf.PARAPHRASE class """ model = model.lower() if model not in _transformer_availability: raise ValueError( 'model not supported, please check supported models from `malaya.paraphrase.available_transformer()`.' ) from malaya.model.tf import PARAPHRASE return transformer_load.load_lm( path=PATH_PARAPHRASE['transformer'], s3_path=S3_PATH_PARAPHRASE['transformer'], model=model, model_class=PARAPHRASE, quantized=quantized, **kwargs, )
def transformer(model: str = 't2t', quantized: bool = False, **kwargs): """ Load Malaya transformer encoder-decoder model to generate a summary given a string. Parameters ---------- model : str, optional (default='base') Model architecture supported. Allowed values: * ``'t2t'`` - Malaya Transformer BASE parameters. * ``'small-t2t'`` - Malaya Transformer SMALL parameters. * ``'t5'`` - T5 BASE parameters. * ``'small-t5'`` - T5 SMALL parameters. * ``'bigbird'`` - BigBird + Pegasus BASE parameters. * ``'small-bigbird'`` - BigBird + Pegasus SMALL parameters. quantized : bool, optional (default=False) if True, will load 8-bit quantized model. Quantized model not necessary faster, totally depends on the machine. Returns ------- result: model List of model classes: * if `t2t` in model, will return `malaya.model.tf.Summarization`. * if `t5` in model, will return `malaya.model.t5.Summarization`. * if `bigbird` in model, will return `malaya.model.bigbird.Summarization`. """ model = model.lower() if model not in _transformer_availability: raise ValueError( 'model not supported, please check supported models from `malaya.summarization.abstractive.available_transformer()`.' ) if 't2t' in model: return transformer_load.load_lm( module='abstractive-summarization', model=model, model_class=TF_Summarization, quantized=quantized, **kwargs, ) if 't5' in model: return t5_load.load( module='abstractive-summarization', model=model, model_class=T5_Summarization, quantized=quantized, **kwargs, ) if 'bigbird' in model: return bigbird_load.load_lm( module='abstractive-summarization', model=model, model_class=BigBird_Summarization, maxlen=_transformer_availability[model]['Suggested length'], quantized=quantized, **kwargs, )