ktrain icon indicating copy to clipboard operation
ktrain copied to clipboard

Any plan to support T5?

Open evilying opened this issue 3 years ago • 1 comments

Hi Amaiya,

I wonder if you have any plan to support T5 model or is there any way to convert it so that it can work? I have tried the following:

MODEL_NAME = 't5-small'
t = text.Transformer(MODEL_NAME, maxlen=64, class_names=label_fields)
train = t.preprocess_train(x_train, y_train)
val = t.preprocess_test(x_test, y_test)

But error occurs: ValueError: Unrecognized configuration class <class 'transformers.models.t5.configuration_t5.T5Config'> for this kind of AutoModel: AutoModelForSequenceClassification. Model type should be one of AlbertConfig, BartConfig, BertConfig, BigBirdConfig, BigBirdPegasusConfig, BioGptConfig, BloomConfig, CamembertConfig, CanineConfig, ConvBertConfig, CTRLConfig, Data2VecTextConfig, DebertaConfig, DebertaV2Config, DistilBertConfig, ElectraConfig, ErnieConfig, ErnieMConfig, EsmConfig, FlaubertConfig, FNetConfig, FunnelConfig, GPT2Config, GPT2Config, GPTBigCodeConfig, GPTNeoConfig, GPTNeoXConfig, GPTJConfig, IBertConfig, LayoutLMConfig, LayoutLMv2Config, LayoutLMv3Config, LEDConfig, LiltConfig, LlamaConfig, LongformerConfig, LukeConfig, MarkupLMConfig, MBartConfig, MegaConfig, MegatronBertConfig, MobileBertConfig, MPNetConfig, MvpConfig, NezhaConfig, NystromformerConfig, OpenLlamaConfig, OpenAIGPTConfig, OPTConfig, PerceiverConfig, PLBartConfig, QDQBertConfig, ReformerConfig, RemBertConfig, RobertaConfig, RobertaPreLayerNormConfig, RoCBertConfig, RoFormerConfig, SqueezeBertConfig, TapasConfig, TransfoXLConfig, XLMConfig, XLMRobertaConfig, XLMRobertaXLConfig, XLNetConfig, XmodConfig, YosoConfig

Thanks!

Best, Kun

evilying avatar Jun 13 '23 15:06 evilying

Hi Kun,

Text classification in ktrain should work with any model that includes a *For SequenceClassification class in transformers. T5 is a text-to-text model, so there's no *ForSequenceClassification class in transformers for conventional classification/regression. So, it's more that transformers doesn't support it. You get the same error even when you use transformers directly without even using ktrain:

In [3]: model = TFAutoModelForSequenceClassification.from_pretrained('t5-small')
Downloading: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1.21k/1.21k [00:00<00:00, 679kB/s]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 model = TFAutoModelForSequenceClassification.from_pretrained('t5-small')

File ~/mambaforge/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py:467, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    463     model_class = _get_model_class(config, cls._model_mapping)
    464     return model_class.from_pretrained(
    465         pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
    466     )
--> 467 raise ValueError(
    468     f"Unrecognized configuration class {config.__class__} for this kind of AutoModel: {cls.__name__}.\n"
    469     f"Model type should be one of {', '.join(c.__name__ for c in cls._model_mapping.keys())}."
    470 )

ValueError: Unrecognized configuration class <class 'transformers.models.t5.configuration_t5.T5Config'> for this kind of AutoModel: TFAutoModelForSequenceClassification.
Model type should be one of AlbertConfig, BartConfig, BertConfig, CamembertConfig, ConvBertConfig, CTRLConfig, DebertaConfig, DebertaV2Config, DistilBertConfig, ElectraConfig, EsmConfig, FlaubertConfig, FunnelConfig, GPT2Config, GPT2Config, GPTJConfig, LayoutLMConfig, LayoutLMv3Config, LongformerConfig, MobileBertConfig, MPNetConfig, OpenAIGPTConfig, RemBertConfig, RobertaConfig, RobertaPreLayerNormConfig, RoFormerConfig, TapasConfig, TransfoXLConfig, XLMConfig, XLMRobertaConfig, XLNetConfig.

As shown here, you can use it for classification but not in the same way as models like BERT.

amaiya avatar Jun 13 '23 19:06 amaiya