Fine-Tuned SBERT MiniLM for Mental Health Classification

A fine-tuned Sentence-BERT (SBERT) model based on sentence-transformers/all-MiniLM-L6-v2, developed for binary mental-health text classification.

The model generates 384-dimensional sentence embeddings using the fine-tuned SBERT encoder. These embeddings are passed to a trained Logistic Regression classifier to classify text into Non-MH or MH.

Model Pipeline

Input Text
    |
    v
Fine-Tuned SBERT
(all-MiniLM-L6-v2)
    |
    v
Mean Pooling
    |
    v
L2 Normalization
    |
    v
384-Dimensional Embedding
    |
    v
Logistic Regression
    |
    v
Non-MH / MH

Model Details

Property Value
Base Model sentence-transformers/all-MiniLM-L6-v2
Architecture BERT / MiniLM
Transformer Layers 6
Attention Heads 12
Hidden Size 384
Embedding Dimension 384
Pooling Mean Pooling
Normalization L2 Normalization
Project Max Sequence Length 32 tokens
Downstream Classifier Logistic Regression
Number of Classes 2
Labels Non-MH, MH

Logistic Regression Configuration

C = 1.0
class_weight = balanced
max_iter = 1000

Repository Contents

.
β”œβ”€β”€ 1_Pooling/
β”‚   └── config.json
β”œβ”€β”€ config.json
β”œβ”€β”€ config_sentence_transformers.json
β”œβ”€β”€ logistic_regression_classifier.joblib
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ modules.json
β”œβ”€β”€ sentence_bert_config.json
β”œβ”€β”€ special_tokens_map.json
β”œβ”€β”€ tokenizer.json
β”œβ”€β”€ tokenizer_config.json
└── vocab.txt

Key Files

  • model.safetensors β€” fine-tuned SBERT model weights
  • config.json β€” Transformer model configuration
  • config_sentence_transformers.json β€” Sentence Transformers configuration
  • modules.json β€” Sentence Transformers module configuration
  • 1_Pooling/config.json β€” mean-pooling configuration
  • tokenizer.json β€” tokenizer
  • tokenizer_config.json β€” tokenizer configuration
  • vocab.txt β€” vocabulary
  • logistic_regression_classifier.joblib β€” trained Logistic Regression classifier

Installation

pip install sentence-transformers scikit-learn joblib

Usage

1. Load the Fine-Tuned SBERT Model

from sentence_transformers import SentenceTransformer

encoder = SentenceTransformer(
    "AbdullahImran/Fine-Tuned-SBERT-MiniLM"
)

2. Generate Sentence Embeddings

texts = [
    "I have been feeling very anxious lately.",
    "The weather is beautiful today."
]

embeddings = encoder.encode(texts)

print(embeddings.shape)

The resulting embeddings have 384 dimensions.

3. Load the Classifier

Download logistic_regression_classifier.joblib from this repository and load it:

import joblib

classifier = joblib.load(
    "logistic_regression_classifier.joblib"
)

4. Perform Classification

predictions = classifier.predict(embeddings)

print(predictions)

The classifier uses the following label encoding:

0 β†’ Non-MH
1 β†’ MH

For example:

for text, prediction in zip(texts, predictions):
    label = "MH" if prediction == 1 else "Non-MH"
    print(f"{text} -> {label}")

Complete Example

from sentence_transformers import SentenceTransformer
import joblib

# Load the fine-tuned encoder
encoder = SentenceTransformer(
    "AbdullahImran/Fine-Tuned-SBERT-MiniLM"
)

# Load the trained classifier
classifier = joblib.load(
    "logistic_regression_classifier.joblib"
)

# Input text
texts = [
    "I have been feeling overwhelmed and anxious recently.",
    "I went to the park and enjoyed the sunny weather."
]

# Generate embeddings
embeddings = encoder.encode(texts)

# Classify
predictions = classifier.predict(embeddings)

# Display results
for text, prediction in zip(texts, predictions):
    label = "MH" if prediction == 1 else "Non-MH"
    print(f"{label}: {text}")

Intended Use

This model is intended for:

  • NLP research
  • Mental-health text classification research
  • Sentence embedding experimentation
  • Development and evaluation of binary text classification pipelines

This model is not a medical or clinical diagnostic system and should not be used to diagnose, treat, or make clinical decisions about individuals.

Limitations

Mental-health-related language is highly contextual and can be ambiguous. Model performance depends on the quality, distribution, and representativeness of the training data.

Performance may vary when the model is applied to text from domains, populations, writing styles, or distributions that differ from the training data.

Predictions should therefore be treated as machine-learning outputs rather than clinical assessments.

The Logistic Regression classifier is serialized using joblib. Loading it may require compatible Python and scikit-learn versions.

Project Context

This model is part of a broader Mental Health NLP project involving:

  1. Dataset preparation and cleaning
  2. Mental-health and non-mental-health text classification
  3. SBERT fine-tuning
  4. Sentence embedding generation
  5. Logistic Regression classification
  6. Deployment-oriented model packaging

The repository contains the final fine-tuned SBERT encoder and the associated downstream classifier used by the classification pipeline.

Downloads last month
60
Safetensors
Model size
22.7M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for AbdullahImran/Fine-Tuned-SBERT-MiniLM