krishnaik06 / Huggingfacetransformer

GNU General Public License v3.0
59 stars 97 forks source link

TypeError: '>' not supported between instances of 'NoneType' and 'int' #2

Open Juned-Ansari opened 2 years ago

Juned-Ansari commented 2 years ago

While Executing the following code getting error:

with training_args.strategy.scope():
    model = TFDistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased")

trainer = TFTrainer(
    model=model,                         # the instantiated 🤗 Transformers model to be trained
    args=training_args,                  # training arguments, defined above
    train_dataset=train_dataset,         # training dataset
    eval_dataset=test_dataset             # evaluation dataset
)

trainer.train()

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-78414b52dd9d> in <module>()
      9 )
     10 
---> 11 trainer.train()

/usr/local/lib/python3.7/dist-packages/transformers/trainer_tf.py in train(self)
    583 
    584                     if (
--> 585                         self.args.eval_steps > 0
    586                         and self.args.evaluation_strategy == IntervalStrategy.STEPS
    587                         and self.global_step % self.args.eval_steps == 0

TypeError: '>' not supported between instances of 'NoneType' and 'int'
seuriously commented 2 years ago

I also face this issue. Solved by defining eval_steps as param in training_args

JafirDon commented 2 years ago

try this command: !pip install transformers==4.6.0

Waleed-bin-Qamar commented 2 years ago

While Executing the following code getting error:

with training_args.strategy.scope():
    model = TFDistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased")

trainer = TFTrainer(
    model=model,                         # the instantiated 🤗 Transformers model to be trained
    args=training_args,                  # training arguments, defined above
    train_dataset=train_dataset,         # training dataset
    eval_dataset=test_dataset             # evaluation dataset
)

trainer.train()

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-78414b52dd9d> in <module>()
      9 )
     10 
---> 11 trainer.train()

/usr/local/lib/python3.7/dist-packages/transformers/trainer_tf.py in train(self)
    583 
    584                     if (
--> 585                         self.args.eval_steps > 0
    586                         and self.args.evaluation_strategy == IntervalStrategy.STEPS
    587                         and self.global_step % self.args.eval_steps == 0

TypeError: '>' not supported between instances of 'NoneType' and 'int'

** can you please send updated version of code, in which error is resolved.

RAravindDS commented 2 years ago

I also face this issue. Solved by defining eval_steps as param in training_args

Thanks dude?

How to predict this for new sentence, I am having confusion on this

tf.data.Dataset.from_tensor_slices(( dict(train_encodings), y_train ))

How we need to give a new text here?

basel-ay commented 4 months ago

The error message indicates that the self.args.eval_steps is None, and it's trying to compare it with an integer. To solve this error, you need to make sure that eval_steps is properly set to an integer value greater than 0.

By adding evaluation_strategy="steps" to the TFTrainingArguments, the issue shall be solved.

image