词嵌入矩阵,可以加载使用word2vector,glove

API

CLASS torch.nn.Embedding(num_embeddings: int, embedding_dim: int, padding_idx: Optional[int] = None, max_norm: Optional[float] = None, norm_type: float = 2.0, scale_grad_by_freq: bool = False, sparse: bool = False, _weight: Optional[torch.Tensor] = None)
参数 描述
num_embeddings (int) size of the dictionary of embeddings
embedding_dim (int) the size of each embedding vector
padding_idx (int, optional) If given, pads the output with the embedding vector at padding_idx (initialized to zeros) whenever it encounters the index.
max_norm (float, optional) If given, each embedding vector with norm larger than max_norm is renormalized to have norm max_norm.
norm_type (float, optional) The p of the p-norm to compute for the max_norm option. Default 2.
scale_grad_by_freq (boolean, optional) If given, this will scale gradients by the inverse of frequency of the words in the mini-batch. Default False.
sparse (bool, optional) If True, gradient w.r.t. weight matrix will be a sparse tensor. See Notes for more details regarding sparse gradients.
>>> # an Embedding module containing 10 tensors of size 3
>>> embedding = nn.Embedding(10, 3) # 10表示有10个词,3表示3个维度
>>> # a batch of 2 samples of 4 indices each
>>> input = torch.LongTensor([[1,2,4,5],[4,3,2,9]])
>>> embedding(input)
tensor([[[-0.0251, -1.6902,  0.7172],[-0.6431,  0.0748,  0.6969],[ 1.4970,  1.3448, -0.9685],[-0.3677, -2.7265, -0.1685]],[[ 1.4970,  1.3448, -0.9685],[ 0.4362, -0.4004,  0.9400],[-0.6431,  0.0748,  0.6969],[ 0.9124, -2.3616,  1.1151]]])

参考:
https://pytorch.org/docs/master/generated/torch.nn.Embedding.html?highlight=nn%20embedding#torch.nn.Embedding
https://www.cnblogs.com/lindaxin/p/7991436.html

pytorch torch.nn.Embedding相关推荐

  1. 【Pytorch基础教程28】浅谈torch.nn.embedding

    学习总结 文章目录 学习总结 一.nn.Embedding 二.代码栗子 2.1 通过embedding降维 2.2 RNN中用embedding改进 2.3 deepFM模型中embedding R ...

  2. torch.nn.Embedding理解

    Pytorch官网的解释是:一个保存了固定字典和大小的简单查找表.这个模块常用来保存词嵌入和用下标检索它们.模块的输入是一个下标的列表,输出是对应的词嵌入. torch.nn.Embedding(nu ...

  3. torch.nn.Embedding()的固定化

    问题 最近在运行模型时,结果不稳定,所以尝试修改随机初始化的参数,使参数是随机初始化的,但是每次都一样 发现是用了 self.embed_user = nn.Embedding(user_num, f ...

  4. pytorch中nn.Embedding和nn.LSTM和nn.Linear

    使用pytorch实现一个LSTM网络很简单,最基本的有三个要素:nn.Embedding, nn.LSTM, nn.Linear 基本框架为: class LSTMModel(nn.Module): ...

  5. torch.nn.Embedding的使用

    torch.nn.Embedding 在使用pytorch进行词嵌入使用torch.nn.Embedding()就可以做到 nn.Embedding在pytoch中的解释 class torch.nn ...

  6. torch.nn.Embedding()中的padding_idx参数解读

    torch.nn.Embedding() Word Embedding 词嵌入,就是把一个词典,随机初始化映射为一个向量矩阵. 列如:有一组词典,有两个词"hello"和" ...

  7. 什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用

    文章目录 使embedding空前流行的word2vec 句子的表达 训练样本 损失函数 输入向量表达和输出向量表达vwv_{w}vw​ 从word2vec到item2vec 讨论环节 pytorch ...

  8. 模型的第一层:详解torch.nn.Embedding和torch.nn.Linear

    文章目录 1.概述 2.Embedding 2.1 nn.Linear 2.2 nn.Embedding 对比 初始化第一层 1.概述 torch.nn.Embedding是用来将一个数字变成一个指定 ...

  9. PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx

    PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx 在写 PyTorch 代码时,我们会发现在 torch.nn.xxx 和 torch.nn.funct ...

最新文章

  1. 支持百万级TPS,Kafka是怎么做到的?答案藏在这10张图里
  2. 过分了,又双叒叕吃狗粮:因为爱情,才有思科
  3. 自学python能赚钱吗-学习Python多久能找到工作?老男孩Python开发培训
  4. 在CentOS6.8下安装Docker
  5. 初次转化max模型为3D Tiles失败、cesium加载一个obj格式的3D 机房模型
  6. mybatis-一对一的关联查询有两种配置方式
  7. Maven学习笔记(待完善)
  8. Centos7 使用Docker 部署Nginx+mysql+tomcat+调试联通_03
  9. pytesseract识别数字
  10. ROS 机器人操作系统:版本说明
  11. 黑月教主工具脱水印_PS三种去水印方法简单粗暴!看完你就学会!
  12. 3、switch -项目7-定期存款利息计算器
  13. android反编译脱壳,Android脱壳圣战之---如何脱掉爱加密家的保护壳
  14. 空间|时间|对象 圈人 + 目标人群透视 - 暨PostgreSQL 10与Greenplum的对比和选择
  15. 【微信小程序】wx.request请求后success回调的数据无法显示到页面上
  16. 微信公众号如何进行账号迁移?
  17. 【List】个人 常用学习工作软件清单
  18. 每日一问。2015.1.8
  19. 一支笔的测试点_给你一支笔,如何测试
  20. 鞍山市2021中高考成绩查询,2021年鞍山高中学校排名及录取分数线排名

热门文章

  1. python的运行环境是如何搭建的_教女朋友学Python运行环境搭建
  2. python开发人员看什么书_python初学者看什么书
  3. python自动翻译pdf_python实现从pdf文件中提取文本,并自动翻译的方法
  4. sql limit不接具体数字_SQL汇总函数和分组函数
  5. “Python字符串index()方法应用案例”文末三道思考题答案
  6. Python在线考试系统防作弊功能的思路和实现
  7. 力扣40. 组合总和 II(JavaScript)
  8. 力扣347. 前 K 个高频元素(JavaScript,堆)
  9. mysql5.6 排序失效_mysql 使用union(all) + order by 导致排序失效
  10. 苹果6s最大屏幕尺寸_iPhone 6s:经典的小屏旗舰,百元价位也能做苹果党