'BertForSequenceClassification using SparkNLP makes incorrect prediction
I have finetuned a BertForSequenceClassification model externally usnig PyTorch. I have then exported and saved the model following the documentation of SparkNLP. The problem that I am facing is that before converting it to a SparkNLP model, it was predicting the classes correctly but after the conversion the model is making a lot of misclassification errors.
The below code is where I am loading my fine tuned PyTorch model and converting it into a TF model for SparkNLP.
from transformers import TFBertForSequenceClassification, BertTokenizer, BertConfig
tokenizer = BertTokenizer.from_pretrained("model/tokenizer", do_lower_case=True)
tokenizer.save_pretrained('spark_nlp/tokenizer')
model = TFBertForSequenceClassification.from_pretrained("model/base_model", num_labels=31, from_pt=True)
model = TFBertForSequenceClassification.from_pretrained("model/fine_tuned_model/finetuned_bert.model", from_pt=True, config=model.config)
model.save_pretrained("spark_nlp/tf_model", saved_model=True)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
