# Please explain how HF TFSequenceClassifier implements variable input length

**URL:** <https://discuss.huggingface.co/t/please-explain-how-hf-tfsequenceclassifier-implements-variable-input-length/21878>\
**Category:** Intermediate\
**Created:** [August 21, 2022, 12:29pm UTC](https://discuss.huggingface.co/t/please-explain-how-hf-tfsequenceclassifier-implements-variable-input-length/21878 "2022-08-21T12:29:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serj](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/serj/32/5754_2.png) [@Serj](https://discuss.huggingface.co/u/Serj)\
**Post date:** [August 21, 2022, 12:29pm UTC](https://discuss.huggingface.co/t/please-explain-how-hf-tfsequenceclassifier-implements-variable-input-length/21878/1 "2022-08-21T12:29:14Z")

</div>

Background: I’m creating Keras models that are based on HF models such as - TFDistilBertForSequenceClassification (uncased).

I’m using distilbert as a feature tokenizer, and adding a classifier on top. It means I need to define inputs, use distilbert, bind the output and create a new Keras model.

Here’s the thing - when creating a model like that, I need to define a fix input length, for instance 512. Due to that, any sentence that will use this model, needs to be padded to 512. Even during inference time, which is a bummer because we are just wasting time. Any sentence of shorter length will cause an error.

When using HF implementation, I can use which ever input length I want, up to 512.  
How did you achieve this feat?

I’m going over your repository: [https://github.dev/huggingface/transformers/blob/main/src/transformers/models/distilbert/modeling\_tf\_distilbert.py](https://github.dev/huggingface/transformers/blob/main/src/transformers/models/distilbert/modeling_tf_distilbert.py)

But still don’t get it. Please help
