MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / embedding

Function embedding

imperative/python/megengine/functional/nn.py:1669–1693  ·  view source on GitHub ↗

r"""Applies lookup table for embedding. Args: inp: tensor with indices. weight: learnable weights which embeds from. padding_idx: should be set to None, not supported now. max_norm: should be set to None, not supported now. norm_type: should be set to Non

(
    inp: Tensor,
    weight: Tensor,
    padding_idx: Optional[int] = None,
    max_norm: Optional[float] = None,
    norm_type: Optional[float] = None,
)

Source from the content-addressed store, hash-verified

1667
1668
1669def embedding(
1670 inp: Tensor,
1671 weight: Tensor,
1672 padding_idx: Optional[int] = None,
1673 max_norm: Optional[float] = None,
1674 norm_type: Optional[float] = None,
1675):
1676 r"""Applies lookup table for embedding.
1677
1678 Args:
1679 inp: tensor with indices.
1680 weight: learnable weights which embeds from.
1681 padding_idx: should be set to None, not supported now.
1682 max_norm: should be set to None, not supported now.
1683 norm_type: should be set to None, not supported now.
1684
1685 Refer to :class:`~.module.Embedding` for more information.
1686 """
1687 if padding_idx is not None:
1688 raise ValueError("Not support padding_idx Now!")
1689 if max_norm is not None or norm_type is not None:
1690 raise ValueError("Not support weight normlization Now!")
1691
1692 dest_shp = list(inp.shape) + [weight.shape[-1]]
1693 return weight[inp.reshape(-1)].reshape(dest_shp)
1694
1695
1696def indexing_one_hot(

Callers

nothing calls this directly

Calls 2

listFunction · 0.85
reshapeMethod · 0.45

Tested by

no test coverage detected