Replace toxicity model with multi-label classifier
This commit is contained in:
parent
803df7feee
commit
1568c787f8
24 changed files with 2581129 additions and 119717 deletions
|
|
@ -3,25 +3,26 @@ import { validateManifest } from "../src/inference/model-metadata";
|
|||
import { resolveOutputIndex } from "../src/inference/classifier";
|
||||
|
||||
const manifest = {
|
||||
source: "wagesj45/toxic-comment-classifier",
|
||||
source: "wagesj45/multilabel-toxic-comment-classifier",
|
||||
revision: "abc123",
|
||||
architecture: "DistilBertForSequenceClassification",
|
||||
labels: { toxic: 1, nonToxic: 0, names: { toxic: 1, non_toxic: 0 } },
|
||||
architecture: "ModernBertForSequenceClassification",
|
||||
labels: { names: { toxicity: 0, severe_toxicity: 1, obscene: 2, threat: 3, insult: 4, identity_attack: 5, sexual_explicit: 6 } },
|
||||
scoring: "multi-label-sigmoid" as const,
|
||||
maxLength: 512,
|
||||
quantization: "int8-dynamic",
|
||||
runtime: "onnxruntime-web-wasm"
|
||||
};
|
||||
|
||||
describe("model contract", () => {
|
||||
it("accepts a binary manifest and resolves common output labels", () => {
|
||||
it("accepts a multi-label manifest and resolves output labels", () => {
|
||||
expect(validateManifest(manifest)).toEqual(manifest);
|
||||
expect(resolveOutputIndex("LABEL_1", manifest)).toBe(1);
|
||||
expect(resolveOutputIndex("not-toxic", manifest)).toBe(0);
|
||||
expect(resolveOutputIndex("toxic", manifest)).toBe(1);
|
||||
expect(resolveOutputIndex("identity-attack", manifest)).toBe(5);
|
||||
expect(resolveOutputIndex("toxicity", manifest)).toBe(0);
|
||||
});
|
||||
|
||||
it("rejects incomplete metadata", () => {
|
||||
expect(() => validateManifest({ ...manifest, labels: { toxic: 1, nonToxic: 1, names: {} } })).toThrow();
|
||||
expect(() => validateManifest({ ...manifest, labels: { names: { ...manifest.labels.names, threat: 1 } } })).toThrow();
|
||||
expect(() => validateManifest({ ...manifest, maxLength: 0 })).toThrow();
|
||||
expect(() => validateManifest({ ...manifest, labels: undefined as unknown as typeof manifest.labels })).toThrow();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue