nsl.lib.replicate_embeddings
Stay organized with collections
Save and categorize content based on your preferences.
Replicates the given embeddings
by replicate_times
.
nsl.lib.replicate_embeddings(
embeddings, replicate_times
)
This function is useful when comparing the same instance with multiple other
instances. For example, given a seed and its neighbors, this function can be
used to replicate the embeddings of the seed by the number of its neighbors,
such that the distances between the seed and its neighbors can be computed
efficiently.
The replicate_times
argument is either a scalar, or a 1-D tensor.
For example, if
embeddings = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
then we would have the following results for different replicate_times
arguments:
replicate_times = 2
result = [[0, 1, 2], [0, 1, 2], [3, 4, 5], [3, 4, 5], [6, 7, 8], [6, 7, 8]]
and
replicate_times = [3, 0, 1]
result = [[0, 1, 2], [0, 1, 2], [0, 1, 2], [6, 7, 8]]
Args |
embeddings
|
A Tensor of shape [batch_size, d1, ..., dN] .
|
replicate_times
|
An integer scalar or an integer 1-D Tensor of shape [batch
size] . Each element indicates the number of times the corresponding row
in embeddings should be replicated.
|
Returns |
A Tensor of shape [N, d1, ..., dN] , where N is the sum of all elements
in replicate_times .
|
Raises |
InvalidArgumentError
|
If any value in replicate_times is negative.
|
TypeError
|
If replicate_times contains any value that cannot be cast to
the int32 type.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-10-28 UTC.
[null,null,["Last updated 2022-10-28 UTC."],[],[],null,["# nsl.lib.replicate_embeddings\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/neural-structured-learning/blob/v1.4.0/neural_structured_learning/lib/utils.py#L345-L402) |\n\nReplicates the given `embeddings` by `replicate_times`. \n\n nsl.lib.replicate_embeddings(\n embeddings, replicate_times\n )\n\nThis function is useful when comparing the same instance with multiple other\ninstances. For example, given a seed and its neighbors, this function can be\nused to replicate the embeddings of the seed by the number of its neighbors,\nsuch that the distances between the seed and its neighbors can be computed\nefficiently.\n\nThe `replicate_times` argument is either a scalar, or a 1-D tensor.\nFor example, if \n\n embeddings = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]\n\nthen we would have the following results for different `replicate_times`\narguments: \n\n replicate_times = 2\n result = [[0, 1, 2], [0, 1, 2], [3, 4, 5], [3, 4, 5], [6, 7, 8], [6, 7, 8]]\n\nand \n\n replicate_times = [3, 0, 1]\n result = [[0, 1, 2], [0, 1, 2], [0, 1, 2], [6, 7, 8]]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `embeddings` | A Tensor of shape `[batch_size, d1, ..., dN]`. |\n| `replicate_times` | An integer scalar or an integer 1-D Tensor of shape `[batch size]`. Each element indicates the number of times the corresponding row in `embeddings` should be replicated. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A Tensor of shape `[N, d1, ..., dN]`, where `N` is the sum of all elements in `replicate_times`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|------------------------|----------------------------------------------------------------------------------|\n| `InvalidArgumentError` | If any value in `replicate_times` is negative. |\n| `TypeError` | If `replicate_times` contains any value that cannot be cast to the `int32` type. |\n\n\u003cbr /\u003e"]]