I have pyspark df like this:
id desc
1 abd hdbh jbj
2 sgjhd jhdgh gjhg
3 bvj hvhgvgh
4 jkjb bhj
Now I want to convert my desc column to vector so I'm using Google sentence encoder as udf, here's my code:
module_url = "https://tfhub.dev/google/universal-sentence-encoder/4"
model = hub.load(module_url)
def embedding(input):
return (model[input])
df.withColumn("Embedding", list(embedding(f.lit("desc"))))
Here's the error log:
ValueError Traceback (most recent call last)
/tmp/ipykernel_13810/1173342766.py in <module>
----> 1 df_shirt_sample.withColumn("Embedding", list(embedding(f.lit("desc"))))
/tmp/ipykernel_13810/446837446.py in embedding(input)
1 def embedding(input):
----> 2 return (model(input))
~/miniconda3/envs/dev_env_37/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in _call_attribute(instance, *args, **kwargs)
684
685 def _call_attribute(instance, *args, **kwargs):
--> 686 return instance.__call__(*args, **kwargs)
687
688
~/miniconda3/envs/dev_env_37/lib/python3.7/site-packages/tensorflow/python/util/traceback_utils.py in error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb
~/miniconda3/envs/dev_env_37/lib/python3.7/site-packages/tensorflow/python/eager/function_spec.py in _convert_inputs_to_signature(inputs, input_signature, flat_input_signature)
521 need_packing = True
522 except ValueError:
--> 523 raise ValueError("When input_signature is provided, all inputs to "
524 "the Python function must be convertible to "
525 "tensors:\n"
ValueError: When input_signature is provided, all inputs to the Python function must be convertible to tensors:
inputs: (
Column<b'desc'>)
input_signature: (
TensorSpec(shape=<unknown>, dtype=tf.string, name=None)).
Can someone tell me what I'm doing wrong