Skip to main content

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

Metadata

Release files for destigmatizer 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for destigmatizer 0.0.12
File Size Uploaded Provenance Actions
destigmatizer-0.0.12.tar.gz 32.9 kB Without provenance Details for destigmatizer-0.0.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for destigmatizer 0.0.12
File Interpreter ABI Platform Actions
destigmatizer-0.0.12-py3-none-any.whl Python 3 none any Details for destigmatizer-0.0.12-py3-none-any.whl

Total release size: 65.5 kB

Release files / destigmatizer-0.0.12.tar.gz

Download URL destigmatizer-0.0.12.tar.gz
Size 32.9 kB
Tags Source
SHA-256 checksum
How to use checksums
33eb377bcf808fdf0704aa75afc3922188797698dd739769bb7d2156517a6d45
BLAKE2b-256 checksum
How to use checksums
0814f512c858823f4038025dd8655363c3f26056796f81682da548ab829af28e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / destigmatizer-0.0.12-py3-none-any.whl

Download URL destigmatizer-0.0.12-py3-none-any.whl
Size 32.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cb23a83f0e328ad3687755f467c551ee21a615e32faca7d1a67827b526ecebc
BLAKE2b-256 checksum
How to use checksums
e142d3822821cb78331c0ea5ea24d0360940ec896277537a06c597f7a24fc596
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for destigmatizer 0.0.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.12 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page