Token Classification
Transformers.js
ONNX
bert
feature-extraction
coreference
multilingual
onnxruntime-web
Instructions to use cp500/infon-coref-pointer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use cp500/infon-coref-pointer with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('token-classification', 'cp500/infon-coref-pointer');
Upload js/test/pairs.test.ts with huggingface_hub
Browse files- js/test/pairs.test.ts +77 -0
js/test/pairs.test.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { test } from 'node:test';
|
| 2 |
+
import { strict as assert } from 'node:assert';
|
| 3 |
+
import {
|
| 4 |
+
buildPairs,
|
| 5 |
+
pickAntecedents,
|
| 6 |
+
groupClusters,
|
| 7 |
+
} from '../src/pairs.js';
|
| 8 |
+
|
| 9 |
+
test('buildPairs: empty', () => {
|
| 10 |
+
const [pi, pj] = buildPairs(0);
|
| 11 |
+
assert.equal(pi.length, 0);
|
| 12 |
+
assert.equal(pj.length, 0);
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
test('buildPairs: single mention has only DUMMY pair', () => {
|
| 16 |
+
const [pi, pj] = buildPairs(1);
|
| 17 |
+
assert.deepEqual(Array.from(pi), [1n]);
|
| 18 |
+
assert.deepEqual(Array.from(pj), [0n]);
|
| 19 |
+
});
|
| 20 |
+
|
| 21 |
+
test('buildPairs: triangular shape matches Python', () => {
|
| 22 |
+
// M=3 β mention 1 has [0]; mention 2 has [0,1]; mention 3 has [0,1,2].
|
| 23 |
+
// Total = 1 + 2 + 3 = 6.
|
| 24 |
+
const [pi, pj] = buildPairs(3);
|
| 25 |
+
assert.deepEqual(Array.from(pi), [1n, 2n, 2n, 3n, 3n, 3n]);
|
| 26 |
+
assert.deepEqual(Array.from(pj), [0n, 0n, 1n, 0n, 1n, 2n]);
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
test('pickAntecedents: argmax respects per-mention slicing', () => {
|
| 30 |
+
const [pi, pj] = buildPairs(3);
|
| 31 |
+
// Set up scores so mention 1 β DUMMY, mention 2 β mention 1,
|
| 32 |
+
// mention 3 β mention 1.
|
| 33 |
+
const scores = Float32Array.from([
|
| 34 |
+
9.0, // m=1, j=0 (DUMMY) β best
|
| 35 |
+
-1.0, // m=2, j=0 (DUMMY)
|
| 36 |
+
9.0, // m=2, j=1 β best
|
| 37 |
+
-1.0, // m=3, j=0 (DUMMY)
|
| 38 |
+
9.0, // m=3, j=1 β best
|
| 39 |
+
-1.0, // m=3, j=2
|
| 40 |
+
]);
|
| 41 |
+
const out = pickAntecedents(3, pi, pj, scores);
|
| 42 |
+
assert.deepEqual(
|
| 43 |
+
out.map((x) => x.antecedent),
|
| 44 |
+
[0, 1, 1],
|
| 45 |
+
);
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
test('groupClusters: chained pointers form one cluster', () => {
|
| 49 |
+
// m0 β DUMMY, m1 β m0, m2 β m1 β all in one cluster.
|
| 50 |
+
const decisions = [
|
| 51 |
+
{ antecedent: 0 },
|
| 52 |
+
{ antecedent: 1 },
|
| 53 |
+
{ antecedent: 2 },
|
| 54 |
+
];
|
| 55 |
+
const { cluster, clusters } = groupClusters(decisions);
|
| 56 |
+
assert.deepEqual(cluster, [0, 0, 0]);
|
| 57 |
+
assert.deepEqual(clusters, [[0, 1, 2]]);
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
test('groupClusters: singletons have cluster=-1', () => {
|
| 61 |
+
// Two independent singletons + one chain.
|
| 62 |
+
const decisions = [
|
| 63 |
+
{ antecedent: 0 }, // m0: DUMMY β singleton
|
| 64 |
+
{ antecedent: 0 }, // m1: DUMMY β singleton
|
| 65 |
+
{ antecedent: 1 }, // m2 β m0 β cluster
|
| 66 |
+
{ antecedent: 3 }, // m3 β m2 β cluster
|
| 67 |
+
];
|
| 68 |
+
const { cluster, clusters } = groupClusters(decisions);
|
| 69 |
+
assert.equal(cluster[1], -1);
|
| 70 |
+
assert.deepEqual(clusters, [[0, 2, 3]]);
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
test('groupClusters: empty input', () => {
|
| 74 |
+
const { cluster, clusters } = groupClusters([]);
|
| 75 |
+
assert.deepEqual(cluster, []);
|
| 76 |
+
assert.deepEqual(clusters, []);
|
| 77 |
+
});
|