Skip to content

Commit

Permalink
Convert BatchFeature too (thanks Amy)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rocketknight1 committed Jan 31, 2024
1 parent 0ec0200 commit 8eb0489
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/transformers/tf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import numpy as np
import tensorflow as tf

from .feature_extraction_utils import BatchFeature
from .tokenization_utils_base import BatchEncoding
from .utils import logging

Expand Down Expand Up @@ -257,10 +258,10 @@ def _expand_single_1d_tensor(t):


def convert_batch_encoding(*args, **kwargs):
# Convert HF BatchEncoding objects in the inputs to dicts that Keras understands
if args and isinstance(args[0], BatchEncoding):
# Convert HF BatchEncoding/BatchFeature objects in the inputs to dicts that Keras understands
if args and isinstance(args[0], (BatchEncoding, BatchFeature)):
args = list(args)
args[0] = dict(args[0])
elif "x" in kwargs and isinstance(kwargs["x"], BatchEncoding):
elif "x" in kwargs and isinstance(kwargs["x"], (BatchEncoding, BatchFeature)):
kwargs["x"] = dict(kwargs["x"])
return args, kwargs

0 comments on commit 8eb0489

Please sign in to comment.