From 31ad34dd09bbd27890e8cc5b98759681e2234d19 Mon Sep 17 00:00:00 2001 From: Joshua Lochner Date: Sun, 19 Nov 2023 19:07:18 +0200 Subject: [PATCH] Improvements --- src/models.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/models.js b/src/models.js index 925556414..6767857db 100644 --- a/src/models.js +++ b/src/models.js @@ -492,11 +492,13 @@ function seq2seqUpdatebeam(beam, newTokenId) { * @private */ async function encoderForward(self, model_inputs) { - let encoderFeeds = {}; - for (let key of self.session.inputNames) { + const encoderFeeds = Object.create(null); + for (const key of self.session.inputNames) { encoderFeeds[key] = model_inputs[key]; } - if (!encoderFeeds.token_type_ids && self.session.inputNames.includes('token_type_ids')) { + if (self.session.inputNames.includes('token_type_ids') && !encoderFeeds.token_type_ids) { + // Assign default `token_type_ids` to the `encoderFeeds` if the model expects it, + // but they weren't created by the tokenizer. add_token_types(encoderFeeds); } return await sessionRun(self.session, encoderFeeds);