-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fine-Tune on our dataset #6
Comments
You can use this Colab to fine-tuning your dataset based on the text classification tasks. For other down-stream tasks, I'm afraid to say that you need to be patient. I'll add others soon! |
how to get embedding of ParsBert pretrain model? |
I used this Bert Persian classification model raise ValueError ('No model found in config file.') How can I add a config file so that I do not get this error? |
Did you fine-tune parsbert on your dataset? Which methods did you use (PyTorch, TensorFlow, Script)? Did you save your model except for the script technique (What type of files do you have on your saved model directory)? |
https://github.com/hooshvare/parsbert/blob/master/notebooks/Taaghche_Sentiment_Analysis.ipynb I made my model from this link |
Ok, then. Your model fine-tuned on Transformers you can't load the model just as simple as from transformers import TFAutoModelForSequenceClassification
tf_model = TFAutoModelForSequenceClassification.from_pretrained(YOURSAVED_DIRECTORY) otherwise, if you have pytorch_model.bin from transformers import TFAutoModelForSequenceClassification
tf_model = TFAutoModelForSequenceClassification.from_pretrained(YOURSAVED_DIRECTORY, from_pt=True) Also, make sure you have |
With my model, only these two files are saved from transformers import TFAutoModelForSequenceClassification This is how I got this error |
Link used |
First of all, you can download https://cdn.huggingface.co/HooshvareLab/bert-base-parsbert-uncased/vocab.txt Secondly, you must load the model from the saved directory, not just the h5 model! supposed that I have a directory with the name of + bert-fa-cls-base-uncased
- config.json
- vocab.txt
- tf_model.h5 you need to pass the directory, not the model singly; I mean, load your model using this piece of code: from transformers import TFAutoModelForSequenceClassification
tf_model = TFAutoModelForSequenceClassification.from_pretrained("./bert-fa-cls-base-uncased/") |
please help me from transformers import BertConfig, BertTokenizer |
The whole process is as simple as you think! but before dive into it, we need to set some grounds
I'm going to demonstrate the entire steps regarding one of our models
0 + and a preliminary step regarding the mentioned model, in your case you don't need to this part. Step 0!pip install -qU transformers
!mkdir -p /content/bert-fa-base-uncased-sentiment-snappfood
!wget https://s3.amazonaws.com/models.huggingface.co/bert/HooshvareLab/bert-fa-base-uncased-sentiment-snappfood/config.json -qO /content/bert-fa-base-uncased-sentiment-snappfood/config.json
!wget https://cdn.huggingface.co/HooshvareLab/bert-fa-base-uncased-sentiment-snappfood/tf_model.h5 -qO /content/bert-fa-base-uncased-sentiment-snappfood/tf_model.h5
!wget https://cdn.huggingface.co/HooshvareLab/bert-fa-base-uncased-sentiment-snappfood/vocab.txt -qO /content/bert-fa-base-uncased-sentiment-snappfood/vocab.txt
!ls /content/bert-fa-base-uncased-sentiment-snappfood Output config.json tf_model.h5 vocab.txt Step 1from transformers import TFBertForSequenceClassification
from transformers import AutoConfig
from transformers import AutoTokenizer
import tensorflow as tf
import numpy as np Step 2config = AutoConfig.from_pretrained('/content/bert-fa-base-uncased-sentiment-snappfood/')
tokenizer = AutoTokenizer.from_pretrained('/content/bert-fa-base-uncased-sentiment-snappfood/')
model = TFBertForSequenceClassification.from_pretrained('/content/bert-fa-base-uncased-sentiment-snappfood/')
model.summary() Output All model checkpoint weights were used when initializing TFBertForSequenceClassification.
All the weights of TFBertForSequenceClassification were initialized from the model checkpoint at /content/bert-fa-base-uncased-sentiment-snappfood/.
If your task is similar to the task the model of the checkpoint was trained on, you can already use TFBertForSequenceClassification for predictions without further training.
Model: "tf_bert_for_sequence_classification"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
bert (TFBertMainLayer) multiple 162841344
_________________________________________________________________
dropout_37 (Dropout) multiple 0
_________________________________________________________________
classifier (Dense) multiple 1538
=================================================================
Total params: 162,842,882
Trainable params: 162,842,882
Non-trainable params: 0
_________________________________________________________________ Step 3prompt = 'این خوراک بسیار خوب است'
inputs = tokenizer.encode(prompt, return_tensors="tf", max_length=128, padding=True, truncation=True)
logits = model(inputs)[0]
outputs = tf.keras.backend.softmax(logits)
prediction = tf.argmax(outputs, axis=1)
prediction = prediction[0].numpy()
scores = outputs[0].numpy()
labels = config.id2label
print(scores)
print(labels[prediction]) Output [0.9952093 0.00479068]
HAPPY |
Thank you very much for your help |
Hello Mehrdad I used 45300 test data for the model predicate اصلاح طلبی باید راهبرد راهگشایی برای برونرفت حاکمیت ازین بن بست سیاسی چهل ساله که ریشه همه یا کمینه بیشتر مشکلات کنونی کشوراست ارائه کند وانهم تناقض وتنافر بزرگ حاکمیتی یعنی جمهوریت وولایت مطلقه است تا موضع وسمت وسوی خود را شفاف وبوضوح بیان نکند ازاصلاح طلبی فقط همان نامش را یدک میکشد,positive,political label sentence is a positive but predict political my model have 3 labels : label2id: {'negative': 0, 'political': 1, 'positive': 2}id2label: {0: 'negative', 1: 'political', 2: 'positive'}How do you think I can improve the accuracy and floss of the model to have a better prediction? |
Hello Mehrdad I used 45300 test data for the model predicate |
hello mehrdad But my lossـvalidation value increased and the accuracy decreased How can I increase my accuracy to have a better forecast(predict)? |
Epoch 1/10 |
how to fine-tune ParseBERT Model on our dataset?
Please help me ...
thanks
The text was updated successfully, but these errors were encountered: