av commited on
Commit ·
9d929f5
1
Parent(s): ed5b990
fix: use actual text length for HRM input instead of padding to 2048
Browse files- index.html +6 -7
index.html
CHANGED
|
@@ -521,16 +521,15 @@
|
|
| 521 |
const bytes = encoder.encode(text);
|
| 522 |
const len = Math.min(bytes.length, HRM_MAX_LEN);
|
| 523 |
|
| 524 |
-
const inputIds = new BigInt64Array(
|
| 525 |
-
const attentionMask = new BigInt64Array(
|
| 526 |
|
| 527 |
for (let i = 0; i < len; i++) {
|
| 528 |
inputIds[i] = BigInt(bytes[i]);
|
| 529 |
attentionMask[i] = 1n;
|
| 530 |
}
|
| 531 |
-
// Remaining positions are already 0 (padded)
|
| 532 |
|
| 533 |
-
return { inputIds, attentionMask };
|
| 534 |
}
|
| 535 |
|
| 536 |
async function analyzeDistilbert(text) {
|
|
@@ -540,11 +539,11 @@
|
|
| 540 |
}
|
| 541 |
|
| 542 |
async function analyzeHrm(text) {
|
| 543 |
-
const { inputIds, attentionMask } = tokenizeBytes(text);
|
| 544 |
const ortLib = await getOrt();
|
| 545 |
|
| 546 |
-
const inputTensor = new ortLib.Tensor('int64', inputIds, [1,
|
| 547 |
-
const maskTensor = new ortLib.Tensor('int64', attentionMask, [1,
|
| 548 |
|
| 549 |
const results = await hrmSession.run({
|
| 550 |
input_ids: inputTensor,
|
|
|
|
| 521 |
const bytes = encoder.encode(text);
|
| 522 |
const len = Math.min(bytes.length, HRM_MAX_LEN);
|
| 523 |
|
| 524 |
+
const inputIds = new BigInt64Array(len);
|
| 525 |
+
const attentionMask = new BigInt64Array(len);
|
| 526 |
|
| 527 |
for (let i = 0; i < len; i++) {
|
| 528 |
inputIds[i] = BigInt(bytes[i]);
|
| 529 |
attentionMask[i] = 1n;
|
| 530 |
}
|
|
|
|
| 531 |
|
| 532 |
+
return { inputIds, attentionMask, seqLen: len };
|
| 533 |
}
|
| 534 |
|
| 535 |
async function analyzeDistilbert(text) {
|
|
|
|
| 539 |
}
|
| 540 |
|
| 541 |
async function analyzeHrm(text) {
|
| 542 |
+
const { inputIds, attentionMask, seqLen } = tokenizeBytes(text);
|
| 543 |
const ortLib = await getOrt();
|
| 544 |
|
| 545 |
+
const inputTensor = new ortLib.Tensor('int64', inputIds, [1, seqLen]);
|
| 546 |
+
const maskTensor = new ortLib.Tensor('int64', attentionMask, [1, seqLen]);
|
| 547 |
|
| 548 |
const results = await hrmSession.run({
|
| 549 |
input_ids: inputTensor,
|