pytorch - pytorch where is Embedding "max_norm" implemented?
问题描述
The "embedding" class documentation https://pytorch.org/docs/stable/nn.html says
max_norm (float, optional) – If given, will renormalize the embedding vectors to have a norm lesser than this before extracting.
1) In my model, I use this embedding class as a parameter, not just as an input (the model learns the embedding.) In this case, I assume every time when updates happen, the embedding gets renormalized, not only when it's initialized. Is my understanding correct?
2) I wanted to confirm 1) by looking at the source, but I couldn't find the implementation in pytorch embedding class. https://pytorch.org/docs/stable/_modules/torch/nn/modules/sparse.html
Can someone point me to the max_norm
implementation?
解决方案
如果您在此处forward
的 Embedding 类中看到函数,则有一个对torch.nn.functional.embedding的引用,它使用了此处的 cpp 文档中的 embedding_renorm_,这意味着它是一个 cpp 实现。在 pytorch repo 上的一些 github 搜索指向了这个文件(1、2)。
对 1 的回答是肯定的。2的答案如上。
推荐阅读
- javascript - 有没有办法可以根据用户活动(如评论)增加模型中的值?
- clang - 是否有任何关于 clang 源代码的文档?
- python - tensor.numpy() 在 tensorflow.data.Dataset 中不起作用。引发错误:AttributeError: 'Tensor' object has no attribute 'numpy'
- postgresql - 无法连接到 Postgresql
- python - 将多个字典组合到pyspark rdd中的另一个字典
- java - Google Calender API 用于请求其他用户的日历访问
- ios - 如何在 performSegue 的 sender 参数中传递闭包?
- symfony - 如何使用 form_widget 将字段的大小固定为 maxlength
- python - Rasterio rasterize 功能:无法插入正确的几何图形
- animation - 如何用动画翻译