{"record":{"id":"ae179e0abcf88bf1","repo":"huggingface/transformers","slug":"type-of-first-element-unknown-type-first-eleme","errorCode":null,"errorMessage":"type of {first_element} unknown: {type(first_element)}. Should be one of a python, numpy, or pytorch object.","messagePattern":"type of (.+?) unknown: (.+?)\\. Should be one of a python, numpy, or pytorch object\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/feature_extraction_sequence_utils.py","lineNumber":164,"sourceCode":"        # and rebuild them afterwards if no return_tensors is specified\n        # Note that we lose the specific device the tensor may be on for PyTorch\n\n        first_element = required_input[0]\n        if isinstance(first_element, (list, tuple)):\n            # first_element might be an empty list/tuple in some edge cases so we grab the first non empty element.\n            index = 0\n            while len(required_input[index]) == 0:\n                index += 1\n            if index < len(required_input):\n                first_element = required_input[index][0]\n\n        if return_tensors is None:\n            if is_torch_tensor(first_element):\n                return_tensors = \"pt\"\n            elif isinstance(first_element, (int, float, list, tuple, np.ndarray)):\n                return_tensors = \"np\"\n            else:\n                raise ValueError(\n                    f\"type of {first_element} unknown: {type(first_element)}. \"\n                    \"Should be one of a python, numpy, or pytorch object.\"\n                )\n\n        for key, value in processed_features.items():\n            if isinstance(value[0], (int, float)):\n                processed_features[key] = to_numpy(value)\n            elif not isinstance(value, np.ndarray):\n                # An already-batched numpy array can be used as-is; splitting it\n                # into a list of per-example arrays is pure overhead and is very\n                # slow for large inputs (e.g. long audio).\n                processed_features[key] = [to_numpy(v) for v in value]\n\n        # Convert padding_strategy in PaddingStrategy\n        padding_strategy = self._get_padding_strategies(padding=padding, max_length=max_length)\n\n        required_input = processed_features[self.model_input_names[0]]\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/feature_extraction_sequence_utils.py#L146-L182","documentation":"When return_tensors is not given, the feature extractor infers the output format from the type of the first element of the required input. If that element is neither a torch tensor, python scalar/list/tuple, nor a numpy array, the type is unknown and conversion is refused with this ValueError.","triggerScenarios":"Feeding audio/features whose first element is an exotic type — e.g. a pandas Series, a jax array, a string, a TensorFlow tensor, or None — to a sequence feature extractor without specifying return_tensors.","commonSituations":"Loading audio via pandas/numpy-adjacent loaders that wrap arrays in containers; None entries from failed loads; passing already-batched nested structures with mixed types.","solutions":["Convert the input to a plain numpy array or list of floats before calling the feature extractor","Explicitly pass return_tensors='pt' (or 'np') so no inference from element type is needed","Check for None or empty values in the raw audio list and drop/fix them"],"exampleFix":"# before\nfe(series_from_pandas)  # pandas Series element\n\n# after\nfe(np.asarray(series_from_pandas, dtype=np.float32))","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef to_float_array(x):\n    if isinstance(x, (np.ndarray, list, tuple)) and not hasattr(x, \"to_numpy\"):\n        return x\n    return np.asarray(x, dtype=np.float32)","typeGuard":"def is_supported_element(x) -> bool:\n    import torch\n    return torch.is_tensor(x) or isinstance(x, (int, float, list, tuple, np.ndarray))","tryCatchPattern":"try:\n    fe(audio_list)\nexcept ValueError as e:\n    if \"type of\" in str(e) and \"unknown\" in str(e):\n        audio_list = [np.asarray(a, dtype=np.float32) for a in audio_list]\n        fe(audio_list)\n    else:\n        raise","preventionTips":["Normalize audio to np.float32 arrays at the pipeline boundary","Pass return_tensors explicitly to skip type inference","Guard against None entries from loaders"],"tags":["feature-extractor","dtype","audio","transformers"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}