Skip to content

Yolan10/Dark-Triad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dark-Triad

Real-time Dark Triad personality trait detection from text. Analyzes writing for narcissism, Machiavellianism, and psychopathy signals.

Type

app - REST API + CLI for text analysis

Quick Start

npm install
npm run dev     # Start development server

CLI Usage

# Analyze text directly
npm run cli analyze "I am the best and everyone knows it"

# Analyze from file
npm run cli analyze-file ./email.txt --verbose

# Start API server
npm run cli serve --port 3000

API Usage

Analyze Single Text

curl -X POST http://localhost:3000/analyze \
  -H "Content-Type: application/json" \
  -d '{"text": "Your text to analyze..."}'

Response Format

{
  "textSnippet": "Your text to analyze...",
  "traits": {
    "narcissism": { "score": 0.62, "band": "medium", "confidence": 0.7 },
    "machiavellianism": { "score": 0.34, "band": "low", "confidence": 0.7 },
    "psychopathy": { "score": 0.45, "band": "medium", "confidence": 0.7 }
  },
  "overallRisk": "medium",
  "featureBreakdown": {
    "lexicon": { "narcissism": 0.55, "machiavellianism": 0.30, "psychopathy": 0.40 },
    "stylometry": { "firstPersonRatio": 0.08, "negativeEmotionRatio": 0.02 }
  },
  "caveats": [
    "Scores are research-grade indicators, not clinical diagnostics",
    "Best used for aggregate/segmentation analysis, not individual diagnosis"
  ]
}

Batch Analysis

curl -X POST http://localhost:3000/analyze-batch \
  -H "Content-Type: application/json" \
  -d '{"texts": ["Text 1...", "Text 2...", "Text 3..."]}'

Structure

Dark-Triad/
├── src/
│   ├── app/server.ts       # Fastify REST API
│   ├── cli/index.ts        # CLI interface
│   ├── lib/
│   │   ├── types.ts        # Type definitions
│   │   ├── ensemble.ts     # Score combination
│   │   ├── risk-bands.ts   # Band classification
│   │   └── scorers/        # Feature extractors
│   └── index.ts            # Library exports
├── tests/
├── package.json
└── tsconfig.json

Commands

Command Description
npm run dev Development server with hot reload
npm run build Compile TypeScript
npm start Production server
npm run cli Run CLI commands
npm test Run tests

How It Works

Feature Extractors

  1. Lexicon Scorer - Uses darktriad npm package for word-level trait indicators
  2. Stylometry - Extracts linguistic style features:
    • First-person pronoun ratio (I/me/my) → narcissism signal
    • Negative emotion words → psychopathy signal
    • Certainty markers (always/never) → Machiavellianism signal

Ensemble Scoring

Features are combined using weighted averaging (configurable):

  • Lexicon: 50% weight (default)
  • Stylometry: 35% weight (default)
  • (Phase 2) Empath: 15% weight

Risk Bands

Band Score Range Meaning
Low < 0.35 Below threshold
Medium 0.35 - 0.65 Moderate indicators
High > 0.65 Elevated indicators

Important Limitations

  • Not a diagnostic tool - Research-grade indicators only
  • Context matters - Professional/formal text suppresses signals
  • Expected accuracy - Literature suggests ~r=0.25 correlation with actual traits
  • Best use case - Aggregate/segmentation analysis, not individual diagnosis

Configuration

Custom weights and thresholds via API:

{
  "text": "...",
  "config": {
    "weights": { "lexicon": 0.6, "stylometry": 0.4, "empath": 0 },
    "thresholds": { "low": 0.3, "high": 0.7 }
  }
}

Roadmap

  • Phase 1: Lexicon + Stylometry scoring (MVP)
  • Phase 2: Empath integration (Python bridge)
  • Phase 3: Embedding-based scoring (sentence-transformers)
  • Phase 4: Calibration against benchmark datasets

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors