Downloads · 30 days
0
alam1n/phi3-mbti-lora
phi3-mbti-lora is a machine learning model from alam1n. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
Downloads · 30 days
0
Access
Public
Updated Nov 14, 2025
Repo size
35.7 MB
Likes
0
Public
Click a slice to open those files.
.safetensors35.7 MB · 91%
From the Hugging Face model README
library_name: transformers tags: mbti, personality-prediction, phi3, lora, finetuned-model
This repository contains a LoRA fine‑tuned version of microsoft/Phi-3-mini-4k-instruct, optimized for MBTI personality prediction based on text input. The model is trained using Lightning AI on L40S GPUs and supports lightweight inference on T4 GPUs with 4‑bit quantization.
The model predicts MBTI types like: INTJ, ENFP, ISTP, etc.
This model adapts Phi-3-mini-4k-instruct using PEFT LoRA for efficient fine-tuning on MBTI classification from social media / profile text. It analyzes writing patterns, behaviors, and linguistic signals to output the most likely MBTI type.
microsoft/Phi-3-mini-4k-instructThe model is trained on a dataset derived from behavior/social text and may inherit biases such as:
Here is the exact inference code used for this model:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel, LoraConfig
import json
from huggingface_hub import hf_hub_download
import os
# Check versions
import transformers, peft
print(f"Transformers: {transformers.__version__}")
print(f"PEFT: {peft.__version__}")
# Model paths
model_name = "microsoft/Phi-3-mini-4k-instruct"\model_path = "alam1n/phi3-mbti-lora"
# Step 1: Download and fix the config file
print("Downloading and fixing adapter config...")
config_file = hf_hub_download(repo_id=model_path, filename="adapter_config.json")
with open(config_file, 'r') as f:
config_data = json.load(f)
print(f"Original config keys: {list(config_data.keys())}")
# Create clean config
clean_config = {
"base_model_name_or_path": config_data.get("base_model_name_or_path", model_name),
"bias": config_data.get("bias", "none"),
"fan_in_fan_out": config_data.get("fan_in_fan_out", False),
"inference_mode": True,
"init_lora_weights": config_data.get("init_lora_weights", True),
"lora_alpha": config_data.get("lora_alpha", 32),
"lora_dropout": config_data.get("lora_dropout", 0.05),
"modules_to_save": config_data.get("modules_to_save"),
"peft_type": "LORA",
"r": config_data.get("r", 16),
"target_modules": config_data.get("target_modules", []),
"task_type": config_data.get("task_type", "CAUSAL_LM")
}
with open(config_file, 'w') as f:
json.dump(clean_config, f, indent=2)
print("Config fixed!")
# Step 2: Load model with quantization
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16
)
print("Loading base model...")
model = AutoModelForCausalLM.from_pretrained(
model_name,
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True
)
print("Loading LoRA adapter...")
model = PeftModel.from_pretrained(model, model_path)
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True, trust_remote_code=True)
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
print("Model loaded successfully!")
# MBTI prediction function
def predict_mbti(person_text):
model.eval()
prompt = f"""<|system|>
You are an expert in MBTI personality analysis. Return ONLY the MBTI type.
<|end|>
<|user|>
Analyze this person's posts and determine their MBTI type:
"{person_text}"<|end|>
<|assistant|>
"""
input_ids = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**input_ids,
max_new_tokens=10,
do_sample=False,
eos_token_id=tokenizer.convert_tokens_to_ids(["<|end|"])[0],
pad_token_id=tokenizer.convert_tokens_to_ids(["<|end|"])[0]
)
generated_text = tokenizer.decode(outputs[:, input_ids['input_ids'].shape[-1]:][0], skip_special_tokens=False)
return generated_text.split("<|end|>")[0].strip()
# Test example
print(predict_mbti("I love analyzing systems and optimizing code."))
AutoTokenizer from Phi-3.Model performs well for longer text (> 40–50 words). Very short inputs may decrease accuracy.
Carbon estimation can be computed using ML CO₂ Impact calculator.
BibTeX:
@model{phi3_mbti_lora,
title={Phi-3 Mini MBTI Classifier},
author={Md Al Amin},
year={2025},
publisher={HuggingFace}
}
Md Al Amin (alam1n)
For questions/issues: Open an issue in this repository.