Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,3 @@ print(f"Rewritten: {rewritten_text}")

```


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

### Using the CLI command

```bash
# 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
```bash
# From the root directory
python3 -m reframe.tests.run_all_tests
52 changes: 25 additions & 27 deletions example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Reframe Package Example Notebook\n",
"# Destigmatizer (Reframe) Package Example Notebook\n",
"\n",
"This notebook demonstrates the core functionality of the Reframe package for analyzing and rewriting drug-related and stigmatizing content.\n",
"This notebook demonstrates the core functionality of the Destigmatizer package for analyzing and rewriting drug-related and stigmatizing content.\n",
"\n",
"## Features demonstrated:\n",
"1. Classifying drug-related content\n",
Expand All @@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -43,14 +43,14 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Client initialized with model: gpt-4o-2024-11-20\n"
"Client initialized with model: gpt-4o\n"
]
}
],
Expand All @@ -73,13 +73,13 @@
"# Initialize client\n",
"client = get_client('openai', api_key=api_key)\n",
"# model = get_default_model('openai') # Get default model for this client type\n",
"model = \"gpt-4o-2024-11-20\"\n",
"model = \"gpt-4o\" \n",
"print(f\"Client initialized with model: {model}\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -106,7 +106,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -140,7 +140,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 33,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -201,7 +201,7 @@
" top_p: 0.9\n",
" highly_creative:\n",
" model_name: medium\n",
" temperature: 0.9\n",
" temperature: 0.0\n",
" max_tokens: 2500\n",
" top_p: 0.95\n",
" frequency_penalty: 0.2\n",
Expand All @@ -211,7 +211,7 @@
"\n",
"Updated configuration:\n",
"model_name: medium\n",
"temperature: 0.9\n",
"temperature: 0.0\n",
"max_tokens: 2500\n",
"top_p: 0.95\n",
"frequency_penalty: 0.2\n"
Expand Down Expand Up @@ -246,7 +246,7 @@
" config,\n",
" name=\"highly_creative\",\n",
" model_name=\"medium\",\n",
" temperature=0.9,\n",
" temperature=0.0,\n",
" max_tokens=2500,\n",
" top_p=0.95,\n",
" frequency_penalty=0.2\n",
Expand All @@ -271,7 +271,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 34,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -310,7 +310,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 35,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -356,7 +356,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 36,
"metadata": {},
"outputs": [
{
Expand All @@ -367,10 +367,10 @@
"Stigma classification result: ns\n",
"\n",
"Classifying stigmatizing language for: \"Addicts really need to get control of themselves. ...\"\n",
"Stigma classification result: s, labeling: uses the term 'addicts,' which is stigmatizing and reduces individuals to their substance use, stereotyping: assumes that people with addiction lack willpower and oversimplifies the complexity of addiction, separation: implies a divide between people who use drugs and those who are perceived as having self-control, discrimination: suggests that people with addiction are at fault for their condition, potentially justifying a lack of support or empathy.\n",
"Stigma classification result: s, labeling: uses the term 'addicts' in a derogatory manner, stereotyping: assumes that people with addiction simply lack willpower, ignoring the complexity of substance use disorders, separation: implies a moral failing, creating a divide between those who use drugs and those who don't, discrimination: suggests that people with addiction are responsible for their condition and undeserving of empathy or support.\n",
"\n",
"Classifying stigmatizing language for: \"I think we should really work on the housing crisi...\"\n",
"Stigma classification result: s, labeling: refers to homeless individuals in a generalized and dehumanizing way, stereotyping: implies that homeless individuals are inherently \"scary,\" which perpetuates negative assumptions, separation: creates an \"us vs. them\" dynamic by portraying homeless individuals as a threat, discrimination: suggests fear-based attitudes that could lead to exclusion or unfair treatment of homeless individuals, many of whom may struggle with substance use disorders.\n"
"Stigma classification result: s, labeling: refers to homeless individuals in a way that implies they are inherently frightening, stereotyping: implies that homeless individuals, who may include people with substance use disorders, are dangerous, separation: creates a divide between housed individuals and those experiencing homelessness, discrimination: suggests that homeless individuals are a problem to be managed rather than people in need of support and resources.\n"
]
}
],
Expand Down Expand Up @@ -402,7 +402,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 37,
"metadata": {},
"outputs": [
{
Expand All @@ -411,15 +411,15 @@
"text": [
"Analyzing text for drug content and stigma: \"Addicts really need to get control of themselves. ...\"\n",
"Drug classification: d\n",
"Stigma classification: s, labeling: uses the term 'addicts,' which is stigmatizing and reduces individuals to their substance use, stereotyping: assumes that people with addiction lack willpower and oversimplifies the complexity of addiction, separation: implies a divide between people who use drugs and those who are perceived as having self-control, discrimination: suggests that people with addiction are at fault for their condition, potentially justifying a lack of support or empathy.\n",
"Stigma classification: s, labeling: uses the term 'addicts' in a derogatory manner, stereotyping: assumes that people with addiction simply lack willpower, ignoring the complexity of substance use disorders, separation: implies a moral failing, creating a divide between those who use drugs and those who don't, discrimination: suggests that people with addiction are responsible for their condition and undeserving of empathy or support.\n",
"\n",
"Analyzing text for drug content and stigma: \"I really feel for people who suffer from substance...\"\n",
"Drug classification: nd\n",
"Stigma classification: ns\n",
"\n",
"Analyzing text for drug content and stigma: \"I think we should really work on the housing crisi...\"\n",
"Drug classification: nd\n",
"Stigma classification: s, labeling: refers to homeless individuals in a generalized and dehumanizing way, stereotyping: implies that homeless individuals are inherently \"scary,\" which perpetuates negative assumptions, separation: creates an \"us vs. them\" dynamic by portraying homeless individuals as a threat, discrimination: suggests fear-based attitudes that could lead to exclusion or unfair treatment of homeless individuals, many of whom may struggle with substance use disorders.\n"
"Stigma classification: s, stereotyping: implies that homeless individuals are inherently frightening, reinforcing negative generalizations, separation: creates a divide between housed individuals and those experiencing homelessness, suggesting they are 'other' and to be feared, discrimination: could lead to support for policies that further marginalize homeless individuals rather than addressing root causes.\n"
]
}
],
Expand Down Expand Up @@ -460,7 +460,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 38,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -496,15 +496,15 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 39,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Original: Addicts really need to get control of themselves. Just stop doing drugs. It seems like these people are just lacking willpower.\n",
"Rewritten: people struggling with substance use face complex challenges. recovery requires support, understanding, and access to resources.\n"
"Rewritten: individuals struggling with substance use need support and understanding. recovery is a complex process. it requires compassion and assistance.\n"
]
}
],
Expand Down Expand Up @@ -540,17 +540,15 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Step 1: Classifying drug-related content...\n",
"Text is not drug-related. Skipping further analysis.\n",
"Original: Addicts really need to get control of themselves. Just stop doing drugs. It seems like these people are just lacking willpower.\n",
"Rewritten: Addicts really need to get control of themselves. Just stop doing drugs. It seems like these people are just lacking willpower.\n"
"Rewritten: individuals struggling with substance use need support and understanding. recovery is a journey. it seems like these individuals face many challenges.\n"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion reframe_example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"highly_creative": {
"model_name": "medium",
"temperature": 0.9,
"temperature": 0.0,
"max_tokens": 2500,
"top_p": 0.95,
"frequency_penalty": 0.2
Expand Down
63 changes: 30 additions & 33 deletions src/destigmatizer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,58 @@
"""
Reframe: A Python package for destigmatizing language related to drug use.
Destigmatizer: A Python package for destigmatizing language related to drug use.

This package provides tools to identify, analyze, and rewrite text
containing stigmatizing language.
"""

# Import from core for backward compatibility
# Core functions
from .core import (
initialize,
analyze_and_rewrite_text,
classify_if_drug,
classify_if_stigma,
analyze_text_llm,
rewrite_to_destigma,
get_emotion,
analyze_and_rewrite_text
rewrite_to_destigma
)

# Import main classes for direct access
from .clients import LLMClient, OpenAIClient, TogetherClient, ClaudeClient, get_client
from .classifiers import BaseClassifier, DrugClassifier, StigmaClassifier
from .analyzers import TextAnalyzer, StyleAnalyzer, EmotionAnalyzer, LLMBasedAnalyzer
from .rewriters import TextRewriter, DestigmatizingRewriter
from .utils import get_model_mapping, get_default_model, determine_client_type, load_user_model_configs
# Pipeline components
from .pipeline import create_pipeline, TextPipeline
from .filters import (
classify_drug_filter,
classify_stigma_filter,
analyze_style_filter,
rewrite_text_filter
)

# Original components for backward compatibility
from .clients import get_client, LLMClient, OpenAIClient, TogetherClient, ClaudeClient
from .utils import get_model_mapping, get_default_model

__all__ = [
# Core functions (backward compatibility)
# Core functions
'initialize',
'analyze_and_rewrite_text',
'classify_if_drug',
'classify_if_stigma',
'analyze_text_llm',
'rewrite_to_destigma',
'get_emotion',
'analyze_and_rewrite_text',

# Client classes
# Pipeline components
'create_pipeline',
'TextPipeline',
'classify_drug_filter',
'classify_stigma_filter',
'analyze_style_filter',
'rewrite_text_filter',

# Client utilities
'get_client',
'LLMClient',
'OpenAIClient',
'TogetherClient',
'ClaudeClient',
'get_client',

# Classifier classes
'BaseClassifier',
'DrugClassifier',
'StigmaClassifier',

# Analyzer classes
'TextAnalyzer',
'StyleAnalyzer',
'EmotionAnalyzer',
'LLMBasedAnalyzer',

# Rewriter classes
'TextRewriter',
'DestigmatizingRewriter',

# Model utilities
'get_model_mapping',
'get_default_model',
'load_user_model_configs'
'get_default_model'
]
Loading