@hviana/sema 0.5.9 → 0.7.1
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/.github/workflows/release.yml +80 -0
- package/AGENTS.md +73 -13
- 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/meter.d.ts +1 -4
- package/dist/src/meter.js +0 -3
- package/dist/src/mind/attention.js +22 -20
- package/dist/src/mind/graph-search.d.ts +43 -9
- package/dist/src/mind/graph-search.js +82 -15
- package/dist/src/mind/junction.d.ts +13 -0
- package/dist/src/mind/junction.js +13 -0
- package/dist/src/mind/mechanisms/cover.js +23 -2
- package/dist/src/mind/mechanisms/prefix-completion.js +13 -11
- package/dist/src/mind/mechanisms/recall.js +8 -4
- package/dist/src/mind/mind.d.ts +1 -1
- package/dist/src/mind/mind.js +1 -1
- package/dist/src/mind/pipeline-mechanism.d.ts +0 -24
- package/dist/src/mind/pipeline-mechanism.js +13 -36
- package/dist/src/mind/pipeline.d.ts +23 -0
- package/dist/src/mind/pipeline.js +51 -3
- package/dist/src/mind/recognition.d.ts +6 -1
- package/dist/src/mind/recognition.js +11 -6
- package/dist/src/mind/resonance.js +48 -13
- package/dist/src/store.js +22 -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 +8 -5
- package/src/meter.ts +1 -4
- package/src/mind/attention.ts +22 -19
- package/src/mind/graph-search.ts +93 -16
- package/src/mind/junction.ts +13 -0
- package/src/mind/mechanisms/cover.ts +23 -4
- package/src/mind/mechanisms/prefix-completion.ts +13 -11
- package/src/mind/mechanisms/recall.ts +8 -4
- package/src/mind/mind.ts +1 -1
- package/src/mind/pipeline-mechanism.ts +13 -42
- package/src/mind/pipeline.ts +87 -3
- package/src/mind/recognition.ts +19 -6
- package/src/mind/resonance.ts +79 -50
- package/src/store.ts +21 -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/test/89-completion-recursion.test.mjs +230 -0
- package/test/90-connector-read-cap.test.mjs +130 -0
- package/test/91-branch-bytes-cache.test.mjs +152 -0
- package/test/93-regime-prediction.test.mjs +148 -0
- package/test/94-cross-region-budget.test.mjs +67 -0
- package/test/95-wide-resonance-removed.test.mjs +109 -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
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
export interface Episode {
|
|
2
|
-
context: string;
|
|
3
|
-
continuation: string;
|
|
4
|
-
}
|
|
5
|
-
export type TrainingItem = string | Episode;
|
|
6
|
-
/** Dedup + trim a concept's items: drop empty/degenerate pairs and exact
|
|
7
|
-
* repeats so a concept never deposits the same form twice. */
|
|
8
|
-
export declare function refineItems(items: TrainingItem[]): TrainingItem[];
|
|
9
|
-
/** One normalized SmolSent row. */
|
|
10
|
-
export interface SmolSentRow {
|
|
11
|
-
src: string;
|
|
12
|
-
trg: string;
|
|
13
|
-
sl: string;
|
|
14
|
-
tl: string;
|
|
15
|
-
}
|
|
16
|
-
/** Normalize a raw datasets-server row into a SmolSentRow, or null when it lacks
|
|
17
|
-
* both sides or a side is implausibly large (a dump, not a sentence). */
|
|
18
|
-
export declare function toSmolSentRow(row: unknown): SmolSentRow | null;
|
|
19
|
-
/** Translate ONE SmolSent pair into SEMA facts. The two sentences are one
|
|
20
|
-
* meaning in two languages, but the two BINDINGS are not equally sound —
|
|
21
|
-
* SmolSent's English side is a shared pool translated into every language, so
|
|
22
|
-
* `trg -> src` gives one English context a different answer in every language
|
|
23
|
-
* file. See SMOLSENT_DIRECTIONS. refineItems drops the degenerate case where
|
|
24
|
-
* src === trg. */
|
|
25
|
-
export declare function smolSentRowToItems(row: SmolSentRow): TrainingItem[];
|
|
26
|
-
/** One normalized Aya row. */
|
|
27
|
-
export interface AyaRow {
|
|
28
|
-
inputs: string;
|
|
29
|
-
targets: string;
|
|
30
|
-
language: string;
|
|
31
|
-
}
|
|
32
|
-
/** Normalize a raw datasets-server row object into an AyaRow, or null when it
|
|
33
|
-
* lacks a usable prompt/answer or a field is implausibly large (a dump, not a
|
|
34
|
-
* cognitive example). Trims surrounding whitespace; keeps inner text verbatim
|
|
35
|
-
* (human prose, possibly multi-paragraph). */
|
|
36
|
-
export declare function toAyaRow(row: unknown): AyaRow | null;
|
|
37
|
-
/** Translate ONE Aya row into SEMA training items. A row is a single human
|
|
38
|
-
* (question → answer) exchange — exactly one FACT, the (inputs → targets) edge.
|
|
39
|
-
* No standalone-answer experience and no one-exchange "cumulative" walk: a lone
|
|
40
|
-
* Q→A is not multi-turn, and both would only replicate the same edge. */
|
|
41
|
-
export declare function ayaRowToItems(row: AyaRow): TrainingItem[];
|
|
42
|
-
/** A single oasst2 message node (the fields we use; the tree nests via replies). */
|
|
43
|
-
interface OasstNode {
|
|
44
|
-
role?: string;
|
|
45
|
-
text?: string;
|
|
46
|
-
rank?: number | null;
|
|
47
|
-
deleted?: boolean;
|
|
48
|
-
replies?: OasstNode[];
|
|
49
|
-
}
|
|
50
|
-
/** One conversational turn extracted from a tree. */
|
|
51
|
-
export interface OasstTurn {
|
|
52
|
-
role: string;
|
|
53
|
-
text: string;
|
|
54
|
-
}
|
|
55
|
-
/** Collapse a conversation tree to ONE linear path: at each node, descend into
|
|
56
|
-
* its best-ranked, non-deleted reply (rank 0 preferred; unranked sorts last).
|
|
57
|
-
* Returns the ordered turns (already strictly alternating in this corpus). */
|
|
58
|
-
export declare function bestOasstPath(root: OasstNode): OasstTurn[];
|
|
59
|
-
/** Translate ONE multi-turn oasst2 conversation into SEMA training items.
|
|
60
|
-
*
|
|
61
|
-
* This is the ONE stage where cumulative continuous context is truly necessary:
|
|
62
|
-
* the data is a real multi-turn dialogue, and what must be learned is how each
|
|
63
|
-
* turn follows from the WHOLE conversation so far — not from the previous turn
|
|
64
|
-
* alone. The conversation is emitted ONLY as the accumulated walk; standalone
|
|
65
|
-
* turn experiences and local adjacent-pair facts are NOT emitted (they are
|
|
66
|
-
* subsumed by it and would merely replicate the content).
|
|
67
|
-
*
|
|
68
|
-
* The walk is the pattern proven in test/13-conversation.test.mjs
|
|
69
|
-
* ("teachConversation"): each turn is the continuation of all prior turns,
|
|
70
|
-
* with BARE turn text — NO "User:/Assistant:" labels. The SHAPE is identical
|
|
71
|
-
* (cumulative context → next turn); the join string is not, and does not need
|
|
72
|
-
* to be — that file joins with nothing and this corpus joins with "\n" (see
|
|
73
|
-
* `accumulate`). Saying "byte-for-byte", as this comment used to, invites the
|
|
74
|
-
* reading that the two must agree on a separator. They must not agree,
|
|
75
|
-
* because there is nothing to agree about: turn boundaries are offsets, and
|
|
76
|
-
* the join string is just corpus text. Roles already
|
|
77
|
-
* alternate by position in an oasst2 best-path (the root is a prompter), so a
|
|
78
|
-
* label adds nothing the position does not, while a clean continuation matches
|
|
79
|
-
* the test's recall (predictNext queries bare prior turns) and lets a turn share
|
|
80
|
-
* its gist with the same text elsewhere (e.g. an Aya question stored bare).
|
|
81
|
-
*
|
|
82
|
-
* Returns [] for a conversation below the multi-turn threshold, so callers can
|
|
83
|
-
* simply skip empties. */
|
|
84
|
-
export declare function oasstConversationToItems(turns: OasstTurn[]): TrainingItem[];
|
|
85
|
-
/** One utterance of a Taskmaster conversation. */
|
|
86
|
-
export interface TaskmasterTurn {
|
|
87
|
-
speaker: string;
|
|
88
|
-
text: string;
|
|
89
|
-
}
|
|
90
|
-
/** Normalize ONE element of a Taskmaster data file into its turns, or null when
|
|
91
|
-
* it carries no usable utterance. Empty/whitespace-only utterances are dropped
|
|
92
|
-
* (TM-3 has a few); a single implausibly long utterance rejects the whole
|
|
93
|
-
* conversation as corrupt rather than depositing a dump. */
|
|
94
|
-
export declare function toTaskmasterTurns(row: unknown): TaskmasterTurn[] | null;
|
|
95
|
-
/** Collapse consecutive same-speaker turns into one, joining with a space, and
|
|
96
|
-
* return the bare texts in order. A turn with no speaker never merges with its
|
|
97
|
-
* neighbour: an unlabelled row is of unknown origin, and joining two of them
|
|
98
|
-
* would invent a contribution that may span two speakers. */
|
|
99
|
-
export declare function mergeTaskmasterTurns(turns: TaskmasterTurn[]): string[];
|
|
100
|
-
/** Translate ONE Taskmaster conversation into SEMA training items: the
|
|
101
|
-
* cumulative walk over its merged turns. Returns [] for a conversation below
|
|
102
|
-
* TASKMASTER_MIN_TURNS, so callers can simply skip empties. */
|
|
103
|
-
export declare function taskmasterConversationToItems(turns: TaskmasterTurn[]): TrainingItem[];
|
|
104
|
-
/** One (subject, relation, object) triple from a 2Wiki `evidences` cell. */
|
|
105
|
-
export interface WikiTriple {
|
|
106
|
-
subject: string;
|
|
107
|
-
relation: string;
|
|
108
|
-
object: string;
|
|
109
|
-
}
|
|
110
|
-
/** Normalize a 2Wiki row into its evidence triples, or null when it carries
|
|
111
|
-
* none usable. `evidences` is a JSON STRING holding an array of 3-element
|
|
112
|
-
* arrays; a row whose cell is absent, unparseable, or empty yields null.
|
|
113
|
-
* Individual malformed or oversized triples are dropped without discarding the
|
|
114
|
-
* row — one bad triple should not cost the others. */
|
|
115
|
-
export declare function toWikiTriples(row: unknown): WikiTriple[] | null;
|
|
116
|
-
/** Render ONE triple as the prose fact Sema stores. Kept separate so the two
|
|
117
|
-
* deposits below are guaranteed to share a byte-identical continuation: the
|
|
118
|
-
* pivot fact only works if it leads to the SAME node the relation fact does. */
|
|
119
|
-
export declare function wikiTripleSentence(t: WikiTriple): string;
|
|
120
|
-
/** Translate a row's triples into SEMA items: per triple, the relation fact and
|
|
121
|
-
* the bare-subject PIVOT fact (see the section note above). refineItems drops
|
|
122
|
-
* the duplicates this produces when a row states the same triple twice. */
|
|
123
|
-
export declare function wikiTriplesToItems(triples: WikiTriple[]): TrainingItem[];
|
|
124
|
-
/** Normalize a SODA row into its turns, or null when it carries no usable
|
|
125
|
-
* dialogue. Speakers are optional (they only drive merging); an implausibly
|
|
126
|
-
* long turn rejects the dialogue as corrupt. */
|
|
127
|
-
export declare function toSodaTurns(row: unknown): TaskmasterTurn[] | null;
|
|
128
|
-
/** Translate ONE SODA dialogue into SEMA items: the cumulative walk over its
|
|
129
|
-
* speaker-merged turns. Shares `mergeTaskmasterTurns` because the rule is the
|
|
130
|
-
* same one — consecutive turns by one speaker are one contribution. */
|
|
131
|
-
export declare function sodaDialogueToItems(turns: TaskmasterTurn[]): TrainingItem[];
|
|
132
|
-
/** Translate ONE MASSIVE row into SEMA items: its bare utterance, as an
|
|
133
|
-
* experience. `annot_utt` (slot-annotated) is deliberately not used — its
|
|
134
|
-
* "[date : ...]" markup is not prose. Returns [] for an unusable row. */
|
|
135
|
-
export declare function massiveRowToItems(row: unknown): TrainingItem[];
|
|
136
|
-
/** One normalized General-Knowledge row. */
|
|
137
|
-
export interface GenKnowRow {
|
|
138
|
-
question: string;
|
|
139
|
-
answer: string;
|
|
140
|
-
}
|
|
141
|
-
/** Normalize a raw datasets-server row into a GenKnowRow, or null when it lacks
|
|
142
|
-
* a usable question/answer or a side is implausibly large (corruption). */
|
|
143
|
-
export declare function toGenKnowRow(row: unknown): GenKnowRow | null;
|
|
144
|
-
/** Translate ONE General-Knowledge row into SEMA items: exactly one
|
|
145
|
-
* (question → answer) FACT. refineItems drops a degenerate question === answer. */
|
|
146
|
-
export declare function genKnowRowToItems(row: GenKnowRow): TrainingItem[];
|
|
147
|
-
/** How many rows to materialise in one read from a row-group of `rgRows` rows
|
|
148
|
-
* occupying `groupBytes` uncompressed bytes, under a `budgetBytes` target.
|
|
149
|
-
*
|
|
150
|
-
* The group's own footer statistics give the mean row width, so the batch
|
|
151
|
-
* follows the CORPUS's row size rather than the writer's layout: wide rows
|
|
152
|
-
* (SODA carries a whole dialogue per row) batch smaller than narrow ones at
|
|
153
|
-
* the same memory cost. Never exceeds the group — a batch is a subdivision of
|
|
154
|
-
* a group, never a span across two, because `parquetReadObjects` is given an
|
|
155
|
-
* absolute row range and column chunks are per-group. Never returns 0, or the
|
|
156
|
-
* read loop could not advance.
|
|
157
|
-
*
|
|
158
|
-
* A writer that omits `total_byte_size` yields `groupBytes <= 0`; the batch is
|
|
159
|
-
* then the whole group, which is exactly the behaviour this replaced. That
|
|
160
|
-
* fallback is safe for every file we read today (all three report it) and
|
|
161
|
-
* degrades to the old memory profile rather than to a wrong result. */
|
|
162
|
-
export declare function parquetBatchRows(rgRows: number, groupBytes: number, budgetBytes: number): number;
|
|
163
|
-
export {};
|