Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ruby Chain
|
| 2 |
+
|
| 3 |
+
Pre-trained Markov chain databases for [Ruby](https://github.com/protocol-luna/ruby), the spontaneous message generator in the Luna Protocol ecosystem.
|
| 4 |
+
|
| 5 |
+
Trained on **16.9M human messages** from [mookiezi/Discord-Dialogues](https://huggingface.co/datasets/mookiezi/Discord-Dialogues) — a diverse collection of Discord conversations.
|
| 6 |
+
|
| 7 |
+
## Files
|
| 8 |
+
|
| 9 |
+
| File | Order | Transitions | Starters | Size | Description |
|
| 10 |
+
|------|-------|-------------|----------|------|-------------|
|
| 11 |
+
| `chain-order2.db` | 2 | 18,955,474 | 615,483 | 1.1 GB | Original chain, good variety but less coherent |
|
| 12 |
+
| `chain-order3.db` | 3 | 6,833,837 | 788,166 | 626 MB | Better coherence, smaller footprint |
|
| 13 |
+
| `chain-order4.db` | 4 | 6,891,633 | 1,101,029 | 747 MB | Highest coherence, more unique starters |
|
| 14 |
+
| `messages.txt.gz` | — | — | — | 274 MB | 16.9M messages used for training |
|
| 15 |
+
|
| 16 |
+
**Recommended:** `chain-order3.db` or `chain-order4.db` depending on your size vs coherence tradeoff.
|
| 17 |
+
|
| 18 |
+
## Database Schema
|
| 19 |
+
|
| 20 |
+
```sql
|
| 21 |
+
CREATE TABLE transitions (
|
| 22 |
+
prefix TEXT,
|
| 23 |
+
suffix TEXT,
|
| 24 |
+
count INTEGER,
|
| 25 |
+
channel_id TEXT,
|
| 26 |
+
PRIMARY KEY (prefix, suffix, channel_id)
|
| 27 |
+
);
|
| 28 |
+
|
| 29 |
+
CREATE TABLE starters (
|
| 30 |
+
prefix TEXT,
|
| 31 |
+
channel_id TEXT,
|
| 32 |
+
PRIMARY KEY (prefix, channel_id)
|
| 33 |
+
);
|
| 34 |
+
|
| 35 |
+
CREATE INDEX idx_trans_prefix ON transitions(prefix);
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
Prefixes are words joined by `\x00`. The `order` determines how many words form a prefix (e.g., order 3 → 3-word prefix).
|
| 39 |
+
|
| 40 |
+
The `channel_id` column is always `""` (cross-channel aggregate — the source dataset doesn't include channel metadata).
|
| 41 |
+
|
| 42 |
+
## Usage
|
| 43 |
+
|
| 44 |
+
```js
|
| 45 |
+
const Database = require('better-sqlite3');
|
| 46 |
+
const db = new Database('chain-order3.db');
|
| 47 |
+
|
| 48 |
+
// Get a random starter
|
| 49 |
+
const starter = db.prepare(
|
| 50 |
+
'SELECT prefix FROM starters ORDER BY RANDOM() LIMIT 1'
|
| 51 |
+
).get()?.prefix;
|
| 52 |
+
|
| 53 |
+
// Sample the chain
|
| 54 |
+
function generate(db, prefix, maxLen = 30) {
|
| 55 |
+
const words = prefix.split('\x00');
|
| 56 |
+
for (let i = 0; i < maxLen; i++) {
|
| 57 |
+
const row = db.prepare(
|
| 58 |
+
'SELECT suffix, count FROM transitions WHERE prefix = ? ORDER BY RANDOM()'
|
| 59 |
+
).all(prefix);
|
| 60 |
+
if (!row.length) break;
|
| 61 |
+
const total = row.reduce((s, r) => s + r.count, 0);
|
| 62 |
+
let roll = Math.random() * total;
|
| 63 |
+
let suffix = row[0].suffix;
|
| 64 |
+
for (const r of row) {
|
| 65 |
+
roll -= r.count;
|
| 66 |
+
if (roll <= 0) { suffix = r.suffix; break; }
|
| 67 |
+
}
|
| 68 |
+
words.push(suffix);
|
| 69 |
+
prefix = words.slice(-3).join('\x00');
|
| 70 |
+
}
|
| 71 |
+
return words.join(' ');
|
| 72 |
+
}
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## Source
|
| 76 |
+
|
| 77 |
+
Trained with [Ruby's `tools/train-multi.js`](https://github.com/protocol-luna/ruby) — multi-worker Node.js trainer using better-sqlite3. ~300,000 messages/second on 4 CPU cores.
|