Model Description
- Many of the most significant developments in the modern corporate sector are driven by data. Data will become more crucial and revolutionary to daily individual operations in the near future.
- In order to predict the Big Five personality traits for this project, I employed transfer learning using the microsoft/MiniLM-L12-H384-uncased.
- The model's learning patterns between personality attributes and input text were refined using a carefully selected dataset for personality traits.
- The microsoft/MiniLM-L12-H384-uncased model increased the prediction accuracy of personality traits by utilising transfer learning to reach more than 97% comparing to my last model which was depended on roberta-large "65%".
- This finetuned model is able to estimate an individual's Big Five personality traits based on their input text with high accuracy by utilising transfer learning and optimising microsoft/MiniLM-L12-H384-uncased.
- This experiment demonstrates the efficacy of predicting the Big Five personality traits and the strength of transfer learning in machine learning.
- Developed by: [Nasser Elsaman]
- Model type: [Text/ Personality Classification Model]
- Language (NLP): [English]
- License: [MIT]
- Finetuned from model: microsoft/MiniLM-L12-H384-uncased
- Goal from this finetuned model: This model is for educational and research purposes only, any uses outside of this, the author is not responsible.
- Hardware Type: [Free GPU from Google Colab]
- Hours used: [ > 4 Hours]
- Software: [Google Colab]
Uses:-
Direct Use:
- Individuals can utilise the personality prediction model directly to acquire insights into their own personality qualities based on the input text. Users can input text to get predictions for the Big Five personality characteristics, and this model is for educational and research purposes only, any uses outside of this, the author is not responsible.
Downstream Use:
- This model is designed for later usage or fine-tuning for certain needs. It was created as a stand-alone personality prediction finetuned model.
Out-of-Scope Use:
- Use this model with caution when making significant choices about people in fields like employment, education, or law.
Biases, Risks, and Limitations:
- The personality prediction model, like any machine learning models, has limits and potential biases that should be considered.
Generalisations:
- The algorithm predicts personality qualities using patterns acquired from a given dataset. Its results will not alter when applied to people from diverse ethnic or cultural backgrounds who are underrepresented in the training data.
Ethical considerations:
- Personality prediction models should be utilised responsibly, with the awareness that personality features do not define a person's value or talents. It is critical to avoid forming unjust judgements or discriminating against someone based on their expected personality characteristics.
Privacy concerns:
- The model is based on user-provided input text, which may include sensitive or confidential information. Users should be cautious while giving personal information and maintain the security of their data.
Recommendations:
- To reduce the dangers and limits associated with personality prediction models, the following guidelines are proposed:
Awareness and Education:
- Users should understand the model's limits and potential biases. Increase awareness that personality traits are multifaceted and cannot be fully represented by a single model or text analysis.
Avoid Stereotypes and Discrimination:
- Users should use caution when making judgements or conclusions based primarily on projected personality attributes. Personality forecasts should not be used to discriminate against people or reinforce stereotypes, and this model is for educational and research purposes only.
Contextual Interpretation:
- Place the model's predictions in context and evaluate extra information about the individual beyond the input text.
Data Privacy and Security:
- Ensure that user data is processed securely and in accordance with privacy legislation. Users should be cautious while giving personal information.
Promote Ethical Use:
Encourage the proper use of personality prediction models while discouraging abuse or harmful uses.
It is crucial to highlight that the preceding recommendations are generic principles; additional context-specific recommendations should be made depending on the individual use case and the ethical issues.
How to Get Started with the Model:
Use the code below to get started with the model.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
def personality_detection(text, threshold=0.05, endpoint= 1.0):
token="Write_Your_HUG_Access_token_Id_Here"
tokenizer = AutoTokenizer.from_pretrained ("Nasserelsaman/microsoft-finetuned-personality",token=token)
model = AutoModelForSequenceClassification.from_pretrained ("Nasserelsaman/microsoft-finetuned-personality",token=token)
inputs = tokenizer(text, truncation=True, padding=True, return_tensors="pt")
outputs = model(**inputs)
predictions = outputs.logits.squeeze().detach().numpy()
# Get raw logits
logits = model(**inputs).logits
# Apply sigmoid to squash between 0 and 1
probabilities = torch.sigmoid(logits)
# Set values less than the threshold to 0.05
predictions[predictions < threshold] = 0.05
predictions[predictions > endpoint] = 1.0
label_names = ['Agreeableness', 'Conscientiousness', 'Extraversion', 'Neuroticism', 'Openness']
result = {label_names[i]: f"{predictions[i]*100:.0f}%" for i in range(len(label_names))}
return result
Results
[I get a fine-tuned model with a high accuracy more than 97%; test by yourself on my streamlit app
The personality_detection function returns a dictionary containing the predicted personality traits based on the given input text. The dictionary contains the following personality traits with their corresponding predicted values:
- Agreeableness: A value between 5% and 100% represents the predicted agreeableness trait.
- Conscientiousness: A value between 5% and 100% represents the predicted conscientiousness trait.
- Extroversion: A value between 5% and 100% represents the predicted extroversion trait.
- Neuroticism: A value between 5% and 100% represents the predicted neuroticism trait.
- Openness: A value between 5% and 100% represents the predicted openness trait.
Please note that I made the min value is 5% not 0% as 0% has no meaning but 5% means the user has low peronslaity type in this trait, but max value 100% meaning this personality type is the dominant type.
Example:-
text_input = "Strongly Agree with that I am the life of the party. Disagree with that I sympathize with othersโ feelings. Strongly Agree with that I get chores done right away. Disagree with that I have frequent mood swings. Disagree with that I have a vivid imagination. Neutral with that I donโt talk a lot. Strongly Disagree with that I am not interested in other peopleโs problems. Neutral with that I often forget to put things back in their proper place. Strongly Agree with that I am relaxed most of the time. Neutral with that I am not interested in abstract ideas. Strongly Agree with that I talk to a lot of different people at parties. Agree with that I feel othersโ emotions. Disagree with that I like order. Strongly Agree with that I get upset easily. Neutral with that I have difficulty understanding abstract ideas. Strongly Disagree with that I keep in the background. Agree with that I am not really interested in others. Strongly Disagree with that I make a mess of things. Strongly Agree with that I seldom feel blue. Strongly Disagree with that I do not have a good imagination."
personality_prediction = personality_detection(text_input) print(personality_prediction)
Output:-
{ "Agreeableness":"5%" "Conscientiousness":"5%" "Extraversion":"6%" "Neuroticism":"100%" "Openness":"5%" }
* In addition to a spider graph in my streamlit app
Epochs:
- There were 3 epochs only, and I got a high accuracy from the second one as follows without overfitting:
Epoch | Training Loss | Validation Loss | Accuracy |
---|---|---|---|
1 | 0.626600 | 0.188280 | 0.945493 |
2 | 0.166500 | 0.095803 | 0.970488 |
3 | 0.104300 | 0.074864 | 0.976524 |
** Please note the following points explaining my result and why this were not overfitting:
- With a large training dataset of 360,855 samples, good performance may be achieved in a few epochs. The model has enough data to learn from.
- Using a pretrained language model, such as microsoft/MiniLM-L12-H384-uncased, results in stronger initialization, allowing for faster convergence than random initialization, and this model with 12-layer, 384-hidden, 12-heads, 33M parameters, and 2.7x faster than BERT-Base and for more details in this point check the paper "MiniLM: Deep Self-Attention Distillation for Task-Agnostic Compression of Pre-Trained Transformers".
- The low training and validation losses after only 2-3 epochs show that the model is fitting the data correctly and is not overfitting.
- Increasing accuracy and decreasing loss values over epochs demonstrate smooth continuous learning, rather than spikes, which may imply overfitting.
- The high accuracy of 97.65% after only three epochs is amazing and understandable considering the massive sample quantity, pretrained weights, and smooth learning curves.
Evaluation Metrics:
- The evaluation metrics used are: Accuracy, Recall and F1-score.
- Accuracy:- Training data (0.976524) - Test data (0.9765239651189411)
- Recall:- {'recall': 0.9765239651189411}
- F1-score:- {'f1': 0.9765239651189411}
Citation:
@misc{wang2020minilm,
author = {Wenhui Wang and
Furu Wei and
Li Dong and
Hangbo Bao and
Nan Yang and
Ming Zhou},
title = {MiniLM: Deep Self-Attention Distillation for Task-Agnostic Compression of Pre-Trained Transformers},
year = {2020},
url = {http://arxiv.org/abs/1810.04805},
archivePrefix = {arXiv},
eprint = {2002.10957},
primaryClass={cs.CL}
}
Model Summary:
- Model_Name: microsoft/MiniLM-L12-H384-uncased
- Dataset Size: 360855 rows; after making data cleansing and class balance to the Kaggle personality dataset
- Num_Of_Epochs: 3
- Tokenizer Max_length: 275
- Batch size: 64
- Learning Rate: 5e-6
- Software: Google Colab with free GPU
* Final Finetuning Model is: Nasserelsaman/microsoft_finetuned_personality, and please note that his model is for educational and research purposes only, any uses outside of this, the author is not responsible.
* Model streamlit app: Personality_Assessment
* This project is based on The Mini IPIP personality measure
Model Card Authors:
- Downloads last month
- 195