|
| 1 | +# ChatRel |
| 2 | + |
| 3 | +**Apply 7 empirically-grounded psychology frameworks to your chat history with a partner. 100% local, privacy-preserving. Chinese + English.** |
| 4 | + |
| 5 | +[中文 README](README.zh.md) · [Methodology](docs/methodology.md) · [Limitations](docs/limitations.md) · [Schema](docs/schema.md) |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +Most chat analyzers give you a word cloud, a sentiment line, and a heatmap. ChatRel does the opposite: it takes the dyadic interaction signals you already generated — in seven months of messaging your partner — and maps them onto the frameworks relationship scientists have actually studied for 40+ years: |
| 10 | + |
| 11 | +| Framework | What it measures | Anchor citation | |
| 12 | +|---|---|---| |
| 13 | +| **Sternberg Triangular** | Intimacy × Passion × Commitment as three separable axes | Sternberg (1986) | |
| 14 | +| **Knapp Stages** | 10-stage model of relational development (Initiating → Bonding, then Differentiating → Terminating) | Knapp (1978) | |
| 15 | +| **ECR-R Attachment** | Anxiety × Avoidance dimensions, mapped to Bartholomew 4-category types | Fraley, Waller & Brennan (2000); Bartholomew & Horowitz (1991) | |
| 16 | +| **Gottman 5:1 + Four Horsemen** | Positive-to-negative interaction ratio; criticism/contempt/defensiveness/stonewalling density | Gottman (1994) | |
| 17 | +| **Social Penetration** | Self-disclosure depth layered from shallow → core | Altman & Taylor (1973) | |
| 18 | +| **Critical Slowing (EWS)** | Rising variance + AR(1) as early-warning for regime shifts | Scheffer et al. (2009) | |
| 19 | +| **LIWC (Chinese proxy)** | Function-word / cognitive / affective markers | Pennebaker et al. | |
| 20 | + |
| 21 | +**Output** is seven linked interactive HTML reports (Plotly-based), one per framework plus a curated memory book and a portal index. Everything runs on your machine. No data is ever sent anywhere. |
| 22 | + |
| 23 | +## Screenshots |
| 24 | + |
| 25 | +<!-- screenshots go in docs/screenshots/; commit ones generated from synthetic data only --> |
| 26 | + |
| 27 | +`docs/screenshots/` contains demo images generated from the synthetic dataset shipped in `sample_data/`. |
| 28 | + |
| 29 | +## Install |
| 30 | + |
| 31 | +```bash |
| 32 | +git clone https://github.com/marycollins6715569-alt/chatrel.git |
| 33 | +cd chatrel |
| 34 | +pip install -e . |
| 35 | +``` |
| 36 | + |
| 37 | +Requires Python 3.10+. Dependencies: `jieba`, `snownlp`, `pandas`, `numpy`, `plotly`. |
| 38 | + |
| 39 | +## Demo (no data required) |
| 40 | + |
| 41 | +```bash |
| 42 | +chatrel sample --out sample_data/synthetic_couple.json |
| 43 | +chatrel analyze sample_data/synthetic_couple.json --out ./output |
| 44 | +open ./output/index.html # or start on Windows |
| 45 | +``` |
| 46 | + |
| 47 | +This generates a ~2 000-message fictional 90-day couple chat containing every signal the analyzers look for, then runs the full pipeline. Everything in `output/` is derived from fake data you can freely screenshot. |
| 48 | + |
| 49 | +## Real data |
| 50 | + |
| 51 | +ChatRel reads a canonical chat JSON (see [docs/schema.md](docs/schema.md)): |
| 52 | + |
| 53 | +```json |
| 54 | +{ |
| 55 | + "me_name": "Alex", |
| 56 | + "partner_name": "Sam", |
| 57 | + "messages": [ |
| 58 | + {"ts": 1700000000, "role": "me", "text": "hi", "type": "text"}, |
| 59 | + {"ts": 1700000010, "role": "partner", "text": "hey!"} |
| 60 | + ] |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +### Adapters |
| 65 | + |
| 66 | +* **Telegram**: export from Telegram Desktop → Settings → Advanced → Export Telegram data → JSON, then |
| 67 | + ```bash |
| 68 | + python -m chatrel.adapters.telegram result.json --out chat.json |
| 69 | + ``` |
| 70 | +* **WeChat**: ChatRel does **not** bundle WeChat decryption. See [`src/chatrel/adapters/wechat.py`](src/chatrel/adapters/wechat.py) — it points you to external tools and provides a helper to consume their output. |
| 71 | +* **Generic CSV / JSON**: `python -m chatrel.adapters.generic path.csv --out chat.json` — works for any `ts,role,text` dump. |
| 72 | + |
| 73 | +Write your own adapter: it only needs to return a `chatrel.schema.Chat`. |
| 74 | + |
| 75 | +## CLI |
| 76 | + |
| 77 | +```bash |
| 78 | +chatrel sample # Generate synthetic demo chat |
| 79 | +chatrel analyze chat.json --out ./output |
| 80 | + # Run everything + portal index.html |
| 81 | +chatrel depth chat.json # Sternberg + Knapp + IDS only |
| 82 | +chatrel attachment chat.json # ECR-R + Gottman + 12-week forecast |
| 83 | +chatrel conflict chat.json # Conflict-repair events |
| 84 | +chatrel external chat.json # Poaching / resilience analysis |
| 85 | +chatrel memory chat.json # Auto-curated memory book |
| 86 | +chatrel portal --out ./output # Rebuild index from existing metrics |
| 87 | +``` |
| 88 | + |
| 89 | +All subcommands accept `--out` (defaults to `./output`) and `--no-html` (metrics only). |
| 90 | + |
| 91 | +## What you get |
| 92 | + |
| 93 | +Each analyzer writes a `metrics_*.json` under the output directory; a corresponding HTML renderer turns that JSON into an interactive report. The seven outputs are: |
| 94 | + |
| 95 | +| File | Content | |
| 96 | +|---|---| |
| 97 | +| `depth_metrics.json` + `depth_report.html` | Weekly signal time series · Sternberg triad scores · Knapp phase anchors · composite Intimacy Depth Score (IDS) · milestones · private lexicon | |
| 98 | +| `attachment_forecast.json` + `attachment_forecast_report.html` | ECR-R scores · Bartholomew classification · couple-dynamic type · 12-week 3-scenario forecast · Gottman weekly P:N · four horsemen · critical slowing EWS | |
| 99 | +| `conflict_events.json` + `conflict_report.html` | Detected conflict windows with initiator/peak/first-apology/recovery · monthly trend · repair-pattern stats | |
| 100 | +| `resilience_metrics.json` + `resilience_report.html` | External-threat exposure · exclusivity/trust/we-ness density · 2 h response style · composite Resilience Index · joint stress coping | |
| 101 | +| `memory_book_data.json` + `memory_book.html` | 10 chapters of auto-curated moments: firsts / sweetest / deepest / private lexicon / top days / role-specific best, with client-side search | |
| 102 | +| `index.html` | Portal linking all of the above | |
| 103 | + |
| 104 | +## Privacy |
| 105 | + |
| 106 | +**ChatRel processes everything locally and makes zero network calls.** |
| 107 | + |
| 108 | +* Your chat JSON never leaves the machine. |
| 109 | +* The generated reports are standalone HTML; Plotly is loaded from a CDN at view time (you can swap to local by editing `renderers/common.py`). |
| 110 | +* `.gitignore` blocks accidental commits of chat data and generated reports. Review it before pushing. |
| 111 | +* The synthetic sample is the only bundled demo dataset — never commit real data. |
| 112 | + |
| 113 | +## Ethics |
| 114 | + |
| 115 | +You're analyzing a real person who hasn't read your lexicon. A few constraints that ChatRel bakes in but cannot enforce: |
| 116 | + |
| 117 | +* The tool produces **proxy signals**, not diagnoses. Do not tell someone they "are" Anxious-Preoccupied. |
| 118 | +* Attachment "types" are dimensional, contextual, and change with safety. The 2D scatter is a starting point, not a label. |
| 119 | +* Forecasts are damped linear extrapolation with mean reversion, **not** probabilistic predictions. Do not tell someone "we'll break up in six weeks." |
| 120 | +* If you decide to discuss findings with your partner, discuss the **patterns** (who apologizes more, when rituals dip), not the scores. |
| 121 | + |
| 122 | +## Contributing |
| 123 | + |
| 124 | +* New lexicons (English, Japanese, Spanish, …) are very welcome — open an issue or PR. |
| 125 | +* New adapters (WhatsApp, iMessage, Discord, …) likewise. |
| 126 | +* Eval data with expert-annotated ground truth would substantially improve validation — we'd love to collaborate. |
| 127 | + |
| 128 | +## License |
| 129 | + |
| 130 | +MIT © ChatRel contributors. |
| 131 | + |
| 132 | +## Acknowledgements |
| 133 | + |
| 134 | +Built on top of: [jieba](https://github.com/fxsjy/jieba), [SnowNLP](https://github.com/isnowfy/snownlp), [Plotly](https://plotly.com/python/). The psychology frameworks are cited inline and in [`docs/methodology.md`](docs/methodology.md). |
0 commit comments