krishnaik06 / huggingfacetransformer Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU General Public License v3.0
License: GNU General Public License v3.0
TypeError Traceback (most recent call last)
in ()
9 )
10
---> 11 trainer.train()
2 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs)
1145 except Exception as e: # pylint:disable=broad-except
1146 if hasattr(e, "ag_error_metadata"):
-> 1147 raise e.ag_error_metadata.to_exception(e)
1148 else:
1149 raise
TypeError: in user code:
File "/usr/local/lib/python3.7/dist-packages/transformers/trainer_tf.py", line 697, in distributed_training_steps *
self.args.strategy.run(self.apply_gradients, inputs)
File "/usr/local/lib/python3.7/dist-packages/transformers/trainer_tf.py", line 639, in apply_gradients *
gradients = self.training_step(features, labels, nb_instances_in_global_batch)
File "/usr/local/lib/python3.7/dist-packages/transformers/trainer_tf.py", line 622, in training_step *
per_example_loss, _ = self.run_model(features, labels, True)
File "/usr/local/lib/python3.7/dist-packages/transformers/trainer_tf.py", line 744, in run_model *
outputs = self.model(features, labels=labels, training=training)[:2]
File "/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler **
raise e.with_traceback(filtered_tb) from None
TypeError: Exception encountered when calling layer "tf_distil_bert_for_sequence_classification" (type TFDistilBertForSequenceClassification).
in user code:
File "/usr/local/lib/python3.7/dist-packages/transformers/models/distilbert/modeling_tf_distilbert.py", line 816, in call *
loss = None if inputs["labels"] is None else self.compute_loss(inputs["labels"], logits)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 919, in compute_loss **
y, y_pred, sample_weight, regularization_losses=self.losses)
TypeError: 'NoneType' object is not callable
Call arguments received:
• input_ids={'input_ids': 'tf.Tensor(shape=(8, 238), dtype=int32)', 'attention_mask': 'tf.Tensor(shape=(8, 238), dtype=int32)'}
• attention_mask=None
• head_mask=None
• inputs_embeds=None
• output_attentions=None
• output_hidden_states=None
• return_dict=None
• labels=tf.Tensor(shape=(8,), dtype=int32)
• training=True
• kwargs=<class 'inspect._empty'>
How to predict sentiment for a single sentence using the trainer(TFTrainer) in the given code.
optimizer = tf.keras.optimizers.Adam(learning_rate=5e-5)
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer=optimizer, loss=loss, metrics=['accuracy'])
model.fit(train_dataset.batch(8), epochs=2, validation_data=test_dataset.batch(16))
evaluation = model.evaluate(test_dataset.batch(16))
print(f"Loss: {evaluation[0]}, Accuracy: {evaluation[1]}")
predictions = model.predict(test_dataset.batch(16))
predicted_labels = tf.argmax(predictions.logits, axis=1).numpy()
cm = confusion_matrix(y_test, predicted_labels)
print(cm)
model.save_pretrained('senti_model')
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'
TypeError: in user code:
File "H:\NLP_Training\NLP_3.8\lib\site-packages\transformers\trainer_tf.py", line 701, in distributed_training_steps *
nb_instances_in_batch = self._compute_nb_instances(batch)
File "H:\NLP_Training\NLP_3.8\lib\site-packages\transformers\trainer_tf.py", line 713, in _compute_nb_instances *
nb_instances = tf.reduce_sum(tf.cast(labels != -100, dtype=tf.int32))
TypeError: Expected bool passed to parameter 'y' of op 'NotEqual', got -100 of type 'int' instead. Error: Expected bool, but got -100 of type 'int'.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.