Computes embeddings for the given ids and weights. This op assumes that there is at least one id for each row in the dense tensor represented by sp_ids (i.e. there are no rows with empty features), and that all the indices of sp_ids are in canonical row-major order. It also assumes that all
(params,
sp_ids,
sp_weights,
combiner=None,
max_norm=None,
name=None)
| 836 | |
| 837 | @tf_export("nn.embedding_lookup_sparse", v1=[]) |
| 838 | def embedding_lookup_sparse_v2(params, |
| 839 | sp_ids, |
| 840 | sp_weights, |
| 841 | combiner=None, |
| 842 | max_norm=None, |
| 843 | name=None): |
| 844 | """Computes embeddings for the given ids and weights. |
| 845 | This op assumes that there is at least one id for each row in the dense tensor |
| 846 | represented by sp_ids (i.e. there are no rows with empty features), and that |
| 847 | all the indices of sp_ids are in canonical row-major order. |
| 848 | It also assumes that all id values lie in the range [0, p0), where p0 |
| 849 | is the sum of the size of params along dimension 0. |
| 850 | Args: |
| 851 | params: A single tensor representing the complete embedding tensor, or a |
| 852 | list of P tensors all of same shape except for the first dimension, |
| 853 | representing sharded embedding tensors. Alternatively, a |
| 854 | `PartitionedVariable`, created by partitioning along dimension 0. Each |
| 855 | element must be appropriately sized for ``"div"`` `partition_strategy`. |
| 856 | sp_ids: N x M `SparseTensor` of int64 ids where N is typically batch size |
| 857 | and M is arbitrary. |
| 858 | sp_weights: either a `SparseTensor` of float / double weights, or `None` to |
| 859 | indicate all weights should be taken to be 1. If specified, `sp_weights` |
| 860 | must have exactly the same shape and indices as `sp_ids`. |
| 861 | combiner: A string specifying the reduction op. Currently "mean", "sqrtn", |
| 862 | "tile" and "sum" are supported. "sum" computes the weighted sum of the |
| 863 | embedding results for each row. "mean" is the weighted sum divided by the |
| 864 | total weight. "sqrtn" is the weighted sum divided by the square root of the |
| 865 | sum of the squares of the weights. |
| 866 | max_norm: If not `None`, each embedding is clipped if its l2-norm is larger |
| 867 | than this value, before combining. |
| 868 | name: Optional name for the op. |
| 869 | Returns: |
| 870 | A dense tensor representing the combined embeddings for the |
| 871 | sparse ids. For each row in the dense tensor represented by `sp_ids`, the op |
| 872 | looks up the embeddings for all ids in that row, multiplies them by the |
| 873 | corresponding weight, and combines these embeddings as specified. |
| 874 | In other words, if |
| 875 | `shape(combined params) = [p0, p1, ..., pm]` |
| 876 | and |
| 877 | `shape(sp_ids) = shape(sp_weights) = [d0, d1, ..., dn]` |
| 878 | then |
| 879 | `shape(output) = [d0, d1, ..., dn-1, p1, ..., pm]`. |
| 880 | For instance, if params is a 10x20 matrix, and sp_ids / sp_weights are |
| 881 | ```python |
| 882 | [0, 0]: id 1, weight 2.0 |
| 883 | [0, 1]: id 3, weight 0.5 |
| 884 | [1, 0]: id 0, weight 1.0 |
| 885 | [2, 3]: id 1, weight 3.0 |
| 886 | ``` |
| 887 | with `combiner`="mean", then the output will be a 3x20 matrix where |
| 888 | ```python |
| 889 | output[0, :] = (params[1, :] * 2.0 + params[3, :] * 0.5) / (2.0 + 0.5) |
| 890 | output[1, :] = (params[0, :] * 1.0) / 1.0 |
| 891 | output[2, :] = (params[1, :] * 3.0) / 3.0 |
| 892 | ``` |
| 893 | Raises: |
| 894 | TypeError: If `sp_ids` is not a `SparseTensor`, or if `sp_weights` is |
| 895 | neither `None` nor `SparseTensor`. |
nothing calls this directly
no test coverage detected