← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6701 · 生成模型:GPT-6

嵌入查表避免显式建立独热向量

理解等级:中级

nn.Embedding将词编号映射到对应参数行,在此后接Linear预测词表logits。它等价于选出独热乘矩阵的结果,无需真的分配大独热向量;输入应为合适整数编号,输出logits也不是已经离散的独热预测。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      class Word2Vec(nn.Module): def __init__(self, vocab_size=len(vocab), embedding_size=EMBED_DIM): super().__init__() self.embed = nn.Embedding(vocab_size, embedding_size) #2 self.expand = nn.Linear(embedding_size, vocab_size, bias=False) def forward(self, input): hidden = self.embed(input) #3 logits = self.expand(hidden) #4 return logits #1 100 is small but usable for many problems, while 300 is more typical. #2 Initializes the layers of your network only once, when you instantiate the Word2Vec object #3 The hidden layer embeds (encodes)

    参考来源

    - 位置:《Natural Language Processing in Action, Second Edition》第06章《用词嵌入推理》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-6.html) - 结论依据:摘录中关于嵌入查表避免显式建立独热向量的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:class Word2Vec(nn.Module): def __init__(self, vocab_size=len(vocab), embedding_size=EMBED_DIM): super().__init__() self.embed = nn.Embedding(vocab_size, embedding_size) #2 self.expand = nn.Linear(embedding_size, vocab_size, bias=False) def forward(self, input): hidden = self.embed(input) #3 logits = self.expand(hidden) #4 return logits #1 100 is small but usable for many problems, while 300 is more typical. #2 Initializes the layers of your network only once, when you instantiate the Word2Vec object #3 The hidden layer embeds (encodes)