pliers.extractors.TFHubTextExtractor

class pliers.extractors.TFHubTextExtractor(url_or_path, features=None, output_key='default', preprocessor_url_or_path=None, preprocessor_kwargs=None, keras_kwargs=None, **kwargs)[source]

Bases: TFHubExtractor

TFHub extractor class for text models :param url_or_path: url or path to TFHub model. You can

browse models at https://tfhub.dev/.

Parameters
  • features (optional) –

    list of labels or other feature names. The number of items must match the number of features in the model output. For example, if a text encoder outputting 768-dimensional encoding is passed

    output_key (str): key to desired embedding in output

    dictionary (see documentation at https://www.tensorflow.org/hub/common_saved_model_apis/text). Set to None is the output is not a dictionary, or to output all keys (e.g. base BERT), this must be a list containing 768 items. Each dimension in the model output will be returned as a separate feature in the ExtractorResult. Alternatively, the model output can be packed into a single feature (i.e. a vector) by passing a single-element list (e.g. [‘encoding’]) or a string. If no value is passed, the extractor will automatically compute the number of features in the model output and return an equal number of features in pliers, labeling each feature with a generic prefix + its positional index in the model output (feature_0, feature_1, … ,feature_n).

  • output_key (str) – key to desired embedding in output dictionary (see documentation at https://www.tensorflow.org/hub/common_saved_model_apis/text). Set to None is the output is not a dictionary, or to output all keys

  • preprocessor_url_or_path (str) – if the model requires preprocessing through another TFHub model, specifies the url or path to the preprocessing module. Information on required preprocessing and appropriate models is generally available on the TFHub model webpage

  • preprocessor_kwargs (dict) – dictionary or named arguments for preprocessor model hub.KerasLayer call

__init__(url_or_path, features=None, output_key='default', preprocessor_url_or_path=None, preprocessor_kwargs=None, keras_kwargs=None, **kwargs)[source]
transform(stim, *args, **kwargs)

Executes the transformation on the passed stim(s).

Parameters
  • stims (str, Stim, list) –

    One or more stimuli to process. Must be one of:

    • A string giving the path to a file that can be read in as a Stim (e.g., a .txt file, .jpg image, etc.)

    • A Stim instance of any type.

    • An iterable of stims, where each element is either a string or a Stim.

  • validation (str) –

    String specifying how validation errors should be handled. Must be one of:

    • ’strict’: Raise an exception on any validation error

    • ’warn’: Issue a warning for all validation errors

    • ’loose’: Silently ignore all validation errors

  • args – Optional positional arguments to pass onto the internal _transform call.

  • kwargs – Optional positional arguments to pass onto the internal _transform call.