-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add create LoDTensor from list option and simplify recommender book example #10946
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
isthe 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.