ThilinaRajapakse / simpletransformers

Transformers for Information Retrieval, Text Classification, NER, QA, Language Modelling, Language Generation, T5, Multi-Modal, and Conversational AI
https://simpletransformers.ai/
Apache License 2.0
4.09k stars 728 forks source link

model.predict(), reload/rerun the whole file with fine tuned ClassificationModel. #1234

Closed aziz-ullah-khan closed 2 years ago

aziz-ullah-khan commented 3 years ago

Model Prediction issue While predicting the class for the fine tuned trained classification model, it rerun/reload the whole file. The code works fine in notebook but when converted to python(.py) and run the script locally in VS or terminal create such issue that is with prediction reload the whole python file.

Code `model_type = "bert" model_name = "cl-tohoku/bert-base-japanese-whole-word-masking" output_directory = './models/model_intent/' cuda_available = torch.cuda.is_available() hide_progress = False intents = ['a', 'b', 'c', 'd', 'e']

model_args = ClassificationArgs(num_train_epochs=10, output_dir=output_directory, overwrite_output_dir=True, save_model_every_epoch=False, save_eval_checkpoints=False, manual_seed=42, silent=hide_progress)`

model = ClassificationModel( model_type, model_name, num_labels=len(intents), args=model_args, use_cuda=cuda_available )

train_data_intents contain text and label column model.train_model(train_data_intents)

model_intent = ClassificationModel( model_type, model_name = model_directory, args=model_args, use_cuda=cuda_available, )

The issue is here the model is performing prediction it reload the whole file form importing the packages to the end of the file. sentence = 'おはよう!' predictions, raw_outputs = model_intent.predict(sentence)

The model is predicting well but the issue is the reload of all the code again and again.

Please note, in Google Colab there is no such issue but when converted to .py and run that locally create such isssue. When I run the .py file in google colab there is no such issue as well.

Kindly advise on this issue

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.