Real-time Dark Triad personality trait detection from text. Analyzes writing for narcissism, Machiavellianism, and psychopathy signals.
app - REST API + CLI for text analysis
npm install
npm run dev # Start development server# 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 3000curl -X POST http://localhost:3000/analyze \
-H "Content-Type: application/json" \
-d '{"text": "Your text to analyze..."}'{
"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"
]
}curl -X POST http://localhost:3000/analyze-batch \
-H "Content-Type: application/json" \
-d '{"texts": ["Text 1...", "Text 2...", "Text 3..."]}'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
| 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 |
- Lexicon Scorer - Uses
darktriadnpm package for word-level trait indicators - 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
Features are combined using weighted averaging (configurable):
- Lexicon: 50% weight (default)
- Stylometry: 35% weight (default)
- (Phase 2) Empath: 15% weight
| Band | Score Range | Meaning |
|---|---|---|
| Low | < 0.35 | Below threshold |
| Medium | 0.35 - 0.65 | Moderate indicators |
| High | > 0.65 | Elevated indicators |
- 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
Custom weights and thresholds via API:
{
"text": "...",
"config": {
"weights": { "lexicon": 0.6, "stylometry": 0.4, "empath": 0 },
"thresholds": { "low": 0.3, "high": 0.7 }
}
}- 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
- darktriad npm - Lexicon-based scoring
- Empath - Psychological dictionary
- DLATK - Research-grade NLP toolkit