Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create LoDTensor from list option and simplify recommender book example #10946

Merged
merged 2 commits into from
May 25, 2018

Conversation

kexinzhao
Copy link
Contributor

@kexinzhao kexinzhao commented May 25, 2018

Please check #10735 for why we are doing this.

To solve the issue above, we have merged a PR #10817 and now there is utility functions here to create LoDTensor.

In this PR, we further enhance create_lod_tensor API so that user can create LoDTensor from a list of sequences of data as follows:

Use create_lod_tensor(data, lod, place) API to generate LoD Tensor,
where data is a list of sequences of index numbers, lod is
the level of detail (lod) info associated with data.
For example, data = [[10, 2, 3], [2, 3]] means that it contains
two sequences of indexes, of length 3 and 2, respectively.
Correspondingly, lod = [[3, 2]] contains one level of detail info,
indicating that data consists of two sequences of length 3 and 2.

Using this new option, we also simplify the recommender system book example.

@kexinzhao kexinzhao changed the title Add create LoDTensor from list option and modify recommender book example Add create LoDTensor from list option and simplify recommender book example May 25, 2018
Copy link
Contributor

@daming-lu daming-lu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny things. Can be modified in future PR as this one had already passed CI 😁

@@ -126,6 +126,18 @@ def create_lod_tensor(data, lod, place):
"""
if isinstance(data, core.LoDTensor):
return create_lod_tensor(np.array(data), lod, place)
elif isinstance(data, list):
# When input data is a list, it only deal with the case where the base element
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deals

category_id = create_lod_tensor([[10], [8], [9]], [[0, 3]])
movie_title = create_lod_tensor([[1069], [4140], [2923], [710], [988]],
[[0, 5]])
# Use the first data from paddle.dataset.movielens.test() as input.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are touching this inference, I raised an issue here, but it is not related to this PR 🤣

Copy link
Contributor

@sidgoyal78 sidgoyal78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kexinzhao kexinzhao merged commit c79ec9f into PaddlePaddle:develop May 25, 2018
@kexinzhao kexinzhao deleted the recommender_system_lod_fix branch May 25, 2018 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants