cp500 commited on
Commit
d5f9738
·
verified ·
1 Parent(s): bd7a5c9

Upload js/src/types.ts with huggingface_hub

Browse files
Files changed (1) hide show
  1. js/src/types.ts +104 -0
js/src/types.ts ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Public type surface for @cp500/infon-coref.
3
+ *
4
+ * Most consumers only need {@link CorefResult}; the rest are exposed
5
+ * so power users can wire individual pipeline stages on their own.
6
+ */
7
+
8
+ /** A single wordpiece token, with its char-level alignment back into
9
+ * the source text. ``start`` and ``end`` are byte offsets into the
10
+ * UTF-8 string (the same convention Python uses).
11
+ */
12
+ export interface Token {
13
+ /** Token-vocabulary id. */
14
+ id: number;
15
+ /** The decoded string for this token (includes ▁ for SentencePiece
16
+ * word-initial pieces). */
17
+ text: string;
18
+ /** Inclusive char offset where this token starts. */
19
+ start: number;
20
+ /** Exclusive char offset where this token ends. */
21
+ end: number;
22
+ }
23
+
24
+ /** A detected mention span, in wordpiece coordinates and char
25
+ * coordinates. ``start``/``end`` are inclusive **wordpiece** indices;
26
+ * ``charStart``/``charEnd`` are exclusive **char** offsets. */
27
+ export interface Mention {
28
+ /** First wordpiece in the mention (inclusive). */
29
+ start: number;
30
+ /** Last wordpiece in the mention (inclusive). */
31
+ end: number;
32
+ /** Char offset where the mention begins. */
33
+ charStart: number;
34
+ /** Char offset just past the last char of the mention. */
35
+ charEnd: number;
36
+ /** The literal substring of the source text covered by this mention. */
37
+ text: string;
38
+ /** Cluster index this mention was assigned to. -1 if singleton. */
39
+ cluster: number;
40
+ /** Index of the most recent earlier mention sharing this cluster, or
41
+ * -1 if this mention starts a new cluster. */
42
+ antecedent: number;
43
+ }
44
+
45
+ /** End-to-end coreference resolution output. */
46
+ export interface CorefResult {
47
+ /** Original input text, unchanged. */
48
+ text: string;
49
+ /** Wordpiece tokenization with offsets. */
50
+ tokens: Token[];
51
+ /** Mentions in document order, with cluster + antecedent assignments. */
52
+ mentions: Mention[];
53
+ /** clusters[c] is a list of mention indices belonging to cluster c.
54
+ * Only multi-mention clusters are listed; singletons are marked
55
+ * with ``cluster: -1`` on the {@link Mention}. */
56
+ clusters: number[][];
57
+ /** Per-stage timing in milliseconds. */
58
+ timing: {
59
+ tokenize: number;
60
+ backbone: number;
61
+ bioDecode: number;
62
+ scorer: number;
63
+ total: number;
64
+ };
65
+ }
66
+
67
+ /** Quantization variant + execution device picked at load time. The
68
+ * library auto-falls-back when a requested combination isn't
69
+ * available (e.g. WebGPU + FP16 → WASM + FP16 → WASM + FP32). */
70
+ export interface ModelOptions {
71
+ /** ``'fp16'`` halves the download (235 MB vs 470 MB) and runs
72
+ * faster on WebGPU. ``'fp32'`` is the safe default for debugging.
73
+ * @default 'fp16' */
74
+ precision?: 'fp32' | 'fp16';
75
+ /** Execution provider for ORT. Browser values: ``'webgpu'`` |
76
+ * ``'wasm'``. Node values: ``'cpu'`` | ``'cuda'``. ``'auto'`` picks
77
+ * the fastest available.
78
+ * @default 'auto' */
79
+ device?: 'auto' | 'webgpu' | 'wasm' | 'cpu' | 'cuda';
80
+ /** Hard cap on input wordpieces; longer inputs get truncated.
81
+ * @default 256 */
82
+ maxLength?: number;
83
+ /** Threshold over the BIO ``B``/``I`` softmax (vs ``O``) for span
84
+ * detection. Higher = stricter, fewer mentions.
85
+ * @default 0.5 */
86
+ bioThreshold?: number;
87
+ /** Print timing + per-stage shapes to ``console.debug``.
88
+ * @default false */
89
+ debug?: boolean;
90
+ }
91
+
92
+ /** Loaded ONNX session pair + tokenizer + metadata. */
93
+ export interface LoadedModel {
94
+ backbone: import('./ort.js').OrtSession;
95
+ scorer: import('./ort.js').OrtSession;
96
+ tokenizer: import('./tokenizer.js').Tokenizer;
97
+ meta: {
98
+ hiddenSize: number;
99
+ nBioClasses: number;
100
+ maxLength: number;
101
+ precision: 'fp32' | 'fp16';
102
+ device: string;
103
+ };
104
+ }