in src/nodes/client/token-classification.ts [92:143]
async runWithInputs(inputs: Inputs) {
const { text, modelid, device, quantized } = inputs;
const _modelid = modelid?.trim();
if (!text) {
// No input node
this.dispatchEvent(
new CustomEvent("outputs", { detail: { results: null, text: text } })
);
return;
}
if (this.cachedResult && compareObjects(this.cachedInput, inputs)) {
this.dispatchEvent(
new CustomEvent("outputs", {
detail: {
results: {
tokens: this.cachedResult,
},
text: text,
},
})
);
return;
}
const classifier: TokenClassificationPipeline = await this.getInstance(
_modelid,
quantized,
device
);
const result = await classifier(text, {
ignore_labels: [], // Return all labels
});
const resultArray = (
Array.isArray(result) ? result : [result]
) as TokenClassificationSingle[];
const tokens = this.postProcess(classifier.tokenizer, resultArray);
this.cachedInput = inputs;
this.cachedResult = tokens;
this.dispatchEvent(
new CustomEvent("outputs", {
detail: {
results: {
tokens: tokens,
},
text: text,
},
})
);
}