Instructions to use abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification") model = AutoModelForCausalLM.from_pretrained("abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification
- SGLang
How to use abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification with Docker Model Runner:
docker model run hf.co/abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification
Llama-3.1-8B-Instruct-Mental-Health-Classification
This model is a fine-tuned version of meta-llama/Meta-Llama-3.1-8B-Instruct on an suchintikasarkar/sentiment-analysis-for-mental-health dataset.
Tutorial
Get started with the new Llama models and customize Llama-3.1-8B-It to predict various mental health disorders from the text by following the Fine-Tuning Llama 3.1 for Text Classification tutorial.
Use with Transformers
from transformers import AutoTokenizer,AutoModelForCausalLM,pipeline
import torch
model_id = "abdullahmazhar51/Llama-3.1-8B-Instruct-Mental-Health-Classification"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
return_dict=True,
low_cpu_mem_usage=True,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=True,
)
text = "I constantly worry about everything, even small things, and it's making it hard for me to focus on my work and enjoy life."
prompt = f"""Classify the text into Normal, Depression, Anxiety, Bipolar, and return the answer as the corresponding mental health disorder label.
text: {text}
label: """.strip()
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
torch_dtype=torch.float16,
device_map="auto",
)
outputs = pipe(prompt, max_new_tokens=2, do_sample=True, temperature=0.1)
print(outputs[0]["generated_text"].split("label: ")[-1].strip())
# Depression
Results
100%|ββββββββββ| 300/300 [03:24<00:00, 1.47it/s]
Accuracy: 0.913
Accuracy for label Normal: 0.972
Accuracy for label Depression: 0.913
Accuracy for label Anxiety: 0.667
Accuracy for label Bipolar: 0.800
Classification Report:
precision recall f1-score support
Normal 0.92 0.97 0.95 143
Depression 0.93 0.91 0.92 115
Anxiety 0.75 0.67 0.71 27
Bipolar 1.00 0.80 0.89 15
accuracy 0.91 300
macro avg 0.90 0.84 0.87 300
weighted avg 0.91 0.91 0.91 300
Confusion Matrix:
[[139 3 1 0]
[ 5 105 5 0]
[ 6 3 18 0]
[ 1 2 0 12]]
- Downloads last month
- 10