transformer 翻譯,transformer是什么意思,transformer中文翻譯,transformer發(fā)音、用法及例句
?transformer
transformer發(fā)音
英:[tr?ns?f?:m?(r)] 美:[tr?ns?f?rm?]
英: 美:
transformer中文意思翻譯
n. 變壓器
transformer詞形變化
動(dòng)詞過(guò)去分詞: transformed | 動(dòng)詞第三人稱(chēng)單數: transforms | 形容詞: transformable | 動(dòng)詞現在分詞: transforming | 動(dòng)詞過(guò)去式: transformed |
transformer常見(jiàn)例句
1 、With rich transformer design experience.───具有豐富變壓器設計經(jīng)驗。
2 、To get there, all you have to do is transform.─── 只要變形你就能回到真實(shí)世界
3 、A transformer supplying auxiliaries of a power station.───向電站的輔助設備供電的變壓器。
4 、With a gentle twist, a button can define, unite, and transform.───只要溫柔地搓一搓,一個(gè)鈕扣就能自我定義,團結一體,或者改頭換面。
5 、Yeah, thank you. And do you have a transformer for shaver? My husband's doesn't work without that.───好的,謝謝。另外,你們有用于剃須刀的變壓器嗎?我丈夫的壞了。
6 、A little paint will soon transform this old car .───只要噴上一點(diǎn)油漆就會(huì )馬上使這部舊車(chē)變個(gè)模樣。
7 、Certain granular solids transform into highly mobile slurries.───一定數量的粒狀固體就可以變成非常易流動(dòng)的泥漿。
8 、The thermometer of main transformer is damaged. Loco19.We changed it.───19號的點(diǎn)接式溫度計壞。已經(jīng)更換。
9 、Can you transform this five-yuan note into five one-yuan notes?───你能把這五元錢(qián)換成五個(gè)一元的嗎?
10 、And the age of the transformers is over.─── 變形金剛的時(shí)代已經(jīng)結束了
11 、The substation equipped with a transformer of 500 KVA is at the south of the plant.───在工程的南邊有一座裝有五百千伏安變電器的變電站。
12 、And that, too, has transformed the landscape.─── 這一因素對情勢的轉變也有影響
13 、Comparison of two grounding methods for 330 kV transformer neutral point.───中性點(diǎn)直接接地330kV變壓器中性點(diǎn)兩種接地方式比較。
14 、Today we will transform animal into water goblet.───今天我們來(lái)學(xué)習把動(dòng)物變成高腳杯。
15 、This is a transformer, and this is a gobot.─── 這是變形金剛 這是百變雄師
16 、How can an acorn transform itself into an oak tree?───一個(gè)橡子怎樣能把它自己轉變成一棵櫟樹(shù)?
17 、Bachelor degree or with more transformer design experience.───大學(xué)本科學(xué)歷或具有較多變壓器設計經(jīng)驗的人員。
18 、DJL offers ballast and transformer for both fixture and portable lamp use.───在美國擁有成熟完善的銷(xiāo)售網(wǎng)絡(luò )并設有銷(xiāo)售中心及倉庫。
19 、Only transformer coupling can contribute to the voltage gain of an amplifier by virtue of a stepup turns ratio.───只有放大器耦合方能通過(guò)開(kāi)壓匝數比提高變壓器電壓增益。
20 、In order to transform them, we must first unite with them.───為了改造,先要團結。
21 、A current is induced in the secondary of the transformer.───二級變壓器產(chǎn)生電流。
22 、Keep away from the transformer.───不要靠近那個(gè)變壓器。
23 、A variac and transformer, at far right, supply high voltage for the modulator.───為調制器提供高電壓的一臺自耦變壓器和一臺變壓器在右邊遠處。
24 、The Clean Data transformer operates on specified data columns of the source table that your step accesses.───Clean Data轉換器操作源表中步驟所訪(fǎng)問(wèn)的特定數據列。
25 、A guard spots Nina leaving the transformer room, and she shoots him.───一個(gè)警衛在尼娜離開(kāi)配電室時(shí)發(fā)現了她,尼娜射殺了他。
26 、Single DC welding transformer thyistor panel with water saver system.───單相直流焊機用變壓器可控硅柜,帶有節水系統
27 、A linear differential transformer has three coils.───一個(gè)直線(xiàn)差動(dòng)變壓器有三個(gè)線(xiàn)圈。
28 、Why Do They Fail To Transform?───為什么他們會(huì )變革失敗?
29 、Professional Produce:Different Types Of Ballast Transformer And Lights.───專(zhuān)業(yè)生產(chǎn)照明電器類(lèi)產(chǎn)品:電子、電感或變壓器、燈具等。
30 、Its moving iron core transformer structure is most widely used.───動(dòng)鐵芯式變壓器結構,應用最廣。
31 、The transformer simply plugs into a mains socket.───變壓器只是簡(jiǎn)單**在電源**座中。
32 、The transformer isolates the transistors with regard to d-c bias voltage.───變壓器可在兩個(gè)晶體管之間隔離直流偏壓。
33 、A little paint will soon transform the old house.───刷一點(diǎn)油漆很快就會(huì )使這所舊房子大為改觀(guān)。
34 、A Fourier transform does this, but with waves.───傅立葉變化就是這樣,但是它是按照波的情況。
35 、New to create a new transformer service.───以創(chuàng )建新的轉換器服務(wù)。
36 、Company's transformer business will benefit from the UHV.───公司變壓器業(yè)務(wù)將受益于特高壓。
37 、In an ideal amplifier, the final stage tube acts as a signal source and the output transformer acts as a load.───在一個(gè)理想放大器,最后階段管作為信號源和輸出變壓器的負載。
38 、Draw the Transformer Substation and Concentrate the Monitiring System in the.───儀器儀表。電氣化鐵道牽引變電所集中監控系統。
39 、Obvious effect on degraded insulating oil treatment, field transformer oil treatment when machine electrified.───處理劣化變質(zhì)的絕緣油效果明顯,可現場(chǎng)帶電處理各種牌號的變壓器油。
40 、For general insulation and protection for appliance, wire harness, transformer, lead wire of motors, etc.───一般應用于電器、線(xiàn)束、變壓器、馬達引線(xiàn)等絕緣和保護。
41 、Did you check the transformer?───你檢查了變壓器沒(méi)有?
42 、You were transformed, and transformations can be reversed.─── 你是被轉化為死亡騎士的 既是轉化 就也能逆轉
43 、Present Situation of Transformer Trade and Its Trend.───變壓器行業(yè)現狀與發(fā)展動(dòng)向。
44 、The transformer winding should be impregnated with insulation paint and baked.───變壓器繞組要用絕緣漆浸透并烘干。
45 、Dongfeng Pointing to a Million Transform of Commercial Vehicle Co.───東風(fēng)劍指百萬(wàn)商用車(chē)公司轉型。
46 、To alter in form or nature; transform.───在性質(zhì)或形式上的改變;變形
47 、The sun transform the gild cupola into dazzling point of light.───太陽(yáng)將這些鍍金的圓屋頂變成了閃耀的光點(diǎn)。
48 、Application of PLC and Frequency Transformer to TV Studio Technology.───PLC以及變頻器在電視演播工藝中的應用。
49 、A minimum of 3 years relevant design experiences in Lan transformer field.───3年以上網(wǎng)絡(luò )變壓器開(kāi)發(fā)經(jīng)驗,能獨立開(kāi)發(fā)新產(chǎn)品優(yōu)先。
50 、If the filament transformer has a center tap, don't use it.───如果變壓器燈絲繞組有抽頭,請不要使用它。
51 、Any pin type of transformer and relay can adjust exactly.───任何不同的變壓器或繼電器的焊錫引腳可以被精確的調整設定。
52 、A little paint will transform this old car.───噴點(diǎn)漆就能讓這輛舊車(chē)變個(gè)模樣。
53 、This apparentlysimple function of the transformer makes it as vital to modern industry as the gear train.───變壓器的這種顯而易見(jiàn)的基本功能使其與齒輪裝置一樣,對現代工業(yè)至關(guān)重要。
54 、Discussion on the Economic Operation of the Main Transformer in Dongqing Co.───東輕公司主變壓器經(jīng)濟運行探討。
55 、And then when I transformed, I didn't know where I was.─── 但是當我變形完 我就不知道自己在哪里了
56 、A loud bang. An electric power transformer exploded. No light until dawn.───大聲轟隆。壞電變壓器。沒(méi)有光直到黎明。
57 、Let's go to transform the mud to PEM system.───去將本段泥漿轉化成PEM泥漿體系。
58 、But then that applause is transforming into bigger applause, and then that bigger applause is transforming into standing ovation.─── 后來(lái)掌聲越來(lái)越大 如同雷鳴一般 再后來(lái)觀(guān)眾們越來(lái)越激動(dòng) 他們紛紛起立鼓掌
59 、There is 220 kilovolt transformer substation inside the county 2, ..───縣內有220千伏變電站二座,...
60 、A transformer provides no power of its own.───變壓器本身不產(chǎn)生電力。
61 、Insulation on transformer cover and partition.───可用于電壓器的覆蓋和隔層不導電用途。
62 、Cursed to transform into a beast at night.───夜幕降臨變身為野獸的詛咒。
63 、So an EI-frame transformer is always better than a toroidal transformer?───因此,一依愛(ài)框架變壓器總比一環(huán)形變壓器?
64 、He is a transformer of human flesh; a creator of monsters.───他能改造人類(lèi)的形狀,他是魔鬼的制造者。
65 、There is messtin in transformer.───變壓器里有飯盒。
66 、To make or transform into a single unit.───使變成一個(gè)單位
67 、There was an error while deleting the color transform.───在刪除該顏色傳輸時(shí)有一個(gè)錯誤。
68 、His words and actions must transform our lives.───他說(shuō)的話(huà)和他的行為必定改變我們的生活。
69 、He bound to you, and you transformed.─── 他附在你身上 然后你就變身了
70 、The transformer is more expensive than the toy train.───變形金剛比玩具火車(chē)貴得多。
71 、But this would hardly “transform” Sudan.───但是這樣做很難”改變”蘇丹。
72 、NINGBO TIANYUAN POWER TRANSFORMER CO., LTD.───寧波天元電力變壓器有限公司。
73 、Company main products: Voltage stabilizer , high low pressure transformer , reactance implement.───公司主要產(chǎn)品:穩壓器、高低壓變壓器、電抗器。
74 、You are about to have a very transformative experience.─── 你就要經(jīng)歷一場(chǎng)顛覆性的體驗
75 、To transform a metal into a mineral by oxidation.───使礦化通過(guò)氧化使金屬轉化為一種無(wú)機物
76 、The damaged windings of(the transformer)should be rewound.───壞了的(變壓器)線(xiàn)圈應當重繞。
77 、He knew that he could not transform society by one bugle blast.───他知道,改造社會(huì )不能一蹴而就。
78 、The copper and iron lost of transformer, motor and generator cause temperature rise.───變壓器馬達及發(fā)電機等的銅損、鐵損增加而過(guò)溫。
79 、AC source is a better alternative to isolation transformer + variac.───交流源可以更好的代替變隔離壓器+調壓器。
80 、With cigar lighter device and transformer of any car.───可配置汽車(chē)點(diǎn)煙器及變壓器。
81 、So we are all capable of transforming our world.─── 所以我們所有人都能改變我們的世界
82 、This provides reference to transformer DC resistance test.───為變壓器直流電阻試驗提供借鑒。
83 、The tinning process of dry type current transformer is Electroplate Technology.───傳統干式電流互感器的鍍錫工藝是采用槽鍍鍍錫技術(shù)。
84 、Design and Analysis of Pulse Transformer in Forward Converter.───單端正激式脈沖變壓器的分析與設計。
85 、Open tender for purchasing power transformer.───公開(kāi)招標購買(mǎi)電力運輸設備。
86 、Under certain conditions we can transform the bad into the good.───在一定條件下,我們能把壞事變成好事。
87 、Click Browse to locate the transform you want to use.───單擊“瀏覽”以查找您要使用的轉換。
88 、Professional Produce: Different Types Of Ballast Transformer And Lights.───專(zhuān)業(yè)生產(chǎn)照明電器類(lèi)產(chǎn)品:電子、感或變壓器、具等。
89 、The process by which the transformer is enabled to draw the requisite amount of power is as follows.───使變壓器能夠從電源輸入必要數量的功率的過(guò)程如下。
90 、The damaged windings of the transformer should be rewound.───壞了的變壓器線(xiàn)圈應當重繞。
為什么說(shuō)Transformer的注意力機制是相對廉價(jià)的注意力機制相對更對于RNN系列及CNN系列算法有何優(yōu)勢
基于注意力機制的構造與基于RNN的不同,基于RNN的是在時(shí)間步上串聯(lián)(在每個(gè)time step只能輸入一個(gè)token),而基于注意力機制的是類(lèi)似于桶狀結構(一起將數據輸入到模型中去)
為什么說(shuō)Transformer的注意力機制是相對廉價(jià)的注意力機制相對更對于RNN系列及CNN系列算法有何優(yōu)勢
QA形式對自然語(yǔ)言處理中注意力機制(Attention)進(jìn)行總結,并對Transformer進(jìn)行深入解析。
二、Transformer(Attention Is All You Need)詳解
1、Transformer的整體架構是怎樣的?由哪些部分組成?
2、Transformer Encoder 與 Transformer Decoder 有哪些不同?
3、Encoder-Decoder attention 與self-attention mechanism有哪些不同?
4、multi-head self-attention mechanism具體的計算過(guò)程是怎樣的?
5、Transformer在GPT和Bert等詞向量預訓練模型中具體是怎么應用的?有什么變化?
一、Attention機制剖析
1、為什么要引入Attention機制?
根據通用近似定理,前饋網(wǎng)絡(luò )和循環(huán)網(wǎng)絡(luò )都有很強的能力。但為什么還要引入注意力機制呢?
計算能力的限制:當要記住很多“信息“,模型就要變得更復雜,然而目前計算能力依然是限制神經(jīng)網(wǎng)絡(luò )發(fā)展的瓶頸。
優(yōu)化算法的限制:雖然局部連接、權重共享以及pooling等優(yōu)化操作可以讓神經(jīng)網(wǎng)絡(luò )變得簡(jiǎn)單一些,有效緩解模型復雜度和表達能力之間的矛盾;但是,如循環(huán)神經(jīng)網(wǎng)絡(luò )中的長(cháng)距離以來(lái)問(wèn)題,信息“記憶”能力并不高。
可以借助人腦處理信息過(guò)載的方式,例如Attention機制可以提高神經(jīng)網(wǎng)絡(luò )處理信息的能力。
2、Attention機制有哪些?(怎么分類(lèi)?)
當用神經(jīng)網(wǎng)絡(luò )來(lái)處理大量的輸入信息時(shí),也可以借鑒人腦的注意力機制,只 選擇一些關(guān)鍵的信息輸入進(jìn)行處理,來(lái)提高神經(jīng)網(wǎng)絡(luò )的效率。按照認知神經(jīng)學(xué)中的注意力,可以總體上分為兩類(lèi):
聚焦式(focus)注意力:自上而下的有意識的注意力,主動(dòng)注意——是指有預定目的、依賴(lài)任務(wù)的、主動(dòng)有意識地聚焦于某一對象的注意力;
顯著(zhù)性(saliency-based)注意力:自下而上的有意識的注意力,被動(dòng)注意——基于顯著(zhù)性的注意力是由外界刺激驅動(dòng)的注意,不需要主動(dòng)干預,也和任務(wù)無(wú)關(guān);可以將max-pooling和門(mén)控(gating)機制來(lái)近似地看作是自下而上的基于顯著(zhù)性的注意力機制。
在人工神經(jīng)網(wǎng)絡(luò )中,注意力機制一般就特指聚焦式注意力。
3、Attention機制的計算流程是怎樣的?
Attention機制的實(shí)質(zhì):尋址(addressing)
Attention機制的實(shí)質(zhì)其實(shí)就是一個(gè)尋址(addressing)的過(guò)程,如上圖所示:給定一個(gè)和任務(wù)相關(guān)的查詢(xún)Query向量 q,通過(guò)計算與Key的注意力分布并附加在Value上,從而計算Attention Value,這個(gè)過(guò)程實(shí)際上是Attention機制緩解神經(jīng)網(wǎng)絡(luò )模型復雜度的體現:不需要將所有的N個(gè)輸入信息都輸入到神經(jīng)網(wǎng)絡(luò )進(jìn)行計算,只需要從X中選擇一些和任務(wù)相關(guān)的信息輸入給神經(jīng)網(wǎng)絡(luò )。
注意力機制可以分為三步:一是信息輸入;二是計算注意力分布α;三是根據注意力分布α 來(lái)計算輸入信息的加權平均。step1-信息輸入:用X = [x1, · · · , xN ]表示N 個(gè)輸入信息;
step2-注意力分布計算:令Key=Value=X,則可以給出注意力分布
我們將 稱(chēng)之為注意力分布(概率分布), 為注意力打分機制,有幾種打分機制:
step3-信息加權平均:注意力分布 可以解釋為在上下文查詢(xún)q時(shí),第i個(gè)信息受關(guān)注的程度,采用一種“軟性”的信息選擇機制對輸入信息X進(jìn)行編碼為:
這種編碼方式為軟性注意力機制(soft Attention),軟性注意力機制有兩種:普通模式(Key=Value=X)和鍵值對模式(Key!=Value)。
軟性注意力機制(soft Attention)
4、Attention機制的變種有哪些?
與普通的Attention機制(上圖左)相比,Attention機制有哪些變種呢?
變種1-硬性注意力:之前提到的注意力是軟性注意力,其選擇的信息是所有輸入信息在注意力 分布下的期望。還有一種注意力是只關(guān)注到某一個(gè)位置上的信息,叫做硬性注意力(hard attention)。硬性注意力有兩種實(shí)現方式:(1)一種是選取最高概率的輸入信息;(2)另一種硬性注意力可以通過(guò)在注意力分布式上隨機采樣的方式實(shí)現。硬性注意力模型的缺點(diǎn):
硬性注意力的一個(gè)缺點(diǎn)是基于最大采樣或隨機采樣的方式來(lái)選擇信息。因此最終的損失函數與注意力分布之間的函數關(guān)系不可導,因此無(wú)法使用在反向傳播算法進(jìn)行訓練。為了使用反向傳播算法,一般使用軟性注意力來(lái)代替硬性注意力。硬性注意力需要通過(guò)強化學(xué)習來(lái)進(jìn)行訓練?!渡窠?jīng)網(wǎng)絡(luò )與深度學(xué)習》變種2-鍵值對注意力:即上圖右邊的鍵值對模式,此時(shí)Key!=Value,注意力函數變?yōu)椋?/p>
變種3-多頭注意力:多頭注意力(multi-head attention)是利用多個(gè)查詢(xún)Q = [q1, · · · , qM],來(lái)平行地計算從輸入信息中選取多個(gè)信息。每個(gè)注意力關(guān)注輸入信息的不同部分,然后再進(jìn)行拼接:
5、一種強大的Attention機制:為什么自注意力模型(self-Attention model)在長(cháng)距離序列中如此強大?
(1)卷積或循環(huán)神經(jīng)網(wǎng)絡(luò )難道不能處理長(cháng)距離序列嗎?
當使用神經(jīng)網(wǎng)絡(luò )來(lái)處理一個(gè)變長(cháng)的向量序列時(shí),我們通??梢允褂镁矸e網(wǎng)絡(luò )或循環(huán)網(wǎng)絡(luò )進(jìn)行編碼來(lái)得到一個(gè)相同長(cháng)度的輸出向量序列,如圖所示:
基于卷積網(wǎng)絡(luò )和循環(huán)網(wǎng)絡(luò )的變長(cháng)序列編碼
從上圖可以看出,無(wú)論卷積還是循環(huán)神經(jīng)網(wǎng)絡(luò )其實(shí)都是對變長(cháng)序列的一種“局部編碼”:卷積神經(jīng)網(wǎng)絡(luò )顯然是基于N-gram的局部編碼;而對于循環(huán)神經(jīng)網(wǎng)絡(luò ),由于梯度消失等問(wèn)題也只能建立短距離依賴(lài)。
(2)要解決這種短距離依賴(lài)的“局部編碼”問(wèn)題,從而對輸入序列建立長(cháng)距離依賴(lài)關(guān)系,有哪些辦法呢?
如果要建立輸入序列之間的長(cháng)距離依賴(lài)關(guān)系,可以使用以下兩種方法:一 種方法是增加網(wǎng)絡(luò )的層數,通過(guò)一個(gè)深層網(wǎng)絡(luò )來(lái)獲取遠距離的信息交互,另一種方法是使用全連接網(wǎng)絡(luò )。 ——《神經(jīng)網(wǎng)絡(luò )與深度學(xué)習》全連接模型和自注意力模型:實(shí)線(xiàn)表示為可學(xué)習的權重,虛線(xiàn)表示動(dòng)態(tài)生成的權重。由上圖可以看出,全連接網(wǎng)絡(luò )雖然是一種非常直接的建模遠距離依賴(lài)的模型, 但是無(wú)法處理變長(cháng)的輸入序列。不同的輸入長(cháng)度,其連接權重的大小也是不同的。
這時(shí)我們就可以利用注意力機制來(lái)“動(dòng)態(tài)”地生成不同連接的權重,這就是自注意力模型(self-attention model)。由于自注意力模型的權重是動(dòng)態(tài)生成的,因此可以處理變長(cháng)的信息序列。
總體來(lái)說(shuō),為什么自注意力模型(self-Attention model)如此強大:利用注意力機制來(lái)“動(dòng)態(tài)”地生成不同連接的權重,從而處理變長(cháng)的信息序列。
(3)自注意力模型(self-Attention model)具體的計算流程是怎樣的呢?
同樣,給出信息輸入:用X = [x1, · · · , xN ]表示N 個(gè)輸入信息;通過(guò)線(xiàn)性變換得到為查詢(xún)向量序列,鍵向量序列和值向量序列:
上面的公式可以看出,self-Attention中的Q是對自身(self)輸入的變換,而在傳統的Attention中,Q來(lái)自于外部。
self-Attention計算過(guò)程剖解(來(lái)自《細講 | Attention Is All You Need 》)
注意力計算公式為:
自注意力模型(self-Attention model)中,通常使用縮放點(diǎn)積來(lái)作為注意力打分函數,輸出向量序列可以寫(xiě)為:
二、Transformer(Attention Is All You Need)詳解
從Transformer這篇論文的題目可以看出,Transformer的核心就是Attention,這也就是為什么本文會(huì )在剖析玩Attention機制之后會(huì )引出Transformer,如果對上面的Attention機制特別是自注意力模型(self-Attention model)理解后,Transformer就很容易理解了。
1、Transformer的整體架構是怎樣的?由哪些部分組成?
Transformer模型架構
Transformer其實(shí)這就是一個(gè)Seq2Seq模型,左邊一個(gè)encoder把輸入讀進(jìn)去,右邊一個(gè)decoder得到輸出:
Seq2Seq模型
Transformer=Transformer Encoder+Transformer Decoder
(1)Transformer Encoder(N=6層,每層包括2個(gè)sub-layers):
Transformer Encoder
sub-layer-1:multi-head self-attention mechanism,用來(lái)進(jìn)行self-attention。
sub-layer-2:Position-wise Feed-forward Networks,簡(jiǎn)單的全連接網(wǎng)絡(luò ),對每個(gè)position的向量分別進(jìn)行相同的操作,包括兩個(gè)線(xiàn)性變換和一個(gè)ReLU激活輸出(輸入輸出層的維度都為512,中間層為2048):
每個(gè)sub-layer都使用了殘差網(wǎng)絡(luò ):
(2)Transformer Decoder(N=6層,每層包括3個(gè)sub-layers):
Transformer Decoder
sub-layer-1:Masked multi-head self-attention mechanism,用來(lái)進(jìn)行self-attention,與Encoder不同:由于是序列生成過(guò)程,所以在時(shí)刻 i 的時(shí)候,大于 i 的時(shí)刻都沒(méi)有結果,只有小于 i 的時(shí)刻有結果,因此需要做Mask。
sub-layer-2:Position-wise Feed-forward Networks,同Encoder。
sub-layer-3:Encoder-Decoder attention計算。
2、Transformer Encoder 與 Transformer Decoder 有哪些不同?
(1)multi-head self-attention mechanism不同,Encoder中不需要使用Masked,而Decoder中需要使用Masked;
(2)Decoder中多了一層Encoder-Decoder attention,這與 self-attention mechanism不同。
3、Encoder-Decoder attention 與self-attention mechanism有哪些不同?
它們都是用了 multi-head計算,不過(guò)Encoder-Decoder attention采用傳統的attention機制,其中的Query是self-attention mechanism已經(jīng)計算出的上一時(shí)間i處的編碼值,Key和Value都是Encoder的輸出,這與self-attention mechanism不同。代碼中具體體現:
## Multihead Attention ( self-attention)self.dec = multihead_attention(queries=self.dec,
keys=self.dec,
num_units=hp.hidden_units,
num_heads=hp.num_heads,
dropout_rate=hp.dropout_rate,
is_training=is_training,
causality=True,
scope="self_attention")
## Multihead Attention ( Encoder-Decoder attention)
self.dec = multihead_attention(queries=self.dec,
keys=self.enc,
num_units=hp.hidden_units,
num_heads=hp.num_heads,
dropout_rate=hp.dropout_rate,
is_training=is_training,
causality=False,
scope="vanilla_attention")
4、multi-head self-attention mechanism具體的計算過(guò)程是怎樣的?
multi-head self-attention mechanism計算過(guò)程
Transformer中的Attention機制由Scaled Dot-Product Attention和Multi-Head Attention組成,上圖給出了整體流程。下面具體介紹各個(gè)環(huán)節:
Expand:實(shí)際上是經(jīng)過(guò)線(xiàn)性變換,生成Q、K、V三個(gè)向量;
Split heads: 進(jìn)行分頭操作,在原文中將原來(lái)每個(gè)位置512維度分成8個(gè)head,每個(gè)head維度變?yōu)?4;
Self Attention:對每個(gè)head進(jìn)行Self Attention,具體過(guò)程和第一部分介紹的一致;
Concat heads:對進(jìn)行完Self Attention每個(gè)head進(jìn)行拼接;
上述過(guò)程公式為:
5、Transformer在GPT和Bert等詞向量預訓練模型中具體是怎么應用的?有什么變化?
GPT中訓練的是單向語(yǔ)言模型,其實(shí)就是直接應用Transformer Decoder;
Bert中訓練的是雙向語(yǔ)言模型,應用了Transformer Encoder部分,不過(guò)在Encoder基礎上還做了Masked操作;
BERT Transformer 使用雙向self-attention,而GPT Transformer 使用受限制的self-attention,其中每個(gè)token只能處理其左側的上下文。雙向 Transformer 通常被稱(chēng)為“Transformer encoder”,而左側上下文被稱(chēng)為“Transformer decoder”,decoder是不能獲要預測的信息的。
版權聲明: 本站僅提供信息存儲空間服務(wù),旨在傳遞更多信息,不擁有所有權,不承擔相關(guān)法律責任,不代表本網(wǎng)贊同其觀(guān)點(diǎn)和對其真實(shí)性負責。如因作品內容、版權和其它問(wèn)題需要同本網(wǎng)聯(lián)系的,請發(fā)送郵件至 舉報,一經(jīng)查實(shí),本站將立刻刪除。