| | --- |
| | license: afl-3.0 |
| | language: |
| | - en |
| | base_model: |
| | - google/flan-t5-xl |
| | pipeline_tag: text-classification |
| | tags: |
| | - personality |
| | --- |
| | |
| |
|
| |
|
| | ## Model Details |
| |
|
| | * **Model Type:** PersonalityClassifier is a fine-tuned model from `google/flan-t5-xl` using annotation data for personality classification. |
| | * **Model Date:** PersonalityClassifier was trained in Jan 2024. |
| | * **Paper or resources for more information:** [https://arxiv.org/abs/2504.06868](https://arxiv.org/abs/2504.06868) |
| | * **Train data:** [https://huggingface.co/datasets/mirlab/personality_120000](https://huggingface.co/datasets/mirlab/personality_120000) |
| | ## Requirements |
| |
|
| | * `torch==2.1.0` |
| | * `transformers==4.29.0` |
| |
|
| | ## How to use the model |
| |
|
| | ```python |
| | import torch |
| | from transformers import T5ForConditionalGeneration, AutoTokenizer |
| | |
| | # Set device to CUDA if available, otherwise use CPU |
| | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
| | |
| | # Load model and tokenizer |
| | model_name = "mirlab/PersonalityClassifier" |
| | tokenizer = AutoTokenizer.from_pretrained(model_name) |
| | model = T5ForConditionalGeneration.from_pretrained(model_name).to(device) |
| | |
| | # Define model inference function |
| | def modelGenerate(input_text, lm, tokenizer): |
| | # Tokenize input text and move to device |
| | input_ids = tokenizer(input_text, truncation=True, padding=True, return_tensors='pt')['input_ids'].to(device) |
| | |
| | # Generate text using the model |
| | model_output = lm.generate(input_ids) |
| | |
| | # Decode generated tokens into text |
| | model_answer = tokenizer.batch_decode(model_output, skip_special_tokens=True) |
| | |
| | return model_answer |
| | |
| | # Example input text |
| | # Format: "[Valence] Statement: [Your Statement]. Trait: [Target Trait]" |
| | # Target Trait is among ["Openness", "Conscientiousness", "Extraversion", "Agreeableness", "Neuroticism", "Machiavellianism", "Narcissism", "Psychopathy"]. |
| | # Valence indicates positive (+) or negative (-) alignment with the trait. |
| | |
| | input_texts = "[Valence] Statement: I am outgoing. Trait: Extraversion" |
| | |
| | # Generate output using the model and print |
| | output_texts = modelGenerate(input_texts, model, tokenizer) |
| | print(output_texts) |