Skip to main content

An llm-powered platform-agnostic language utility for destigmatizing drug language

Project description

Destigmatizer (Reframe)

Python library that leverages LLMs to remove harmful language from texts on drug use.

Testing

You can explore Destigmatizer's functionality interactively using Jupyter notebooks. Below is an example of how to classify and rewrite text using the library.

Using Destigmatizer in a Jupyter Notebook

Installing and Set Up

!pip install destigmatizer

# Import the destigmatizer package
import destigmatizer
from destigmatizer import core
from destigmatizer.clients import get_client
from destigmatizer.utils import get_default_model, get_model_mapping
import json
import os

# Define example texts
NON_DRUG_POST = "I think we should really work on the housing crisis in urban areas. The homeless are getting scary."
DRUG_NON_STIGMA_POST = "I really feel for people who suffer from substance use disorder, being unable to control an impulse due to dependency sounds scary."
DRUG_AND_STIGMA_POST = "Addicts really need to get control of themselves. Just stop doing drugs. It seems like these people are just lacking willpower."

# Set up API client
# for example OpenAI

client = get_client('openai', api_key=api_key)

Classifying Drug-Related and Stigmatizing Content

# Classify whether a text is drug-related and whether it contains stigma
drug_classification = core.classify_drug_content([NON_DRUG_POST, DRUG_NON_STIGMA_POST, DRUG_AND_STIGMA_POST], client, model)
stigma_classification = core.classify_stigma([NON_DRUG_POST, DRUG_NON_STIGMA_POST, DRUG_AND_STIGMA_POST], client, model)

# Print results
for text, drug_label, stigma_label in zip([NON_DRUG_POST, DRUG_NON_STIGMA_POST, DRUG_AND_STIGMA_POST], drug_classification, stigma_classification):
    print(f"Text: {text}\nDrug-related: {drug_label}\nStigmatizing: {stigma_label}\n")

Rewwriting Stigmatizing Content

# Rewrite a stigmatizing post to be more empathetic
rewritten_text = core.rewrite_stigmatizing_text(DRUG_AND_STIGMA_POST, client, model)

print(f"Original: {DRUG_AND_STIGMA_POST}")
print(f"Rewritten: {rewritten_text}")

Reframe includes integrated tests for all major functions. You can run tests in two ways:

Using the CLI command

# Test all functions
reframe-test

# Test a specific function
reframe-test drug --api_key YOUR_API_KEY

# Use a specific model with Together AI
reframe-test --client_type together --model "meta-llama/Meta-Llama-3.1" 

# Use Claude
reframe-test --client_type claude --model "claude-3-haiku-20240307"

# Using environment variables (recommended)
# First set the environment variables:
export OPENAI_API_KEY="your-openai-key"
export TOGETHER_API_KEY="your-together-key"
export ANTHROPIC_API_KEY="your-anthropic-key"

# Then run tests without specifying the API key
reframe-test --client_type openai
reframe-test --client_type together
reframe-test --client_type claude

Running test scripts directly

# From the root directory
python3 -m reframe.tests.run_all_tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

destigmatizer-0.0.11.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

destigmatizer-0.0.11-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file destigmatizer-0.0.11.tar.gz.

File metadata

  • Download URL: destigmatizer-0.0.11.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for destigmatizer-0.0.11.tar.gz
Algorithm Hash digest
SHA256 3b277e7626cb1ddd1619d97a1d00e5fc379d5c78fac35d367cbd718ac1c68265
MD5 2b68d14773ca6bf229fac2100d06de71
BLAKE2b-256 fd68aed4345b9208d9d7a03dd35eed19596cecd51d26ba7deab497bb8c0069d5

See more details on using hashes here.

File details

Details for the file destigmatizer-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: destigmatizer-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for destigmatizer-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 99dd9f46684fdc6fe506e30f8ea04d5f0a13f6f0f36dd6e145d66c32fe52a587
MD5 5a9f9db15c71d81d796a2fddbf7b176e
BLAKE2b-256 00604417903323440256c57c3a58e17a9117c1fabe60c156e7a1cbb463092706

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page