pliers.extractors.TFHubExtractor¶
- class pliers.extractors.TFHubExtractor(url_or_path, features=None, transform_out=None, transform_inp=None, keras_kwargs=None)[source]¶
Bases:
ExtractorA generic class for Tensorflow Hub extractors :param url_or_path: url or path to TFHub model. You can
browse models at https://tfhub.dev/.
- Parameters
features (optional) – list of labels (for classification) or other feature names. The number of items must match the number of features in the output. For example, if a classification model with 1000 output classes is passed (e.g. EfficientNet B6, see https://tfhub.dev/tensorflow/efficientnet/b6/classification/1), this must be a list containing 1000 items. If a text encoder outputting 768-dimensional encoding is passed (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. Along the lines of the previous examples, if a single feature name is passed here (e.g. if features=[‘encoding’]) for a TFHub model that outputs a 768-dimensional encoding, the extractor will return only one feature named ‘encoding’, which contains the encoding vector as a 1-d array wrapped in a list. 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).
transform_out (optional) – function to transform model output for compatibility with extractor result
transform_inp (optional) – function to transform Stim.data for compatibility with model input format
keras_kwargs (dict) – arguments to hub.KerasLayer call
- __init__(url_or_path, features=None, transform_out=None, transform_inp=None, keras_kwargs=None)[source]¶
- transform(stim, *args, **kwargs)¶
Executes the transformation on the passed stim(s).
- Parameters
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.