chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

電子發(fā)燒友App

硬聲App

掃碼添加小助手

加入工程師交流群

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示
創(chuàng)作
電子發(fā)燒友網(wǎng)>電子資料下載>電子資料>PyTorch教程10.6之編碼器-解碼器架構(gòu)

PyTorch教程10.6之編碼器-解碼器架構(gòu)

2023-06-05 | pdf | 0.11 MB | 次下載 | 免費(fèi)

資料介紹

在一般的 seq2seq 問題中,如機(jī)器翻譯(第 10.5 節(jié)),輸入和輸出的長度不同且未對(duì)齊。處理這類數(shù)據(jù)的標(biāo)準(zhǔn)方法是設(shè)計(jì)一個(gè)編碼器-解碼器架構(gòu)(圖 10.6.1),它由兩個(gè)主要組件組成:一個(gè) 編碼器,它以可變長度序列作為輸入,以及一個(gè) 解碼器,作為一個(gè)條件語言模型,接收編碼輸入和目標(biāo)序列的向左上下文,并預(yù)測目標(biāo)序列中的后續(xù)標(biāo)記。

../_images/編碼器解碼器.svg

圖 10.6.1編碼器-解碼器架構(gòu)。

讓我們以從英語到法語的機(jī)器翻譯為例。給定一個(gè)英文輸入序列:“They”、“are”、“watching”、“.”,這種編碼器-解碼器架構(gòu)首先將可變長度輸入編碼為一個(gè)狀態(tài),然后對(duì)該狀態(tài)進(jìn)行解碼以生成翻譯后的序列,token通過標(biāo)記,作為輸出:“Ils”、“regardent”、“.”。由于編碼器-解碼器架構(gòu)構(gòu)成了后續(xù)章節(jié)中不同 seq2seq 模型的基礎(chǔ),因此本節(jié)將此架構(gòu)轉(zhuǎn)換為稍后將實(shí)現(xiàn)的接口。

from torch import nn
from d2l import torch as d2l
from mxnet.gluon import nn
from d2l import mxnet as d2l
from flax import linen as nn
from d2l import jax as d2l
No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
import tensorflow as tf
from d2l import tensorflow as d2l

10.6.1。編碼器

在編碼器接口中,我們只是指定編碼器將可變長度序列作為輸入X。實(shí)現(xiàn)將由繼承此基類的任何模型提供Encoder。

class Encoder(nn.Module): #@save
  """The base encoder interface for the encoder-decoder architecture."""
  def __init__(self):
    super().__init__()

  # Later there can be additional arguments (e.g., length excluding padding)
  def forward(self, X, *args):
    raise NotImplementedError
class Encoder(nn.Block): #@save
  """The base encoder interface for the encoder-decoder architecture."""
  def __init__(self):
    super().__init__()

  # Later there can be additional arguments (e.g., length excluding padding)
  def forward(self, X, *args):
    raise NotImplementedError
class Encoder(nn.Module): #@save
  """The base encoder interface for the encoder-decoder architecture."""
  def setup(self):
    raise NotImplementedError

  # Later there can be additional arguments (e.g., length excluding padding)
  def __call__(self, X, *args):
    raise NotImplementedError
class Encoder(tf.keras.layers.Layer): #@save
  """The base encoder interface for the encoder-decoder architecture."""
  def __init__(self):
    super().__init__()

  # Later there can be additional arguments (e.g., length excluding padding)
  def call(self, X, *args):
    raise NotImplementedError

10.6.2。解碼器

在下面的解碼器接口中,我們添加了一個(gè)額外的init_state 方法來將編碼器輸出 ( enc_all_outputs) 轉(zhuǎn)換為編碼狀態(tài)。請(qǐng)注意,此步驟可能需要額外的輸入,例如輸入的有效長度,這在 第 10.5 節(jié)中有解釋。為了逐個(gè)令牌生成可變長度序列令牌,每次解碼器都可以將輸入(例如,在先前時(shí)間步生成的令牌)和編碼狀態(tài)映射到當(dāng)前時(shí)間步的輸出令牌。

class Decoder(nn.Module): #@save
  """The base decoder interface for the encoder-decoder architecture."""
  def __init__(self):
    super().__init__()

  # Later there can be additional arguments (e.g., length excluding padding)
  def init_state(self, enc_all_outputs, *args):
    raise NotImplementedError

  def forward(self, X, state):
    raise NotImplementedError
class Decoder(nn.Block): #@save
  """The base decoder interface for the encoder-decoder architecture."""
  def __init__(self):
    super().__init__()

  # Later there can be additional arguments (e.g., length excluding padding)
  def init_state(self, enc_all_outputs, *args):
    raise NotImplementedError

  def forward(self, X, state):
    raise NotImplementedError
class Decoder(nn.Module): #@save
  """The base decoder interface for the encoder-decoder architecture."""
  def setup(self):
    raise NotImplementedError

  # Later there can be additional arguments (e.g., length excluding padding)
  def init_state(self, enc_all_outputs, *args):
    raise NotImplementedError

  def __call__(self, X, state):
    raise NotImplementedError
class Decoder(tf.keras.layers.Layer): #@save
  """The base decoder interface for the encoder-decoder architecture."""
  def __init__(self):
    super().__init__()

  # Later there can be additional arguments (e.g., length excluding padding)
  def init_state(self, enc_all_outputs, *args):
    raise NotImplementedError

  def call(self, X, state):
    raise NotImplementedError

10.6.3。將編碼器和解碼器放在一起

在前向傳播中,編碼器的輸出用于產(chǎn)生編碼狀態(tài),解碼器將進(jìn)一步使用該狀態(tài)作為其輸入之一。

class EncoderDecoder(d2l.Classifier): #@save
  """The base class for the encoder-decoder architecture."""
  def __init__(self, encoder, decoder):
    super().__init__()
    self.encoder = encoder
    self.decoder = decoder

  def forward(self, enc_X, dec_X, *args):
    enc_all_outputs = self.encoder(enc_X, *args)
    dec_state = self.decoder.init_state(enc_all_outputs, *args)
    # Return decoder output only
    return self.decoder(dec_X, dec_state)[0]
class EncoderDecoder(d2l.Classifier): #@save
  """The base class for the encoder-decoder architecture."""
  def __init__(self, encoder, decoder):
    super().__init__()
    self.encoder = encoder
    self.decoder = decoder

  def forward(self, enc_X, dec_X, *args):
    enc_all_outputs = self.encoder(enc_X, *args)
    dec_state = self.decoder.init_state(enc_all_outputs, *args)
    # Return decoder output only
    return self.decoder(dec_X, dec_state)[0]
class EncoderDecoder(d2l.Classifier): #@save
  """The base class for the encoder-decoder architecture."""
  encoder: nn.Module
  decoder: nn.Module
  training: bool

  def __call__(self, enc_X, dec_X, *args):
    enc_all_outputs = self.encoder(enc_X, *args, training=self.training)
    dec_state = self.decoder.init_state(enc_all_outputs, *args)
    # Return decoder output only
    return self.decoder(dec_X, dec_state, training=self.training)[0]
class EncoderDecoder(d2l.Classifier): #@save
  """The base class for the encoder-decoder architecture."""
  def __init__(self, encoder, decoder):
    super().__init__()
    self.encoder = encoder
    self.decoder = decoder

  def call(self, enc_X, dec_X, *args):
    enc_all_outputs = self.encoder(enc_X, *args, training=True)
    dec_state = self.decoder.init_state(enc_all_outputs, *args)
    # Return decoder output only
    return self.decoder(dec_X, dec_state, training=True)[0]

在下一節(jié)中,我們將看到如何應(yīng)用 RNN 來設(shè)計(jì)基于這種編碼器-解碼器架構(gòu)的 seq2seq 模型。

10.6.4。概括

編碼器-解碼器架構(gòu)可以處理由可變長度序列組成的輸入和輸出,因此適用于機(jī)器翻譯等 seq2seq 問題。編碼器將可變長度序列作為輸入,并將其轉(zhuǎn)換為具有固定形狀的狀態(tài)。解碼器將固定形狀的編碼狀態(tài)映射到可變長度序列。

10.6.5。練習(xí)

  1. 假設(shè)我們使用神經(jīng)網(wǎng)絡(luò)來實(shí)現(xiàn)編碼器-解碼器架構(gòu)。編碼器和解碼器必須是同一類型的神經(jīng)網(wǎng)絡(luò)嗎?

  2. 除了機(jī)器翻譯,你能想到另一個(gè)可以應(yīng)用編碼器-解碼器架構(gòu)的應(yīng)用程序嗎?

解碼器 編碼器 pytorch
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評(píng)論

查看更多

下載排行

本周

  1. 11節(jié)電池用電池保護(hù)IC S-8261D系列數(shù)據(jù)手冊
  2. 3.07 MB   |  1次下載  |  1 積分
  3. 2PT8P2107 觸控 IO 型 8-Bit MCU規(guī)格書
  4. 3.73 MB   |  次下載  |  免費(fèi)
  5. 3PT8P2309 觸控 A/D 型 8-Bit MCU規(guī)格書
  6. 4.05 MB   |  次下載  |  免費(fèi)
  7. 4氮化鎵GaN FET/GaN HEMT 功率驅(qū)動(dòng)電路選型表
  8. 0.10 MB   |  次下載  |  免費(fèi)
  9. 5AU-48雙麥多功能語音處理模組規(guī)格書(5)
  10. 2.24 MB  |  次下載  |  免費(fèi)
  11. 6WX-0813_AI_ENC語音處理模組規(guī)格書
  12. 907.46 KB  |  次下載  |  免費(fèi)
  13. 7電子管膽機(jī)中文資料
  14. 0.03 MB   |  次下載  |  1 積分
  15. 8ESI Allegro XP 大尺寸MLCC測試分選機(jī)規(guī)格書
  16. 0.66 MB   |  次下載  |  免費(fèi)

本月

  1. 1美的電磁爐電路原理圖資料
  2. 4.39 MB   |  20次下載  |  10 積分
  3. 2反激式開關(guān)電源設(shè)計(jì)解析
  4. 0.89 MB   |  14次下載  |  5 積分
  5. 3耗盡型MOS FET產(chǎn)品目錄選型表
  6. 0.14 MB   |  3次下載  |  免費(fèi)
  7. 4簡易光伏控制器原理圖資料
  8. 0.07 MB   |  1次下載  |  5 積分
  9. 5FP7135V060-G1/FP7125替代物料pin to pin
  10. 495.40 KB  |  1次下載  |  免費(fèi)
  11. 62EDL05x06xx系列 600V半橋門驅(qū)動(dòng)器帶集成自舉二極管(BSD)手冊
  12. 0.69 MB   |  1次下載  |  免費(fèi)
  13. 7TI系列-米爾TI AM62L核心板開發(fā)板-高能效低功耗嵌入式平臺(tái)
  14. 1.51 MB  |  1次下載  |  免費(fèi)
  15. 81節(jié)電池用電池保護(hù)IC S-8261D系列數(shù)據(jù)手冊
  16. 3.07 MB   |  1次下載  |  1 積分

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935137次下載  |  10 積分
  3. 2開源硬件-PMP21529.1-4 開關(guān)降壓/升壓雙向直流/直流轉(zhuǎn)換器 PCB layout 設(shè)計(jì)
  4. 1.48MB  |  420064次下載  |  10 積分
  5. 3Altium DXP2002下載入口
  6. 未知  |  233095次下載  |  10 積分
  7. 4電路仿真軟件multisim 10.0免費(fèi)下載
  8. 340992  |  191457次下載  |  10 積分
  9. 5十天學(xué)會(huì)AVR單片機(jī)與C語言視頻教程 下載
  10. 158M  |  183360次下載  |  10 積分
  11. 6labview8.5下載
  12. 未知  |  81605次下載  |  10 積分
  13. 7Keil工具M(jìn)DK-Arm免費(fèi)下載
  14. 0.02 MB  |  73831次下載  |  10 積分
  15. 8LabVIEW 8.6下載
  16. 未知  |  65991次下載  |  10 積分