File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ import {
42
42
AutoConfig ,
43
43
} from './configs.js' ;
44
44
45
+ import {
46
+ add_token_types ,
47
+ } from './tokenizers.js' ;
48
+
45
49
import {
46
50
Callable ,
47
51
isIntegralNumber ,
@@ -488,10 +492,15 @@ function seq2seqUpdatebeam(beam, newTokenId) {
488
492
* @private
489
493
*/
490
494
async function encoderForward ( self , model_inputs ) {
491
- let encoderFeeds = { } ;
492
- for ( let key of self . session . inputNames ) {
495
+ const encoderFeeds = Object . create ( null ) ;
496
+ for ( const key of self . session . inputNames ) {
493
497
encoderFeeds [ key ] = model_inputs [ key ] ;
494
498
}
499
+ if ( self . session . inputNames . includes ( 'token_type_ids' ) && ! encoderFeeds . token_type_ids ) {
500
+ // Assign default `token_type_ids` to the `encoderFeeds` if the model expects it,
501
+ // but they weren't created by the tokenizer.
502
+ add_token_types ( encoderFeeds ) ;
503
+ }
495
504
return await sessionRun ( self . session , encoderFeeds ) ;
496
505
}
497
506
Original file line number Diff line number Diff line change @@ -2578,7 +2578,7 @@ export class PreTrainedTokenizer extends Callable {
2578
2578
* @param {Object } inputs An object containing the input ids and attention mask.
2579
2579
* @returns {Object } The prepared inputs object.
2580
2580
*/
2581
- function add_token_types ( inputs ) {
2581
+ export function add_token_types ( inputs ) {
2582
2582
// TODO ensure correctness when token pair is present
2583
2583
if ( inputs . input_ids instanceof Tensor ) {
2584
2584
inputs . token_type_ids = new Tensor (
You can’t perform that action at this time.
0 commit comments