Using CSV data as input to recommender

Open
#315 2 comments 0 reactions 1 assignee View on GitHub

@maciejkula is already working on this.

Since Jun 17, 2021.

Assessment

This issue has not been assessed yet.

Description

question

I'm trying to replicate the quick start recommender with some csv data, and using the pandas read_csv operation.

Reading the csv data works and I can inspect it, e.g.

my_file_train = pd.read_csv("my_file.csv",header=0)

and I can view the .head() the data appears as expected. The type of the my_file_train is

<class 'pandas.core.frame.DataFrame'>

Following the approach taken in https://stackoverflow.com/questions/58362316/how-do-i-go-from-pandas-dataframe-to-tensorflow-batchdataset-for-nlp I can get a DataSet from the Panda DataFrame

training_dataset = (
    tf.data.Dataset.from_tensor_slices(
        (
            tf.cast(my_file_train['feature1'].values, tf.string),
            tf.cast(my_file_train['user_id'].values, tf.int64)
        )
    )
)

The type of training_datasetis:

<class 'tensorflow.python.data.ops.dataset_ops.TensorSliceDataset'>

but so then I try to build vocabularies as in the example, where we see code like this:

user_ids_vocabulary = tf.keras.layers.experimental.preprocessing.StringLookup(mask_token=None)
user_ids_vocabulary.adapt(ratings.map(lambda x: x["user_id"]))

and I had thought that I could do something similar like this:

user_ids_vocabulary = tf.keras.layers.experimental.preprocessing.StringLookup(mask_token=None)
user_ids_vocabulary.adapt(training_dataset.map(lambda x: x[1]))

since the DataSet I have is tuples rather than a dictionary, but I get the following error:

TypeError: () takes 1 positional argument but 2 were given

which probably just exposes that I'm taking completely the wrong approach somewhere, but I'd be very grateful if anyone could set me on track.

Would it be simpler to create my own tfds dataset a la https://www.tensorflow.org/datasets/add_dataset rather than converting it on the fly? or is there some thing simple that I'm missing in terms of the manipulation that I'm trying to do?

Dominant language
Python
Stars
2k
Forks
300
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tensorflow/recommenders

All issues in tensorflow/recommenders

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.