@hviana/sema 0.5.9 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +20 -4
- package/DATASETS.md +12 -11
- package/dist/example/train_base/cache.d.ts +35 -0
- package/dist/example/train_base/cache.js +211 -0
- package/dist/example/train_base/config.d.ts +21 -0
- package/dist/example/train_base/config.js +94 -0
- package/dist/example/train_base/corpora/aya.d.ts +19 -0
- package/dist/example/train_base/corpora/aya.js +76 -0
- package/dist/example/train_base/corpora/converted-parquet.d.ts +14 -0
- package/dist/example/train_base/corpora/converted-parquet.js +44 -0
- package/dist/example/train_base/corpora/genknow.d.ts +14 -0
- package/dist/example/train_base/corpora/genknow.js +83 -0
- package/dist/example/train_base/corpora/index.d.ts +29 -0
- package/dist/example/train_base/corpora/index.js +81 -0
- package/dist/example/train_base/corpora/massive.d.ts +7 -0
- package/dist/example/train_base/corpora/massive.js +98 -0
- package/dist/example/train_base/corpora/oasst2.d.ts +52 -0
- package/dist/example/train_base/corpora/oasst2.js +120 -0
- package/dist/example/train_base/corpora/smolsent.d.ts +23 -0
- package/dist/example/train_base/corpora/smolsent.js +156 -0
- package/dist/example/train_base/corpora/soda.d.ts +12 -0
- package/dist/example/train_base/corpora/soda.js +113 -0
- package/dist/example/train_base/corpora/taskmaster.d.ts +15 -0
- package/dist/example/train_base/corpora/taskmaster.js +144 -0
- package/dist/example/train_base/corpora/wiki2.d.ts +23 -0
- package/dist/example/train_base/corpora/wiki2.js +132 -0
- package/dist/example/train_base/corpus.d.ts +88 -0
- package/dist/example/train_base/corpus.js +65 -0
- package/dist/example/train_base/discovery.d.ts +48 -0
- package/dist/example/train_base/discovery.js +143 -0
- package/dist/example/train_base/http.d.ts +82 -0
- package/dist/example/train_base/http.js +219 -0
- package/dist/example/train_base/items.d.ts +46 -0
- package/dist/example/train_base/items.js +98 -0
- package/dist/example/train_base/main.d.ts +4 -0
- package/dist/example/train_base/main.js +207 -0
- package/dist/example/train_base/progress.d.ts +34 -0
- package/dist/example/train_base/progress.js +114 -0
- package/dist/example/train_base/readers.d.ts +125 -0
- package/dist/example/train_base/readers.js +391 -0
- package/dist/example/train_base/runtime.d.ts +115 -0
- package/dist/example/train_base/runtime.js +637 -0
- package/dist/example/train_base/stage.d.ts +3 -0
- package/dist/example/train_base/stage.js +246 -0
- package/dist/example/train_base/ui.d.ts +88 -0
- package/dist/example/train_base/ui.js +272 -0
- package/dist/src/mind/mind.d.ts +1 -1
- package/dist/src/mind/mind.js +1 -1
- package/example/train_base/cache.ts +251 -0
- package/example/train_base/config.ts +128 -0
- package/example/train_base/corpora/aya.ts +106 -0
- package/example/train_base/corpora/converted-parquet.ts +64 -0
- package/example/train_base/corpora/genknow.ts +114 -0
- package/example/train_base/corpora/index.ts +88 -0
- package/example/train_base/corpora/massive.ts +111 -0
- package/example/train_base/corpora/oasst2.ts +163 -0
- package/example/train_base/corpora/smolsent.ts +203 -0
- package/example/train_base/corpora/soda.ts +130 -0
- package/example/train_base/corpora/taskmaster.ts +217 -0
- package/example/train_base/corpora/wiki2.ts +190 -0
- package/example/train_base/corpus.ts +150 -0
- package/example/train_base/discovery.ts +203 -0
- package/example/train_base/http.ts +284 -0
- package/example/train_base/items.ts +118 -0
- package/example/train_base/main.ts +240 -0
- package/example/train_base/progress.ts +149 -0
- package/example/train_base/readers.ts +505 -0
- package/example/train_base/runtime.ts +894 -0
- package/example/train_base/stage.ts +276 -0
- package/example/train_base/ui.ts +333 -0
- package/jsr.json +1 -1
- package/package.json +2 -4
- package/src/mind/mind.ts +1 -1
- package/test/13-conversation.test.mjs +1 -1
- package/test/84-composed-answer-honesty.test.mjs +2 -1
- package/test/88-dependency-footprint.test.mjs +99 -0
- package/dist/example/train_base.d.ts +0 -163
- package/dist/example/train_base.js +0 -3220
- package/example/train_base.ts +0 -3882
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// train_base/corpora/genknow.ts — MuskumPillerum/General-Knowledge Q&A
|
|
2
|
+
//
|
|
3
|
+
// Knobs, the row adapter, and the stage descriptor for ONE corpus, together
|
|
4
|
+
// with the evidence that fixed each default. A corpus file owns everything
|
|
5
|
+
// source-specific; the contract it fills is ../corpus.ts and the loop that runs
|
|
6
|
+
// it is ../stage.ts.
|
|
7
|
+
import { env } from "../config.js";
|
|
8
|
+
import { refineItems } from "../items.js";
|
|
9
|
+
import { jsonArray } from "../readers.js";
|
|
10
|
+
import { singleUnit } from "../corpus.js";
|
|
11
|
+
// ── MuskumPillerum/General-Knowledge (the fourth training stage, after oasst2) ──
|
|
12
|
+
// A ~37.6k-row general-knowledge Q&A set: each row is a single {Question, Answer}
|
|
13
|
+
// pair. A row is a pure RELATION (question → answer), so it becomes exactly ONE
|
|
14
|
+
// FACT, identical in shape to the Aya stage. It ships as a single JSON array
|
|
15
|
+
// file (output.json); we DOWNLOAD it and stream the array. GENKNOW_URL overrides
|
|
16
|
+
// the source.
|
|
17
|
+
//
|
|
18
|
+
// DISABLED BY DEFAULT ON LICENCE GROUNDS (2026-08-13). The HF repo carries NO
|
|
19
|
+
// licence tag and no licence in its card — an earlier header in this file
|
|
20
|
+
// claimed MIT without support — and its own dataset card states it "contains a
|
|
21
|
+
// subset of the alpaca dataset". Alpaca is CC BY-NC 4.0: NonCommercial, which
|
|
22
|
+
// conflicts with Sema's commercial licence. Because a Sema store retains its
|
|
23
|
+
// training text VERBATIM, an unlicensed corpus inside it makes the whole
|
|
24
|
+
// artifact undistributable. See DATASETS.md §3.2. GENKNOW=1 re-enables the
|
|
25
|
+
// stage for local, non-distributed experiments only.
|
|
26
|
+
const GENKNOW = env("GENKNOW", "0") !== "0";
|
|
27
|
+
const GENKNOW_URL = env("GENKNOW_URL", "https://huggingface.co/datasets/MuskumPillerum/General-Knowledge/resolve/main/output.json");
|
|
28
|
+
// A Question/Answer longer than this is skipped (answers run to a few hundred
|
|
29
|
+
// chars; this only guards against a corrupt/runaway field).
|
|
30
|
+
const MAX_GENKNOW_CHARS = Math.max(4_000, Math.floor(Number(env("MAX_GENKNOW_KB", "64")) * 1000) || 64_000);
|
|
31
|
+
/** Turn a source value into clean prose: decode the literal "\n"/"\t"/"\r"
|
|
32
|
+
* two-character escapes the source JSON left in the text, collapse the runs of
|
|
33
|
+
* whitespace that creates, and trim. */
|
|
34
|
+
function unescapePlain(s) {
|
|
35
|
+
return s
|
|
36
|
+
.replace(/\\r\\n|\\n|\\r/g, "\n")
|
|
37
|
+
.replace(/\\t/g, " ")
|
|
38
|
+
.replace(/[ \t]+/g, " ")
|
|
39
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
40
|
+
.trim();
|
|
41
|
+
}
|
|
42
|
+
/** Normalize a raw datasets-server row into a GenKnowRow, or null when it lacks
|
|
43
|
+
* a usable question/answer or a side is implausibly large (corruption). */
|
|
44
|
+
export function toGenKnowRow(row, maxChars = MAX_GENKNOW_CHARS) {
|
|
45
|
+
if (!row || typeof row !== "object")
|
|
46
|
+
return null;
|
|
47
|
+
const r = row;
|
|
48
|
+
const question = typeof r.Question === "string"
|
|
49
|
+
? unescapePlain(r.Question)
|
|
50
|
+
: "";
|
|
51
|
+
const answer = typeof r.Answer === "string" ? unescapePlain(r.Answer) : "";
|
|
52
|
+
if (!question || !answer)
|
|
53
|
+
return null;
|
|
54
|
+
if (question.length > maxChars || answer.length > maxChars)
|
|
55
|
+
return null;
|
|
56
|
+
return { question, answer };
|
|
57
|
+
}
|
|
58
|
+
/** Translate ONE General-Knowledge row into SEMA items: exactly one
|
|
59
|
+
* (question → answer) FACT. refineItems drops a degenerate question === answer. */
|
|
60
|
+
export function genKnowRowToItems(row) {
|
|
61
|
+
return refineItems([{ context: row.question, continuation: row.answer }]);
|
|
62
|
+
}
|
|
63
|
+
export const genknow = {
|
|
64
|
+
id: "genknow",
|
|
65
|
+
label: "General-Knowledge",
|
|
66
|
+
kind: "Q&A facts",
|
|
67
|
+
enabled: GENKNOW,
|
|
68
|
+
read: jsonArray(),
|
|
69
|
+
toItems: (row) => {
|
|
70
|
+
const r = toGenKnowRow(row);
|
|
71
|
+
return r ? genKnowRowToItems(r) : null;
|
|
72
|
+
},
|
|
73
|
+
discover: singleUnit({
|
|
74
|
+
// Resume id "genknow::qa" — the string this store already records.
|
|
75
|
+
key: "qa",
|
|
76
|
+
label: "General-Knowledge",
|
|
77
|
+
display: "General-Knowledge",
|
|
78
|
+
url: GENKNOW_URL,
|
|
79
|
+
dest: "general_knowledge.json",
|
|
80
|
+
localMatch: [/general.*knowledge.*\.json$/i, /output\.json$/i],
|
|
81
|
+
localWhat: "General-Knowledge *.json",
|
|
82
|
+
}),
|
|
83
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Corpus } from "../corpus.js";
|
|
2
|
+
export declare const CURRICULUM: Corpus[];
|
|
3
|
+
/** The corpora this RUN will train, for the panel header — derived, so it can
|
|
4
|
+
* never go stale the way the hand-written string it replaces had. */
|
|
5
|
+
export declare const enabledLabels: () => string;
|
|
6
|
+
/** The corpora a STORE contains: everything this run will train PLUS everything
|
|
7
|
+
* an earlier run already did, in curriculum order.
|
|
8
|
+
*
|
|
9
|
+
* Not the same question as `enabledLabels`, and conflating them wrote a false
|
|
10
|
+
* statement into every store that was ever resumed with a different set of
|
|
11
|
+
* stages enabled. Observed on a real store: `train.dataset` read
|
|
12
|
+
* "SmolSent+Aya+oasst2" while the tally recorded 37,623 General-Knowledge
|
|
13
|
+
* deposits sitting in it. That is not cosmetic — a Sema store retains its
|
|
14
|
+
* training text VERBATIM, so `train.dataset` is the record of whose licence
|
|
15
|
+
* terms travel with the artifact, and General-Knowledge is precisely the
|
|
16
|
+
* corpus DATASETS.md §3.2 disables on NonCommercial grounds.
|
|
17
|
+
*
|
|
18
|
+
* `trainedIds` are the corpus ids an earlier run deposited under (the keys of
|
|
19
|
+
* the per-corpus tally). An id no longer in the curriculum cannot be named and
|
|
20
|
+
* is dropped — the tally still carries it, which is where that evidence lives. */
|
|
21
|
+
export declare const storedLabels: (trainedIds: Iterable<string>) => string;
|
|
22
|
+
export * from "./smolsent.js";
|
|
23
|
+
export * from "./aya.js";
|
|
24
|
+
export * from "./oasst2.js";
|
|
25
|
+
export * from "./taskmaster.js";
|
|
26
|
+
export * from "./wiki2.js";
|
|
27
|
+
export * from "./soda.js";
|
|
28
|
+
export * from "./massive.js";
|
|
29
|
+
export * from "./genknow.js";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// train_base/corpora/index.ts — THE CURRICULUM.
|
|
2
|
+
//
|
|
3
|
+
// The order is the curriculum, and it is load-bearing: each stage runs only
|
|
4
|
+
// after the previous one finishes, and every stage records itself in the same
|
|
5
|
+
// completed-set, so a single store resumes the whole sequence.
|
|
6
|
+
//
|
|
7
|
+
// 1. SmolSent sentence-level TRANSLATION pairs across 100+ low-resource
|
|
8
|
+
// languages. Each pair is "two names for one meaning" → a
|
|
9
|
+
// foreign→English translation FACT, so every language's
|
|
10
|
+
// rendering of a meaning converges on ONE English node (cf.
|
|
11
|
+
// test/05-concepts.test.mjs).
|
|
12
|
+
// 2. Aya ~204k human prompt→completion pairs, 70+ languages → one
|
|
13
|
+
// (question → answer) FACT each.
|
|
14
|
+
// 3. oasst2 MULTI-TURN human↔assistant conversation trees → the
|
|
15
|
+
// accumulated-context walk (single-turn trees are skipped).
|
|
16
|
+
// 4. Taskmaster task-oriented DIALOGUE, the best-scoring corpora on the
|
|
17
|
+
// fold-unit recurrence benchmark that predicts halo health.
|
|
18
|
+
// 5. 2Wiki the `evidences` TRIPLES — the one stage aimed at
|
|
19
|
+
// COMPOSITION. Its Wikipedia passages and its composed
|
|
20
|
+
// questions are deliberately NOT read.
|
|
21
|
+
// 6. SODA social/commonsense DIALOGUE, budgeted.
|
|
22
|
+
// 7. MASSIVE short intent utterances → ONE bare experience each.
|
|
23
|
+
// DISABLED BY DEFAULT — edge-less content was measured to
|
|
24
|
+
// manufacture answers where the store should stay silent.
|
|
25
|
+
// 8. GenKnow ~37.6k {Question, Answer} pairs → one FACT each. DISABLED
|
|
26
|
+
// BY DEFAULT on licence grounds; see DATASETS.md §3.2.
|
|
27
|
+
import { smolsent } from "./smolsent.js";
|
|
28
|
+
import { aya } from "./aya.js";
|
|
29
|
+
import { oasst2 } from "./oasst2.js";
|
|
30
|
+
import { taskmaster } from "./taskmaster.js";
|
|
31
|
+
import { wiki2 } from "./wiki2.js";
|
|
32
|
+
import { soda } from "./soda.js";
|
|
33
|
+
import { massive } from "./massive.js";
|
|
34
|
+
import { genknow } from "./genknow.js";
|
|
35
|
+
export const CURRICULUM = [
|
|
36
|
+
smolsent,
|
|
37
|
+
aya,
|
|
38
|
+
oasst2,
|
|
39
|
+
taskmaster,
|
|
40
|
+
wiki2,
|
|
41
|
+
soda,
|
|
42
|
+
massive,
|
|
43
|
+
genknow,
|
|
44
|
+
];
|
|
45
|
+
/** The corpora this RUN will train, for the panel header — derived, so it can
|
|
46
|
+
* never go stale the way the hand-written string it replaces had. */
|
|
47
|
+
export const enabledLabels = () => CURRICULUM.filter((c) => c.enabled).map((c) => c.label).join("+");
|
|
48
|
+
/** The corpora a STORE contains: everything this run will train PLUS everything
|
|
49
|
+
* an earlier run already did, in curriculum order.
|
|
50
|
+
*
|
|
51
|
+
* Not the same question as `enabledLabels`, and conflating them wrote a false
|
|
52
|
+
* statement into every store that was ever resumed with a different set of
|
|
53
|
+
* stages enabled. Observed on a real store: `train.dataset` read
|
|
54
|
+
* "SmolSent+Aya+oasst2" while the tally recorded 37,623 General-Knowledge
|
|
55
|
+
* deposits sitting in it. That is not cosmetic — a Sema store retains its
|
|
56
|
+
* training text VERBATIM, so `train.dataset` is the record of whose licence
|
|
57
|
+
* terms travel with the artifact, and General-Knowledge is precisely the
|
|
58
|
+
* corpus DATASETS.md §3.2 disables on NonCommercial grounds.
|
|
59
|
+
*
|
|
60
|
+
* `trainedIds` are the corpus ids an earlier run deposited under (the keys of
|
|
61
|
+
* the per-corpus tally). An id no longer in the curriculum cannot be named and
|
|
62
|
+
* is dropped — the tally still carries it, which is where that evidence lives. */
|
|
63
|
+
export const storedLabels = (trainedIds) => {
|
|
64
|
+
const trained = new Set(trainedIds);
|
|
65
|
+
return CURRICULUM
|
|
66
|
+
.filter((c) => c.enabled || trained.has(c.id))
|
|
67
|
+
.map((c) => c.label)
|
|
68
|
+
.join("+");
|
|
69
|
+
};
|
|
70
|
+
// One re-export per corpus, carrying the descriptor AND its adapters. The
|
|
71
|
+
// explicit `export { aya, genknow, … }` list that used to sit here named the
|
|
72
|
+
// eight descriptors a second time; the star exports below already provide them,
|
|
73
|
+
// and a hand-kept list of everything is exactly the thing that goes stale.
|
|
74
|
+
export * from "./smolsent.js";
|
|
75
|
+
export * from "./aya.js";
|
|
76
|
+
export * from "./oasst2.js";
|
|
77
|
+
export * from "./taskmaster.js";
|
|
78
|
+
export * from "./wiki2.js";
|
|
79
|
+
export * from "./soda.js";
|
|
80
|
+
export * from "./massive.js";
|
|
81
|
+
export * from "./genknow.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type TrainingItem } from "../items.js";
|
|
2
|
+
import type { Corpus } from "../corpus.js";
|
|
3
|
+
/** Translate ONE MASSIVE row into SEMA items: its bare utterance, as an
|
|
4
|
+
* experience. `annot_utt` (slot-annotated) is deliberately not used — its
|
|
5
|
+
* "[date : ...]" markup is not prose. Returns [] for an unusable row. */
|
|
6
|
+
export declare function massiveRowToItems(row: unknown, maxChars?: number): TrainingItem[];
|
|
7
|
+
export declare const massive: Corpus;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// train_base/corpora/massive.ts — AmazonScience/massive short intents
|
|
2
|
+
//
|
|
3
|
+
// Knobs, the row adapter, and the stage descriptor for ONE corpus, together
|
|
4
|
+
// with the evidence that fixed each default. A corpus file owns everything
|
|
5
|
+
// source-specific; the contract it fills is ../corpus.ts and the loop that runs
|
|
6
|
+
// it is ../stage.ts.
|
|
7
|
+
import { env } from "../config.js";
|
|
8
|
+
import { refineItems } from "../items.js";
|
|
9
|
+
import { parquet } from "../readers.js";
|
|
10
|
+
import { convertedParquetUnits } from "./converted-parquet.js";
|
|
11
|
+
// MASSIVE deposits BARE UTTERANCES — an experience, not an episode — and that
|
|
12
|
+
// is the only shape its data supports. Two richer shapes were considered and
|
|
13
|
+
// rejected on evidence:
|
|
14
|
+
// • Same-intent pairs as paraphrases. 49.1% of consecutive rows share
|
|
15
|
+
// (locale, intent), but they are NOT meaning-equivalent: intent 48 in mn-MN
|
|
16
|
+
// runs "wake me at nine on the fifth" next to "set an alarm two hours from
|
|
17
|
+
// now". Depositing that pair as an episode teaches a continuation that does
|
|
18
|
+
// not exist.
|
|
19
|
+
// • Same-id rows across locales. Those ARE translations of one another —
|
|
20
|
+
// which is exactly SmolSent's relation, and SmolSent scores worst of every
|
|
21
|
+
// corpus measured on fold-unit recurrence (23.2%) because cross-lingual
|
|
22
|
+
// pairs share no units.
|
|
23
|
+
// So the stage contributes recurring fold units and lexical coverage (65.1%
|
|
24
|
+
// recurring unit mass, median 29 B) and nothing relational. `annot_utt` carries
|
|
25
|
+
// slot markup ("[date : tavdahad] ...") and is never read.
|
|
26
|
+
// DISABLED BY DEFAULT, on evidence gathered after the stage was written. A bare
|
|
27
|
+
// experience deposits content with NO EDGE, and that cuts both ways. Measured on
|
|
28
|
+
// a three-pair dialogue store with and without six MASSIVE-style utterances:
|
|
29
|
+
//
|
|
30
|
+
// "set an alarm" without: "Sure, what size would you like?" (wrong)
|
|
31
|
+
// with: "set an alarm for seven" (better)
|
|
32
|
+
// "play music" without: "" (correct silence)
|
|
33
|
+
// with: "Yes, sweetened or unsweetened?" (wrong)
|
|
34
|
+
//
|
|
35
|
+
// So it displaces some wrong answers and manufactures others, INCLUDING turning
|
|
36
|
+
// a correct silence into a wrong answer — and honest silence is a stated
|
|
37
|
+
// property of this engine (AGENTS §2.13). On the mixed-curriculum store the
|
|
38
|
+
// same shape produced the fragment "nus" for "wake me up at nine am".
|
|
39
|
+
//
|
|
40
|
+
// That evidence is four probes on toy stores and is NOT conclusive; it is,
|
|
41
|
+
// however, the only evidence there is, and it points the wrong way. The stage
|
|
42
|
+
// stays implemented and one env var away. Turn it on (MASSIVE=1) once there is
|
|
43
|
+
// a real measurement showing the recurring fold units it contributes (72.3% of
|
|
44
|
+
// deposited unit mass) buy more than the spurious answers cost.
|
|
45
|
+
const MASSIVE = env("MASSIVE", "0") !== "0";
|
|
46
|
+
const MASSIVE_DATASET = env("MASSIVE_DATASET", "AmazonScience/massive");
|
|
47
|
+
// "all" is the config covering every locale in one set of shards.
|
|
48
|
+
const MASSIVE_CONFIG = env("MASSIVE_CONFIG", "all");
|
|
49
|
+
const MASSIVE_SPLITS = env("MASSIVE_SPLITS", "train")
|
|
50
|
+
.split(",").map((s) => s.trim()).filter(Boolean);
|
|
51
|
+
// 0 = every row (587,214 in `all`/train, ~17 MB of content).
|
|
52
|
+
const MASSIVE_MAX_ROWS = Math.max(0, Math.floor(Number(env("MASSIVE_MAX_ROWS", "0"))) || 0);
|
|
53
|
+
const MAX_MASSIVE_UTT_CHARS = Math.max(100, Math.floor(Number(env("MAX_MASSIVE_UTT_KB", "2")) * 1000) || 2_000);
|
|
54
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
55
|
+
// §6e⁗ MASSIVE parsing — one short utterance → ONE SEMA experience
|
|
56
|
+
//
|
|
57
|
+
// See the constants note for why this deposits a bare experience and not a
|
|
58
|
+
// relation: the two relational shapes this corpus appears to offer are both
|
|
59
|
+
// false (same-intent rows are not paraphrases; same-id rows across locales are
|
|
60
|
+
// translations, SmolSent's worst-scoring relation).
|
|
61
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
62
|
+
/** Translate ONE MASSIVE row into SEMA items: its bare utterance, as an
|
|
63
|
+
* experience. `annot_utt` (slot-annotated) is deliberately not used — its
|
|
64
|
+
* "[date : ...]" markup is not prose. Returns [] for an unusable row. */
|
|
65
|
+
export function massiveRowToItems(row, maxChars = MAX_MASSIVE_UTT_CHARS) {
|
|
66
|
+
if (!row || typeof row !== "object")
|
|
67
|
+
return [];
|
|
68
|
+
const utt = row.utt;
|
|
69
|
+
const text = typeof utt === "string" ? utt.trim() : "";
|
|
70
|
+
if (!text || text.length > maxChars)
|
|
71
|
+
return [];
|
|
72
|
+
return refineItems([text]);
|
|
73
|
+
}
|
|
74
|
+
export const massive = {
|
|
75
|
+
id: "massive",
|
|
76
|
+
label: "MASSIVE",
|
|
77
|
+
kind: "short intents",
|
|
78
|
+
enabled: MASSIVE,
|
|
79
|
+
maxRows: MASSIVE_MAX_ROWS,
|
|
80
|
+
// One of ten columns — `annot_utt`, whose slot markup the note above rejects,
|
|
81
|
+
// is not decoded either. Measured on the converted train shard: 92 MB
|
|
82
|
+
// uncompressed across all ten, 36 MB for `utt` (38.7%).
|
|
83
|
+
read: parquet({ columns: ["utt"] }),
|
|
84
|
+
toItems: (row) => {
|
|
85
|
+
const items = massiveRowToItems(row);
|
|
86
|
+
return items.length ? items : null;
|
|
87
|
+
},
|
|
88
|
+
unitNoun: "shard(s)",
|
|
89
|
+
log: { rows: "row(s)" },
|
|
90
|
+
discover: convertedParquetUnits({
|
|
91
|
+
id: "massive",
|
|
92
|
+
label: "MASSIVE",
|
|
93
|
+
dataset: MASSIVE_DATASET,
|
|
94
|
+
config: MASSIVE_CONFIG,
|
|
95
|
+
splits: MASSIVE_SPLITS,
|
|
96
|
+
localSub: "massive",
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type TrainingItem } from "../items.js";
|
|
2
|
+
import { type Corpus } from "../corpus.js";
|
|
3
|
+
/** A single oasst2 message node (the fields we use; the tree nests via replies). */
|
|
4
|
+
interface OasstNode {
|
|
5
|
+
role?: string;
|
|
6
|
+
text?: string;
|
|
7
|
+
rank?: number | null;
|
|
8
|
+
deleted?: boolean;
|
|
9
|
+
replies?: OasstNode[];
|
|
10
|
+
}
|
|
11
|
+
/** One conversational turn extracted from a tree. */
|
|
12
|
+
export interface OasstTurn {
|
|
13
|
+
role: string;
|
|
14
|
+
text: string;
|
|
15
|
+
}
|
|
16
|
+
/** Collapse a conversation tree to ONE linear path: at each node, descend into
|
|
17
|
+
* its best-ranked, non-deleted reply (rank 0 preferred; unranked sorts last).
|
|
18
|
+
* Returns the ordered turns (already strictly alternating in this corpus). */
|
|
19
|
+
export declare function bestOasstPath(root: OasstNode): OasstTurn[];
|
|
20
|
+
/** Translate ONE multi-turn oasst2 conversation into SEMA training items.
|
|
21
|
+
*
|
|
22
|
+
* This is the ONE stage where cumulative continuous context is truly necessary:
|
|
23
|
+
* the data is a real multi-turn dialogue, and what must be learned is how each
|
|
24
|
+
* turn follows from the WHOLE conversation so far — not from the previous turn
|
|
25
|
+
* alone. The conversation is emitted ONLY as the accumulated walk; standalone
|
|
26
|
+
* turn experiences and local adjacent-pair facts are NOT emitted (they are
|
|
27
|
+
* subsumed by it and would merely replicate the content).
|
|
28
|
+
*
|
|
29
|
+
* The walk is the pattern proven in test/13-conversation.test.mjs
|
|
30
|
+
* ("teachConversation"): each turn is the continuation of all prior turns,
|
|
31
|
+
* with BARE turn text — NO "User:/Assistant:" labels. The SHAPE is identical
|
|
32
|
+
* (cumulative context → next turn); the join string is not, and does not need
|
|
33
|
+
* to be — that file joins with nothing and this corpus joins with "\n" (see
|
|
34
|
+
* `accumulate`). Saying "byte-for-byte", as this comment used to, invites the
|
|
35
|
+
* reading that the two must agree on a separator. They must not agree,
|
|
36
|
+
* because there is nothing to agree about: turn boundaries are offsets, and
|
|
37
|
+
* the join string is just corpus text. Roles already
|
|
38
|
+
* alternate by position in an oasst2 best-path (the root is a prompter), so a
|
|
39
|
+
* label adds nothing the position does not, while a clean continuation matches
|
|
40
|
+
* the test's recall (predictNext queries bare prior turns) and lets a turn share
|
|
41
|
+
* its gist with the same text elsewhere (e.g. an Aya question stored bare).
|
|
42
|
+
*
|
|
43
|
+
* Returns [] for a conversation below the multi-turn threshold, so callers can
|
|
44
|
+
* simply skip empties. */
|
|
45
|
+
export declare function oasstConversationToItems(turns: OasstTurn[], minTurns?: number): TrainingItem[];
|
|
46
|
+
/** The row adapter: ONE line of the tree dump → its deposits. Returns null for
|
|
47
|
+
* a tree with no prompt and for every single-turn tree — the latter is the
|
|
48
|
+
* stage's design, not a defect, which is why the reader counts it `unusable`
|
|
49
|
+
* rather than `skipped`. */
|
|
50
|
+
export declare function oasstTreeToItems(row: unknown): TrainingItem[] | null;
|
|
51
|
+
export declare const oasst2: Corpus;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// train_base/corpora/oasst2.ts — OpenAssistant/oasst2 conversation trees
|
|
2
|
+
//
|
|
3
|
+
// Knobs, the row adapter, and the stage descriptor for ONE corpus, together
|
|
4
|
+
// with the evidence that fixed each default. A corpus file owns everything
|
|
5
|
+
// source-specific; the contract it fills is ../corpus.ts and the loop that runs
|
|
6
|
+
// it is ../stage.ts.
|
|
7
|
+
import { env } from "../config.js";
|
|
8
|
+
import { accumulate, refineItems } from "../items.js";
|
|
9
|
+
import { lines } from "../readers.js";
|
|
10
|
+
import { singleUnit } from "../corpus.js";
|
|
11
|
+
// ── OpenAssistant/oasst2 (the fourth training stage, after Aya) ──
|
|
12
|
+
// oasst2 is a corpus of human↔assistant conversation TREES. Its richest, most
|
|
13
|
+
// stream-friendly artifact is "<date>_oasst2_ready.trees.jsonl.gz": one JSON
|
|
14
|
+
// conversation tree PER LINE, gzip-compressed (a web standard — Decompression
|
|
15
|
+
// Stream("gzip")). Each tree is {message_tree_id, prompt:{role,text,replies:[…]}}
|
|
16
|
+
// where `replies` nests recursively and a prompt can have several ranked
|
|
17
|
+
// assistant replies (rank 0 = best). We follow the best-ranked, non-deleted
|
|
18
|
+
// reply at each step to get ONE linear, strictly-alternating conversation per
|
|
19
|
+
// tree, then keep only the MULTI-TURN ones (≥ OASST_MIN_TURNS messages, i.e. at
|
|
20
|
+
// least two full user→assistant exchanges) — single Q→A trees are skipped, by
|
|
21
|
+
// design. OASST=0 disables the stage; OASST_URL overrides the source.
|
|
22
|
+
const OASST = env("OASST", "1") !== "0";
|
|
23
|
+
const OASST_URL = env("OASST_URL", "https://huggingface.co/datasets/OpenAssistant/oasst2/resolve/main/2023-11-05_oasst2_ready.trees.jsonl.gz");
|
|
24
|
+
// Multi-turn threshold: a conversation must have at least this many turns to be
|
|
25
|
+
// trained (4 = user→assistant→user→assistant, the smallest real multi-turn).
|
|
26
|
+
const OASST_MIN_TURNS = Math.max(2, Math.floor(Number(env("OASST_MIN_TURNS", "4"))) || 4);
|
|
27
|
+
// Skip a tree whose decoded JSON line exceeds this (a pathological record); the
|
|
28
|
+
// real maximum is far smaller, so this only guards against corruption.
|
|
29
|
+
const MAX_OASST_LINE_CHARS = Math.max(100_000, Math.floor(Number(env("MAX_OASST_LINE_MB", "8")) * 1_000_000) || 8_000_000);
|
|
30
|
+
/** Collapse a conversation tree to ONE linear path: at each node, descend into
|
|
31
|
+
* its best-ranked, non-deleted reply (rank 0 preferred; unranked sorts last).
|
|
32
|
+
* Returns the ordered turns (already strictly alternating in this corpus). */
|
|
33
|
+
export function bestOasstPath(root) {
|
|
34
|
+
const turns = [];
|
|
35
|
+
let node = root;
|
|
36
|
+
while (node) {
|
|
37
|
+
const text = typeof node.text === "string" ? node.text.trim() : "";
|
|
38
|
+
if (text)
|
|
39
|
+
turns.push({ role: String(node.role ?? "?"), text });
|
|
40
|
+
const live = (node.replies ?? []).filter((r) => r && !r.deleted && typeof r.text === "string" && r.text.trim() !== "");
|
|
41
|
+
if (live.length === 0)
|
|
42
|
+
break;
|
|
43
|
+
live.sort((a, b) => (a.rank ?? Number.MAX_SAFE_INTEGER) - (b.rank ?? Number.MAX_SAFE_INTEGER));
|
|
44
|
+
node = live[0];
|
|
45
|
+
}
|
|
46
|
+
return turns;
|
|
47
|
+
}
|
|
48
|
+
/** Translate ONE multi-turn oasst2 conversation into SEMA training items.
|
|
49
|
+
*
|
|
50
|
+
* This is the ONE stage where cumulative continuous context is truly necessary:
|
|
51
|
+
* the data is a real multi-turn dialogue, and what must be learned is how each
|
|
52
|
+
* turn follows from the WHOLE conversation so far — not from the previous turn
|
|
53
|
+
* alone. The conversation is emitted ONLY as the accumulated walk; standalone
|
|
54
|
+
* turn experiences and local adjacent-pair facts are NOT emitted (they are
|
|
55
|
+
* subsumed by it and would merely replicate the content).
|
|
56
|
+
*
|
|
57
|
+
* The walk is the pattern proven in test/13-conversation.test.mjs
|
|
58
|
+
* ("teachConversation"): each turn is the continuation of all prior turns,
|
|
59
|
+
* with BARE turn text — NO "User:/Assistant:" labels. The SHAPE is identical
|
|
60
|
+
* (cumulative context → next turn); the join string is not, and does not need
|
|
61
|
+
* to be — that file joins with nothing and this corpus joins with "\n" (see
|
|
62
|
+
* `accumulate`). Saying "byte-for-byte", as this comment used to, invites the
|
|
63
|
+
* reading that the two must agree on a separator. They must not agree,
|
|
64
|
+
* because there is nothing to agree about: turn boundaries are offsets, and
|
|
65
|
+
* the join string is just corpus text. Roles already
|
|
66
|
+
* alternate by position in an oasst2 best-path (the root is a prompter), so a
|
|
67
|
+
* label adds nothing the position does not, while a clean continuation matches
|
|
68
|
+
* the test's recall (predictNext queries bare prior turns) and lets a turn share
|
|
69
|
+
* its gist with the same text elsewhere (e.g. an Aya question stored bare).
|
|
70
|
+
*
|
|
71
|
+
* Returns [] for a conversation below the multi-turn threshold, so callers can
|
|
72
|
+
* simply skip empties. */
|
|
73
|
+
export function oasstConversationToItems(turns, minTurns = OASST_MIN_TURNS) {
|
|
74
|
+
if (turns.length < minTurns)
|
|
75
|
+
return []; // not multi-turn — skip
|
|
76
|
+
return refineItems(accumulate(turns.map((t) => t.text)));
|
|
77
|
+
}
|
|
78
|
+
/** The row adapter: ONE line of the tree dump → its deposits. Returns null for
|
|
79
|
+
* a tree with no prompt and for every single-turn tree — the latter is the
|
|
80
|
+
* stage's design, not a defect, which is why the reader counts it `unusable`
|
|
81
|
+
* rather than `skipped`. */
|
|
82
|
+
export function oasstTreeToItems(row) {
|
|
83
|
+
if (!row || typeof row !== "object")
|
|
84
|
+
return null;
|
|
85
|
+
const tree = row;
|
|
86
|
+
if (!tree.prompt)
|
|
87
|
+
return null;
|
|
88
|
+
const items = oasstConversationToItems(bestOasstPath(tree.prompt));
|
|
89
|
+
return items.length ? items : null;
|
|
90
|
+
}
|
|
91
|
+
export const oasst2 = {
|
|
92
|
+
id: "oasst2",
|
|
93
|
+
label: "oasst2",
|
|
94
|
+
kind: "multi-turn chat",
|
|
95
|
+
enabled: OASST,
|
|
96
|
+
read: lines({ gzip: true, maxLineChars: MAX_OASST_LINE_CHARS }),
|
|
97
|
+
toItems: oasstTreeToItems,
|
|
98
|
+
// The one corpus that KEEPS a cached file after a complete read: a copy left
|
|
99
|
+
// behind by a previous interrupted run is not this stage's to reclaim.
|
|
100
|
+
keepCached: true,
|
|
101
|
+
log: {
|
|
102
|
+
deposits: "examples",
|
|
103
|
+
// A tree that yields items is exactly a tree that cleared OASST_MIN_TURNS.
|
|
104
|
+
rows: "conversation(s)",
|
|
105
|
+
// The single-turn trees this stage drops BY DESIGN must not be reported as
|
|
106
|
+
// damage — only genuinely malformed lines are.
|
|
107
|
+
malformedOnly: true,
|
|
108
|
+
},
|
|
109
|
+
discover: singleUnit({
|
|
110
|
+
// Resume id "oasst2::trees" — the string this store already records.
|
|
111
|
+
key: "trees",
|
|
112
|
+
label: "oasst2",
|
|
113
|
+
display: "oasst2 (multi-turn)",
|
|
114
|
+
url: OASST_URL,
|
|
115
|
+
dest: "oasst2_ready.trees.jsonl.gz",
|
|
116
|
+
acquireLabel: "oasst2 trees",
|
|
117
|
+
localMatch: [/oasst.*trees.*\.jsonl\.gz$/i, /oasst.*\.jsonl\.gz$/i],
|
|
118
|
+
localWhat: "oasst2 *trees*.jsonl.gz",
|
|
119
|
+
}),
|
|
120
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type TrainingItem } from "../items.js";
|
|
2
|
+
import type { Corpus } from "../corpus.js";
|
|
3
|
+
/** One normalized SmolSent row. */
|
|
4
|
+
export interface SmolSentRow {
|
|
5
|
+
src: string;
|
|
6
|
+
trg: string;
|
|
7
|
+
sl: string;
|
|
8
|
+
tl: string;
|
|
9
|
+
}
|
|
10
|
+
/** Normalize a raw datasets-server row into a SmolSentRow, or null when it lacks
|
|
11
|
+
* both sides or a side is implausibly large (a dump, not a sentence). */
|
|
12
|
+
export declare function toSmolSentRow(row: unknown, maxChars?: number): SmolSentRow | null;
|
|
13
|
+
/** Translate ONE SmolSent pair into SEMA facts. The two sentences are one
|
|
14
|
+
* meaning in two languages, but the two BINDINGS are not equally sound —
|
|
15
|
+
* SmolSent's English side is a shared pool translated into every language, so
|
|
16
|
+
* `trg -> src` gives one English context a different answer in every language
|
|
17
|
+
* file. See SMOLSENT_DIRECTIONS. refineItems drops the degenerate case where
|
|
18
|
+
* src === trg. */
|
|
19
|
+
export declare function smolSentRowToItems(row: SmolSentRow, dirs?: {
|
|
20
|
+
src2trg: boolean;
|
|
21
|
+
trg2src: boolean;
|
|
22
|
+
}): TrainingItem[];
|
|
23
|
+
export declare const smolsent: Corpus;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// train_base/corpora/smolsent.ts — google/smol sentence pairs
|
|
2
|
+
//
|
|
3
|
+
// Knobs, the row adapter, and the stage descriptor for ONE corpus, together
|
|
4
|
+
// with the evidence that fixed each default. A corpus file owns everything
|
|
5
|
+
// source-specific; the contract it fills is ../corpus.ts and the loop that runs
|
|
6
|
+
// it is ../stage.ts.
|
|
7
|
+
import { env, LOCAL_PATH } from "../config.js";
|
|
8
|
+
import { refineItems } from "../items.js";
|
|
9
|
+
import { hfTree, localFiles } from "../discovery.js";
|
|
10
|
+
import { lines } from "../readers.js";
|
|
11
|
+
import { basename, join } from "node:path";
|
|
12
|
+
// ── google/smol · SmolSent (the first training stage) ──
|
|
13
|
+
// SmolSent is Google's sentence-level translation set: ~863 human sentence pairs
|
|
14
|
+
// per language pair across 100+ low-resource languages, cc-by-4.0 (commercial-
|
|
15
|
+
// friendly). Each row is {sl, tl, src, trg, …} — a source sentence and its
|
|
16
|
+
// translation. A pair is "two names for one meaning", which is exactly the
|
|
17
|
+
// cross-language concept SEMA fuses (see test/05-concepts.test.mjs), so each row
|
|
18
|
+
// becomes FACTS that bind the two phrasings as one concept at recall time.
|
|
19
|
+
//
|
|
20
|
+
// The corpus ships as one plain JSONL file PER language pair under smolsent/ in
|
|
21
|
+
// the HF repo (e.g. smolsent/ha_en.jsonl). We DOWNLOAD each file and stream its
|
|
22
|
+
// lines — far faster and free of the rate-limiting that per-row API paging hit.
|
|
23
|
+
// The file list is discovered from the HF repo tree. SMOLSENT=0 disables the
|
|
24
|
+
// stage; SMOLSENT_PAIRS (comma-separated basenames without .jsonl, e.g.
|
|
25
|
+
// "ha_en,zu_en") restricts to a chosen subset.
|
|
26
|
+
const SMOLSENT = env("SMOLSENT", "1") !== "0";
|
|
27
|
+
const SMOLSENT_DATASET = env("SMOLSENT_DATASET", "google/smol");
|
|
28
|
+
const SMOLSENT_PAIRS = (process.env.SMOLSENT_PAIRS ?? "")
|
|
29
|
+
.split(",").map((s) => s.trim()).filter(Boolean);
|
|
30
|
+
// The resume id PREFIX for the SmolSent stage; one completed-files entry per
|
|
31
|
+
// file (e.g. "smolsent::ha_en.jsonl").
|
|
32
|
+
const SMOLSENT_ID = "smolsent";
|
|
33
|
+
// Which direction(s) of a translation pair to deposit. Was effectively "both",
|
|
34
|
+
// and that is now the default NO longer, for a reason measured rather than
|
|
35
|
+
// assumed.
|
|
36
|
+
//
|
|
37
|
+
// SmolSent's English side is a SHARED POOL translated into every language: row
|
|
38
|
+
// id 0 of smolsent/ha_en.jsonl, zu_en.jsonl and am_en.jsonl all carry the SAME
|
|
39
|
+
// `trg` ("It allows me to work by following my vibes and ..."). The two
|
|
40
|
+
// directions are therefore not symmetric at all:
|
|
41
|
+
//
|
|
42
|
+
// src2trg (foreign -> English) many distinct contexts -> ONE shared
|
|
43
|
+
// continuation. Every language's rendering of
|
|
44
|
+
// a meaning converges on the same English
|
|
45
|
+
// node — the cross-language concept fusion
|
|
46
|
+
// this stage exists for.
|
|
47
|
+
// trg2src (English -> foreign) ONE context -> 100+ DIFFERENT continuations,
|
|
48
|
+
// one per language file. The same English
|
|
49
|
+
// sentence is deposited over and over with a
|
|
50
|
+
// different answer each time.
|
|
51
|
+
//
|
|
52
|
+
// So dropping trg2src is not merely a corpus-size economy (it halves the
|
|
53
|
+
// largest stage, which was 60.9% of all examples in the last trained store); it
|
|
54
|
+
// removes a genuine ambiguity pathology. Set SMOLSENT_DIRECTIONS=both to
|
|
55
|
+
// restore the old behaviour, or trg2src for English->foreign only.
|
|
56
|
+
//
|
|
57
|
+
// WHAT THE CUT DOES NOT DO, measured on a three-pair store: asking the English
|
|
58
|
+
// sentence still ANSWERS with a foreign rendering, because the engine can reach
|
|
59
|
+
// a shared continuation's predecessors on its own. What is removed is the
|
|
60
|
+
// DEPOSITED forward ambiguity — one context carrying ~100 competing
|
|
61
|
+
// continuations — not every reverse association.
|
|
62
|
+
const SMOLSENT_DIRECTIONS = env("SMOLSENT_DIRECTIONS", "src2trg")
|
|
63
|
+
.trim().toLowerCase();
|
|
64
|
+
const SMOLSENT_SRC2TRG = SMOLSENT_DIRECTIONS !== "trg2src";
|
|
65
|
+
const SMOLSENT_TRG2SRC = SMOLSENT_DIRECTIONS === "trg2src" ||
|
|
66
|
+
SMOLSENT_DIRECTIONS === "both";
|
|
67
|
+
// A SmolSent side longer than this is skipped (a sentence pair is short; a huge
|
|
68
|
+
// value is corruption, not a sentence).
|
|
69
|
+
const MAX_SMOLSENT_CHARS = Math.max(2_000, Math.floor(Number(env("MAX_SMOLSENT_KB", "16")) * 1000) || 16_000);
|
|
70
|
+
/** Normalize a raw datasets-server row into a SmolSentRow, or null when it lacks
|
|
71
|
+
* both sides or a side is implausibly large (a dump, not a sentence). */
|
|
72
|
+
export function toSmolSentRow(row, maxChars = MAX_SMOLSENT_CHARS) {
|
|
73
|
+
if (!row || typeof row !== "object")
|
|
74
|
+
return null;
|
|
75
|
+
const r = row;
|
|
76
|
+
const src = typeof r.src === "string" ? r.src.trim() : "";
|
|
77
|
+
// `trg` is a single string in smolsent; tolerate a list form defensively.
|
|
78
|
+
const trgRaw = Array.isArray(r.trgs) ? r.trgs[0] : r.trg;
|
|
79
|
+
const trg = typeof trgRaw === "string" ? trgRaw.trim() : "";
|
|
80
|
+
if (!src || !trg)
|
|
81
|
+
return null;
|
|
82
|
+
if (src.length > maxChars || trg.length > maxChars)
|
|
83
|
+
return null;
|
|
84
|
+
const sl = typeof r.sl === "string" ? r.sl.trim() : "";
|
|
85
|
+
const tl = typeof r.tl === "string" ? r.tl.trim() : "";
|
|
86
|
+
return { src, trg, sl, tl };
|
|
87
|
+
}
|
|
88
|
+
/** Translate ONE SmolSent pair into SEMA facts. The two sentences are one
|
|
89
|
+
* meaning in two languages, but the two BINDINGS are not equally sound —
|
|
90
|
+
* SmolSent's English side is a shared pool translated into every language, so
|
|
91
|
+
* `trg -> src` gives one English context a different answer in every language
|
|
92
|
+
* file. See SMOLSENT_DIRECTIONS. refineItems drops the degenerate case where
|
|
93
|
+
* src === trg. */
|
|
94
|
+
export function smolSentRowToItems(row, dirs = {
|
|
95
|
+
src2trg: SMOLSENT_SRC2TRG,
|
|
96
|
+
trg2src: SMOLSENT_TRG2SRC,
|
|
97
|
+
}) {
|
|
98
|
+
const { src, trg } = row;
|
|
99
|
+
const items = [];
|
|
100
|
+
if (dirs.src2trg)
|
|
101
|
+
items.push({ context: src, continuation: trg });
|
|
102
|
+
if (dirs.trg2src)
|
|
103
|
+
items.push({ context: trg, continuation: src });
|
|
104
|
+
return refineItems(items);
|
|
105
|
+
}
|
|
106
|
+
/** Discover the SmolSent per-pair JSONL files from the HF repo tree, restricted
|
|
107
|
+
* to SMOLSENT_PAIRS (basenames without .jsonl) when set. Each entry is the
|
|
108
|
+
* repo-relative path, e.g. "smolsent/ha_en.jsonl". */
|
|
109
|
+
async function listFiles(ctx) {
|
|
110
|
+
const paths = await hfTree(SMOLSENT_DATASET, "smolsent", /\.jsonl$/i, `GET smol tree`, ctx.http);
|
|
111
|
+
if (!SMOLSENT_PAIRS.length)
|
|
112
|
+
return paths;
|
|
113
|
+
const want = new Set(SMOLSENT_PAIRS.map((p) => p.replace(/\.jsonl$/i, "")));
|
|
114
|
+
return paths.filter((p) => want.has(basename(p.path).replace(/\.jsonl$/i, "")));
|
|
115
|
+
}
|
|
116
|
+
const unit = (name) => ({
|
|
117
|
+
key: name,
|
|
118
|
+
// The log names a pair by its language code alone; the panel keeps the file.
|
|
119
|
+
name: name.replace(/\.jsonl$/i, ""),
|
|
120
|
+
display: `SmolSent ${name}`,
|
|
121
|
+
});
|
|
122
|
+
export const smolsent = {
|
|
123
|
+
id: SMOLSENT_ID,
|
|
124
|
+
label: "SmolSent",
|
|
125
|
+
kind: "translation",
|
|
126
|
+
enabled: SMOLSENT,
|
|
127
|
+
unitNoun: "translation file(s)",
|
|
128
|
+
// The *4 is chars-to-a-generous-JSON-envelope: the guard bounds ONE side of
|
|
129
|
+
// a pair, the line carries both plus its keys.
|
|
130
|
+
read: lines({ maxLineChars: MAX_SMOLSENT_CHARS * 4 }),
|
|
131
|
+
toItems: (row) => {
|
|
132
|
+
const r = toSmolSentRow(row);
|
|
133
|
+
return r ? smolSentRowToItems(r) : null;
|
|
134
|
+
},
|
|
135
|
+
async discover(ctx) {
|
|
136
|
+
// Work-list: local *.jsonl in LOCAL_PATH, else the repo's smolsent/ files.
|
|
137
|
+
if (LOCAL_PATH) {
|
|
138
|
+
let names = localFiles(LOCAL_PATH, /\.jsonl$/i);
|
|
139
|
+
if (SMOLSENT_PAIRS.length) {
|
|
140
|
+
const want = new Set(SMOLSENT_PAIRS.map((p) => p.replace(/\.jsonl$/i, "")));
|
|
141
|
+
names = names.filter((n) => want.has(n.path.replace(/\.jsonl$/i, "")));
|
|
142
|
+
}
|
|
143
|
+
return names.map((n) => ({
|
|
144
|
+
...unit(n.path),
|
|
145
|
+
local: join(LOCAL_PATH, n.path),
|
|
146
|
+
bytes: n.size,
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
return (await listFiles(ctx)).map(({ path, size }) => ({
|
|
150
|
+
...unit(basename(path)),
|
|
151
|
+
// owner/name and the file path are URL PATH segments — do not encode "/".
|
|
152
|
+
url: `https://huggingface.co/datasets/${SMOLSENT_DATASET}/resolve/main/${path}`,
|
|
153
|
+
bytes: size,
|
|
154
|
+
}));
|
|
155
|
+
},
|
|
156
|
+
};
|