title
stringclasses
312 values
author
stringclasses
138 values
date
stringclasses
263 values
local
stringclasses
312 values
tags
stringclasses
196 values
URL
stringclasses
312 values
chunk
stringlengths
7
30.6k
embedding
sequencelengths
768
768
How to train a new language model from scratch using Transformers and Tokenizers
julien-c
February 14, 2020
how-to-train
guide, nlp
https://huggingface.co/blog/how-to-train
5. Fine-tune your LM on a downstream task We now can fine-tune our new Esperanto language model on a downstream task of Part-of-speech tagging. As mentioned before, Esperanto is a highly regular language where word endings typically condition the grammatical part of speech. Using a dataset of annotated Esperanto POS tags formatted in the CoNLL-2003 format (see example below), we can use the run_ner.py script from transformers. > POS tagging is a token classification task just as NER so we can just use the exact same script. Again, here’s the hosted Tensorboard for this fine-tuning. We train for 3 epochs using a batch size of 64 per GPU. Training and eval losses converge to small residual values as the task is rather easy (the language is regular) – it’s still fun to be able to train it end-to-end 😃. This time, let’s use a TokenClassificationPipeline: python from transformers import TokenClassificationPipeline, pipeline MODEL_PATH = "./models/EsperBERTo-small-pos/" nlp = pipeline( "ner", model=MODEL_PATH, tokenizer=MODEL_PATH, ) # or instantiate a TokenClassificationPipeline directly. nlp("Mi estas viro kej estas tago varma.") # {'entity': 'PRON', 'score': 0.9979867339134216, 'word': ' Mi'} # {'entity': 'VERB', 'score': 0.9683094620704651, 'word': ' estas'} # {'entity': 'VERB', 'score': 0.9797462821006775, 'word': ' estas'} # {'entity': 'NOUN', 'score': 0.8509314060211182, 'word': ' tago'} # {'entity': 'ADJ', 'score': 0.9996201395988464, 'word': ' varma'} Looks like it worked! 🔥 For a more challenging dataset for NER, @stefan-it recommended that we could train on the silver standard dataset from WikiANN
[ 0.04526380077004433, -0.09483867138624191, -0.02273421175777912, 0.03288443014025688, 0.003405157942324877, 0.03935791924595833, 0.02155645750463009, 0.03341498225927353, -0.05484903231263161, 0.039321113377809525, -0.06631335616111755, 0.041409071534872055, 0.05469236150383949, 0.06749388575553894, 0.00996932853013277, 0.003890096675604582, 0.025895364582538605, 0.016932182013988495, -0.05455097183585167, -0.0219107698649168, 0.019420310854911804, -0.03325118124485016, 0.11226695030927658, 0.07474730908870697, -0.0015212252037599683, 0.00660736532881856, -0.03984419256448746, -0.023345105350017548, -0.11037860065698624, 0.023151328787207603, -0.06010782718658447, 0.022361021488904953, -0.038391295820474625, 0.05343924090266228, -0.02820380963385105, 0.038057807832956314, -0.059853266924619675, 0.020697910338640213, -0.017425552010536194, -0.0008092930074781179, -0.049042440950870514, 0.042946942150592804, -0.019161611795425415, 0.04476552456617355, 0.05936270207166672, -0.032621514052152634, -0.12204132974147797, -0.0032481225207448006, -0.016139289364218712, -0.04628874734044075, -0.05727452412247658, 0.06410359591245651, 0.06754785776138306, -0.046386297792196274, 0.004250484984368086, -0.0015681463992223144, 0.02736699767410755, -0.08427765220403671, -0.006573610007762909, 0.007103932090103626, 0.0010614162310957909, 0.01928306370973587, -0.060959041118621826, -0.019081871956586838, 0.01965886726975441, 0.010704058222472668, -0.10874523222446442, 0.021296488121151924, -0.061217475682497025, -0.04641370102763176, -0.002210984006524086, 0.006927173119038343, -0.026645855978131294, -0.03658146783709526, -0.03390445560216904, -0.07833194732666016, 0.01285665761679411, 0.020453356206417084, -0.01698085479438305, 0.06416849792003632, -0.009524531662464142, 0.052080921828746796, 0.03400091826915741, 0.06872094422578812, 0.08140718936920166, 0.07203363627195358, 0.07251451909542084, -0.041063860058784485, -0.031525444239377975, -0.019200176000595093, 0.0006903987377882004, -0.04827392101287842, -0.0335739403963089, 0.04425870254635811, 0.10163532197475433, 0.01693984493613243, -0.017979273572564125, 0.04740605875849724, -0.10872366279363632, -0.04736008122563362, 0.0351412408053875, -0.07238270342350006, 0.04907677322626114, -0.05984773486852646, -0.06915318965911865, 0.008157644420862198, 0.01621413417160511, -0.04033862426877022, -0.03639834001660347, 0.007850955240428448, -0.00952953938394785, 0.018353911116719246, 0.00039376100176014006, 0.1008780226111412, -0.05317983776330948, 0.012437359429895878, -0.03753912076354027, 0.03706446290016174, -0.05056991055607796, 0.014012514613568783, 0.0846274346113205, 0.07274290919303894, 0.060869742184877396, 0.007652408443391323, -0.015271766111254692, 0.05144397169351578, 0.03625986725091934, 0.048691459000110626, -0.02866022102534771, -0.0129301892593503, 0.031924840062856674, -0.0524807944893837, 0.0038702008314430714, 0.05782092735171318, -0.02760694921016693, -0.006344847846776247, 0.05488016456365585, -0.028137797489762306, 0.021636398509144783, -0.029750172048807144, -0.04103047028183937, 0.06341930478811264, -0.08981094509363174, -0.012454459443688393, 0.05215771496295929, -0.00821651704609394, 0.009814518503844738, 0.0653548538684845, 0.06947796046733856, 0.0666511058807373, 0.005417410749942064, 0.0768682211637497, -0.016050206497311592, -0.04911668971180916, 0.031143367290496826, 0.05715298652648926, -0.036877524107694626, -0.004159531556069851, -0.07533491402864456, 0.0023925662972033024, 0.003604130819439888, 0.03132030740380287, -0.019906790927052498, -0.003917589783668518, 0.02110673114657402, -0.05422790348529816, -0.01767336204648018, 0.02329169772565365, 0.00011966692545684054, 0.033722374588251114, 0.07547309994697571, -0.0065322439186275005, 0.07581494748592377, -0.027206938713788986, -0.021538179367780685, -0.0028640213422477245, 0.00065427809022367, 0.047989554703235626, -0.029381589964032173, -0.021268252283334732, -0.03819214180111885, 0.06760262697935104, -0.011793617159128189, 0.006636557634919882, 0.0009118503658100963, -0.08198710530996323, 0.03890009596943855, -0.05777357891201973, -0.03250937536358833, -0.013628611341118813, -0.023885296657681465, -0.012265725992619991, 0.07551657408475876, -0.0415593683719635, -0.02257830835878849, -0.032888609915971756, -0.012717495672404766, 0.045038267970085144, 0.03341333568096161, 0.020041657611727715, 0.048605985939502716, 0.0007994439802132547, -0.0064013004302978516, 0.013852446340024471, -0.022780777886509895, 0.020660720765590668, -0.018776927143335342, -0.09761325269937515, 0.021718423813581467, 0.03747706860303879, -0.0728587955236435, -0.08634588867425919, -0.004582579713314772, -0.0836777463555336, 0.0010238316608592868, -0.061896827071905136, -0.025909235700964928, 0.029752293601632118, 0.008990297093987465, -0.03969385847449303, 0.112530916929245, -0.0781489908695221, -0.031170854344964027, 0.011454480700194836, -0.007685475517064333, 0.005559003911912441, 0.06146899610757828, 0.03803527355194092, -0.007683190051466227, -0.05345350131392479, -0.02971985749900341, -0.06397280097007751, 0.02172277867794037, 0.015185040421783924, -0.05993356928229332, -0.05301298573613167, -0.025117196142673492, 0.010353690013289452, 0.02675662748515606, 0.007658056449145079, -0.028987953439354897, 0.0639231950044632, -0.06371202319860458, 0.07748117297887802, 0.015866314992308617, 0.014254122972488403, 0.1332578808069229, 0.0036516296677291393, -0.020495599135756493, 0.032958220690488815, -0.05055585503578186, 0.06575163453817368, 0.02549431100487709, -0.053132325410842896, -0.01958307810127735, -0.027464520186185837, -0.001536171999759972, 0.027934249490499496, 0.00602574460208416, 0.04030183330178261, 0.014745746739208698, 0.01318423543125391, -0.020498227328062057, -0.04826703667640686, 0.034377288073301315, -0.012619810178875923, 0.020416423678398132, -0.0017470918828621507, 0.0005612674867734313, -0.02736065723001957, -0.009912570007145405, -0.013346879743039608, -0.0006568495300598443, -0.0014150325441733003, 0.015581752173602581, 0.037734732031822205, 0.01823265291750431, -0.01163735892623663, -0.02497371844947338, -0.07851769030094147, -0.0001261831057490781, -0.04207736998796463, 0.05627681314945221, 0.04079039394855499, -0.01012365147471428, 0.02007210999727249, -0.03727157041430473, -0.03294205293059349, 0.006358853075653315, -0.004579452332109213, 0.020849650725722313, 0.010867440141737461, -0.03506315127015114, -0.03465196490287781, -0.0016608041478320956, 0.03188126161694527, 0.017594289034605026, -0.01756167970597744, 0.010081478394567966, 0.009116866625845432, -0.0483890026807785, -0.005771527532488108, 0.017110269516706467, -0.026331845670938492, -0.021649399772286415, -0.005332850385457277, 0.019479546695947647, 0.017847198992967606, -0.07683075219392776, -0.022405272349715233, -0.033057138323783875, 0.01840527169406414, 0.023925988003611565, -0.024429315701127052, 0.0021460875868797302, 0.04336189851164818, -0.02712828293442726, 0.016255265101790428, -0.02707860805094242, 0.03506685048341751, 0.026832519099116325, 0.027691541239619255, 0.021770382300019264, -0.04641076177358627, -0.005995872896164656, -0.04686472937464714, -0.006460866890847683, 0.002927997848019004, -0.00880496483296156, 0.040412262082099915, 0.015557389706373215, 0.06306691467761993, 0.008946878835558891, 0.046152811497449875, -0.026118578389286995, -0.00000951712172536645, -0.013296382501721382, 0.0070878262631595135, -0.026317939162254333, -0.015615335665643215, -0.017064379528164864, 0.027253085747361183, -0.01331003662198782, -0.015915514901280403, 0.03511540964245796, 0.00019752189109567553, 0.004203465301543474, 0.05172744393348694, 0.030863773077726364, -0.0010086280526593328, 0.014569425024092197, -0.004753194749355316, 0.0030116743873804808, -0.021710624918341637, -0.008718102239072323, -0.047629520297050476, 0.030352553352713585, -0.032345812767744064, 0.0044964952394366264, 0.006507880985736847, 0.008681206032633781, 0.06883850693702698, 0.002779668429866433, 0.0014720914186909795, 0.0067294202744960785, 0.001906133838929236, 0.020129060372710228, 0.007690914906561375, -0.04952368140220642, 0.03436116874217987, -0.011593624018132687, -0.03349553048610687, -0.039893168956041336, 0.07381253689527512, 0.006623208988457918, 0.033524587750434875, -0.044511131942272186, 0.02575039304792881, -0.002748400904238224, 0.030211523175239563, 0.0010624596616253257, -0.0069321999326348305, -0.02944125607609749, 0.005112620070576668, -0.012128644622862339, 0.029003893956542015, -0.0005205255001783371, 0.013954736292362213, -0.022317735478281975, 0.018318094313144684, -0.009800869040191174, -0.023259621113538742, 0.009112969972193241, -0.00009948754450306296, 0.021537238731980324, -0.032562270760536194, -0.019712720066308975, 0.01221265085041523, 0.019894901663064957, 0.02812672033905983, 0.010204793885350227, -0.01195130031555891, -0.010621906258165836, -0.014148994348943233, -0.020400524139404297, 0.01616540551185608, -0.00009349307219963521, -0.002785427263006568, -0.0043752905912697315, -0.051162704825401306, 0.05346359312534332, 0.01286301575601101, 0.01797730289399624, 0.037770144641399384, -0.01702108606696129, -0.005137606058269739, 0.00874226912856102, -0.02509361505508423, -0.010804124176502228, 0.030984535813331604, -0.014937630854547024, -0.015125110745429993, 0.004353766795247793, 0.04519237205386162, -0.02196834795176983, 0.018940569832921028, 0.030874039977788925, 0.009297634474933147, -0.034848663955926895, -0.020396914333105087, 0.05703679844737053, -0.040943168103694916, 0.060960493981838226, -0.014901416376233101, 0.028952203691005707, 0.05112103745341301, -0.008864146657288074, 0.009358520619571209, -0.03510868549346924, -0.012518324889242649, 0.06626586616039276, -0.0137416310608387, 0.03777550533413887, -0.019898077473044395, 0.006523245945572853, -0.019229194149374962, 0.0212083887308836, -0.00904929731041193, -0.004450744483619928, -0.006437288597226143, 0.019858993589878082, -0.024559056386351585, 0.03260015323758125, -0.009446685202419758, 0.00981760025024414, 0.009527215734124184, 0.015693284571170807, 0.036492038518190384, 0.058603398501873016, 0.009951278567314148, -0.016926605254411697, -0.031278133392333984, 0.014056909829378128, -0.021295325830578804, -0.03491165488958359, 0.0651862621307373, 0.03310307860374451, 0.05744316428899765, 0.013174649327993393, -0.010171527042984962, -0.019020486623048782, 0.02676413580775261, 0.03509160503745079, 0.00024251210561487824, -0.04010813310742378, -0.022381624206900597, -0.003619459457695484, -0.02095131389796734, 0.006395350210368633, 0.01093190349638462, 0.009268241003155708, -0.021108847111463547, -0.0044473265297710896, 0.004871878772974014, -0.02569522149860859, -0.019157202914357185, -0.03961586579680443, -0.0029576250817626715, 0.02614339254796505, 0.0011734804138541222, 0.029178036376833916, 0.022976156324148178, -0.018684202805161476, 0.02554849535226822, 0.012494564987719059, 0.02764039672911167, 0.0004165930731687695, 0.014804601669311523, -0.007142048794776201, -0.0071212477050721645, 0.0002741449570748955, 0.0065321531146764755, -0.007360030431300402, 0.03644980117678642, -0.02407425083220005, 0.021713105961680412, -0.08354343473911285, 0.006800665985792875, 0.021915849298238754, 0.023332813754677773, 0.026176346465945244, -0.02177467942237854, -0.005036219488829374, -0.01402189303189516, -0.01849413849413395, -0.03051835112273693, -0.03678120672702789, -0.06008785218000412, 0.029961224645376205, -0.005182017106562853, -0.015618955716490746, 0.003651154227554798, 0.013555396348237991, -0.0508866012096405, 0.004191738087683916, 0.00808722898364067, 0.01389589998871088, 0.06990648061037064, -0.011657103896141052, -0.03302549198269844, -0.0007789586088620126, 0.002364991931244731, -0.0033499589189887047, -0.044619087129831314, 0.04501746594905853, -0.005163026973605156, 0.00015491990779992193, 0.016509097069501877, -0.013822313398122787, -0.05080992728471756, 0.03211565315723419, 0.01583700254559517, 0.021627206355333328, -0.024450434371829033, -0.07762961089611053, 0.038322582840919495, 0.07549519091844559, 0.004954424686729908, 0.01786239817738533, -0.015449811704456806, -0.061167631298303604, -0.009430620819330215, -0.03319466486573219, 0.09353277087211609, 0.0042228237725794315, -0.009062138386070728, 0.0021583689376711845, 0.007311500608921051, 0.0403924398124218, -0.011789930984377861, -0.05101367458701134, 0.02603285387158394, -0.0014823107048869133, 0.012199698016047478, 0.026811186224222183, 0.019096868112683296, -0.01882730983197689, -0.013873650692403316, -0.008400266058743, -0.06253789365291595, 0.014129500836133957, 0.07054318487644196, -0.02663840726017952, 0.004415570292621851, 0.02015499398112297, -0.0385669581592083, 0.032746098935604095, 0.013434652239084244, 0.0007770180236548185, -0.04993868246674538, 0.0005883999983780086, -0.032315365970134735, 0.03582180291414261, -0.007290231063961983, -0.03089190647006035, 0.03157440572977066, -0.018468866124749184, 0.013257338665425777, 0.00819608848541975, -0.004754090681672096, 0.04708295315504074, 0.0031463601626455784, -0.004155577160418034, -0.00046874649706296623, 0.06293197721242905, 0.001412138226442039, 0.019398551434278488, -0.004909600596874952, -0.013618677854537964, 0.012369922362267971, -0.03356892988085747, -0.022345921024680138, -0.018197979778051376, -0.023563971742987633, 0.06827858090400696, -0.04496011883020401, -0.02531854808330536, -0.020949453115463257, 0.060776486992836, 0.00990345235913992, 0.030026772990822792, 0.002884381450712681, -0.02470322698354721, 0.023997727781534195, 0.04409051686525345, -0.02638653665781021, 0.03063625656068325, -0.00366820115596056, -0.027838027104735374, 0.007628527004271746, 0.005179265514016151, 0.057134851813316345, -0.005503334570676088, -0.019836535677313805, 0.010392733849585056, -0.073552206158638, -0.009188881143927574, 0.042249564081430435, 0.005202206317335367, -0.008253104984760284, 0.030879434198141098, 0.03495023772120476, -0.003227515146136284, 0.015306226909160614, -0.03058437816798687, -0.0037338638212531805, -0.028986286371946335, -0.005772260017693043, -0.04103861376643181, 0.03805117681622505, -0.016889015212655067, -0.06173122301697731, -0.08454413712024689, -0.010954782366752625, 0.035853926092386246, 0.01757274568080902, -0.027379848062992096, -0.012594706378877163, 0.005269356071949005, -0.038022857159376144, 0.011231094598770142, 0.03236355632543564, 0.019267937168478966, -0.05156964808702469, 0.0032808822579681873, 0.004130474291741848, -0.010984884575009346, 0.0312361940741539, -0.004541361704468727, -0.0011790948919951916, -0.05344035103917122, -0.010923569090664387, -0.0063018640503287315, -0.06399848312139511, 0.03236021101474762, -0.037461668252944946, -0.02621733583509922, 0.025585832074284554, -0.007379695773124695, 0.03909783810377121, 0.05952097102999687, -0.0400925911962986, 0.007547880057245493, -0.023785660043358803, 0.03588385507464409, -0.017588092014193535, 0.03938326612114906, 0.012915083207190037, 0.051711201667785645, -0.021436654031276703, -0.006246086675673723, -0.00146400963421911, 0.014104889705777168, 0.0037052587140351534, 0.023362798616290092, 0.025225814431905746, -0.025135565549135208, -0.04924675077199936, 0.0031816884875297546, 0.030245909467339516, 0.03731349855661392, 0.05529981106519699, -0.018455252051353455, -0.043297357857227325, 0.006307636387646198, -0.0251903235912323, -0.007822512648999691, 0.0012987593654543161, -0.02416546456515789, -0.03956056758761406, -0.02210518717765808, 0.02631339803338051, -0.04024644196033478, 0.011442865245044231, -0.059578437358140945, -0.016648966819047928, -0.06854449957609177, -0.0229453444480896, 0.0026307241059839725, 0.03397279977798462, 0.04835851863026619, 0.08399967849254608, 0.03867684304714203, 0.022136569023132324, 0.01723838597536087, -0.002323911990970373, -0.002106486586853862, 0.015241315588355064, 0.07888054847717285, -0.00812299083918333, -0.002082191174849868, -0.03545772656798363, 0.04152386635541916, -0.016767047345638275, -0.038443226367235184, -0.04149440675973892, 0.04078826680779457, 0.011647671461105347, 0.012851356528699398, 0.03513094410300255, 0.046040263026952744, -0.029446428641676903, -0.017272327095270157, 0.0517101064324379, 0.014618477784097195, 0.017547233030200005, 0.008724439889192581, -0.07291042804718018, -0.020986922085285187, -0.012579639442265034, -0.03328448161482811, 0.008791208267211914, 0.011765082366764545, 0.025071440264582634, 0.0036690805573016405, -0.01817493326961994, 0.00018086627824231982, -0.03335859626531601, 0.005011482164263725, -0.029350528493523598, 0.07148834317922592, 0.01601138710975647, 0.0007546854321844876, -0.02398008666932583, 0.06411125510931015, 0.031677305698394775, 0.019877731800079346, -0.025049708783626556, 0.007116083521395922, 0.031467095017433167, 0.005751192569732666, 0.0012251697480678558, 0.017550883814692497, 0.019916504621505737, 0.02456994168460369, -0.031845394521951675, -0.016679301857948303, -0.0049139573238790035 ]
How to train a new language model from scratch using Transformers and Tokenizers
julien-c
February 14, 2020
how-to-train
guide, nlp
https://huggingface.co/blog/how-to-train
# How to train a new language model from scratch using Transformers and Tokenizers Over the past few months, we made several improvements to our transformers and tokenizers libraries, with the goal of making it easier than ever to train a new language model from scratch. In this post we’ll demo how to train a “small” model (84 M parameters = 6 layers, 768 hidden size, 12 attention heads) – that’s the same number of layers & heads as DistilBERT – on Esperanto. We’ll then fine-tune the model on a downstream task of part-of-speech tagging. Esperanto is a constructed language with a goal of being easy to learn. We pick it for this demo for several reasons: - it is a relatively low-resource language (even though it’s spoken by ~2 million people) so this demo is less boring than training one more English model 😁 - its grammar is highly regular (e.g. all common nouns end in -o, all adjectives in -a) so we should get interesting linguistic results even on a small dataset. - finally, the overarching goal at the foundation of the language is to bring people closer (fostering world peace and international understanding) which one could argue is aligned with the goal of the NLP community 💚 > N.B. You won’t need to understand Esperanto to understand this post, but if you do want to learn it, Duolingo has a nice course with 280k active learners. Our model is going to be called… wait for it… EsperBERTo 😂
[ 0.04338841140270233, -0.04796644300222397, -0.038412559777498245, -0.007312643341720104, 0.019081884995102882, 0.08553280681371689, 0.006179140415042639, 0.02577647753059864, -0.03303997218608856, 0.04525212198495865, -0.02702436037361622, 0.09826286882162094, 0.004234003368765116, 0.03750742971897125, 0.038706645369529724, -0.009216772392392159, -0.013942236080765724, -0.016457220539450645, -0.03222062811255455, -0.04014122486114502, -0.04845020920038223, -0.05559512972831726, 0.06847731024026871, -0.027882596477866173, 0.04234683886170387, -0.021873334422707558, 0.07354090362787247, 0.010338564403355122, 0.014579225331544876, 0.04570741206407547, -0.08769015967845917, -0.0056107849813997746, -0.02139890566468239, -0.042838215827941895, -0.07042244076728821, 0.03521055355668068, -0.06313519179821014, 0.025889893993735313, 0.0014579857233911753, -0.032014504075050354, -0.030577650293707848, 0.049633461982011795, -0.026563206687569618, 0.043659958988428116, -0.005414654966443777, 0.004870716016739607, -0.15974287688732147, 0.039426930248737335, -0.06163305044174194, -0.07201141864061356, -0.06241748481988907, 0.01188551727682352, 0.0249446090310812, 0.0054186866618692875, -0.011276383884251118, -0.004168599843978882, 0.031949058175086975, -0.07967504113912582, -0.020656118169426918, 0.027196722105145454, 0.007656360976397991, 0.01289304718375206, -0.009240989573299885, -0.019222615286707878, 0.024312132969498634, -0.011925448663532734, -0.07665831595659256, 0.01910647377371788, -0.04593830555677414, -0.07320250570774078, 0.009292512200772762, -0.04303776100277901, -0.02791789546608925, -0.040446937084198, 0.0010184876155108213, -0.006983447354286909, 0.04967435821890831, 0.0392855741083622, 0.016327792778611183, 0.05951029062271118, -0.003930090926587582, 0.03821698576211929, 0.06178615614771843, 0.005807444918900728, 0.06348489969968796, 0.037640634924173355, 0.008985362015664577, -0.010171682573854923, -0.07935222238302231, 0.026856688782572746, -0.011659977026283741, -0.12965169548988342, -0.04658183082938194, 0.03203631564974785, 0.071725994348526, 0.013331633992493153, -0.0265923161059618, 0.053920261561870575, -0.028216104954481125, -0.03661877289414406, 0.007570162415504456, -0.02848018705844879, 0.0825250893831253, -0.0570971742272377, -0.03373650088906288, 0.003715884406119585, 0.01884135790169239, -0.043651457875967026, -0.012092049233615398, -0.01702364720404148, 0.007728848606348038, -0.06866709887981415, 0.029911665245890617, 0.08128523826599121, -0.095329649746418, 0.01876246929168701, 0.022387854754924774, 0.021274494007229805, -0.053694870322942734, 0.02728934772312641, 0.00550933089107275, 0.07267799973487854, 0.05567982420325279, 0.014533386565744877, -0.04336567968130112, 0.0917348712682724, 0.010043268091976643, 0.08480633050203323, -0.0021389226894825697, -0.00005316092574503273, 0.06481967866420746, -0.08623968064785004, 0.04768052324652672, -0.004701168276369572, 0.024542996659874916, 0.011835056357085705, 0.04659087210893631, -0.014108086936175823, 0.033221397548913956, -0.031255289912223816, -0.05417930334806442, 0.05467456206679344, -0.05851684510707855, -0.05931272730231285, 0.031476713716983795, 0.03233100846409798, -0.06969625502824783, 0.029801687225699425, 0.0611126534640789, 0.0559774674475193, -0.04187827557325363, 0.03075183928012848, -0.005437833722680807, -0.023178579285740852, 0.08629772812128067, 0.06020726263523102, -0.04590367525815964, -0.04541168734431267, -0.04573016241192818, -0.015697145834565163, -0.03648655489087105, 0.0011700077448040247, 0.01105302944779396, 0.05228029564023018, 0.0012325142743065953, -0.050089068710803986, -0.032444290816783905, 0.07437612116336823, 0.002748071448877454, 0.07849611341953278, 0.077915258705616, 0.020495988428592682, 0.037802837789058685, -0.02191435731947422, -0.036611221730709076, -0.026583842933177948, -0.023766351863741875, 0.016022419556975365, 0.027584563940763474, -0.017690513283014297, -0.026544637978076935, 0.050344835966825485, 0.0005948937032371759, 0.044726960361003876, 0.04049183428287506, -0.0821387842297554, 0.011373655870556831, -0.046892765909433365, -0.08223693817853928, 0.003244931111112237, 0.01782473735511303, 0.004311318974941969, 0.0615592822432518, -0.0034094862639904022, 0.018955960869789124, -0.050861287862062454, -0.029030904173851013, 0.08216430246829987, 0.013173084706068039, 0.11135753244161606, 0.030046649277210236, 0.03727461397647858, -0.013145389035344124, 0.011942422948777676, 0.028568411245942116, 0.00790650025010109, -0.016089914366602898, -0.03808611258864403, 0.028757670894265175, 0.00021199093316681683, -0.034086037427186966, -0.06866010278463364, 0.013898799195885658, -0.040485966950654984, 0.015962056815624237, -0.03685903921723366, 0.021982936188578606, 0.047847386449575424, 0.03734013810753822, -0.008847053162753582, 0.15475845336914062, -0.10010366886854172, -0.08703575283288956, 0.01783290132880211, -0.017102910205721855, 0.036835674196481705, 0.058426517993211746, -0.008695507422089577, 0.04442954063415527, -0.06741415709257126, -0.03498547896742821, -0.0750335156917572, -0.010152512229979038, -0.049366146326065063, -0.02960968390107155, -0.035611338913440704, -0.022585012018680573, 0.030390992760658264, 0.008062724024057388, -0.02978452481329441, -0.0419958233833313, 0.0025212792679667473, -0.03536317124962807, -0.0014725164510309696, 0.02108515240252018, 0.08891695737838745, 0.11673422157764435, 0.02769298665225506, 0.01054981630295515, 0.057414401322603226, -0.06723670661449432, 0.08193697780370712, 0.01983405463397503, -0.05928941071033478, 0.004914787597954273, 0.01530626229941845, 0.022393355146050453, -0.019697707146406174, 0.009268980473279953, -0.01361837051808834, -0.02975820191204548, 0.03412959724664688, -0.055080000311136246, -0.056699492037296295, -0.004977280739694834, -0.06668820977210999, -0.04909399524331093, 0.016577964648604393, 0.011017330922186375, -0.042690955102443695, -0.003602688666433096, -0.021761775016784668, 0.013390542939305305, -0.010027359239757061, 0.008433575741946697, 0.02515373006463051, 0.017383279278874397, -0.03325505182147026, -0.036902859807014465, -0.04545360431075096, -0.007035207003355026, -0.032829489558935165, 0.006894209887832403, 0.05079171806573868, -0.0062970626167953014, 0.015543662942945957, -0.024032849818468094, -0.02631400153040886, -0.019431261345744133, -0.0031519399490207434, -0.003919965121895075, 0.017064694315195084, -0.033075787127017975, -0.01387137919664383, -0.004063671920448542, 0.011137782596051693, 0.025584781542420387, -0.017740324139595032, 0.02282489836215973, -0.00026064549456350505, -0.01959500089287758, 0.012084762565791607, -0.010363265872001648, 0.00023396153119392693, -0.025756871327757835, -0.01313407439738512, 0.01713886484503746, 0.012360063381493092, -0.08109685033559799, -0.03113650158047676, -0.023749303072690964, -0.009591110982000828, 0.02567456290125847, -0.043040137737989426, 0.015483196824789047, 0.02138213813304901, -0.01774558052420616, -0.004031756427139044, -0.03506120666861534, -0.006942871492356062, -0.007633101660758257, 0.05817706882953644, -0.0000018813678934748168, -0.0489322803914547, -0.047318898141384125, -0.01658998802304268, 0.041723594069480896, 0.008317646570503712, -0.02368696965277195, 0.027573462575674057, 0.017135242000222206, 0.034902237355709076, 0.007731898687779903, -0.0009409635094925761, 0.029153529554605484, 0.017122311517596245, 0.039710525423288345, 0.02647448517382145, -0.024238046258687973, -0.010137980803847313, 0.005068587139248848, 0.03574593737721443, -0.029486624523997307, -0.0016496715834364295, 0.07031069695949554, 0.02148868329823017, 0.009135191328823566, 0.04062425717711449, 0.004033427219837904, -0.03385794907808304, 0.008762737736105919, -0.011858709156513214, 0.042228810489177704, -0.05078501999378204, -0.016207199543714523, -0.047113120555877686, 0.006429528351873159, -0.04629305377602577, 0.018349649384617805, -0.009244437329471111, 0.009825109504163265, 0.04341869801282883, 0.035881973803043365, -0.021341539919376373, 0.03564042970538139, 0.006069909781217575, 0.021666374057531357, -0.013673882931470871, -0.023875469341874123, 0.025613097473978996, -0.013395103625953197, -0.020990150049328804, -0.07208326458930969, 0.06587543338537216, 0.0019947246182709932, 0.04858095943927765, 0.0010547711281105876, 0.022143026813864708, -0.02494342438876629, 0.019155576825141907, 0.005665046628564596, -0.0034295269288122654, -0.013197572901844978, 0.008452648296952248, -0.006079443730413914, 0.005358402151614428, 0.05037054792046547, 0.04431019723415375, -0.019780054688453674, -0.03383265808224678, -0.03055708110332489, -0.010849134996533394, -0.0017650731606408954, -0.03054245188832283, 0.01966409757733345, -0.034846995025873184, 0.0009321596007794142, 0.009290454909205437, -0.001616933848708868, -0.0012145201908424497, -0.0045598517172038555, -0.004964790772646666, 0.024729110300540924, -0.024493372067809105, 0.000029846123652532697, -0.021026788279414177, 0.013066242448985577, -0.01556748989969492, 0.042360126972198486, -0.03001135215163231, 0.0020465622656047344, 0.025707151740789413, 0.013586233370006084, 0.046715524047613144, -0.02211657725274563, -0.03229004517197609, 0.0018639254849404097, 0.0016606705030426383, 0.011430884711444378, 0.028055179864168167, -0.014140256680548191, 0.010004578158259392, 0.005597265902906656, 0.03238081932067871, -0.018891416490077972, 0.0222234595566988, 0.017071740701794624, -0.01537119410932064, -0.013868576847016811, -0.005444209557026625, 0.03966216742992401, -0.014839604496955872, 0.038378600031137466, -0.021002061665058136, 0.0289206150919199, 0.056396979838609695, -0.008269097656011581, 0.027375908568501472, -0.015624670311808586, 0.004774462431669235, 0.052371904253959656, -0.002797971945255995, 0.0013843688648194075, 0.024526309221982956, -0.061025168746709824, 0.003931066021323204, 0.007544387131929398, 0.015585370361804962, -0.018391543999314308, -0.007343101780861616, 0.04625173285603523, -0.04870673641562462, 0.026285789906978607, -0.016265014186501503, -0.00778823159635067, -0.02955380082130432, 0.007709674071520567, 0.012835207395255566, 0.04131672531366348, 0.015483608469367027, -0.03650607913732529, -0.018473563715815544, -0.009302998892962933, -0.01615159772336483, 0.0051505593582987785, 0.035878170281648636, 0.013538958504796028, 0.015835460275411606, -0.033617351204156876, 0.027554871514439583, -0.032681629061698914, 0.021868081763386726, 0.06806280463933945, -0.016312414780259132, -0.03631415590643883, -0.030362294986844063, -0.012795413844287395, -0.0014784263912588358, -0.007500643841922283, -0.02549007162451744, 0.012965202331542969, 0.006709490902721882, 0.007880293764173985, 0.03318687155842781, 0.00029442249797284603, 0.005068864673376083, -0.053716082125902176, 0.021798904985189438, -0.02883855253458023, 0.005832066293805838, -0.01721186190843582, -0.003949194215238094, -0.0085537014529109, 0.027955172583460808, 0.04437101259827614, 0.036380887031555176, 0.003303159959614277, 0.003848043270409107, -0.024303914979100227, -0.008387258276343346, 0.033541787415742874, 0.02726706676185131, -0.019613493233919144, -0.026835091412067413, -0.03016417659819126, 0.0014207997592166066, -0.07619232684373856, 0.006810122635215521, 0.01366710476577282, 0.03349869325757027, 0.020107705146074295, -0.0019898065365850925, 0.024685971438884735, 0.027036583051085472, -0.01162607129663229, -0.05142849311232567, -0.021879035979509354, -0.06981045752763748, -0.02092667669057846, -0.004862604197114706, 0.004977896343916655, -0.026685362681746483, -0.02302209846675396, -0.047893766313791275, 0.009811876341700554, -0.014014274813234806, 0.0230800099670887, 0.0249883271753788, -0.008050856180489063, -0.027190906926989555, -0.02030562423169613, 0.0010618082014843822, 0.04211178049445152, -0.02962188608944416, 0.018743323162198067, 0.05811294913291931, -0.005994122941046953, -0.011781688779592514, -0.001627109362743795, -0.008301781490445137, 0.021175118163228035, 0.04654667526483536, -0.014893054962158203, -0.049080997705459595, -0.04430529475212097, -0.009310220368206501, 0.06125404313206673, -0.002070216229185462, -0.0008075432269833982, 0.015392179600894451, -0.05601072683930397, 0.01820804551243782, -0.05697285383939743, 0.0575869083404541, 0.025235336273908615, -0.04120353236794472, 0.008446109481155872, 0.017611542716622353, 0.026222918182611465, -0.03244579955935478, -0.021757284179329872, 0.031723752617836, 0.02604888193309307, 0.05382392928004265, 0.029308533295989037, 0.01661306992173195, -0.02612977847456932, 0.008049996569752693, 0.031297553330659866, -0.045830029994249344, 0.05069851130247116, 0.03505377471446991, -0.021949181333184242, -0.008772521279752254, 0.018532611429691315, -0.024707689881324768, -0.004836808890104294, 0.025657543912529945, 0.035424765199422836, -0.017094340175390244, -0.033844299614429474, -0.006446606479585171, -0.028847143054008484, -0.03462885692715645, 0.0158428605645895, 0.07367566972970963, 0.0005728924297727644, 0.06488820910453796, 0.013958204537630081, -0.00617822352796793, 0.06768765300512314, 0.016037341207265854, -0.026687102392315865, 0.039261139929294586, 0.006681183818727732, 0.039299145340919495, -0.005480627063661814, -0.004677462857216597, 0.002263728529214859, -0.02160762809216976, -0.00815785862505436, -0.005301570985466242, -0.03525378555059433, 0.027373064309358597, 0.043197404593229294, -0.04774468392133713, -0.030239665880799294, -0.0035048157442361116, 0.05303461104631424, 0.03371727839112282, 0.05243806168437004, -0.021966267377138138, 0.033993180841207504, 0.04553142562508583, 0.05121490731835365, -0.007328971289098263, 0.058244530111551285, 0.01907414384186268, -0.02387423813343048, 0.003917033784091473, 0.05176369100809097, 0.030380617827177048, 0.004594630561769009, 0.022203419357538223, 0.049381472170352936, -0.06467967480421066, -0.04631248116493225, 0.008210621774196625, -0.009936954826116562, -0.009936126880347729, 0.020659606903791428, 0.007747166324406862, -0.043079160153865814, 0.018698664382100105, -0.04557289183139801, -0.02933838777244091, -0.042627546936273575, -0.04469313472509384, -0.03557625040411949, 0.04533996060490608, -0.025198260322213173, -0.052461132407188416, -0.03715487942099571, -0.011255982331931591, 0.01604742370545864, -0.022196149453520775, -0.000026311696274206042, -0.010554761625826359, 0.005340565927326679, 0.0031620461959391832, -0.00381335592828691, 0.010199091397225857, 0.01874397136271, -0.08293966203927994, 0.0371452271938324, -0.005675094202160835, 0.010917534120380878, 0.029484618455171585, -0.0009385189623571932, 0.010175789706408978, -0.04795914515852928, 0.010435717180371284, -0.010620750486850739, -0.036832597106695175, 0.013648506253957748, -0.054393183439970016, -0.012693527154624462, -0.0006007957272231579, 0.0359816774725914, 0.02518950216472149, 0.09262938797473907, 0.0008330395794473588, -0.039649415761232376, 0.03081611543893814, 0.01598166860640049, 0.013918905518949032, 0.03382066637277603, 0.0008558431873098016, 0.012105661444365978, 0.01037740707397461, -0.017129074782133102, -0.02209349535405636, -0.009840143844485283, 0.022538652643561363, 0.005321193020790815, 0.017385289072990417, -0.03773112595081329, -0.01716548390686512, -0.013644995167851448, 0.02310596965253353, -0.013015829026699066, 0.07008165121078491, 0.017955442890524864, 0.0035392800346016884, -0.0067517017014324665, 0.03443419933319092, -0.0210188627243042, -0.015092563815414906, -0.023906132206320763, -0.0498775988817215, -0.008291543461382389, 0.0338156521320343, 0.009591732174158096, 0.03761858493089676, -0.055032502859830856, -0.023601191118359566, -0.09270285815000534, -0.012065940536558628, -0.008548417128622532, 0.010488823987543583, 0.049200352281332016, 0.0037401493173092604, 0.02789296954870224, 0.01703794114291668, -0.014071058481931686, -0.008030609227716923, -0.0225982628762722, 0.02453485131263733, 0.0860007032752037, -0.015393764711916447, -0.011126412078738213, 0.02034885622560978, -0.010722831822931767, -0.007795029319822788, -0.03147722780704498, -0.03317790478467941, -0.020264409482479095, 0.014996208250522614, 0.005106636323034763, 0.03557968512177467, -0.010916792787611485, -0.019585927948355675, -0.016947804018855095, 0.018597694113850594, 0.014110910706222057, 0.025649873539805412, -0.012329863384366035, -0.04044388234615326, -0.007320327218621969, 0.011013328097760677, 0.010501745156943798, 0.036404386162757874, 0.03281141072511673, 0.027703696861863136, 0.01656048744916916, -0.01499518845230341, 0.01876079849898815, 0.03892005607485771, 0.002556494204327464, -0.023995043709874153, 0.044474419206380844, 0.03699369356036186, 0.0019130390137434006, 0.020522188395261765, 0.04989925026893616, 0.04752805083990097, 0.023466527462005615, -0.039836667478084564, 0.008972314186394215, 0.014722791500389576, 0.016568902879953384, 0.010614664293825626, -0.016450554132461548, 0.01704130321741104, -0.015142728574573994, -0.04432200267910957, -0.045641638338565826, 0.001290410989895463 ]
How to train a new language model from scratch using Transformers and Tokenizers
julien-c
February 14, 2020
how-to-train
guide, nlp
https://huggingface.co/blog/how-to-train
TADA! ➡️ Your model has a page on https://huggingface.co/models and everyone can load it using AutoModel.from_pretrained("username/model_name"). If you want to take a look at models in different languages, check https://huggingface.co/models
[ 0.055580127984285355, -0.022484255954623222, 0.025987068191170692, -0.024185150861740112, 0.07237397879362106, 0.06770715862512589, 0.05365786328911781, 0.060510728508234024, -0.05999663472175598, -0.005906953476369381, -0.09811072051525116, 0.040375933051109314, -0.006699665915220976, 0.03351078927516937, -0.010016709566116333, -0.06214548274874687, 0.02247346006333828, -0.019217848777770996, 0.008079318329691887, 0.008390339091420174, -0.012014434672892094, -0.05594554543495178, 0.0374327078461647, -0.032795511186122894, -0.04772522300481796, -0.05408110097050667, 0.06449185311794281, 0.05214574187994003, -0.001518944394774735, -0.0022633038461208344, -0.10365453362464905, -0.017714036628603935, 0.017978327348828316, -0.02675248123705387, -0.011031990870833397, 0.04363469034433365, -0.11972932517528534, 0.03897429257631302, 0.03149927034974098, -0.056941501796245575, -0.03017113357782364, -0.013571077026426792, -0.050435151904821396, 0.08129856735467911, 0.01052361074835062, -0.04983679577708244, -0.21195779740810394, 0.06902433186769485, 0.002813815837725997, -0.02233099937438965, -0.04841519892215729, 0.03250914067029953, -0.005963105708360672, 0.0011788582196459174, 0.015519428066909313, -0.025296496227383614, -0.008466728031635284, -0.05024648830294609, 0.012514655478298664, -0.05251414328813553, 0.08384085446596146, 0.09973005205392838, -0.012006747536361217, 0.038976553827524185, 0.037617407739162445, 0.04261854663491249, -0.008410275913774967, -0.026204301044344902, -0.020332949236035347, -0.03950807824730873, 0.022319506853818893, -0.06047254055738449, 0.0074270605109632015, -0.0702020525932312, -0.012767990119755268, -0.04457942396402359, -0.026906460523605347, 0.03968115150928497, 0.0212537981569767, 0.026017678901553154, 0.03400944173336029, 0.01690889149904251, 0.021458784118294716, 0.08813035488128662, 0.04514097422361374, 0.02181398682296276, 0.011984343640506268, -0.024263951927423477, -0.021319597959518433, 0.0379316546022892, -0.016015736386179924, -0.12072567641735077, -0.010435410775244236, -0.027134830132126808, 0.07200256735086441, -0.03755083307623863, 0.041836757212877274, 0.043537721037864685, 0.003958906512707472, -0.014875402674078941, -0.03572818264365196, -0.03803640231490135, 0.007685176096856594, -0.04858437925577164, -0.029215501621365547, 0.009658647701144218, -0.016338041052222252, -0.08452592045068741, -0.025716429576277733, -0.000338059791829437, 0.0003496856370475143, -0.05244363471865654, -0.007353258319199085, 0.026445744559168816, -0.08233796060085297, 0.04183705896139145, 0.007939240895211697, -0.009459538385272026, 0.03362838551402092, 0.019157271832227707, 0.01527820061892271, 0.0738847553730011, 0.01288150530308485, 0.023206323385238647, 0.06193171814084053, 0.09123778343200684, 0.006296417210251093, 0.02009275183081627, -0.006758866831660271, -0.04094713181257248, 0.04818875715136528, -0.026142871007323265, 0.07820583134889603, 0.03398339822888374, 0.029462438076734543, -0.02786402218043804, -0.0005223847692832351, -0.05597742274403572, 0.05124753341078758, 0.003319242736324668, -0.05338358134031296, 0.047404903918504715, -0.03491323068737984, 0.04662303999066353, 0.0807456448674202, 0.00762891536578536, -0.06978306919336319, 0.04430816322565079, -0.03374949470162392, 0.04450764134526253, -0.07228667289018631, 0.07935048639774323, 0.01963147334754467, -0.04252006486058235, 0.02016509510576725, 0.07125985622406006, -0.035424623638391495, -0.02120276913046837, -0.040163759142160416, -0.042254794389009476, 0.01806892268359661, 0.008296419866383076, -0.049413759261369705, 0.02745446003973484, 0.0057984041050076485, 0.00999805424362421, -0.03062429651618004, 0.015599406324326992, 0.039181046187877655, -0.06649241596460342, 0.022324200719594955, -0.05649816617369652, 0.08115167170763016, -0.027021009474992752, -0.012479259632527828, 0.04844105616211891, 0.04232005402445793, -0.019266286864876747, -0.013762942515313625, -0.0008010903256945312, -0.04514648765325546, 0.05665511265397072, -0.011888319626450539, 0.008883431553840637, 0.05878652259707451, -0.07279325276613235, 0.00858295802026987, -0.007077778223901987, -0.031036529690027237, 0.032708194106817245, -0.05687713995575905, -0.03585932031273842, 0.07007770240306854, -0.030000830069184303, 0.03641095384955406, -0.08281231671571732, -0.033019423484802246, 0.10126926004886627, 0.007939383387565613, 0.061642710119485855, 0.05547904223203659, -0.020691771060228348, 0.027902482077479362, -0.04995262622833252, -0.01572035253047943, 0.020323676988482475, 0.03707461059093475, -0.05970838665962219, 0.050267137587070465, 0.005692680831998587, 0.03395845368504524, -0.10745789855718613, 0.0601051039993763, -0.0675077810883522, 0.00800949428230524, -0.04385923221707344, -0.037418682128190994, 0.02666889876127243, -0.027980102226138115, 0.0037768955808132887, 0.2113065868616104, -0.01474994421005249, -0.01840846985578537, -0.03741292655467987, -0.06158322095870972, 0.09186708927154541, 0.054850831627845764, 0.06974774599075317, 0.08323350548744202, -0.09796738624572754, -0.050297219306230545, -0.054528627544641495, 0.0009923620382323861, 0.056403059512376785, 0.010048113763332367, -0.013408861123025417, 0.022342054173350334, -0.04508616402745247, 0.009079765528440475, 0.02251031994819641, 0.015077593736350536, -0.020500678569078445, 0.03286368399858475, 0.023810280486941338, -0.03159109875559807, -0.029273033142089844, 0.014775988645851612, 0.034954607486724854, -0.09491167962551117, -0.0028769292403012514, -0.011676423251628876, 0.012593183666467667, 0.02352290041744709, -0.023815665394067764, 0.029546238481998444, 0.008758916519582272, -0.019049247726798058, 0.004918656311929226, -0.02938043512403965, 0.09641057997941971, 0.03748982027173042, -0.004728557541966438, -0.052684567868709564, -0.02502545155584812, -0.04981790482997894, -0.02640705555677414, -0.007071193773299456, 0.0041029625572264194, 0.036002252250909805, 0.0015615127049386501, 0.02219543233513832, -0.016320522874593735, 0.014135378412902355, 0.027817776426672935, 0.016902411356568336, 0.05183292552828789, 0.025578202679753304, -0.011244517751038074, -0.007637319155037403, -0.0023751212283968925, -0.0008128124172799289, -0.014870170503854752, 0.03313954174518585, 0.03238474205136299, 0.015242730267345905, -0.030238591134548187, -0.011392750777304173, -0.03204408288002014, -0.040784865617752075, 0.03183905780315399, 0.015266705304384232, 0.04628869518637657, 0.005463412497192621, -0.016849450767040253, 0.0036920299753546715, -0.027500363066792488, 0.053507573902606964, -0.0032818003091961145, 0.028338881209492683, 0.060032084584236145, -0.011096439324319363, 0.002667309483513236, 0.007949474267661572, 0.0036206599324941635, -0.008020433597266674, 0.036043282598257065, 0.00730204489082098, 0.01035055797547102, -0.12457463890314102, -0.015341944061219692, 0.021182846277952194, -0.00418068515136838, 0.0008095763041637838, -0.015390451066195965, 0.021608686074614525, -0.0001680077548371628, -0.011021028272807598, 0.016418620944023132, -0.018917443230748177, 0.002601063810288906, 0.05305757746100426, 0.003004322526976466, -0.042401425540447235, -0.0029313478153198957, -0.011788091622292995, 0.022369371727108955, 0.045550260692834854, 0.006815973203629255, -0.03896030783653259, 0.02968086116015911, -0.003742009634152055, 0.007507619448006153, -0.018132423982024193, 0.008949818089604378, 0.01830228604376316, 0.005591969937086105, 0.032109335064888, -0.029832182452082634, -0.011455104686319828, -0.005461474414914846, -0.04058508574962616, 0.024488726630806923, -0.024041613563895226, 0.01068928837776184, -0.017934799194335938, -0.003374987281858921, 0.012522054836153984, 0.02496560476720333, -0.020045248791575432, -0.013620087876915932, 0.015119579620659351, -0.010439681820571423, -0.01140559371560812, -0.009212741628289223, -0.015154310502111912, 0.0243149995803833, 0.03247072547674179, -0.02053919993340969, -0.021653415635228157, -0.008547194302082062, 0.0398067869246006, 0.06032633036375046, 0.012740874662995338, -0.025207825005054474, 0.024640394374728203, 0.03526639565825462, 0.017747845500707626, -0.0033101586159318686, -0.0407530702650547, 0.004365116357803345, -0.01632457785308361, -0.046342168003320694, -0.06230326369404793, 0.034398358315229416, -0.0039442796260118484, 0.023258347064256668, -0.02118108980357647, 0.0566694512963295, -0.025120696052908897, 0.02321016974747181, -0.003770145820453763, 0.01960155740380287, -0.021997325122356415, 0.002556271618232131, -0.01819363608956337, -0.04075842350721359, 0.06523463875055313, 0.007998757995665073, -0.01722203753888607, -0.0016519187483936548, -0.03481971472501755, -0.03133136406540871, -0.0047397431917488575, -0.015413357876241207, 0.044217005372047424, 0.0010091050062328577, 0.029466785490512848, 0.04459509626030922, -0.007593173533678055, 0.006236230954527855, 0.03999530151486397, -0.005604865960776806, 0.00010735285468399525, 0.0107987429946661, 0.021098732948303223, 0.0003611113061197102, -0.008246975019574165, 0.0015705630648881197, 0.05922476947307587, -0.013615641742944717, -0.04731089621782303, 0.030867012217640877, 0.009059177711606026, 0.04613114520907402, -0.03939606249332428, -0.07658933848142624, 0.029280371963977814, -0.03548477590084076, -0.014987443573772907, -0.047611117362976074, 0.0018047037301585078, -0.025797339156270027, 0.022217677906155586, 0.04343115910887718, -0.02682306244969368, -0.0008054643403738737, -0.044998809695243835, 0.019917206838726997, -0.04564056918025017, 0.011198612861335278, -0.002325050998479128, -0.02997811883687973, 0.01680830307304859, -0.007802486885339022, 0.02904200181365013, 0.016595566645264626, -0.010708202607929707, -0.026870636269450188, -0.05083877965807915, -0.013474496081471443, 0.01937403902411461, 0.004353940486907959, 0.008275359869003296, 0.0070509216748178005, -0.006351381074637175, 0.01898699440062046, 0.028193071484565735, -0.03991500288248062, -0.01702756993472576, -0.020076515153050423, 0.03277392312884331, -0.009096878580749035, 0.044581979513168335, 0.009112930856645107, -0.05094912648200989, 0.005033099092543125, -0.03971412405371666, 0.005664479453116655, 0.03256098926067352, 0.0022310512140393257, -0.05034933239221573, 0.050811588764190674, 0.034200720489025116, 0.0059630172327160835, -0.013676517643034458, 0.038555797189474106, 0.0022453523706644773, 0.04043162241578102, -0.040377177298069, -0.01035419199615717, -0.0076955645345151424, 0.042309194803237915, -0.00701354444026947, 0.01707819104194641, -0.022125568240880966, -0.07046012580394745, -0.02251209132373333, 0.016367945820093155, -0.010796116665005684, -0.01378512941300869, 0.0032159551046788692, -0.02534753829240799, -0.0068314871750772, 0.03326037898659706, 0.04801846668124199, 0.013918492943048477, 0.000893369666300714, 0.019171059131622314, -0.03513607010245323, 0.026508033275604248, 0.02278710901737213, -0.016245370730757713, -0.017357567325234413, 0.019359098747372627, 0.03829338401556015, 0.06363868713378906, 0.023010211065411568, 0.01975199766457081, -0.009461045265197754, 0.001029900275170803, 0.013382546603679657, -0.03541911393404007, -0.005110403522849083, -0.01380250882357359, 0.0335705541074276, 0.01343412697315216, -0.01194815058261156, -0.019774457439780235, 0.015219707041978836, 0.05791494622826576, -0.034362953156232834, -0.024937670677900314, 0.02884729579091072, 0.010541127994656563, 0.005233748350292444, -0.01579921878874302, 0.035017985850572586, -0.023377712815999985, -0.016919255256652832, -0.02259961888194084, 0.013486679643392563, -0.019481807947158813, 0.0021077534183859825, -0.026020580902695656, -0.0321766696870327, 0.029144998639822006, 0.03073280118405819, 0.05403772369027138, 0.009714186191558838, -0.014468871057033539, -0.03887540102005005, -0.004436985123902559, 0.04480826109647751, -0.05094096437096596, 0.013535810634493828, 0.036572206765413284, -0.0004902526852674782, 0.022381916642189026, 0.019366832450032234, -0.0010994084877893329, 0.013595652766525745, 0.0011497177183628082, 0.02532847598195076, -0.006009179167449474, -0.048900362104177475, 0.008976849727332592, 0.01828630268573761, -0.00827043317258358, 0.024235712364315987, -0.036167409271001816, -0.0362832173705101, 0.0019339644350111485, -0.04108280688524246, 0.032701414078474045, 0.06401196122169495, -0.007791673298925161, 0.030034396797418594, 0.029272980988025665, 0.015935132279992104, 0.009260154329240322, -0.017908379435539246, 0.004447776824235916, 0.008434268645942211, 0.023096684366464615, -0.025836912915110588, 0.0199739933013916, 0.007781088352203369, 0.00361558236181736, 0.03338320553302765, -0.04965750128030777, -0.01714344695210457, 0.019731929525732994, -0.0032896443735808134, 0.011079364456236362, -0.013311251066625118, -0.03201541304588318, -0.012741854414343834, 0.02793612889945507, 0.01091515552252531, 0.03538339212536812, 0.003260569414123893, -0.007068524602800608, 0.0003553453425411135, -0.022079624235630035, 0.01583268493413925, 0.05904991179704666, -0.029070647433400154, 0.07075410336256027, 0.005469988565891981, 0.011086462996900082, 0.017359500750899315, 0.014738389290869236, 0.014195806346833706, -0.01037860382348299, 0.053625818341970444, 0.017837313935160637, 0.04285522177815437, 0.02622409723699093, 0.012041108682751656, -0.027069509029388428, -0.029465971514582634, -0.005210562609136105, -0.00881681963801384, 0.03663061931729317, 0.02296878769993782, -0.024137424305081367, 0.04198051244020462, -0.0440865084528923, 0.04411407187581062, 0.016729213297367096, 0.05130300670862198, -0.010488904081285, 0.006682913284748793, 0.0323854461312294, 0.004603451583534479, 0.012899115681648254, 0.04683876037597656, 0.011801889166235924, -0.004494285210967064, 0.030395863577723503, 0.012239867821335793, 0.015654170885682106, -0.02520875632762909, 0.01350746676325798, 0.035910338163375854, -0.03514387458562851, -0.038412127643823624, 0.0019336299737915397, 0.005203393753618002, -0.01738686114549637, -0.03486540541052818, 0.014298493973910809, -0.04193289950489998, -0.012932423502206802, -0.018498407676815987, 0.019066449254751205, 0.0018109750235453248, -0.017288167029619217, 0.01613539643585682, 0.03379521146416664, 0.03057088330388069, -0.013225767761468887, 0.00849623791873455, 0.01977440156042576, 0.02778312750160694, 0.009782228618860245, 0.010443524457514286, -0.030727054923772812, -0.03903624415397644, -0.03542884439229965, -0.02637162245810032, 0.012947977520525455, 0.0039957198314368725, 0.012241571210324764, 0.015849245712161064, 0.0351872518658638, 0.0054069035686552525, 0.03135156258940697, 0.02321789599955082, -0.009229831397533417, -0.017646627500653267, 0.009129388257861137, -0.0303359255194664, -0.015114122070372105, -0.03320399671792984, -0.03768877685070038, 0.02720329724252224, -0.027906635776162148, -0.007407524157315493, 0.04452349990606308, 0.013565254397690296, -0.032867755740880966, -0.05055167153477669, 0.02094007283449173, -0.03044528141617775, -0.040197305381298065, 0.05868469178676605, 0.009444449096918106, -0.0180825088173151, 0.022364582866430283, -0.0004811922262888402, 0.0026540348771959543, -0.020001275464892387, 0.00020542995480354875, 0.023683536797761917, -0.02577192708849907, -0.010965126566588879, -0.02076292224228382, 0.06499750912189484, 0.017039891332387924, 0.03949524089694023, 0.05141620710492134, 0.01893201842904091, -0.01907898671925068, -0.02334984764456749, 0.02407427690923214, -0.04080517590045929, 0.022022560238838196, -0.02252466045320034, -0.0555567629635334, -0.028935506939888, -0.023180488497018814, -0.013906608335673809, -0.03703926131129265, -0.05326545238494873, -0.03482339531183243, -0.023619072511792183, -0.012294427491724491, -0.030146636068820953, 0.027223801240324974, 0.0656748116016388, 0.013351388275623322, -0.0016668782336637378, 0.029925039038062096, 0.012301581911742687, 0.01866094022989273, -0.022933736443519592, 0.005667242221534252, 0.03214435279369354, 0.024876412004232407, -0.003671275684610009, 0.0020938809029757977, 0.037975214421749115, -0.004600947257131338, -0.06034156307578087, 0.0068686953745782375, 0.015013528987765312, 0.011371933855116367, -0.04598436504602432, -0.025457095354795456, 0.009782591834664345, -0.014543539844453335, 0.048847347497940063, -0.004824032075703144, -0.012173631228506565, -0.02689260058104992, 0.03732660040259361, -0.055992912501096725, 0.017514429986476898, -0.023371636867523193, 0.025307191535830498, 0.06443489342927933, 0.006903537083417177, 0.017893247306346893, 0.01708579622209072, -0.018234029412269592, 0.005068272352218628, 0.022656099870800972, -0.029021091759204865, -0.030393363907933235, -0.007195151876658201, 0.006126766093075275, -0.015020601451396942, -0.03606467694044113, 0.006870255805552006, -0.00010006162483477965, -0.0461251363158226, -0.022061757743358612, 0.0033613136038184166, 0.009626805782318115, 0.0008275542641058564, -0.0023174327798187733, -0.008703866973519325, 0.05524864420294762, 0.01121719554066658, -0.025739923119544983, -0.03285115212202072, 0.028806038200855255 ]
How to train a new language model from scratch using Transformers and Tokenizers
julien-c
February 14, 2020
how-to-train
guide, nlp
https://huggingface.co/blog/how-to-train
3. Train a language model from scratch Update: The associated Colab notebook uses our new Trainer directly, instead of through a script. Feel free to pick the approach you like best. We will now train our language model using the run_language_modeling.py script from transformers (newly renamed from run_lm_finetuning.py as it now supports training from scratch more seamlessly). Just remember to leave --model_name_or_path to None to train from scratch vs. from an existing model or checkpoint. > We’ll train a RoBERTa-like model, which is a BERT-like with a couple of changes (check the documentation for more details). As the model is BERT-like, we’ll train it on a task of Masked language modeling, i.e. the predict how to fill arbitrary tokens that we randomly mask in the dataset. This is taken care of by the example script. We just need to do two things: - implement a simple subclass of Dataset that loads data from our text files - Depending on your use case, you might not even need to write your own subclass of Dataset, if one of the provided examples (TextDataset and LineByLineTextDataset) works – but there are lots of custom tweaks that you might want to add based on what your corpus looks like. - Choose and experiment with different sets of hyperparameters. Here’s a simple version of our EsperantoDataset. python from torch.utils.data import Dataset class EsperantoDataset(Dataset): def __init__(self, evaluate: bool = False): tokenizer = ByteLevelBPETokenizer( "./models/EsperBERTo-small/vocab.json", "./models/EsperBERTo-small/merges.txt", ) tokenizer._tokenizer.post_processor = BertProcessing( ("</s>", tokenizer.token_to_id("</s>")), ("<s>", tokenizer.token_to_id("<s>")), ) tokenizer.enable_truncation(max_length=512) # or use the RobertaTokenizer from `transformers` directly. self.examples = [] src_files = Path("./data/").glob("*-eval.txt") if evaluate else Path("./data/").glob("*-train.txt") for src_file in src_files: print("🔥", src_file) lines = src_file.read_text(encoding="utf-8").splitlines() self.examples += [x.ids for x in tokenizer.encode_batch(lines)] def __len__(self): return len(self.examples) def __getitem__(self, i): # We’ll pad at the batch level. return torch.tensor(self.examples[i]) If your dataset is very large, you can opt to load and tokenize examples on the fly, rather than as a preprocessing step. Here is one specific set of hyper-parameters and arguments we pass to the script: --output_dir ./models/EsperBERTo-small-v1 --model_type roberta --mlm --config_name ./models/EsperBERTo-small --tokenizer_name ./models/EsperBERTo-small --do_train --do_eval --learning_rate 1e-4 --num_train_epochs 5 --save_total_limit 2 --save_steps 2000 --per_gpu_train_batch_size 16 --evaluate_during_training --seed 42 As usual, pick the largest batch size you can fit on your GPU(s). 🔥🔥🔥 Let’s start training!! 🔥🔥🔥 Here you can check our Tensorboard for one particular set of hyper-parameters: > Our example scripts log into the Tensorboard format by default, under runs/. Then to view your board just run tensorboard dev upload --logdir runs – this will set up tensorboard.dev, a Google-managed hosted version that lets you share your ML experiment with anyone.
[ 0.031237203627824783, -0.037789493799209595, -0.04114155471324921, 0.037951283156871796, 0.006213490851223469, 0.0643656924366951, 0.011316786520183086, 0.030382582917809486, 0.01253008283674717, 0.0035449606366455555, -0.07934226095676422, 0.055028147995471954, 0.0010401627514511347, 0.07660318911075592, 0.033848632127046585, -0.033169809728860855, 0.04311578348278999, 0.0016742992447689176, 0.014681546948850155, 0.017206933349370956, -0.028571924194693565, -0.0280024204403162, 0.07385149598121643, 0.01173677109181881, 0.02944355644285679, -0.05556053668260574, 0.04933551698923111, 0.010783634148538113, -0.035837266594171524, 0.030267857015132904, -0.11259040236473083, 0.016223004087805748, 0.0022370663937181234, 0.00702663604170084, -0.0359736792743206, 0.04762088507413864, -0.03727484866976738, 0.007985271513462067, 0.03629319369792938, 0.0020756146404892206, -0.04165968298912048, 0.03587576374411583, 0.00960609782487154, 0.08795956522226334, -0.03846601024270058, -0.023027140647172928, -0.1658138632774353, 0.07169082015752792, -0.03738590329885483, -0.08062146604061127, -0.04484798014163971, 0.07985518127679825, 0.02384115755558014, -0.015995074063539505, -0.025943731889128685, 0.0020365193486213684, 0.03846295550465584, -0.09239078313112259, 0.006803237367421389, 0.007657210808247328, 0.026035765185952187, 0.015107673592865467, 0.003886716440320015, -0.006025414913892746, 0.01610676571726799, 0.004625596571713686, -0.05116524174809456, 0.018506495282053947, -0.06006926670670509, -0.03208431974053383, -0.011563954874873161, -0.03608326241374016, -0.05268193036317825, -0.0323462076485157, -0.014228139072656631, -0.04915250837802887, -0.018323708325624466, 0.019333533942699432, 0.031080661341547966, 0.059192076325416565, 0.004570998717099428, 0.005773273762315512, 0.03709358349442482, 0.029649734497070312, 0.07773183286190033, 0.03749944269657135, 0.022610820829868317, -0.02824086882174015, -0.053128696978092194, 0.042178984731435776, -0.026716038584709167, -0.10894149541854858, -0.025545280426740646, 0.011436398141086102, 0.1022963747382164, -0.008812857791781425, -0.0338984876871109, 0.03492743894457817, -0.01948687620460987, -0.06111718341708183, -0.016435809433460236, -0.08536256849765778, -0.016212843358516693, -0.0343475304543972, -0.0839521735906601, 0.05992020294070244, -0.008972449228167534, -0.0024008508771657944, -0.010179723612964153, -0.01691557466983795, 0.016980649903416634, -0.05706898495554924, -0.05367189645767212, 0.10499662905931473, -0.12311018258333206, -0.010906994342803955, 0.02209329791367054, 0.031062036752700806, -0.03568444028496742, 0.02279643528163433, -0.017154550179839134, 0.044116947799921036, 0.06329550594091415, 0.0023472777102142572, -0.04177117720246315, 0.09606767445802689, -0.024590739980340004, 0.035273477435112, 0.031809404492378235, 0.00908801518380642, 0.06284056603908539, -0.030553093180060387, 0.07347062230110168, -0.0015214629238471389, 0.022303521633148193, 0.014879402704536915, 0.03723016753792763, -0.033867061138153076, 0.01587236486375332, 0.024100402370095253, -0.040910352021455765, 0.07883943617343903, -0.06674908101558685, 0.0251588337123394, 0.03323596715927124, -0.012378118000924587, -0.07588613778352737, 0.10293890535831451, 0.016043297946453094, 0.04866733402013779, -0.10023130476474762, 0.05105360597372055, -0.012603795155882835, -0.04094782471656799, 0.032846324145793915, 0.06799205392599106, -0.06970395147800446, -0.010138402692973614, -0.0461445227265358, -0.02146236225962639, -0.01198427565395832, 0.054070714861154556, -0.09199400991201401, -0.010107486508786678, 0.01605912484228611, -0.03339741379022598, -0.007284615654498339, 0.07442121207714081, 0.03056117706000805, 0.060632042586803436, 0.0679776668548584, -0.007874567061662674, 0.07312066107988358, 0.01614762656390667, 0.018997879698872566, 0.007760696113109589, 0.024970991536974907, 0.029914861544966698, 0.015025590546429157, 0.0037163018714636564, -0.04639919474720955, 0.037859413772821426, 0.005766001529991627, 0.04382077232003212, 0.019884498789906502, -0.06891394406557083, 0.008877668529748917, -0.05467435345053673, -0.0001555156341055408, 0.039196450263261795, 0.014907380566000938, 0.013387355022132397, 0.08214227110147476, -0.0185121838003397, 0.07262511551380157, -0.06950938701629639, 0.015555479563772678, 0.07990362495183945, 0.019830793142318726, 0.0677834078669548, 0.04517947882413864, -0.01612946204841137, -0.00289649935439229, -0.014953237026929855, 0.04626123607158661, -0.01662672869861126, 0.03705079108476639, -0.0725356936454773, 0.04141750931739807, -0.009248758666217327, -0.0194497499614954, -0.0685003250837326, 0.04597487300634384, -0.048911742866039276, 0.01310016680508852, -0.053363390266895294, -0.02549506537616253, 0.01628562994301319, 0.03503917157649994, 0.004593502730131149, 0.16617567837238312, -0.09452113509178162, -0.0028528966940939426, -0.023052917793393135, -0.047143448144197464, 0.02469358593225479, 0.0519067719578743, 0.04020104557275772, 0.08742327988147736, -0.05799887329339981, -0.05100012198090553, -0.09860319644212723, 0.0462314747273922, 0.022393472492694855, -0.06529254466295242, -0.02296573854982853, -0.026962952688336372, 0.006857771426439285, -0.02560182847082615, -0.017956571653485298, 0.016711806878447533, -0.023660430684685707, -0.04149841144680977, 0.015489715151488781, -0.013433939777314663, 0.04638976231217384, 0.07931686192750931, 0.02235409803688526, 0.021454203873872757, 0.01205788180232048, -0.017282739281654358, 0.02557210437953472, -0.009407788515090942, -0.03876395523548126, -0.002939980011433363, 0.0589151494204998, 0.01053844764828682, 0.00022241874830797315, 0.0033941648434847593, 0.04692979156970978, -0.02017349749803543, -0.025008825585246086, -0.05203080177307129, -0.01282286923378706, -0.004646813031286001, -0.05748908966779709, -0.008611193858087063, 0.011420968919992447, -0.010659400373697281, -0.006059540435671806, 0.01585518755018711, -0.0228602085262537, 0.01606624759733677, 0.028968671336770058, 0.007785093504935503, 0.07507412880659103, 0.009216883219778538, -0.03624489903450012, -0.054304324090480804, -0.027835138142108917, -0.008750868029892445, -0.024680236354470253, 0.025068385526537895, 0.047902245074510574, -0.0031214815098792315, 0.019989319145679474, -0.02582598105072975, -0.031319085508584976, 0.01187230460345745, 0.03971346840262413, -0.018936732783913612, 0.03560865297913551, -0.008715745992958546, -0.027289418503642082, -0.027684127911925316, 0.0028103620279580355, 0.009777022525668144, -0.015351745299994946, 0.014413568191230297, 0.017333997413516045, -0.0527954064309597, 0.015099906362593174, -0.002516264794394374, -0.011239519342780113, -0.013332154601812363, 0.0006814123480580747, 0.04878261685371399, 0.01650824397802353, -0.08447958528995514, -0.010502220131456852, 0.007312154397368431, 0.0011075285729020834, 0.014907428994774818, -0.04176982492208481, 0.009231938049197197, -0.01460573635995388, -0.07299422472715378, 0.010357308201491833, -0.009027141146361828, 0.01848718523979187, 0.008305304683744907, 0.019004909321665764, -0.019370002672076225, -0.02429467812180519, -0.04890250787138939, 0.0006978926830925047, 0.006416009273380041, 0.03116871789097786, -0.04556471109390259, 0.02335226535797119, -0.0022778394632041454, 0.033385492861270905, -0.0011242559412494302, 0.007224253378808498, -0.003229799447581172, 0.04612145200371742, 0.011637981049716473, 0.01044072862714529, -0.02446599490940571, -0.016692154109477997, 0.02046143263578415, 0.02136237360537052, -0.03841172903776169, 0.02074519731104374, 0.029204513877630234, 0.044169869273900986, -0.031331028789281845, 0.03425484895706177, -0.0163374375551939, -0.006224543321877718, -0.004365164320915937, -0.0422603040933609, 0.009416217915713787, -0.022473683580756187, -0.022510461509227753, -0.03502795100212097, -0.0013423068448901176, -0.040535613894462585, -0.009374438785016537, 0.004251355770975351, 0.014568120241165161, 0.0514490082859993, 0.01886366680264473, 0.013860736973583698, 0.011143778450787067, 0.03130296245217323, 0.0384470634162426, 0.0017091938061639667, -0.019672244787216187, 0.014433835633099079, -0.039849184453487396, -0.016197901219129562, -0.035359591245651245, 0.03767550364136696, 0.03510291501879692, -0.0008516747620888054, -0.028725698590278625, 0.00984185840934515, -0.01286937203258276, 0.05505182966589928, 0.005527185741811991, 0.0003423857851885259, -0.0072959186509251595, -0.0071973358280956745, -0.027096837759017944, -0.007702578324824572, 0.046263083815574646, 0.02323784865438938, -0.02184555120766163, -0.0017149785999208689, -0.045032888650894165, -0.01697678677737713, 0.00017989570915233344, -0.028785133734345436, -0.013224538415670395, -0.07106699794530869, 0.00004151183748035692, 0.0286378413438797, 0.012805641628801823, -0.008193514309823513, -0.004774169530719519, 0.007979865185916424, 0.0021867260802537203, -0.00406134407967329, -0.014618724584579468, -0.014188981615006924, -0.008692066185176373, -0.016790302470326424, 0.030328337103128433, -0.054589029401540756, 0.02005789987742901, 0.02334294281899929, 0.025344235822558403, 0.05512421205639839, -0.043534018099308014, -0.02507672645151615, -0.005038432311266661, -0.026669399812817574, 0.019433334469795227, 0.045005522668361664, 0.0028950993437319994, 0.018126757815480232, 0.042043287307024, 0.05142057314515114, -0.00904057640582323, -0.024486592039465904, 0.02112908661365509, 0.012483257800340652, -0.04039432853460312, -0.017155803740024567, 0.010903139598667622, 0.0033504869788885117, 0.023594200611114502, -0.022052621468901634, 0.04092495143413544, 0.056545134633779526, -0.014146916568279266, 0.004917223937809467, -0.04320447891950607, -0.04509343206882477, 0.007757829502224922, 0.009079616516828537, 0.015221641398966312, 0.013742746785283089, -0.014063708484172821, -0.012787922285497189, -0.016469353809952736, -0.028999654576182365, -0.04793568328022957, -0.018624484539031982, 0.042989976704120636, -0.04593752324581146, 0.01866304688155651, -0.00046305227442644536, -0.011271627619862556, -0.028663456439971924, -0.004050613380968571, -0.0051058209501206875, 0.039325911551713943, 0.017778584733605385, -0.03579993173480034, 0.00533407274633646, 0.02489531971514225, -0.014838027767837048, 0.009035410359501839, 0.06216372177004814, 0.027681756764650345, 0.05658210813999176, 0.010409326292574406, 0.03143703565001488, -0.016016816720366478, 0.03487003967165947, 0.035921890288591385, -0.010855374857783318, -0.00782802328467369, -0.06755886971950531, 0.011308628134429455, 0.014598493464291096, 0.0005873374757356942, 0.011222912929952145, 0.03273656964302063, -0.024498332291841507, 0.03227541595697403, 0.05042770504951477, 0.03576282784342766, 0.01019694097340107, -0.07168033719062805, 0.016171330586075783, -0.014438658021390438, -0.011361366137862206, -0.0007398112793453038, 0.01935344561934471, -0.004909079521894455, 0.0329011008143425, 0.047624558210372925, 0.04343258962035179, 0.009408070705831051, 0.009209495969116688, -0.011559093371033669, -0.01932082138955593, 0.01571866124868393, -0.03802035376429558, 0.017249228432774544, -0.017554106190800667, -0.06129438802599907, 0.02583332546055317, -0.04252387955784798, -0.012221267446875572, 0.0026529678143560886, 0.022724833339452744, -0.02707306295633316, -0.005261264741420746, 0.07458116859197617, -0.0020008310675621033, -0.04546637460589409, -0.025276565924286842, -0.004593859892338514, -0.024715008214116096, -0.008700492791831493, -0.01890914887189865, 0.0007085484685376287, -0.008339053951203823, -0.0290216077119112, -0.011541672050952911, 0.013150024227797985, -0.008765306323766708, 0.026031138375401497, 0.04976004362106323, -0.009546888992190361, -0.013524270616471767, -0.030677059665322304, -0.012830947525799274, 0.033780574798583984, -0.042772550135850906, 0.014550727792084217, 0.06275449693202972, 0.0013236482627689838, 0.018951846286654472, 0.054501648992300034, 0.004727655090391636, 0.017028531059622765, 0.055192917585372925, -0.024792831391096115, -0.07006710022687912, -0.030635742470622063, 0.0237803403288126, 0.04216876998543739, -0.035698212683200836, -0.019069921225309372, -0.031078200787305832, -0.023366011679172516, -0.0013757447013631463, -0.04181967303156853, 0.03251035138964653, 0.047667380422353745, 0.0007161860121414065, 0.050746481865644455, 0.0188148096203804, -0.0005410159355960786, 0.0005110892234370112, -0.021955307573080063, 0.01911822520196438, 0.028601480647921562, 0.008223148062825203, 0.021924512460827827, -0.0017846187110990286, 0.004433714784681797, 0.011606375686824322, 0.02731945365667343, -0.07858648896217346, 0.03507135808467865, 0.047355230897665024, -0.03134870529174805, 0.004710305016487837, 0.015792736783623695, -0.041018255054950714, -0.025261135771870613, -0.003543868660926819, 0.05787060782313347, 0.01643259823322296, -0.038410257548093796, -0.0007263626903295517, 0.00489283911883831, -0.04129472374916077, 0.0046501378528773785, 0.053469885140657425, -0.03925113007426262, 0.0730295181274414, 0.019107280299067497, -0.015047864988446236, 0.02261737920343876, 0.015902288258075714, -0.004486143589019775, -0.0056107621639966965, 0.040935974568128586, 0.052593689411878586, -0.011815664358437061, 0.010903416201472282, -0.026561494916677475, -0.020132800564169884, -0.03605842590332031, -0.015846865251660347, -0.032815854996442795, -0.010145445354282856, 0.0639529898762703, -0.014056584797799587, -0.029319195076823235, 0.02225944586098194, 0.04842614009976387, 0.058530405163764954, 0.04892057925462723, -0.018202707171440125, 0.048735361546278, 0.046245161443948746, 0.016304289922118187, -0.0016286992467939854, 0.04000835120677948, 0.0014979841653257608, 0.00477225286886096, 0.04351799935102463, 0.03981402888894081, 0.01352537702769041, 0.04177330434322357, 0.0012777450028806925, 0.023489590734243393, -0.019581900909543037, -0.03893400728702545, 0.020771050825715065, -0.002056465018540621, -0.007844050414860249, -0.012620826251804829, 0.007815548218786716, -0.04300650954246521, -0.0012568967649713159, -0.02344839833676815, -0.02900680899620056, -0.031309448182582855, -0.027563897892832756, -0.028392469510436058, 0.019146401435136795, 0.012922218069434166, -0.041718535125255585, -0.002829723758623004, -0.027383003383874893, -0.027066567912697792, -0.011815905570983887, -0.016762910410761833, -0.028563588857650757, -0.024920813739299774, -0.03597060963511467, -0.03802233934402466, 0.0008620754815638065, -0.02591511234641075, -0.030721573159098625, -0.024596303701400757, 0.0015620611375197768, -0.026530183851718903, 0.016276096925139427, 0.008791433647274971, 0.009208871982991695, -0.02771843411028385, 0.01336628757417202, -0.01274939626455307, -0.05581801012158394, 0.0524318628013134, -0.055532392114400864, 0.004958357661962509, 0.0030786858405917883, 0.0353177934885025, 0.03678376227617264, 0.0594167523086071, 0.006846324075013399, -0.05825873464345932, 0.009073515422642231, 0.0283212810754776, -0.047075141221284866, 0.04497300833463669, 0.013260932639241219, 0.024646399542689323, 0.004628293216228485, -0.01647757552564144, -0.0037733360659331083, -0.007995454594492912, -0.018471544608473778, 0.037279415875673294, 0.015149736776947975, -0.041653405874967575, -0.013089941814541817, 0.0208510160446167, -0.00010020494664786384, -0.008500187657773495, 0.05299593135714531, -0.018274011090397835, 0.00699451332911849, -0.019909020513296127, 0.05134199187159538, -0.030054718255996704, -0.0028910476248711348, -0.03935556858778, -0.062134671956300735, -0.0341356135904789, -0.022619785740971565, -0.03080088458955288, 0.03331691026687622, -0.03330347314476967, -0.027048306539654732, -0.06302658468484879, -0.016575144603848457, 0.0000781478374847211, 0.017028972506523132, 0.049993276596069336, 0.026297202333807945, 0.003118139458820224, 0.02758674882352352, -0.021438954398036003, 0.031095169484615326, -0.01528092473745346, -0.014552854001522064, 0.07075881958007812, 0.022975625470280647, -0.009164029732346535, 0.02231595851480961, -0.005913932342082262, 0.004459037445485592, -0.020550992339849472, -0.02034052275121212, -0.03516080230474472, 0.009680300951004028, -0.024326033890247345, 0.02924797683954239, 0.027674149721860886, -0.032468874007463455, -0.0023629621136933565, 0.033550649881362915, -0.011024581268429756, 0.004044988192617893, 0.019873814657330513, -0.06282096356153488, -0.03351442515850067, -0.024288881570100784, -0.045913033187389374, 0.013780687935650349, 0.00460267998278141, 0.0507018119096756, -0.006236565299332142, -0.037597570568323135, -0.00886413361877203, 0.024103641510009766, -0.01820063591003418, -0.029655950143933296, 0.0008996182004921138, 0.024877769872546196, -0.02111496403813362, 0.010605131275951862, 0.03113250434398651, 0.04160277917981148, 0.022973569110035896, -0.014221169985830784, 0.01710015907883644, 0.029606720432639122, 0.0012027384946122766, 0.010665079578757286, -0.021193983033299446, 0.033391647040843964, 0.007115074899047613, -0.002308268565684557, -0.02332119643688202, 0.031201617792248726 ]
How to train a new language model from scratch using Transformers and Tokenizers
julien-c
February 14, 2020
how-to-train
guide, nlp
https://huggingface.co/blog/how-to-train
Thank you!
[ 0.03582184761762619, 0.014917245134711266, 0.1064121276140213, 0.013955991715192795, 0.1340298056602478, 0.042345672845840454, 0.030655426904559135, 0.04903286695480347, -0.032038137316703796, -0.09784821420907974, -0.02339094690978527, 0.03995697572827339, -0.01871742494404316, 0.0024023670703172684, 0.0006893304525874555, 0.0617804229259491, 0.0417938306927681, -0.004533983767032623, 0.01230056956410408, 0.008676229976117611, -0.01241267193108797, -0.040559038519859314, 0.06075572595000267, 0.01683993451297283, 0.005108661018311977, -0.014932291582226753, 0.012357850559055805, -0.014096085913479328, -0.055145129561424255, 0.0543329231441021, -0.008427169173955917, 0.004302592948079109, 0.059741899371147156, -0.008708610199391842, -0.009945407509803772, 0.003799373283982277, -0.06482046097517014, -0.003476005280390382, -0.05609647557139397, -0.04729646071791649, 0.004935006145387888, -0.06463637202978134, -0.007793728727847338, 0.042337629944086075, -0.03129434213042259, -0.0009785478468984365, -0.29562750458717346, 0.07023068517446518, -0.025315143167972565, -0.001674689119681716, -0.02686641737818718, 0.006284052040427923, 0.014243711717426777, -0.009904075413942337, 0.04243120178580284, 0.012484178878366947, 0.029250983148813248, -0.050916437059640884, -0.014655322767794132, -0.08483218401670456, 0.07239583134651184, -0.009143790230154991, 0.0034283034037798643, 0.00941845215857029, 0.041007183492183685, 0.06301959604024887, -0.005770291667431593, 0.05021220073103905, -0.034143559634685516, -0.011885539628565311, 0.03500832989811897, -0.026511922478675842, -0.02473149076104164, -0.02385031059384346, 0.06414429843425751, -0.047303829342126846, -0.06465610861778259, 0.02507847175002098, 0.06394754350185394, 0.08407402783632278, -0.017913062125444412, -0.014791185967624187, 0.10802043974399567, 0.09417229890823364, 0.00023449776927009225, -0.050016555935144424, 0.05866439640522003, -0.048261094838380814, 0.013923556543886662, -0.012416881509125233, -0.04495321586728096, -0.0744595155119896, 0.03316996619105339, 0.044435303658246994, 0.022805558517575264, -0.05245215445756912, 0.0667240172624588, -0.0031489890534430742, 0.04697617515921593, 0.0037226604763418436, -0.03637048974633217, -0.0031272091437131166, -0.019406115636229515, -0.03937055915594101, -0.04289316013455391, -0.007052770350128412, -0.024983223527669907, -0.05621364712715149, -0.048461008816957474, 0.03735025227069855, -0.011579299345612526, 0.05300365388393402, 0.0486593022942543, -0.02725832909345627, -0.04552583396434784, 0.072946697473526, 0.01741175912320614, -0.006442380137741566, 0.008107380010187626, 0.02822970226407051, 0.0029637725092470646, 0.1124928668141365, 0.07217659801244736, 0.038784172385931015, 0.03856651484966278, -0.006402693688869476, 0.02524460293352604, 0.06069929152727127, -0.09286141395568848, -0.03841105476021767, 0.01355647761374712, -0.006142187863588333, 0.029644068330526352, -0.023899998515844345, -0.051160458475351334, -0.050050169229507446, -0.011739067733287811, -0.0021058754064142704, 0.022122908383607864, 0.005026291590183973, -0.002326815389096737, 0.041919611394405365, -0.01462602149695158, 0.06703659147024155, 0.035924363881349564, -0.0369182787835598, -0.023609386757016182, 0.03627453371882439, -0.011771014891564846, -0.014631667174398899, 0.018099837005138397, 0.07838220149278641, -0.029327524825930595, -0.06164199113845825, -0.014446052722632885, 0.04670325666666031, 0.02239629440009594, 0.02085002139210701, -0.10044771432876587, -0.02109968475997448, 0.03815990686416626, 0.017587989568710327, 0.005013604648411274, 0.01053282804787159, 0.046193886548280716, -0.02653166465461254, 0.025425951927900314, -0.00830328743904829, -0.02870338037610054, -0.09198840707540512, -0.02413547784090042, 0.019643625244498253, 0.0570317804813385, -0.018178269267082214, -0.07989450544118881, 0.02891545742750168, 0.07349969446659088, 0.033506229519844055, 0.01200388465076685, 0.00986540224403143, -0.043309397995471954, 0.03559517487883568, 0.0019230105681344867, 0.01934731751680374, 0.022442687302827835, -0.01963353529572487, 0.055426158010959625, -0.021146049723029137, -0.018151363357901573, 0.049007516354322433, -0.14430227875709534, -0.062240052968263626, 0.11569830030202866, -0.01593109779059887, -0.002424286212772131, -0.0743061751127243, -0.0222026314586401, 0.10166456550359726, 0.05785377696156502, 0.061047766357660294, 0.03015666827559471, 0.042044468224048615, 0.09240956604480743, -0.03366287425160408, -0.04850507527589798, 0.03674739971756935, 0.06902584433555603, -0.019860263913869858, 0.004290353506803513, 0.01077384501695633, -0.05652894452214241, -0.07234175503253937, 0.0568414069712162, -0.05724729597568512, -0.02094268426299095, -0.007383502554148436, -0.005549504421651363, -0.033594463020563126, 0.022338151931762695, -0.06408701837062836, 0.06695074588060379, 0.019857235252857208, -0.03113418258726597, 0.03934876248240471, -0.030552569776773453, 0.10304394364356995, 0.07441404461860657, -0.0029631892684847116, 0.07109291851520538, -0.07545079290866852, -0.027203772217035294, -0.01022458914667368, -0.014724415726959705, 0.08769144862890244, 0.017062945291399956, 0.05422892048954964, 0.005131077952682972, -0.06382536143064499, 0.029395489022135735, -0.008082274347543716, 0.012783602811396122, 0.010784941725432873, -0.01719078980386257, 0.0426718145608902, -0.03554153814911842, -0.05092940479516983, 0.03630925342440605, 0.037792228162288666, -0.06894110143184662, -0.029184993356466293, -0.053064484149217606, 0.0854339525103569, 0.023517822846770287, -0.02022898755967617, 0.08616814762353897, -0.0298664141446352, -0.006199604831635952, -0.016284804791212082, -0.005292976275086403, 0.01914425566792488, 0.0002092768409056589, -0.007959465496242046, 0.02031477354466915, -0.060598839074373245, -0.010732888244092464, -0.00803186185657978, 0.018404079601168633, 0.0018689308781176805, -0.0010656126542016864, 0.051397427916526794, -0.013739547692239285, -0.023374764248728752, 0.030547956004738808, 0.016541743651032448, -0.007031685207039118, 0.004113170318305492, 0.04703886806964874, -0.010832558386027813, -0.008775264956057072, -0.021056272089481354, -0.011420954018831253, -0.03577436879277229, 0.006604224909096956, 0.014893999323248863, 0.046988215297460556, -0.026934975758194923, 0.03863273933529854, -0.0014075865037739277, -0.01839590072631836, 0.021529296413064003, 0.010666626505553722, 0.028133215382695198, 0.001927840057760477, -0.05171404406428337, 0.03180554881691933, -0.021399013698101044, -0.01645619049668312, 0.031716056168079376, -0.04292991757392883, 0.008192203007638454, 0.03875147923827171, -0.0017178085399791598, 0.002369930734857917, 0.023741604760289192, -0.043949950486421585, 0.0424952358007431, -0.005027335602790117, 0.004449354484677315, -0.16950488090515137, -0.02917049638926983, 0.03110516630113125, 0.036664094775915146, -0.029732855036854744, -0.0170260202139616, 0.037651799619197845, -0.04075097665190697, -0.03375532850623131, -0.015966871753335, 0.029702985659241676, 0.02211766690015793, 0.021261904388666153, -0.03176764398813248, -0.013054179027676582, -0.004100761376321316, -0.019189439713954926, -0.00027508186758495867, 0.008113649673759937, -0.011875336058437824, -0.006286374293267727, 0.05008791759610176, -0.010285546071827412, -0.018715279176831245, -0.021541744470596313, 0.059658877551555634, 0.029982127249240875, 0.017086094245314598, 0.010330037213861942, -0.022919025272130966, -0.02306893654167652, 0.03593936562538147, -0.021971765905618668, 0.027628403156995773, -0.012071539647877216, 0.00025805807672441006, -0.0012022448936477304, -0.027419498190283775, -0.01654146797955036, 0.04278917983174324, 0.030468754470348358, 0.012810674495995045, 0.036064017564058304, 0.04083459451794624, -0.03792219236493111, 0.004536918364465237, 0.010552775114774704, 0.0003056453133467585, 0.056059978902339935, -0.02941523864865303, -0.04795883968472481, -0.007983710616827011, -0.005280863493680954, 0.04341895878314972, -0.014446142129600048, -0.002493445295840502, -0.032737910747528076, 0.010558261536061764, 0.06505643576383591, -0.027242055162787437, -0.0038921828381717205, 0.017469534650444984, 0.012320537120103836, 0.01149656716734171, -0.0225201528519392, 0.05348007008433342, -0.04023681581020355, 0.019367363303899765, -0.042448993772268295, 0.054383911192417145, 0.020596740767359734, -0.004423342179507017, -0.018997767940163612, 0.01676657423377037, 0.0062933266162872314, 0.020826613530516624, -0.009401045739650726, -0.013376615010201931, 0.035369567573070526, -0.004556143190711737, 0.010933133773505688, -0.012842286378145218, -0.01641780510544777, -0.010858830064535141, -0.008690047077834606, 0.029222410172224045, 0.0015761980321258307, 0.029517006129026413, -0.011816379614174366, 0.040445826947689056, 0.021417634561657906, 0.009842832572758198, -0.019646231085062027, -0.007831694558262825, -0.0030747258570045233, 0.018883220851421356, 0.059196241199970245, -0.021468468010425568, 0.008883651345968246, 0.0017140267882496119, 0.005566417705267668, -0.004694868344813585, -0.017840249463915825, 0.023264147341251373, 0.007874027825891972, 0.03016381897032261, -0.010315352119505405, -0.035325706005096436, -0.013275917619466782, 0.022212281823158264, 0.010324681177735329, -0.04944348707795143, -0.0007516755140386522, -0.0327327735722065, -0.02252816967666149, 0.018049070611596107, -0.018035707995295525, -0.042529527097940445, -0.035045355558395386, 0.01756337843835354, -0.026875656098127365, 0.02004122920334339, 0.022113574668765068, -0.035193413496017456, -0.010192418470978737, 0.0020658797584474087, 0.0044273752719163895, -0.002663596998900175, 0.018075071275234222, 0.003223104402422905, -0.028881361708045006, -0.04197750985622406, 0.03690379858016968, -0.008963172324001789, 0.027296364307403564, 0.004638420883566141, -0.008288268931210041, 0.04241782799363136, -0.012560578063130379, -0.058773767203092575, 0.013624581508338451, 0.0017954943468794227, 0.003488530870527029, -0.02547241747379303, 0.013310101814568043, -0.012609526515007019, 0.0020879325456917286, 0.00884877610951662, -0.006766055710613728, 0.021099520847201347, 0.04181639105081558, -0.049204081296920776, -0.022262804210186005, -0.0025544404052197933, -0.009850287809967995, 0.0161641463637352, 0.01927011087536812, -0.020509811118245125, -0.02378622256219387, 0.06101968139410019, -0.0057489313185215, -0.01233746949583292, -0.07312779873609543, 0.03270307555794716, -0.04514234885573387, -0.00637868233025074, -0.0044298372231423855, 0.008695988915860653, -0.010842828080058098, -0.013973083347082138, -0.01640784554183483, -0.01471512857824564, 0.042721301317214966, -0.015391276217997074, 0.01578410528600216, 0.023694677278399467, 0.020164960995316505, 0.013118368573486805, 0.022719837725162506, 0.02418244257569313, -0.005504109431058168, 0.0020851516164839268, 0.041314467787742615, 0.01119512040168047, -0.008873989805579185, -0.026918403804302216, 0.02796662226319313, -0.0015426933532580733, 0.002973745344206691, 0.05894489213824272, -0.059522271156311035, -0.029048850759863853, -0.01174286287277937, -0.028633616864681244, -0.0025262522976845503, 0.0012569321552291512, 0.012392304837703705, -0.013092519715428352, -0.009316825307905674, -0.0034208418801426888, 0.021591641008853912, 0.02839174121618271, -0.00905181560665369, -0.014542858116328716, 0.001688131713308394, 0.03813757374882698, 0.012203555554151535, -0.011556966230273247, -0.00827887374907732, -0.00878655631095171, -0.006078267004340887, 0.023331359028816223, -0.01282221358269453, -0.014795664697885513, -0.024064067751169205, -0.051774412393569946, -0.039824407547712326, 0.020548023283481598, 0.01560380682349205, 0.023867812007665634, 0.02578163519501686, 0.007643633056432009, -0.02164357155561447, 0.04787847027182579, 0.053414031863212585, -0.010625854134559631, 0.007398422807455063, 0.03965878486633301, -0.018471436575055122, 0.03396550193428993, 0.020918164402246475, 0.01792977564036846, -0.02356158196926117, 0.026828918606042862, 0.0299287810921669, 0.023884231224656105, -0.07452455163002014, 0.017491871491074562, -0.01180950179696083, 0.010182106867432594, 0.011290980502963066, -0.013212263584136963, -0.00616818480193615, -0.02593117393553257, -0.039023980498313904, 0.02644515596330166, 0.030501458793878555, -0.020909661427140236, 0.030199017375707626, 0.0024780372623354197, 0.024579932913184166, 0.0006694445619359612, 0.0050532519817352295, -0.025466641411185265, -0.0007795717101544142, 0.005152358207851648, -0.0061842091381549835, -0.01608729362487793, 0.017736488953232765, -0.017698587849736214, -0.007414317689836025, 0.005310223437845707, 0.02912868745625019, 0.035780955106019974, -0.01756075583398342, 0.017987947911024094, 0.007785458117723465, -0.017648564651608467, 0.014238578267395496, 0.026562068611383438, -0.026261309161782265, 0.009997205808758736, 0.045717015862464905, -0.04033854603767395, 0.017999941483139992, -0.019431693479418755, 0.04149176552891731, 0.012597964145243168, 0.013564459048211575, -0.012938208878040314, 0.005832276772707701, 0.011982128024101257, 0.006372643169015646, 0.006283801048994064, -0.024014310911297798, 0.02564837969839573, 0.01266750693321228, 0.000627373403403908, 0.029331747442483902, 0.020597834140062332, 0.01622885838150978, 0.0164114311337471, -0.016062026843428612, 0.022791653871536255, -0.014616714790463448, -0.0011197885032743216, 0.01430816575884819, -0.033594027161598206, 0.028421275317668915, -0.03140915185213089, 0.031796250492334366, 0.001726192538626492, -0.010205883532762527, 0.014513506554067135, -0.031003661453723907, 0.009488307870924473, 0.028740890324115753, -0.006731302011758089, -0.016614975407719612, -0.048149943351745605, 0.020596416667103767, 0.05826834216713905, -0.028922295197844505, -0.01582292653620243, -0.015946069732308388, -0.05592527613043785, 0.048102982342243195, -0.012911968864500523, -0.03017519973218441, 0.0008717830060049891, 0.04187149181962013, -0.006466080900281668, -0.014331490732729435, -0.012699885293841362, -0.046984441578388214, -0.0764581561088562, 0.012542002834379673, 0.02958308346569538, -0.0112617714330554, 0.001018193201161921, 0.004982439335435629, 0.02990536019206047, -0.013825245201587677, -0.0035037158522754908, -0.006682390347123146, 0.05364855006337166, 0.023040540516376495, 0.04112439230084419, -0.022223003208637238, -0.02401520311832428, -0.021146632730960846, 0.0005078830290585756, 0.0016095041064545512, -0.004527922719717026, 0.0046087466180324554, -0.007066614925861359, -0.020714597776532173, 0.0019050106639042497, 0.004520771559327841, 0.02421308495104313, 0.03224116563796997, 0.014277043752372265, -0.01915091648697853, 0.04016444459557533, -0.03227568045258522, -0.01928640343248844, -0.02062993496656418, -0.0212908536195755, -0.0004075980687048286, -0.0005746483220718801, -0.008262635208666325, 0.021281911060214043, 0.012796109542250633, -0.01581766828894615, -0.044119007885456085, -0.008850198239088058, -0.018408408388495445, 0.011509589850902557, 0.016512563452124596, 0.010760542936623096, -0.02123982459306717, -0.03759017586708069, 0.023254716768860817, 0.014863019809126854, -0.04394179955124855, 0.0004829931422136724, -0.03497970104217529, -0.032068882137537, -0.013737697154283524, 0.004712791182100773, 0.07118083536624908, 0.02259041741490364, 0.012116672471165657, 0.0273303110152483, 0.03456234186887741, -0.00046777274110354483, -0.022944841533899307, 0.022981779649853706, 0.01909037120640278, 0.02714485488831997, -0.019625550135970116, -0.022807737812399864, -0.024255862459540367, -0.06082854047417641, 0.0021969482768326998, -0.002418047981336713, -0.06004129350185394, -0.01669485680758953, 0.0008370992727577686, 0.009537667967379093, -0.040538206696510315, 0.03392400965094566, 0.03818489611148834, 0.0061010029166936874, 0.02319456823170185, -0.009521735832095146, -0.00006451027002185583, -0.008037195540964603, 0.022330226376652718, 0.0012515350244939327, 0.03955741599202156, 0.034602850675582886, -0.0075980848632752895, -0.05560057610273361, 0.04401763901114464, -0.031373560428619385, -0.04679428040981293, -0.00015281660307664424, 0.05890542268753052, -0.019112519919872284, -0.02808789722621441, 0.0020764812361449003, 0.016497071832418442, 0.005267312750220299, -0.003595433197915554, 0.023836949840188026, -0.021230479702353477, 0.01112350169569254, 0.010532228276133537, -0.038822077214717865, 0.013578096404671669, -0.004223907366394997, 0.01284179650247097, 0.03110506758093834, 0.020146889612078667, -0.0218161940574646, -0.0036042851861566305, -0.053407344967126846, 0.011450049467384815, 0.002359141130000353, 0.01161665003746748, -0.0023263029288500547, 0.021768206730484962, -0.041764289140701294, -0.01374275702983141, -0.041195761412382126, 0.04455313831567764, 0.015789031982421875, -0.037275832146406174, -0.02694115787744522, -0.025024933740496635, 0.007649821229279041, 0.011421049945056438, 0.029408251866698265, 0.008746393024921417, 0.06094074249267578, 0.028947891667485237, -0.028218397870659828, 0.005383246578276157, 0.026133481413125992 ]
How to train a new language model from scratch using Transformers and Tokenizers
julien-c
February 14, 2020
how-to-train
guide, nlp
https://huggingface.co/blog/how-to-train
6. Share your model 🎉 Finally, when you have a nice model, please think about sharing it with the community: - upload your model using the CLI: transformers-cli upload - write a README.md model card and add it to the repository under model_cards/. Your model card should ideally include: - a model description, - training params (dataset, preprocessing, hyperparameters), - evaluation results, - intended uses & limitations - whatever else is helpful! 🤓
[ 0.03290002420544624, -0.023994656279683113, 0.030820699408650398, 0.04428759217262268, 0.09049855917692184, 0.016455039381980896, -0.007614787667989731, 0.046422626823186874, -0.011227457784116268, -0.006832692306488752, -0.05399039760231972, 0.03721701353788376, 0.02508559264242649, 0.06200612336397171, -0.041073027998209, -0.02146114408969879, -0.018264954909682274, 0.024973412975668907, 0.00040845092735253274, 0.017711155116558075, 0.009755177423357964, -0.13632798194885254, 0.07305905967950821, -0.025404399260878563, 0.047768957912921906, -0.044771939516067505, 0.07814093679189682, 0.017182733863592148, -0.025338809937238693, 0.04825795069336891, -0.0826396495103836, -0.019048433750867844, 0.009378544986248016, -0.05056450143456459, -0.027447590604424477, 0.056256186217069626, -0.06724456697702408, 0.041470564901828766, 0.03546050563454628, -0.055454954504966736, 0.01813911460340023, -0.012801705859601498, -0.06964454054832458, 0.0418134443461895, 0.03506619483232498, -0.028531229123473167, -0.15838734805583954, 0.04673943296074867, -0.03826424106955528, 0.02525842934846878, -0.008485478349030018, 0.04325975477695465, -0.024149786680936813, 0.025847721844911575, 0.04863205924630165, 0.03462018072605133, -0.012448861263692379, -0.07721017301082611, -0.04370342195034027, 0.044786375015974045, 0.049806881695985794, 0.03854399174451828, 0.04940519481897354, 0.06568022072315216, 0.013765394687652588, 0.0037167693953961134, -0.028512433171272278, -0.016537176445126534, -0.04960986599326134, -0.04870445281267166, 0.029833951964974403, -0.029034672304987907, -0.00966665893793106, -0.10170166194438934, -0.012610088102519512, -0.04571474343538284, 0.04183494672179222, 0.035165831446647644, 0.09308478236198425, 0.06643321365118027, 0.03610343113541603, 0.009295902214944363, 0.02668694779276848, 0.042669232934713364, 0.02512379176914692, -0.008984921500086784, 0.02630387246608734, -0.016339192166924477, -0.08000743389129639, 0.01630420796573162, 0.009373597800731659, -0.09796738624572754, -0.036233194172382355, 0.04021107405424118, 0.10785151273012161, 0.017703022807836533, -0.01824965886771679, -0.02186886966228485, -0.0822119489312172, 0.0011515789665281773, -0.05750865116715431, 0.03382439538836479, 0.013194011524319649, -0.02565363235771656, -0.04053801670670509, 0.003570470493286848, 0.004077065270394087, -0.1442405730485916, -0.02706466056406498, 0.04289316013455391, -0.05947844684123993, -0.02660335600376129, 0.0013491531135514379, 0.02341577783226967, -0.024333110079169273, 0.04096315801143646, 0.0314120389521122, -0.0611959844827652, -0.004184613469988108, 0.02894316427409649, 0.010773912072181702, 0.08231855928897858, 0.0004057584155816585, 0.010334476828575134, 0.006328384857624769, 0.07367414236068726, 0.05267254263162613, -0.008242228999733925, -0.022220101207494736, -0.047152455896139145, 0.06818078458309174, -0.037601348012685776, 0.012690612114965916, -0.008602405898272991, 0.004608543124049902, -0.1287025660276413, 0.017940785735845566, -0.027696799486875534, 0.06205647811293602, 0.0351603701710701, -0.012941638007760048, 0.06107074022293091, -0.008088640868663788, -0.022425342351198196, 0.031397268176078796, -0.008950305171310902, -0.04826679080724716, 0.053048085421323776, 0.04286219924688339, 0.03522399067878723, -0.01806318573653698, 0.08354025334119797, 0.010966419242322445, -0.04835304617881775, 0.0037329525221139193, 0.056163039058446884, -0.04866710677742958, 0.04751237481832504, -0.06117578595876694, 0.009217556565999985, -0.008772600442171097, -0.02785666100680828, -0.047048021107912064, 0.030435362830758095, 0.003637440735474229, -0.04671984910964966, -0.025020547211170197, -0.030134184285998344, 0.053466252982616425, -0.005505270324647427, 0.0007922659278847277, -0.05591190978884697, 0.057856425642967224, -0.021100260317325592, 0.02588760107755661, 0.1045575812458992, 0.022462038323283195, 0.047895368188619614, 0.028511015698313713, -0.03410707414150238, -0.011886515654623508, 0.03995296731591225, -0.03475445881485939, 0.03209461644291878, 0.05042807385325432, -0.10544708371162415, -0.01095738634467125, -0.03834155201911926, -0.028978485614061356, 0.012640648521482944, -0.047757238149642944, -0.03963518142700195, 0.09418046474456787, -0.00836800318211317, 0.025582846254110336, -0.0310148186981678, -0.04218434914946556, 0.0868702158331871, 0.0016794116236269474, 0.049168284982442856, 0.017283763736486435, 0.007191406097263098, 0.012159593403339386, -0.02715972252190113, 0.004474031738936901, 0.020762428641319275, 0.03341378644108772, -0.06194773316383362, 0.03886279836297035, -0.004931911360472441, -0.00038201460847631097, -0.10960645228624344, 0.03279038146138191, -0.09268469363451004, 0.007776451297104359, -0.05475449562072754, -0.024639559909701347, 0.008422894403338432, -0.02020828239619732, 0.03255317732691765, 0.17141257226467133, 0.02399817295372486, -0.04931337386369705, -0.006643874105066061, -0.02367962896823883, 0.04697217047214508, 0.059313129633665085, 0.0653168335556984, 0.0950632244348526, -0.049214959144592285, -0.0018536709249019623, -0.03968850523233414, -0.06459406763315201, 0.08227955549955368, -0.013217384926974773, -0.0020486596040427685, -0.034676048904657364, -0.019026927649974823, -0.014840989373624325, -0.031124593690037727, -0.007425490766763687, 0.010268150828778744, 0.01829024776816368, -0.000008896120561985299, 0.022454921156167984, 0.025016048923134804, 0.06569919735193253, 0.04303488880395889, -0.03223539516329765, -0.019459767267107964, -0.0907188206911087, 0.061116937547922134, 0.02415960654616356, -0.0717511922121048, 0.046897388994693756, -0.032812803983688354, 0.0009554654825478792, -0.009283722378313541, -0.012989870272576809, 0.028479794040322304, 0.013662354089319706, 0.024693794548511505, -0.03556494414806366, -0.048963431268930435, 0.0289518553763628, -0.027295971289277077, 0.006935198325663805, -0.0078001003712415695, 0.005084942560642958, -0.01369620393961668, 0.022098759189248085, -0.02540842816233635, 0.011601188220083714, 0.015371429733932018, -0.005544896237552166, 0.01081022433936596, 0.007292408496141434, -0.014288016594946384, -0.027133477851748466, -0.015471036545932293, 0.002152909990400076, -0.01957741007208824, 0.00905027985572815, 0.02125966176390648, -0.008464349433779716, 0.012616605497896671, -0.01061666663736105, -0.05796661972999573, -0.024126356467604637, -0.001458743936382234, 0.01171085238456726, 0.04555730149149895, -0.017431875690817833, -0.005276123061776161, -0.01487401220947504, -0.012140865437686443, 0.002128438325598836, -0.01988879218697548, 0.0019599071238189936, 0.022016823291778564, 0.0019775377586483955, 0.020962737500667572, 0.03810565546154976, -0.008215882815420628, -0.04101124405860901, 0.009742935188114643, 0.0033456545788794756, -0.008776654489338398, -0.1092521920800209, -0.05595969781279564, -0.001059619477018714, 0.062145281583070755, 0.006961694452911615, -0.001552710309624672, 0.003163304878398776, -0.0191819928586483, -0.005451676435768604, 0.00669188192114234, 0.01598365604877472, 0.007511920761317015, 0.015936000272631645, 0.046111464500427246, -0.025072719901800156, 0.0011602299055084586, -0.02091001719236374, 0.021145589649677277, 0.047779276967048645, 0.046535100787878036, -0.024789029732346535, 0.023843230679631233, -0.012274324893951416, -0.01161258202046156, -0.01094148587435484, 0.02201903611421585, 0.05447585880756378, 0.040444716811180115, -0.02259841002523899, -0.032637812197208405, 0.006647184025496244, 0.01621313951909542, -0.0254193302243948, 0.014228119514882565, -0.006958799436688423, 0.007785426918417215, -0.011054917238652706, -0.001433779951184988, 0.014361021108925343, 0.027520185336470604, -0.0024736188352108, -0.018542109057307243, 0.035294294357299805, -0.008400097489356995, 0.022775644436478615, 0.00895334966480732, 0.03492492809891701, 0.00010232391650788486, 0.004834790248423815, -0.050351861864328384, -0.0011077240342274308, -0.012491816654801369, 0.04611131548881531, -0.0033015378285199404, -0.012846235185861588, -0.009448806755244732, 0.00976384337991476, 0.03313140943646431, 0.0005732577992603183, -0.015095187351107597, -0.05082663148641586, 0.004925941117107868, -0.022416524589061737, -0.02609710581600666, -0.02853856235742569, 0.09054550528526306, 0.00046719328383915126, 0.00020034167391713709, -0.018620287999510765, 0.050226300954818726, 0.008370259776711464, 0.040046434849500656, -0.006683918181806803, 0.009523666463792324, -0.015543825924396515, 0.025032727047801018, -0.02648991532623768, -0.027998559176921844, 0.057376183569431305, 0.0149832209572196, -0.022812705487012863, -0.027716590091586113, -0.03322374448180199, -0.013334638439118862, -0.009921636432409286, 0.013305175118148327, 0.0639423355460167, -0.025617310777306557, 0.02803622931241989, 0.026237545534968376, 0.009603822603821754, -0.033354680985212326, 0.03732128441333771, -0.024804916232824326, -0.007943973876535892, -0.045482002198696136, -0.0014714215649291873, 0.014276678673923016, -0.00940162967890501, -0.007687482051551342, 0.020516807213425636, -0.010168171487748623, 0.02492743358016014, 0.031862594187259674, -0.00793419498950243, 0.03554018959403038, -0.025304123759269714, -0.04371865466237068, 0.01612030155956745, -0.017920073121786118, 0.006720234639942646, -0.009753036312758923, -0.03439725935459137, -0.025746438652276993, 0.0038855529855936766, 0.03824764862656593, -0.026874635368585587, -0.003519756020978093, -0.004486924968659878, 0.05929143354296684, -0.036388784646987915, -0.009815629571676254, 0.009359416551887989, -0.03825501725077629, 0.017500367015600204, 0.0061564319767057896, 0.027738096192479134, 0.026269180700182915, -0.04281578212976456, 0.0018210414564236999, -0.038704533129930496, -0.014902517199516296, 0.048252400010824203, -0.008805208839476109, -0.01342909038066864, 0.05044034868478775, -0.0657634362578392, 0.06430342048406601, 0.03198344632983208, -0.005479314364492893, 0.008075998164713383, -0.0013093585148453712, 0.04548323526978493, -0.03198542445898056, 0.0370098352432251, -0.015599671751260757, -0.042102959007024765, -0.007506887894123793, -0.028872637078166008, -0.0017443880205973983, 0.028048066422343254, 0.0457017719745636, -0.014766791835427284, 0.021748464554548264, 0.03472669795155525, 0.01407186221331358, -0.012904857285320759, 0.018631797283887863, 0.007315553724765778, 0.026954183354973793, -0.03622262552380562, 0.006180043797940016, -0.04694707691669464, 0.0103810029104352, -0.005192429292947054, 0.04373486712574959, -0.003303459845483303, -0.08471313118934631, 0.026403632014989853, 0.004616276361048222, -0.030170314013957977, -0.012331141158938408, 0.02718920260667801, -0.06106256693601608, -0.019502710551023483, 0.031149812042713165, 0.0014577771071344614, 0.041963621973991394, 0.0025156692136079073, -0.006014678161591291, -0.027742836624383926, -0.019198449328541756, 0.0027605462819337845, -0.020373737439513206, -0.0008643966866657138, 0.026837920770049095, 0.06767810881137848, 0.0939384326338768, -0.0037690899334847927, -0.002945635700598359, 0.0013902763603255153, -0.0007673588115721941, -0.016630927100777626, -0.030094914138317108, -0.025728657841682434, -0.03208574280142784, 0.030364373698830605, 0.032446227967739105, -0.007450835779309273, 0.0178107637912035, 0.05194076895713806, 0.06872139871120453, -0.03594352677464485, 0.020824849605560303, 0.03137888386845589, -0.012734264135360718, -0.027103662490844727, 0.014898009598255157, 0.008073371835052967, -0.0325290709733963, -0.00024341001699212939, 0.005797553341835737, 0.013096475042402744, -0.019268617033958435, -0.04663019999861717, -0.015244667418301105, -0.05334889516234398, 0.006992586422711611, 0.009386132471263409, 0.06395206600427628, -0.00011377567716408521, -0.02685912698507309, -0.009147481992840767, 0.03694762662053108, 0.036198582500219345, -0.020709959790110588, 0.003942910116165876, -0.0075934580527246, 0.0021420232951641083, -0.003868150757625699, 0.019393885508179665, -0.008654913865029812, 0.0025175607297569513, 0.023453718051314354, 0.0008126376196742058, 0.014695671387016773, -0.06510009616613388, 0.040143419057130814, 0.008947250433266163, -0.031170684844255447, -0.020268654450774193, -0.03927239775657654, -0.06838230043649673, 0.02423717826604843, -0.0571693480014801, 0.01980113796889782, 0.07783990353345871, -0.015580848790705204, -0.017637260258197784, 0.001697647268883884, 0.01861201599240303, 0.0018798038363456726, 0.015083188191056252, 0.041682735085487366, -0.03080279380083084, 0.01183267217129469, -0.004113778937608004, 0.03410426527261734, -0.01951673813164234, 0.011856845580041409, 0.028792187571525574, -0.04401508718729019, -0.0039510163478553295, 0.03809000551700592, -0.02296321466565132, 0.01604357920587063, -0.0023332498967647552, -0.019686957821249962, 0.02449984848499298, -0.007316133007407188, 0.019806597381830215, 0.020329046994447708, 0.027231723070144653, 0.02685587666928768, -0.015440271236002445, 0.022735191509127617, 0.06493932008743286, 0.01936369761824608, -0.014951311983168125, 0.0519125759601593, -0.003520150203257799, 0.04351687431335449, 0.04696694761514664, -0.011534817516803741, -0.0023708923254162073, 0.027215326204895973, 0.0492381677031517, -0.008699364960193634, -0.009580748155713081, 0.02457457035779953, 0.024648919701576233, -0.04193243756890297, 0.003324381075799465, -0.00010503115481697023, -0.029218608513474464, 0.05106354504823685, 0.00422793859615922, -0.015116855502128601, -0.01739257574081421, 0.0007435735315084457, 0.047583915293216705, 0.017088713124394417, 0.02364082634449005, -0.026121683418750763, 0.04290763661265373, 0.06396327167749405, 0.01559505145996809, 0.04382947459816933, 0.018259797245264053, 0.02515685185790062, -0.03452915698289871, 0.035798050463199615, -0.01295068021863699, -0.005388188175857067, 0.0151212802156806, -0.009515272453427315, 0.009748199954628944, -0.023809585720300674, -0.00926342885941267, -0.02111511491239071, 0.047717440873384476, -0.003264225088059902, -0.03670146316289902, 0.05922279879450798, -0.03766029700636864, 0.017917128279805183, -0.013469187542796135, -0.023624224588274956, -0.005269903689622879, -0.03708485886454582, -0.005914710462093353, 0.04032967984676361, 0.016204727813601494, 0.027649100869894028, -0.007598884403705597, 0.03645889833569527, 0.008692814037203789, 0.05008665472269058, -0.006263246759772301, -0.03267107531428337, -0.06016923114657402, -0.004562443122267723, 0.0066879731602966785, 0.015520655550062656, 0.007999883964657784, -0.0016648732125759125, 0.007889565080404282, 0.02251718007028103, 0.007407577708363533, 0.03132760152220726, 0.0010892020072788, -0.009471679106354713, -0.03816468268632889, -0.01652717962861061, -0.02519039623439312, -0.05885792523622513, 0.0018424494192004204, -0.02619018778204918, 0.016742456704378128, -0.014608421362936497, 0.0008778295014053583, 0.021713662892580032, 0.016454169526696205, -0.04635486751794815, -0.04002493992447853, 0.012009339407086372, -0.0059962463565170765, -0.015676040202379227, 0.01599816046655178, -0.021427055820822716, -0.012811430729925632, 0.03018081746995449, 0.011233619414269924, 0.029108017683029175, 0.0005834063049405813, 0.023366620764136314, 0.040043171495199203, -0.028970975428819656, 0.009252375923097134, 0.0006608875119127333, 0.06296899169683456, 0.03531757742166519, 0.01705198548734188, 0.03513391315937042, 0.039860207587480545, -0.010374198667705059, -0.016790106892585754, -0.0023339493200182915, 0.013438232243061066, 0.012483164668083191, -0.015262003056704998, -0.03642812371253967, -0.02950715273618698, 0.0032313053961843252, 0.006841051392257214, 0.02536974474787712, -0.08510205894708633, -0.021226761862635612, -0.013892185874283314, -0.04305544123053551, -0.04688897728919983, 0.002798974048346281, 0.05578102916479111, 0.028447777032852173, 0.005658793728798628, -0.00441016536206007, -0.03854960575699806, 0.002995056565850973, -0.006946682929992676, 0.036077868193387985, 0.03118148259818554, -0.008063770830631256, -0.01275777630507946, -0.011399243958294392, 0.024341240525245667, -0.02962726354598999, -0.07126134634017944, -0.013696856796741486, 0.02183682844042778, -0.012384004890918732, -0.023229043930768967, -0.03958772495388985, 0.04891062155365944, -0.0010656374506652355, 0.012198843993246555, -0.030569808557629585, 0.005204701330512762, 0.0016719512641429901, 0.0010612583719193935, -0.05846545472741127, 0.032896656543016434, -0.03410854563117027, -0.014302672818303108, 0.03329487144947052, 0.0226450078189373, -0.013695086352527142, 0.018700674176216125, -0.038780294358730316, 0.02058078721165657, -0.012075508013367653, -0.021791262552142143, -0.05920575186610222, -0.009604456834495068, -0.008656884543597698, -0.03849933296442032, -0.04738793894648552, 0.011988471262156963, -0.005815573967993259, -0.015794729813933372, -0.00960452388972044, 0.01734713278710842, 0.0014386697439476848, 0.015582391992211342, -0.0006007908959873021, -0.04386713355779648, 0.00048204121412709355, 0.024984195828437805, -0.035533349961042404, -0.04692264273762703, 0.0010554059408605099 ]
How to train a new language model from scratch using Transformers and Tokenizers
julien-c
February 14, 2020
how-to-train
guide, nlp
https://huggingface.co/blog/how-to-train
2. Train a tokenizer We choose to train a byte-level Byte-pair encoding tokenizer (the same as GPT-2), with the same special tokens as RoBERTa. Let’s arbitrarily pick its size to be 52,000. We recommend training a byte-level BPE (rather than let’s say, a WordPiece tokenizer like BERT) because it will start building its vocabulary from an alphabet of single bytes, so all words will be decomposable into tokens (no more <unk> tokens!). python #! pip install tokenizers from pathlib import Path from tokenizers import ByteLevelBPETokenizer paths = [str(x) for x in Path("./eo_data/").glob("**/*.txt")] # Initialize a tokenizer tokenizer = ByteLevelBPETokenizer() # Customize training tokenizer.train(files=paths, vocab_size=52_000, min_frequency=2, special_tokens=[ "<s>", "<pad>", "</s>", "<unk>", "<mask>", ]) # Save files to disk tokenizer.save_model(".", "esperberto") And here’s a slightly accelerated capture of the output: On our dataset, training took about ~5 minutes. 🔥🔥 Wow, that was fast! ⚡️🔥 We now have both a vocab.json, which is a list of the most frequent tokens ranked by frequency, and a merges.txt list of merges. json { "<s>": 0, "<pad>": 1, "</s>": 2, "<unk>": 3, "<mask>": 4, "!": 5, "\"": 6, "#": 7, "$": 8, "%": 9, "&": 10, "'": 11, "(": 12, ")": 13, # ... } # merges.txt l a Ġ k o n Ġ la t a Ġ e Ġ d Ġ p # ... What is great is that our tokenizer is optimized for Esperanto. Compared to a generic tokenizer trained for English, more native words are represented by a single, unsplit token. Diacritics, i.e. accented characters used in Esperanto – ĉ, ĝ, ĥ, ĵ, ŝ, and ŭ – are encoded natively. We also represent sequences in a more efficient manner. Here on this corpus, the average length of encoded sequences is ~30% smaller as when using the pretrained GPT-2 tokenizer. Here’s how you can use it in tokenizers, including handling the RoBERTa special tokens – of course, you’ll also be able to use it directly from transformers. python from tokenizers.implementations import ByteLevelBPETokenizer from tokenizers.processors import BertProcessing tokenizer = ByteLevelBPETokenizer( "./models/EsperBERTo-small/vocab.json", "./models/EsperBERTo-small/merges.txt", ) tokenizer._tokenizer.post_processor = BertProcessing( ("</s>", tokenizer.token_to_id("</s>")), ("<s>", tokenizer.token_to_id("<s>")), ) tokenizer.enable_truncation(max_length=512) print( tokenizer.encode("Mi estas Julien.") ) # Encoding(num_tokens=7, ...) # tokens: ['<s>', 'Mi', 'Ġestas', 'ĠJuli', 'en', '.', '</s>']
[ 0.05093905329704285, -0.02071400173008442, 0.027971306815743446, 0.0011301814811304212, 0.057313695549964905, 0.07343178987503052, 0.032247256487607956, 0.049172356724739075, -0.04948524013161659, -0.029394881799817085, -0.08027844876050949, 0.05025390908122063, -0.026455692946910858, 0.04165637493133545, 0.021419426426291466, -0.03994966298341751, 0.042444173246622086, -0.03787270188331604, 0.004705488681793213, -0.05901097133755684, -0.03022402711212635, -0.018872635439038277, 0.10242405533790588, 0.006372462492436171, 0.025083858519792557, -0.04846636578440666, -0.027129510417580605, -0.010281804949045181, -0.009575426578521729, -0.012749784626066685, -0.11904408782720566, 0.014805994927883148, 0.018046380952000618, 0.014096014201641083, 0.03223501518368721, 0.05542304739356041, -0.12127507477998734, 0.04135768115520477, 0.05791320651769638, 0.003044773591682315, -0.0009735848871059716, 0.004699996206909418, -0.049235280603170395, 0.06751415878534317, -0.027452772483229637, 0.0010946464026346803, -0.16815289855003357, 0.10546678304672241, 0.011286349035799503, -0.09067085385322571, -0.062182702124118805, 0.08001372963190079, -0.02549351006746292, 0.049070216715335846, 0.014892878010869026, -0.0018299074145033956, -0.027156485244631767, -0.08915792405605316, 0.007964969612658024, 0.016392970457673073, 0.059491582214832306, -0.015056338161230087, -0.0031955258455127478, 0.026548901572823524, 0.05361160635948181, 0.009311141446232796, -0.09736581891775131, 0.062300778925418854, -0.06205330044031143, -0.06111018359661102, 0.03655458986759186, -0.03342922776937485, -0.04721449688076973, -0.012825953774154186, -0.038617074489593506, -0.04981740191578865, 0.034412931650877, -0.030314749106764793, 0.05075597018003464, 0.07295927405357361, 0.002824614755809307, 0.0465267039835453, 0.008012774400413036, 0.0075122700072824955, 0.080298513174057, 0.009646418504416943, 0.045542195439338684, -0.04303852468729019, -0.08350632339715958, 0.05750082805752754, -0.03382185846567154, -0.10104891657829285, -0.00500538619235158, 0.026898428797721863, 0.045153457671403885, 0.01758420281112194, -0.044935453683137894, 0.002879600739106536, 0.011734742671251297, 0.04188922047615051, -0.044974666088819504, -0.06459259241819382, 0.007292992435395718, -0.055837616324424744, -0.06968721747398376, 0.07184305787086487, 0.004121420904994011, -0.02364211529493332, -0.00944269634783268, 0.010490762069821358, 0.0027611262630671263, -0.02330915257334709, -0.03642403706908226, 0.060461219400167465, -0.05903766304254532, 0.04253506287932396, -0.016107255592942238, 0.028032764792442322, -0.06341058015823364, 0.07315228134393692, 0.04258041828870773, 0.06549075245857239, 0.08239027112722397, -0.030079016461968422, -0.0308093074709177, 0.0434299111366272, 0.02091185376048088, 0.05627552419900894, 0.0007595385541208088, -0.0022889841347932816, -0.00480214087292552, 0.003021468175575137, 0.03242873772978783, 0.007721663452684879, 0.001153404824435711, 0.019598618149757385, -0.006811866071075201, 0.0011145168682560325, 0.00007388862286461517, 0.009843958541750908, -0.08988559246063232, 0.06288682669401169, -0.04901571571826935, -0.028602590784430504, -0.0051555149257183075, 0.04971317574381828, -0.0953134074807167, 0.069790780544281, -0.001852962770499289, 0.0028185879345983267, -0.08337770402431488, 0.06345600634813309, 0.01597520336508751, -0.019496485590934753, 0.03732369467616081, 0.03519897535443306, -0.03419990465044975, -0.04809426888823509, -0.026122411713004112, -0.020903076976537704, -0.003599878866225481, -0.02447681874036789, -0.016536522656679153, 0.030721072107553482, -0.01853313110768795, -0.052230365574359894, 0.021421784535050392, 0.07766768336296082, -0.021003754809498787, 0.039365943521261215, 0.04074098542332649, 0.03829248249530792, 0.07711441814899445, 0.027589790523052216, -0.039264097809791565, 0.00935473944991827, 0.04215006157755852, 0.019751375541090965, 0.01865042746067047, -0.03902152180671692, -0.035543717443943024, 0.04223470762372017, -0.0248978640884161, 0.02142486907541752, 0.007613735273480415, -0.14421647787094116, -0.000816540268715471, -0.031766995787620544, 0.03682667016983032, 0.030974268913269043, -0.024938803166151047, -0.06463441252708435, 0.10988248139619827, 0.011344322934746742, 0.00036948861088603735, -0.048603273928165436, 0.03407502919435501, 0.1134515255689621, -0.006305895280092955, 0.023609016090631485, 0.03320744261145592, -0.006205020006746054, 0.025827335193753242, 0.000570018426515162, -0.008737960830330849, -0.04649033397436142, -0.04613601043820381, -0.05647509917616844, 0.04852354899048805, -0.021053355187177658, -0.013960304670035839, -0.05573860555887222, 0.022496135905385017, -0.0919121652841568, -0.01915583200752735, -0.0005627631326206028, 0.014562712050974369, 0.04896955192089081, 0.013624853454530239, -0.06359204649925232, 0.09627307206392288, -0.08199628442525864, -0.008214235305786133, -0.021562062203884125, -0.02195843681693077, 0.07658226788043976, 0.03578413650393486, -0.03099919483065605, 0.07827907800674438, -0.07441206276416779, -0.039107900112867355, -0.12494607269763947, 0.03152529150247574, 0.03073728084564209, -0.039416227489709854, -0.00247962842695415, 0.008169426582753658, -0.03147997334599495, 0.018288280814886093, -0.0514083132147789, -0.03747473657131195, -0.0179451797157526, -0.007413296028971672, 0.014112932607531548, -0.014458241872489452, 0.02933136560022831, 0.0957140177488327, 0.03549633547663689, -0.02625449188053608, -0.022644132375717163, -0.011451823636889458, 0.10331954807043076, -0.04076389595866203, -0.02245955914258957, 0.04409461095929146, 0.0015413217479363084, -0.01600341498851776, -0.017367849126458168, 0.010533704422414303, 0.03988027572631836, -0.0007727332995273173, 0.02606569416821003, -0.03933033347129822, 0.002258831635117531, 0.006307337898761034, -0.03366665914654732, -0.0005106372409500182, -0.003942341543734074, 0.015802357345819473, 0.012571397237479687, 0.012712113559246063, 0.00783257745206356, 0.034185539931058884, 0.016639817506074905, 0.0022417018190026283, 0.01494808029383421, 0.019818676635622978, -0.02426254190504551, -0.020533844828605652, -0.011838988400995731, 0.009598101489245892, -0.028572628274559975, 0.004707762971520424, 0.04396543279290199, -0.002707541221752763, 0.04478524252772331, 0.0017889206064864993, -0.0324622318148613, -0.011523591354489326, 0.037761837244033813, 0.00004704588354798034, 0.044694364070892334, -0.012683764100074768, -0.05240063741803169, -0.010510697029531002, 0.00406618369743228, -0.04529570788145065, 0.023253047838807106, 0.0251050665974617, 0.046283021569252014, 0.000903029867913574, 0.001979749882593751, -0.01959761418402195, -0.010243967175483704, -0.04232608526945114, 0.004250279627740383, -0.011514931917190552, 0.03784502297639847, -0.09403949975967407, -0.010900955647230148, -0.018147384747862816, 0.025039546191692352, 0.0011003118706867099, -0.022852368652820587, 0.03900708630681038, -0.010845331475138664, -0.020636145025491714, -0.008104744367301464, 0.02229120396077633, 0.01965099759399891, 0.009360019117593765, 0.01717316173017025, -0.032574765384197235, -0.005033704452216625, -0.013722377829253674, 0.005452493671327829, 0.02858935296535492, 0.043926138430833817, -0.010008564218878746, 0.03411468118429184, -0.0024864256847649813, 0.014870820567011833, -0.018176520243287086, -0.028257394209504128, -0.005008561071008444, 0.001246873871423304, 0.04894702136516571, -0.025451891124248505, -0.0353502556681633, -0.019033968448638916, 0.015747735276818275, 0.038213152438402176, -0.023791082203388214, 0.0371926948428154, 0.03008313663303852, 0.01902604289352894, -0.015281317755579948, 0.03337235376238823, -0.008898742496967316, -0.01909351348876953, 0.007574109360575676, -0.01779828779399395, 0.008410709910094738, -0.03395650535821915, 0.006220498122274876, -0.05734194442629814, 0.038432762026786804, -0.0183099415153265, -0.0062157344073057175, -0.030294939875602722, 0.018813975155353546, 0.038277264684438705, 0.004650424234569073, 0.025836292654275894, -0.019855501130223274, 0.03714490681886673, 0.03461496904492378, -0.0013529948191717267, -0.018043378368020058, 0.013314015232026577, 0.0017920283135026693, 0.00008975147648015991, -0.016944022849202156, 0.040247756987810135, -0.030982501804828644, -0.030956484377384186, -0.0108023164793849, 0.05940192565321922, -0.02157239429652691, 0.03493954986333847, -0.0018042776500806212, 0.0026754376012831926, -0.012290168553590775, 0.01817559450864792, -0.05073205754160881, 0.01953752338886261, 0.06519629806280136, 0.024620775133371353, -0.008694118820130825, -0.0015696329064667225, -0.050730329006910324, -0.006742075551301241, 0.02753104269504547, 0.0006735536153428257, 0.01082073338329792, -0.07225547730922699, -0.004477155394852161, 0.03492266684770584, -0.016824377700686455, -0.025037448853254318, -0.005238649435341358, 0.03146200254559517, -0.01596829481422901, 0.005040613003075123, 0.043451495468616486, 0.002508900361135602, -0.004341167397797108, 0.008060052990913391, 0.06128079444169998, -0.05046314001083374, 0.027511069551110268, -0.011579490266740322, 0.023425385355949402, 0.023609396070241928, -0.02585032396018505, -0.03651449829339981, 0.03570558875799179, 0.025350185111165047, 0.02170395478606224, 0.029548928141593933, -0.005422606132924557, -0.04162343218922615, 0.049313098192214966, 0.013724538497626781, -0.017290722578763962, 0.006317933090031147, 0.010277818888425827, 0.0099524250254035, -0.01721157133579254, 0.0054727285169065, 0.005441978573799133, -0.0029869331046938896, 0.042262908071279526, 0.028924087062478065, 0.0507378876209259, 0.008322572335600853, -0.0016478522447869182, 0.014824904501438141, -0.027063662186264992, -0.0013513584854081273, -0.022563720121979713, -0.019760988652706146, 0.03802002593874931, 0.008586759679019451, -0.02136652171611786, -0.02844088524580002, 0.01937064714729786, -0.039476048201322556, -0.0185234397649765, 0.0012295265914872289, 0.04488305002450943, -0.03588828817009926, 0.0009704093681648374, -0.015483953058719635, -0.0057969121262431145, -0.039375901222229004, -0.02144027128815651, -0.031602971255779266, 0.04399658739566803, -0.01035628654062748, -0.02945058047771454, -0.0034124325029551983, 0.03875889256596565, -0.04140699654817581, -0.0020963798742741346, 0.025046830996870995, 0.051914457231760025, 0.03794876113533974, 0.05041868984699249, 0.005271764472126961, -0.023132234811782837, 0.007197024300694466, 0.007044699043035507, -0.029762987047433853, 0.017997751012444496, -0.04353419691324234, 0.007804541848599911, 0.022055895999073982, -0.0003089343081228435, 0.02545485831797123, 0.030643031001091003, 0.005753738339990377, 0.04452591761946678, 0.04442155733704567, -0.020525135099887848, 0.042973220348358154, -0.05607165768742561, 0.036541618406772614, -0.029975978657603264, -0.012635873630642891, -0.009501008316874504, -0.016054043546319008, -0.0370965451002121, 0.04729732498526573, 0.04758016765117645, 0.052256785333156586, -0.018202077597379684, 0.04116110876202583, -0.03482886403799057, -0.026722174137830734, 0.014268970116972923, -0.01632380671799183, 0.009269995614886284, -0.018015949055552483, -0.045947425067424774, 0.02934993989765644, -0.029387755319476128, 0.00412138644605875, 0.008866315707564354, 0.0349862240254879, -0.004838587716221809, -0.033870480954647064, 0.03350403159856796, 0.016537467017769814, -0.008320963010191917, -0.027748487889766693, 0.013173092156648636, -0.004617593251168728, -0.020089754834771156, -0.005082465708255768, -0.01959805004298687, -0.00647574570029974, 0.007448452524840832, 0.004847323056310415, -0.006666719447821379, 0.06271360069513321, -0.004541889298707247, 0.05731829255819321, -0.07019536942243576, -0.004786087200045586, -0.0316024124622345, -0.00012715652701444924, 0.02926640585064888, -0.04242481663823128, -0.007379470393061638, 0.02001609280705452, 0.01033799909055233, 0.014125948771834373, 0.014348480850458145, -0.017118098214268684, 0.003159184940159321, 0.06362389028072357, 0.010880175046622753, -0.05545375496149063, -0.012820395641028881, 0.01977206952869892, 0.07675781100988388, 0.013600978069007397, 0.020274458453059196, -0.006926049944013357, -0.03550794720649719, -0.014071819372475147, -0.03317907080054283, 0.021590961143374443, 0.03643214702606201, -0.002719394164159894, 0.00022849264496471733, 0.02390730008482933, 0.044006045907735825, -0.0029912455938756466, -0.01287943497300148, 0.02044885978102684, 0.05027994140982628, 0.014670808799564838, 0.018007362261414528, -0.011396560817956924, 0.005279615055769682, 0.005664434749633074, 0.017424898222088814, -0.0695192962884903, 0.03273535147309303, 0.038267072290182114, 0.007742488756775856, 0.005278031807392836, 0.01276432815939188, -0.037026211619377136, 0.005602284334599972, 0.022705335170030594, 0.01355550903826952, 0.012869295664131641, -0.025127658620476723, -0.000013320448488229886, -0.015645436942577362, -0.013124697841703892, 0.013663815334439278, 0.04216435179114342, -0.00898802187293768, 0.05373266339302063, 0.010865363292396069, 0.006453349255025387, 0.04372183978557587, -0.015137136913836002, -0.01224132813513279, 0.0022968873381614685, 0.02670619636774063, 0.010085719637572765, 0.03823336586356163, 0.02028866671025753, -0.004562211688607931, -0.02096295915544033, -0.04428936913609505, 0.009830988012254238, -0.022036923095583916, -0.014053530991077423, 0.04468362033367157, -0.03505800664424896, 0.00561312073841691, -0.021411355584859848, 0.021652905270457268, 0.03171259164810181, 0.03798716887831688, -0.04353776574134827, 0.026467885822057724, 0.014855336397886276, 0.027042249217629433, 0.018389316275715828, 0.012460875324904919, 0.045248739421367645, -0.024973848834633827, 0.04020338132977486, 0.02234700880944729, 0.042042043060064316, 0.05090468376874924, -0.005111582111567259, 0.03987980633974075, -0.04542570561170578, -0.015211937017738819, 0.012220093049108982, 0.01953227072954178, -0.0032856096513569355, -0.010702388361096382, 0.0011613003443926573, -0.047822337597608566, 0.0028354679234325886, -0.02394477091729641, -0.006265413947403431, -0.023169565945863724, -0.0014729266986250877, 0.036845866590738297, 0.049092452973127365, 0.03820585086941719, -0.03868035972118378, 0.004038988146930933, -0.01949935592710972, -0.00041133342892862856, 0.014225595630705357, -0.025285771116614342, -0.0325980968773365, 0.003040285548195243, -0.03182681277394295, -0.015794847160577774, 0.016766691580414772, -0.04593495652079582, -0.031052187085151672, -0.01997731626033783, 0.004812626633793116, -0.037215523421764374, -0.002685388084501028, 0.007119797170162201, 0.020069148391485214, -0.029796777293086052, 0.004636184778064489, 0.021946318447589874, -0.03576939180493355, 0.02532622590661049, -0.051024023443460464, -0.00844019465148449, -0.02566196396946907, 0.04373876750469208, 0.03563021123409271, 0.038282498717308044, -0.003346492303535342, -0.06227346882224083, -0.029997892677783966, -0.014538394287228584, -0.0277789868414402, 0.02941361628472805, 0.023352833464741707, -0.01503923162817955, -0.026631828397512436, -0.044309332966804504, -0.02556612342596054, -0.022897429764270782, -0.01218874566257, 0.002723354147747159, -0.034615881741046906, -0.016434630379080772, -0.03182259574532509, 0.019904524087905884, 0.022633500397205353, 0.00004436524977791123, 0.0366688035428524, -0.008431370370090008, 0.011760532855987549, -0.006219984497874975, -0.004362252540886402, -0.07022762298583984, -0.0006143784848973155, -0.03422836586833, -0.03340078145265579, -0.03632747381925583, 0.0012986580841243267, -0.01647401973605156, 0.01528574712574482, -0.05629930645227432, 0.0009235418401658535, -0.05293884500861168, 0.024583425372838974, 0.01326063647866249, -0.020442374050617218, 0.03228287398815155, -0.005642286967486143, -0.0030162131879478693, 0.050840239971876144, -0.002813163213431835, -0.009667783975601196, 0.02759796939790249, -0.0005897182272747159, 0.08187631517648697, 0.04107408970594406, -0.03300217166543007, -0.05346012860536575, -0.0006090854876674712, 0.0037625215481966734, -0.031638242304325104, -0.008482658304274082, -0.024718528613448143, 0.007130712736397982, 0.008300764486193657, 0.022690583020448685, -0.014482115395367146, -0.0083564892411232, 0.029073333367705345, 0.007508752401918173, -0.004602562636137009, 0.020360583439469337, 0.021784169599413872, -0.08240194618701935, 0.0038645740132778883, -0.009020345285534859, -0.004969736561179161, 0.027174264192581177, 0.01618671976029873, 0.02087879367172718, 0.02062012441456318, -0.042960166931152344, -0.00418469263240695, 0.02631022222340107, -0.02713913656771183, -0.011259184218943119, 0.03783293068408966, 0.023981673642992973, -0.04381588473916054, -0.02453700825572014, 0.07118373364210129, 0.020071187987923622, -0.06119215115904808, -0.02071209065616131, -0.043905265629291534, 0.03955617547035217, -0.005209065042436123, 0.034455519169569016, 0.0012982786865904927, 0.048709042370319366, 0.03340417891740799, 0.005829147063195705, 0.005405339878052473, 0.017074622213840485 ]
How to train a new language model from scratch using Transformers and Tokenizers
julien-c
February 14, 2020
how-to-train
guide, nlp
https://huggingface.co/blog/how-to-train
1. Find a dataset First, let us find a corpus of text in Esperanto. Here we’ll use the Esperanto portion of the OSCAR corpus from INRIA. OSCAR is a huge multilingual corpus obtained by language classification and filtering of Common Crawl dumps of the Web. The Esperanto portion of the dataset is only 299M, so we’ll concatenate with the Esperanto sub-corpus of the Leipzig Corpora Collection, which is comprised of text from diverse sources like news, literature, and wikipedia. The final training corpus has a size of 3 GB, which is still small – for your model, you will get better results the more data you can get to pretrain on.
[ -0.002777343848720193, -0.02532578818500042, 0.011824551038444042, 0.023398565128445625, 0.05580642446875572, 0.03158360347151756, 0.03352586179971695, 0.01190439984202385, -0.05229681357741356, 0.011564459651708603, -0.06763749569654465, 0.0338510163128376, 0.005564113613218069, 0.015180225484073162, 0.08657747507095337, -0.051040925085544586, 0.03815640136599541, 0.03718758746981621, 0.0010909378761425614, -0.011291100643575191, -0.05481184273958206, 0.017733529210090637, 0.06911177933216095, 0.009066395461559296, 0.03811083734035492, -0.03932041674852371, 0.03438239172101021, 0.08151248842477798, -0.03765566274523735, 0.0045792837627232075, -0.11217910796403885, -0.025116074830293655, 0.008911602199077606, -0.011283347383141518, -0.09357325732707977, 0.06748909503221512, -0.0855209082365036, 0.0697130560874939, 0.0033392144832760096, -0.031911060214042664, -0.03388528525829315, 0.018443772569298744, -0.03823418915271759, 0.0807972177863121, 0.002728882012888789, -0.027812551707029343, -0.13813096284866333, 0.05023316293954849, -0.03586554899811745, -0.03133110702037811, -0.0577772855758667, 0.012388988398015499, -0.04442187026143074, 0.04694618657231331, 0.014226439408957958, 0.008317932486534119, 0.03611987829208374, -0.08228783309459686, 0.014497148804366589, 0.006039333995431662, 0.005091964732855558, 0.03966231644153595, -0.004963725805282593, 0.04446689411997795, 0.018537841737270355, 0.017680726945400238, -0.04530361667275429, -0.008715186268091202, -0.03805244714021683, -0.04000521078705788, 0.050743043422698975, -0.011458029970526695, -0.02412818744778633, -0.03209639713168144, -0.0013276104582473636, -0.09327463805675507, -0.0026202592998743057, 0.028723422437906265, 0.001679863897152245, -0.0021713273599743843, -0.006409156136214733, 0.04534322768449783, 0.04107275605201721, 0.04408101364970207, 0.10792019218206406, 0.00915074534714222, 0.01746724732220173, -0.013436875306069851, -0.06263262033462524, 0.006722285877913237, 0.025953931733965874, -0.07267379760742188, 0.011089351959526539, 0.04477992653846741, 0.05010285601019859, -0.04462314397096634, 0.037000611424446106, 0.05476963147521019, -0.03791211172938347, 0.0501793809235096, -0.05625369772315025, -0.027244972065091133, 0.029353616759181023, -0.11807888001203537, -0.10707033425569534, 0.008495285175740719, 0.012691842392086983, -0.02106909267604351, -0.001958407461643219, 0.026855947449803352, 0.030974287539720535, -0.003303835866972804, -0.04067832604050636, 0.0074451761320233345, -0.11380141228437424, -0.004779459442943335, 0.07182478159666061, 0.03858328238129616, -0.039769817143678665, 0.06479897350072861, 0.005130593664944172, 0.0975286141037941, 0.047663118690252304, 0.0700279250741005, -0.036146845668554306, 0.0657893642783165, 0.024111073464155197, 0.003719949396327138, 0.02092069946229458, 0.013938984833657742, 0.0350809171795845, -0.07136623561382294, 0.08331094682216644, -0.02852792851626873, -0.0239181499928236, 0.02372962050139904, -0.00279519846662879, 0.01899111643433571, 0.06086665764451027, -0.015537247993052006, -0.05182170495390892, 0.010684771463274956, -0.10371778905391693, 0.006427395157516003, 0.056287817656993866, 0.000326408859109506, -0.08306793123483658, 0.035512130707502365, -0.003048111917451024, 0.03187916427850723, -0.07063020020723343, 0.08017577230930328, -0.022009406238794327, -0.04833881929516792, 0.05909764766693115, 0.009143947623670101, 0.009195790626108646, -0.059769369661808014, -0.06425808370113373, 0.011154180392622948, 0.01256238017231226, 0.005315358284860849, -0.020462898537516594, 0.04312780126929283, 0.008401349186897278, -0.09378407895565033, -0.012525615282356739, 0.0787540003657341, -0.026140626519918442, 0.0034872007090598345, -0.01705501414835453, -0.042504001408815384, 0.10906589776277542, -0.018440138548612595, -0.04731682315468788, 0.003329142462462187, 0.014128599315881729, 0.005789313465356827, -0.001473025418817997, -0.014908617362380028, 0.02402443252503872, 0.012375139631330967, -0.048607710748910904, 0.03219442442059517, 0.00775888841599226, -0.06880898773670197, 0.06393203884363174, -0.007281402125954628, -0.01899687945842743, -0.029696809127926826, 0.01434143353253603, -0.05659780651330948, 0.043364331126213074, -0.009562301449477673, -0.017300479114055634, -0.043184857815504074, 0.029255827888846397, 0.08838478475809097, 0.07068801671266556, 0.08313276618719101, 0.0017991934437304735, -0.005554282106459141, 0.04405738785862923, 0.01676000840961933, -0.024598298594355583, -0.050596725195646286, -0.007663463242352009, -0.03049572929739952, 0.0018465719185769558, -0.03975581005215645, -0.0029527703300118446, -0.0664435476064682, 0.031604066491127014, -0.1006806269288063, -0.0152858542278409, -0.018619172275066376, 0.017788182944059372, 0.05698409304022789, 0.00506317475810647, -0.040633656084537506, 0.16147680580615997, -0.053934499621391296, -0.04531973972916603, 0.06674742698669434, -0.05238324776291847, 0.0546974241733551, 0.04969271272420883, 0.061635810881853104, 0.02899758890271187, -0.07397767156362534, 0.005131414160132408, 0.002051340416073799, 0.04867153242230415, 0.03682243451476097, -0.03262418136000633, -0.05935923755168915, 0.01405720878392458, 0.0036796494387090206, 0.019105449318885803, 0.02715911902487278, -0.011113893240690231, -0.038439638912677765, -0.03924534469842911, 0.04466947168111801, 0.009902196936309338, 0.015537506900727749, 0.11584769189357758, 0.007749148644506931, -0.04116478189826012, 0.019106734544038773, 0.002387681510299444, 0.006767054088413715, -0.023039763793349266, -0.08702821284532547, -0.048092857003211975, 0.002066272310912609, 0.025948455557227135, -0.023907268419861794, -0.026578370481729507, 0.012194034643471241, 0.003585967468097806, 0.0014068403979763389, -0.00818571262061596, -0.027660077437758446, 0.03771581873297691, -0.023456105962395668, 0.0022923131473362446, 0.004785425029695034, 0.012557738460600376, -0.008881445042788982, 0.027455268427729607, -0.005394811276346445, 0.03768329322338104, -0.010162010788917542, -0.012522069737315178, 0.02477179653942585, 0.0040900264866650105, -0.03845175355672836, -0.02073686383664608, -0.0038595586083829403, -0.03592965379357338, -0.05308354273438454, 0.0297903623431921, 0.015309302136301994, 0.005159204825758934, -0.019544800743460655, 0.011701184324920177, -0.03846949338912964, 0.008827698417007923, 0.02682623825967312, -0.005588202271610498, 0.023559831082820892, -0.0017345813103020191, -0.026829548180103302, 0.006074038799852133, -0.016446806490421295, 0.0037854008842259645, -0.0066076177172362804, -0.018451141193509102, 0.02734193578362465, -0.05541304871439934, -0.005741105414927006, 0.018080102279782295, 0.00047239300329238176, -0.03108956851065159, 0.024404743686318398, -0.016203753650188446, 0.03493289649486542, -0.09544239193201065, 0.03408467024564743, 0.0032158885151147842, 0.023130763322114944, -0.004412900656461716, -0.019368626177310944, -0.002505103824660182, 0.019621742889285088, -0.0264130849391222, -0.0048944964073598385, 0.023596985265612602, -0.013709788210690022, 0.04521726444363594, 0.05449816957116127, -0.021549394354224205, 0.021717822179198265, -0.04889495298266411, 0.016509301960468292, 0.04404619708657265, 0.03538024052977562, -0.029192686080932617, 0.0319695770740509, 0.02132679894566536, 0.053666990250349045, -0.015207905322313309, 0.018148217350244522, 0.0029963962733745575, 0.00808214582502842, 0.031868621706962585, -0.0007933195447549224, 0.003754155244678259, -0.01828678324818611, -0.036872055381536484, 0.023505857214331627, -0.03262251242995262, 0.017219386994838715, 0.00011552005162229761, 0.050372686237096786, -0.003048927756026387, 0.05905502289533615, -0.007100551389157772, -0.05162319168448448, 0.044005248695611954, -0.006607145071029663, 0.0013483266811817884, -0.02621336653828621, -0.02498030662536621, 0.001683899899944663, -0.01649530604481697, -0.04894189164042473, -0.022876372560858727, -0.036559075117111206, 0.02768922969698906, 0.0894363671541214, -0.00925888866186142, 0.00800693966448307, 0.06976078450679779, -0.0130414217710495, 0.03404261916875839, -0.023474015295505524, -0.01115858182311058, 0.040155079215765, 0.01530391350388527, -0.041269585490226746, -0.04679250717163086, 0.04142927750945091, 0.01302734762430191, 0.02620796300470829, -0.04728148877620697, 0.0661446824669838, -0.012326791882514954, 0.03693190962076187, 0.06698364019393921, -0.007355017121881247, -0.02905532717704773, 0.007132767699658871, 0.02805262804031372, 0.005415207240730524, 0.00812762975692749, 0.03466402366757393, -0.038337863981723785, 0.026293445378541946, -0.054203249514102936, -0.04687324911355972, 0.005877668038010597, -0.031147683039307594, 0.01714298501610756, -0.06678862869739532, 0.034062646329402924, 0.03490667790174484, 0.011752644553780556, -0.030770916491746902, 0.0013708570040762424, -0.002602061489596963, 0.00013379857409745455, 0.008236320689320564, -0.012807267718017101, -0.018988775089383125, -0.0006670436123386025, -0.008449756540358067, 0.021775199100375175, -0.01046705711632967, -0.006664054002612829, -0.01604561321437359, 0.05587855726480484, 0.0014248376246541739, -0.033660948276519775, -0.016539985314011574, 0.01882612518966198, -0.02325379103422165, 0.02005585841834545, -0.0305208470672369, 0.02466966025531292, 0.013937490060925484, 0.015222068876028061, 0.00266628572717309, -0.0567663311958313, -0.01672121323645115, -0.040556445717811584, -0.0019796115811914206, -0.022467074915766716, -0.005447261035442352, -0.0066545153968036175, 0.012333976104855537, 0.016954807564616203, -0.012414513155817986, 0.005341976415365934, 0.030286844819784164, 0.001461840351112187, -0.030498748645186424, -0.031395215541124344, 0.0186280757188797, 0.043896980583667755, 0.01589978300035, -0.0067733461037278175, -0.003939975518733263, -0.0531548373401165, -0.01696722023189068, 0.009364981204271317, -0.03820418193936348, -0.012071151286363602, -0.044726140797138214, 0.014640722423791885, -0.010865523479878902, -0.008439727127552032, -0.03366834297776222, -0.002032212447375059, -0.04950299486517906, -0.014971104450523853, -0.006190319079905748, 0.012316369451582432, 0.014507961459457874, -0.03520220145583153, 0.022573105990886688, 0.01606479287147522, -0.040015194565057755, 0.009339041076600552, 0.033354297280311584, 0.0106024956330657, 0.04168127104640007, -0.02175312303006649, -0.030149394646286964, -0.04834164306521416, 0.014559874311089516, 0.005857713520526886, -0.03662228211760521, 0.03973369672894478, -0.031007979065179825, -0.009148240089416504, 0.015719905495643616, 0.0136073874309659, 0.032991886138916016, -0.004465346224606037, -0.009298591874539852, 0.024409078061580658, 0.019039038568735123, -0.0030172138940542936, 0.06471305340528488, -0.023457249626517296, -0.009564419277012348, -0.0550304539501667, 0.0042435829527676105, 0.0005851018358953297, 0.006876006722450256, -0.04109213501214981, 0.041933342814445496, 0.03810492157936096, 0.050358451902866364, 0.028370629996061325, 0.025404592975974083, -0.02145414426922798, 0.035129427909851074, 0.017158104106783867, -0.027682997286319733, -0.014604831114411354, -0.013246272690594196, -0.008776545524597168, -0.009267470799386501, -0.04113338142633438, -0.00927539449185133, 0.026303961873054504, 0.006038259249180555, -0.012035662308335304, 0.005365349352359772, 0.005158326122909784, 0.0031138614285737276, -0.018030982464551926, -0.024743802845478058, -0.002292809309437871, -0.012036307714879513, -0.04482036456465721, 0.009095883928239346, -0.029787296429276466, 0.03309764713048935, -0.020155765116214752, -0.06830677390098572, -0.012319238856434822, 0.024964116513729095, 0.021182242780923843, 0.05324013531208038, 0.00247407634742558, -0.045625343918800354, -0.02690865285694599, 0.05936668813228607, 0.011713105253875256, -0.056220561265945435, 0.04490790143609047, 0.0017316393787041306, 0.013056629337370396, -0.009135975502431393, 0.03250274434685707, -0.02277158387005329, 0.0270504429936409, 0.04582704231142998, 0.01233750768005848, -0.012812509201467037, 0.002619092585518956, 0.013566447421908379, 0.051860421895980835, 0.0317370630800724, -0.005726474802941084, -0.02685297466814518, -0.038057684898376465, 0.012319587171077728, 0.023678019642829895, 0.050604116171598434, 0.012774092145264149, 0.007673276588320732, 0.050180140882730484, -0.005938604939728975, 0.04320058971643448, -0.0006201352225616574, -0.014807472936809063, 0.03365259990096092, -0.008652311749756336, 0.04236958548426628, 0.01192812342196703, -0.008347408846020699, -0.012628735974431038, 0.038965772837400436, 0.011448300443589687, -0.05364444479346275, 0.0279603973031044, 0.018170323222875595, -0.03281554952263832, -0.00884893350303173, 0.02219810150563717, -0.07678578048944473, 0.019195787608623505, 0.055818259716033936, 0.02482016384601593, 0.028172843158245087, -0.016581326723098755, -0.004552491940557957, -0.022389264777302742, -0.015506281517446041, -0.012897120788693428, 0.021299757063388824, -0.01743566431105137, 0.07222827523946762, -0.020794721320271492, 0.01979355700314045, 0.014429133385419846, -0.027451898902654648, -0.03824562206864357, 0.015271486714482307, 0.027394212782382965, 0.04428655654191971, 0.04819140210747719, -0.012631946243345737, -0.023405490443110466, -0.012884199619293213, -0.01655714586377144, 0.01318837609142065, -0.037766117602586746, -0.012444894760847092, 0.04019186645746231, -0.06651733070611954, -0.04014795646071434, -0.050970204174518585, 0.043825775384902954, 0.016289973631501198, 0.010828674770891666, -0.04462574049830437, 0.037748683243989944, 0.001635957625694573, 0.015342127531766891, 0.07208213955163956, 0.028823137283325195, 0.011636544950306416, -0.011072437278926373, 0.009792216122150421, 0.06588482856750488, 0.05848751962184906, 0.028488321229815483, -0.0045824237167835236, 0.04033153876662254, -0.038651179522275925, -0.020616116002202034, -0.007628771476447582, -0.008066088892519474, -0.03245319426059723, 0.011440902948379517, 0.04562235251069069, -0.04783956706523895, 0.014858700335025787, -0.03878924250602722, 0.02650730311870575, 0.008789029903709888, -0.010361382737755775, -0.007721719332039356, 0.0382806770503521, -0.020808303728699684, -0.001573653076775372, -0.054042648524045944, 0.012925141490995884, 0.03970599174499512, -0.0020774637814611197, -0.021170884370803833, -0.030597444623708725, -0.007738697808235884, -0.028775695711374283, 0.008334816433489323, 0.021114544942975044, 0.03485802188515663, -0.061282094568014145, 0.0028195518534630537, 0.0001267230254597962, 0.011088186874985695, 0.011448124423623085, 0.01633518561720848, 0.021575473248958588, -0.009557299315929413, 0.014971330761909485, 0.002057519508525729, -0.04902457818388939, -0.031245360150933266, -0.04262514039874077, -0.0009218117920681834, 0.014613213948905468, -0.019962333142757416, 0.046085670590400696, 0.05316827818751335, 0.030845295637845993, -0.06217096373438835, 0.02216370403766632, -0.02609473280608654, -0.01049270760267973, 0.04286722093820572, -0.012914194725453854, -0.01379744429141283, -0.022510264068841934, -0.02144174836575985, -0.020498601719737053, -0.03303738310933113, -0.037735868245363235, 0.028587257489562035, -0.031845252960920334, -0.033818308264017105, -0.025526268407702446, -0.01407101284712553, 0.009916762821376324, -0.01930498518049717, 0.0689048245549202, 0.011561952531337738, 0.02234593965113163, -0.01588241197168827, 0.04160767421126366, -0.0038221036083996296, 0.04678865149617195, -0.03380042314529419, -0.03903941810131073, -0.02657264471054077, -0.001366844866424799, -0.033094462007284164, -0.04212705418467522, -0.05098829045891762, -0.025022253394126892, -0.040423523634672165, 0.006791689898818731, -0.028984002768993378, 0.03318718075752258, 0.037019651383161545, 0.020208539441227913, 0.03510979935526848, 0.03573869541287422, 0.029071731492877007, 0.044236380606889725, -0.02380412258207798, -0.007075691595673561, 0.03371953219175339, 0.0022156937047839165, -0.004005047492682934, 0.015231349505484104, 0.00023963034618645906, -0.02009756863117218, -0.03977267071604729, -0.024149654433131218, 0.02818015031516552, 0.04293958470225334, -0.012368852272629738, -0.004850163124501705, -0.01950390823185444, 0.020104175433516502, 0.020856931805610657, 0.01473580114543438, -0.02890758030116558, 0.036815375089645386, 0.010575562715530396, -0.034813426434993744, 0.007226528599858284, 0.012644554488360882, -0.014660445041954517, 0.047906581312417984, 0.003228484420105815, 0.017668917775154114, 0.01564211957156658, -0.007262914441525936, 0.007431886158883572, 0.00863447692245245, -0.006685289554297924, -0.020388390868902206, 0.04819266125559807, 0.032804880291223526, -0.023665398359298706, 0.014468405395746231, 0.04672447592020035, 0.02655351348221302, -0.0025656595826148987, -0.034907907247543335, -0.015724847093224525, 0.04484209045767784, 0.01611838862299919, 0.0018680213252082467, -0.014838334172964096, 0.019999999552965164, 0.011012990958988667, 0.0266452357172966, -0.0071352762170135975, 0.009965639561414719 ]
How to train a new language model from scratch using Transformers and Tokenizers
julien-c
February 14, 2020
how-to-train
guide, nlp
https://huggingface.co/blog/how-to-train
4. Check that the LM actually trained Aside from looking at the training and eval losses going down, the easiest way to check whether our language model is learning anything interesting is via the FillMaskPipeline. Pipelines are simple wrappers around tokenizers and models, and the 'fill-mask' one will let you input a sequence containing a masked token (here, <mask>) and return a list of the most probable filled sequences, with their probabilities. python from transformers import pipeline fill_mask = pipeline( "fill-mask", model="./models/EsperBERTo-small", tokenizer="./models/EsperBERTo-small" ) # The sun <mask>. # => result = fill_mask("La suno <mask>.") # {'score': 0.2526160776615143, 'sequence': '<s> La suno brilis.</s>', 'token': 10820} # {'score': 0.0999930202960968, 'sequence': '<s> La suno lumis.</s>', 'token': 23833} # {'score': 0.04382849484682083, 'sequence': '<s> La suno brilas.</s>', 'token': 15006} # {'score': 0.026011141017079353, 'sequence': '<s> La suno falas.</s>', 'token': 7392} # {'score': 0.016859788447618484, 'sequence': '<s> La suno pasis.</s>', 'token': 4552} Ok, simple syntax/grammar works. Let’s try a slightly more interesting prompt: python fill_mask("Jen la komenco de bela <mask>.") # This is the beginning of a beautiful <mask>. # => # { # 'score':0.06502299010753632 # 'sequence':'<s> Jen la komenco de bela vivo.</s>' # 'token':1099 # } # { # 'score':0.0421181358397007 # 'sequence':'<s> Jen la komenco de bela vespero.</s>' # 'token':5100 # } # { # 'score':0.024884626269340515 # 'sequence':'<s> Jen la komenco de bela laboro.</s>' # 'token':1570 # } # { # 'score':0.02324388362467289 # 'sequence':'<s> Jen la komenco de bela tago.</s>' # 'token':1688 # } # { # 'score':0.020378097891807556 # 'sequence':'<s> Jen la komenco de bela festo.</s>' # 'token':4580 # } > “Jen la komenco de bela tago”, indeed! With more complex prompts, you can probe whether your language model captured more semantic knowledge or even some sort of (statistical) common sense reasoning.
[ 0.07899538427591324, -0.04066430777311325, 0.011012708768248558, -0.0335247777402401, 0.04120038077235222, 0.044754620641469955, 0.05697348341345787, 0.0530204214155674, -0.05088852718472481, 0.03892305865883827, -0.04258105158805847, 0.09202717244625092, 0.07789108902215958, 0.0617528036236763, -0.001470831804908812, -0.010496214032173157, 0.03630558401346207, 0.0016617235960438848, 0.010492450557649136, 0.004678561817854643, -0.0253139715641737, -0.06078602746129036, 0.0899982750415802, -0.02459460310637951, 0.02732986956834793, -0.051346153020858765, 0.02407267689704895, -0.010110268369317055, -0.07196851819753647, 0.008882853202521801, -0.10189902782440186, 0.03953391686081886, 0.0017366856336593628, -0.023659342899918556, -0.03744637221097946, 0.07737786322832108, -0.10751642286777496, 0.0491986982524395, 0.048282090574502945, 0.009769671596586704, 0.02642051689326763, -0.026702312752604485, -0.014512729831039906, 0.009420848451554775, -0.030614033341407776, -0.060403939336538315, -0.16022345423698425, 0.005498428829014301, -0.04233192279934883, -0.050077296793460846, -0.05410638451576233, 0.050633493810892105, -0.021640906110405922, -0.01921854168176651, -0.009591133333742619, -0.04251343756914139, 0.0015019240090623498, -0.05451340600848198, 0.007015049923211336, 0.010775831528007984, -0.007789173163473606, 0.0455051064491272, -0.01342506892979145, 0.015469979494810104, 0.007031349930912256, -0.009997230023145676, -0.004012192599475384, 0.050230976194143295, -0.061807647347450256, -0.0645008385181427, -0.011087938211858273, 0.014264659024775028, -0.0002666598011273891, 0.004767348058521748, 0.0444810725748539, -0.04349895566701889, -0.01183905079960823, 0.08023904263973236, -0.029239509254693985, 0.04744817689061165, 0.013992488384246826, 0.02509947307407856, 0.020973049104213715, 0.02009514346718788, 0.028911951929330826, 0.019711937755346298, 0.07965000718832016, -0.03460746631026268, -0.009789329022169113, 0.03151577338576317, -0.010751551948487759, -0.12256573140621185, -0.04126514494419098, 0.010075105354189873, 0.04749889299273491, -0.042833101004362106, 0.010888742282986641, 0.02555053122341633, -0.09836890548467636, -0.08525064587593079, -0.01259193941950798, -0.10665755718946457, 0.01366739347577095, -0.06171790137887001, -0.09683433920145035, 0.01545505691319704, -0.00784250907599926, 0.016816554591059685, -0.049500722438097, -0.011788442730903625, -0.0012777792289853096, 0.023976212367415428, -0.023344358429312706, 0.05036621913313866, -0.06340308487415314, 0.016165778040885925, -0.04509793594479561, 0.041860297322273254, -0.012735752388834953, 0.06289400160312653, -0.005907139740884304, 0.06266416609287262, 0.08858072012662888, 0.008058716543018818, 0.0027320890221744776, 0.07649998366832733, -0.013943688943982124, 0.08873298764228821, 0.011965730227530003, -0.004656320437788963, 0.04470653459429741, 0.007613072637468576, 0.033750344067811966, 0.076478511095047, 0.024855561554431915, -0.010970892384648323, 0.06105219945311546, -0.020752111449837685, 0.0050504463724792, 0.008832938969135284, -0.0697999820113182, 0.03167159482836723, -0.07628156989812851, -0.0027987512294203043, 0.06672921031713486, 0.00321556837297976, -0.03205586224794388, 0.03616418316960335, 0.03701860457658768, 0.029690595343708992, 0.0017716349102556705, 0.05168650671839714, -0.033094167709350586, -0.030665993690490723, 0.040123362094163895, 0.08471869677305222, -0.05081215873360634, -0.03044169209897518, -0.06487502157688141, -0.010838855989277363, -0.0055034467950463295, 0.04416559264063835, 0.004887157119810581, -0.0017802888760343194, 0.04729202017188072, -0.022066332399845123, -0.013862750492990017, 0.007430303376168013, 0.03878627344965935, 0.06626111268997192, 0.025399336591362953, -0.0001674466475378722, 0.09183330833911896, -0.037984300404787064, -0.03427993878722191, 0.017491666600108147, 0.019118063151836395, -0.004257811699062586, 0.02913540229201317, 0.012180326506495476, -0.0671844407916069, 0.030082326382398605, -0.04190719127655029, 0.0354108102619648, 0.01964305341243744, -0.07344063371419907, 0.03612489625811577, -0.05229206383228302, 0.0220055989921093, -0.0039808680303394794, -0.03683069348335266, 0.02693932130932808, 0.045983657240867615, -0.047217801213264465, -0.020317237824201584, -0.04220741614699364, -0.017680980265140533, 0.03315863758325577, 0.040767911821603775, -0.006467558443546295, -0.006754160393029451, 0.016442518681287766, 0.04880617558956146, -0.07971364259719849, 0.030451640486717224, 0.027416547760367393, -0.026520218700170517, -0.11294975876808167, 0.011623230762779713, 0.035197194665670395, 0.03632699325680733, -0.09726108610630035, 0.029502637684345245, -0.05201362818479538, -0.04960360750555992, -0.02983582764863968, -0.03171181678771973, -0.016880493611097336, 0.0019862675108015537, 0.012252520769834518, 0.14910562336444855, -0.017151523381471634, -0.04576500877737999, -0.04749070480465889, -0.024996349588036537, 0.006944253575056791, 0.041597288101911545, 0.06110730022192001, 0.06186912953853607, -0.08414238691329956, -0.0706898421049118, -0.05767785757780075, 0.008359048515558243, 0.08322667330503464, -0.0532376691699028, -0.028928404673933983, -0.03493502363562584, 0.017364580184221268, -0.03502724692225456, 0.009912929497659206, 0.006092045456171036, -0.018551768735051155, -0.007232177071273327, 0.11861861497163773, -0.030702006071805954, 0.0126565583050251, 0.09600654244422913, -0.005895460024476051, -0.02698158286511898, 0.017402788624167442, -0.05260134115815163, 0.01877933368086815, -0.032005324959754944, -0.01232809480279684, -0.026639632880687714, -0.02543608285486698, -0.006896350998431444, 0.013880666345357895, -0.025070205330848694, 0.050821978598833084, 0.011605039238929749, 0.0028076001908630133, -0.004162726923823357, -0.011794398538768291, 0.005654127802699804, -0.022673211991786957, 0.022354107350111008, -0.028401674702763557, 0.0017679433804005384, 0.02979004755616188, 0.02404221147298813, -0.006609336007386446, 0.015392174012959003, 0.005839412100613117, 0.01496612373739481, 0.02258101850748062, 0.007869506254792213, -0.016583576798439026, -0.023578299209475517, -0.025809282436966896, -0.0475136861205101, -0.019922692328691483, 0.03740791603922844, 0.025229666382074356, -0.019390540197491646, 0.004769791848957539, -0.00577129703015089, 0.013699249364435673, -0.02847158908843994, 0.004258019849658012, -0.003101320005953312, 0.0582849495112896, -0.014833910390734673, -0.01822711154818535, -0.05602410435676575, -0.010373049415647984, 0.01873820833861828, -0.01764461025595665, 0.003054796950891614, 0.02315261960029602, -0.042319055646657944, 0.018195772543549538, 0.018656453117728233, -0.017771007493138313, -0.02693459577858448, 0.013466526754200459, 0.014162817038595676, 0.01566103845834732, -0.09672816842794418, 0.004435638897120953, 0.04443798586726189, -0.06839323788881302, 0.025361064821481705, -0.02465946599841118, 0.07397241145372391, 0.04751107469201088, -0.0077413953840732574, 0.017047835513949394, -0.0328955352306366, 0.0056700194254517555, -0.0023113484494388103, 0.06496884673833847, 0.008363253436982632, -0.013977921567857265, -0.044939279556274414, 0.008360393345355988, 0.04473185911774635, 0.010657801292836666, 0.027259161695837975, -0.002404026221483946, -0.007985067553818226, 0.015624210238456726, -0.0168659258633852, 0.03363862261176109, 0.03223690018057823, 0.0683290958404541, 0.019591884687542915, -0.040434420108795166, -0.021836601197719574, -0.009223012253642082, -0.024388480931520462, 0.013097010552883148, -0.050032224506139755, 0.023159092292189598, 0.008895783685147762, -0.01921064220368862, -0.0022641043178737164, 0.02343672513961792, -0.02332681231200695, 0.016432395204901695, -0.0050519309006631374, -0.009002172388136387, -0.020519288256764412, -0.01217686478048563, -0.023208918049931526, -0.07035119831562042, 0.038316935300827026, -0.05169367045164108, -0.018276948481798172, -0.04742344841361046, 0.008867956697940826, 0.013604046776890755, -0.00016447019879706204, 0.04988943040370941, 0.008266349323093891, 0.0017241300083696842, 0.07132399827241898, 0.04202406853437424, -0.028810786083340645, 0.023125136271119118, -0.004959683865308762, -0.03410914167761803, -0.02246948890388012, 0.04992038011550903, 0.024782823398709297, 0.018886351957917213, -0.01870689168572426, 0.032400380820035934, -0.0018022196600213647, 0.05093291029334068, -0.012588098645210266, 0.005150186829268932, -0.034525685012340546, -0.023371204733848572, -0.02362963743507862, -0.02394253760576248, 0.05851071700453758, 0.01430793572217226, -0.01000216044485569, 0.009662872180342674, -0.060059960931539536, -0.011581039987504482, -0.01508555468171835, 0.008600510656833649, 0.041121311485767365, -0.028579194098711014, 0.049271371215581894, 0.025730999186635017, 0.010839313268661499, -0.013532965444028378, -0.009781945496797562, 0.02100159041583538, -0.007489906623959541, -0.03273214027285576, 0.025642121210694313, 0.0006549597601406276, -0.02927732653915882, 0.014096066355705261, 0.00963048916310072, -0.05113492161035538, 0.04477721452713013, 0.01594816893339157, -0.014125755988061428, 0.012400561012327671, -0.06354600191116333, -0.03464149311184883, 0.03181591257452965, -0.049339715391397476, -0.011233024299144745, 0.0019857599399983883, -0.032842569053173065, -0.014346557669341564, 0.025916216894984245, 0.03895197808742523, -0.007546776439994574, 0.00834015291184187, 0.012743850238621235, -0.0052805435843765736, -0.060385867953300476, 0.008459821343421936, -0.012297403998672962, 0.005348804406821728, 0.014657826162874699, -0.025361374020576477, 0.01906426064670086, -0.0010222827550023794, -0.006840219255536795, 0.0019611427560448647, -0.02153552509844303, 0.020502254366874695, 0.051466960459947586, -0.006609068717807531, -0.005076196976006031, 0.01750730350613594, -0.013516465201973915, 0.0027509473729878664, 0.01415875181555748, -0.025270462036132812, -0.022563718259334564, -0.006521472241729498, -0.006741287652403116, -0.04424118995666504, 0.03332160413265228, -0.05455126240849495, -0.031004523858428, -0.039288341999053955, -0.004851962439715862, 0.006097128614783287, 0.07200942933559418, 0.03489387035369873, -0.05755056068301201, -0.03844938054680824, 0.04507112503051758, -0.024675607681274414, -0.03046746924519539, -0.0022484951186925173, 0.009934834204614162, 0.021568477153778076, -0.012912836857140064, 0.007300389464944601, -0.006331650540232658, 0.058823224157094955, -0.003814220894128084, -0.03005901351571083, -0.016907498240470886, -0.07196817547082901, 0.009755563922226429, -0.004185318946838379, 0.019090784713625908, -0.008911730721592903, 0.019789543002843857, 0.008380534127354622, 0.00835670530796051, 0.029566412791609764, -0.01318038534373045, -0.00949392095208168, -0.007606508210301399, -0.03736009821295738, -0.000533816812094301, -0.02604043483734131, 0.05276570841670036, 0.008001047186553478, -0.02177625149488449, 0.002442873315885663, 0.002058559563010931, 0.03822620213031769, -0.008757879957556725, 0.03456753119826317, 0.018091224133968353, -0.014856534078717232, -0.004944749642163515, -0.019981663674116135, 0.010363989509642124, 0.009104902856051922, -0.011591247282922268, 0.02260311134159565, -0.060368336737155914, -0.009883763268589973, 0.047005798667669296, -0.0000815434759715572, 0.00012400098785292357, -0.0066864886321127415, 0.008321094326674938, 0.0020753326825797558, -0.031763624399900436, -0.00667544873431325, -0.012850223109126091, -0.031750649213790894, 0.02115635573863983, -0.027555612847208977, -0.03359607607126236, 0.03903885930776596, 0.04869573190808296, -0.03853367641568184, 0.024864178150892258, -0.005095289088785648, -0.0007446689996868372, 0.05653621628880501, 0.006928520742803812, 0.029462475329637527, -0.036346472799777985, -0.0256853885948658, 0.04584934189915657, -0.05707385390996933, -0.027688127011060715, 0.0461026206612587, 0.0053415000438690186, 0.04870426282286644, 0.047121014446020126, -0.00836817268282175, 0.038422174751758575, 0.026863841339945793, 0.0362493172287941, 0.00031874666456133127, 0.01908951811492443, 0.011521474458277225, 0.03071369230747223, -0.03768017515540123, 0.01924336701631546, 0.02570965327322483, -0.04662787541747093, 0.012128777801990509, -0.038656044751405716, 0.04223534092307091, 0.02779274247586727, -0.016028232872486115, -0.0011959896655753255, -0.02261483110487461, 0.006198978517204523, 0.068428635597229, -0.019408972933888435, 0.04034009948372841, 0.010981258936226368, 0.032281145453453064, 0.014553889632225037, -0.007964507676661015, -0.02886483632028103, 0.008997833356261253, -0.017037322744727135, -0.06891695410013199, 0.0048275357112288475, 0.08928553014993668, 0.0074476636946201324, 0.02482200413942337, 0.02053954266011715, -0.03980449587106705, 0.02682853676378727, 0.042437341064214706, 0.03159932419657707, -0.010225345380604267, -0.006159799173474312, 0.006038946099579334, 0.04409047216176987, -0.06359165161848068, 0.0027671423740684986, 0.05456053465604782, -0.02255854196846485, 0.04967628791928291, -0.021034708246588707, -0.003109112847596407, 0.01647987775504589, 0.009651286527514458, 0.01870366744697094, -0.0011367491679266095, 0.05136367306113243, 0.057707104831933975, 0.010686035268008709, -0.0050257667899131775, -0.00995948538184166, -0.018092302605509758, -0.0369752012193203, -0.02495691552758217, -0.008289527148008347, 0.018932407721877098, 0.04565511643886566, 0.0056206719018518925, 0.01947471871972084, -0.02797710709273815, 0.05837554112076759, -0.016722161322832108, 0.018325766548514366, -0.0018381234258413315, 0.020263873040676117, 0.027599656954407692, 0.009063931182026863, -0.025584794580936432, 0.043054260313510895, -0.014265881851315498, 0.018949244171380997, 0.06612986326217651, 0.013613899238407612, 0.011428149417042732, 0.03921012580394745, 0.026022661477327347, 0.026048805564641953, -0.027455640956759453, -0.02417571283876896, 0.04164585471153259, 0.0019630282185971737, -0.02915327250957489, -0.0020755883306264877, 0.018703853711485863, -0.010350020602345467, -0.03593389689922333, -0.04549901932477951, -0.007492590229958296, -0.0005971924401819706, -0.013115501962602139, -0.03731250762939453, 0.019296227023005486, 0.01326711755245924, -0.03342685103416443, -0.022216375917196274, 0.007443962153047323, 0.006819724105298519, 0.007127933204174042, -0.04762636125087738, -0.024839455261826515, -0.028159480541944504, -0.021898632869124413, -0.022509213536977768, 0.03454266116023064, -0.005847092252224684, -0.02930932119488716, 0.009780550375580788, 0.018827680498361588, -0.02273321896791458, 0.06809613108634949, -0.0008697546436451375, -0.002669001230970025, 0.004058476537466049, 0.007612163200974464, -0.021813103929162025, -0.05127205699682236, 0.07065141201019287, -0.017610054463148117, -0.017218273133039474, 0.0009475959232077003, 0.021010901778936386, 0.010323560796678066, 0.0362582728266716, 0.005543510429561138, -0.018646785989403725, -0.023548560217022896, 0.035281721502542496, -0.030068183317780495, 0.03062559850513935, -0.01577610708773136, 0.0324002280831337, -0.03685983270406723, 0.005124386865645647, -0.02245502732694149, 0.0006602198700420558, 0.007307031191885471, 0.038602087646722794, -0.012611011043190956, -0.02762460894882679, 0.027458159253001213, 0.003044388722628355, 0.025046484544873238, 0.03444975987076759, 0.04613208770751953, 0.004467997699975967, -0.019462648779153824, 0.006190724205225706, 0.01190913189202547, -0.027535518631339073, 0.013179607689380646, -0.019384387880563736, -0.04161597415804863, -0.04693140834569931, 0.023684147745370865, -0.03411559388041496, 0.039293769747018814, -0.05773242935538292, 0.002616096055135131, -0.040472909808158875, -0.005818629637360573, 0.04133995994925499, 0.011063292622566223, 0.08115782588720322, 0.016458626836538315, 0.01318596675992012, -0.02882789634168148, -0.021545061841607094, -0.007812025025486946, -0.03363850340247154, 0.02067836932837963, 0.043463222682476044, 0.06376110762357712, -0.0032319570891559124, 0.0018758336082100868, 0.0023911166936159134, -0.037382256239652634, -0.048409245908260345, -0.03647129610180855, 0.024012373760342598, 0.0032768165692687035, -0.02562764100730419, 0.0017978381365537643, 0.0508594736456871, -0.03147156536579132, 0.032087892293930054, 0.034827399998903275, 0.000519271066877991, 0.00758006889373064, 0.03220353275537491, -0.0486530102789402, -0.012175815179944038, 0.03206349536776543, 0.01030050776898861, 0.035432688891887665, 0.04168228060007095, 0.03780828043818474, 0.050098542124032974, -0.001091523328796029, -0.019393401220440865, 0.015231628902256489, -0.024156179279088974, -0.05302409455180168, 0.0220523439347744, 0.020090796053409576, -0.005050553008913994, -0.03279709070920944, 0.05085411295294762, 0.012860552407801151, -0.0032691119704395533, -0.035462651401758194, 0.0016212925547733903, 0.013104301877319813, 0.004765974823385477, 0.006105434615164995, -0.03006022609770298, 0.014138497412204742, 0.004331658128648996, -0.032650407403707504, -0.04693200811743736, 0.03566548973321915 ]
How to generate text: using different decoding methods for language generation with Transformers
patrickvonplaten
March, 2020
how-to-generate
guide, nlp
https://huggingface.co/blog/how-to-generate
Greedy Search Greedy search is the simplest decoding method. It selects the word with the highest probability as its next word: \(w_t = argmax_{w}P(w | w_{1:t-1})\) at each timestep \(t\). The following sketch shows greedy search. Starting from the word \(\text{"The"},\) the algorithm greedily chooses the next word of highest probability \(\text{"nice"}\) and so on, so that the final generated word sequence is \((\text{"The"}, \text{"nice"}, \text{"woman"})\) having an overall probability of \(0.5 \times 0.4 = 0.2\) . In the following we will generate word sequences using GPT2 on the context \((\text{"I"}, \text{"enjoy"}, \text{"walking"}, \text{"with"}, \text{"my"}, \text{"cute"}, \text{"dog"})\). Let's see how greedy search can be used in transformers: python # encode context the generation is conditioned on model_inputs = tokenizer('I enjoy walking with my cute dog', return_tensors='pt').to(torch_device) # generate 40 new tokens greedy_output = model.generate(**model_inputs, max_new_tokens=40) print("Output:\n" + 100 * '-') print(tokenizer.decode(greedy_output[0], skip_special_tokens=True)) Output: ---------------------------------------------------------------------------------------------------- I enjoy walking with my cute dog, but I'm not sure if I'll ever be able to walk with my dog. I'm not sure if I'll ever be able to walk with my dog. I'm not sure Alright! We have generated our first short text with GPT2 😊. The generated words following the context are reasonable, but the model quickly starts repeating itself! This is a very common problem in language generation in general and seems to be even more so in greedy and beam search - check out Vijayakumar et al., 2016 and Shao et al., 2017. The major drawback of greedy search though is that it misses high probability words hidden behind a low probability word as can be seen in our sketch above: The word \(\text{"has"}\) with its high conditional probability of \(0.9\) is hidden behind the word \(\text{"dog"}\), which has only the second-highest conditional probability, so that greedy search misses the word sequence \(\text{"The"}, \text{"dog"}, \text{"has"}\) . Thankfully, we have beam search to alleviate this problem!
[ 0.023698970675468445, 0.013929763808846474, 0.028692476451396942, -0.024171141907572746, 0.04355953261256218, 0.046674031764268875, 0.041918352246284485, 0.02269076742231846, -0.0452243909239769, -0.0062102642841637135, -0.11697018146514893, 0.07446299493312836, -0.013841290958225727, 0.048959605395793915, -0.0003192711155861616, -0.010427872650325298, 0.06931756436824799, -0.04897070676088333, 0.024616098031401634, -0.0388171412050724, -0.012956039048731327, -0.03412584960460663, 0.05752916261553764, -0.013039661571383476, 0.057780999690294266, -0.03213274106383324, -0.011341897770762444, 0.010128868743777275, -0.004289984703063965, 0.0292638149112463, -0.09586536139249802, -0.015663523226976395, 0.03826207295060158, -0.04881199449300766, 0.04397621005773544, 0.025061003863811493, -0.16088847815990448, 0.04551338404417038, 0.030658183619379997, -0.020552126690745354, -0.047885749489068985, -0.02848425880074501, -0.03090112842619419, 0.043296460062265396, 0.0006813919171690941, -0.024132980033755302, -0.15087132155895233, 0.09373151510953903, -0.1164439246058464, -0.11736030876636505, -0.04162848740816116, 0.026280805468559265, -0.05007714033126831, 0.06728053838014603, -0.026509106159210205, -0.02546318620443344, 0.0014994501834735274, -0.10885518789291382, 0.026693856343626976, -0.0023361225612461567, 0.03787819668650627, 0.023746920749545097, 0.015564347617328167, 0.07554282993078232, 0.034150008112192154, -0.027058983221650124, -0.01453676912933588, 0.03545225039124489, -0.02266055904328823, -0.04427202418446541, 0.05464055389165878, -0.004023709800094366, -0.05911949649453163, 0.029840514063835144, -0.03035934828221798, 0.0059009725227952, -0.04499344900250435, -0.021107142791152, -0.025629952549934387, 0.09182757139205933, 0.01413669716566801, 0.000876898760907352, 0.0579393096268177, 0.04862475395202637, 0.10940522700548172, 0.022171908989548683, 0.008819405920803547, -0.018628239631652832, -0.03238201141357422, 0.061022404581308365, -0.03614446148276329, -0.14405927062034607, 0.008350505493581295, -0.01697082631289959, 0.023745736107230186, -0.014389732852578163, -0.0017629986396059394, 0.026712918654084206, -0.014629949815571308, 0.011437322944402695, 0.004613774828612804, -0.06448575854301453, 0.016207696869969368, -0.038078416138887405, -0.06707899272441864, 0.049524690955877304, -0.019437549635767937, -0.04328576475381851, -0.018126145005226135, 0.006044900976121426, 0.010599962435662746, 0.02862144634127617, 0.009294446557760239, 0.009400514885783195, -0.0025726770982146263, 0.03748554736375809, 0.018712244927883148, -0.0064703309908509254, -0.0888972282409668, -0.0534512996673584, -0.04498814046382904, 0.0778362974524498, 0.05882729962468147, -0.005897821858525276, -0.0015899291029199958, 0.003619918366894126, -0.014875607565045357, 0.033207982778549194, 0.00046972939162515104, -0.0043547083623707294, 0.08498924970626831, 0.01950753852725029, -0.02852047048509121, -0.010751868598163128, 0.0277455635368824, 0.021192453801631927, 0.04697003960609436, -0.004084973130375147, -0.05286146700382233, -0.04778483882546425, -0.0007627138402312994, 0.019762039184570312, -0.05073168873786926, 0.04037319868803024, -0.010692241601645947, -0.012751802802085876, -0.05901920795440674, 0.09119134396314621, 0.013287816196680069, 0.04278895631432533, -0.007711353711783886, 0.0017072343034669757, 0.0602225735783577, -0.06680256873369217, 0.012629943899810314, 0.058814868330955505, -0.009522377513349056, -0.013570906594395638, -0.08515945822000504, -0.016808880493044853, 0.0024877344258129597, -0.023043012246489525, 0.021354271098971367, -0.007360539399087429, 0.04435763508081436, -0.06961493194103241, 0.03335513174533844, 0.043771758675575256, -0.05639205127954483, 0.0712461918592453, 0.0016525426181033254, 0.029361935332417488, 0.06045679375529289, 0.027722040191292763, 0.006125970743596554, 0.05005999654531479, -0.016636816784739494, 0.011014951393008232, -0.014809206128120422, -0.04130169749259949, -0.012338978238403797, 0.02347087673842907, -0.008218604139983654, -0.011912918649613857, 0.04196176677942276, -0.08528946340084076, 0.002890444127842784, 0.047660138458013535, 0.05701195076107979, 0.0031580172944813967, -0.07941851764917374, -0.07155546545982361, 0.06645841151475906, -0.017833851277828217, -0.01917612925171852, -0.04854007437825203, -0.02712882310152054, 0.03464854136109352, 0.035089269280433655, 0.027502868324518204, 0.0661894902586937, 0.004948655143380165, 0.022361954674124718, -0.010059167630970478, -0.038110990077257156, -0.0645781010389328, -0.017115185037255287, -0.03528934717178345, 0.009383024647831917, 0.06554850935935974, -0.007856964133679867, -0.05696159973740578, -0.010986515320837498, -0.15566451847553253, 0.002174130640923977, -0.05755298212170601, 0.005619230680167675, 0.0618634931743145, 0.019394192844629288, 0.0070832702331244946, 0.10151670128107071, -0.09578437358140945, -0.03249247372150421, -0.005492093972861767, -0.006817357614636421, 0.07425570487976074, 0.02423315867781639, 0.03748117759823799, -0.0012891340302303433, -0.05360669270157814, -0.03264545276761055, -0.04689919948577881, 0.02147715538740158, 0.03460066020488739, -0.026891717687249184, -0.12038102000951767, 0.018611712381243706, 0.05420290678739548, 0.05898327752947807, -0.010158374905586243, -0.017638225108385086, -0.003734016325324774, -0.0751020535826683, 0.05089668929576874, 0.004782291129231453, -0.0382775254547596, 0.08033610880374908, -0.046850524842739105, -0.050031665712594986, -0.012253684923052788, -0.027399273589253426, 0.041497573256492615, -0.06295307725667953, -0.05174683779478073, -0.0008900839020498097, 0.09128841012716293, 0.008546950295567513, -0.019599096849560738, 0.015838103368878365, 0.04515562579035759, -0.027881445363163948, -0.019809726625680923, 0.01316733006387949, -0.029903611168265343, -0.02476789429783821, 0.017948253080248833, 0.03679655119776726, 0.02724798023700714, -0.002004367997869849, 0.007761569228023291, -0.029874563217163086, -0.002395986346527934, -0.009661163203418255, -0.02444520965218544, 0.030592966824769974, 0.023175783455371857, 0.007942021824419498, 0.013247942551970482, -0.04223373159766197, -0.02695371024310589, -0.02619555965065956, -0.01582794450223446, 0.05756760388612747, 0.01947467215359211, -0.0024672995787113905, -0.002455824287608266, -0.010212364606559277, 0.024480704218149185, -0.01250979583710432, 0.04373468458652496, -0.03635454922914505, 0.02065557800233364, -0.017876215279102325, -0.023413188755512238, 0.003735302947461605, -0.014480448327958584, -0.010192913934588432, 0.006970172747969627, -0.05421983823180199, 0.0380476750433445, -0.026275068521499634, 0.00965174287557602, -0.0007331191445700824, -0.016680540516972542, -0.026173407211899757, -0.011738195084035397, 0.01785488985478878, 0.043085068464279175, -0.09167594462633133, -0.01483835093677044, 0.021192528307437897, -0.02338779717683792, -0.011401977390050888, -0.016725528985261917, 0.015847958624362946, 0.0098843639716506, -0.013039122335612774, -0.031109033152461052, 0.0002797039342112839, 0.017336895689368248, -0.013507257215678692, 0.009319276548922062, 0.011832267977297306, -0.0067726727575063705, -0.020121518522500992, 0.019128838554024696, -0.006975746713578701, 0.011200263164937496, 0.06466837972402573, 0.04357083514332771, 0.005003368016332388, 0.004422707483172417, -0.059527575969696045, -0.02621135488152504, 0.01280918624252081, -0.0049143205396831036, 0.0368218757212162, 0.0044041648507118225, -0.0033254502341151237, -0.01922224834561348, -0.007894689217209816, 0.006863628048449755, -0.017544914036989212, -0.009586512111127377, 0.009710163809359074, 0.001057066605426371, -0.022633802145719528, 0.02760685607790947, -0.0016874975990504026, -0.015421206131577492, 0.013763920404016972, -0.0006326579605229199, 0.010732611641287804, 0.013062053360044956, -0.03167126327753067, 0.00317195663228631, 0.03083507902920246, -0.0589110292494297, -0.04560002684593201, -0.020897438749670982, -0.04161752760410309, 0.010969606228172779, 0.006073655094951391, 0.05556264519691467, -0.004328135401010513, 0.03245139867067337, 0.03944064676761627, 0.03624844178557396, -0.044019829481840134, 0.01018057856708765, 0.0187978632748127, -0.05614546686410904, 0.005603153258562088, 0.052966468036174774, -0.004963043611496687, 0.018805760890245438, -0.013893858529627323, 0.04493676498532295, 0.011596191674470901, -0.018289413303136826, -0.007258303929120302, 0.0034385037142783403, -0.02886301279067993, 0.03734176978468895, -0.019361723214387894, -0.04166998341679573, 0.08569081127643585, -0.0020051696337759495, -0.013048673048615456, -0.019369782879948616, -0.07416296005249023, -0.002338321879506111, 0.017679888755083084, -0.03620200231671333, 0.03570833057165146, -0.01292042713612318, -0.00907166302204132, 0.0031808281783014536, -0.012696641497313976, -0.008517124690115452, -0.011662498116493225, -0.011528626084327698, -0.047789379954338074, 0.025540906935930252, -0.004814358428120613, -0.005271109752357006, 0.028211800381541252, 0.0033221933990716934, 0.028879381716251373, -0.0603611096739769, 0.005837737582623959, 0.0032572203781455755, -0.02579405903816223, -0.006377125158905983, -0.039223894476890564, -0.024181609973311424, 0.05274961516261101, 0.019706811755895615, -0.002499533584341407, 0.016171995550394058, 0.015368257649242878, -0.003658528905361891, 0.028777258470654488, 0.021392537280917168, 0.006569028366357088, -0.029067009687423706, -0.026564814150333405, 0.005157330073416233, -0.03380008414387703, 0.03505175560712814, -0.014687800779938698, 0.001835775445215404, 0.019551696255803108, -0.01473073847591877, 0.045224908739328384, 0.01851769909262657, -0.011771682649850845, -0.02089310996234417, -0.024667512625455856, -0.009569929912686348, 0.048399344086647034, -0.019312094897031784, 0.018063537776470184, 0.029509419575333595, 0.010724950581789017, -0.008082224987447262, 0.006269169971346855, -0.06348267942667007, -0.0094460379332304, -0.003725329414010048, 0.029790498316287994, -0.06618837267160416, 0.021689441055059433, 0.016096124425530434, 0.004341010004281998, 0.0031851651147007942, 0.029665593057870865, -0.0015447515761479735, 0.045470163226127625, 0.009810059331357479, -0.04010118916630745, 0.0040757916867733, 0.028916651383042336, -0.026061486452817917, -0.029839705675840378, 0.0183895044028759, -0.008775347843766212, 0.040482308715581894, 0.006642356514930725, -0.02138807252049446, -0.034939445555210114, 0.0043504368513822556, 0.007894672453403473, -0.02117125876247883, -0.0405581071972847, -0.035316236317157745, 0.003249019617214799, -0.016265904530882835, 0.003540859092026949, -0.0076439762488007545, 0.04787105321884155, -0.004633642267435789, -0.012350313365459442, 0.018264465034008026, 0.001959775108844042, 0.031736109405756, -0.04750610142946243, 0.013372602872550488, -0.04197230190038681, -0.0030421819537878036, -0.0014657450374215841, 0.02193335071206093, 0.010411180555820465, 0.04243924096226692, 0.03446635976433754, 0.03591935709118843, -0.009345407597720623, 0.031691085547208786, 0.026172418147325516, -0.03778228163719177, 0.03942369297146797, -0.01672140695154667, -0.007684065494686365, 0.012351561337709427, -0.013861930929124355, 0.03126029670238495, 0.02836051769554615, -0.007127602584660053, 0.05189426243305206, 0.013676717877388, -0.0007914057350717485, -0.020246682688593864, 0.013899209909141064, -0.002523592207580805, 0.004588793963193893, 0.003934287000447512, -0.027725322172045708, -0.034776341170072556, 0.018391991034150124, -0.0069419206120073795, -0.028064152225852013, 0.0003744068380910903, -0.029719334095716476, -0.011373677290976048, -0.017061421647667885, 0.009085378609597683, -0.0013984241522848606, 0.08813854306936264, 0.03621217608451843, 0.0064245727844536304, 0.0028545628301799297, 0.02856774628162384, 0.05329705774784088, -0.03409794345498085, 0.012737286277115345, 0.02061932347714901, 0.03354818746447563, -0.02157951332628727, 0.04328770563006401, -0.041442304849624634, -0.00193471007514745, 0.03717665746808052, 0.001472027855925262, -0.03312866762280464, -0.0049114772118628025, 0.049781184643507004, 0.02359590493142605, 0.0316925048828125, 0.023324796929955482, -0.027887757867574692, 0.006368368398398161, 0.03381997346878052, -0.01650242879986763, 0.03259023651480675, 0.04445931687951088, -0.012775959447026253, -0.007428618147969246, 0.005256175063550472, 0.04868113994598389, 0.0210587065666914, -0.07397321611642838, 0.007306925021111965, 0.005848609376698732, -0.009703930467367172, 0.03650974854826927, -0.011399962939321995, 0.0031715668737888336, 0.045583225786685944, 0.011998520232737064, -0.06536849588155746, 0.00007864450890338048, 0.04519062489271164, -0.04344053566455841, -0.0007049854029901326, -0.021461788564920425, -0.021344881504774094, -0.033604346215724945, -0.011564294807612896, 0.025485845282673836, 0.029450779780745506, -0.013033575378358364, 0.04123226925730705, -0.009533955715596676, 0.03757491707801819, 0.00649933610111475, 0.06291606277227402, -0.023939020931720734, 0.05154997482895851, 0.009843368083238602, 0.024270659312605858, -0.02153027430176735, 0.02635601907968521, -0.006022111512720585, 0.07867226749658585, 0.06397765129804611, 0.00745133962482214, 0.037674956023693085, -0.026212796568870544, -0.011453601531684399, 0.019219305366277695, -0.0414905846118927, -0.03810121864080429, -0.0009827694157138467, 0.0035373943392187357, 0.047356706112623215, -0.04520435258746147, 0.031022299081087112, -0.05614275112748146, 0.023195700719952583, 0.043996505439281464, 0.027461586520075798, -0.041147273033857346, 0.0057335891760885715, 0.016746243461966515, 0.020084194839000702, 0.04282088950276375, 0.05749138072133064, 0.03151868283748627, -0.01587597094476223, 0.03535906597971916, 0.013381089083850384, 0.05777334049344063, 0.06164192408323288, -0.01917254365980625, -0.008087928406894207, -0.03323245793581009, -0.0020702783949673176, 0.005085720680654049, 0.00695772934705019, -0.01889120787382126, 0.029311178252100945, 0.027104590088129044, -0.02232091873884201, 0.009619094431400299, -0.02392713911831379, 0.00366069283336401, 0.019327139481902122, -0.016481386497616768, -0.002171618863940239, 0.02956785075366497, -0.031193973496556282, -0.019479943439364433, -0.020373575389385223, 0.013669083826243877, 0.022289404645562172, 0.021328208968043327, -0.047457922250032425, -0.03476635739207268, -0.012068435549736023, -0.025145066902041435, -0.012249952182173729, -0.02835695818066597, -0.014612938277423382, 0.0025886783841997385, 0.03720749169588089, 0.03241186589002609, -0.005414869170635939, 0.02074233442544937, 0.029306024312973022, 0.014188873581588268, -0.0322025790810585, 0.01508302427828312, 0.0029818089678883553, 0.018360266461968422, 0.034736812114715576, -0.03114469163119793, -0.008657044731080532, -0.005651882849633694, 0.04705020412802696, 0.008847175166010857, 0.030443618074059486, -0.025720376521348953, -0.047546837478876114, 0.0026121388655155897, -0.04185688868165016, -0.01128779910504818, -0.0013085039099678397, 0.016379669308662415, -0.006340201944112778, 0.027112871408462524, -0.03800337761640549, -0.01756402477622032, -0.009890630841255188, -0.00909141730517149, 0.022789455950260162, -0.013864980079233646, -0.05147666856646538, -0.0077642835676670074, 0.030446764081716537, -0.019376734271645546, -0.02250381000339985, 0.03955284506082535, 0.010012753307819366, 0.019859187304973602, 0.002629890339449048, 0.01622692123055458, -0.032079316675662994, -0.04076136276125908, -0.030213378369808197, -0.04320533946156502, 0.02126353792846203, -0.0027913113590329885, -0.04603002965450287, 0.0005930350162088871, -0.046120427548885345, 0.04752855375409126, -0.014201560989022255, 0.026111485436558723, -0.014262477867305279, 0.003146521048620343, 0.0480068065226078, 0.012569839134812355, 0.09060824662446976, 0.004452168941497803, 0.013764690607786179, -0.05444939434528351, 0.00750143313780427, 0.011779597960412502, 0.046337444335222244, 0.013431977480649948, 0.016092300415039062, -0.04844825342297554, -0.009342309087514877, 0.01757960021495819, -0.0027372713666409254, 0.0341484509408474, 0.02172286994755268, -0.02225233055651188, -0.01829802244901657, 0.018349695950746536, 0.028650805354118347, -0.014305803924798965, -0.0442347526550293, 0.000053035902965348214, 0.01844635233283043, 0.007293557748198509, 0.03186255693435669, -0.031559087336063385, 0.0026861790101975203, 0.014334257692098618, 0.025661643594503403, 0.03252217173576355, 0.01730445958673954, 0.03521488979458809, 0.01523289643228054, 0.014555874280631542, -0.032324742525815964, 0.03019167296588421, 0.03181047365069389, -0.03357953950762749, 0.009334270842373371, 0.039315495640039444, -0.048881083726882935, -0.03725612908601761, 0.031889643520116806, 0.027086051180958748, -0.034984443336725235, 0.038599491119384766, 0.004914718680083752, 0.05253686010837555, 0.0343385674059391, 0.012224054895341396, 0.0022254602517932653, 0.084102563560009, -0.017517615109682083, 0.029692191630601883, 0.009524259716272354, 0.0033791051246225834 ]
How to generate text: using different decoding methods for language generation with Transformers
patrickvonplaten
March, 2020
how-to-generate
guide, nlp
https://huggingface.co/blog/how-to-generate
Beam search Beam search reduces the risk of missing hidden high probability word sequences by keeping the most likely num_beams of hypotheses at each time step and eventually choosing the hypothesis that has the overall highest probability. Let's illustrate with num_beams=2: At time step 1, besides the most likely hypothesis \((\text{"The"}, \text{"nice"})\), beam search also keeps track of the second most likely one \((\text{"The"}, \text{"dog"})\). At time step 2, beam search finds that the word sequence \((\text{"The"}, \text{"dog"}, \text{"has"})\), has with \(0.36\) a higher probability than \((\text{"The"}, \text{"nice"}, \text{"woman"})\), which has \(0.2\) . Great, it has found the most likely word sequence in our toy example! Beam search will always find an output sequence with higher probability than greedy search, but is not guaranteed to find the most likely output. Let's see how beam search can be used in transformers. We set num_beams > 1 and early_stopping=True so that generation is finished when all beam hypotheses reached the EOS token. python # activate beam search and early_stopping beam_output = model.generate( **model_inputs, max_new_tokens=40, num_beams=5, early_stopping=True ) print("Output:\n" + 100 * '-') print(tokenizer.decode(beam_output[0], skip_special_tokens=True)) Output: ---------------------------------------------------------------------------------------------------- I enjoy walking with my cute dog, but I'm not sure if I'll ever be able to walk with him again. I'm not sure if I'll ever be able to walk with him again. I'm not sure While the result is arguably more fluent, the output still includes repetitions of the same word sequences. One of the available remedies is to introduce n-grams (a.k.a word sequences of n words) penalties as introduced by Paulus et al. (2017) and Klein et al. (2017). The most common n-grams penalty makes sure that no n-gram appears twice by manually setting the probability of next words that could create an already seen n-gram to 0. Let's try it out by setting no_repeat_ngram_size=2 so that no 2-gram appears twice: python # set no_repeat_ngram_size to 2 beam_output = model.generate( **model_inputs, max_new_tokens=40, num_beams=5, no_repeat_ngram_size=2, early_stopping=True ) print("Output:\n" + 100 * '-') print(tokenizer.decode(beam_output[0], skip_special_tokens=True)) Output: ---------------------------------------------------------------------------------------------------- I enjoy walking with my cute dog, but I'm not sure if I'll ever be able to walk with him again. I've been thinking about this for a while now, and I think it's time for me to Nice, that looks much better! We can see that the repetition does not appear anymore. Nevertheless, n-gram penalties have to be used with care. An article generated about the city New York should not use a 2-gram penalty or otherwise, the name of the city would only appear once in the whole text! Another important feature about beam search is that we can compare the top beams after generation and choose the generated beam that fits our purpose best. In transformers, we simply set the parameter num_return_sequences to the number of highest scoring beams that should be returned. Make sure though that num_return_sequences <= num_beams! python # set return_num_sequences > 1 beam_outputs = model.generate( **model_inputs, max_new_tokens=40, num_beams=5, no_repeat_ngram_size=2, num_return_sequences=5, early_stopping=True ) # now we have 3 output sequences print("Output:\n" + 100 * '-') for i, beam_output in enumerate(beam_outputs): print("{}: {}".format(i, tokenizer.decode(beam_output, skip_special_tokens=True))) Output: ---------------------------------------------------------------------------------------------------- 0: I enjoy walking with my cute dog, but I'm not sure if I'll ever be able to walk with him again. I've been thinking about this for a while now, and I think it's time for me to 1: I enjoy walking with my cute dog, but I'm not sure if I'll ever be able to walk with her again. I've been thinking about this for a while now, and I think it's time for me to 2: I enjoy walking with my cute dog, but I'm not sure if I'll ever be able to walk with him again. I've been thinking about this for a while now, and I think it's a good idea to 3: I enjoy walking with my cute dog, but I'm not sure if I'll ever be able to walk with him again. I've been thinking about this for a while now, and I think it's time to take a 4: I enjoy walking with my cute dog, but I'm not sure if I'll ever be able to walk with him again. I've been thinking about this for a while now, and I think it's a good idea. As can be seen, the five beam hypotheses are only marginally different to each other - which should not be too surprising when using only 5 beams. In open-ended generation, a couple of reasons have been brought forward why beam search might not be the best possible option: - Beam search can work very well in tasks where the length of the desired generation is more or less predictable as in machine translation or summarization - see Murray et al. (2018) and Yang et al. (2018). But this is not the case for open-ended generation where the desired output length can vary greatly, e.g. dialog and story generation. - We have seen that beam search heavily suffers from repetitive generation. This is especially hard to control with n-gram- or other penalties in story generation since finding a good trade-off between inhibiting repetition and repeating cycles of identical n-grams requires a lot of finetuning. - As argued in Ari Holtzman et al. (2019), high quality human language does not follow a distribution of high probability next words. In other words, as humans, we want generated text to surprise us and not to be boring/predictable. The authors show this nicely by plotting the probability, a model would give to human text vs. what beam search does. So let's stop being boring and introduce some randomness 🤪.
[ -0.014782017096877098, 0.014650287106633186, 0.046428970992565155, -0.03658571094274521, 0.0449768491089344, 0.03151160851120949, 0.07449854165315628, 0.02294895052909851, -0.07320138067007065, 0.00017023517284542322, -0.11173757165670395, 0.00045338697964325547, 0.03242672234773636, 0.06031564623117447, -0.06101304292678833, -0.03639297932386398, 0.04088520258665085, -0.029651714488863945, 0.00905875489115715, 0.020256582647562027, 0.03675229474902153, -0.009736000560224056, 0.055745452642440796, -0.060001540929079056, 0.04608311131596565, -0.004099180456250906, -0.02064397558569908, -0.009112228639423847, -0.05054076761007309, 0.04162640869617462, -0.08899688720703125, -0.018325647339224815, 0.02767329290509224, -0.0519481897354126, 0.02952846884727478, 0.047036122530698776, -0.14363908767700195, 0.06164947524666786, 0.06790021806955338, -0.042232491075992584, -0.03409012779593468, -0.039566975086927414, -0.07557262480258942, -0.006697754375636578, -0.04021436721086502, -0.024770686402916908, -0.1600508689880371, 0.08065250515937805, -0.10725587606430054, -0.05596247687935829, -0.07028094679117203, 0.04388980194926262, -0.028532791882753372, 0.033493224531412125, -0.0010368424700573087, -0.040346331894397736, -0.0027905732858926058, -0.05647468939423561, 0.016714297235012054, 0.04179873317480087, -0.018290210515260696, -0.0031552081927657127, 0.0668385773897171, 0.05871647968888283, 0.01833576336503029, 0.009683453477919102, 0.007444065064191818, 0.053507931530475616, -0.06617505848407745, -0.0009001505095511675, 0.037672508507966995, 0.03401917964220047, -0.061257362365722656, -0.05332191288471222, 0.010124475695192814, -0.04629864543676376, -0.04902687296271324, 0.053822968155145645, -0.02852136828005314, -0.0025770997162908316, 0.06276416778564453, 0.04205179214477539, 0.04901355877518654, 0.06209128350019455, 0.051096685230731964, 0.0717235580086708, 0.04007783532142639, -0.019105028361082077, -0.04334738478064537, 0.03314841911196709, -0.004964388441294432, -0.14851032197475433, 0.029637720435857773, 0.047992877662181854, 0.012469552457332611, 0.006025957874953747, 0.03336666524410248, 0.043054040521383286, -0.03349679335951805, -0.0057370299473404884, 0.0024158323649317026, -0.07929325103759766, 0.014703630469739437, 0.02469373121857643, -0.04741762951016426, 0.008211961947381496, -0.008370058611035347, -0.05236705392599106, -0.03980831056833267, 0.030943023040890694, 0.004470617976039648, -0.015187284909188747, 0.017623886466026306, 0.04515963792800903, 0.020906172692775726, 0.021210215985774994, 0.05590980499982834, 0.06675373762845993, -0.03477427363395691, -0.021490179002285004, -0.0314919576048851, 0.09107428044080734, 0.11800643801689148, -0.018027663230895996, -0.04192715510725975, -0.0006222635274752975, -0.037428196519613266, 0.03846145048737526, -0.038680288940668106, 0.02243630401790142, 0.02285502851009369, 0.01142665185034275, -0.009166045114398003, -0.009508242830634117, -0.010247965343296528, 0.013114326633512974, 0.010229759849607944, -0.003138052299618721, -0.03997458145022392, -0.02460983581840992, -0.023952215909957886, -0.008378071710467339, -0.02785210870206356, 0.03470481559634209, 0.0038161533884704113, 0.011910514906048775, -0.03690461814403534, 0.042990315705537796, -0.05969196557998657, 0.059866324067115784, 0.011509493924677372, 0.025202875956892967, 0.018828367814421654, -0.07484635710716248, -0.036867495626211166, 0.05312257260084152, 0.05095057189464569, -0.0032136207446455956, -0.05915974825620651, 0.0033093297388404608, -0.04135431721806526, -0.026423735544085503, 0.0402008555829525, -0.05156603455543518, 0.06622090190649033, -0.05429331213235855, 0.08141373842954636, 0.03420212119817734, -0.02148376777768135, 0.09739197045564651, 0.011705285869538784, -0.006547321565449238, 0.12382496148347855, -0.03722162917256355, 0.016448024660348892, 0.021536119282245636, -0.022423600777983665, 0.010616922751069069, -0.06342197954654694, -0.02287907339632511, -0.033633753657341, -0.018304072320461273, 0.0010674966033548117, 0.009554971940815449, -0.005368771031498909, -0.13329243659973145, 0.03755461424589157, 0.03872973099350929, 0.020716970786452293, -0.008429381996393204, -0.01646391674876213, -0.11683535575866699, 0.06254604458808899, -0.042227696627378464, -0.0182678010314703, -0.07820522785186768, 0.0034482362680137157, 0.038649678230285645, 0.0395556204020977, 0.04485515505075455, 0.06310346722602844, 0.0746021568775177, 0.020158031955361366, -0.037929337471723557, -0.016127869486808777, -0.048651568591594696, -0.015314772725105286, -0.042272232472896576, 0.018100189045071602, 0.049225348979234695, 0.009655364789068699, -0.07249631732702255, -0.005289149936288595, -0.11952454596757889, -0.05563483014702797, -0.04028380662202835, 0.022308405488729477, 0.005344676319509745, 0.0046575418673455715, 0.022266777232289314, 0.12604647874832153, -0.03503629192709923, 0.003691036021336913, -0.02953614667057991, -0.028603455051779747, 0.05200876668095589, 0.030167344957590103, 0.019692663103342056, -0.01285312045365572, -0.042956139892339706, 0.017688682302832603, -0.008514137007296085, 0.06955564022064209, 0.05487946420907974, 0.03613787144422531, -0.054043401032686234, -0.014340193942189217, 0.009288967587053776, -0.010845599696040154, -0.0041451952420175076, -0.014804408885538578, -0.029242994263768196, -0.019048774614930153, 0.10652127116918564, -0.002507490571588278, -0.06315131485462189, 0.0854560062289238, -0.00476779043674469, -0.02648479864001274, -0.03331896290183067, -0.016104791313409805, 0.028897477313876152, -0.08091092854738235, -0.0875171571969986, 0.038293253630399704, 0.07254977524280548, -0.0018965338822454214, -0.032579660415649414, 0.008513093926012516, 0.005840279161930084, -0.025332918390631676, -0.017378365620970726, 0.01210563350468874, -0.0472627729177475, -0.0034411728847771883, 0.027295153588056564, 0.012736054137349129, -0.01154404878616333, -0.010734842158854008, 0.006377633661031723, 0.006466659717261791, 0.005631570238620043, 0.016237108036875725, -0.0020583216100931168, 0.00493785971775651, 0.020085515454411507, 0.009192812256515026, -0.036186717450618744, -0.03136008605360985, -0.00487778102979064, -0.03245186060667038, 0.005460308399051428, 0.04921779781579971, 0.031278252601623535, 0.014539031311869621, 0.0012240883661434054, -0.00883535761386156, 0.006231904495507479, -0.004101542755961418, -0.009970501996576786, -0.04031544551253319, -0.006465599872171879, 0.027347242459654808, -0.02198171056807041, -0.02002618834376335, -0.011032243259251118, -0.011422393843531609, 0.01833764649927616, -0.03328600898385048, 0.0008728758548386395, -0.02629193849861622, 0.0010903622023761272, 0.0167127326130867, -0.02565053105354309, -0.020766394212841988, 0.03366073593497276, 0.03235660865902901, 0.061166517436504364, -0.09257093071937561, -0.006516970694065094, -0.002184835495427251, -0.02161700278520584, -0.005498945713043213, -0.0046282620169222355, 0.04575502872467041, 0.012143885716795921, -0.012184645049273968, -0.023930437862873077, -0.03407061845064163, -0.001155847916379571, -0.001901166862808168, 0.007658910006284714, 0.018070712685585022, -0.003002102952450514, -0.044704679399728775, 0.014073849655687809, -0.0015205745585262775, 0.0171008612960577, 0.04419395700097084, 0.025558652356266975, 0.009847051464021206, 0.005765814799815416, -0.05076620355248451, -0.02086336351931095, 0.027247261255979538, 0.02286124974489212, 0.024875864386558533, -0.028433499857783318, 0.002839083783328533, -0.003509475849568844, -0.037563685327768326, -0.01665906235575676, -0.015169937163591385, 0.016052257269620895, 0.059908006340265274, 0.0054901293478906155, -0.01950041949748993, 0.029331054538488388, 0.02419508621096611, -0.0138881616294384, -0.012254747562110424, -0.007740695029497147, -0.0007294982206076384, 0.0029504133854061365, -0.004195691552013159, 0.01292463205754757, 0.025210527703166008, -0.07717671990394592, -0.003959156572818756, -0.0013039797777310014, -0.020735589787364006, 0.012560456059873104, 0.015053419396281242, -0.010232727974653244, 0.010783178731799126, -0.001269683358259499, 0.04171114042401314, 0.015910662710666656, -0.05871887877583504, 0.009549419395625591, 0.04058273881673813, 0.00197885581292212, -0.0007554271724075079, 0.033588144928216934, 0.016235163435339928, 0.03887619450688362, 0.008381410501897335, 0.02435426041483879, -0.007089997176080942, 0.015374431386590004, 0.008477414026856422, 0.009189506992697716, -0.013283421285450459, 0.04509630799293518, -0.02004200592637062, -0.0527985580265522, 0.05875847861170769, 0.024400031194090843, -0.038013145327568054, -0.013147126883268356, -0.057052284479141235, 0.045843735337257385, 0.0363437719643116, 0.002374973613768816, -0.009006692096590996, 0.002712368732318282, -0.014994435012340546, -0.008811051025986671, -0.029783358797430992, -0.022116390988230705, -0.03249070793390274, -0.01976013369858265, -0.021722761914134026, 0.013919233344495296, 0.023028362542390823, 0.0006013508536852896, -0.011297334916889668, 0.010274749249219894, 0.036374736577272415, -0.024527156725525856, 0.0012300478992983699, -0.02554006315767765, -0.026763176545500755, 0.0022592043969780207, -0.08653505146503448, -0.02122439444065094, 0.02560504339635372, -0.0059277513064444065, 0.02605617046356201, 0.002285052090883255, 0.0017817439511418343, 0.02847195789217949, -0.004495619330555201, 0.02936704084277153, -0.010230501182377338, -0.017459411174058914, -0.0459185391664505, 0.006669649388641119, -0.038364410400390625, 0.03775397315621376, -0.03905082494020462, 0.012854084372520447, 0.0007080051000230014, -0.022949466481804848, 0.009140758775174618, 0.000881697575096041, 0.011950045824050903, -0.05017079412937164, -0.0052067493088543415, 0.00473714480176568, 0.05508140102028847, 0.020056728273630142, 0.030136480927467346, 0.04059188812971115, -0.004750275984406471, 0.012457161210477352, -0.017931999638676643, -0.0796239972114563, -0.03108125738799572, -0.010346773080527782, 0.0159221813082695, -0.043083127588033676, 0.03647773712873459, 0.010554980486631393, -0.04503140226006508, -0.02195814624428749, -0.029631201177835464, 0.02111699990928173, 0.06095200404524803, 0.01570655032992363, -0.00957207940518856, -0.017285289242863655, 0.05096998065710068, -0.03255875036120415, -0.04865913838148117, -0.0024023381993174553, 0.015602771192789078, 0.027508385479450226, 0.02096819505095482, -0.015854960307478905, -0.04421546682715416, 0.02218909189105034, -0.0005709604592993855, -0.021444516256451607, -0.04082903265953064, -0.042021822184324265, 0.012679705396294594, -0.028541002422571182, 0.012913857586681843, -0.03300686553120613, 0.006997641641646624, -0.0075650205835700035, 0.016614237800240517, 0.03158173710107803, -0.009932136163115501, 0.001870741369202733, -0.0069455597549676895, -0.0016759982099756598, -0.06198151782155037, 0.014867542311549187, 0.019854342564940453, 0.05374341458082199, 0.006615424528717995, 0.06048523634672165, 0.03606536611914635, 0.0037343078292906284, -0.006885632406920195, 0.014468756504356861, 0.029245659708976746, -0.006484535988420248, 0.03887674957513809, -0.028635237365961075, 0.02100387029349804, -0.023946603760123253, 0.005721625406295061, 0.024261342361569405, 0.019569113850593567, 0.00764174060896039, 0.03504033386707306, -0.006612018682062626, -0.029819602146744728, -0.018828822299838066, 0.006295328959822655, -0.01715455949306488, -0.004417384043335915, -0.02226104773581028, -0.005458242259919643, 0.0006021847948431969, 0.014815259724855423, -0.025590764358639717, -0.06774187088012695, 0.05144108086824417, 0.01388376485556364, -0.0321609228849411, -0.025429697707295418, 0.0037308691535145044, 0.03346258029341698, 0.08554603904485703, 0.032988082617521286, -0.010298492386937141, -0.014935044571757317, 0.018417488783597946, 0.04836995527148247, -0.034102898091077805, 0.025801677256822586, 0.021934298798441887, 0.0423523411154747, 0.0220017209649086, 0.05397966131567955, -0.025739194825291634, 0.010250166989862919, -0.007515538018196821, 0.030218036845326424, -0.018933895975351334, -0.009310595691204071, 0.037209402769804, 0.018664997071027756, 0.010717551223933697, 0.03292220085859299, -0.00034938406315632164, -0.01008630357682705, 0.010568587109446526, 0.0025766603648662567, 0.015119782648980618, 0.0386500358581543, 0.002683937083929777, -0.0300461295992136, 0.019463783130049706, 0.02318604476749897, 0.031346600502729416, -0.02914942055940628, 0.053490977734327316, -0.004455624148249626, 0.008451304398477077, 0.025866908952593803, -0.014723703265190125, -0.0191874410957098, 0.0451786033809185, 0.010526617057621479, -0.06022820994257927, -0.00819331593811512, 0.05204153433442116, -0.049940600991249084, 0.0317520834505558, -0.018115002661943436, -0.06357035040855408, 0.007970395497977734, -0.010654835030436516, 0.028727779164910316, 0.003966873046010733, -0.05161850526928902, 0.036116983741521835, -0.023539777845144272, 0.046550486236810684, 0.05104481801390648, 0.06750961393117905, 0.0017219287110492587, 0.05492103099822998, 0.03654108941555023, 0.037479467689991, 0.006087844260036945, 0.01087169162929058, -0.01623082160949707, 0.03356223553419113, 0.04520958289504051, 0.00008764179074205458, 0.03127622231841087, -0.013428578153252602, -0.031741853803396225, 0.027299124747514725, -0.04484347254037857, -0.012809191830456257, -0.007313982583582401, -0.00599342305213213, 0.04211848974227905, -0.004372520837932825, 0.014462833292782307, -0.03753717988729477, 0.034152764827013016, 0.040298160165548325, 0.051877185702323914, 0.007209675386548042, -0.0031408285722136497, -0.010484493337571621, 0.043302856385707855, 0.028131704777479172, 0.07483894377946854, 0.015832683071494102, -0.013008716516196728, 0.045587506145238876, 0.006560084410011768, 0.058867257088422775, 0.07567344605922699, 0.018838446587324142, 0.0107581140473485, -0.029625272378325462, -0.00991075485944748, 0.0035850335843861103, 0.00973264779895544, -0.016284920275211334, 0.016066452488303185, 0.017287446185946465, -0.04451142996549606, -0.015911336988210678, -0.01584618166089058, 0.0024901574943214655, -0.015854191035032272, -0.010703332722187042, 0.007206081412732601, 0.03782568499445915, -0.020268458873033524, -0.04196770861744881, -0.027685662731528282, -0.0020792600698769093, 0.0046789138577878475, 0.028689175844192505, -0.042601265013217926, 0.003440920263528824, -0.0322415791451931, -0.01856420747935772, 0.007633762434124947, -0.0035785590298473835, -0.024795101955533028, 0.006221672520041466, -0.022120805457234383, 0.046570371836423874, -0.04451790452003479, 0.05451570078730583, 0.0062875389121472836, 0.0032693264074623585, -0.01779092103242874, -0.0012302611721679568, -0.002010588301345706, -0.003122389782220125, 0.03244416043162346, -0.009967988356947899, -0.028860878199338913, -0.026231735944747925, 0.049683235585689545, 0.013551696203649044, 0.0007749323267489672, -0.026362387463450432, -0.004448725376278162, 0.0024487923365086317, -0.033928267657756805, 0.00486280070617795, -0.009116804227232933, 0.015326933935284615, -0.017221415415406227, -0.03738613426685333, -0.012167761102318764, 0.002091143513098359, -0.012055926024913788, 0.007607673294842243, 0.06490390002727509, -0.022203583270311356, -0.029370684176683426, -0.01624104380607605, 0.03859343379735947, 0.02207673154771328, 0.003681628732010722, 0.027521511539816856, 0.018530774861574173, 0.0654148980975151, -0.0068703037686645985, 0.01448760274797678, -0.05490918457508087, -0.009535667486488819, -0.03733576089143753, -0.051849670708179474, -0.016099758446216583, -0.023967484012246132, -0.04215197637677193, -0.011893721297383308, -0.024644745513796806, 0.016648845747113228, 0.005854418501257896, -0.010575858876109123, -0.034380167722702026, -0.016426745802164078, 0.027448125183582306, -0.0021583919879049063, 0.05252791941165924, 0.018725210800766945, 0.049953363835811615, 0.00045867584412917495, -0.007530951872467995, 0.02818223461508751, 0.039088986814022064, 0.007583449594676495, 0.007684121374040842, -0.02055003121495247, 0.016932526603341103, -0.03515249490737915, -0.04383577033877373, -0.003559973556548357, 0.015270497649908066, -0.017438525334000587, 0.023902984336018562, 0.022989440709352493, 0.01852092519402504, -0.02433484047651291, -0.0020022487733513117, -0.0051191565580666065, -0.016640685498714447, 0.002491232007741928, 0.024685557931661606, -0.03242528811097145, -0.004629607778042555, 0.04601696878671646, 0.022253237664699554, 0.029859527945518494, 0.008663635700941086, 0.04142305627465248, -0.0076852478086948395, 0.009461930952966213, -0.023946164175868034, -0.01639426499605179, -0.02663794532418251, -0.028958693146705627, -0.009002698585391045, -0.007777328137308359, -0.039126306772232056, 0.0013793440302833915, 0.02082795277237892, 0.02708422765135765, -0.03572435677051544, 0.014800649136304855, 0.02287687174975872, 0.05779430642724037, -0.012508333660662174, 0.02295016497373581, -0.00260399142280221, 0.02852860651910305, 0.025506865233182907, 0.02888084016740322, -0.009609214030206203, 0.0227449219673872 ]
How to generate text: using different decoding methods for language generation with Transformers
patrickvonplaten
March, 2020
how-to-generate
guide, nlp
https://huggingface.co/blog/how-to-generate
Conclusion As ad-hoc decoding methods, top-p and top-K sampling seem to produce more fluent text than traditional greedy - and beam search on open-ended language generation. There is evidence that the apparent flaws of greedy and beam search - mainly generating repetitive word sequences - are caused by the model (especially the way the model is trained), rather than the decoding method, cf. Welleck et al. (2019). Also, as demonstrated in Welleck et al. (2020), it looks as top-K and top-p sampling also suffer from generating repetitive word sequences. In Welleck et al. (2019), the authors show that according to human evaluations, beam search can generate more fluent text than Top-p sampling, when adapting the model's training objective. Open-ended language generation is a rapidly evolving field of research and as it is often the case there is no one-size-fits-all method here, so one has to see what works best in one's specific use case. Fortunately, you can try out all the different decoding methods in transfomers 🤗 -- you can have an overview of the available methods here. Thanks to everybody, who has contributed to the blog post: Alexander Rush, Julien Chaumand, Thomas Wolf, Victor Sanh, Sam Shleifer, Clément Delangue, Yacine Jernite, Oliver Åstrand and John de Wasseige.
[ 0.032403551042079926, 0.014942373149096966, 0.019527608528733253, 0.002095057163387537, 0.034768637269735336, 0.031515564769506454, 0.016963476315140724, -0.013505022041499615, -0.03362809866666794, -0.05949033424258232, -0.1296330690383911, -0.062125373631715775, -0.0072342646308243275, -0.028804944828152657, 0.03295481577515602, -0.008058059960603714, 0.01732831634581089, 0.02113245241343975, 0.027988316491246223, 0.020376289263367653, 0.015887625515460968, 0.03164453059434891, 0.06817133724689484, -0.03770983964204788, 0.041170910000801086, -0.0663062334060669, -0.019762499257922173, -0.0670035108923912, -0.05970211327075958, -0.01909453794360161, -0.11154025048017502, 0.0041275424882769585, 0.03294898569583893, 0.021176030859351158, -0.07002084702253342, -0.040118396282196045, -0.08295029401779175, 0.04438813030719757, -0.0029839074704796076, -0.04509137570858002, -0.036320798099040985, -0.05464155226945877, 0.00840076245367527, 0.06479369848966599, -0.01025351881980896, 0.004288196563720703, -0.0990971028804779, 0.03005707636475563, -0.10312090814113617, -0.03323119133710861, -0.10283160954713821, 0.05209069326519966, -0.006302194204181433, 0.03689898923039436, -0.0012373082572594285, 0.014608388766646385, 0.0038389707915484905, -0.06471344083547592, 0.0538976714015007, 0.011912232264876366, -0.03901408612728119, -0.006252397783100605, 0.03700558468699455, 0.008519528433680534, 0.00964974146336317, -0.0199159923940897, -0.04749531298875809, 0.04026808217167854, -0.012931968085467815, 0.032108526676893234, -0.006605430040508509, 0.0051130144856870174, -0.03500586003065109, -0.006543631199747324, 0.05190981924533844, 0.01680651307106018, -0.003538555698469281, 0.07008551806211472, -0.012678953818976879, -0.03390980139374733, 0.0016197104705497622, 0.036565132439136505, 0.01982807368040085, 0.024138348177075386, 0.06045958772301674, 0.03341185301542282, 0.04795956611633301, -0.004644187167286873, -0.05033373460173607, -0.003245110623538494, -0.025536706671118736, -0.15096119046211243, -0.015199745073914528, 0.06380190700292587, 0.022570068016648293, -0.005482279229909182, 0.02773454040288925, 0.09188033640384674, 0.02192702144384384, 0.005378334783017635, 0.02286134846508503, -0.03680245205760002, 0.01949756219983101, -0.008397805504500866, -0.06716039031744003, -0.0033455840311944485, -0.01986587792634964, -0.007410139311105013, 0.004344789776951075, 0.016560744494199753, 0.009325509890913963, 0.03285204619169235, 0.03830282762646675, -0.01080275047570467, -0.08429544419050217, -0.004802283365279436, -0.008280551061034203, 0.04492802917957306, -0.08669596910476685, -0.05368252843618393, -0.035159800201654434, 0.06280190497636795, 0.007327822037041187, -0.0645778626203537, 0.008152537979185581, 0.002474972978234291, 0.025156181305646896, 0.06743405014276505, -0.024385347962379456, 0.028584009036421776, 0.043173614889383316, 0.004411239176988602, 0.018543574959039688, 0.028958173468708992, -0.004172128159552813, 0.017260028049349785, 0.02842278778553009, -0.07700783014297485, -0.07653118669986725, -0.01524049136787653, -0.058877959847450256, -0.005044467281550169, -0.007829954847693443, 0.029835011810064316, -0.013073169626295567, 0.026198552921414375, -0.08786678314208984, 0.05628228932619095, -0.023851236328482628, 0.028690453618764877, 0.011578869074583054, 0.1201244369149208, -0.00002063258580164984, -0.038412656635046005, 0.039455462247133255, 0.06728458404541016, -0.0027005497831851244, 0.006634884048253298, -0.041826032102108, 0.010211668908596039, -0.019707409664988518, 0.019575420767068863, 0.04400560259819031, 0.03139175474643707, 0.029263444244861603, -0.013472866266965866, 0.00725747412070632, 0.06971310824155807, -0.059444691985845566, 0.026011856272816658, -0.01221440639346838, 0.05563037469983101, 0.09798677265644073, -0.06729543954133987, -0.002196769928559661, -0.00016080580826383084, -0.054032083600759506, -0.025228548794984818, -0.0017221440793946385, -0.00686370674520731, -0.06802335381507874, 0.01523679494857788, 0.028308771550655365, 0.0031809951178729534, 0.022283097729086876, -0.07832653075456619, 0.039542146027088165, 0.022545166313648224, -0.02368321269750595, 0.02283964678645134, -0.03165963292121887, -0.06377049535512924, 0.12448297441005707, -0.021881146356463432, 0.002151407767087221, -0.06980796158313751, 0.04886257275938988, 0.07609228789806366, 0.09016768634319305, 0.08116119354963303, 0.10436955094337463, 0.045929063111543655, 0.03171868249773979, -0.006788867991417646, -0.0480460450053215, -0.022652655839920044, -0.0004043474909849465, 0.021786058321595192, 0.006148978136479855, 0.0521383136510849, -0.00645044120028615, -0.07606464624404907, -0.02330332249403, -0.11278557032346725, 0.005251334980130196, -0.009473076090216637, 0.02178410068154335, 0.016857240349054337, 0.03565775603055954, 0.0026905585546046495, 0.12475807219743729, -0.05540801212191582, -0.04431761056184769, -0.0038201375864446163, -0.024730471894145012, 0.07545880973339081, 0.06733816862106323, 0.013618690893054008, 0.021042926236987114, -0.026509854942560196, -0.007815823890268803, -0.05180426314473152, 0.06794050335884094, 0.02143695205450058, -0.003187756985425949, -0.018840327858924866, -0.013473646715283394, -0.02491431124508381, -0.047660090029239655, -0.02875685505568981, -0.04414237663149834, -0.017671829089522362, -0.08033351600170135, 0.04701337590813637, 0.0275557953864336, -0.046407975256443024, 0.0905362069606781, -0.017363106831908226, -0.05355655401945114, -0.02788909524679184, -0.04830411076545715, 0.11631494015455246, -0.0394391268491745, -0.07588851451873779, -0.013169875368475914, 0.013194247148931026, 0.0024402516428381205, -0.031081829220056534, -0.008573020808398724, 0.013840354979038239, -0.018809663131833076, -0.07192394137382507, 0.003705488983541727, -0.018322564661502838, 0.02137231081724167, -0.02037743479013443, 0.013839658349752426, 0.01263515930622816, 0.016696665436029434, 0.04455741122364998, -0.0265541672706604, -0.017466019839048386, -0.024113928899168968, 0.020431218668818474, 0.014493121765553951, 0.019052084535360336, 0.01057464350014925, -0.071143239736557, -0.024963825941085815, -0.03013540245592594, -0.05709430202841759, 0.026292618364095688, 0.03437228500843048, 0.040594350546598434, 0.01401894073933363, -0.031800348311662674, -0.03277987614274025, -0.010388564318418503, -0.038115907460451126, 0.02048848569393158, -0.025624331086874008, 0.004242344293743372, -0.05677976459264755, 0.014676659367978573, -0.004031869117170572, -0.0026406433898955584, -0.04160946235060692, 0.026637645438313484, -0.052453745156526566, -0.001077137072570622, -0.06600698828697205, -0.001990986755117774, -0.03448457643389702, 0.0043991077691316605, -0.030541645362973213, -0.024886751547455788, -0.008073976263403893, 0.04773510992527008, -0.08554726094007492, -0.006647946313023567, 0.0005169878713786602, -0.019201213493943214, -0.018312539905309677, -0.009811854921281338, 0.00414094515144825, -0.019089199602603912, -0.012141900137066841, 0.015542811714112759, 0.006378539372235537, 0.032306600362062454, -0.01401996798813343, 0.03224378079175949, 0.011685576289892197, -0.0402795672416687, -0.026919933035969734, 0.023111173883080482, 0.04979560524225235, 0.023015672340989113, 0.04826423153281212, -0.0034423740580677986, 0.0010255174711346626, 0.021287687122821808, -0.05514628812670708, 0.008337941952049732, 0.01857847534120083, -0.010147945955395699, 0.03425086289644241, -0.05837620794773102, -0.031908292323350906, -0.009092631749808788, -0.01041176076978445, -0.0013820858439430594, -0.034951455891132355, 0.00033454305958002806, 0.031233401969075203, 0.03858410194516182, -0.024246806278824806, 0.05187338590621948, 0.0010329957585781813, -0.035627689212560654, -0.010489024221897125, -0.004485317040234804, -0.007662543561309576, 0.019968563690781593, -0.04340458661317825, 0.05330396071076393, 0.02923092618584633, -0.037954337894916534, -0.022591352462768555, -0.005467656534165144, -0.018504323437809944, 0.04025101661682129, 0.009000210091471672, 0.026153769344091415, 0.004850713070482016, -0.01287203561514616, 0.02625478059053421, 0.01429011207073927, -0.018963562324643135, 0.03371727839112282, 0.005261407699435949, -0.014267995953559875, -0.005328793544322252, 0.0700521171092987, 0.012780637480318546, 0.042561739683151245, -0.017272992059588432, 0.0522795245051384, -0.004910777322947979, 0.004842814523726702, 0.02355167455971241, 0.0010626609437167645, -0.0015710804145783186, 0.00025304488372057676, -0.001544050988741219, -0.05008586123585701, 0.04922759160399437, 0.021341625601053238, -0.04296007379889488, -0.0184437558054924, -0.06717514246702194, -0.0558910109102726, 0.024026302620768547, -0.005998394452035427, -0.0006493033142760396, 0.011495319195091724, 0.022137081250548363, 0.010853363201022148, -0.035683006048202515, -0.03757290542125702, 0.02517055533826351, 0.021185610443353653, -0.018185783177614212, 0.04214288666844368, 0.01453991886228323, 0.011104527860879898, 0.021079039201140404, -0.019349442794919014, 0.003016494680196047, -0.055868953466415405, -0.019803132861852646, 0.010950151830911636, -0.006137743592262268, 0.06893325597047806, -0.06617151200771332, 0.011373528279364109, -0.0018961767200380564, 0.005709407385438681, -0.024252556264400482, -0.0384325310587883, 0.022999033331871033, 0.015440935268998146, 0.020116373896598816, 0.01737784408032894, -0.0024309561122208834, -0.023924730718135834, -0.04189267382025719, -0.015819914638996124, -0.038732100278139114, 0.029215021058917046, -0.004591566510498524, -0.02459666132926941, 0.019055886194109917, -0.008639007806777954, -0.05026761814951897, 0.001781856524758041, 0.0002780531067401171, -0.002162232296541333, 0.0024474177043884993, -0.007620633114129305, 0.05230852589011192, -0.0021074048709124327, 0.04115888848900795, 0.0013453962747007608, -0.00047642478602938354, -0.032171305269002914, -0.01580619066953659, -0.02310366928577423, 0.02053946442902088, -0.004804842174053192, 0.009559105150401592, -0.008804692886769772, 0.0032411618158221245, 0.02767718769609928, 0.03755564987659454, 0.005936388857662678, 0.03833747282624245, 0.00524289533495903, 0.0590050108730793, 0.003577904310077429, -0.016636958345770836, -0.02785840630531311, -0.01237632054835558, -0.011259455233812332, -0.05287519842386246, 0.0788213312625885, -0.004225733689963818, 0.009586450643837452, 0.006253220606595278, 0.005774299614131451, -0.05625161901116371, 0.020467132329940796, -0.02308697998523712, -0.01884133741259575, 0.025263626128435135, 0.019012005999684334, -0.03704310208559036, -0.011998452246189117, 0.013545695692300797, -0.007037976756691933, 0.009739394299685955, -0.017115436494350433, -0.004044164903461933, -0.012919842265546322, 0.03057454526424408, 0.014222132973372936, -0.010068508796393871, 0.03575738146901131, -0.04259680584073067, -0.009520148858428001, 0.022014528512954712, 0.022350341081619263, 0.026760663837194443, 0.002954155905172229, 0.0684661939740181, 0.012771664187312126, -0.0234975628554821, 0.012834171764552593, -0.003891995642334223, -0.025737179443240166, 0.036519065499305725, 0.023970551788806915, 0.013006091117858887, -0.002924297470599413, 0.00610350351780653, -0.010738883167505264, 0.00407365383580327, 0.04095741733908653, 0.022032704204320908, 0.0055931261740624905, 0.04313062131404877, -0.002543453359976411, -0.004371692892163992, 0.03267785161733627, -0.01664108969271183, -0.004998185206204653, 0.002634534379467368, -0.015209757722914219, -0.0251200869679451, 0.0119645269587636, -0.08229592442512512, 0.021574223414063454, 0.002850109711289406, -0.051971837878227234, -0.03267906978726387, 0.032287221401929855, -0.005075094290077686, 0.07109387964010239, 0.019412610679864883, -0.018214596435427666, -0.06862261891365051, -0.00715024396777153, 0.015477639622986317, -0.017044663429260254, 0.003846853505820036, 0.03805958852171898, 0.010033485479652882, 0.000944718427490443, 0.05383196473121643, -0.04723082110285759, -0.008606202900409698, 0.0521368682384491, 0.011631901375949383, -0.026161806657910347, -0.009961249306797981, 0.0398816242814064, -0.022968284785747528, 0.01880464516580105, 0.022090889513492584, -0.04462316632270813, 0.04437219724059105, 0.013621557503938675, -0.046330273151397705, 0.06685101240873337, -0.009335044771432877, -0.022083645686507225, -0.04440077394247055, 0.04507151618599892, 0.05421572923660278, -0.041177112609148026, -0.014519059099256992, 0.007194084115326405, 0.0033924859017133713, -0.023749426007270813, 0.05591485649347305, -0.023306429386138916, -0.05530157312750816, 0.044239792972803116, -0.018271518871188164, -0.005099702626466751, 0.03163741156458855, 0.08142007142305374, -0.06552355736494064, 0.010138795711100101, -0.007538256701081991, -0.03655903786420822, 0.01227177307009697, 0.012691318057477474, 0.035097986459732056, -0.03103543259203434, -0.02322249859571457, 0.016960959881544113, -0.02360565774142742, 0.022582126781344414, 0.013758557848632336, 0.07956227660179138, 0.06753473728895187, 0.039540063589811325, 0.019137978553771973, 0.04874157905578613, 0.02256712131202221, -0.04602379724383354, -0.013297817669808865, 0.030066244304180145, 0.043279193341732025, 0.02498471550643444, 0.021956630051136017, -0.020671768113970757, -0.03095126524567604, 0.004524755757302046, -0.06415122002363205, 0.011851665563881397, -0.009354072622954845, -0.006053367629647255, 0.03667089715600014, 0.020772242918610573, 0.013766570016741753, -0.044070541858673096, 0.039350345730781555, 0.023274872452020645, 0.005168506875634193, 0.02654029242694378, 0.023910412564873695, 0.012826554477214813, 0.04245413467288017, 0.004048502072691917, 0.08772098273038864, -0.0073970309458673, 0.00728191202506423, 0.042236555367708206, 0.008879248052835464, 0.05622106418013573, 0.03786036744713783, -0.0028590690344572067, 0.026316674426198006, -0.0006457770359702408, 0.024045754224061966, -0.010359369218349457, 0.05237869545817375, 0.020996900275349617, 0.00908726267516613, -0.016872361302375793, -0.00696997344493866, -0.027952710166573524, -0.030255842953920364, -0.036186739802360535, 0.01871665008366108, 0.005424627102911472, -0.01703101396560669, 0.04797196015715599, -0.005907944869250059, -0.041935909539461136, 0.02190517447888851, 0.03810511901974678, -0.002383193699643016, 0.06232660263776779, -0.02407555840909481, -0.025508180260658264, -0.03208911046385765, -0.0008927704766392708, 0.004684287589043379, -0.00032484132680110633, 0.011786678805947304, -0.014578917063772678, -0.006655032280832529, 0.005827960092574358, 0.018130706623196602, 0.017342016100883484, -0.0037101684138178825, -0.012405630201101303, -0.026675784960389137, 0.023497439920902252, -0.00989109743386507, 0.025853706523776054, 0.024957546964287758, -0.01363128237426281, -0.02921832539141178, -0.016157101839780807, 0.0039445809088647366, -0.0007245937013067305, 0.03020722046494484, -0.015123809687793255, -0.011430582962930202, -0.030713289976119995, -0.013442632742226124, -0.01620533876121044, 0.011467980220913887, 0.005088336765766144, -0.045595645904541016, -0.0039850398898124695, -0.049490466713905334, -0.008077736012637615, 0.000493869069032371, -0.010622013360261917, 0.026200763881206512, 0.008114749565720558, 0.008656677789986134, -0.010417538695037365, 0.04621889069676399, -0.00743382703512907, -0.019606322050094604, 0.024388890713453293, -0.013637930154800415, 0.026992473751306534, 0.007895693182945251, 0.012537083588540554, -0.049392834305763245, 0.01461021788418293, -0.04793158546090126, -0.06670570373535156, 0.014114960096776485, 0.014717426151037216, -0.006705051753669977, -0.0014750347472727299, -0.0292368121445179, 0.04725423455238342, -0.013294990174472332, 0.013938218355178833, -0.04737933725118637, 0.014550929889082909, 0.06004687398672104, -0.020805438980460167, 0.005202847067266703, 0.013716372661292553, 0.06390681862831116, -0.0107005275785923, -0.02175423502922058, 0.028404634445905685, 0.032716743648052216, 0.04735555499792099, 0.02500251680612564, -0.010082746855914593, 0.003826876636594534, 0.00222395989112556, -0.050018686801195145, -0.015667056664824486, -0.002385589526966214, 0.02538500353693962, 0.0011263934429734945, 0.02215164341032505, 0.005827865097671747, -0.01697308011353016, -0.05389298126101494, 0.004236990585923195, -0.02013964205980301, 0.010776786133646965, 0.01943313702940941, -0.030331535264849663, -0.012844836339354515, -0.01326681300997734, 0.08317992091178894, 0.004110358655452728, 0.015012049116194248, -0.0028662490658462048, 0.007044277153909206, 0.0003133999998681247, 0.004515601322054863, 0.01655539497733116, -0.012728467583656311, -0.01720934361219406, 0.07835877686738968, -0.034221064299345016, -0.009812911972403526, 0.018798833712935448, 0.05983102321624756, 0.009441337548196316, -0.010264750570058823, 0.0015557410661131144, 0.02519576996564865, 0.0004578974039759487, -0.010760645382106304, -0.013025350868701935, 0.035245783627033234, 0.036557674407958984, 0.037320103496313095, 0.011743850074708462, 0.0034810092765837908, 0.0016098521882668138 ]
How to generate text: using different decoding methods for language generation with Transformers
patrickvonplaten
March, 2020
how-to-generate
guide, nlp
https://huggingface.co/blog/how-to-generate
Appendix generate has evolved into a highly composable method, with flags to manipulate the resulting text in many directions that were not covered in this blog post. Here are a few helpful pages to guide you: - How to parameterize generate - How to stream the output - Full list of decoding options - generate API reference - LLM score leaderboard If you find that navigating our docs is challenging and you can't easily find what you're looking for, drop us a message in this GitHub issue. Your feedback is critical to set our future direction! 🤗
[ 0.043817032128572464, -0.01621835120022297, 0.14616671204566956, -0.06470081210136414, 0.130752295255661, -0.028828449547290802, 0.01611296273767948, 0.04866698384284973, -0.026236385107040405, -0.0909317135810852, -0.04398210346698761, -0.041485745459795, -0.023544879630208015, 0.021369513124227524, -0.0024460391141474247, 0.02890913188457489, 0.004382125101983547, 0.02637074887752533, 0.008201193995773792, 0.018823832273483276, 0.020400872454047203, 0.005698692984879017, 0.055933140218257904, -0.04198095202445984, 0.04434511438012123, -0.023393569514155388, -0.02315329946577549, -0.021603932604193687, -0.08008792251348495, 0.008387531153857708, -0.018961040303111076, -0.012114795856177807, 0.017109833657741547, -0.006624104455113411, -0.047274552285671234, -0.001013516215607524, -0.09288603812456131, -0.002734068315476179, 0.01651787757873535, 0.018719278275966644, -0.027277832850813866, -0.030227800831198692, -0.013001810759305954, 0.06155769154429436, -0.043957602232694626, -0.037549737840890884, -0.18513123691082, 0.05249735713005066, -0.11572054773569107, 0.0015042971353977919, -0.04890226945281029, 0.051093921065330505, -0.03645237162709236, -0.046147651970386505, 0.00981929898262024, 0.006060643587261438, 0.02735813707113266, -0.07211955636739731, 0.04134663939476013, 0.02841748483479023, 0.013226932846009731, 0.006320510059595108, 0.026253072544932365, 0.028184140101075172, 0.0965442955493927, 0.03338424488902092, -0.04743935912847519, 0.06311172246932983, -0.04750072956085205, 0.019330903887748718, 0.019708959385752678, -0.04376821592450142, -0.01863051950931549, -0.04805797338485718, -0.006035174708813429, -0.07349681109189987, -0.02794504538178444, 0.11282461881637573, 0.010266486555337906, 0.031385473906993866, 0.008969001471996307, 0.038394633680582047, 0.05274731665849686, 0.001580550684593618, -0.01892605982720852, 0.03052838146686554, 0.06509522348642349, -0.007214627228677273, -0.05284149944782257, 0.029009724035859108, -0.00861671008169651, -0.1449662297964096, -0.02778417244553566, 0.03948722779750824, -0.0009474888211116195, -0.0167743768543005, 0.018627183511853218, 0.029184291139245033, -0.015586387366056442, 0.03568694740533829, 0.01107007171958685, 0.014331042766571045, 0.0591927170753479, -0.016797082498669624, -0.06296724826097488, -0.0036610197275877, -0.06976398825645447, -0.07232480496168137, -0.03484506160020828, 0.07972288131713867, 0.008090982213616371, 0.0613437183201313, 0.026797108352184296, 0.03736521303653717, -0.03116648644208908, 0.06845846772193909, -0.009219147264957428, -0.00037866810453124344, -0.07450778782367706, -0.017037145793437958, 0.008198218420147896, 0.08435032516717911, 0.06611936539411545, 0.006381609942764044, 0.01536200474947691, 0.056342169642448425, 0.061106372624635696, 0.03299415111541748, -0.012854818254709244, 0.010434108786284924, 0.042042408138513565, 0.023336203768849373, -0.013533567078411579, -0.01181027665734291, -0.030384154990315437, -0.02247764728963375, -0.007987610064446926, -0.04983881488442421, 0.0222841277718544, 0.0020912548061460257, 0.0070208171382546425, -0.01119194831699133, -0.0571618378162384, -0.0005761540378443897, -0.03963100165128708, -0.027742350473999977, -0.055576108396053314, -0.0028631098102778196, -0.03211602568626404, 0.04712601751089096, 0.04400414228439331, 0.04279095306992531, -0.015712803229689598, -0.07018618285655975, 0.022741645574569702, 0.058673687279224396, 0.0158605445176363, 0.018230635672807693, -0.08430115878582001, -0.01649031788110733, 0.04237106442451477, 0.053149230778217316, -0.07460538297891617, 0.02137683890759945, 0.025978082790970802, -0.0023452788591384888, 0.004912815056741238, 0.02304210141301155, -0.06424828618764877, -0.027064399793744087, -0.04857632517814636, -0.02706957794725895, 0.06736224889755249, 0.004591198172420263, 0.05390661954879761, 0.01850007101893425, 0.04810784384608269, 0.03603494167327881, -0.004897641018033028, 0.008853566832840443, -0.0741945281624794, -0.009925128892064095, 0.04814592003822327, -0.043699413537979126, 0.0010057772742584348, -0.05914441496133804, 0.050957903265953064, -0.08654246479272842, 0.011558490805327892, 0.0035042413510382175, -0.09149879217147827, -0.0011358142364770174, 0.07623769342899323, 0.01607496105134487, -0.06559383869171143, -0.02909143455326557, -0.04437734931707382, 0.11553065478801727, 0.04168609902262688, 0.062384508550167084, 0.022116713225841522, 0.09130226820707321, 0.06352865695953369, 0.02003609761595726, -0.06807368248701096, 0.011379843577742577, 0.012657846324145794, -0.018931904807686806, 0.08367472141981125, -0.012812050990760326, 0.01557413674890995, -0.029359111562371254, -0.013375550508499146, -0.09087888896465302, -0.041432999074459076, -0.0001213352516060695, -0.0048950957134366035, 0.03007824905216694, -0.007844237610697746, -0.027290616184473038, 0.14516973495483398, -0.024980274960398674, 0.01109434012323618, -0.02268412709236145, -0.01370877493172884, 0.10374453663825989, -0.023494603112339973, 0.06985411792993546, -0.00439137127250433, -0.08534424751996994, 0.016030967235565186, 0.0015468229539692402, -0.04118317365646362, 0.024928288534283638, -0.04566989466547966, -0.010706750676035881, -0.011810696683824062, 0.043813955038785934, 0.06286265701055527, -0.07946830987930298, 0.043701402842998505, 0.0020014483015984297, -0.038281701505184174, -0.01081798691302538, 0.009657960385084152, 0.013006845489144325, 0.06899289786815643, -0.033056121319532394, -0.006043432280421257, 0.03157166764140129, -0.05082753673195839, 0.05377516150474548, 0.014473363757133484, -0.03253110125660896, 0.04117286577820778, -0.007673630025237799, -0.02404710464179516, -0.00920057576149702, -0.012028571218252182, 0.010257621295750141, -0.001077761291526258, -0.052382778376340866, -0.009992753155529499, -0.03863843157887459, 0.04767356440424919, -0.0033214956056326628, 0.012040704488754272, 0.006772467866539955, -0.01621135137975216, 0.023246482014656067, -0.010139982216060162, -0.007348336279392242, 0.010374781675636768, -0.000348130997736007, 0.02156500332057476, -0.019069410860538483, 0.03724290803074837, -0.04037864878773689, -0.00935459230095148, -0.04134505242109299, -0.01861303485929966, -0.006390935741364956, 0.04966311156749725, 0.005950744729489088, 0.02561504952609539, -0.0246299896389246, -0.029312822967767715, -0.02481171488761902, -0.013366775587201118, 0.024996783584356308, -0.0031120406929403543, 0.04333939030766487, -0.011749209836125374, 0.00599633576348424, 0.04151393473148346, -0.00907328724861145, 0.03613320738077164, -0.01261725090444088, -0.03104534186422825, -0.009734625928103924, 0.028189335018396378, -0.007677111774682999, 0.017924780026078224, -0.03503017500042915, -0.04980384185910225, 0.026837319135665894, 0.011173584498465061, 0.02966570109128952, -0.11593209207057953, -0.05180880427360535, 0.007615778129547834, -0.01289596688002348, 0.005446464288979769, -0.017851484939455986, 0.05744834616780281, -0.020617643371224403, -0.008703514002263546, -0.0036851512268185616, 0.00033227604581043124, -0.012878235429525375, 0.031222917139530182, -0.009484531357884407, 0.004955992568284273, 0.010442246682941914, -0.04301855340600014, 0.006308847106993198, -0.004403974860906601, -0.031953368335962296, 0.016051115468144417, 0.02609449252486229, 0.03473004326224327, -0.03890257328748703, -0.0012316418578848243, -0.003682164940983057, 0.008699643425643444, 0.031409330666065216, -0.008106179535388947, -0.036246806383132935, -0.0011050032917410135, 0.015652665868401527, 0.03896293044090271, -0.0027630769181996584, -0.06073922663927078, -0.0192007627338171, 0.010524868965148926, -0.005545325577259064, 0.014742030762135983, 0.021406423300504684, 0.00047257819096557796, 0.013957426883280277, 0.019288212060928345, -0.02661142498254776, 0.004854485858231783, -0.018578913062810898, -0.0076368884183466434, -0.003440679982304573, 0.03151954710483551, -0.06463173031806946, -0.06269732862710953, -0.005892814137041569, -0.02053723856806755, 0.03998864069581032, -0.03277406468987465, -0.005284254439175129, 0.007846170105040073, 0.011809701099991798, 0.049713075160980225, -0.0649336725473404, -0.009326469153165817, -0.020578164607286453, -0.03565933182835579, 0.028654024004936218, 0.00452805683016777, 0.09299948811531067, 0.019458934664726257, -0.011392438784241676, 0.001917730551213026, 0.05844492092728615, 0.005515035707503557, 0.000315830489853397, 0.0006077145808376372, 0.015043764375150204, -0.04875167831778526, 0.008737897500395775, -0.05049016699194908, -0.015381194651126862, 0.06909865140914917, 0.02859986573457718, -0.05054445192217827, 0.008986747823655605, -0.019992263987660408, -0.002749053295701742, -0.006424214690923691, -0.01158920582383871, 0.004673439543694258, -0.005603693891316652, 0.009164156392216682, 0.0009295949712395668, 0.024378381669521332, -0.023875972256064415, -0.02869369462132454, -0.03155083209276199, -0.014157530851662159, 0.03396495431661606, 0.019807210192084312, 0.013552354648709297, 0.05136031657457352, 0.028532495722174644, 0.030727310106158257, -0.04482962191104889, 0.002654032548889518, 0.009968922473490238, -0.02947916090488434, 0.026915496215224266, -0.03383142873644829, -0.016457965597510338, 0.010926325805485249, 0.051802802830934525, -0.008975007571280003, -0.020156048238277435, -0.010090149939060211, -0.002231133636087179, -0.008874787949025631, 0.02466893009841442, 0.008487047627568245, -0.03254306688904762, -0.016544640064239502, -0.03288721665740013, -0.06723479926586151, -0.019324472174048424, 0.0678296759724617, 0.005971233826130629, -0.003252780996263027, -0.008681620471179485, 0.005394377745687962, 0.021102674305438995, 0.010176046751439571, 0.021423084661364555, 0.0064178043976426125, -0.0023494523484259844, 0.0284731462597847, -0.010137545876204967, 0.03053259663283825, 0.02475670538842678, -0.026397980749607086, 0.01114896684885025, 0.014198612421751022, -0.06516576558351517, 0.013677369803190231, -0.041193876415491104, 0.011742650531232357, 0.013115162961184978, 0.022174261510372162, -0.02222471311688423, -0.014424772933125496, -0.011147623881697655, 0.014698159880936146, -0.009680826216936111, 0.04732799530029297, 0.015842732042074203, 0.006642800755798817, -0.05342794582247734, -0.0037845259066671133, 0.005842519458383322, -0.03250643238425255, 0.04926225170493126, -0.027729354798793793, 0.02481965348124504, 0.004270851146429777, 0.015430920757353306, 0.01644173264503479, 0.006819149479269981, -0.020758964121341705, 0.07042620331048965, 0.010343209840357304, 0.0279146209359169, 0.005844671744853258, -0.014567120000720024, -0.01742369495332241, 0.012344790622591972, 0.021483752876520157, -0.044162850826978683, -0.0018622421193867922, -0.0015782458940520883, 0.04013875499367714, 0.04092587158083916, 0.002832158701494336, 0.03209850564599037, -0.01911676861345768, -0.035804376006126404, 0.06653271615505219, -0.006488703191280365, 0.0028444991912692785, 0.007322058081626892, 0.07830825448036194, 0.01617269590497017, 0.0005962863215245306, 0.014333846978843212, -0.002734862035140395, -0.03314584866166115, 0.020985078066587448, -0.06966345012187958, 0.00008086644083959982, -0.010520718060433865, -0.0032504801638424397, 0.015007881447672844, -0.018795741721987724, -0.020579379051923752, 0.08199626952409744, 0.04496876522898674, 0.016890332102775574, -0.02499012090265751, -0.007845957763493061, -0.03330240771174431, 0.006827214732766151, -0.03535180911421776, -0.005539667792618275, -0.055154599249362946, -0.0250584427267313, 0.020365489646792412, -0.026718365028500557, -0.005091085564345121, 0.02199188619852066, -0.007217105012387037, 0.009314053691923618, -0.003578375093638897, -0.035677190870046616, 0.05253835767507553, 0.020239686593413353, -0.026608774438500404, -0.00618444848805666, 0.03590104356408119, -0.010350141674280167, 0.030526630580425262, -0.011636524461209774, 0.023064857348799706, 0.01916237734258175, -0.014402568340301514, 0.0633881539106369, 0.007489768788218498, -0.008668881841003895, 0.05853462591767311, 0.011058053001761436, 0.0189556572586298, -0.05586976185441017, 0.011123882606625557, 0.015315992757678032, 0.028395211324095726, -0.0007116134511306882, -0.024068642407655716, -0.058815885335206985, 0.025365471839904785, -0.01587682031095028, 0.07033704221248627, 0.0013907558750361204, -0.012364187277853489, 0.013232299126684666, 0.01527177169919014, 0.04839980602264404, -0.01115667074918747, 0.003514757612720132, -0.023905785754323006, -0.0019263967406004667, 0.0028207225259393454, 0.050662215799093246, -0.047491371631622314, -0.00026860192883759737, 0.029231932014226913, -0.00005813154348288663, -0.033392928540706635, 0.0081715676933527, 0.05533701553940773, -0.023800650611519814, 0.041220806539058685, -0.007895974442362785, -0.01934024505317211, -0.00405379431322217, 0.014220036566257477, 0.016533201560378075, 0.04966990277171135, 0.016875717788934708, -0.01800503581762314, 0.010534185916185379, 0.004126443527638912, -0.00006154887523734942, 0.04391929507255554, 0.005624263547360897, 0.0478084459900856, -0.02715829759836197, 0.04898896813392639, -0.0040924870409071445, 0.026359401643276215, -0.002487495541572571, 0.03831346705555916, 0.02977832220494747, 0.052704039961099625, 0.0015815147198736668, -0.018115904182195663, -0.016159217804670334, -0.021126393228769302, -0.06387525796890259, 0.00836833007633686, -0.03971606120467186, 0.019504178315401077, 0.046819064766168594, -0.0030612293630838394, 0.024652816355228424, -0.05556151643395424, 0.03771955147385597, 0.0043886564671993256, 0.017301877960562706, -0.01649622432887554, 0.007809031289070845, 0.01574009843170643, -0.020803071558475494, 0.00559352757409215, 0.017817040905356407, -0.008194792084395885, -0.05562341958284378, 0.07463938742876053, 0.0062494599260389805, 0.0026230481453239918, 0.03907395526766777, -0.032622210681438446, 0.018489202484488487, -0.0009715792839415371, 0.025103801861405373, 0.015371420420706272, 0.01191422063857317, 0.006493423134088516, -0.01000618189573288, -0.02467510476708412, -0.014027263969182968, -0.03967346251010895, 0.026222167536616325, -0.022648533806204796, -0.012225904501974583, -0.009573518298566341, -0.0039905826561152935, 0.03959466144442558, -0.0038572850171476603, -0.012611608020961285, -0.016145171597599983, 0.00342015759088099, 0.02172195166349411, 0.030388521030545235, -0.04289615899324417, 0.0015921819722279906, -0.035179536789655685, -0.0004855598381254822, 0.018426263704895973, 0.02109692059457302, -0.0059463041834533215, -0.01642218977212906, 0.025397105142474174, -0.00780165521427989, -0.01691608503460884, 0.04530089348554611, -0.003377550980076194, 0.03543935343623161, -0.04034067690372467, 0.005597688723355532, 0.005371556151658297, 0.0015291511081159115, 0.00972955022007227, -0.013671583496034145, -0.012670885771512985, -0.041125357151031494, 0.03357371315360069, 0.004678940400481224, 0.02818823605775833, -0.05387367680668831, -0.032593633979558945, -0.012639190070331097, -0.021387342363595963, 0.03346967324614525, -0.02128843404352665, 0.017487624660134315, -0.022105565294623375, -0.016640959307551384, 0.003920245449990034, 0.03045082651078701, -0.006817811168730259, 0.024478303268551826, 0.013827242888510227, -0.011134237051010132, -0.04662465304136276, -0.03972623497247696, 0.049586258828639984, 0.0020964418072253466, 0.009017414413392544, 0.043994590640068054, 0.0007576263160444796, 0.03199361264705658, -0.005555834621191025, 0.020744062960147858, -0.037537749856710434, 0.03431369364261627, -0.06760680675506592, -0.058633655309677124, 0.004079023841768503, -0.019931616261601448, 0.0010817907750606537, 0.03625897318124771, 0.02719784714281559, -0.023935610428452492, -0.012751906178891659, -0.058361299335956573, -0.020629744976758957, -0.0020015710033476353, 0.06613858789205551, 0.012381023727357388, 0.05025223642587662, 0.018518349155783653, -0.002951001049950719, -0.004557354375720024, 0.0190584734082222, 0.025284016504883766, 0.02323317341506481, 0.026954451575875282, 0.004356767982244492, 0.006339543499052525, 0.011208618059754372, -0.07402390986680984, -0.027462776750326157, -0.0173463374376297, 0.02902797982096672, -0.041631296277046204, -0.008526226505637169, 0.012992063537240028, 0.03575325384736061, 0.005893283523619175, -0.009779529646039009, -0.016228778287768364, 0.010704715736210346, 0.003965320996940136, -0.019160516560077667, -0.07898662239313126, 0.008245265111327171, 0.0064798155799508095, 0.005440689157694578, 0.030761349946260452, -0.029397541657090187, -0.023504583165049553, -0.00030659750336781144, -0.009936196729540825, -0.003152086166664958, 0.029356244951486588, -0.02762717753648758, 0.027529796585440636, 0.012078018859028816, 0.0084875812754035, -0.046159062534570694, -0.00007388676749542356, 0.03361201658844948, 0.009548958390951157, -0.005081574898213148, 0.0019167665159329772, -0.030626537278294563, 0.010595294646918774, 0.0462888702750206, 0.03770522400736809, 0.036966923624277115, 0.05647975206375122, 0.013342533260583878, 0.020207995548844337, -0.02006622403860092, -0.029119864106178284 ]
How to generate text: using different decoding methods for language generation with Transformers
patrickvonplaten
March, 2020
how-to-generate
guide, nlp
https://huggingface.co/blog/how-to-generate
Sampling In its most basic form, sampling means randomly picking the next word \(w_t\) according to its conditional probability distribution: $$ w_t \sim P(w|w_{1:t-1}) $$ Taking the example from above, the following graphic visualizes language generation when sampling. It becomes obvious that language generation using sampling is not deterministic anymore. The word \((\text{"car"})\) is sampled from the conditioned probability distribution \(P(w | \text{"The"})\), followed by sampling \((\text{"drives"})\) from \(P(w | \text{"The"}, \text{"car"})\) . In transformers, we set do_sample=True and deactivate Top-K sampling (more on this later) via top_k=0. In the following, we will fix the random seed for illustration purposes. Feel free to change the set_seed argument to obtain different results, or to remove it for non-determinism. python # set seed to reproduce results. Feel free to change the seed though to get different results from transformers import set_seed set_seed(42) # activate sampling and deactivate top_k by setting top_k sampling to 0 sample_output = model.generate( **model_inputs, max_new_tokens=40, do_sample=True, top_k=0 ) print("Output:\n" + 100 * '-') print(tokenizer.decode(sample_output[0], skip_special_tokens=True)) Output: ---------------------------------------------------------------------------------------------------- I enjoy walking with my cute dog for the rest of the day, but this had me staying in an unusual room and not going on nights out with friends (which will always be wondered for a mere minute or so at this point). Interesting! The text seems alright - but when taking a closer look, it is not very coherent and doesn't sound like it was written by a human. That is the big problem when sampling word sequences: The models often generate incoherent gibberish, cf. Ari Holtzman et al. (2019). A trick is to make the distribution \(P(w|w_{1:t-1})\) sharper (increasing the likelihood of high probability words and decreasing the likelihood of low probability words) by lowering the so-called temperature of the softmax. An illustration of applying temperature to our example from above could look as follows. The conditional next word distribution of step \(t=1\) becomes much sharper leaving almost no chance for word \((\text{"car"})\) to be selected. Let's see how we can cool down the distribution in the library by setting temperature=0.6: python # set seed to reproduce results. Feel free to change the seed though to get different results set_seed(42) # use temperature to decrease the sensitivity to low probability candidates sample_output = model.generate( **model_inputs, max_new_tokens=40, do_sample=True, top_k=0, temperature=0.6, ) print("Output:\n" + 100 * '-') print(tokenizer.decode(sample_output[0], skip_special_tokens=True)) Output: ---------------------------------------------------------------------------------------------------- I enjoy walking with my cute dog, but I don't like to chew on it. I like to eat it and not chew on it. I like to be able to walk with my dog." So how did you decide OK. There are less weird n-grams and the output is a bit more coherent now! While applying temperature can make a distribution less random, in its limit, when setting temperature \(\to 0\), temperature scaled sampling becomes equal to greedy decoding and will suffer from the same problems as before.
[ 0.09365792572498322, -0.0034209166187793016, -0.008999810554087162, 0.007520679850131273, 0.11419407278299332, 0.026565421372652054, 0.037599965929985046, 0.05526881292462349, -0.02078370936214924, -0.038252558559179306, -0.13043229281902313, 0.02212735451757908, 0.02583923004567623, 0.014981082640588284, -0.040777288377285004, 0.01806243695318699, 0.026739660650491714, -0.018135039135813713, 0.06799283623695374, -0.032214149832725525, -0.006069324444979429, -0.01685766503214836, 0.06208020821213722, -0.016697587445378304, 0.07628253102302551, -0.026987696066498756, 0.01732764020562172, -0.01064222026616335, -0.03964965417981148, 0.01498609408736229, -0.1795688271522522, 0.008119197562336922, 0.03154904767870903, -0.018415942788124084, 0.010038251988589764, -0.031049581244587898, -0.14781253039836884, 0.05060373619198799, 0.04759450629353523, -0.0650244876742363, 0.006315723992884159, -0.00939314067363739, -0.017740359529852867, -0.007294462528079748, -0.057982880622148514, -0.08158674091100693, -0.1369156539440155, 0.08173868805170059, -0.11902721971273422, -0.10327372699975967, -0.09587374329566956, -0.008858188055455685, -0.030496397987008095, -0.011237013153731823, -0.01384645514190197, -0.061297088861465454, -0.006613836158066988, -0.08415688574314117, 0.0711115226149559, 0.008888468146324158, 0.0641428753733635, -0.010640877299010754, 0.03210577368736267, 0.055861830711364746, -0.00028304822626523674, -0.00485891941934824, 0.04143671318888664, 0.07010415196418762, -0.034567706286907196, -0.024935001507401466, -0.0368267297744751, -0.05234768986701965, -0.06520367413759232, 0.0052099996246397495, 0.0031263420823961496, 0.0171501561999321, -0.02843765914440155, 0.08228558301925659, 0.007435651030391455, 0.0609310083091259, 0.03561970219016075, -0.023444941267371178, 0.07899557799100876, 0.05583607777953148, 0.06603638827800751, -0.02365034818649292, 0.03212788328528404, -0.025186123326420784, -0.012154430150985718, 0.03278901055455208, -0.0576140359044075, -0.13217683136463165, -0.004509063437581062, 0.019930399954319, -0.006990935653448105, -0.019469019025564194, -0.021051017567515373, 0.07287273555994034, -0.006401457823812962, 0.0002779602073132992, -0.003506837412714958, -0.01648676209151745, 0.022291414439678192, -0.06166614592075348, -0.02541445940732956, 0.03909655287861824, 0.019665727391839027, -0.032659851014614105, -0.01667862944304943, 0.048422809690237045, -0.007201345171779394, 0.002120379591360688, 0.05122185871005058, 0.03351913392543793, -0.012922736816108227, -0.01561160758137703, -0.01705515943467617, 0.02341952919960022, -0.046704601496458054, -0.05276663228869438, -0.04506874457001686, -0.008466855622828007, 0.05476435273885727, -0.036255910992622375, -0.036243535578250885, 0.03310081362724304, 0.02749471180140972, 0.05474798008799553, -0.022278983145952225, -0.05762075260281563, 0.05254639312624931, 0.03536736220121384, 0.007819713093340397, 0.0018772288458421826, -0.007277565076947212, 0.020551759749650955, 0.023941926658153534, -0.00585765577852726, 0.010171255096793175, -0.01533206831663847, -0.007172571495175362, 0.01325221173465252, -0.017593292519450188, 0.04416979104280472, -0.025418780744075775, -0.0026189545169472694, -0.02718484401702881, 0.030561119318008423, -0.02452407218515873, 0.03298373892903328, -0.022487320005893707, 0.09806565940380096, -0.04984544217586517, -0.06220647320151329, 0.06061301380395889, 0.03592242673039436, -0.036921676248311996, 0.022128231823444366, -0.07262395322322845, -0.0501110814511776, -0.016582898795604706, 0.04281063750386238, 0.04749593138694763, 0.016069844365119934, 0.06397498399019241, -0.047364491969347, 0.017092615365982056, 0.07329308986663818, 0.013254079967737198, 0.021486179903149605, -0.0110517842695117, -0.026638083159923553, 0.027680013328790665, -0.039564188569784164, 0.014465578831732273, 0.05841398611664772, -0.014669287949800491, -0.014345455914735794, 0.031301409006118774, 0.0030654985457658768, -0.07634247094392776, 0.0012813967186957598, 0.02840854413807392, -0.04846857860684395, 0.060893092304468155, -0.0928541049361229, 0.06484125554561615, 0.009457999840378761, 0.00925632193684578, 0.03339020162820816, -0.029498225077986717, -0.07536450028419495, 0.07856345921754837, -0.025030385702848434, -0.0027768672443926334, -0.06436023116111755, -0.035055097192525864, 0.0407075360417366, 0.03940799832344055, 0.061722226440906525, 0.022645937278866768, 0.029038317501544952, 0.008905327878892422, -0.059062112122774124, -0.008032490499317646, 0.029402591288089752, -0.007117834873497486, -0.04480212181806564, 0.029293105006217957, 0.043633561581373215, -0.025769364088773727, -0.07219935208559036, -0.021091626957058907, -0.1010240837931633, -0.01871914230287075, -0.029015645384788513, -0.038269270211458206, 0.01087197009474039, 0.03481509909033775, 0.005784718785434961, 0.11590027809143066, -0.05587885156273842, 0.008522918447852135, -0.007887247949838638, -0.007014649920165539, 0.048696547746658325, 0.00473292451351881, 0.023233959451317787, 0.03307162597775459, -0.08449383080005646, -0.01530770119279623, -0.012665830552577972, 0.04452168196439743, 0.02431860938668251, -0.016585495322942734, -0.036412663757801056, 0.02220315672457218, 0.034864164888858795, -0.012085904367268085, -0.06028272956609726, 0.0501369908452034, -0.007772205863147974, -0.037867579609155655, 0.07913423329591751, -0.027901632711291313, -0.013747279532253742, 0.08693230897188187, -0.07374684512615204, -0.03874040022492409, -0.01189374178647995, -0.06821588426828384, -0.01295910868793726, 0.0013876777375116944, -0.0592401847243309, -0.003607482649385929, 0.08327265828847885, -0.015094122849404812, 0.012556875124573708, -0.016855141147971153, 0.002814969513565302, -0.032788779586553574, -0.005366713739931583, -0.008616995997726917, -0.06651122868061066, -0.03973127901554108, -0.022107958793640137, 0.03601353242993355, 0.0425519235432148, 0.01353537943214178, 0.01027053501456976, 0.00960585754364729, -0.024925753474235535, 0.004321714863181114, -0.028422722592949867, 0.02008933760225773, -0.006566641386598349, 0.04273446649312973, -0.0276945773512125, -0.04390161484479904, -0.03770850971341133, -0.04509992152452469, -0.016572624444961548, 0.023089615628123283, 0.02190740592777729, 0.018618324771523476, 0.011578169651329517, 0.023454170674085617, 0.01856674998998642, -0.004602515138685703, -0.006406952161341906, -0.012522254139184952, 0.0025926721282303333, -0.010926364921033382, -0.01749318651854992, 0.018758883699774742, 0.023160379379987717, -0.021968871355056763, 0.005213442724198103, 0.0027746662963181734, -0.03152477368712425, -0.028904767706990242, 0.004035606049001217, -0.049476347863674164, 0.007580868899822235, -0.038112983107566833, 0.019395438954234123, 0.020025014877319336, 0.06271273642778397, -0.10747947543859482, -0.030432365834712982, 0.02688591554760933, -0.02611090987920761, -0.0017591860378161073, -0.04114033654332161, 0.04171639680862427, -0.014586066827178001, -0.03674422577023506, 0.03039499744772911, 0.010119713842868805, 0.0009084130288101733, -0.002000178210437298, 0.04720577225089073, 0.024717453867197037, -0.03350111097097397, -0.012552635744214058, 0.0047515518963336945, 0.011670513078570366, 0.02116110362112522, 0.050953056663274765, 0.03832615166902542, 0.0165567547082901, 0.008791687898337841, -0.05675072222948074, -0.009503484703600407, 0.05039580538868904, 0.0311001967638731, 0.02982126548886299, -0.02385709062218666, -0.013603686355054379, 0.02906336821615696, 0.005926464218646288, 0.016582971438765526, -0.026246286928653717, -0.005355111323297024, 0.010554390028119087, -0.02216828241944313, -0.003747085575014353, 0.039234086871147156, -0.024133477360010147, -0.01188835222274065, 0.01241636648774147, 0.009521327912807465, 0.010371513664722443, 0.016112780198454857, -0.04045964032411575, -0.005922780837863684, 0.03192886710166931, -0.03746798634529114, -0.027580957859754562, -0.021293899044394493, -0.000713296583853662, 0.03929264098405838, 0.02312159352004528, 0.03623894974589348, 0.01829141564667225, 0.04293477162718773, 0.04490526765584946, -0.019705718383193016, -0.039471615105867386, 0.03238049894571304, 0.04840688779950142, -0.07378218322992325, -0.017335977405309677, 0.06349295377731323, 0.03130965307354927, 0.042848967015743256, -0.012334798462688923, 0.01726340875029564, 0.010796785354614258, 0.020160935819149017, 0.013172339648008347, 0.010302075184881687, -0.01636197604238987, 0.011924132704734802, -0.0392603762447834, -0.047568876296281815, 0.07602637261152267, 0.015330227091908455, -0.022278958931565285, 0.020754516124725342, -0.030794939026236534, 0.005683215335011482, -0.02472003735601902, -0.015221089124679565, 0.010374346747994423, -0.016286199912428856, -0.006037604063749313, -0.014123845845460892, -0.0026301448233425617, -0.003577808616682887, -0.01252685859799385, 0.01737383008003235, -0.028474660590291023, 0.0372287817299366, -0.009559319354593754, -0.02379596419632435, 0.038971807807683945, 0.012304289266467094, 0.04102272912859917, -0.04503212124109268, -0.0044089192524552345, -0.01414844486862421, -0.01682877354323864, 0.027454230934381485, -0.05826316401362419, -0.011839953251183033, 0.018318209797143936, 0.027911707758903503, -0.00573149835690856, 0.042079292237758636, -0.009220244362950325, -0.01883849874138832, 0.01864285208284855, 0.05171465128660202, -0.009339921176433563, -0.020611058920621872, -0.04777161777019501, -0.0028204829432070255, -0.046338535845279694, -0.019027521833777428, 0.0044641559943556786, 0.029388172551989555, 0.012854556553065777, -0.03973214700818062, 0.03670218214392662, 0.028287295252084732, -0.04192676395177841, -0.021024474874138832, -0.00037950603291392326, -0.005565576255321503, 0.009928891435265541, -0.007034007925540209, 0.01569512113928795, 0.047299593687057495, 0.018742479383945465, -0.016715334728360176, 0.0059383343905210495, -0.03898544982075691, -0.008393718861043453, 0.01801505871117115, 0.03489316999912262, -0.03289187327027321, 0.03989966958761215, 0.01540080551058054, -0.015616128221154213, 0.00013674890215042979, 0.02541120909154415, -0.03039138950407505, 0.059186749160289764, 0.005375613458454609, -0.03418703377246857, -0.03248972445726395, 0.013028910383582115, -0.00811777450144291, -0.037865571677684784, -0.0029756673611700535, 0.01696009747684002, 0.04323717951774597, 0.0007457227329723537, 0.0000948343295021914, 0.020880507305264473, 0.0404471717774868, -0.011887638829648495, -0.006877628620713949, -0.008931063115596771, -0.045088399201631546, 0.001581688760779798, 0.006997941993176937, 0.02708185650408268, -0.027447452768683434, -0.032875701785087585, -0.020038047805428505, 0.0015871612122282386, 0.029632868245244026, 0.027026327326893806, -0.010022459551692009, -0.026026755571365356, 0.01850603148341179, -0.035785283893346786, -0.018494922667741776, -0.006522390991449356, 0.015853136777877808, 0.02240564487874508, 0.032178301364183426, 0.05407523363828659, 0.04304848983883858, -0.01410821732133627, 0.03532779589295387, 0.00873972475528717, -0.03005959279835224, -0.009920630604028702, -0.06882838904857635, 0.00553129892796278, -0.010068599134683609, -0.02323790080845356, 0.031016657128930092, 0.012899516150355339, 0.008674662560224533, 0.03468451648950577, 0.03872692957520485, 0.026338079944252968, -0.03220177814364433, 0.02169770747423172, 0.002026584232226014, -0.020892756059765816, 0.0002146608312614262, -0.015501623041927814, -0.029580378904938698, 0.025223376229405403, -0.022866414859890938, -0.046846795827150345, -0.017771350219845772, -0.030268210917711258, -0.021894970908761024, -0.031452588737010956, 0.01185983419418335, -0.004460399970412254, 0.07768195122480392, 0.035212524235248566, 0.03759070858359337, -0.017448781058192253, 0.019389644265174866, 0.05714957043528557, -0.036496520042419434, -0.0023478574585169554, 0.016846492886543274, 0.03286994993686676, 0.02619183622300625, 0.034576065838336945, -0.009034662507474422, -0.0002846481220331043, -0.0004312623350415379, 0.011405742727220058, -0.028372742235660553, -0.011611474677920341, 0.04867929220199585, 0.027848776429891586, 0.007014715578407049, -0.009614618495106697, -0.026300765573978424, -0.00036506977630779147, 0.029947327449917793, -0.01702728122472763, 0.000141430355142802, 0.0778115913271904, -0.020154809579253197, -0.034706514328718185, 0.0031096721068024635, -0.044334422796964645, 0.0031625761184841394, -0.04487188532948494, 0.03708628937602043, -0.0015295820776373148, 0.007088825572282076, 0.06409129500389099, 0.00039263252983801067, -0.0015429259510710835, 0.006675961427390575, -0.010442426428198814, -0.019430741667747498, 0.03012171760201454, 0.026903899386525154, -0.053344015032052994, 0.04478207975625992, 0.03425854817032814, -0.01730348914861679, 0.0173598974943161, -0.012939565815031528, 0.039130955934524536, 0.01964014396071434, -0.03219934180378914, 0.0354795828461647, 0.01971263997256756, 0.0011412501335144043, -0.020123397931456566, 0.032703548669815063, -0.0158061683177948, 0.0526554211974144, 0.017903946340084076, 0.044324442744255066, 0.03333073481917381, -0.012951443903148174, 0.005516367964446545, 0.03723210468888283, 0.05195096880197525, 0.01856030710041523, -0.010893726721405983, -0.023510931059718132, -0.0043885898776352406, -0.007294833660125732, -0.04040056839585304, 0.009336908347904682, -0.04067481681704521, 0.055482957512140274, 0.04824492707848549, 0.019779270514845848, 0.03772340342402458, -0.03707658872008324, 0.04255988821387291, 0.02087225392460823, 0.027428889647126198, 0.0051627629436552525, -0.003358861431479454, 0.013472482562065125, 0.01392514817416668, 0.00309643242508173, 0.06519055366516113, 0.04669210687279701, 0.009745950810611248, 0.04683639109134674, 0.013456693850457668, 0.04172781854867935, 0.036136236041784286, 0.0025130421854555607, 0.025151582434773445, -0.04690070450305939, -0.004998384974896908, 0.01487773284316063, 0.02535100094974041, -0.042625851929187775, -0.008828237652778625, -0.023401347920298576, -0.038854241371154785, 0.011539961211383343, -0.017437664791941643, -0.0037298807874321938, 0.02052452228963375, -0.05370189994573593, 0.009189591743052006, 0.030558068305253983, 0.025566762313246727, -0.03673997521400452, 0.01252646092325449, 0.027788642793893814, -0.007321829907596111, -0.0013159816153347492, -0.029401445761322975, -0.038745567202568054, -0.011346184648573399, -0.020507723093032837, -0.005016258917748928, -0.000996147282421589, 0.018110858276486397, -0.03945370391011238, -0.010090257041156292, 0.01524665579199791, -0.047989822924137115, 0.035853106528520584, 0.029065091162919998, -0.003232369665056467, -0.021031152456998825, 0.018147969618439674, 0.005721333436667919, 0.024423761293292046, 0.03472088649868965, -0.0050629363395273685, -0.004755909088999033, -0.026106717064976692, 0.08048694580793381, 0.018121207132935524, 0.03627898544073105, -0.02861192636191845, -0.015591111034154892, -0.005578602198511362, -0.050169121474027634, 0.0013941969955340028, 0.022341370582580566, 0.00859459862112999, -0.0037032924592494965, 0.011767925694584846, -0.0649060308933258, -0.015495920553803444, -0.030279232189059258, 0.000273992249276489, 0.03175521269440651, -0.013053689152002335, -0.025092201307415962, -0.009608153253793716, 0.02492407336831093, -0.02269016206264496, 0.04931668937206268, 0.05039805546402931, 0.041167862713336945, 0.0021138230804353952, 0.03453092277050018, 0.01502646692097187, -0.049334295094013214, 0.027695346623659134, -0.000003485415618342813, -0.03252415359020233, -0.003453262383118272, -0.026656515896320343, -0.0404902845621109, 0.0027149508241564035, -0.007085658609867096, 0.02879570983350277, -0.00408785417675972, -0.020588019862771034, 0.01613706722855568, -0.006698519457131624, 0.025284133851528168, -0.017269317060709, 0.0359860323369503, 0.035917576402425766, 0.0194865632802248, -0.02654896304011345, 0.010318487882614136, 0.03082064911723137, 0.023085307329893112, 0.009322614409029484, 0.02370535023510456, -0.04247357323765755, 0.01869848184287548, -0.05505937710404396, -0.03419122099876404, 0.02049216441810131, 0.0299052931368351, -0.03989823907613754, -0.020458431914448738, 0.02577499859035015, 0.03679444640874863, -0.02533443085849285, -0.013473792932927608, 0.0025956607423722744, 0.023725079372525215, 0.0072330934926867485, 0.012869473546743393, -0.050133202224969864, -0.010074394755065441, 0.023616688326001167, 0.013670225627720356, 0.023828858509659767, 0.02496718056499958, -0.006887804716825485, 0.030244527384638786, 0.003934959881007671, 0.018796293064951897, 0.056343358010053635, 0.03472578525543213, -0.0655185654759407, -0.0003449300129432231, 0.0055427574552595615, -0.03272455185651779, -0.018510732799768448, 0.008768483996391296, 0.0385625883936882, -0.04090357944369316, 0.019411686807870865, 0.02567371539771557, 0.037372786551713943, -0.031713828444480896, 0.014679123647511005, -0.012035040184855461, 0.04464118927717209, -0.011886194348335266, 0.01923956908285618, 0.0026500204112380743, 0.03121408447623253 ]
How to generate text: using different decoding methods for language generation with Transformers
patrickvonplaten
March, 2020
how-to-generate
guide, nlp
https://huggingface.co/blog/how-to-generate
# How to generate text: using different decoding methods for language generation with Transformers Note: Edited on July 2023 with up-to-date references and examples.
[ 0.05630471929907799, 0.006690107751637697, 0.07678764313459396, -0.04130718857049942, 0.0923580527305603, 0.03351301699876785, 0.036202747374773026, 0.07313425093889236, -0.023860525339841843, -0.03473580256104469, -0.06619352847337723, 0.035219207406044006, -0.021915603429079056, 0.055087123066186905, -0.017340630292892456, 0.018333805724978447, 0.012228434905409813, 0.02632560394704342, 0.003982457332313061, 0.004325035028159618, -0.03093389980494976, -0.025360990315675735, 0.049417342990636826, -0.005232317838817835, 0.07898405939340591, -0.025782370939850807, 0.03393325209617615, -0.02162114530801773, -0.06315147876739502, 0.03878834843635559, -0.08774857223033905, -0.005477590952068567, 0.019234061241149902, -0.0009267808636650443, -0.08453889191150665, 0.014812445268034935, -0.10941516607999802, -0.003717758459970355, 0.0062407925724983215, -0.024805476889014244, -0.024937724694609642, -0.017879143357276917, 0.03768908604979515, 0.007797264494001865, -0.02514965645968914, 0.013984295539557934, -0.2685895562171936, 0.08251608163118362, -0.07897946238517761, -0.008927002549171448, -0.046536725014448166, 0.05886431038379669, -0.01907414197921753, -0.018331225961446762, -0.011686180718243122, 0.026445286348462105, -0.012285678647458553, -0.1220417320728302, 0.027799390256404877, -0.00018835953960660845, 0.05543716996908188, -0.007076834794133902, -0.010087182745337486, 0.03591104969382286, 0.04353427514433861, -0.0224748607724905, -0.03033258020877838, 0.03449242562055588, -0.058085937052965164, -0.004149570595473051, -0.03366810455918312, -0.03167266771197319, -0.05191430449485779, -0.046014994382858276, 0.020446160808205605, -0.016320519149303436, -0.01307276077568531, 0.07435029745101929, 0.02918928675353527, 0.08400258421897888, 0.013019015081226826, -0.019963689148426056, 0.08841172605752945, 0.02251412719488144, 0.04327346384525299, -0.014305689372122288, 0.071026511490345, -0.014154499396681786, -0.03918895125389099, 0.03057195246219635, -0.016750242561101913, -0.17301319539546967, -0.04655102640390396, 0.020134933292865753, 0.03944826498627663, -0.015671657398343086, 0.02744271792471409, 0.07558415085077286, -0.02989671565592289, 0.001302220392972231, -0.016194352880120277, 0.02203972637653351, 0.0583859421312809, -0.03941480442881584, -0.03879925608634949, -0.041741155087947845, -0.016227291896939278, -0.06866070628166199, -0.0076454090885818005, 0.022260012105107307, 0.007400177419185638, -0.0027070820797234774, 0.097128726541996, 0.030063144862651825, -0.045567587018013, 0.05125323683023453, 0.04336608946323395, -0.0038465361576527357, -0.07474233955144882, 0.022407041862607002, -0.0005029352614656091, 0.03641493245959282, 0.03932727873325348, 0.03130386769771576, -0.0003959817113354802, 0.03355113044381142, 0.02928493358194828, 0.0205022431910038, -0.03954361379146576, -0.022037336602807045, 0.05820925906300545, -0.020002448931336403, 0.0794447511434555, -0.009049700573086739, 0.022457778453826904, -0.04189814627170563, -0.00437899399548769, -0.020023277029395103, -0.015750057995319366, -0.009257650934159756, 0.001918207504786551, 0.04304554685950279, -0.004374191630631685, 0.07036033272743225, -0.0012578613823279738, -0.036715880036354065, -0.09577716141939163, 0.04408535733819008, -0.0007289726054295897, 0.022191565483808517, 0.018989533185958862, 0.03258661553263664, -0.029703926295042038, -0.06207894906401634, 0.030183220282197, 0.05716291442513466, -0.006227473728358746, 0.022953903302550316, -0.108405701816082, -0.04682975262403488, -0.012219767086207867, 0.034507159143686295, 0.027066510170698166, 0.02068902924656868, 0.018788853660225868, -0.08378209173679352, -0.015538730658590794, 0.06846387684345245, 0.02722637541592121, -0.03432488068938255, -0.02605823427438736, -0.026863107457756996, 0.08251184970140457, -0.040545325726270676, -0.03762471303343773, 0.027316484600305557, 0.02806462161242962, 0.05534667521715164, 0.03053446114063263, -0.041850171983242035, -0.06730567663908005, -0.0017954984214156866, 0.005930023267865181, 0.027791861444711685, 0.02575007639825344, -0.03872169554233551, 0.021682938560843468, -0.04233936965465546, 0.003390153404325247, 0.05435938015580177, -0.07271169126033783, -0.06355448067188263, 0.08721136301755905, 0.013746398501098156, -0.0029618386179208755, -0.06026396155357361, -0.030810272321105003, 0.11892694979906082, 0.04052111506462097, 0.11183246970176697, 0.05612906441092491, 0.0013639876851812005, 0.05640112981200218, -0.00434204051271081, -0.01959896832704544, 0.026944776996970177, 0.06244484707713127, 0.02592957206070423, 0.019839750602841377, -0.017713211476802826, 0.023423783481121063, -0.08161941915750504, 0.02929229475557804, -0.09882279485464096, 0.0036133478861302137, -0.04441889375448227, -0.010694948956370354, 0.0198570154607296, 0.007435152307152748, -0.024325720965862274, 0.12063563615083694, -0.011625719256699085, -0.044818442314863205, 0.018640413880348206, -0.01428578607738018, 0.10208853334188461, 0.04677955061197281, 0.026361770927906036, 0.04342593625187874, -0.08894166350364685, 0.0002523827424738556, -0.014905674383044243, 0.0154031440615654, 0.015679746866226196, -0.022686773911118507, -0.01699235290288925, -0.011527330614626408, 0.024587448686361313, 0.028152406215667725, -0.029248397797346115, 0.013096608221530914, -0.003833720926195383, -0.011529495939612389, 0.0321025587618351, -0.03938756138086319, 0.022220376878976822, 0.07232917100191116, 0.00303462240844965, -0.012666101567447186, -0.004735940136015415, -0.06988687813282013, 0.08442728966474533, 0.006058338563889265, -0.05631106719374657, 0.050918787717819214, 0.008025671355426311, 0.013110535219311714, -0.023414837196469307, 0.00011806097609223798, 0.01227293349802494, -0.028968455269932747, -0.05642925575375557, 0.015625163912773132, -0.06392981112003326, -0.011791129596531391, -0.025902530178427696, 0.03650177642703056, 0.01727760024368763, -0.011064467020332813, 0.02059806138277054, -0.002322897082194686, -0.01775854267179966, 0.018467724323272705, -0.017535800114274025, 0.01240658201277256, 0.013281211256980896, 0.03338087350130081, -0.016569938510656357, -0.02321455255150795, -0.0007398803136311471, -0.040989119559526443, -0.0162311140447855, 0.0332840196788311, 0.01316013466566801, 0.0014853611355647445, -0.007680205162614584, 0.006839327048510313, -0.01952420361340046, -0.0039701866917312145, 0.006112589500844479, -0.006873815320432186, 0.03753555566072464, -0.02436850406229496, -0.014227090403437614, 0.03701303154230118, -0.0013358586002141237, 0.01023514848202467, 0.005512499716132879, -0.029570428654551506, 0.025704998522996902, 0.018492041155695915, 0.0007111465092748404, -0.028763072565197945, -0.001637207460589707, -0.06495766341686249, 0.024887194857001305, 0.00982283428311348, 0.021109087392687798, -0.13271008431911469, -0.06454754620790482, 0.016331056132912636, 0.002129623666405678, -0.004254738334566355, -0.004528956487774849, 0.04040692001581192, -0.027979528531432152, -0.017094701528549194, -0.001320169074460864, 0.010342518799006939, -0.0035353137645870447, 0.010380716994404793, 0.015691664069890976, -0.023299038410186768, -0.04056260734796524, -0.0502130389213562, 0.006736258044838905, -0.01011180691421032, 0.009113644249737263, 0.014005675911903381, 0.036660511046648026, 0.009397456422448158, -0.0010316591942682862, -0.01843504048883915, 0.03286611661314964, 0.030849209055304527, 0.016925889998674393, 0.015543476678431034, -0.014905668795108795, 0.010221119038760662, 0.03560618311166763, 0.011156023479998112, 0.01661957986652851, -0.035250239074230194, 0.0062508308328688145, 0.00930385384708643, -0.016363389790058136, 0.014345998875796795, 0.03507227450609207, 0.01629924215376377, -0.02097836323082447, -0.004027435090392828, 0.002415441209450364, -0.04784848913550377, -0.016671380028128624, -0.02008524164557457, 0.0035338641609996557, 0.019711529836058617, -0.03062368370592594, -0.04574890807271004, -0.014185527339577675, -0.002008505631238222, 0.0219707190990448, 0.006616982631385326, 0.006556738168001175, -0.0022280768025666475, 0.027567008510231972, 0.053897567093372345, -0.02283686399459839, -0.027529247105121613, 0.018256481736898422, 0.004351998213678598, -0.022520171478390694, -0.06704708188772202, 0.09222280234098434, -0.023809656500816345, 0.051981180906295776, 0.017069635912775993, 0.06155119836330414, -0.01648288406431675, 0.011812953278422356, 0.008319317363202572, 0.019729116931557655, -0.034180689603090286, 0.030109276995062828, -0.059796351939439774, -0.024567432701587677, 0.11698310822248459, -0.00044109069858677685, -0.02040187455713749, -0.04883791133761406, -0.03636215627193451, -0.003014604328200221, -0.005318950396031141, 0.0248260498046875, 0.02510414645075798, 0.010749971494078636, -0.00002390599183854647, 0.006836871616542339, 0.03538741171360016, -0.021847307682037354, -0.003976154141128063, 0.0009948849910870194, -0.0027720320504158735, 0.019080502912402153, 0.025505192577838898, -0.037825826555490494, 0.025014089420437813, -0.010278765112161636, 0.011372363194823265, -0.07125627249479294, -0.005698861554265022, 0.028851579874753952, 0.005536843556910753, 0.036422744393348694, -0.03821638599038124, -0.023493599146604538, -0.022118667140603065, 0.028019282966852188, 0.01965722255408764, -0.012998932041227818, -0.02423323132097721, -0.02599678933620453, -0.005843753926455975, -0.005931077990680933, -0.0007556173368357122, -0.0609535314142704, -0.0449918694794178, -0.011137498542666435, -0.04204227030277252, 0.006236101035028696, 0.029064351692795753, -0.009781456552445889, 0.001932433107867837, -0.016521696001291275, 0.01780823804438114, 0.026771271601319313, -0.005489936098456383, 0.009982412680983543, -0.0031123487278819084, -0.01329937856644392, 0.0412321537733078, 0.01870322786271572, 0.018934216350317, 0.03885766491293907, -0.016926253214478493, 0.00881313905119896, -0.026943344622850418, -0.06430655717849731, -0.03352344036102295, -0.015605778433382511, 0.019518891349434853, -0.01479499600827694, 0.032556552439928055, -0.005680596921592951, -0.00018705356342252344, -0.022159049287438393, 0.012398959137499332, -0.006810902152210474, 0.05860560014843941, -0.014248267747461796, -0.047245945781469345, -0.01760595664381981, 0.0001435827580280602, -0.003909154795110226, -0.005124113522469997, 0.02802160568535328, -0.026885202154517174, 0.06434869021177292, 0.007480280939489603, 0.0050943754613399506, -0.03529074788093567, 0.021687693893909454, -0.002314257901161909, 0.013488550670444965, -0.005155614111572504, -0.04671967774629593, 0.02369028329849243, 0.01067513320595026, -0.0021672500297427177, -0.012032746337354183, 0.021093107759952545, -0.0010729717323556542, -0.01029305811971426, 0.020892011001706123, 0.015488235279917717, 0.03477076068520546, 0.01457311399281025, -0.003287975676357746, 0.005543888080865145, -0.008450612425804138, 0.017184337601065636, 0.01773250289261341, -0.007631351239979267, 0.014206001535058022, 0.0771297961473465, 0.026212867349386215, 0.015298466198146343, -0.006111240014433861, -0.01171277929097414, -0.023719200864434242, 0.008955137804150581, -0.024465318769216537, -0.01143376063555479, -0.017292022705078125, 0.013174569234251976, -0.015135168097913265, -0.0008511363994330168, 0.051220521330833435, 0.059930287301540375, 0.03135421872138977, 0.0026112052146345377, -0.007928391918540001, 0.01512989029288292, -0.007568873465061188, -0.005460675340145826, -0.017426226288080215, 0.0007098939386196434, -0.04251982271671295, 0.0027641155757009983, 0.02663988247513771, -0.04051341488957405, -0.00950394943356514, -0.02065766230225563, -0.03813551366329193, -0.01049241703003645, -0.014184189960360527, -0.015396316535770893, 0.059510815888643265, 0.005758415441960096, -0.007626657374203205, 0.002414207672700286, 0.06103852763772011, 0.04493420571088791, 0.010472488589584827, 0.024741699919104576, 0.01511982548981905, 0.018148524686694145, 0.017952626571059227, 0.0606018528342247, 0.0019861161708831787, -0.006832785438746214, 0.04821665212512016, -0.0036848101299256086, 0.002577151171863079, -0.05503726005554199, 0.0317288301885128, 0.0040701949037611485, 0.015851622447371483, 0.013389374129474163, -0.035680338740348816, -0.010738839395344257, -0.0012901898007839918, -0.054614998400211334, 0.024542132392525673, 0.04262242466211319, -0.008486653678119183, -0.01914917677640915, 0.027148324996232986, 0.01769796945154667, -0.02606860175728798, -0.018112991005182266, 0.007537281606346369, -0.007198622450232506, 0.032384492456912994, 0.025632500648498535, -0.017559969797730446, -0.005627409089356661, -0.000449902203399688, 0.029924973845481873, -0.023022634908556938, 0.003780862782150507, 0.024843890219926834, -0.02304585464298725, 0.027826951816678047, -0.0027028864715248346, -0.004980047699064016, 0.01350362878292799, 0.021361706778407097, 0.01495242677628994, 0.02357950620353222, 0.029083268716931343, -0.0037445458583533764, 0.01986023411154747, -0.04202953726053238, 0.0016701258718967438, 0.05881188064813614, 0.006167471408843994, 0.05872420221567154, 0.030137035995721817, 0.03347497805953026, 0.014385576359927654, -0.00963518861681223, -0.024638354778289795, 0.024757085368037224, 0.021591883152723312, 0.010265757329761982, 0.012958318926393986, 0.006922922562807798, -0.009733512997627258, -0.035534292459487915, -0.04389910399913788, -0.016734205186367035, -0.05308492109179497, 0.0427825003862381, 0.02269625850021839, -0.009262708947062492, 0.026146698743104935, -0.03614933043718338, 0.06483215093612671, 0.015785494819283485, 0.007707074284553528, -0.0276386309415102, 0.02220887318253517, 0.04586634039878845, -0.005335912574082613, 0.026082459837198257, 0.018330633640289307, 0.010572396218776703, 0.026394540444016457, 0.06928947567939758, -0.006688814144581556, 0.0057417964562773705, 0.019437527284026146, -0.019218457862734795, 0.03545422852039337, -0.002362815197557211, -0.014639080502092838, -0.024220235645771027, 0.04678163677453995, -0.015287644229829311, -0.011463308706879616, -0.01116281095892191, -0.030530447140336037, -0.011708620004355907, 0.021049033850431442, -0.009521178901195526, -0.028167327865958214, -0.038927577435970306, -0.02053440734744072, 0.04366641491651535, -0.003914866596460342, -0.0182599276304245, 0.0002315987803740427, 0.014571440406143665, 0.022197484970092773, 0.046729229390621185, -0.00972718745470047, -0.02117132395505905, -0.04081443324685097, -0.02147904969751835, -0.02821122109889984, -0.017210986465215683, 0.009649715386331081, -0.02381546050310135, -0.00007245341839734465, 0.001141185057349503, -0.03092365339398384, 0.035566966980695724, 0.007588464301079512, 0.024289922788739204, -0.030404139310121536, 0.032296132296323776, -0.0333220511674881, -0.0026007206179201603, -0.021377593278884888, -0.031207870692014694, 0.004981048870831728, -0.028389453887939453, 0.00856493879109621, 0.025227602571249008, 0.04857279732823372, -0.03519594669342041, -0.02782745100557804, -0.004695425741374493, -0.033291108906269073, -0.00969264842569828, 0.0192059725522995, 0.01716461032629013, -0.008069789037108421, 0.008234236389398575, -0.016818217933177948, 0.021417060866951942, -0.013786343857645988, 0.02559506706893444, 0.023616624996066093, -0.016760796308517456, -0.04531952738761902, -0.04761167988181114, 0.06753817200660706, -0.014122181572020054, 0.00833291094750166, 0.027074700221419334, 0.03227108716964722, -0.019712939858436584, -0.03567007929086685, 0.016045667231082916, -0.03147653490304947, 0.011918473057448864, -0.029356209561228752, -0.0664626806974411, -0.016200309619307518, -0.011952496133744717, -0.017785245552659035, 0.018526969477534294, -0.04247385263442993, -0.004065460991114378, -0.02465592510998249, -0.01812840811908245, -0.011715949513018131, 0.00921944435685873, 0.07095061987638474, -0.002202935516834259, 0.06922460347414017, -0.01515178382396698, 0.004611501470208168, -0.022178728133440018, 0.00342715997248888, 0.029020186513662338, 0.021227670833468437, 0.034042395651340485, -0.004177138675004244, -0.00021189279505051672, 0.003665502183139324, -0.0592229962348938, -0.03906696289777756, 0.018111683428287506, 0.007260605692863464, -0.020935682579874992, -0.027520813047885895, -0.0009429678320884705, 0.013787743635475636, 0.006748219486325979, 0.014509599655866623, 0.019047552719712257, 0.00016805878840386868, 0.017107678577303886, 0.002099391771480441, -0.06474731862545013, 0.007336672395467758, -0.01040006335824728, 0.049252867698669434, 0.031609851866960526, 0.03846895322203636, 0.021827416494488716, 0.0014063830021768808, -0.03770206496119499, 0.023707590997219086, 0.0313938669860363, -0.017836887389421463, -0.015927106142044067, 0.029552621766924858, -0.006831020582467318, -0.021414387971162796, -0.032722149044275284, 0.06336965411901474, 0.023187706246972084, 0.010269763879477978, -0.025941956788301468, 0.0014121560379862785, -0.03596235439181328, -0.02642683871090412, 0.03970126435160637, 0.008037381805479527, 0.047232046723365784, 0.014789029024541378, 0.001597932423464954, 0.0044758617877960205, -0.0023654825054109097 ]
How to generate text: using different decoding methods for language generation with Transformers
patrickvonplaten
March, 2020
how-to-generate
guide, nlp
https://huggingface.co/blog/how-to-generate
Top-p (nucleus) sampling Instead of sampling only from the most likely K words, in Top-p sampling chooses from the smallest possible set of words whose cumulative probability exceeds the probability p. The probability mass is then redistributed among this set of words. This way, the size of the set of words (a.k.a the number of words in the set) can dynamically increase and decrease according to the next word's probability distribution. Ok, that was very wordy, let's visualize. Having set \(p=0.92\), Top-p sampling picks the minimum number of words to exceed together \(p=92\%\) of the probability mass, defined as \(V_{\text{top-p}}\). In the first example, this included the 9 most likely words, whereas it only has to pick the top 3 words in the second example to exceed 92%. Quite simple actually! It can be seen that it keeps a wide range of words where the next word is arguably less predictable, e.g. \(P(w | \text{"The''})\), and only a few words when the next word seems more predictable, e.g. \(P(w | \text{"The"}, \text{"car"})\). Alright, time to check it out in transformers! We activate Top-p sampling by setting 0 < top_p < 1: python # set seed to reproduce results. Feel free to change the seed though to get different results set_seed(42) # set top_k to 50 sample_output = model.generate( **model_inputs, max_new_tokens=40, do_sample=True, top_p=0.92, top_k=0 ) print("Output:\n" + 100 * '-') print(tokenizer.decode(sample_output[0], skip_special_tokens=True)) Output: ---------------------------------------------------------------------------------------------------- I enjoy walking with my cute dog for the rest of the day, but this had me staying in an unusual room and not going on nights out with friends (which will always be my yearning for such a spacious screen on my desk Great, that sounds like it could have been written by a human. Well, maybe not quite yet. While in theory, Top-p seems more elegant than Top-K, both methods work well in practice. Top-p can also be used in combination with Top-K, which can avoid very low ranked words while allowing for some dynamic selection. Finally, to get multiple independently sampled outputs, we can again set the parameter num_return_sequences > 1: python # set seed to reproduce results. Feel free to change the seed though to get different results set_seed(42) # set top_k = 50 and set top_p = 0.95 and num_return_sequences = 3 sample_outputs = model.generate( **model_inputs, max_new_tokens=40, do_sample=True, top_k=50, top_p=0.95, num_return_sequences=3, ) print("Output:\n" + 100 * '-') for i, sample_output in enumerate(sample_outputs): print("{}: {}".format(i, tokenizer.decode(sample_output, skip_special_tokens=True))) Output: ---------------------------------------------------------------------------------------------------- 0: I enjoy walking with my cute dog for the rest of the day, but this time it was hard for me to figure out what to do with it. When I finally looked at this for a few moments, I immediately thought, " 1: I enjoy walking with my cute dog. The only time I felt like walking was when I was working, so it was awesome for me. I didn't want to walk for days. I am really curious how she can walk with me 2: I enjoy walking with my cute dog (Chama-I-I-I-I-I), and I really enjoy running. I play in a little game I play with my brother in which I take pictures of our houses. Cool, now you should have all the tools to let your model write your stories with transformers!
[ 0.04196736961603165, -0.003814463969320059, -0.028402946889400482, -0.014757812023162842, 0.07495160400867462, 0.00947350449860096, 0.01858614943921566, 0.04953596368432045, -0.06694609671831131, 0.0058721983805298805, -0.1353730410337448, -0.043741174042224884, 0.013551619835197926, 0.03852645307779312, 0.03955131024122238, 0.019372977316379547, 0.05547033250331879, 0.01323777437210083, 0.07445633411407471, -0.08017171174287796, 0.027652200311422348, -0.019435282796621323, 0.074733667075634, -0.062197402119636536, 0.07273409515619278, -0.008055664598941803, -0.020888552069664, -0.017983991652727127, -0.051476068794727325, -0.0022191759198904037, -0.1875266432762146, -0.017346540465950966, 0.034484729170799255, -0.01151925977319479, 0.0382731631398201, -0.020358672365546227, -0.09759290516376495, 0.07715792953968048, 0.06824924051761627, -0.04863004758954048, -0.04114088416099548, -0.0029431439470499754, -0.07071008533239365, 0.012708261609077454, -0.04603240266442299, -0.0726347342133522, -0.05958988144993782, 0.10390231013298035, -0.10264471918344498, -0.067760169506073, -0.058277640491724014, 0.0026121214032173157, -0.0811934843659401, 0.04231179878115654, -0.015634484589099884, -0.0529930554330349, -0.004653812386095524, -0.0762459859251976, 0.03830351680517197, -0.016222964972257614, 0.04227308928966522, -0.022966166958212852, 0.05365907400846481, 0.08297502994537354, -0.04049554839730263, -0.015043067745864391, -0.009518090635538101, 0.06926866620779037, -0.05424918979406357, -0.07104717195034027, -0.015677370131015778, -0.02987147867679596, -0.05729997158050537, -0.0070454394444823265, -0.015794778242707253, -0.01089502964168787, 0.006486954633146524, 0.0471087321639061, -0.015935802832245827, 0.033685121685266495, -0.021839717403054237, 0.0036301210056990385, 0.03009290248155594, 0.047121189534664154, 0.04044875502586365, 0.007307503372430801, 0.019931552931666374, -0.0683487132191658, -0.06115485355257988, 0.035827383399009705, 0.023230616003274918, -0.09300857037305832, 0.035444144159555435, 0.006260256748646498, 0.012594422325491905, -0.02993432804942131, -0.035456616431474686, 0.11180873215198517, 0.0002276580926263705, -0.005825061351060867, 0.021136537194252014, -0.06322628259658813, 0.013701379299163818, -0.050653617829084396, -0.07678473740816116, 0.043886687606573105, -0.026786113157868385, -0.035841576755046844, -0.0243015605956316, 0.041235119104385376, -0.015839358791708946, -0.058598898351192474, 0.00565677834674716, 0.019736170768737793, -0.022732850164175034, -0.011822381056845188, -0.00469695869833231, 0.030858146026730537, -0.018632570281624794, -0.03748832643032074, -0.021748043596744537, 0.045766688883304596, 0.09546469151973724, -0.0257559884339571, -0.052349530160427094, 0.0026789912953972816, 0.005656567867845297, 0.02530387043952942, 0.025097636505961418, -0.02501184307038784, 0.04305123910307884, 0.007777901366353035, -0.007524511776864529, -0.008924726396799088, 0.034874577075242996, 0.0003370986378286034, 0.04319366067647934, -0.030020637437701225, -0.02455483190715313, 0.03135943412780762, -0.003951497375965118, 0.011237475089728832, -0.012064855545759201, 0.008106277324259281, -0.03800863027572632, 0.008274907246232033, -0.0818151906132698, 0.05495471879839897, 0.00008147928747348487, 0.034229911863803864, -0.010613998398184776, 0.09807180613279343, 0.00861671194434166, -0.03670412674546242, 0.05600683018565178, 0.025039449334144592, -0.012056490406394005, -0.024926496669650078, -0.10272578150033951, -0.04391905292868614, -0.01631092093884945, 0.017160605639219284, 0.010916470550000668, 0.012768669053912163, 0.0510319247841835, -0.021750178188085556, 0.044444747269153595, 0.045640405267477036, -0.02869301475584507, 0.033985596150159836, -0.017274722456932068, -0.032111458480358124, 0.04206596314907074, -0.056808218359947205, -0.012807782739400864, 0.04462835565209389, 0.006877976469695568, 0.025685980916023254, -0.020803527906537056, 0.012491485103964806, -0.04073459282517433, 0.029856303706765175, 0.0330304279923439, 0.006266938988119364, 0.038176603615283966, -0.11904209852218628, 0.054152246564626694, 0.03472774848341942, 0.010133649222552776, 0.017595132812857628, -0.031959351152181625, -0.07624605298042297, 0.10938157141208649, 0.01489411760121584, 0.019771860912442207, -0.07069356739521027, -0.00639172550290823, 0.023496752604842186, 0.08211108297109604, 0.0327470526099205, 0.0423644557595253, 0.05078767240047455, 0.03271948918700218, -0.051359765231609344, -0.02692149393260479, -0.05940208211541176, -0.05874557048082352, -0.03778944909572601, 0.05881904065608978, 0.04262764751911163, -0.06966297328472137, -0.03122946247458458, -0.04640376195311546, -0.1507992446422577, -0.035265251994132996, 0.0085404422134161, -0.05033446475863457, -0.001935379346832633, -0.007757204584777355, 0.038279272615909576, 0.0725351870059967, -0.04915700480341911, 0.03485135734081268, -0.001525349565781653, -0.021465551108121872, 0.04838162660598755, -0.004075102973729372, -0.014385784044861794, 0.02882109023630619, -0.03272810950875282, -0.036996904760599136, -0.015664799138903618, 0.01830229163169861, 0.04006200283765793, 0.02395407110452652, -0.043852850794792175, -0.011884707026183605, 0.021755017340183258, -0.007687245029956102, -0.05147983878850937, 0.021412530913949013, 0.016064707189798355, -0.0954391211271286, 0.06912596523761749, 0.01666843891143799, 0.029278535395860672, 0.1302805244922638, -0.08787109702825546, -0.00820931326597929, -0.02502366714179516, -0.07289063185453415, 0.023274986073374748, 0.0002725004160311073, -0.04437260702252388, 0.014673229306936264, 0.08391626179218292, 0.009412652812898159, -0.023018108680844307, -0.023866666480898857, -0.05397823452949524, -0.022446388378739357, -0.008590822108089924, -0.009463117457926273, -0.022966977208852768, -0.026842692866921425, -0.009844208136200905, 0.028910133987665176, 0.019815661013126373, 0.013145951554179192, 0.0022733143996447325, -0.010652650147676468, -0.012044633738696575, 0.013869844377040863, -0.01982520893216133, 0.004763355478644371, -0.026998737826943398, 0.023782499134540558, -0.03867482393980026, -0.043572310358285904, -0.03061738982796669, -0.018262190744280815, 0.017179682850837708, 0.04218146577477455, 0.03174686059355736, 0.03915286809206009, 0.002492188476026058, 0.0565636120736599, 0.006247269455343485, -0.055202409625053406, 0.006926571484655142, -0.04063721373677254, -0.014017267152667046, -0.018450306728482246, 0.002759585389867425, 0.007015029899775982, -0.0034033560659736395, -0.009046852588653564, 0.01391552947461605, -0.009687592275440693, -0.008962276391685009, -0.04125016927719116, 0.023828892037272453, -0.03835410997271538, 0.0014880065573379397, -0.03536573052406311, -0.010538130067288876, -0.0003696397179737687, 0.03970782831311226, -0.08864972740411758, -0.0037292102351784706, 0.031290583312511444, -0.01396919321268797, 0.014373674988746643, -0.0351545512676239, 0.021935710683465004, -0.0046426085755229, -0.033361006528139114, 0.012966352514922619, 0.04567788541316986, 0.006401851773262024, 0.0016788621433079243, 0.0439520999789238, 0.012121659703552723, -0.019828811287879944, 0.017133528366684914, 0.005452210083603859, 0.031092984601855278, 0.012452667579054832, 0.04361715912818909, 0.020434604957699776, -0.004476931877434254, 0.012476769275963306, -0.05249179154634476, 0.022595426067709923, 0.04675808921456337, 0.034796781837940216, 0.027368847280740738, -0.017180604860186577, -0.02972768060863018, -0.002032047836109996, 0.010729314759373665, 0.015934821218252182, -0.0353936068713665, -0.015118042007088661, 0.03191850334405899, 0.01562824845314026, -0.020123915746808052, 0.03245212137699127, -0.033034246414899826, -0.011697129346430302, 0.017660537734627724, -0.024413932114839554, 0.026467865332961082, 0.015727879479527473, -0.03387131914496422, -0.004147651139646769, -0.01705615036189556, -0.038427773863077164, 0.00278534390963614, -0.04404653608798981, 0.01365143433213234, 0.009711792692542076, 0.019910132512450218, 0.0121074877679348, 0.0036493942607194185, 0.0403067022562027, 0.02703278511762619, -0.019450435414910316, -0.010041693225502968, 0.015891432762145996, 0.014223551377654076, -0.028336582705378532, 0.01172377448529005, 0.06020067259669304, 0.029267657548189163, 0.06179621443152428, 0.0011614570394158363, 0.03769709914922714, 0.011343041434884071, 0.010286311618983746, 0.01520287524908781, 0.0033462722785770893, -0.046591345220804214, 0.04386615380644798, -0.04078494384884834, -0.03485610708594322, 0.028548328205943108, 0.03291958197951317, -0.02869492955505848, 0.021470915526151657, -0.040232498198747635, 0.007472125813364983, -0.03489680960774422, -0.02073127217590809, -0.013338862918317318, -0.035242632031440735, -0.001294866087846458, -0.018092038109898567, -0.04227537289261818, -0.003774588694795966, -0.040877390652894974, 0.021413985639810562, -0.05780111625790596, 0.033374808728694916, -0.02811749279499054, -0.016379699110984802, -0.012464623898267746, 0.0015094145201146603, 0.021379485726356506, -0.05317068099975586, 0.0044178469106554985, -0.033703990280628204, -0.04733409732580185, 0.01619342900812626, -0.06979473680257797, 0.02740045264363289, 0.032178543508052826, 0.02172856405377388, -0.005426220595836639, 0.019290121272206306, -0.00506694708019495, 0.007209588773548603, 0.03172065317630768, 0.045580651611089706, 0.0076382700353860855, -0.011034402996301651, -0.029721461236476898, -0.008696619421243668, -0.021038563922047615, 0.021530330181121826, 0.004916734993457794, 0.00924351904541254, 0.016276204958558083, -0.026232078671455383, 0.03459066525101662, 0.018414953723549843, -0.008521602489054203, -0.034816619008779526, -0.011205672286450863, -0.005507387686520815, 0.009335382841527462, 0.01928562857210636, 0.025068743154406548, 0.018564373254776, 0.006564108654856682, -0.016854997724294662, 0.02605186030268669, -0.052553363144397736, 0.014496679417788982, 0.03861541673541069, 0.062102481722831726, -0.0008634441182948649, 0.030345087870955467, 0.013491541147232056, -0.00783436931669712, 0.011948120780289173, 0.00782011728733778, -0.013741256669163704, 0.050948817282915115, -0.0004644075524993241, -0.010984379798173904, -0.03591807186603546, 0.03584153950214386, -0.008393016643822193, -0.05464527755975723, -0.00043801276478916407, 0.028935400769114494, 0.05382026731967926, 0.017931634560227394, -0.0406721867620945, 0.012102884240448475, 0.001592426560819149, 0.005266587715595961, -0.0002948941837530583, 0.001716196653433144, -0.029955124482512474, -0.004925619810819626, 0.0038551785983145237, 0.0353793166577816, 0.017795303836464882, -0.03937140852212906, -0.003671759506687522, -0.008739134296774864, 0.032231081277132034, 0.0006127230590209365, 0.006427303422242403, -0.03969886526465416, 0.024721575900912285, -0.05420887470245361, -0.02641831710934639, 0.011174858547747135, 0.03154992684721947, 0.011194213293492794, 0.05488211289048195, 0.04900322109460831, 0.06407590955495834, -0.012290692888200283, 0.027008645236492157, -0.0067053590901196, -0.04817989468574524, -0.007991802878677845, -0.051109906286001205, 0.018610753118991852, -0.026254018768668175, -0.019628791138529778, 0.03238857537508011, 0.00973819475620985, 0.015301953069865704, 0.03586290031671524, 0.0190095417201519, 0.05999009311199188, -0.014682812616229057, 0.002462151227518916, 0.031654588878154755, -0.023585667833685875, -0.009678924456238747, 0.008340155705809593, 0.008365531452000141, 0.013232569210231304, -0.010553260333836079, -0.008153557777404785, -0.008013222366571426, -0.010320085100829601, -0.022315099835395813, -0.01819385401904583, 0.009736038744449615, 0.009945905767381191, 0.05418512597680092, 0.0228688083589077, 0.016203461214900017, -0.03206271305680275, -0.013992320746183395, 0.01811608485877514, -0.0009830555645748973, 0.020788436755537987, -0.008094258606433868, 0.003779418533667922, 0.03309136629104614, 0.05898040533065796, -0.0328463651239872, -0.016001099720597267, -0.02771494910120964, 0.01026347279548645, -0.05652756243944168, 0.02144993655383587, 0.05371423065662384, 0.015153368934988976, 0.00018612657731864601, -0.00232178857550025, -0.014898340217769146, 0.00004025276575703174, 0.020463746041059494, -0.04106521978974342, 0.00994758028537035, 0.04600392282009125, 0.007871870882809162, 0.002448381157591939, 0.01522610429674387, -0.007023574318736792, 0.014691322110593319, -0.0578327439725399, 0.007755588740110397, -0.018759621307253838, 0.016054049134254456, 0.032667022198438644, 0.0005576805560849607, 0.004561102949082851, 0.02055443450808525, 0.024014314636588097, -0.03975960984826088, 0.024902401491999626, 0.061655785888433456, -0.058507226407527924, 0.03412695601582527, -0.008633341640233994, -0.054718855768442154, 0.03302263841032982, -0.003055473556742072, 0.04413985460996628, 0.00850957166403532, -0.061908528208732605, 0.051049694418907166, 0.02171415463089943, 0.0321849063038826, 0.006064306478947401, 0.05315261706709862, 0.02577180787920952, 0.04122420772910118, 0.002749741543084383, 0.045503806322813034, 0.021825244650244713, 0.022532464936375618, -0.0073709976859390736, 0.06840246915817261, 0.01584680564701557, 0.01745358482003212, 0.03439328819513321, -0.013268964365124702, 0.007407195866107941, 0.029077643528580666, -0.03555133193731308, 0.0049217441119253635, -0.0070678130723536015, -0.006574446335434914, 0.050521090626716614, -0.010389218106865883, 0.020965581759810448, -0.03804593160748482, 0.04226621612906456, 0.0225727166980505, 0.023828886449337006, -0.005610629450529814, 0.008999650366604328, -0.019415006041526794, -0.0007883386570028961, 0.0033178413286805153, 0.03587063029408455, 0.011630058288574219, -0.0072525679133832455, 0.06877397000789642, 0.017697036266326904, 0.06509114801883698, 0.05385684594511986, 0.016977645456790924, -0.005894120782613754, -0.033267538994550705, 0.0041292579844594, -0.027964312583208084, 0.02936067059636116, -0.002772141946479678, 0.00036185490898787975, -0.01748216710984707, -0.05047784373164177, 0.034730006009340286, -0.026227587834000587, -0.016115600243210793, 0.03356834873557091, -0.024923207238316536, 0.009837298654019833, 0.05530540272593498, 0.017110362648963928, -0.03603995591402054, -0.027995985001325607, 0.03614497184753418, -0.014261995442211628, 0.01674572005867958, -0.05246654897928238, -0.01869991049170494, -0.01670607551932335, 0.004125189036130905, 0.0060366857796907425, -0.03463263437151909, 0.010201488621532917, -0.04997048154473305, -0.023863021284341812, 0.05629156902432442, -0.0284907016903162, 0.026032624766230583, 0.028997080400586128, 0.0111030088737607, -0.022938445210456848, -0.001837126212194562, 0.019434072077274323, -0.0011340532219037414, 0.023320699110627174, 0.008907686918973923, -0.020850179716944695, -0.002735504414886236, 0.067287877202034, 0.008400899358093739, 0.02822341024875641, -0.010366585105657578, -0.016765428707003593, 0.024780480191111565, -0.019429510459303856, -0.013851040974259377, 0.02935221791267395, 0.020392844453454018, -0.015671059489250183, 0.017749764025211334, -0.02654173970222473, -0.004177791066467762, -0.023957915604114532, -0.029653295874595642, 0.04010404646396637, 0.00441059609875083, -0.029711123555898666, -0.006213669665157795, 0.03198685869574547, -0.020538723096251488, 0.004450071137398481, 0.06940053403377533, 0.014726398512721062, 0.03673713654279709, 0.01717320829629898, -0.011557355523109436, -0.059071481227874756, 0.029445353895425797, -0.01125218253582716, -0.030172176659107208, -0.022417474538087845, 0.0040675378404557705, -0.052551936358213425, 0.00894828699529171, 0.009990755468606949, 0.028823792934417725, -0.031143372878432274, 0.0023550360929220915, -0.026527825742959976, 0.004922081716358662, -0.005074146203696728, 0.04986085370182991, 0.045891571789979935, 0.04114497825503349, 0.015590013936161995, -0.04217830300331116, -0.013501633889973164, 0.033010441809892654, 0.04778742790222168, -0.005877500865608454, 0.03086693212389946, 0.00394940422847867, -0.0039055501110851765, -0.033151235431432724, -0.06018506735563278, 0.00741194561123848, 0.017772438004612923, -0.027909541502594948, -0.014366013929247856, 0.02714473195374012, 0.06516963988542557, -0.010614128783345222, 0.009951489046216011, -0.028281614184379578, 0.016727304086089134, 0.00637105293571949, 0.004746377468109131, -0.05031722038984299, -0.013679134659469128, 0.030492322519421577, 0.014164741151034832, 0.0341835618019104, -0.008369035087525845, 0.01768086850643158, 0.04027383774518967, -0.009321441873908043, -0.04402894154191017, 0.007950350642204285, 0.019901087507605553, -0.04716147109866142, 0.04898548498749733, 0.01826181262731552, -0.02710236981511116, -0.011224308982491493, 0.01673000119626522, 0.03265542536973953, -0.011425466276705265, 0.030239222571253777, 0.026450661942362785, 0.025407699868083, 0.015017381869256496, 0.0030107656493782997, -0.011036907322704792, 0.03633597120642662, 0.019722143188118935, 0.04779308661818504, -0.02500673569738865, -0.009352533146739006 ]
How to generate text: using different decoding methods for language generation with Transformers
patrickvonplaten
March, 2020
how-to-generate
guide, nlp
https://huggingface.co/blog/how-to-generate
Introduction In recent years, there has been an increasing interest in open-ended language generation thanks to the rise of large transformer-based language models trained on millions of webpages, including OpenAI's ChatGPT and Meta's LLaMA. The results on conditioned open-ended language generation are impressive, having shown to generalize to new tasks, handle code, or take non-text data as input. Besides the improved transformer architecture and massive unsupervised training data, better decoding methods have also played an important role. This blog post gives a brief overview of different decoding strategies and more importantly shows how you can implement them with very little effort using the popular transformers library! All of the following functionalities can be used for auto-regressive language generation (here a refresher). In short, auto-regressive language generation is based on the assumption that the probability distribution of a word sequence can be decomposed into the product of conditional next word distributions: $$ P(w_{1:T} | W_0 ) = \prod_{t=1}^T P(w_{t} | w_{1: t-1}, W_0) \text{ ,with } w_{1: 0} = \emptyset, $$ and \(W_0\) being the initial context word sequence. The length \(T\) of the word sequence is usually determined on-the-fly and corresponds to the timestep \(t=T\) the EOS token is generated from \(P(w_{t} | w_{1: t-1}, W_{0})\). We will give a tour of the currently most prominent decoding methods, mainly Greedy search, Beam search, and Sampling. Let's quickly install transformers and load the model. We will use GPT2 in PyTorch for demonstration, but the API is 1-to-1 the same for TensorFlow and JAX. python !pip install -q transformers python from transformers import AutoModelForCausalLM, AutoTokenizer import torch torch_device = "cuda" if torch.cuda.is_available() else "cpu" tokenizer = AutoTokenizer.from_pretrained("gpt2") # add the EOS token as PAD token to avoid warnings model = AutoModelForCausalLM.from_pretrained("gpt2", pad_token_id=tokenizer.eos_token_id).to(torch_device)
[ 0.026886381208896637, 0.002136462600901723, 0.05283287540078163, -0.01396355964243412, 0.038424402475357056, 0.0575445182621479, 0.07299195230007172, 0.06291019171476364, -0.00002802674862323329, -0.017975984141230583, -0.09790188074111938, 0.053021661937236786, 0.011502072215080261, 0.07629908621311188, -0.004634106531739235, -0.0055128480307757854, 0.027341898530721664, 0.0051881843246519566, -0.027340514585375786, 0.020082341507077217, 0.03237055242061615, 0.011061253026127815, 0.02743665501475334, -0.001913562067784369, 0.012862569652497768, -0.05970991775393486, 0.02104230783879757, 0.001398532185703516, -0.04379964619874954, -0.009451353922486305, -0.1193881630897522, -0.008331711404025555, -0.019625235348939896, -0.040688879787921906, 0.0044815754517912865, 0.01613602787256241, -0.13712665438652039, 0.018228083848953247, 0.058523647487163544, -0.023782379925251007, -0.008904690854251385, 0.008866248652338982, -0.03766234591603279, 0.022234942764043808, -0.020179472863674164, 0.0055214641615748405, -0.1719161719083786, 0.10116613656282425, -0.07560812681913376, -0.07282263040542603, -0.08176060020923615, 0.03893830627202988, -0.05758913233876228, 0.0017386805266141891, -0.02131287194788456, 0.045220449566841125, -0.04429040476679802, -0.12862516939640045, 0.0027851909399032593, -0.026372404769062996, 0.009581489488482475, 0.025042930617928505, 0.0026211554650217295, 0.02040441893041134, 0.07188503444194794, -0.0518157035112381, -0.07567142695188522, 0.04920932650566101, -0.05912938714027405, -0.05180417001247406, -0.01808435283601284, -0.003925221972167492, -0.0649404227733612, -0.03840215131640434, 0.022578928619623184, -0.01293174922466278, -0.014179504476487637, 0.03757501021027565, 0.03301842510700226, 0.04000849276781082, 0.005684956442564726, 0.09911313652992249, 0.058631524443626404, 0.013221587054431438, 0.0564679354429245, 0.015090771950781345, 0.03524764999747276, -0.04134092479944229, -0.02097814902663231, 0.021783199161291122, -0.021599063649773598, -0.13348691165447235, 0.004015585873275995, 0.0056699602864682674, 0.06030219793319702, -0.010135727934539318, -0.002620816696435213, 0.05906054005026817, -0.05871171876788139, -0.009063946083188057, 0.03357144817709923, -0.0323675200343132, 0.01460140198469162, -0.046822287142276764, -0.02815650776028633, 0.030768288299441338, -0.011716656386852264, -0.028046613559126854, 0.0016075627645477653, -0.010963188484311104, 0.020071692764759064, 0.002038482343778014, 0.031266503036022186, 0.07901640981435776, -0.09439176321029663, -0.009928099811077118, 0.0015861665597185493, 0.014478846453130245, -0.015870697796344757, -0.012680962681770325, -0.055566150695085526, 0.05414295569062233, 0.041160646826028824, -0.044554006308317184, -0.01321866549551487, 0.06440635770559311, 0.025533411651849747, 0.051936399191617966, 0.00563611788675189, -0.02217298559844494, 0.06929438561201096, -0.03160720318555832, 0.042142484337091446, -0.00314126955345273, 0.011517898179590702, 0.01107562892138958, 0.0635630413889885, -0.05058509111404419, -0.009009269066154957, -0.01020285114645958, -0.01709488220512867, 0.04435727000236511, -0.04216403886675835, 0.02014830894768238, 0.011603578925132751, 0.006681020371615887, -0.09644243866205215, 0.05648025870323181, -0.023715699091553688, 0.04078919440507889, -0.053087133914232254, 0.0573853999376297, -0.027637969702482224, -0.035656366497278214, 0.034606464207172394, 0.059750597923994064, -0.02773621492087841, 0.02744985558092594, -0.0978461429476738, -0.025286775082349777, -0.01676083542406559, 0.04188811033964157, 0.02316957525908947, -0.0026723798364400864, 0.033202238380908966, -0.041191063821315765, 0.020529791712760925, 0.052157923579216, 0.010668301023542881, 0.05762319266796112, -0.005073093809187412, -0.00505371019244194, 0.0908110961318016, -0.010453722439706326, 0.022078482434153557, 0.000120032302220352, 0.026403501629829407, 0.024389423429965973, 0.006528113503009081, -0.008413782343268394, -0.0749664455652237, 0.014098068699240685, 0.04046517238020897, 0.01413741521537304, 0.05540125444531441, -0.10486217588186264, 0.0007970881997607648, -0.007971690036356449, 0.0014457895886152983, 0.044689375907182693, -0.037502557039260864, -0.00022943496878724545, 0.05633186548948288, -0.01156222727149725, 0.010053970851004124, -0.05588582158088684, -0.03361017256975174, 0.09323998540639877, 0.0702177882194519, 0.08689329028129578, 0.06006177142262459, 0.007269447669386864, 0.028959179297089577, -0.027643799781799316, -0.03187829256057739, -0.05464603006839752, -0.01367720402777195, -0.0013990612933412194, 0.0005149547359906137, -0.007796945981681347, -0.0057584019377827644, -0.11356272548437119, -0.0025084165390580893, -0.11474555730819702, -0.004474141635000706, -0.00778539665043354, -0.01115468516945839, -0.0030374207999557257, -0.0018798570381477475, 0.022345302626490593, 0.14529794454574585, -0.13649879395961761, -0.0004498859343584627, -0.05234577879309654, -0.0009623855585232377, 0.08901496231555939, 0.03500259667634964, 0.05251823365688324, 0.02902253530919552, -0.06776849925518036, -0.02770623378455639, -0.10409945994615555, 0.034040894359350204, 0.021474679931998253, 0.01193465106189251, -0.07976679503917694, 0.01622195914387703, -0.027249937877058983, 0.026399526745080948, -0.00335066020488739, 0.014867948368191719, 0.02853420563042164, -0.04912896826863289, 0.027400877326726913, 0.0075157093815505505, -0.04070241004228592, 0.05193762108683586, 0.0029431672301143408, -0.01747122034430504, -0.008424953557550907, -0.03228595480322838, 0.08625581860542297, -0.04611320048570633, -0.046646296977996826, 0.009580223821103573, 0.03701557219028473, 0.001966355834156275, 0.008245530538260937, -0.007465841248631477, 0.040763672441244125, -0.012204151600599289, -0.01973702572286129, -0.0002881028631236404, -0.06016850471496582, 0.0009683400276117027, -0.03405388444662094, 0.03114745207130909, 0.056744832545518875, 0.018511304631829262, -0.009792824275791645, -0.008244122378528118, -0.021554913371801376, -0.00867342110723257, -0.004276723600924015, 0.017155876383185387, 0.036572858691215515, 0.03430933132767677, -0.023093223571777344, -0.036532461643218994, -0.029854992404580116, -0.01383643876761198, -0.018382102251052856, 0.04138882830739021, 0.056622862815856934, -0.009919524192810059, -0.0017245856579393148, 0.0033367217984050512, 0.013538519851863384, -0.023300359025597572, 0.031638696789741516, -0.01442787516862154, 0.02799103781580925, -0.00389756727963686, -0.030041303485631943, -0.01393639761954546, -0.004058945924043655, -0.02541187033057213, 0.003839055774733424, -0.01908845826983452, -0.001121637295000255, -0.033072423189878464, -0.0265152920037508, 0.004058608785271645, 0.012785482220351696, -0.0216070469468832, -0.00007316868141060695, 0.013159623369574547, 0.03607537969946861, -0.09555837512016296, -0.01394319161772728, 0.007735882420092821, -0.025063375011086464, -0.004935405682772398, -0.015158875845372677, 0.02499575726687908, -0.01671207696199417, -0.02230011858046055, -0.004600732121616602, 0.000898972968570888, 0.02636547014117241, 0.004998163320124149, 0.000827068870421499, 0.015236569568514824, -0.02044321969151497, -0.03007218986749649, -0.003816857235506177, 0.0147276371717453, 0.002144090598449111, 0.02105432003736496, 0.016018008813261986, -0.023535221815109253, 0.02994314208626747, -0.04387697950005531, -0.006869070697575808, 0.030412426218390465, 0.006165799219161272, 0.028255198150873184, 0.016856340691447258, -0.0009921066230162978, 0.010678249411284924, 0.014744069427251816, 0.02446676976978779, -0.032588712871074677, -0.006688940804451704, 0.03452213481068611, 0.015182917937636375, -0.02816251665353775, 0.05962973088026047, -0.007733660750091076, -0.026460761204361916, 0.0004010865231975913, -0.03693677484989166, 0.001495309523306787, 0.01057042833417654, -0.013472527265548706, 0.0004927605041302741, 0.005437592044472694, -0.029901579022407532, -0.0303160659968853, -0.020358752459287643, -0.012153449468314648, 0.03077731654047966, 0.016134412959218025, 0.03566959872841835, -0.002090448746457696, 0.02732706069946289, 0.027879206463694572, 0.03439059481024742, -0.056519631296396255, 0.007392405066639185, 0.011754326522350311, -0.04493441432714462, -0.015357299707829952, 0.07294884324073792, 0.005083137657493353, 0.0036503958981484175, -0.01414515171200037, 0.061189644038677216, -0.009453310631215572, 0.03954372927546501, 0.0031772940419614315, 0.008042517118155956, -0.012649822980165482, 0.02764069475233555, -0.03169376403093338, -0.05002477020025253, 0.06992967426776886, 0.036559101194143295, -0.043965138494968414, -0.05855254456400871, -0.06539008021354675, -0.020739158615469933, -0.01814997009932995, -0.005497574806213379, 0.005679901223629713, -0.009979844093322754, 0.016281798481941223, 0.026798304170370102, 0.027872659265995026, -0.010071477852761745, 0.037064604461193085, 0.0029976493678987026, -0.01765824481844902, 0.019782811403274536, 0.00856284610927105, 0.025767536833882332, 0.019149787724018097, 0.012343219481408596, 0.03675183281302452, -0.08726286888122559, 0.001080631627701223, -0.014068875461816788, -0.025927124544978142, 0.02529883198440075, -0.07012981921434402, 0.009276483207941055, 0.020589184015989304, 0.03654849901795387, 0.003733237273991108, 0.002669386565685272, -0.007860003039240837, 0.01045896764844656, 0.01462562195956707, 0.02601740136742592, 0.010738561861217022, -0.06786920130252838, -0.034433066844940186, -0.022064339369535446, -0.03241764381527901, 0.0011608018539845943, -0.005667766090482473, -0.033915530890226364, 0.042953744530677795, -0.034247394651174545, 0.03426661714911461, 0.03028452768921852, 0.007284663151949644, -0.006833606865257025, -0.02988162636756897, -0.023924419656395912, -0.00006864315218990669, 0.016647057607769966, -0.007546825800091028, 0.029189513996243477, 0.020347770303487778, -0.03192906081676483, -0.02642439305782318, -0.021696964278817177, -0.03693927824497223, -0.025328757241368294, 0.028522657230496407, -0.008436210453510284, 0.026967652142047882, 0.00814573373645544, -0.00858991127461195, -0.008132295683026314, -0.0065550049766898155, -0.0014255779096856713, 0.033864155411720276, 0.0108961695805192, -0.019546961411833763, -0.024123188108205795, 0.030695706605911255, 0.01615247316658497, -0.028088266029953957, 0.06141115352511406, 0.010165579617023468, 0.033927109092473984, 0.0009034752729348838, -0.003974896389991045, -0.04116404801607132, 0.00181694352068007, 0.018111933022737503, -0.00562796276062727, -0.0065319957211613655, -0.020865144208073616, 0.009817726910114288, 0.0008902109111659229, -0.0032034432515501976, 0.02045675553381443, 0.007330635562539101, -0.010978514328598976, 0.0007939334027469158, 0.0371243953704834, 0.020082399249076843, 0.020819079130887985, -0.023461440578103065, -0.006689876317977905, -0.03465144708752632, -0.024692680686712265, 0.045602913945913315, 0.016409391537308693, 0.0006282199174165726, 0.02715514972805977, 0.05740562826395035, 0.023446884006261826, 0.02823273278772831, 0.03565915673971176, -0.005751991178840399, -0.023204579949378967, 0.013472198508679867, -0.01001791562885046, 0.010154323652386665, -0.011077912524342537, -0.008507010526955128, 0.04378555342555046, 0.006762489676475525, 0.024432627484202385, 0.0340690091252327, 0.039548635482788086, -0.02465411089360714, -0.021185796707868576, 0.022396769374608994, 0.009366558864712715, -0.02290448732674122, -0.05646909400820732, -0.004566992167383432, -0.03283826634287834, 0.004660172387957573, 0.024330131709575653, -0.023761797696352005, 0.004873659927397966, -0.02832532301545143, -0.01908242702484131, 0.00011904535494977608, 0.01287178322672844, -0.007787745911628008, 0.07204389572143555, 0.010926876217126846, -0.010890895500779152, -0.004867909476161003, -0.005942867137491703, 0.03735528513789177, -0.02340579405426979, -0.017850255593657494, 0.04304824396967888, -0.012407498434185982, -0.006893225014209747, 0.03523721918463707, -0.04621311277151108, -0.025641685351729393, 0.05033804476261139, 0.03596439212560654, -0.052274491637945175, -0.014846806414425373, 0.0057760123163461685, -0.0022510916460305452, 0.018552539870142937, 0.013770478777587414, -0.030705073848366737, -0.024111753329634666, 0.018050823360681534, -0.042661912739276886, 0.05718276649713516, 0.05961987376213074, -0.02470454014837742, -0.02879837341606617, 0.00979641079902649, 0.03349350020289421, -0.018799830228090286, -0.020858749747276306, 0.00785207562148571, 0.01198853924870491, 0.014918036758899689, 0.00683479942381382, -0.01845591887831688, -0.03556571900844574, 0.02124725840985775, 0.017527971416711807, -0.06210402026772499, -0.010448185727000237, 0.05705434828996658, -0.055289652198553085, 0.008460032753646374, 0.015562398359179497, -0.02872992493212223, -0.03388003259897232, -0.011982808820903301, 0.03563806414604187, 0.006543110124766827, -0.018360821530222893, -0.01174027007073164, -0.018282640725374222, -0.027160273864865303, -0.013035880401730537, 0.08041945099830627, 0.014260202646255493, 0.06450619548559189, 0.027212465181946754, 0.04913324490189552, 0.003812885144725442, -0.0009028853964991868, -0.016826419159770012, 0.02785130962729454, 0.07021071016788483, 0.025525318458676338, 0.034407954663038254, 0.011225536465644836, -0.0028005908243358135, -0.018700916320085526, -0.058361344039440155, -0.049402132630348206, -0.02963658794760704, 0.012396150268614292, 0.05224866792559624, -0.006869735196232796, 0.02035623975098133, -0.03257910907268524, 0.05187924578785896, 0.05785952880978584, 0.04382346570491791, 0.006105219479650259, 0.04057357460260391, -0.006421580910682678, 0.03606787696480751, 0.030477328225970268, 0.04393535479903221, 0.008014892227947712, -0.0010041040368378162, 0.036656703799963, 0.031178301200270653, 0.0662514865398407, 0.025203971192240715, -0.010623267851769924, 0.0034149123821407557, -0.005616580136120319, -0.000504613621160388, 0.01669250801205635, 0.02146645449101925, -0.002593062585219741, -0.030192842707037926, -0.0101262042298913, -0.022306928411126137, 0.021831169724464417, -0.004612376447767019, -0.022775115445256233, -0.03636343032121658, -0.02338259667158127, -0.014570149593055248, 0.04825102165341377, -0.008368528448045254, -0.049060117453336716, 0.013016159646213055, -0.007443285081535578, -0.021918971091508865, 0.044181082397699356, -0.035050418227910995, -0.016613736748695374, -0.019853219389915466, -0.015769384801387787, -0.02367347478866577, -0.027370965108275414, 0.005029663443565369, -0.026393039152026176, -0.004409885499626398, 0.011760355904698372, -0.02909301221370697, 0.011922190897166729, 0.03635221719741821, 0.008360828272998333, -0.03757188096642494, -0.009133144281804562, -0.0004170646134298295, 0.00957361701875925, -0.006353875156491995, -0.04416819289326668, -0.010751252993941307, -0.005394261330366135, 0.01366870291531086, 0.04727592319250107, 0.058674126863479614, -0.012481232173740864, -0.05050140619277954, -0.012145322747528553, -0.006747938692569733, -0.019235974177718163, 0.03588598966598511, -0.020855676382780075, -0.004827722907066345, -0.005769367329776287, -0.015062503516674042, -0.005225390195846558, -0.004682159051299095, -0.003893276210874319, 0.0521148256957531, 0.01807083562016487, -0.0372948981821537, -0.014126505702733994, 0.04742257669568062, 0.004862576723098755, 0.035405680537223816, 0.0693468302488327, 0.022095724940299988, 0.029435357078909874, 0.005880575627088547, 0.03725481405854225, -0.0838383361697197, 0.026004493236541748, -0.038789428770542145, -0.08398683369159698, 0.0014745898079127073, 0.00994103029370308, 0.00046033665421418846, -0.006235964596271515, -0.054054662585258484, 0.011239760555326939, -0.06183726340532303, 0.0076760537922382355, 0.04026011377573013, -0.010216071270406246, 0.07387952506542206, -0.0012439301935955882, 0.04760303720831871, 0.019467288628220558, 0.006621644366532564, -0.004021420609205961, -0.006088279187679291, 0.015380601398646832, 0.0669560581445694, 0.01038641668856144, 0.014608882367610931, 0.003579425159841776, -0.006654593162238598, 0.0007568406872451305, -0.0019749163184314966, 0.02551906742155552, -0.010856413282454014, -0.024022754281759262, -0.01705935411155224, 0.04818583279848099, 0.016227560117840767, 0.011175570078194141, -0.00731732789427042, -0.020754070952534676, 0.005263783037662506, 0.0248943530023098, 0.0008425910491496325, -0.06954756379127502, -0.004785955883562565, 0.032843608409166336, 0.03806387633085251, 0.040718160569667816, 0.011512810364365578, 0.03968888148665428, -0.011158852837979794, 0.011052491143345833, -0.0018072023522108793, 0.058459024876356125, -0.022319458425045013, -0.025078507140278816, 0.004981998819857836, -0.0009022403974086046, -0.03272927552461624, -0.011765461415052414, 0.031013749539852142, -0.0009422540315426886, -0.022704806178808212, 0.0004143415135331452, -0.023089569061994553, -0.0038198435213416815, 0.0067270672880113125, 0.023187758401036263, 0.03550601378083229, 0.03570866212248802, 0.02846525050699711, -0.003628746373578906, -0.05328930541872978, -0.0036862469278275967 ]
How to generate text: using different decoding methods for language generation with Transformers
patrickvonplaten
March, 2020
how-to-generate
guide, nlp
https://huggingface.co/blog/how-to-generate
Top-K Sampling Fan et. al (2018) introduced a simple, but very powerful sampling scheme, called Top-K sampling. In Top-K sampling, the K most likely next words are filtered and the probability mass is redistributed among only those K next words. GPT2 adopted this sampling scheme, which was one of the reasons for its success in story generation. We extend the range of words used for both sampling steps in the example above from 3 words to 10 words to better illustrate Top-K sampling. Having set \(K = 6\), in both sampling steps we limit our sampling pool to 6 words. While the 6 most likely words, defined as \(V_{\text{top-K}}\) encompass only ca. two-thirds of the whole probability mass in the first step, it includes almost all of the probability mass in the second step. Nevertheless, we see that it successfully eliminates the rather weird candidates \((\text{not"}, \text{the"}, \text{small"}, \text{told"})\) in the second sampling step. Let's see how Top-K can be used in the library by setting top_k=50: python # set seed to reproduce results. Feel free to change the seed though to get different results set_seed(42) # set top_k to 50 sample_output = model.generate( **model_inputs, max_new_tokens=40, do_sample=True, top_k=50 ) print("Output:\n" + 100 * '-') print(tokenizer.decode(sample_output[0], skip_special_tokens=True)) Output: ---------------------------------------------------------------------------------------------------- I enjoy walking with my cute dog for the rest of the day, but this time it was hard for me to figure out what to do with it. (One reason I asked this for a few months back is that I had a Not bad at all! The text is arguably the most human-sounding text so far. One concern though with Top-K sampling is that it does not dynamically adapt the number of words that are filtered from the next word probability distribution \(P(w|w_{1:t-1})\). This can be problematic as some words might be sampled from a very sharp distribution (distribution on the right in the graph above), whereas others from a much more flat distribution (distribution on the left in the graph above). In step \(t=1\), Top-K eliminates the possibility to sample \((\text{"people"}, \text{"big"}, \text{"house"}, \text{"cat"})\), which seem like reasonable candidates. On the other hand, in step \(t=2\) the method includes the arguably ill-fitted words \((\text{"down"}, \text{"a"})\) in the sample pool of words. Thus, limiting the sample pool to a fixed size K could endanger the model to produce gibberish for sharp distributions and limit the model's creativity for flat distribution. This intuition led Ari Holtzman et al. (2019) to create Top-p- or nucleus-sampling.
[ 0.017972595989704132, -0.0333731435239315, -0.00983202550560236, 0.002602221444249153, 0.09611862152814865, 0.006561956834048033, 0.010640772059559822, 0.010338676162064075, -0.05866548791527748, -0.009469225071370602, -0.13796848058700562, -0.035251930356025696, 0.005474548786878586, 0.05828157067298889, -0.011845504865050316, 0.012413552962243557, 0.022648943588137627, 0.00579485110938549, 0.05123966932296753, -0.11192470788955688, 0.058148037642240524, -0.024735186249017715, 0.07578890025615692, -0.07914692163467407, 0.08193668723106384, -0.009877900592982769, -0.010135915130376816, -0.007270247675478458, -0.03445564955472946, 0.020804839208722115, -0.17959025502204895, 0.0068268985487520695, 0.055395275354385376, -0.0006902452441863716, 0.04259024187922478, -0.0675744041800499, -0.10752612352371216, 0.048288170248270035, 0.05891543626785278, -0.027667086571455002, -0.011613322421908379, -0.036425698548555374, -0.061222244054079056, 0.035857681185007095, -0.02746582217514515, -0.04935166984796524, -0.1095605120062828, 0.0715034008026123, -0.09319052845239639, -0.07887633144855499, -0.04409406706690788, 0.03093723952770233, -0.08342041820287704, 0.014638551510870457, -0.0207391194999218, -0.027168555185198784, 0.009731903672218323, -0.11149805039167404, 0.007290932349860668, 0.01386816706508398, 0.01709807850420475, -0.02130240947008133, 0.06114455685019493, 0.0730753093957901, -0.012333907186985016, -0.018366169184446335, -0.029146568849682808, 0.05504698306322098, -0.06794852018356323, -0.04117155820131302, -0.008263562805950642, -0.055029649287462234, -0.04572334885597229, -0.03283262997865677, -0.037302859127521515, -0.015671374276280403, 0.007384785450994968, 0.053895846009254456, -0.010598436929285526, 0.004851709119975567, -0.003401351859793067, -0.022135231643915176, 0.031651053577661514, 0.022655999287962914, 0.048570211976766586, 0.022510241717100143, 0.05672655254602432, -0.05275045335292816, -0.03228596970438957, 0.05329160764813423, -0.03233133628964424, -0.11640549451112747, 0.05282494053244591, 0.06191922351717949, 0.009183444082736969, -0.016147799789905548, -0.028987010940909386, 0.06413325667381287, 0.01643797755241394, -0.004021231085062027, -0.02022896520793438, -0.11336927115917206, -0.009675933979451656, -0.028171319514513016, -0.0967038944363594, 0.05395083129405975, -0.031190922483801842, -0.023624636232852936, 0.004792100749909878, 0.04880169406533241, 0.005856685806065798, -0.02088550478219986, -0.021604089066386223, 0.0243152417242527, -0.03456765413284302, 0.053916215896606445, -0.009209181182086468, 0.004790332168340683, -0.06799377501010895, -0.025580408051609993, -0.02303250879049301, 0.05454881861805916, 0.08679051697254181, -0.012180808000266552, -0.035246506333351135, -0.02334780804812908, 0.02471449226140976, 0.016999028623104095, -0.027357134968042374, -0.006255766376852989, 0.04090694710612297, 0.031207313761115074, -0.01753091998398304, -0.007887140847742558, 0.0358528234064579, -0.013300756923854351, 0.025212733075022697, -0.014292825944721699, -0.011084464378654957, -0.005056184716522694, 0.04278763756155968, -0.025844328105449677, -0.03121142089366913, 0.02831481397151947, 0.001701612607575953, 0.034744974225759506, -0.06418320536613464, 0.03321019187569618, -0.04386523738503456, 0.046724576503038406, -0.021875059232115746, 0.09513823688030243, -0.04622495174407959, -0.029289979487657547, 0.05900539830327034, 0.014849020168185234, -0.00954759307205677, -0.007329255808144808, -0.06049824506044388, -0.058319419622421265, -0.003967831376940012, 0.025752311572432518, 0.051952946931123734, -0.029479924589395523, 0.04368628188967705, -0.017195116728544235, 0.029895780608057976, 0.027133455500006676, -0.0324614979326725, 0.015626734122633934, -0.039791032671928406, -0.034225571900606155, 0.04005277156829834, -0.02862490713596344, 0.04066682606935501, 0.05316351726651192, -0.005216941237449646, 0.022464660927653313, -0.012625779025256634, 0.027597088366746902, -0.0480269193649292, -0.007277138996869326, 0.01567988470196724, 0.005305022932589054, 0.034846823662519455, -0.10938982665538788, 0.016560601070523262, 0.033692434430122375, 0.02910728193819523, -0.0183532927185297, -0.04437337815761566, -0.08720217645168304, 0.0804542824625969, 0.021725649014115334, 0.0036447306629270315, -0.0744319036602974, 0.032103970646858215, 0.05317113921046257, 0.047676026821136475, 0.06061780825257301, 0.0804571658372879, 0.06899256259202957, 0.039621397852897644, -0.024345969781279564, -0.03944065049290657, -0.025925811380147934, -0.03631529584527016, -0.05206276848912239, 0.0395708791911602, 0.03628285229206085, -0.05959056690335274, -0.039717111736536026, 0.004479698371142149, -0.10939130932092667, -0.03083972819149494, -0.010750063695013523, 0.04336988553404808, 0.0157192200422287, 0.006139819044619799, 0.009480848908424377, 0.1277254819869995, -0.0623759850859642, 0.029085619375109673, -0.025441857054829597, -0.03789597749710083, 0.07834535837173462, 0.05222543701529503, -0.026798730716109276, 0.05555266514420509, -0.027823032811284065, -0.06462102383375168, -0.04698394984006882, 0.021009422838687897, 0.04885198548436165, 0.023651687428355217, -0.05255316570401192, -0.0207419041544199, -0.01492603961378336, 0.03572307899594307, -0.05543054640293121, 0.0029851209837943316, 0.013404685072600842, -0.07177218794822693, 0.07856247574090958, -0.012881899252533913, -0.0014474581694230437, 0.08459043502807617, -0.04218093305826187, -0.034242112189531326, -0.08097393810749054, -0.05335844308137894, 0.007436798885464668, -0.02642708644270897, -0.054628174751996994, 0.01701427809894085, 0.0928557738661766, -0.025057809427380562, -0.02082090824842453, -0.03952138125896454, -0.04584047198295593, -0.020964689552783966, -0.047257743775844574, -0.003326959442347288, -0.016554832458496094, -0.0002501958515495062, 0.0017511951737105846, 0.008654291741549969, -0.0027276540640741587, -0.012461422011256218, 0.0027090299408882856, 0.008001035079360008, -0.03193247690796852, -0.011301737278699875, 0.023617302998900414, -0.0127716651186347, -0.015227949246764183, 0.04256381839513779, -0.027415161952376366, -0.00170026661362499, -0.008908074349164963, -0.004743572324514389, 0.010954645462334156, 0.02154013141989708, 0.06047244742512703, 0.021838687360286713, 0.012921915389597416, 0.049262646585702896, -0.001376860891468823, -0.038472358137369156, -0.00003704662958625704, -0.024772243574261665, 0.006217207759618759, -0.004156050272285938, -0.013297337107360363, 0.007945088669657707, -0.007976049557328224, -0.02339908294379711, 0.0011330588022246957, -0.020307615399360657, -0.0020144013687968254, -0.02927973121404648, 0.0024775618221610785, -0.018826816231012344, -0.005198020488023758, -0.016610000282526016, 0.011634251102805138, -0.0005488725146278739, 0.05907382443547249, -0.10383325070142746, -0.010953514836728573, 0.021557144820690155, 0.021361464634537697, 0.011973862536251545, -0.029480300843715668, 0.02405000664293766, -0.0002743590157479048, -0.017370697110891342, 0.023811805993318558, 0.036566924303770065, -0.0011165969772264361, -0.0057387640699744225, 0.009828906506299973, -0.019641036167740822, 0.004918769467622042, 0.008832265622913837, -0.0004006323288194835, 0.05071669816970825, 0.04753667861223221, 0.04183641076087952, 0.02523716166615486, 0.013207875192165375, -0.0021319594234228134, -0.023604705929756165, 0.013379007577896118, 0.030246110633015633, 0.03334851562976837, 0.031663764268159866, -0.015678565949201584, 0.003932851366698742, -0.015427826903760433, 0.008442079648375511, 0.02091025747358799, -0.017611704766750336, -0.0015923723112791777, 0.01941416785120964, 0.00031608782592229545, -0.012989155016839504, 0.03655916079878807, -0.015295115299522877, -0.019628487527370453, 0.014851746149361134, -0.003020728472620249, 0.025726664811372757, 0.0045471577905118465, -0.028990721330046654, 0.006533354986459017, 0.028768716380000114, -0.05812263488769531, 0.010624327696859837, -0.025987401604652405, -0.003135128878057003, 0.028187790885567665, 0.008279762230813503, 0.012366966344416142, 0.025520626455545425, 0.03241060674190521, 0.03868314251303673, -0.006484304089099169, -0.0025054116267710924, 0.019427111372351646, 0.005524751264601946, -0.01809612475335598, -0.005287487991154194, 0.02549515850841999, 0.03543107211589813, 0.0310375839471817, -0.014642409980297089, 0.04214821010828018, 0.01154049951583147, -0.008868720382452011, 0.024914126843214035, 0.0035864473320543766, -0.015116474591195583, 0.03396710753440857, -0.040831662714481354, -0.036671556532382965, 0.03780939057469368, 0.03130529075860977, -0.024743538349866867, 0.023084407672286034, -0.032035306096076965, 0.006088308524340391, 0.003994023893028498, -0.024533044546842575, 0.009978962130844593, -0.0349055640399456, 0.024319106712937355, -0.004035658203065395, -0.0685516744852066, -0.030831674113869667, -0.013015023432672024, 0.011065769009292126, -0.005639185197651386, 0.017918795347213745, -0.01920006237924099, -0.0060381218791007996, 0.0005059778923168778, 0.038115181028842926, -0.0006418076809495687, -0.033666279166936874, 0.018579406663775444, -0.043949972838163376, -0.028991173952817917, 0.013881205581128597, -0.06478794664144516, 0.0097556933760643, 0.015780160203576088, 0.031901899725198746, 0.012087607756257057, 0.005081617273390293, -0.021123943850398064, -0.017069276422262192, 0.03819781169295311, 0.04244343936443329, 0.034321244806051254, 0.000609401729889214, -0.008608740754425526, -0.0037710797041654587, -0.023276057094335556, 0.009338267147541046, -0.015337595716118813, 0.0321662575006485, 0.046938396990299225, -0.015173372812569141, 0.03671585023403168, -0.023542732000350952, -0.012135961093008518, -0.02112271450459957, -0.021350683644413948, -0.004589255899190903, 0.006657871883362532, -0.016757093369960785, 0.04983643814921379, 0.009826354682445526, -0.007274291943758726, -0.013559052720665932, -0.016819797456264496, -0.08150088787078857, -0.00011983321019215509, 0.009453901089727879, 0.03128965571522713, -0.0330820195376873, 0.045042984187603, -0.00041998212691396475, -0.0037993043661117554, 0.011176331900060177, -0.026105428114533424, -0.00932416133582592, 0.04832332581281662, -0.002699075033888221, -0.0399840883910656, -0.04269897937774658, 0.018460692837834358, 0.01323118805885315, -0.053964074701070786, 0.034269314259290695, 0.007114591542631388, 0.05600840598344803, 0.00818521250039339, -0.03121986798942089, 0.003763145999982953, -0.000394545029848814, -0.0008867285796441138, -0.006760155316442251, -0.0007570178131572902, -0.01497217733412981, 0.010339911095798016, 0.01384004857391119, 0.042401742190122604, -0.00007764499605400488, -0.01882000081241131, 0.0038831604178994894, 0.013050717301666737, 0.029265930876135826, -0.00014933054626453668, 0.011755234561860561, -0.027994399890303612, 0.025562308728694916, -0.05123843252658844, -0.01909032091498375, -0.02333909459412098, 0.019860217347741127, 0.008346359245479107, 0.04366038739681244, 0.05839109793305397, 0.07067932188510895, -0.031632546335458755, 0.04720139503479004, -0.015308395028114319, -0.019943658262491226, 0.012350199744105339, -0.05819818004965782, 0.01667221263051033, -0.019733240827918053, -0.009814316406846046, 0.0600915364921093, 0.012783780694007874, -0.005873960442841053, 0.022584769874811172, 0.007739565335214138, 0.02220824919641018, -0.02303893119096756, 0.0013199830427765846, 0.040481533855199814, -0.018505647778511047, -0.013647064566612244, 0.03174323961138725, 0.0003536735603120178, -0.002971306210383773, -0.020998571068048477, -0.010104622691869736, -0.028972050175070763, -0.005289025139063597, -0.0352204255759716, -0.031175296753644943, 0.014579645358026028, 0.015895046293735504, 0.061592575162649155, 0.0242286529392004, 0.0034897036384791136, -0.048601195216178894, -0.005437259096652269, 0.023739375174045563, 0.009936179965734482, 0.01913924515247345, 0.011517571285367012, 0.024019313976168633, 0.027805615216493607, 0.04342937842011452, -0.0443284846842289, -0.02716882713139057, -0.002345392946153879, -0.017859982326626778, -0.02670116536319256, 0.0038007646799087524, 0.05907994881272316, 0.03239310532808304, 0.030404534190893173, 0.010129093192517757, -0.014934197999536991, -0.005903040058910847, -0.007183222100138664, -0.041986241936683655, 0.01183217205107212, -0.008896195329725742, -0.012368077412247658, -0.01102010440081358, -0.008735070005059242, 0.006594415754079819, 0.010410613380372524, -0.029017388820648193, -0.003605638397857547, -0.0046252040192484856, -0.014695987105369568, 0.061560969799757004, 0.008103244937956333, 0.015982432290911674, 0.021196499466896057, 0.03861115872859955, -0.06299921870231628, 0.008923755027353764, 0.04699641838669777, -0.04749765992164612, 0.022884463891386986, -0.010013766586780548, -0.06965766847133636, 0.04796098545193672, 0.02515394613146782, 0.05522477999329567, 0.012346970848739147, -0.0638158991932869, 0.03136225789785385, -0.013523588888347149, 0.018496353179216385, -0.002360365819185972, 0.04927482455968857, -0.0031875998247414827, 0.06415240466594696, 0.001172647112980485, 0.0448826402425766, 0.03808988630771637, 0.0017497342778369784, 0.003636642126366496, 0.08185309171676636, 0.031031256541609764, -0.005836906377226114, 0.04481276124715805, -0.0031046150252223015, 0.005603163503110409, 0.037027452141046524, -0.017729096114635468, 0.0033439670223742723, 0.025532804429531097, 0.008227652870118618, 0.049756139516830444, -0.016711249947547913, 0.039193008095026016, -0.02857901342213154, 0.035583652555942535, 0.061332184821367264, 0.0019538411870598793, -0.02353653870522976, -0.015468770638108253, 0.012399534694850445, 0.007858816534280777, 0.004252752289175987, 0.05512261390686035, 0.0012209111591801047, -0.006966363172978163, 0.07829614728689194, 0.018782317638397217, 0.0911470577120781, 0.03397130221128464, 0.00015954651462379843, 0.005571057554334402, -0.04001540690660477, 0.030289214104413986, -0.03407136723399162, 0.019228894263505936, -0.015846583992242813, 0.008833436295390129, -0.0222813468426466, -0.03780437633395195, 0.014828229323029518, -0.008585944771766663, 0.010230052284896374, 0.03586425259709358, -0.0418841652572155, 0.0076856533996760845, 0.03667477145791054, 0.024187490344047546, -0.044606104493141174, 0.003857891308143735, 0.057493265718221664, -0.018855810165405273, 0.007871248759329319, -0.03704606369137764, -0.0041497861966490746, -0.011730688624083996, 0.007130622863769531, 0.010007279925048351, -0.009586942382156849, 0.01893666759133339, -0.030600937083363533, -0.00862033013254404, 0.059676747769117355, -0.056479208171367645, 0.012521304190158844, 0.021283574402332306, 0.027448812499642372, 0.0021386384032666683, -0.012063886970281601, 0.008483676239848137, 0.007193233817815781, 0.0098936278373003, -0.01498226448893547, -0.00952458381652832, -0.02293623425066471, 0.05942844972014427, 0.019737888127565384, 0.02265026792883873, -0.02903275564312935, -0.03044041618704796, 0.021656697615981102, -0.011704410426318645, -0.003118526889011264, -0.008699986152350903, 0.017749978229403496, -0.014439871534705162, 0.0037992384750396013, -0.028811082243919373, -0.002672224771231413, -0.027242472395300865, -0.008526605553925037, 0.02500081993639469, 0.029429908841848373, -0.017095034942030907, 0.007813471369445324, 0.023502562195062637, -0.030782539397478104, 0.030807800590991974, 0.02130207233130932, 0.03215773031115532, 0.03569592162966728, 0.04302183538675308, 0.018747324123978615, -0.029200859367847443, -0.009565949440002441, -0.02301495335996151, -0.038643963634967804, -0.019793933257460594, -0.0052566840313375, -0.03307386487722397, -0.010339240543544292, 0.00403054803609848, 0.02891281247138977, -0.00790499895811081, 0.015886200591921806, -0.03742288798093796, -0.014242757111787796, -0.01199303101748228, -0.0024536692071706057, 0.04471709579229355, 0.0577189102768898, 0.03188037872314453, -0.04996171593666077, 0.009404875338077545, 0.035648494958877563, 0.03534598648548126, 0.023338694125413895, 0.024117309600114822, -0.008149182423949242, 0.02829812280833721, -0.05366107076406479, -0.0509662926197052, 0.01927880011498928, 0.01563495397567749, -0.01086097676306963, -0.036599885672330856, 0.013816412538290024, 0.06639963388442993, -0.02923743799328804, -0.012587730772793293, -0.014582790434360504, 0.0009290585294365883, 0.012867901474237442, 0.023790985345840454, -0.050791941583156586, -0.0005900039686821401, 0.028502672910690308, 0.006526230834424496, 0.02836318127810955, -0.001897158450447023, 0.046445850282907486, 0.03494910150766373, 0.005273575894534588, -0.013012292794883251, 0.03152039647102356, -0.003943773452192545, -0.057289090007543564, 0.05150829628109932, 0.03542308509349823, -0.04641373082995415, -0.026687419041991234, 0.031582314521074295, 0.029225625097751617, -0.023176563903689384, 0.029564404860138893, 0.04782385006546974, 0.028448794037103653, -0.02009628154337406, 0.007569547276943922, 0.0004118456272408366, 0.05066618323326111, 0.00244869920425117, 0.026615872979164124, -0.0030392261687666178, 0.0006062670727260411 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
4. Axial Positional Encodings Reformer makes it possible to process huge input sequences. However, for such long input sequences standard positional encoding weight matrices alone would use more than 1GB to store its weights. To prevent such large positional encoding matrices, the official Reformer code introduced Axial Position Encodings. Important: Axial Position Encodings were not explained in the official paper, but can be well understood from looking into the code and talking to the authors
[ 0.01739358901977539, 0.09646188467741013, 0.023341769352555275, -0.043460216373205185, 0.002040660474449396, 0.027561791241168976, 0.016433842480182648, -0.06194771081209183, -0.05389344319701195, -0.015819501131772995, -0.05127580836415291, -0.05089105665683746, 0.011229590512812138, -0.051073286682367325, 0.004553745500743389, -0.03393488749861717, 0.05670321360230446, -0.05330052226781845, -0.055022452026605606, 0.013153565116226673, 0.024662571027874947, -0.029239125549793243, 0.06677021831274033, 0.021657345816493034, -0.023887868970632553, 0.00830894336104393, -0.03643778711557388, -0.035780396312475204, -0.08168566972017288, 0.01931758224964142, -0.11804845929145813, -0.031054887920618057, 0.012095138430595398, -0.005220099817961454, -0.007453578058630228, -0.022980768233537674, -0.10860241949558258, 0.1000780388712883, 0.055219992995262146, -0.09749097377061844, -0.07187306880950928, 0.04646946117281914, -0.011006492190063, 0.057535842061042786, -0.039152584969997406, -0.039034537971019745, -0.15089166164398193, 0.10029835253953934, -0.053950387984514236, -0.01762782223522663, -0.10382145643234253, 0.02195117622613907, -0.023371923714876175, 0.07177843898534775, -0.0027597604785114527, -0.03508872911334038, 0.04487120360136032, 0.0204829890280962, 0.043932780623435974, -0.0331120528280735, 0.041041918098926544, 0.022920692339539528, -0.004366520792245865, -0.012464475817978382, 0.023400187492370605, -0.03226516768336296, -0.02087581157684326, 0.022131187841296196, -0.011234312318265438, -0.06697511672973633, -0.014291851781308651, -0.02658211998641491, -0.02081863395869732, -0.012956265360116959, -0.01331146340817213, -0.03963330388069153, -0.08273568004369736, 0.03568759933114052, 0.07354949414730072, 0.024649161845445633, -0.014279734343290329, 0.0881030485033989, 0.02677316591143608, 0.058061253279447556, 0.01884162798523903, 0.07914962619543076, 0.09385830163955688, -0.04665617272257805, 0.03399660065770149, 0.07377025485038757, -0.018386458978056908, -0.07645463198423386, 0.012185241095721722, -0.0006660542567260563, 0.005645453929901123, -0.06495901197195053, -0.0014495470095425844, 0.0247710682451725, 0.03892434388399124, 0.026410873979330063, -0.029815254732966423, -0.0012968922965228558, 0.04837330803275108, -0.02569597214460373, 0.008829226717352867, -0.0025547966361045837, 0.010916775092482567, -0.063718780875206, 0.018379032611846924, 0.01612679287791252, 0.020819928497076035, 0.07575475424528122, 0.02274637296795845, -0.009432915598154068, -0.08260111510753632, 0.04522153362631798, 0.01721986010670662, -0.07033195346593857, 0.008280467242002487, 0.06565847247838974, -0.02325124852359295, 0.0796581283211708, 0.05391284450888634, 0.002205007243901491, 0.015004188753664494, -0.028365151956677437, 0.0047717345878481865, -0.03405261039733887, -0.03574284538626671, -0.04949605092406273, -0.006164971273392439, 0.09183019399642944, 0.055202074348926544, -0.007378310896456242, 0.004720631521195173, -0.07487957924604416, 0.007573901209980249, 0.007839314639568329, -0.015455839224159718, -0.032290395349264145, -0.028225013986229897, -0.002128689317032695, 0.041756995022296906, -0.05163298919796944, -0.03779182583093643, -0.040212053805589676, -0.02844037115573883, 0.09935043007135391, 0.0013527498813346028, -0.02721499465405941, -0.010023681446909904, 0.04546583443880081, 0.01633504405617714, -0.10541430860757828, 0.019541893154382706, 0.02083553746342659, -0.02088160254061222, 0.0005800244980491698, -0.056715499609708786, -0.037806615233421326, -0.051103625446558, 0.013861567713320255, -0.03664742782711983, 0.04660734906792641, 0.022123510017991066, -0.05922272801399231, 0.10709862411022186, -0.002640276914462447, -0.024553511291742325, 0.026331724599003792, -0.042307786643505096, 0.006394365336745977, 0.0012927354546263814, 0.005888338666409254, -0.09104268252849579, -0.016587406396865845, 0.0324818454682827, 0.11981295049190521, -0.012366103939712048, -0.1101069226861, -0.031121132895350456, 0.004676502197980881, -0.004574916325509548, 0.03399446979165077, 0.013759341090917587, -0.03832785785198212, 0.07283952832221985, -0.03378891944885254, -0.031081901863217354, 0.05575297400355339, -0.08436748385429382, -0.02313748188316822, 0.009457556530833244, 0.010771802626550198, 0.03138868138194084, -0.042851321399211884, -0.05050966516137123, 0.11319239437580109, 0.016332736238837242, 0.018207674846053123, 0.039858244359493256, 0.04420679435133934, 0.02095605432987213, 0.0014355330495163798, -0.015834065154194832, -0.002080845180898905, 0.02219473011791706, -0.05652083083987236, 0.02274949662387371, 0.03742004930973053, -0.007915874943137169, -0.10408878326416016, -0.007735840510576963, -0.0918341651558876, 0.012240773066878319, -0.04057414457201958, 0.02783394046127796, 0.0021366761066019535, -0.04795539006590843, -0.043588243424892426, 0.09109534323215485, -0.003993346355855465, -0.020431386306881905, 0.03395863249897957, -0.04339461028575897, 0.08200262486934662, 0.021858492866158485, 0.014869987033307552, 0.011153156869113445, -0.09312553703784943, 0.0008399994112551212, -0.03276637941598892, 0.054696254432201385, 0.08276397734880447, -0.004741853568702936, -0.016742732375860214, -0.049003224819898605, 0.008863646537065506, 0.045063819736242294, -0.017658378928899765, 0.014466029591858387, 0.029708631336688995, -0.0010527304839342833, -0.03386305272579193, -0.0525117851793766, -0.049028173089027405, 0.023139525204896927, 0.02240883745253086, 0.0003104525967501104, 0.0005504146101884544, -0.07510668784379959, 0.027510739862918854, -0.013401666656136513, -0.06575172394514084, -0.07942324876785278, 0.04474567621946335, -0.011736017651855946, -0.0297738928347826, 0.002092017326503992, 0.02905009128153324, 0.03659956902265549, 0.03462795540690422, -0.057899437844753265, -0.05648837983608246, -0.04872694984078407, 0.0235727708786726, -0.012108628638088703, -0.01918289065361023, 0.022753922268748283, -0.05030929297208786, 0.037130359560251236, 0.005679580383002758, -0.0006358805694617331, 0.013238531537353992, 0.05782632529735565, -0.04348938912153244, 0.02888045273721218, -0.008866623975336552, -0.01729741506278515, -0.0006455579423345625, -0.01752377487719059, -0.01218114048242569, 0.042918287217617035, -0.00881953351199627, 0.028826700523495674, 0.022863440215587616, 0.06369920819997787, 0.0213494710624218, -0.005910440348088741, -0.0014065396972000599, 0.0291141364723444, 0.0398852713406086, -0.0018358114175498486, -0.04104882478713989, 0.02717043086886406, -0.021183835342526436, -0.008012564852833748, -0.010741079226136208, 0.017839724197983742, -0.0006493285181932151, -0.009542825631797314, 0.04651856794953346, 0.034293271601200104, 0.015044702216982841, -0.02406971901655197, 0.016770070418715477, -0.0037059381138533354, 0.09717752784490585, -0.09623095393180847, -0.0726974755525589, 0.029133517295122147, -0.006823258940130472, 0.019253572449088097, 0.0013059102930128574, 0.019215771928429604, -0.0164718609303236, 0.0005627795471809804, -0.012598223984241486, 0.024377377703785896, 0.03359172120690346, -0.004082309547811747, -0.0013039842015132308, -0.017515743151307106, 0.062108006328344345, 0.04192941635847092, -0.004027040209621191, 0.005750761833041906, -0.04327769950032234, 0.04756946489214897, 0.014159392565488815, 0.05503518506884575, 0.008541633374989033, -0.037377212196588516, 0.05889062210917473, 0.010138408280909061, 0.03314932435750961, 0.006506652571260929, -0.04579200968146324, -0.0781269520521164, -0.029396235942840576, -0.010751956142485142, -0.00536329485476017, -0.024426830932497978, -0.02561458945274353, -0.02220485359430313, 0.04232126474380493, -0.0006001534056849778, 0.013788268901407719, 0.034113746136426926, -0.04475126415491104, 0.02560180425643921, 0.00857432559132576, 0.025023140013217926, -0.006294864695519209, -0.005772310309112072, 0.018732164055109024, 0.043976981192827225, -0.02743453159928322, -0.015335324220359325, -0.00800467561930418, -0.017644813284277916, 0.04763924703001976, 0.018386706709861755, -0.03269752115011215, -0.02933754026889801, 0.008094200864434242, -0.013387713581323624, 0.006314774509519339, -0.019814753904938698, -0.009926402941346169, 0.02280873991549015, 0.01611558347940445, -0.026017187163233757, 0.036299653351306915, -0.0012240831274539232, 0.036455851048231125, 0.014302241615951061, 0.046723946928977966, -0.03170279785990715, 0.017963536083698273, 0.025663701817393303, 0.008937746286392212, -0.027350647374987602, 0.01831204444169998, -0.013555854558944702, -0.025922175496816635, 0.032645951956510544, 0.04470417648553848, -0.015673650428652763, 0.005363184027373791, -0.048476725816726685, 0.04403764754533768, 0.003003431484103203, 0.03818125277757645, -0.01983356848359108, 0.03516044467687607, 0.03189440816640854, 0.009428035467863083, -0.017972862347960472, -0.009066355414688587, -0.01473545003682375, -0.00697518652305007, 0.0008572800434194505, -0.025204934179782867, 0.013087830506265163, 0.004420247860252857, 0.03484337031841278, -0.03287278860807419, 0.013811860233545303, -0.04014117270708084, -0.0020980448462069035, -0.01243605837225914, 0.0019499433692544699, 0.0017090579494833946, -0.06310304254293442, 0.01666662096977234, 0.012630167417228222, 0.033207327127456665, -0.00689083244651556, -0.025417668744921684, 0.01565735414624214, 0.01108498964458704, 0.03384934365749359, -0.001270295470021665, -0.03855779767036438, -0.05515533685684204, -0.03944046050310135, -0.021619895473122597, 0.0011463320115581155, 0.01735939085483551, -0.029284195974469185, -0.007879838347434998, 0.03166970610618591, 0.028250232338905334, -0.009531999938189983, 0.013424316421151161, -0.04708517715334892, -0.027174336835741997, -0.02295943722128868, 0.02427736669778824, 0.027401117607951164, -0.012586025521159172, 0.02319994941353798, 0.06494324654340744, -0.013787361793220043, 0.02545846253633499, 0.011565716937184334, -0.06007639318704605, 0.0027238766197115183, 0.006992524489760399, 0.03498779237270355, -0.02940291166305542, 0.08013322204351425, -0.024878371506929398, -0.02836756594479084, 0.011376420967280865, -0.03601128235459328, 0.010630705393850803, 0.02377508580684662, 0.01366976834833622, -0.048994068056344986, 0.033978547900915146, 0.02129078097641468, -0.02138671651482582, -0.010694673284888268, 0.014673181809484959, -0.018723472952842712, 0.02293507754802704, -0.0057828910648822784, -0.011797952465713024, -0.06300389766693115, 0.0004074455064255744, 0.018418027088046074, 0.019399670884013176, 0.013915501534938812, -0.025425046682357788, 0.02210964448750019, -0.022373812273144722, -0.009309480898082256, 0.02397434040904045, 0.008161396719515324, -0.019118813797831535, 0.0063793836161494255, 0.023054134100675583, -0.030933087691664696, 0.02396792359650135, -0.04176300764083862, 0.02612985670566559, 0.003181008854880929, -0.025692572817206383, 0.04438087344169617, -0.012180342338979244, -0.015330586582422256, -0.001466298010200262, 0.039631109684705734, 0.036523040384054184, -0.0032345850486308336, 0.024090537801384926, 0.04218371957540512, -0.024780545383691788, 0.04081286862492561, -0.014281096868216991, 0.013117790222167969, 0.02329515479505062, 0.04240038990974426, 0.01234374288469553, -0.013011855073273182, 0.015840699896216393, 0.03162047266960144, 0.08981525897979736, -0.03552929311990738, -0.021916043013334274, -0.005024660844355822, 0.01602492295205593, -0.01231401413679123, 0.010553435422480106, 0.02843768149614334, -0.008425766602158546, 0.03693258762359619, 0.04150346666574478, -0.05500071868300438, 0.027947258204221725, 0.019118139520287514, -0.030820265412330627, -0.04921480640769005, 0.04283657297492027, 0.017295897006988525, 0.00750883761793375, -0.014486823230981827, 0.031222309917211533, -0.04563756659626961, 0.02198021300137043, 0.035911012440919876, -0.013645853847265244, -0.009799005463719368, 0.0413333922624588, 0.025784017518162727, 0.0333755798637867, 0.010267529636621475, 0.02288779802620411, -0.0061106388457119465, 0.005500383209437132, -0.002148732775822282, -0.019638312980532646, 0.008819706737995148, 0.04317541792988777, -0.024187233299016953, -0.01783657819032669, 0.030229348689317703, 0.01516727078706026, -0.030737094581127167, 0.042560819536447525, 0.01275109127163887, 0.016726016998291016, 0.014624126255512238, 0.008734254166483879, -0.025164073333144188, -0.012670159339904785, 0.06501561403274536, -0.03709401935338974, 0.008094915188848972, -0.043823208659887314, 0.032634902745485306, 0.009800265543162823, 0.04733414202928543, 0.0013883054489269853, 0.030225085094571114, 0.07002145051956177, -0.003495741169899702, -0.034358538687229156, -0.001700350665487349, -0.008919009007513523, -0.019529392942786217, 0.038771145045757294, 0.006687175948172808, -0.008317893370985985, 0.035913094878196716, 0.029354926198720932, -0.006103598978370428, 0.061284974217414856, -0.0028672765474766493, 0.028702126815915108, 0.03474454954266548, 0.019076554104685783, 0.04741380736231804, 0.04797925800085068, 0.02585778199136257, 0.01962963677942753, 0.025378143414855003, -0.0050402055494487286, 0.03032706305384636, -0.010835603810846806, -0.0034021264873445034, -0.015348606742918491, 0.03199125826358795, -0.011356429196894169, 0.004915433470159769, 0.006662851199507713, -0.002128445077687502, 0.011241868138313293, -0.0026327541563659906, -0.005374788772314787, -0.05053827911615372, 0.02467343956232071, -0.012634862214326859, 0.016515210270881653, 0.04797207564115524, -0.0739743709564209, 0.03175446018576622, 0.01016880664974451, 0.06909498572349548, 0.01781376264989376, 0.009487287141382694, 0.0347876213490963, 0.040968265384435654, 0.027070578187704086, -0.001661796704865992, -0.0239544864743948, 0.02805701270699501, 0.0005165977054275572, -0.007263184525072575, 0.01752583496272564, 0.05796174705028534, -0.018985217437148094, 0.016172075644135475, 0.03239283710718155, -0.009057979099452496, 0.029124092310667038, -0.008170661516487598, -0.006164857652038336, 0.018564781174063683, -0.047309767454862595, -0.013558807782828808, -0.015315761789679527, 0.009111227467656136, 0.017584657296538353, -0.05215900018811226, 0.012242352589964867, -0.01576622948050499, 0.014079625718295574, -0.028260955587029457, -0.0009642461081966758, -0.008220965042710304, -0.05126497149467468, 0.009686705656349659, 0.054161928594112396, -0.0018619006732478738, 0.002692489419132471, -0.03645447641611099, 0.0003454620309639722, 0.00957457721233368, 0.04126801714301109, -0.002898200647905469, 0.013616046868264675, 0.0006681289523839951, 0.032350800931453705, -0.05591196194291115, 0.03244806081056595, 0.018807630985975266, -0.008427505381405354, -0.03254510089755058, -0.0009538506274111569, -0.009734544903039932, -0.02800707519054413, 0.01771281659603119, -0.022929714992642403, 0.049151334911584854, -0.00210483162663877, 0.043907951563596725, 0.006118427496403456, 0.0031127564143389463, -0.04091819003224373, -0.03442101925611496, -0.03350682556629181, -0.07213441282510757, -0.011818182654678822, -0.007912722416222095, 0.0006683046813122928, -0.02075490728020668, -0.02931748889386654, -0.0018076210981234908, -0.04079771041870117, -0.027133816853165627, 0.026490436866879463, 0.024248111993074417, -0.0018190853297710419, -0.010968230664730072, -0.04429679363965988, 0.0464438833296299, -0.0044891806319355965, 0.0006957108271308243, 0.002626916626468301, 0.019513564184308052, 0.004585715942084789, -0.030493376776576042, 0.0017102410783991218, 0.00859597884118557, 0.004936864599585533, -0.009094487875699997, -0.026842117309570312, -0.003496932564303279, -0.0046320692636072636, 0.009131230413913727, -0.00679981242865324, 0.013021748512983322, 0.04050847515463829, 0.004241535905748606, 0.009502620436251163, -0.05360199883580208, 0.019428692758083344, 0.02851000241935253, 0.0002822318929247558, 0.038235586136579514, -0.0016542745288461447, 0.01993676647543907, -0.045245952904224396, 0.015325503423810005, -0.009998689405620098, 0.06932441890239716, -0.044754739850759506, -0.011892593465745449, -0.03765954449772835, 0.04177767038345337, -0.008379553444683552, -0.05029386281967163, -0.022225210443139076, -0.002121207071468234, -0.0017086622538045049, -0.03096741996705532, -0.026814095675945282, -0.01001743134111166, 0.05327024310827255, 0.010340808890759945, 0.003361818613484502, 0.023769818246364594, 0.012738236226141453, 0.0024272201117128134, -0.017938999459147453, -0.041304074227809906, -0.006167364772409201, 0.010282641276717186, 0.040723130106925964, -0.0013436762383207679, -0.0025504210498183966, -0.004806336015462875, -0.01921270787715912, -0.016040418297052383, -0.012319790199398994, -0.007569245528429747, 0.0018827542662620544, -0.021322544664144516, 0.025860324501991272, -0.02910776063799858, -0.0590587742626667, 0.015575936995446682, 0.008284610696136951, 0.019941061735153198, 0.005198198836296797, 0.00030225186492316425, -0.015200626105070114, 0.020089279860258102, -0.0009725965210236609, 0.03290018066763878, 0.03488641977310181, 0.033605124801397324, 0.03606681525707245, -0.007795157376676798, -0.004298719111829996 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
Local Self-Attention Local self-attention is the obvious solution to reducing the \(\mathcal{O}(n^2)\) memory bottleneck, allowing us to model longer sequences with a reduced computational cost. In local self-attention the input \( \mathbf{X} = \mathbf{X}{1:n} = \mathbf{x}{1}, \ldots, \mathbf{x}{n} \) is cut into \(n_{c}\) chunks: \( \mathbf{X} = \left[\mathbf{X}{1:l{c}}, \ldots, \mathbf{X}{(n{c} - 1) * l_{c} : n_{c} * l_{c}}\right] \) each of length config.local_chunk_length, i.e. \(l_{c}\), and subsequently global self-attention is applied on each chunk separately. Let's take our input sequence for \(n=16, d_h=3\) again for visualization: Assuming \(l_{c} = 4, n_{c} = 4\), chunked attention can be illustrated as follows: As can be seen, the attention operation is applied for each chunk \(\mathbf{X}{1:4}, \mathbf{X}{5:8}, \mathbf{X}{9:12}, \mathbf{X}{13:16}\) individually. The first drawback of this architecture becomes obvious: Some input vectors have no access to their immediate context, e.g. \(\mathbf{x}9\) has no access to \(\mathbf{x}{8}\) and vice-versa in our example. This is problematic because these tokens are not able to learn word representations that take their immediate context into account. A simple remedy is to augment each chunk with config.local_num_chunks_before, i.e. \(n_{p}\), chunks and config.local_num_chunks_after, i.e. \(n_{a}\), so that every input vector has at least access to \(n_{p}\) previous input vectors and \(n_{a}\) following input vectors. This can also be understood as chunking with overlap whereas \(n_{p}\) and \(n_{a}\) define the amount of overlap each chunk has with all previous chunks and following chunks. We denote this extended local self-attention as follows: $$\mathbf{Z}^{\text{loc}} = \left[\mathbf{Z}{1:l{c}}^{\text{loc}}, \ldots, \mathbf{Z}{(n{c} - 1) * l_{c} : n_{c} * l_{c}}^{\text{loc}}\right], $$ with $$\mathbf{Z}{l{c} * (i - 1) + 1 : l_{c} * i}^{\text{loc}} = \text{SelfAttn}(\mathbf{X}{l{c} * (i - 1 - n_{p}) + 1: l_{c} * (i + n_{a})})\left[n_{p} * l_{c}: -n_{a} * l_{c}\right], \forall i \in {1, \ldots, n_{c} }$$ Okay, this formula looks quite complicated. Let's make it easier. In Reformer's self-attention layers \(n_{a}\) is usually set to 0 and \(n_{p}\) is set to 1, so let's write down the formula again for \(i = 1\): $$\mathbf{Z}{1:l{c}}^{\text{loc}} = \text{SelfAttn}(\mathbf{X}{-l{c} + 1: l_{c}})\left[l_{c}:\right]$$ We notice that we have a circular relationship so that the first segment can attend the last segment as well. Let's illustrate this slightly enhanced local attention again. First, we apply self-attention within each windowed segment and keep only the central output segment. Finally, the relevant output is concatenated to \(\mathbf{Z}^{\text{loc}}\) and looks as follows. Note that local self-attention is implemented efficiently way so that no output is computed and subsequently "thrown-out" as shown here for illustration purposes by the red cross. It's important to note here that extending the input vectors for each chunked self-attention function allows each single output vector \( \mathbf{z}{i} \) of this self-attention function to learn better vector representations. E.g. each of the output vectors \( \mathbf{z}{5}^{\text{loc}}, \mathbf{z}{6}^{\text{loc}}, \mathbf{z}{7}^{\text{loc}}, \mathbf{z}{8}^{\text{loc}} \) can take into account all of the input vectors \( \mathbf{X}{1:8} \) to learn better representations. The gain in memory consumption is quite obvious: The \( \mathcal{O}(n^2) \) memory complexity is broken down for each segment individually so that the total asymptotic memory consumption is reduced to \( \mathcal{O}(n_{c} * l_{c}^2) = \mathcal{O}(n * l_{c}) \). This enhanced local self-attention is better than the vanilla local self-attention architecture but still has a major drawback in that every input vector can only attend to a local context of predefined size. For NLP tasks that do not require the transformer model to learn long-range dependencies between the input vectors, which include arguably e.g. speech recognition, named entity recognition and causal language modeling of short sentences, this might not be a big issue. Many NLP tasks do require the model to learn long-range dependencies, so that local self-attention could lead to significant performance degradation, e.g. * Question-answering: the model has to learn the relationship between the question tokens and relevant answer tokens which will most likely not be in the same local range * Multiple-Choice: the model has to compare multiple answer token segments to each other which are usually separated by a significant length * Summarization: the model has to learn the relationship between a long sequence of context tokens and a shorter sequence of summary tokens, whereas the relevant relationships between context and summary can most likely not be captured by local self-attention * etc... Local self-attention on its own is most likely not sufficient for the transformer model to learn the relevant relationships of input vectors (tokens) to each other. Therefore, Reformer additionally employs an efficient self-attention layer that approximates global self-attention, called LSH self-attention.
[ 0.08472848683595657, -0.011682447046041489, 0.05916215479373932, -0.03568662703037262, 0.013447953388094902, 0.0030921860598027706, -0.01487599778920412, 0.010358499363064766, -0.05189843848347664, -0.012789533473551273, -0.0769285187125206, 0.06280582398176193, -0.014083032496273518, -0.0033003014978021383, -0.050441842526197433, 0.08413777500391006, 0.10595816373825073, -0.04791468381881714, -0.03481261059641838, -0.04579997435212135, 0.022283416241407394, 0.03047369047999382, 0.11934204399585724, -0.008468447253108025, -0.04155135527253151, 0.017716996371746063, 0.002001547021791339, 0.04511391744017601, -0.028002144768834114, -0.012617450207471848, -0.11583228409290314, -0.0019518901826813817, 0.04608255252242088, -0.04293566942214966, 0.019459646195173264, -0.06264688819646835, -0.07735343277454376, 0.04975207522511482, 0.09643091261386871, -0.037641480565071106, 0.008461101911962032, -0.0032249221112579107, -0.07512138038873672, 0.027265191078186035, -0.036681462079286575, 0.01820708066225052, -0.12193436920642853, 0.1016637459397316, -0.09047648310661316, 0.004272545222193003, -0.05591553822159767, -0.0047416361048817635, -0.03595642000436783, 0.06979671120643616, -0.022921735420823097, 0.021276066079735756, -0.030592864379286766, -0.041605304926633835, 0.05987022817134857, 0.009045878425240517, 0.04325522109866142, 0.030026409775018692, 0.028298867866396904, 0.10102862119674683, -0.0033008051104843616, -0.0017103254795074463, 0.03597220778465271, -0.011454199440777302, -0.09093739837408066, -0.032071053981781006, 0.004186057485640049, -0.005854509770870209, -0.021906603127717972, -0.022971725091338158, -0.0009985105134546757, -0.04607250913977623, -0.03448981046676636, 0.03824955224990845, 0.016006775200366974, 0.01518563274294138, 0.06107854098081589, 0.04791335016489029, 0.09771670401096344, 0.023744279518723488, 0.026801006868481636, -0.031104937195777893, -0.022086046636104584, -0.11323583126068115, -0.03652689605951309, 0.051544930785894394, -0.07652384787797928, -0.11649110168218613, 0.0032813316211104393, -0.022785542532801628, 0.04360884055495262, -0.058121148496866226, 0.06326008588075638, 0.02795873023569584, -0.023028632625937462, 0.000674620212521404, -0.044990696012973785, -0.028219321742653847, 0.08186662197113037, -0.017012272030115128, -0.06951437145471573, 0.05600278452038765, 0.022366181015968323, -0.02873559296131134, -0.07638721913099289, -0.05049335956573486, -0.02537880651652813, 0.06212134659290314, 0.00239037093706429, 0.017643636092543602, -0.024555860087275505, -0.015214057639241219, 0.0003856894327327609, 0.02565643936395645, -0.04106413945555687, -0.019247185438871384, -0.0723322257399559, 0.09660058468580246, 0.12060245871543884, 0.042864251881837845, 0.0744422972202301, -0.0007293508388102055, 0.028833014890551567, -0.006966537330299616, -0.008736653253436089, -0.08152388781309128, -0.011293234303593636, 0.015530532225966454, 0.019959133118391037, -0.04661095142364502, -0.005152734462171793, -0.04703149199485779, 0.00317967077717185, 0.018428491428494453, -0.009683639742434025, -0.01851177029311657, -0.053255513310432434, -0.029438983649015427, 0.02628529816865921, 0.026657387614250183, 0.07703537493944168, -0.021984964609146118, -0.08552667498588562, 0.04197399318218231, 0.04726473614573479, 0.03868204727768898, 0.008378039114177227, -0.004909192677587271, -0.009046832099556923, -0.029080864042043686, 0.04188191145658493, 0.02159019559621811, 0.04782512038946152, -0.012621973641216755, -0.13188515603542328, 0.03586491942405701, -0.02946157567203045, 0.03622831404209137, -0.018084479495882988, 0.015575367026031017, 0.06346549093723297, -0.03587309271097183, 0.014887435361742973, -0.0015098863514140248, 0.0013963425299152732, 0.028205662965774536, 0.07071487605571747, -0.003622366115450859, 0.06925496459007263, -0.015610248781740665, -0.04841132462024689, 0.014904255978763103, -0.01929767243564129, 0.08102064579725266, -0.015213783830404282, 0.036495815962553024, 0.00664221728220582, -0.01182872336357832, 0.011639384552836418, 0.02245948277413845, 0.005033952184021473, -0.0443856306374073, 0.06070239841938019, -0.009574267081916332, -0.030180076137185097, -0.05744360014796257, -0.06286074966192245, 0.04683499038219452, 0.01888432167470455, -0.0485885888338089, 0.017694981768727303, 0.00871927011758089, -0.013882866129279137, 0.07924459129571915, 0.0857781246304512, 0.0792214497923851, 0.00815926305949688, 0.04562157392501831, 0.028344519436359406, 0.056577734649181366, 0.056269336491823196, -0.016809815540909767, -0.03666195645928383, -0.04377610236406326, 0.10827207565307617, -0.05209650471806526, -0.04120568558573723, -0.07747204601764679, 0.005586523097008467, -0.038639456033706665, -0.0489271804690361, -0.014645631425082684, 0.0292588509619236, 0.048706963658332825, -0.019410617649555206, 0.012403417378664017, 0.13062216341495514, -0.038057174533605576, -0.0485372357070446, 0.0172690749168396, -0.03521260619163513, 0.04029003158211708, 0.010675746947526932, -0.05258515849709511, 0.0579073391854763, -0.05148078501224518, -0.0012295222841203213, -0.07728403061628342, 0.020311560481786728, -0.01684274896979332, -0.002024704124778509, -0.0006442804588004947, -0.045791417360305786, 0.046711865812540054, 0.014955929480493069, -0.036901555955410004, -0.03469917178153992, -0.04874925687909126, -0.0005697122542187572, 0.021229444071650505, -0.019986014813184738, 0.021754702553153038, 0.004261501133441925, -0.014001780189573765, -0.041485607624053955, -0.0042414418421685696, -0.03433982655405998, 0.08045035600662231, -0.005109368357807398, -0.06094341352581978, -0.016444046050310135, 0.02228175476193428, -0.002433461369946599, -0.04499616101384163, -0.0021244953386485577, -0.020350083708763123, -0.027424318715929985, 0.043672382831573486, -0.0018521326128393412, -0.015304149128496647, -0.03578609973192215, -0.028604507446289062, 0.06258892267942429, 0.01596403308212757, 0.005731695797294378, -0.017399409785866737, -0.0059130992740392685, 0.0005042414995841682, -0.011565271764993668, 0.02288576401770115, 0.017536327242851257, 0.00312047335319221, 0.013151406310498714, -0.04831461235880852, -0.00781487487256527, -0.03503000736236572, -0.01796342246234417, 0.006966075859963894, 0.025051526725292206, -0.022037971764802933, 0.0066070593893527985, 0.0021138412412256002, -0.0025391094386577606, 0.03530897572636604, -0.03257540613412857, -0.024694152176380157, -0.01507763285189867, 0.009853832423686981, -0.02761206217110157, -0.025003233924508095, -0.034456245601177216, -0.006452035624533892, -0.014477587305009365, 0.000001930963207996683, -0.012277727015316486, -0.023066246882081032, 0.022127196192741394, -0.0013683105353266, 0.012980681844055653, -0.00015450936916749924, -0.014463170431554317, 0.01087866723537445, -0.014325588010251522, 0.07085006684064865, -0.09714613109827042, -0.061527449637651443, -0.005189946852624416, 0.027172401547431946, -0.00708363763988018, -0.04338407516479492, 0.01574031077325344, 0.05151364952325821, -0.031094294041395187, -0.046838413923978806, -0.006626608781516552, -0.02057870291173458, 0.002476389752700925, 0.019252192229032516, -0.005642208270728588, 0.024783071130514145, 0.01969354972243309, 0.0008017186191864312, 0.05726464465260506, 0.02133059687912464, 0.027062345296144485, 0.014624902978539467, -0.041109129786491394, -0.006197681650519371, -0.03568596765398979, -0.001480916398577392, -0.02915467880666256, 0.0161695946007967, 0.023676371201872826, -0.015095594339072704, -0.03509962186217308, -0.026078810915350914, 0.00535274064168334, -0.028667613863945007, -0.0585956908762455, -0.004492706619203091, 0.03151443228125572, -0.013371961191296577, 0.009067729115486145, 0.023852113634347916, 0.05578886717557907, 0.008449217304587364, 0.025550303980708122, 0.023877307772636414, 0.018652373924851418, -0.005474030040204525, -0.0022123593371361494, -0.040683940052986145, 0.036041438579559326, -0.041900552809238434, -0.0005537482211366296, -0.04840833321213722, 0.009397314861416817, 0.01676016114652157, -0.029989294707775116, -0.03781352564692497, -0.011036467738449574, 0.014563069678843021, 0.006354659795761108, -3.846163565413008e-7, -0.036468058824539185, 0.029462559148669243, 0.013561518862843513, 0.036159027367830276, -0.03479631617665291, -0.004054535645991564, 0.004988782107830048, 0.017794854938983917, -0.0036674232687801123, 0.024233920499682426, -0.01636473648250103, -0.016564246267080307, -0.003737090155482292, -0.00381897552870214, -0.01785786636173725, 0.029915740713477135, -0.004592037294059992, -0.01340476144105196, 0.08513199537992477, 0.03552630916237831, -0.006308248266577721, 0.017474450170993805, -0.07897686958312988, 0.026629919186234474, 0.004630546551197767, 0.01877753622829914, 0.030628418549895287, 0.02133556641638279, 0.0010306319454684854, 0.025854172185063362, -0.027369264513254166, 0.014671866782009602, 0.04101860150694847, -0.028662405908107758, -0.017896952107548714, 0.03988558426499367, 0.036523960530757904, -0.008483728393912315, 0.032991405576467514, 0.007504613138735294, 0.04331136867403984, -0.058535121381282806, 0.012966539710760117, 0.00813568290323019, -0.01011423859745264, -0.0006715456838719547, -0.05167743191123009, 0.024200664833188057, 0.03174211084842682, -0.0029049308504909277, 0.027368085458874702, -0.026586653664708138, 0.006557853892445564, 0.019595585763454437, 0.04324766993522644, -0.010768398642539978, -0.05897281691431999, -0.03410167992115021, -0.035910714417696, 0.014172958210110664, -0.02052004262804985, 0.019357798621058464, -0.002063108840957284, -0.012835673987865448, 0.037334080785512924, -0.012361172586679459, 0.021135980263352394, 0.024801695719361305, 0.009080518037080765, 0.002361608436331153, -0.04200172796845436, -0.00812701415270567, 0.0037840125150978565, 0.005573060363531113, 0.03824592009186745, 0.0005438412190414965, -0.03728155419230461, 0.00936662033200264, -0.005317913834005594, -0.03716623783111572, -0.017989717423915863, -0.03183677792549133, 0.004038795828819275, -0.0205112062394619, 0.001901191775687039, 0.0006232617306523025, -0.02088272199034691, 0.02829468622803688, -0.037012092769145966, 0.05657895654439926, 0.0704534724354744, 0.012630777433514595, -0.011547008529305458, 0.052937101572752, 0.0095663508400321, -0.011744416318833828, -0.0062425886280834675, -0.005761423613876104, 0.030395712703466415, 0.03860831260681152, -0.006756069138646126, -0.013937873765826225, -0.054830439388751984, 0.00424604769796133, 0.0076993051916360855, -0.020188933238387108, 0.01864941418170929, -0.028294699266552925, 0.002555110491812229, -0.03033788874745369, -0.03937830403447151, 0.013902626931667328, -0.031807590276002884, -0.04371855780482292, -0.001815681578591466, -0.009485522285103798, 0.016823267564177513, -0.009227612987160683, -0.021050618961453438, -0.013996676541864872, -0.04735584184527397, 0.01566265895962715, 0.03873661160469055, -0.0016426692018285394, 0.010328375734388828, 0.017276939004659653, 0.05516544356942177, 0.05506562441587448, -0.029979931190609932, 0.03622480109333992, 0.025001054629683495, -0.017598289996385574, -0.008552154526114464, 0.021158477291464806, 0.018940486013889313, -0.025141378864645958, 0.02044869214296341, 0.0008856418426148593, -0.011514812707901001, -0.00434835022315383, 0.044697850942611694, 0.006242218893021345, -0.024269739165902138, -0.06510297954082489, 0.0123022785410285, 0.02965542860329151, 0.0024446884635835886, -0.048982053995132446, -0.043046921491622925, -0.006061539985239506, 0.0013389912201091647, -0.012474412098526955, -0.056705400347709656, -0.005050890147686005, 0.01795133389532566, -0.038161393254995346, -0.0032506559509783983, 0.0000553595345991198, -0.007688693702220917, 0.00864206999540329, 0.05476074293255806, 0.0008997542900033295, -0.02137831039726734, 0.02082120254635811, -0.0012912075035274029, -0.02694210223853588, -0.024987895041704178, 0.02817903645336628, 0.031738221645355225, 0.012617314234375954, 0.05288372188806534, -0.007504179608076811, 0.020932789891958237, -0.0158734992146492, 0.022949865087866783, -0.018460597842931747, -0.039597876369953156, 0.05385956913232803, 0.009571040980517864, 0.033844031393527985, 0.006405260413885117, 0.029516518115997314, -0.05289698764681816, 0.05633792281150818, -0.036886151880025864, 0.010246887803077698, 0.056016068905591965, -0.010088744573295116, -0.004732652101665735, -0.00617767171934247, 0.04302927851676941, -0.04687745124101639, 0.008122848346829414, 0.02644071914255619, 0.002474926644936204, 0.0009145010262727737, 0.009926649741828442, -0.027545955032110214, 0.0404428094625473, 0.00600000424310565, 0.022777969017624855, -0.04009613022208214, -0.0012089622905477881, -0.029899410903453827, -0.02106962539255619, 0.016144299879670143, 0.02323991432785988, -0.03410084918141365, 0.006267561577260494, 0.08383651822805405, 0.05178729444742203, -0.04408028721809387, -0.033729083836078644, 0.01751025952398777, -0.030058935284614563, -0.006034134887158871, -0.004196849185973406, 0.026325413957238197, 0.006467626430094242, 0.021654579788446426, -0.010395676828920841, 0.018569286912679672, 0.04648812487721443, 0.02427617274224758, 0.009970195591449738, 0.027271796017885208, -0.018583867698907852, -0.007955309934914112, 0.024582814425230026, -0.002921843668445945, 0.004456837195903063, -0.007796129211783409, 0.02111833356320858, 0.0042458935640752316, -0.031596358865499496, 0.05414462089538574, 0.012441933155059814, -0.004216487519443035, 0.03547731414437294, -0.006528125610202551, 0.035942185670137405, 0.03970035910606384, -0.008629354648292065, -0.02468409202992916, -0.026462534442543983, 0.012500097043812275, -0.009766459465026855, 0.05004803091287613, -0.004509068094193935, -0.005358356516808271, -0.010688663460314274, 0.021248968318104744, 0.03537564352154732, 0.05399627238512039, 0.007870475761592388, -0.014446134679019451, -0.005099186673760414, -0.04886067658662796, -0.03929118067026138, 0.034221846610307693, 0.025568310171365738, -0.02858647145330906, 0.012916726060211658, 0.010045359842479229, 0.017459489405155182, -0.0010354408295825124, 0.017123203724622726, -0.026794815436005592, -0.009874684736132622, -0.025707148015499115, 0.0030579317826777697, 0.039002273231744766, -0.016222598031163216, 0.021931344643235207, -0.015520821325480938, 0.0181142445653677, 0.03358947113156319, 0.010351541452109814, -0.029723959043622017, -0.07980745285749435, -0.028873423114418983, 0.008720159530639648, -0.015495113097131252, 0.04294072464108467, -0.01206158846616745, -0.035538580268621445, 0.055484697222709656, 0.025340836495161057, -0.036454424262046814, 0.05411604419350624, 0.021840687841176987, 0.0005767160910181701, -0.03965769708156586, -0.005361335817724466, -0.007561598438769579, -0.007592895999550819, 0.049180276691913605, -0.008125243708491325, 0.037873249500989914, 0.017513636499643326, 0.003843504237011075, 0.04250888526439667, -0.012883507646620274, -0.027711689472198486, -0.04801303520798683, 0.023361019790172577, -0.019323250278830528, -0.006670880597084761, -0.03025033511221409, -0.006956914439797401, 0.011990738101303577, -0.011997457593679428, -0.004373829811811447, -0.02441035397350788, -0.02132345549762249, -0.037591803818941116, 0.049235422164201736, 0.02568206749856472, 0.0002968954504467547, -0.014985054731369019, 0.015704939141869545, -0.013229046948254108, 0.036570955067873, 0.04366087168455124, 0.041934818029403687, 0.038165703415870667, -0.01090221107006073, 0.014740998856723309, -0.006203404627740383, 0.02220790833234787, -0.045851849019527435, -0.053733207285404205, -0.01857965998351574, 0.01266116090118885, -0.009808205999433994, 0.025855207815766335, -0.03832562640309334, 0.07681822776794434, -0.010840440168976784, -0.011008326895534992, -0.051598940044641495, -0.025706510990858078, 0.03808271139860153, -0.03323698788881302, 0.03292806074023247, 0.027169350534677505, 0.005288571584969759, -0.01427090261131525, -0.016890794038772583, 0.021673372015357018, 0.03868648782372475, 0.011978164315223694, 0.019664468243718147, -0.0029588788747787476, -0.020801689475774765, -0.01929592341184616, -0.03857884183526039, -0.007686126511543989, -0.009231260977685452, 0.013209445402026176, 0.030546072870492935, 0.0007815695716999471, 0.024942658841609955, 0.04420241713523865, -0.012073851190507412, -0.005343145690858364, -0.021343989297747612, 0.046825915575027466, 0.0011776195606216788, -0.03392352908849716, -0.0013632095651701093, 0.023205934092402458, 0.03547171130776405, 0.06852437555789948, 0.012929234653711319, 0.040214795619249344, 0.03350156173110008, 0.038570694625377655, -0.025553831830620766, 0.043063703924417496, -0.0014376029139384627, -0.05719403922557831, 0.01785474829375744, 0.04095851629972458, -0.02022732049226761, -0.02122221514582634, -0.023630768060684204, 0.014286454766988754, 0.022024022415280342, 0.0059515186585485935, -0.006358323153108358, 0.043808531016111374, -0.027302032336592674, 0.0197764802724123, -0.00842911098152399, 0.007077139336615801, -0.021766312420368195, 0.05490334704518318, -0.0344645231962204, 0.036369189620018005 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
Recap Global Self-Attention The core of every Transformer model is the self-attention layer. To recap the conventional self-attention layer, which we refer to here as the global self-attention layer, let us assume we apply a transformer layer on the embedding vector sequence \(\mathbf{X} = \mathbf{x}1, \ldots, \mathbf{x}_n\) where each vector \(\mathbf{x}{i}\) is of size config.hidden_size, i.e. \(d_h\). In short, a global self-attention layer projects \(\mathbf{X}\) to the query, key and value matrices \(\mathbf{Q}, \mathbf{K}, \mathbf{V}\) and computes the output \(\mathbf{Z}\) using the softmax operation as follows: \(\mathbf{Z} = \text{SelfAttn}(\mathbf{X}) = \text{softmax}(\mathbf{Q}\mathbf{K}^T) \mathbf{V}\) with \(\mathbf{Z}\) being of dimension \(d_h \times n\) (leaving out the key normalization factor and self-attention weights \(\mathbf{W}^{O}\) for simplicity). For more detail on the complete transformer operation, see the illustrated transformer. Visually, we can illustrate this operation as follows for \(n=16, d_h=3\): Note that for all visualizations batch_size and config.num_attention_heads is assumed to be 1. Some vectors, e.g. \(\mathbf{x_3}\) and its corresponding output vector \(\mathbf{z_3}\) are marked so that LSH self-attention can later be better explained. The presented logic can effortlessly be extended for multi-head self-attention (config.num_attention_{h}eads > 1). The reader is advised to read the illustrated transformer as a reference for multi-head self-attention. Important to remember is that for each output vector \(\mathbf{z}{i}\), the whole input sequence \(\mathbf{X}\) is processed. The tensor of the inner dot-product \(\mathbf{Q}\mathbf{K}^T\) has an asymptotic memory complexity of \(\mathcal{O}(n^2)\) which usually represents the memory bottleneck in a transformer model. This is also the reason why bert-base-cased has a config.max_position_embedding_size of only 512.
[ 0.04481486976146698, -0.047732505947351456, 0.061583906412124634, -0.03437037020921707, 0.022489866241812706, 0.052320681512355804, -0.03484846279025078, 0.049371205270290375, 0.012501017190515995, 0.004942636471241713, -0.10263190418481827, 0.08344445377588272, -0.0023346301168203354, 0.045253414660692215, -0.03617560490965843, 0.06268811225891113, 0.05844399705529213, -0.0007406891672872007, -0.08876235783100128, -0.0284871868789196, 0.001488389796577394, -0.08048809319734573, 0.06927672028541565, 0.0008843051618896425, -0.04166574403643608, -0.028162846341729164, 0.006815944332629442, 0.024694137275218964, -0.01485873106867075, 0.05108647793531418, -0.11724160611629486, -0.024353334680199623, 0.04336287081241608, -0.034475795924663544, 0.0073675368912518024, -0.028818830847740173, -0.13746362924575806, 0.017935380339622498, 0.04832366108894348, -0.10129673779010773, 0.011181659065186977, 0.0007520483341068029, -0.12040790170431137, 0.00612559262663126, 0.00018595664005260915, -0.038140248507261276, -0.171359583735466, 0.10074692964553833, -0.07202465832233429, 0.002521214075386524, -0.023208776488900185, 0.04855114221572876, -0.03398699313402176, 0.024196386337280273, 0.0014625497860834002, 0.046892717480659485, -0.003302213503047824, -0.01572292670607567, -0.0016194757772609591, -0.03242960572242737, 0.06416773051023483, 0.02794817090034485, 0.02711799181997776, 0.10516831278800964, 0.017041122540831566, -0.039559539407491684, 0.029208919033408165, -0.023848306387662888, -0.06755012273788452, 0.00888073816895485, -0.04110947623848915, -0.009552234783768654, -0.016997091472148895, -0.03921876102685928, -0.04062959551811218, 0.002184143755584955, 0.028803342953324318, 0.037420932203531265, 0.027984069660305977, -0.0443355068564415, 0.0532858669757843, 0.02830500900745392, 0.05885064974427223, 0.05273756384849548, 0.002039872109889984, -0.006815335713326931, 0.015761418268084526, -0.03108426183462143, -0.055130746215581894, 0.04728420078754425, -0.0739125907421112, -0.1350216269493103, 0.010036383755505085, -0.03373336046934128, 0.057870253920555115, -0.05738803371787071, 0.004782381933182478, -0.028901349753141403, -0.042351920157670975, -0.013707650825381279, -0.024865079671144485, 0.03198796883225441, 0.09227252751588821, -0.0441645123064518, -0.04074440151453018, -0.008364053443074226, 0.006534982938319445, -0.06655000895261765, -0.05785055458545685, 0.017782574519515038, -0.0445682518184185, 0.003425569273531437, 0.012637448497116566, 0.020065922290086746, -0.018746761605143547, 0.03518814221024513, 0.013546016998589039, -0.030792728066444397, -0.00041865461389534175, 0.02802821435034275, -0.02511182799935341, 0.07926870137453079, 0.06379438191652298, -0.009869961068034172, 0.07390914112329483, -0.005297866649925709, -0.022305263206362724, 0.03536209464073181, -0.022725040093064308, -0.03794098272919655, 0.024214839562773705, -0.026064585894346237, 0.07719310373067856, -0.01723276637494564, -0.0632672980427742, -0.0815252885222435, 0.030434519052505493, 0.02225698158144951, -0.017355969175696373, -0.026469958946108818, -0.06492235511541367, -0.046591851860284805, 0.0034216251224279404, -0.030436353757977486, 0.055044014006853104, -0.038358334451913834, -0.08944668620824814, 0.07048966735601425, 0.05813349410891533, 0.07199282944202423, 0.017387207597494125, 0.002735574496909976, -0.021111968904733658, -0.06785362213850021, 0.0480450801551342, -0.002883129520341754, 0.0580308623611927, -0.06367368996143341, -0.10711513459682465, -0.011982046067714691, -0.019396211951971054, 0.008546223863959312, -0.018508370965719223, 0.05437596142292023, 0.01985708810389042, -0.05277109146118164, 0.013118220493197441, -0.019611017778515816, 0.02185405045747757, 0.024386953562498093, 0.0019302918808534741, 0.01785443164408207, 0.03527342155575752, -0.024736741557717323, -0.05577545240521431, 0.008063550107181072, -0.006185975857079029, 0.10263858735561371, 0.0034561112988740206, 0.04649036005139351, -0.04224613308906555, -0.0347975455224514, -0.020958896726369858, 0.04065917804837227, 0.020669439807534218, -0.028696367517113686, 0.012117743492126465, -0.002730622421950102, -0.05201054736971855, -0.002709093503654003, -0.0796668604016304, 0.03176603093743324, 0.018428858369588852, -0.03733469173312187, 0.03238878771662712, -0.012526866048574448, -0.051020797342061996, 0.049661166965961456, 0.05876116454601288, 0.02897571213543415, 0.06325038522481918, 0.011684245429933071, 0.023923374712467194, 0.010706921108067036, 0.022782929241657257, 0.003904959885403514, -0.04271726310253143, -0.008124862797558308, 0.05516176298260689, -0.05221541225910187, -0.033865638077259064, -0.0886743813753128, -0.002838854445144534, -0.018011126667261124, -0.02952585555613041, -0.04502108693122864, -0.010565496049821377, 0.06396248936653137, -0.023323552682995796, 0.030674925073981285, 0.13157415390014648, 0.027520207688212395, -0.05659150332212448, -0.004993334878236055, -0.022889424115419388, -0.023871421813964844, 0.044502049684524536, -0.029104067012667656, 0.013656055554747581, -0.05982737988233566, 0.013603784143924713, -0.06023150682449341, 0.0443943589925766, 0.002134458627551794, -0.027076879516243935, -0.015385996550321579, -0.002228217665106058, 0.03240267187356949, 0.020093396306037903, -0.04070666804909706, -0.013371267355978489, 0.021321868523955345, 0.0264841727912426, 0.006462693680077791, -0.027865443378686905, 0.04647897928953171, 0.023935958743095398, 0.029079394415020943, -0.09194772690534592, 0.012617825530469418, -0.09235444664955139, 0.07942097634077072, -0.000868557021021843, -0.0815790668129921, 0.03321754187345505, 0.018045343458652496, 0.006913460325449705, -0.04491586983203888, -0.02016885206103325, -0.014950359240174294, -0.001294956193305552, 0.021873150020837784, -0.031178316101431847, -0.026746157556772232, -0.02909756824374199, -0.03283102437853813, 0.037725210189819336, 0.038851119577884674, 0.015552980825304985, 0.02468227967619896, -0.002273152582347393, -0.008969780057668686, -0.008772164583206177, -0.014296566136181355, -0.00157751957885921, 0.006600836757570505, 0.047787878662347794, -0.03135890141129494, 0.01794224977493286, -0.03043222986161709, -0.017494233325123787, 0.02597079798579216, 0.04501210153102875, 0.0004734813410323113, 0.0014659767039120197, -0.02124452404677868, -0.01108832098543644, 0.00789290014654398, -0.008656373247504234, -0.023628858849406242, -0.010376131162047386, 0.040137600153684616, 0.009534955024719238, -0.021268390119075775, -0.020898275077342987, 0.023191718384623528, -0.007818772457540035, -0.015720749273896217, -0.0020445063710212708, 0.033553313463926315, 0.011361109092831612, 0.011238133534789085, 0.012547024525702, 0.009698453359305859, -0.020518051460385323, 0.03683056682348251, 0.0017952760681509972, 0.0704643726348877, -0.10155350714921951, -0.05225846543908119, -0.020356440916657448, 0.028931716457009315, 0.008286794647574425, -0.05625314265489578, 0.034760333597660065, 0.05274420231580734, -0.01163227017968893, -0.008718841709196568, -0.008706610649824142, -0.058185070753097534, 0.015423153527081013, 0.033483486622571945, 0.0053876168094575405, 0.033983223140239716, 0.019653158262372017, -0.010196392424404621, 0.05849718675017357, 0.000018852668290492147, 0.032517723739147186, 0.02151520550251007, -0.022513357922434807, 0.0056209866888821125, -0.0034380622673779726, -0.01188388280570507, 0.027160409837961197, 0.006514031905680895, 0.04407114535570145, 0.009745271876454353, -0.0074302866123616695, -0.021636515855789185, -0.022208429872989655, 0.02948104776442051, -0.03778368607163429, 0.0012851373758167028, 0.03896719589829445, 0.0014272695407271385, 0.01988818496465683, 0.06749475747346878, 0.03062996082007885, 0.005401708651334047, 0.00008217206050176173, 0.030670562759041786, 0.057121336460113525, -0.028820233419537544, 0.022846831008791924, -0.05966980382800102, 0.0016361422603949904, -0.04368260130286217, -0.026153329759836197, -0.03507339209318161, 0.0006117437733337283, -0.0002571807708591223, -0.026715414598584175, 0.000018083705072058365, 0.019126927480101585, 0.009413900785148144, 0.015060880221426487, -0.013977020978927612, -0.0380588136613369, 0.029406582936644554, -0.01616615429520607, -0.006464818026870489, -0.03768584504723549, 0.04122073948383331, 0.01053204108029604, 0.005638104863464832, -0.008271845057606697, 0.01294617261737585, -0.008240698836743832, -0.003035204717889428, -0.01865299418568611, -0.0018707802519202232, -0.03494757413864136, 0.03925925865769386, 0.007803034037351608, 0.004236437380313873, 0.09050647914409637, 0.011039878241717815, 0.011372790671885014, 0.00042157352436333895, -0.026505932211875916, 0.017367811873555183, -0.01406484842300415, 0.01545326691120863, 0.04442840814590454, -0.00808284804224968, 0.04500928148627281, 0.01355000026524067, 0.013199199922382832, -0.00920090451836586, 0.027274494990706444, -0.021418754011392593, 0.015165150165557861, 0.03762441873550415, 0.0014318493194878101, -0.002590291202068329, 0.04318838194012642, 0.014040510170161724, 0.06356782466173172, -0.04127674922347069, 0.011574383825063705, 0.017554152756929398, -0.00364392576739192, 0.012529049068689346, -0.059306006878614426, 0.0016339111607521772, 0.026993554085493088, 0.01730753853917122, 0.029102537781000137, -0.010151699185371399, -0.011677160859107971, 0.006342191249132156, 0.026199640706181526, 0.01159148570150137, -0.045327335596084595, -0.042649928480386734, -0.035100579261779785, 0.014677620492875576, -0.004565315321087837, 0.016721894964575768, -0.00837027095258236, -0.022424597293138504, 0.024736518040299416, -0.0008047159644775093, 0.06128557398915291, 0.048104800283908844, -0.0059838006272912025, -0.014426883310079575, -0.02065129764378071, 0.004456282127648592, 0.03127594664692879, 0.0023322743363678455, 0.029914911836385727, 0.051171619445085526, -0.031229168176651, 0.01817089319229126, -0.017067020758986473, -0.03730544447898865, -0.047340452671051025, 0.021396400406956673, 0.03905923292040825, -0.02477962151169777, 0.014621950685977936, -0.023302998393774033, -0.027782157063484192, 0.0213150791823864, -0.04494326934218407, 0.014530032873153687, 0.07680682092905045, 0.004528549034148455, -0.030013471841812134, 0.0510256290435791, 0.035810936242341995, 0.010430526919662952, 0.04237769916653633, 0.014834127388894558, -0.01242564246058464, 0.01163462270051241, 0.019603798165917397, 0.004686216823756695, -0.052319884300231934, 0.03016892820596695, 0.05181729421019554, 0.015700723975896835, -0.01246637012809515, -0.06005995348095894, 0.0352199487388134, 0.012773384340107441, -0.03044077567756176, -0.016992997378110886, -0.02128589153289795, -0.04401357099413872, -0.039904408156871796, 0.01685374602675438, -0.03799493983387947, -0.019858798012137413, 0.030430924147367477, -0.00759464967995882, -0.012759538367390633, 0.0213688425719738, -0.003747685579583049, -0.0081892479211092, -0.004062708932906389, 0.0390125997364521, 0.050577253103256226, 0.04810594394803047, -0.03969278559088707, 0.01618710719048977, 0.04126884415745735, -0.017082862555980682, -0.005924527067691088, 0.027059534564614296, 0.016322553157806396, 0.0016659393440932035, 0.04944401979446411, 0.025402216240763664, -0.0373658686876297, 0.010464316233992577, 0.019759995862841606, 0.046951618045568466, -0.03291231393814087, -0.04796053096652031, 0.007146365009248257, -0.000446441990789026, -0.029556915163993835, -0.007389971055090427, -0.008780082687735558, -0.03416718542575836, 0.03355555608868599, 0.013146652840077877, -0.03932257369160652, -0.02043895237147808, 0.0217446181923151, -0.0622909739613533, -0.010919500142335892, 0.011027837172150612, 0.01916249841451645, 0.03911339119076729, 0.027030114084482193, 0.00787094421684742, 0.016034578904509544, 0.05587630718946457, 0.008241339586675167, -0.05061407387256622, -0.01984514109790325, -0.010105853900313377, 0.004012799821794033, -0.013086563907563686, 0.04130289703607559, -0.006195736117660999, -0.0076749916188418865, -0.03486385568976402, -0.00654397439211607, -0.03574700281023979, -0.06913114339113235, 0.06546653807163239, 0.02559087611734867, -0.004710708744823933, 0.000848541734740138, 0.026246322318911552, -0.02864443138241768, 0.026728279888629913, -0.029847119003534317, 0.02924313209950924, 0.07328618317842484, -0.05182887613773346, 0.01857437938451767, -0.0024499138817191124, 0.056075744330883026, -0.017988543957471848, -0.010322998277842999, 0.026453962549567223, 0.004095260053873062, 0.020759087055921555, -0.0056023383513092995, 0.004591313656419516, 0.042074114084243774, 0.024484457448124886, -0.010044719092547894, -0.020677559077739716, -0.007730059791356325, 0.0011900803074240685, -0.03671295568346977, 0.04397238790988922, -0.0018534199334681034, -0.009370774962008, -0.016614042222499847, 0.04018629714846611, 0.01622002013027668, 0.004226739518344402, -0.01431342214345932, 0.005144015420228243, -0.06481616199016571, -0.020044540986418724, 0.0252070315182209, 0.03888401389122009, 0.026664653792977333, 0.020343584939837456, -0.0016807160573080182, 0.004332247190177441, 0.09031271934509277, 0.019601689651608467, 0.020174654200673103, -0.015537524595856667, 0.010132906027138233, -0.005623797886073589, 0.026828158646821976, -0.013966219499707222, 0.03735775500535965, 0.028576264157891273, 0.03301548212766647, -0.0037757332902401686, -0.030558884143829346, 0.033148881047964096, -0.009672826156020164, -0.027616044506430626, 0.04803735017776489, -0.01924697495996952, 0.033952075988054276, 0.027311235666275024, 0.026001596823334694, 0.019783897325396538, 0.02689129114151001, 0.019711263477802277, 0.014624476432800293, 0.029646610841155052, 0.005637285765260458, -0.000021842441128683276, 0.022054940462112427, 0.017193438485264778, -0.004075936507433653, 0.06619976460933685, -0.004285959992557764, -0.052086442708969116, 0.0035273677203804255, -0.0554022379219532, -0.03360208123922348, -0.004017591942101717, 0.03953307494521141, -0.04882176220417023, 0.003102951915934682, 0.0048127430491149426, -0.023232316598296165, -0.021187836304306984, 0.044553350657224655, -0.02394913323223591, -0.011508922092616558, -0.027257902547717094, -0.0009309214656241238, 0.03863753378391266, 0.008695567026734352, 0.008916596882045269, -0.006772169843316078, -0.006380254868417978, 0.022326137870550156, 0.022944465279579163, -0.010487987659871578, -0.04956720396876335, -0.06993866711854935, 0.006794078275561333, -0.016286930069327354, 0.022036802023649216, 0.008488073945045471, -0.04645572975277901, 0.044639069586992264, 0.01704271323978901, -0.022360293194651604, 0.0537550188601017, -0.0033576723653823137, -0.002947994042187929, -0.04068814590573311, -0.025683963671326637, 0.005360054783523083, 0.011382057331502438, 0.00943711306899786, 0.004479053430259228, 0.023536531254649162, -0.005745069123804569, -0.004315485712140799, 0.03970540314912796, 0.02351432852447033, 0.0012615987798199058, -0.00811920128762722, 0.041043538600206375, 0.005655704997479916, -0.01060534082353115, 0.009325195103883743, -0.017026100307703018, -0.024787873029708862, 0.013946660794317722, 0.015172207728028297, -0.004024128429591656, -0.017072346061468124, 0.011543188244104385, 0.02677827514708042, 0.007757571060210466, -0.01859842613339424, -0.0007074284367263317, 0.02495555207133293, -0.005868927575647831, 0.04208903759717941, 0.05259387195110321, 0.06399492919445038, 0.03529360517859459, -0.026741839945316315, -0.0047547644935548306, 0.02416730672121048, 0.039689887315034866, -0.03238346800208092, -0.03950101137161255, -0.018357427790760994, 0.03157170116901398, 0.04634852334856987, 0.013264955952763557, -0.038365017622709274, 0.017640655860304832, -0.07041752338409424, -0.04907124489545822, 0.0035811306443065405, -0.007887545973062515, 0.05049683526158333, -0.01856580190360546, 0.028801409527659416, 0.018799714744091034, 0.00020227917411830276, -0.03923918679356575, -0.02038484625518322, -0.01650187186896801, 0.04321599379181862, 0.014156044460833073, 0.018839946016669273, -0.028935298323631287, -0.031431443989276886, -0.032180264592170715, -0.047648925334215164, 0.024035107344388962, 0.010049697011709213, 0.002789027290418744, -0.00384344719350338, -0.012478655204176903, 0.01019788347184658, 0.04749138653278351, 0.011795898899435997, 0.019065286964178085, -0.024089910089969635, 0.033973753452301025, 0.002449151361361146, -0.03991175442934036, -0.00509593915194273, 0.034240398555994034, 0.05181335657835007, 0.0314396470785141, 0.011028296314179897, 0.05014553666114807, 0.011689466424286366, 0.013343190774321556, -0.003539710072800517, -0.020972348749637604, -0.025856951251626015, -0.0439176969230175, 0.012149972841143608, 0.012192217633128166, -0.02953975647687912, -0.0515422560274601, -0.026048297062516212, 0.014146716333925724, 0.027426503598690033, 0.010724246501922607, -0.021833470091223717, 0.013351540081202984, -0.03912459313869476, 0.01961345411837101, -0.0012578072492033243, 0.02832057885825634, -0.01953509822487831, 0.01344087440520525, -0.0048497337847948074, 0.010173840448260307 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
LSH Self-Attention Alright, now that we have understood how local self-attention works, we can take a stab at the probably most innovative piece of Reformer: Locality sensitive hashing (LSH) Self-Attention. The premise of LSH self-attention is to be more or less as efficient as local self-attention while approximating global self-attention. LSH self-attention relies on the LSH algorithm as presented in Andoni et al (2015), hence its name. The idea behind LSH self-attention is based on the insight that if \(n\) is large, the softmax applied on the \(\mathbf{Q}\mathbf{K}^T\) attention dot-product weights only very few value vectors with values significantly larger than 0 for each query vector. Let's explain this in more detail. Let \(\mathbf{k}{i} \in \mathbf{K} = \left[\mathbf{k}_1, \ldots, \mathbf{k}_n \right]^T\) and \(\mathbf{q}{i} \in \mathbf{Q} = \left[\mathbf{q}1, \ldots, \mathbf{q}_n\right]^T\) be the key and query vectors. For each \(\mathbf{q}{i}\), the computation \(\text{softmax}(\mathbf{q}{i}^T \mathbf{K}^T)\) can be approximated by using only those key vectors of \(\mathbf{k}{j}\) that have a high cosine similarity with \(\mathbf{q}{i}\). This owes to the fact that the softmax function puts exponentially more weight on larger input values. So far so good, the next problem is to efficiently find the vectors that have a high cosine similarity with \(\mathbf{q}{i}\) for all \(i\). First, the authors of Reformer notice that sharing the query and key projections: \(\mathbf{Q} = \mathbf{K}\) does not impact the performance of a transformer model \({}^1\). Now, instead of having to find the key vectors of high cosine similarity for each query vector \(q_i\), only the cosine similarity of query vectors to each other has to be found. This is important because there is a transitive property to the query-query vector dot product approximation: If \(\mathbf{q}{i}\) has a high cosine similarity to the query vectors \(\mathbf{q}{j}\) and \(\mathbf{q}{k}\), then \(\mathbf{q}{j}\) also has a high cosine similarity to \(\mathbf{q}{k}\). Therefore, the query vectors can be clustered into buckets, such that all query vectors that belong to the same bucket have a high cosine similarity to each other. Let's define \(C{m}\) as the mth set of position indices, such that their corresponding query vectors are in the same bucket: \(C_{m} = { i | \text{ s.t. } \mathbf{q}{i} \in \text{mth cluster}}\) and config.num_buckets, i.e. \(n{b}\), as the number of buckets. For each set of indices \(C_{m}\), the softmax function on the corresponding bucket of query vectors \(\text{softmax}(\mathbf{Q}{i \in C{m}} \mathbf{Q}^T_{i \in C_{m}})\) approximates the softmax function of global self-attention with shared query and key projections \(\text{softmax}(\mathbf{q}{i}^T \mathbf{Q}^T)\) for all position indices \(i\) in \(C{m}\). Second, the authors make use of the LSH algorithm to cluster the query vectors into a predefined number of buckets \(n_{b}\). The LSH algorithm is an ideal choice here because it is very efficient and is an approximation of the nearest neighbor algorithm for cosine similarity. Explaining the LSH scheme is out-of-scope for this notebook, so let's just keep in mind that for each vector \(\mathbf{q}{i}\) the LSH algorithm attributes its position index \(i\) to one of \(n{b}\) predefined buckets, i.e. \(\text{LSH}(\mathbf{q}{i}) = m\) with \(i \in {1, \ldots, n}\) and \(m \in {1, \ldots, n{b}}\). Visually, we can illustrate this as follows for our original example: Third, it can be noted that having clustered all query vectors in \(n_{b}\) buckets, the corresponding set of indices \(C_{m}\) can be used to permute the input vectors \(\mathbf{x}1, \ldots, \mathbf{x}_n\) accordingly \({}^2\) so that shared query-key self-attention can be applied piecewise similar to local attention. Let's clarify with our example input vectors \(\mathbf{X} = \mathbf{x}_1, ..., \mathbf{x}{16}\) and assume config.num_buckets=4 and config.lsh_chunk_length = 4. Looking at the graphic above we can see that we have assigned each query vector \( \mathbf{q}1, \ldots, \mathbf{q}{16} \) to one of the clusters \( \mathcal{C}{1}, \mathcal{C}{2}, \mathcal{C}{3}, \mathcal{C}{4} \) . If we now sort the corresponding input vectors \( \mathbf{x}1, \ldots, \mathbf{x}{16} \) accordingly, we get the following permuted input \( \mathbf{X'} \): The self-attention mechanism should be applied for each cluster individually so that for each cluster \( \mathcal{C}m \) the corresponding output is calculated as follows: \( \mathbf{Z}^{\text{LSH}}{i \in \mathcal{C}m} = \text{SelfAttn}{\mathbf{Q}=\mathbf{K}}(\mathbf{X}{i \in \mathcal{C}_m}) \). Let's illustrate this again for our example. As can be seen, the self-attention function operates on different sizes of matrices, which is suboptimal for efficient batching in GPU and TPU. To overcome this problem, the permuted input can be chunked the same way it is done for local attention so that each chunk is of size config.lsh_chunk_length. By chunking the permuted input, a bucket might be split into two different chunks. To remedy this problem, in LSH self-attention each chunk attends to its previous chunk config.lsh_num_chunks_before=1 in addition to itself, the same way local self-attention does (config.lsh_num_chunks_after is usually set to 0). This way, we can be assured that all vectors in a bucket attend to each other with a high probability \({}^3\). All in all for all chunks \( k \in {1, \ldots, n{c}} \), LSH self-attention can be noted down as follows: $$ \mathbf{Z'}{l{c} * k + 1:l_{c} * (k + 1)}^{\text{LSH}} = \text{SelfAttn}{\mathbf{Q} = \mathbf{K}}(\mathbf{X'}{l_{c} * k + 1): l_{c} * (k + 1)})\left[l_{c}:\right] $$ with \(\mathbf{X'}\) and \( \mathbf{Z'} \) being the input and output vectors permuted according to the LSH algorithm. Enough complicated formulas, let's illustrate LSH self-attention. The permuted vectors \(\mathbf{X'}\) as shown above are chunked and shared query key self-attention is applied to each chunk. Finally, the output \(\mathbf{Z'}^{\text{LSH}}\) is reordered to its original permutation. One important feature to mention here as well is that the accuracy of LSH self-attention can be improved by running LSH self-attention config.num_hashes, e.g. \(n_{h} \) times in parallel, each with a different random LSH hash. By setting config.num_hashes > 1, for each output position \( i \), multiple output vectors \( \mathbf{z}^{\text{LSH}, 1}{i}, \ldots, \mathbf{z}^{\text{LSH}, n{h}}{i} \) are computed and subsequently merged: \( \mathbf{z}^{\text{LSH}}{i} = \sum_k^{n_{h}} \mathbf{Z}^{\text{LSH}, k}{i} * \text{weight}^k_i \). The \( \text{weight}^k_i \) represents the importance of the output vectors \( \mathbf{z}^{\text{LSH}, k}{i} \) of hashing round \( k \) in comparison to the other hashing rounds, and is exponentially proportional to the normalization term of their softmax computation. The intuition behind this is that if the corresponding query vector \( \mathbf{q}{i}^{k} \) have a high cosine similarity with all other query vectors in its respective chunk, then the softmax normalization term of this chunk tends to be high, so that the corresponding output vectors \( \mathbf{q}{i}^{k} \) should be a better approximation to global attention and thus receive more weight than output vectors of hashing rounds with a lower softmax normalization term. For more detail see Appendix A of the paper. For our example, multi-round LSH self-attention can be illustrated as follows. Great. That's it. Now we know how LSH self-attention works in Reformer. Regarding the memory complexity, we now have two terms that compete which each other to be the memory bottleneck: the dot-product: \( \mathcal{O}(n_{h} * n_{c} * l_{c}^2) = \mathcal{O}(n * n_{h} * l_{c}) \) and the required memory for LSH bucketing: \( \mathcal{O}(n * n_{h} * \frac{n_{b}}{2}) \) with \( l_{c} \) being the chunk length. Because for large \( n \), the number of buckets \( \frac{n_{b}}{2} \) grows much faster than the chunk length \( l_{c} \), the user can again factorize the number of buckets config.num_buckets as explained here. Let's recap quickly what we have gone through above: 1. We want to approximate global attention using the knowledge that the softmax operation only puts significant weights on very few key vectors. 2. If key vectors are equal to query vectors this means that for each query vector \( \mathbf{q}{i} \), the softmax only puts significant weight on other query vectors that are similar in terms of cosine similarity. 3. This relationship works in both ways, meaning if \( \mathbf{q}{j} \) is similar to \( \mathbf{q}{i} \) than \(\mathbf{q}{j} \) is also similar to \( \mathbf{q}{i} \), so that we can do a global clustering before applying self-attention on a permuted input. 4. We apply local self-attention on the permuted input and re-order the output to its original permutation. --- \( {}^{1} \) The authors run some preliminary experiments confirming that shared query key self-attention performs more or less as well as standard self-attention. \( {}^{2} \) To be more exact the query vectors within a bucket are sorted according to their original order. This means if, e.g. the vectors \( \mathbf{q}_1, \mathbf{q}_3, \mathbf{q}_7 \) are all hashed to bucket 2, the order of the vectors in bucket 2 would still be \( \mathbf{q}_1 \), followed by \( \mathbf{q}_3 \) and \( \mathbf{q}_7 \). \( {}^3 \) On a side note, it is to mention the authors put a mask on the query vector \( \mathbf{q}{i} \) to prevent the vector from attending to itself. Because the cosine similarity of a vector to itself will always be as high or higher than the cosine similarity to other vectors, the query vectors in shared query key self-attention are strongly discouraged to attend to themselves.
[ 0.02592138573527336, -0.02676825225353241, 0.05294067785143852, -0.017244823276996613, -0.017674073576927185, 0.03413984179496765, -0.0059393527917563915, 0.0034684515558183193, 0.021585896611213684, -0.014941711910068989, -0.09761703014373779, 0.07330244034528732, 0.007793320342898369, 0.004255366511642933, -0.05909653753042221, 0.05021491274237633, 0.05908907577395439, -0.006192829925566912, -0.029210681095719337, 0.028705962002277374, 0.019708996638655663, 0.01537842582911253, 0.07067330926656723, -0.032008275389671326, -0.0284403245896101, -0.020245220512151718, 0.009558220393955708, 0.022688578814268112, -0.07187481224536896, 0.01531633548438549, -0.10119371116161346, -0.06069132685661316, 0.03646942973136902, -0.013383078388869762, 0.0030196839943528175, -0.06153687462210655, -0.07683126628398895, 0.010923252440989017, 0.03019561991095543, -0.08517710864543915, 0.012741959653794765, -0.010981800965964794, -0.08857979625463486, 0.022753331810235977, -0.07378251850605011, -0.040592316538095474, -0.16684356331825256, 0.08615468442440033, -0.10701599717140198, -0.024057580158114433, -0.018701892346143723, 0.04503645375370979, -0.01526720356196165, 0.05055997893214226, -0.03463331609964371, 0.013682443648576736, 0.02660115621984005, -0.018968632444739342, 0.0406462624669075, 0.045399490743875504, 0.06619719415903091, -0.02421022206544876, -0.04206928610801697, 0.07346626371145248, 0.048631589859724045, 0.006459944415837526, 0.0556400790810585, 0.0005856947973370552, -0.10881392657756805, -0.03935985639691353, 0.02104237861931324, -0.002417381852865219, -0.044152792543172836, -0.008921562694013119, -0.044986240565776825, 0.012852021493017673, -0.04364175349473953, 0.06055556237697601, 0.06300987303256989, -0.022021008655428886, 0.00857579242438078, 0.021905088797211647, 0.09568331390619278, 0.030362267047166824, -0.000025949748305720277, -0.009951568208634853, -0.0050456589087843895, -0.035622064024209976, -0.0474347360432148, 0.04699358344078064, -0.025724392384290695, -0.08196846395730972, 0.010687225498259068, -0.03991170972585678, 0.09094283729791641, -0.07296835631132126, 0.028817713260650635, 0.008549771271646023, -0.01971285045146942, -0.0026630305219441652, -0.022080427035689354, -0.005924171768128872, 0.0688834935426712, 0.004094678442925215, -0.03812368959188461, 0.02730206586420536, 0.05573354661464691, -0.031076015904545784, -0.019098227843642235, -0.02968074381351471, -0.04477393627166748, 0.06944382190704346, 0.01720191165804863, 0.055240850895643234, 0.03674311935901642, 0.007672393228858709, -0.013769183307886124, -0.011035866104066372, 0.002609154675155878, -0.006386619992554188, -0.0768665000796318, 0.11995774507522583, 0.03868287801742554, 0.030682897195219994, 0.0964994728565216, -0.003947960212826729, -0.04134760797023773, 0.04826291650533676, -0.015850383788347244, -0.031313706189394, 0.03852217271924019, -0.0009419177658855915, 0.04796411469578743, -0.013096671551465988, -0.02650693990290165, -0.03678305819630623, -0.013059098273515701, 0.014584933407604694, -0.012053020298480988, -0.03940177708864212, -0.02642630785703659, -0.03413781151175499, 0.04926656559109688, -0.04880740866065025, 0.021746842190623283, -0.0406276099383831, -0.07087796926498413, 0.06277737766504288, 0.05098578706383705, 0.051960427314043045, 0.0018236307660117745, 0.032989252358675, -0.017550144344568253, -0.06715074181556702, 0.007593533024191856, 0.039805613458156586, 0.04685668647289276, -0.023511206731200218, -0.09665020555257797, 0.009645900689065456, -0.06585198640823364, -0.011789302341639996, 0.006483970209956169, 0.03626043349504471, 0.046862274408340454, -0.03695099800825119, 0.039114873856306076, -0.002622018801048398, 0.00667106918990612, 0.07037480175495148, 0.04820956289768219, 0.05336232855916023, 0.10222470015287399, -0.014630642719566822, -0.055814336985349655, 0.03835628181695938, 0.0023672073148190975, 0.06707841902971268, -0.03034963458776474, 0.05773281678557396, -0.04639723524451256, -0.007478507701307535, 0.011597213335335255, 0.05260169133543968, -0.029397064819931984, -0.016624586656689644, 0.047281116247177124, 0.010918226093053818, 0.03385411575436592, -0.02713119424879551, -0.09640505909919739, 0.03967319056391716, 0.05396738275885582, -0.0014624334871768951, 0.028352977707982063, 0.004381419159471989, -0.0400017648935318, 0.040908779948949814, 0.05442752689123154, 0.07149288058280945, 0.009267574176192284, 0.0007023342768661678, 0.02581167407333851, 0.025832301005721092, -0.035174984484910965, -0.02229301817715168, -0.0335262194275856, -0.02092183567583561, 0.04248041659593582, -0.06301192194223404, -0.07326453924179077, -0.12817339599132538, -0.014947479590773582, -0.010432998649775982, -0.0675114169716835, 0.03506411984562874, 0.024640904739499092, 0.05053696036338806, -0.02398241125047207, 0.034045591950416565, 0.1607169508934021, 0.022760067135095596, 0.0018842628924176097, 0.03439962863922119, -0.038079194724559784, 0.04519513249397278, 0.03234735503792763, -0.04232747107744217, 0.06454785168170929, -0.034664809703826904, 0.013399730436503887, -0.0528549887239933, 0.047798238694667816, 0.0033021075651049614, -0.047479357570409775, 0.019780069589614868, -0.01836373656988144, 0.04665767401456833, -0.027051076292991638, -0.05078396201133728, -0.01821628026664257, 0.05711149424314499, 0.011001959443092346, 0.04380609467625618, -0.050338733941316605, 0.02346823178231716, 0.011610063724219799, 0.0006667085690423846, -0.06840257346630096, -0.028586221858859062, -0.11315249651670456, 0.06901295483112335, 0.019499119371175766, -0.03222854807972908, 0.057001784443855286, -0.04534364491701126, 0.004910931456834078, -0.0002480428374838084, 0.00011663140321616083, -0.00038088823202997446, 0.01875845156610012, 0.03487369790673256, -0.00937352329492569, -0.0019671942573040724, 0.013954839669167995, -0.049417056143283844, 0.06920360773801804, 0.010183877311646938, 0.013788371346890926, -0.025618860498070717, 0.007517724297940731, 0.006638087797909975, 0.0008606061455793679, -0.0006113587878644466, -0.026206277310848236, 0.02388405054807663, 0.001036695670336485, -0.03159390389919281, 0.020527323707938194, -0.04360969364643097, -0.024591172114014626, 0.02786065638065338, 0.035928744822740555, -0.009911490604281425, 0.015399479307234287, -0.05541954189538956, -0.02289789915084839, 0.038057997822761536, -0.03531168773770332, -0.024796606972813606, -0.03234810382127762, 0.0032773781567811966, -0.024774910882115364, -0.03557784482836723, -0.03834404796361923, 0.00785221066325903, 0.003951419144868851, 0.004467089660465717, -0.03930142894387245, -0.020747454836964607, 0.01927846297621727, 0.001752748852595687, 0.000643896113615483, -0.003988876007497311, -0.009218254126608372, 0.01781030371785164, -0.020803121849894524, 0.0740256980061531, -0.09573943167924881, -0.07523129880428314, -0.0037930719554424286, 0.055220283567905426, 0.015015088021755219, -0.04122980311512947, 0.023151269182562828, 0.028322605416178703, -0.0032913191244006157, -0.03131485357880592, 0.0074177030473947525, -0.02310158498585224, 0.02063462883234024, -0.015077383257448673, 0.01336837187409401, 0.051714200526475906, 0.03456619381904602, -0.01906227134168148, 0.05077383667230606, 0.0020718795713037252, 0.021427497267723083, 0.03013376146554947, -0.022476958110928535, -0.017825758084654808, -0.05612051114439964, 0.018837111070752144, 0.024801630526781082, 0.016446499153971672, 0.032002829015254974, -0.019673027098178864, -0.019898097962141037, 0.014016580767929554, 0.003831145353615284, 0.047560952603816986, -0.036152902990579605, -0.01033924613147974, 0.018006963655352592, 0.0014667880022898316, 0.006827956531196833, 0.044380076229572296, 0.013379108160734177, 0.017078155651688576, 0.016221648082137108, 0.027176935225725174, 0.054676786065101624, -0.013254375196993351, 0.03430389240384102, -0.04394160956144333, -0.009566135704517365, -0.06818271428346634, -0.05327962711453438, -0.008897233754396439, 0.013195903971791267, 0.041386522352695465, -0.026117343455553055, -0.015956342220306396, 0.0003148394462186843, 0.01041321363300085, 0.0036493637599051, -0.014606612734496593, -0.014455802738666534, 0.02530483528971672, -0.008219187147915363, 0.00596623495221138, -0.033527057617902756, 0.038067348301410675, 0.0006482230382971466, 0.005443073343485594, -0.012290622107684612, -0.005708971060812473, 0.010954017750918865, 0.021884163841605186, 0.025866467505693436, -0.004723011516034603, -0.026788651943206787, 0.021949300542473793, 0.010809790343046188, -0.0007586809806525707, 0.06699208915233612, 0.03324265405535698, -0.003949527628719807, 0.0005431902827695012, -0.032907698303461075, 0.027161598205566406, 0.010022338479757309, -0.010127773508429527, 0.011677343398332596, 0.019981900230050087, 0.023290278390049934, -0.007530477363616228, 0.007162982132285833, 0.010011907666921616, 0.028880078345537186, -0.04388335347175598, 0.0029822008218616247, 0.042383939027786255, 0.013346842490136623, -0.03450561687350273, 0.024368539452552795, -0.03811512887477875, 0.02602204494178295, -0.027158603072166443, 0.01766175590455532, 0.02733214758336544, 0.015438148751854897, 0.004419764503836632, -0.03662995621562004, 0.0383894219994545, 0.04377899318933487, 0.0008600393775850534, 0.014767985790967941, -0.00002211462015111465, -0.0366053469479084, 0.0012186100939288735, 0.04734005779027939, -0.003556039184331894, -0.0794009193778038, -0.04274735227227211, 0.001666742260567844, 0.022150319069623947, -0.00669561792165041, 0.016538407653570175, -0.0031730118207633495, -0.04815756157040596, 0.042189113795757294, -0.0076544987969100475, 0.038674142211675644, 0.05723743513226509, 0.005890732631087303, 0.0004082638770341873, -0.03248577192425728, 0.008304738439619541, -0.016735952347517014, -0.0241831187158823, 0.019904645159840584, 0.04936716705560684, -0.029099000617861748, 0.028150027617812157, -0.04093075543642044, -0.037783823907375336, -0.030806036666035652, -0.010044789873063564, 0.012163410894572735, -0.01129642128944397, 0.028802869841456413, -0.002314777811989188, -0.0303984135389328, 0.013806433416903019, -0.04978296905755997, 0.05433844402432442, 0.06120719015598297, 0.007186179049313068, -0.023619916290044785, 0.01672346144914627, 0.04595104604959488, 0.003326513571664691, 0.007517960853874683, 0.00177625915966928, 0.015115915797650814, 0.021976303309202194, -0.007048985920846462, 0.01106337085366249, -0.06672076880931854, 0.01667000912129879, 0.030113134533166885, -0.014221271499991417, -0.03315923735499382, -0.03642599284648895, 0.01073332317173481, 0.03539735823869705, -0.04120490327477455, -0.008437186479568481, 0.009953855536878109, -0.059853870421648026, -0.04275284335017204, 0.019380860030651093, -0.015577907674014568, -0.029190968722105026, -0.002339873695746064, -0.006213392596691847, -0.027392201125621796, 0.028255697339773178, 0.023444287478923798, 0.004280253313481808, 0.02174653299152851, 0.0048040165565907955, 0.0407131128013134, 0.03637751191854477, -0.0034673805348575115, 0.007437906693667173, 0.053323160856962204, -0.033480942249298096, 0.006092275958508253, -0.001867699553258717, 0.03280516713857651, -0.023285498842597008, 0.026435501873493195, 0.0038517697248607874, -0.018575500696897507, 0.010452544316649437, 0.05167253315448761, 0.010343331843614578, -0.03151440620422363, -0.01268095150589943, 0.047870952636003494, 0.02116784267127514, -0.01711348444223404, -0.00477717025205493, -0.012421214021742344, -0.02734467200934887, 0.04790523275732994, 0.024700678884983063, -0.052863288670778275, -0.03868483006954193, 0.020855538547039032, -0.05081624165177345, 0.0051964628510177135, -0.007894577458500862, 0.0018982617184519768, 0.0005477400263771415, 0.03014104999601841, 0.011833912692964077, -0.018696939572691917, 0.01771417446434498, 0.031614698469638824, -0.023165229707956314, -0.04208534210920334, 0.044481322169303894, 0.019833430647850037, -0.00404610438272357, 0.06189732253551483, -0.009248084388673306, 0.0074533503502607346, -0.04022052511572838, -0.0005385368713177741, -0.008003374561667442, -0.012190660461783409, 0.06028415262699127, 0.018872510641813278, 4.449464796607572e-8, 0.007930443622171879, -0.012694498524069786, -0.03433520719408989, 0.0280901025980711, -0.03790263831615448, 0.015304295346140862, 0.04446440190076828, -0.021685345098376274, -0.021774781867861748, -0.030360812321305275, 0.020763272419571877, -0.05367099493741989, -0.013871618546545506, 0.038626525551080704, 0.006695268210023642, 0.012715206481516361, 0.0328700952231884, -0.03184637799859047, 0.03550991043448448, 0.004345127381384373, -0.021838346496224403, -0.03176583722233772, 0.0015613078139722347, 0.013632076792418957, -0.026398103684186935, 0.044192999601364136, 0.007691598497331142, -0.045029379427433014, -0.007776171900331974, 0.029635721817612648, 0.014482864178717136, -0.030128492042422295, -0.027372458949685097, 0.003217219142243266, -0.07044888287782669, -0.003978976979851723, 0.03409251943230629, 0.0231599323451519, 0.016808658838272095, 0.03313428536057472, 0.011823663488030434, -0.00012965116184204817, 0.06611758470535278, -0.001651047496125102, 0.03145698830485344, -0.014511212706565857, -0.007843993604183197, 0.02533242478966713, 0.049021165817976, -0.025885457172989845, -0.0016564028337597847, 0.03967859223484993, 0.0046023293398320675, 0.03369702771306038, -0.015775034204125404, 0.057722605764865875, -0.013007777743041515, -0.04965439811348915, 0.035202011466026306, -0.019800709560513496, -0.001768777845427394, 0.022304469719529152, 0.04152437299489975, -0.006980826146900654, 0.0012445413740351796, 0.012437840923666954, 0.020815148949623108, 0.03802112862467766, -0.015481268055737019, -0.009511535987257957, 0.001503239618614316, 0.024095259606838226, 0.00900911446660757, 0.041564807295799255, 0.017620200291275978, -0.03953879699110985, 0.010819229297339916, -0.03964477777481079, -0.029329847544431686, 0.008860796689987183, 0.004842378664761782, -0.012336633168160915, 0.0172688327729702, -0.00597642594948411, 0.023577053099870682, -0.0019099257187917829, 0.025302935391664505, -0.021089104935526848, 0.007347065024077892, -0.0025185048580169678, 0.024630673229694366, 0.013637436553835869, -0.03854235261678696, 0.003774132113903761, 0.007510852068662643, 0.013492831960320473, 0.02635304071009159, 0.0020056013017892838, -0.030726315453648567, -0.0534336157143116, -0.05867287889122963, -0.010625394992530346, -0.019300833344459534, 0.03599398210644722, -0.005540568847209215, -0.0481049083173275, 0.0072565539740026, -0.027767954394221306, -0.06453753262758255, 0.04864748194813728, 0.01978379860520363, 0.007712911814451218, -0.08117946237325668, -0.04585889354348183, 0.008559724316000938, -0.012223866768181324, 0.012980278581380844, 0.017176056280732155, 0.030834229663014412, -0.019200557842850685, 0.03766151890158653, 0.014408697374165058, -0.004520331509411335, 0.0202341228723526, -0.004803115967661142, 0.02399699203670025, -0.007655850611627102, -0.0231368076056242, -0.0267365463078022, -0.0019723204895853996, 0.025194402784109116, 0.015448749996721745, 0.0577905997633934, -0.01527397334575653, -0.018747519701719284, -0.005404761992394924, 0.07604603469371796, 0.02350039780139923, -0.02666362002491951, -0.029554229229688644, 0.03954048454761505, -0.00645575812086463, 0.03407658264040947, 0.03751866891980171, 0.019664233550429344, 0.05083572119474411, -0.03345286473631859, -0.017751354724168777, -0.00144948810338974, 0.000011253243428654969, -0.007111976854503155, -0.06622615456581116, -0.011987831443548203, 0.031768932938575745, 0.023341210559010506, 0.0015540645690634847, -0.06937588006258011, 0.04685851186513901, -0.020782172679901123, -0.011809798888862133, -0.051488567143678665, -0.0250227227807045, 0.03996618092060089, -0.012884415686130524, 0.03317767009139061, 0.007810229901224375, -0.030949095264077187, -0.04550844058394432, -0.012201432138681412, -0.017214680090546608, 0.02288300171494484, 0.02517777867615223, 0.02855856344103813, -0.059965647757053375, -0.03973696008324623, -0.038691259920597076, -0.012027997523546219, 0.010393470525741577, 0.0034387188497930765, -0.011697803623974323, -0.001982651883736253, -0.0014501817058771849, 0.001526696258224547, 0.03921545669436455, -0.006536502856761217, 0.009464011527597904, -0.024318013340234756, 0.061616797000169754, -0.006218275520950556, -0.03460786119103432, -0.003103533061221242, 0.033816952258348465, 0.01725252903997898, 0.023216405883431435, 0.031652964651584625, 0.03532528877258301, -0.02204155921936035, 0.004097844939678907, 0.004544563125818968, 0.010240382514894009, -0.028106922283768654, -0.045718517154455185, -0.005865807645022869, 0.0002682640915736556, -0.028447628021240234, -0.04890577122569084, -0.02457417920231819, 0.016463566571474075, 0.012352421879768372, 0.0011043852427974343, -0.01211316417902708, 0.010577216744422913, -0.04891345277428627, 0.0318213626742363, 0.015488429926335812, 0.01910087838768959, -0.016201037913560867, 0.024865206331014633, -0.012198098003864288, 0.030088812112808228 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
Benchmark Benchmark tools were recently added to Transformers - see here for a more detailed explanation. To show how much memory can be saved using "local" + "LSH" self-attention, the Reformer model google/reformer-enwik8 is benchmarked for different local_attn_chunk_length and lsh_attn_chunk_length. The default configuration and usage of the google/reformer-enwik8 model can be checked in more detail here. Let's first do some necessary imports and installs. #@title Installs and Imports # pip installs !pip -qq install git+https://github.com/huggingface/transformers.git !pip install -qq py3nvml from transformers import ReformerConfig, PyTorchBenchmark, PyTorchBenchmarkArguments First, let's benchmark the memory usage of the Reformer model using global self-attention. This can be achieved by setting lsh_attn_chunk_length = local_attn_chunk_length = 8192 so that for all input sequences smaller or equal to 8192, the model automatically switches to global self-attention. config = ReformerConfig.from_pretrained("google/reformer-enwik8", lsh_attn_chunk_length=16386, local_attn_chunk_length=16386, lsh_num_chunks_before=0, local_num_chunks_before=0) benchmark_args = PyTorchBenchmarkArguments(sequence_lengths=[2048, 4096, 8192, 16386], batch_sizes=[1], models=["Reformer"], no_speed=True, no_env_print=True) benchmark = PyTorchBenchmark(configs=[config], args=benchmark_args) result = benchmark.run() HBox(children=(FloatProgress(value=0.0, description='Downloading', max=1279.0, style=ProgressStyle(description… 1 / 1 Doesn't fit on GPU. CUDA out of memory. Tried to allocate 2.00 GiB (GPU 0; 11.17 GiB total capacity; 8.87 GiB already allocated; 1.92 GiB free; 8.88 GiB reserved in total by PyTorch) ==================== INFERENCE - MEMORY - RESULT ==================== -------------------------------------------------------------------------------- Model Name Batch Size Seq Length Memory in MB -------------------------------------------------------------------------------- Reformer 1 2048 1465 Reformer 1 4096 2757 Reformer 1 8192 7893 Reformer 1 16386 N/A -------------------------------------------------------------------------------- The longer the input sequence, the more visible is the quadratic relationship \( \mathcal{O}(n^2) \) between input sequence and peak memory usage. As can be seen, in practice it would require a much longer input sequence to clearly observe that doubling the input sequence quadruples the peak memory usage. For this a google/reformer-enwik8 model using global attention, a sequence length of over 16K results in a memory overflow. Now, let's activate local and LSH self-attention by using the model's default parameters. config = ReformerConfig.from_pretrained("google/reformer-enwik8") benchmark_args = PyTorchBenchmarkArguments(sequence_lengths=[2048, 4096, 8192, 16384, 32768, 65436], batch_sizes=[1], models=["Reformer"], no_speed=True, no_env_print=True) benchmark = PyTorchBenchmark(configs=[config], args=benchmark_args) result = benchmark.run() 1 / 1 Doesn't fit on GPU. CUDA out of memory. Tried to allocate 2.00 GiB (GPU 0; 11.17 GiB total capacity; 7.85 GiB already allocated; 1.74 GiB free; 9.06 GiB reserved in total by PyTorch) Doesn't fit on GPU. CUDA out of memory. Tried to allocate 4.00 GiB (GPU 0; 11.17 GiB total capacity; 6.56 GiB already allocated; 3.99 GiB free; 6.81 GiB reserved in total by PyTorch) ==================== INFERENCE - MEMORY - RESULT ==================== -------------------------------------------------------------------------------- Model Name Batch Size Seq Length Memory in MB -------------------------------------------------------------------------------- Reformer 1 2048 1785 Reformer 1 4096 2621 Reformer 1 8192 4281 Reformer 1 16384 7607 Reformer 1 32768 N/A Reformer 1 65436 N/A -------------------------------------------------------------------------------- As expected using local and LSH self-attention is much more memory efficient for longer input sequences, so that the model runs out of memory only at 16K tokens for a 11GB RAM GPU in this notebook.
[ -0.011366480961441994, -0.006340404041111469, 0.015144486911594868, -0.013455868698656559, -0.04588701203465462, 0.05722128972411156, 0.0577072948217392, -0.022158728912472725, -0.02835826948285103, -0.023437026888132095, -0.07536010444164276, 0.10502336919307709, -0.006831918843090534, 0.009687898680567741, 0.019373156130313873, 0.022754907608032227, 0.06011228635907173, -0.003067897167056799, -0.05755842477083206, 0.019849078729748726, 0.017843734472990036, -0.055208392441272736, 0.07906855642795563, 0.005342706106603146, -0.0199419092386961, -0.06664656847715378, 0.032647088170051575, -0.02656721882522106, -0.032557446509599686, -0.004871657583862543, -0.13268724083900452, -0.030462928116321564, 0.00023340588086284697, -0.044180069118738174, 0.014777549542486668, -0.06025811657309532, -0.07495088130235672, 0.03449048474431038, 0.02182292751967907, -0.04331120103597641, -0.001027085236273706, -0.0023593869991600513, -0.07134172320365906, -0.01043036486953497, -0.0004610080795828253, 0.03693046793341637, -0.09460332989692688, 0.03402457386255264, -0.0879296138882637, 0.028748255223035812, -0.06203460693359375, 0.015819577500224113, 0.01226294320076704, 0.023692931979894638, -0.016150973737239838, 0.018581215292215347, 0.05977223068475723, 0.011186073534190655, 0.018344053998589516, 0.0065857963636517525, 0.06164107844233513, 0.0026282158214598894, 0.004254090134054422, 0.07454673200845718, 0.010621903464198112, -0.04299221187829971, -0.03182284161448479, 0.05041588097810745, -0.056131988763809204, -0.0554472878575325, -0.011404849588871002, -0.03613848611712456, 0.032821174710989, 0.012466026470065117, -0.06939844787120819, -0.03653646260499954, -0.02048957534134388, 0.011498096399009228, 0.08620597422122955, 0.0631626546382904, 0.013978756964206696, 0.048317085951566696, 0.018500356003642082, -0.02774946205317974, 0.025028621777892113, -0.04358002170920372, 0.029490971937775612, -0.11245077848434448, -0.05238271877169609, 0.039086565375328064, -0.08566667139530182, -0.06719420105218887, 0.05143820866942406, -0.02672303095459938, 0.0468323789536953, -0.004173011053353548, -0.04332031309604645, 0.04883286729454994, -0.011174840852618217, 0.014507546089589596, -0.033617641776800156, -0.04999533295631409, 0.012925266288220882, -0.015125835314393044, -0.00799535121768713, 0.011945096775889397, -0.03723793849349022, -0.09097377210855484, -0.013301576487720013, -0.002056174213066697, -0.018780145794153214, 0.04219285026192665, -0.031047137454152107, 0.03485585004091263, -0.05677562579512596, -0.005796213634312153, -0.06998126208782196, -0.04832824319601059, -0.0024977312423288822, -0.008649284951388836, -0.03041783906519413, 0.08175162971019745, 0.044777046889066696, 0.021281182765960693, 0.039833713322877884, 0.03835376724600792, -0.02610110118985176, 0.03924167901277542, 0.024762848392128944, -0.006109658163040876, 0.08018843084573746, -0.01174574438482523, 0.09314382076263428, -0.03276938199996948, -0.03403422608971596, -0.05311828851699829, 0.02909865602850914, -0.023160090669989586, -0.039074428379535675, 0.015618696808815002, -0.05164984241127968, 0.025615209713578224, 0.010095725767314434, -0.08623313903808594, 0.04099645838141441, -0.02008993923664093, -0.09536279737949371, 0.09091588854789734, 0.023315010592341423, -0.018038753420114517, -0.10402369499206543, 0.05299407243728638, -0.02312985621392727, -0.007477891631424427, 0.03664452210068703, 0.07238174974918365, -0.020505335181951523, -0.032152511179447174, -0.09433700144290924, -0.005002093035727739, -0.08902429789304733, 0.04635535553097725, -0.0158455278724432, 0.00044135499047115445, 0.0310510266572237, -0.015200869180262089, 0.004185026977211237, -0.05439280718564987, -0.013616954907774925, -0.0035468603018671274, 0.04627710208296776, -0.005592315457761288, 0.07396925985813141, -0.05455157160758972, -0.022461028769612312, 0.05190374329686165, 0.0060302941128611565, 0.024851657450199127, -0.000831647077575326, -0.032210104167461395, -0.0273439884185791, 0.031455036252737045, 0.008916383609175682, 0.08147246390581131, 0.039938200265169144, -0.09031215310096741, 0.05147858336567879, -0.002465870464220643, -0.03587763383984566, -0.028423767536878586, 0.020377719774842262, -0.03619234263896942, 0.08848689496517181, 0.001229231245815754, 0.026968691498041153, -0.010354849509894848, 0.02160465717315674, 0.016714196652173996, 0.06428048014640808, 0.06222923472523689, -0.020013317465782166, 0.049103934317827225, 0.03422156348824501, 0.0307620782405138, -0.03566133603453636, -0.05164201185107231, -0.07125525176525116, -0.049031976610422134, 0.02022639662027359, -0.003947392106056213, 0.029234515503048897, -0.10388396680355072, 0.04338956996798515, 0.03597700223326683, -0.05567064508795738, -0.04211480915546417, -0.028620922937989235, -0.011013868264853954, 0.017729047685861588, 0.031227370724081993, 0.10861723870038986, 0.009769097901880741, -0.031702060252428055, -0.06036723777651787, -0.01705162413418293, 0.043182022869586945, -0.060200970619916916, 0.0628727376461029, 0.04282757267355919, -0.06828144937753677, -0.004263508133590221, -0.11100935935974121, -0.043891679495573044, 0.061320941895246506, -0.09339066594839096, -0.0688658282160759, 0.03696669638156891, 0.08404254913330078, -0.003599913790822029, -0.035936273634433746, -0.058373890817165375, 0.030782433226704597, 0.08249307423830032, 0.02515759877860546, 0.026740411296486855, 0.022843072190880775, -0.07187502831220627, 0.000696554605383426, -0.0504474937915802, -0.06891036033630371, -0.043665703386068344, 0.026176707819104195, 0.022546149790287018, -0.042114678770303726, -0.004391827620565891, -0.01738521084189415, -0.04149414226412773, 0.015224197879433632, -0.02211277186870575, 0.03982686623930931, 0.006761543452739716, 0.07072964310646057, -0.04507451876997948, -0.005965637043118477, 0.010243065655231476, -0.0654856413602829, 0.016683129593729973, 0.004193727392703295, 0.02056356519460678, -0.056749556213617325, -0.009436915628612041, 0.032801590859889984, 0.022305568680167198, 0.0008663333719596267, 0.003434679703786969, 0.005189866758882999, 0.014496222138404846, -0.025605155155062675, 0.00784994475543499, -0.027794085443019867, -0.003929281607270241, -0.004017845261842012, 0.011655141599476337, 0.00036556809209287167, -0.019005488604307175, 0.03790128603577614, 0.009153108112514019, -0.004137227777391672, -0.06261879950761795, 0.00638744980096817, 0.01430404745042324, 0.020009610801935196, 0.027533838525414467, -0.04906186833977699, -0.03051263839006424, 0.033511046320199966, -0.013690067455172539, -0.03758774697780609, -0.0030818225350230932, -0.002801348688080907, -0.02176792360842228, 0.007344936020672321, -0.021886827424168587, 0.010735921561717987, -0.009609933942556381, 0.01594320684671402, -0.023474710062146187, 0.031177358701825142, -0.07526642084121704, -0.03914855048060417, -0.033379290252923965, 0.029083847999572754, -0.019823746755719185, -0.06375689804553986, 0.015046967193484306, 0.043145738542079926, -0.0020933651831001043, 0.00015989535313565284, -0.01709192618727684, -0.022729527205228806, -0.003945611417293549, 0.03497433662414551, -0.023644553497433662, 0.03194510564208031, 0.02849329262971878, -0.0574316680431366, 0.028490744531154633, -0.03422761708498001, 0.03140391409397125, -0.015933701768517494, -0.02576301433146, 0.007732830010354519, -0.012588424608111382, 0.021209994331002235, 0.0059951418079435825, -0.022737551480531693, 0.05459357425570488, -0.04669692739844322, -0.01693044789135456, -0.07372843474149704, -0.006343618966639042, 0.05107811093330383, -0.05633451044559479, -0.031114211305975914, -0.028103334829211235, 0.03929352015256882, 0.014873410575091839, 0.023889461532235146, 0.039121147245168686, -0.011981502175331116, 0.022119225934147835, 0.024023456498980522, 0.07724810391664505, -0.022818483412265778, 0.006377102341502905, -0.023043110966682434, 0.019852502271533012, -0.019729578867554665, -0.054282981902360916, 0.009859519079327583, 0.020103512331843376, 0.05432525649666786, -0.025304388254880905, -0.010974492877721786, -0.03789190948009491, 0.035727474838495255, 0.005755331367254257, -0.031103892251849174, -0.06820934265851974, 0.011734534054994583, -0.0525050051510334, 0.02339816652238369, -0.02188986726105213, 0.005803032778203487, -0.02537834644317627, -0.014828025363385677, -0.046575356274843216, 0.00919129978865385, -0.036385804414749146, 0.013132345862686634, 0.0027340787928551435, -0.0018367439042776823, -0.06701865792274475, 0.018795914947986603, -0.0025269852485507727, -0.024762999266386032, 0.05143233761191368, 0.046777915209531784, -0.038007140159606934, -0.02434743009507656, -0.03649185597896576, 0.008814295753836632, 0.007410920690745115, 0.026324046775698662, 0.01767979934811592, -0.00890875793993473, 0.05139186978340149, -0.0026366193778812885, 0.019400574266910553, -0.01142342109233141, 0.007358321454375982, -0.01628478430211544, -0.007804906461387873, -0.016112420707941055, 0.020581403747200966, -0.006847421173006296, -0.01048314105719328, 0.03498451039195061, 0.001885710284113884, -0.025101441890001297, 0.013811602257192135, 0.042415909469127655, 0.02015352062880993, 0.009475885890424252, -0.038404680788517, 0.011431518010795116, 0.0398162379860878, 0.015387340448796749, 0.01876353845000267, -0.010210479609668255, -0.03751891851425171, 0.00421939417719841, 0.07108138501644135, 0.06484898179769516, -0.018054155632853508, -0.037746280431747437, -0.029386620968580246, 0.032358188182115555, 0.016734007745981216, 0.022016819566488266, -0.01568882167339325, -0.03960183635354042, 0.03591025620698929, -0.00880421232432127, 0.013873512856662273, 0.018585816025733948, -0.028279170393943787, 0.008974529802799225, -0.04587355628609657, 0.026561271399259567, 0.011343530379235744, 0.012448995374143124, 0.0042753564193844795, 0.05370134487748146, -0.03808119148015976, -0.004014166072010994, -0.021656634286046028, -0.0020581199787557125, -0.049829889088869095, -0.013033748604357243, 0.023819047957658768, -0.030129434540867805, 0.0032794075086712837, -0.008029479533433914, 0.01304624043405056, 0.039302341639995575, -0.057874999940395355, 0.04361676052212715, 0.026590049266815186, -0.00986327975988388, -0.04733707755804062, 0.008661838248372078, 0.03204764798283577, 0.033309273421764374, -0.011660601943731308, 0.0009972283151000738, -0.0006834632367826998, 0.024713778868317604, -0.026088209822773933, 0.009549690410494804, -0.00579115329310298, 0.0034848537761718035, 0.010897483676671982, 0.04386252164840698, 0.013262721709907055, -0.05446748062968254, 0.04669159650802612, -0.00892164371907711, 0.0015537725994363427, -0.00533621059730649, -0.015837835147976875, 0.002444971352815628, 0.0048741186037659645, 0.06201555207371712, -0.009812303818762302, -0.016561906784772873, 0.009998055174946785, 0.06259185820817947, 0.013814290054142475, -0.0010289439233019948, 0.014515075832605362, -0.01713612675666809, 0.03627845272421837, 0.02829829230904579, 0.05436205118894577, 0.07625408470630646, 0.0026199044659733772, 0.018838511779904366, 0.003497794969007373, -0.01998799853026867, 0.007271533366292715, -0.004531174432486296, 0.0402582585811615, -0.03178826719522476, 0.029912352561950684, 0.006593451369553804, 0.0002455876092426479, -0.030214132741093636, 0.06773616373538971, 0.0325547493994236, -0.026988457888364792, -0.019649168476462364, 0.040928661823272705, 0.037038516253232956, 0.010400266386568546, -0.01994978077709675, 0.012567674741148949, -0.04039581120014191, -0.005262316204607487, -0.00861358642578125, -0.041636526584625244, -0.002485501579940319, 0.003997631371021271, -0.013085950165987015, 0.01451511774212122, 0.010051120072603226, 0.003369956510141492, -0.00915836077183485, -0.03319971635937691, 0.01975882612168789, -0.013899967074394226, -0.018747473135590553, 0.006383377593010664, -0.05653202161192894, 0.008455775678157806, 0.006497702561318874, 0.01673024334013462, -0.013630034402012825, 0.018207373097538948, 0.0028694793581962585, -0.022478029131889343, 0.015646079555153847, 0.024154571816325188, -0.0022777675185352564, 0.00580649683251977, 0.029695123434066772, 0.02109186351299286, -0.04727299138903618, 0.008654006756842136, -0.0022440210450440645, -0.05975775420665741, 0.029085392132401466, -0.010689164511859417, 0.032943543046712875, 0.07404012233018875, -0.008866759948432446, -0.010755719617009163, -0.012953306548297405, 0.01721203327178955, -0.0367344506084919, 0.022870806977152824, -0.01562295202165842, 0.02644486166536808, -0.059938013553619385, 0.0002152061351807788, 0.0175795778632164, 0.021850530058145523, 0.06394850462675095, -0.031734853982925415, -0.011349418200552464, 0.015618334524333477, 0.029577473178505898, -0.03674207627773285, 0.044888101518154144, -0.019862275570631027, -0.039732567965984344, 0.0009470948134548962, 0.058361466974020004, -0.03232599422335625, 0.0013554501347243786, -0.004328638315200806, 0.020980270579457283, 0.007201832253485918, -0.01524952333420515, 0.025752445682883263, 0.03909996896982193, 0.04421317204833031, 0.03682023286819458, 0.03153126314282417, 0.04367491230368614, 0.044349554926157, 0.015633802860975266, -0.009256531484425068, -0.032231129705905914, 0.03895150125026703, 0.029419828206300735, -0.01089729368686676, 0.025615528225898743, -0.02010313607752323, 0.01577678695321083, -0.012706481851637363, 0.025985410436987877, -0.0028278667014092207, 0.023216137662529945, 0.032662615180015564, 0.018064530566334724, 0.0021575025748461485, -0.008376463316380978, 0.015363276936113834, 0.012530922889709473, 0.022495290264487267, -0.0011441066162660718, -0.0002857423678506166, -0.014303691685199738, 0.007056793197989464, 0.05375651642680168, 0.027309956029057503, 0.023798290640115738, -0.006100886967033148, 0.03850793093442917, 0.012331394478678703, 0.03030054271221161, 0.028308721259236336, -0.03309819847345352, -0.02171374298632145, -0.0013204391580075026, -0.03317572921514511, 0.012399667873978615, 0.005768535193055868, 0.018601274117827415, -0.02199217863380909, 0.014773836359381676, 0.0313175767660141, 0.01818249747157097, 0.0032728302758187056, -0.03197498247027397, 0.006923828274011612, -0.002451488748192787, 0.002949008485302329, -0.014079130254685879, -0.04927682876586914, 0.011919233947992325, 0.02913711406290531, 0.05608402565121651, -0.02475418895483017, 0.025783143937587738, 0.009550645016133785, -0.025432433933019638, -0.010786028578877449, -0.00993041880428791, -0.039861634373664856, 0.04600130766630173, -0.009186447598040104, -0.025110362097620964, -0.001438516890630126, 0.01179501786828041, 0.001819056924432516, 0.036165714263916016, 0.0046925307251513, 0.028013434261083603, -0.051406122744083405, 0.003977726213634014, -0.0021768715232610703, -0.027986198663711548, 0.07969042658805847, 0.0025687236338853836, 0.025035858154296875, -0.009991166181862354, 0.04754822328686714, 0.04917829856276512, -0.0013183432165533304, 0.020669586956501007, -0.003657890483736992, -0.024765875190496445, -0.02990192174911499, -0.014302480034530163, 0.028926419094204903, -0.006920523475855589, 0.023762278258800507, -0.007600641343742609, -0.0364675298333168, -0.017126021906733513, -0.007639381103217602, -0.029710374772548676, 0.06969296932220459, 0.005448439158499241, 0.0030841869302093983, -0.001294164452701807, 0.03182712942361832, 0.019895968958735466, 0.013203351758420467, 0.039616908878088, 0.005096422974020243, 0.04839769005775452, -0.004600760992616415, -0.009873325005173683, -0.048048555850982666, -0.0052986410446465015, 0.00727362185716629, -0.001154015539214015, 0.00032807840034365654, 0.02798216976225376, -0.01451629213988781, 0.02095814421772957, -0.026601040735840797, 0.02405565045773983, -0.021520905196666718, 0.033854614943265915, 0.0009593308786861598, -0.0010723886080086231, 0.04192616418004036, 0.04564347863197327, 0.06133970618247986, 0.026966720819473267, -0.038812439888715744, -0.0033906155731528997, 0.0006977350567467511, 0.004942451138049364, 0.07798738032579422, 0.05324048548936844, 0.017747515812516212, -0.06066657230257988, -0.029751349240541458, 0.024012645706534386, -0.016470463946461678, -0.005495942663401365, 0.02760775201022625, 0.001547590596601367, 0.03860151767730713, -0.01509229838848114, 0.013895923271775246, 0.04553248733282089, 0.051075663417577744, 0.022234752774238586, 0.007312818430364132, 0.029275141656398773, 0.007611624896526337, -0.041877128183841705, 0.004179664887487888, 0.02694382704794407, 0.05138489231467247, 0.04066519811749458, 0.02479199506342411, 0.0625670775771141, 0.02498028241097927, 0.019754527136683464, 0.012727020308375359, 0.049731988459825516, -0.03434917330741882, -0.0526406466960907, -0.014218741096556187, 0.0314764603972435, -0.01065503153949976, -0.034275609999895096, -0.0013718866975978017, -0.029828814789652824, 0.04116104543209076, -0.033358536660671234, -0.02181926555931568, 0.004960780497640371, -0.015712495893239975, 0.014575117267668247, -0.012797764502465725, -0.034403521567583084, 0.016230013221502304, 0.024563226848840714, -0.04538486897945404, 0.036945465952157974 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
3. Reversible Residual Layers Reversible residual layers were first introduced in N. Gomez et al and used to reduce memory consumption when training the popular ResNet model. Mathematically, reversible residual layers are slightly different to "real" residual layers but do not require the activations to be saved during the forward pass, which can drastically reduce memory consumption for training.
[ -0.007430435158312321, -0.0332772433757782, 0.08325320482254028, -0.05475492775440216, 0.06725014746189117, -0.022681407630443573, -0.023923629894852638, -0.016918441280722618, -0.0024600843898952007, -0.04598458483815193, -0.007598763797432184, 0.0851428285241127, -0.001853997353464365, 0.0023229331709444523, -0.03065699338912964, -0.03705130144953728, 0.03736979141831398, -0.09424389898777008, -0.0186964999884367, 0.07311802357435226, 0.032707661390304565, -0.043362416326999664, 0.02476440742611885, -0.08504240214824677, -0.03288915008306503, 0.021653085947036743, -0.035428036004304886, -0.035200607031583786, -0.02313190884888172, 0.00958038866519928, -0.04915980249643326, 0.03881688043475151, 0.044101815670728683, 0.03991413116455078, -0.016448549926280975, -0.03908304497599602, -0.07774672657251358, 0.043088167905807495, -0.055385444313287735, -0.03224511817097664, 0.004093700088560581, 0.06122801825404167, -0.035588666796684265, 0.02550937794148922, -0.005974992178380489, -0.04824971407651901, -0.11571480333805084, 0.023605184629559517, -0.026157410815358162, -0.03219272941350937, -0.056498583406209946, 0.06769131124019623, -0.10026275366544724, 0.062080081552267075, -0.054555073380470276, 0.02029816247522831, 0.023289164528250694, 0.08792344480752945, 0.014215623959898949, 0.00033249257830902934, 0.04441217705607414, 0.06407800316810608, 0.057803574949502945, 0.07078023254871368, -0.009850764647126198, -0.020506789907813072, 0.05184338241815567, -0.036776136606931686, -0.014729409478604794, -0.02468128316104412, -0.05648951604962349, -0.052174996584653854, -0.019681071862578392, -0.0005231530521996319, -0.00565603282302618, -0.02709055133163929, 0.01676836423575878, 0.01588485762476921, -0.007405308540910482, 0.05505521595478058, 0.0032214566599577665, 0.035151802003383636, 0.05635450780391693, 0.014769102446734905, 0.04111901670694351, -0.005819027777761221, 0.02064618282020092, -0.03844039887189865, -0.04762063920497894, 0.05897894129157066, -0.05513289198279381, -0.05513501539826393, 0.053350068628787994, -0.01270982064306736, 0.0634186640381813, -0.03649351745843887, -0.0051048267632722855, 0.009945500642061234, -0.018477171659469604, -0.007445560302585363, -0.043269094079732895, -0.05576527118682861, 0.015200220048427582, -0.049049802124500275, -0.03979162126779556, -0.022123154252767563, -0.03713235631585121, -0.07548382133245468, -0.00016780340229161084, -0.03287520632147789, -0.01718013919889927, 0.02710430696606636, 0.059182580560445786, 0.021500984206795692, -0.08634611964225769, 0.014706311747431755, 0.021208202466368675, 0.01454269140958786, 0.06692672520875931, 0.05008411407470703, -0.023712068796157837, 0.11002217233181, 0.01570085994899273, -0.0024460293352603912, -0.025812631472945213, 0.0016129511641338468, 0.02939811535179615, 0.003754489589482546, -0.015311235561966896, 0.02357257530093193, 0.004934797994792461, 0.07363811135292053, -0.04663649946451187, 0.05256778001785278, 0.016177549958229065, -0.12741921842098236, 0.03157123923301697, -0.0352892242372036, 0.00006925006891833618, 0.005309669300913811, -0.05456158146262169, -0.016691870987415314, 0.0258569847792387, -0.07068514823913574, 0.038816049695014954, -0.09695115685462952, -0.005500983912497759, 0.020761074498295784, 0.05659756809473038, 0.032945968210697174, -0.03850860148668289, 0.04559226706624031, 0.011159799993038177, -0.08929870277643204, -0.023594709113240242, 0.03380637988448143, -0.020355157554149628, 0.00961949210613966, -0.030498145148158073, 0.005717288237065077, 0.0009736156207509339, 0.004994664806872606, -0.044800128787755966, 0.06708674132823944, 0.10151031613349915, -0.03471464291214943, -0.0168401338160038, 0.055427465587854385, 0.0010765759507194161, 0.06804206222295761, -0.027040855959057808, -0.03791775926947594, 0.0434601828455925, -0.036206718534231186, -0.03125913441181183, 0.027577778324484825, -0.058928824961185455, 0.07599221915006638, -0.013948737643659115, -0.024117562919855118, -0.0029292013496160507, -0.032863061875104904, -0.09448225796222687, -0.01843358390033245, 0.044001974165439606, -0.047789957374334335, 0.024560973048210144, -0.04142925515770912, 0.014265667647123337, 0.0911359041929245, -0.12449254840612411, 0.005055808927863836, -0.015314123593270779, -0.07604677975177765, 0.016471950337290764, 0.047441087663173676, 0.004941228777170181, 0.1224924772977829, 0.02535935491323471, 0.08891159296035767, 0.06101840361952782, 0.04448314383625984, -0.05958937481045723, -0.04449949041008949, 0.029585635289549828, 0.020135091617703438, 0.06571677327156067, -0.0456731952726841, 0.052027344703674316, 0.0022603569086641073, 0.00901472195982933, -0.01888238824903965, 0.06679906696081161, -0.08660385012626648, -0.011954360641539097, -0.02059618942439556, -0.029549285769462585, -0.0018976274877786636, -0.00720234913751483, -0.06331478804349899, 0.07279279828071594, 0.05093308910727501, -0.05146230384707451, -0.004751470405608416, -0.02158149518072605, -0.01185546349734068, 0.033246513456106186, -0.08107402920722961, 0.09971488267183304, -0.056792329996824265, 0.06219657510519028, -0.09023915976285934, 0.02050701528787613, 0.06400706619024277, 0.04621874913573265, 0.022993480786681175, 0.001183668035082519, -0.08527424931526184, -0.002247012220323086, -0.04965796321630478, -0.020881833508610725, 0.03611581772565842, 0.027873901650309563, 0.024167068302631378, 0.0033999818842858076, -0.028545398265123367, 0.016084741801023483, 0.032795216888189316, -0.03439157083630562, -0.02499851956963539, -0.0684048980474472, -0.008739234879612923, 0.033211980015039444, -0.051150813698768616, 0.02844284102320671, 0.038223814219236374, -0.030741684138774872, -0.05637530982494354, 0.032997626811265945, 0.02658199705183506, -0.00519951805472374, -0.01932559162378311, -0.004969810135662556, -0.01975102350115776, 0.004133069422096014, -0.02277468703687191, -0.024906329810619354, 0.002017877297475934, 0.013301189988851547, 0.010160875506699085, 0.04431113600730896, -0.0200966689735651, 0.0085541857406497, 0.03744766488671303, 0.008958104997873306, -0.04068479314446449, 0.028915511444211006, -0.03787633031606674, -0.05918538197875023, -0.03831195831298828, -0.008993989787995815, 0.0003280389355495572, 0.031735777854919434, 0.026859408244490623, 0.007219846360385418, -0.000758457463234663, -0.04093020036816597, -0.008069286122918129, 0.019809773191809654, 0.05301182344555855, 0.022422054782509804, 0.0418848842382431, -0.02027604542672634, 0.008103597909212112, -0.02863130532205105, 0.007012322079390287, 0.02349596656858921, -0.03239799290895462, 0.02315957471728325, -0.01724931225180626, -0.0467071607708931, 0.028226705268025398, 0.04744262993335724, 0.005333674140274525, -0.006956364028155804, 0.021883966401219368, -0.01395364385098219, 0.011350675486028194, -0.09190937131643295, -0.05079466104507446, 0.02022424340248108, -0.0075788600370287895, -0.041299186646938324, -0.012869000434875488, 0.01109630148857832, 0.021742332726716995, 0.016451559960842133, -0.03156774863600731, -0.008471482433378696, -0.00048684669309295714, 0.025944167748093605, 0.05567435547709465, -0.08171887695789337, -0.00033713699667714536, 0.03670750930905342, -0.006342093460261822, 0.029947670176625252, -0.05187727138400078, 0.022389505058526993, 0.05764617770910263, 0.03191757574677467, 0.05759333074092865, -0.004480138886719942, 0.028805233538150787, 0.01429277379065752, 0.01501901913434267, -0.04809865728020668, -0.005640075076371431, -0.015198705717921257, -0.04145269840955734, 0.0023738753516227007, 0.010699338279664516, -0.03438501060009003, 0.02419908531010151, 0.014231210574507713, 0.01000309456139803, -0.005235082469880581, 0.02810494415462017, 0.0345638245344162, 0.02336997538805008, 0.04202226549386978, 0.034523870795965195, -0.011386800557374954, -0.01986255683004856, 0.01204652152955532, 0.014233076013624668, 0.05095424875617027, -0.026684841141104698, 0.013363764621317387, -0.008549096062779427, -0.007104013580828905, 0.04565340653061867, -0.015656165778636932, -0.028519190847873688, 0.03148069977760315, -0.030571086332201958, 0.015392223373055458, -0.03352959826588631, -0.005660953465849161, 0.017275149002671242, 0.02520470879971981, -0.0009135167929343879, -0.020454159006476402, 0.0015527041396126151, -0.0014244214398786426, 0.025192460045218468, 0.02162756584584713, 0.032326433807611465, -0.028155488893389702, 0.02299359068274498, 0.004944826941937208, 0.012491792440414429, -0.0235117357224226, 0.024668235331773758, 0.018329598009586334, 0.002867358038201928, 0.06264535337686539, -0.005795687902718782, 0.020365482196211815, 0.028500616550445557, -0.0038430276326835155, -0.004822846036404371, -0.038214150816202164, -0.0021193826105445623, 0.011167749762535095, 0.0018318940419703722, 0.015047031454741955, 0.01712428592145443, 0.03506794199347496, -0.01550216879695654, 0.005575064104050398, 0.003176790662109852, -0.043889120221138, 0.028081001713871956, 0.04673793539404869, 0.026629403233528137, -0.013377734459936619, -0.006464866921305656, 0.032702650874853134, -0.05088112875819206, 0.01258678175508976, -0.01515104714781046, -0.011158779263496399, -0.030609114095568657, -0.025752680376172066, 0.0037855554837733507, 0.02993396483361721, -0.04635541886091232, -0.0491323247551918, 0.014710923656821251, 0.016231415793299675, 0.004121990874409676, -0.0006480233278125525, 0.02919701859354973, -0.045225635170936584, 0.01061394065618515, -0.022626807913184166, 0.0035164866130799055, -0.021248873323202133, 0.049445196986198425, 0.018101690337061882, -0.0013718195259571075, 0.02066941373050213, -0.012443347834050655, 0.041665319353342056, 0.011319560930132866, 0.004320659674704075, -0.009108459576964378, -0.025624139234423637, 0.055839017033576965, 0.034752655774354935, 0.01101619005203247, 0.02111678197979927, -0.04068665951490402, -0.026367440819740295, -0.017946729436516762, -0.0006991968839429319, -0.06339537352323532, 0.013579112477600574, -0.001351715181954205, 0.04537370055913925, -0.04110715910792351, 0.06605145335197449, -0.006264968775212765, -0.05405615270137787, -0.024932431057095528, -0.012302435003221035, 0.005883808713406324, 0.06000189483165741, -0.010541761294007301, -0.05652507022023201, -0.033592548221349716, -0.01007029041647911, -0.017955204471945763, 0.0365346223115921, -0.00917167030274868, 0.02030370943248272, -0.0006648625712841749, 0.020139236003160477, -0.01046917773783207, -0.02740035578608513, 0.04057871922850609, 0.014200559817254543, 0.009507074020802975, -0.03394196927547455, -0.041509468108415604, 0.018702104687690735, 0.03322071582078934, 0.019783716648817062, -0.041729886084795, 0.013203387148678303, -0.051998283714056015, -0.003422727342694998, -0.021994495764374733, 0.017450429499149323, 0.01290532574057579, -0.0007577920914627612, 0.007974199950695038, 0.004470439627766609, 0.0344088040292263, 0.04555022716522217, -0.03421613201498985, 0.0384809784591198, 0.019337579607963562, 0.00785014871507883, 0.0483013354241848, -0.0231014471501112, 0.06269104033708572, 0.07520979642868042, -0.018044451251626015, 0.06797068566083908, -0.06492175161838531, 0.04388141632080078, 0.06856676936149597, -0.000133116016513668, 0.008880773559212685, -0.015567720867693424, -0.03306348994374275, 0.03356325998902321, 0.06916200369596481, 0.017154060304164886, -0.011074332520365715, -0.010696318000555038, 0.021050581708550453, -0.04216860607266426, 0.03417491167783737, 0.028443455696105957, -0.016018882393836975, -0.0016301258001476526, -0.002278396626934409, -0.019090693444013596, -0.038209110498428345, -0.04711966961622238, -0.03315679356455803, -0.030489962548017502, 0.02763042412698269, 0.027956778183579445, 0.027919502928853035, 0.013977334834635258, 0.001209513284265995, -0.023285144940018654, 0.008948097005486488, 0.03309687599539757, -0.05365142598748207, 0.03493927791714668, -0.016632935032248497, -0.010688960552215576, 0.02764704078435898, -0.009383534081280231, 0.017193961888551712, 0.004568784032016993, 0.010060097090899944, -0.01703229546546936, -0.011821755208075047, 0.0236495491117239, 0.04571281746029854, -0.0019738939590752125, -0.022951241582632065, -0.015022369101643562, -0.024561407044529915, -0.09037429094314575, -0.012919955886900425, -0.09847509860992432, -0.01878632977604866, 0.07178951799869537, -0.033793237060308456, 0.03103657439351082, 0.02047717198729515, -0.012379005551338196, -0.020154131576418877, -0.010164923965930939, 0.013620251789689064, -0.008500526659190655, -0.03250229358673096, 0.01988203264772892, -0.0005307073006406426, -0.03981814906001091, 0.0022597340866923332, 0.012191444635391235, -0.0119905611500144, -0.0031654564663767815, 0.0183095820248127, -0.011937955394387245, 0.0881827101111412, 0.024055132642388344, -0.04251053184270859, 0.004925509914755821, -0.0078742615878582, 0.041439227759838104, 0.04827043041586876, -0.006441749632358551, 0.0171267781406641, -0.04346315562725067, 0.033537182956933975, 0.00030108881765045226, 0.020021112635731697, 0.00009802132990444079, 0.04211476445198059, 0.011753041297197342, 0.0013060485944151878, 0.016909662634134293, 0.001865516067482531, -0.009945238940417767, 0.006398964673280716, 0.04347990080714226, -0.03901589661836624, -0.013632654212415218, 0.046018682420253754, 0.017460260540246964, -0.01039714366197586, -0.05887297913432121, -0.0003522654005791992, -0.038901109248399734, 0.010310327634215355, -0.0410112664103508, -0.026957988739013672, 0.003952000290155411, 0.010888469405472279, 0.03742886707186699, 0.036010969430208206, 0.024947162717580795, 0.008694472722709179, 0.06531047821044922, 0.040176838636398315, 0.05702226608991623, 0.019693946465849876, -0.018205292522907257, -0.015985503792762756, 0.019355732947587967, 0.031287696212530136, -0.006184630561619997, 0.006364104803651571, -0.004259908571839333, -0.028893500566482544, 0.03201249614357948, -0.027472475543618202, 0.0067128934897482395, -0.014347231946885586, -0.02387903816998005, 0.01135063823312521, 0.03610311448574066, 0.017320191487669945, -0.002848908770829439, 0.012685326859354973, 0.06739477068185806, 0.003284530946984887, -0.022331221029162407, 0.0034084164071828127, -0.021813219413161278, -0.01637856848537922, 0.032329950481653214, 0.007346905767917633, -0.01629890315234661, -0.03199225664138794, 0.001097257831133902, 0.020934399217367172, 0.002857751678675413, -0.023840347304940224, -0.006236176006495953, 0.011886770837008953, 0.013787305913865566, -0.003917338792234659, 0.026371173560619354, 0.020401936024427414, 0.0532219372689724, -0.007112329360097647, -0.01245051808655262, -0.032613638788461685, 0.004505770746618509, -0.008290114812552929, 0.010344953276216984, -0.005689158104360104, -0.05370865389704704, 0.004579431377351284, 0.014777605421841145, -0.047941163182258606, -0.0030415449291467667, 0.004483033437281847, 0.044616010040044785, 0.04884263128042221, 0.0461905300617218, -0.007985229603946209, -0.026370830833911896, -0.01940014772117138, 0.02957826294004917, 0.0020718276500701904, -0.016114311292767525, 0.002238666405901313, -0.033218707889318466, 0.00007471693970728666, 0.03877311572432518, 0.015731418505311012, -0.05030812695622444, -0.020469611510634422, 0.0013158952351659536, 0.02868502214550972, -0.0004524204705376178, 0.009040242992341518, 0.02971426583826542, -0.018246004357933998, -0.010610410943627357, 0.012342255562543869, 0.06349098682403564, -0.026532649993896484, -0.06890778243541718, -0.005671478807926178, 0.02635897323489189, 0.043260879814624786, 0.008666510693728924, -0.04754464328289032, 0.010355224832892418, 0.02199331670999527, 0.035976823419332504, 0.056044936180114746, -0.028619641438126564, 0.02537444792687893, 0.015267380513250828, -0.03281677886843681, -0.028733596205711365, 0.004846808034926653, 0.03203710913658142, 0.014060183428227901, 0.01701163686811924, -0.01954827643930912, -0.025919334962964058, -0.04309455305337906, -0.008325482718646526, 0.019499467685818672, -0.016004761680960655, -0.015754446387290955, 0.04319847747683525, 0.021173469722270966, -0.02621660940349102, -0.006259223446249962, -0.02746465802192688, -0.03421946242451668, -0.02679024264216423, 0.01809343881905079, -0.004381163511425257, -0.0336012989282608, 0.00758789200335741, 0.01859390363097191, 0.014540056698024273, 0.019678523764014244, -0.014265320263803005, -0.011148336343467236, 0.03153183311223984, -0.023785673081874847, 0.008733799681067467, -0.0008247146033681929, -0.0016287798061966896, -0.0068409922532737255, -0.014216678217053413, 0.01691398210823536, -0.01609070785343647, -0.0007003261707723141, -0.012796849943697453, -0.006101842503994703, 0.061166953295469284, -0.028624651953577995, -0.009955579414963722, -0.062452834099531174, -0.029512088745832443, -0.06947264820337296, 0.015827566385269165, 0.01653037965297699, 0.00399294588714838, 0.013523790054023266, -0.002796366112306714, 0.026666885241866112, -0.014918947592377663, 0.014119892381131649, -0.015548987314105034, 0.05642295256257057, 0.04322250559926033, 0.015585837885737419, -0.01533277053385973, 0.015765270218253136 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
Chunked Feed Forward Layer in Reformer In Reformer, the LSH- or local self-attention layer is usually followed by a residual connection, which then defines the first part in a transformer block. For more detail on this please refer to this blog. The output of the first part of the transformer block, called normed self-attention output can be written as \( \mathbf{\overline{Z}} = \mathbf{Z} + \mathbf{X} \), with \( \mathbf{Z} \) being either \( \mathbf{Z}^{\text{LSH}} \) or \( \mathbf{Z}^\text{loc} \) in Reformer. For our example input \( \mathbf{x}1, \ldots, \mathbf{x}{16} \), we illustrate the normed self-attention output as follows. Now, the second part of a transformer block usually consists of two feed forward layers \( ^{1} \), defined as \( \text{Linear}{\text{int}}(\ldots) \) that processes \( \mathbf{\overline{Z}} \), to an intermediate output \( \mathbf{Y}{\text{int}} \) and \( \text{Linear}{\text{out}}(\ldots) \) that processes the intermediate output to the output \( \mathbf{Y}{\text{out}} \). The two feed forward layers can be defined by $$\mathbf{Y}{\text{out}} = \text{Linear}{\text{out}}(\mathbf{Y}\text{int}) = \text{Linear}{\text{out}}(\text{Linear}{\text{int}}(\mathbf{\overline{Z}})).$$ It is important to remember at this point that mathematically the output of a feed forward layer at position \( \mathbf{y}{\text{out}, i} \) only depends on the input at this position \( \mathbf{\overline{y}}{i} \). In contrast to the self-attention layer, every output \( \mathbf{y}{\text{out}, i} \) is therefore completely independent of all inputs \( \mathbf{\overline{y}}{j \ne i} \) of different positions. Let's illustrate the feed forward layers for \( \mathbf{\overline{z}}_1, \ldots, \mathbf{\overline{z}}{16} \). As can be depicted from the illustration, all input vectors \( \mathbf{\overline{z}}{i} \) are processed by the same feed forward layer in parallel. It becomes interesting when one takes a look at the output dimensions of the feed forward layers. In Reformer, the output dimension of \( \text{Linear}{\text{int}} \) is defined as config.feed_forward_size, e.g. \( d_{f} \), and the output dimension of \( \text{Linear}{\text{out}} \) is defined as config.hidden_size, i.e. \( d{h} \). The Reformer authors observed that in a transformer model the intermediate dimension \( d_{f} \) usually tends to be much larger than the output dimension \(^{2}\) \( d_{h} \). This means that the tensor \( \mathbf{\mathbf{Y}}\text{int} \) of dimension \( d{f} \times n \) allocates a significant amount of the total memory and can even become the memory bottleneck. To get a better feeling for the differences in dimensions let's picture the matrices \( \mathbf{Y}\text{int} \) and \( \mathbf{Y}\text{out} \) for our example. It is becoming quite obvious that the tensor \( \mathbf{Y}\text{int} \) holds much more memory ( \( \frac{d{f}}{d_{h}} \times n \) as much to be exact) than \( \mathbf{Y}{\text{out}} \). But, is it even necessary to compute the full intermediate matrix \( \mathbf{Y}\text{int} \) ? Not really, because relevant is only the output matrix \( \mathbf{Y}\text{out} \). To trade memory for speed, one can thus chunk the linear layers computation to only process one chunk at the time. Defining config.chunk_size_feed_forward as \( c{f} \), chunked linear layers are defined as \( \mathbf{Y}{\text{out}} = \left[\mathbf{Y}{\text{out}, 1: c_{f}}, \ldots, \mathbf{Y}{\text{out}, (n - c{f}): n}\right] \) with \( \mathbf{Y}{\text{out}, (c{f} * i): (i * c_{f} + i)} = \text{Linear}{\text{out}}(\text{Linear}{\text{int}}(\mathbf{\overline{Z}}{(c{f} * i): (i * c_{f} + i)})) \). In practice, it just means that the output is incrementally computed and concatenated to avoid having to store the whole intermediate tensor \( \mathbf{Y}{\text{int}} \) in memory. Assuming \( c{f}=1 \) for our example we can illustrate the incremental computation of the output for position \( i=9 \) as follows. By processing the inputs in chunks of size 1, the only tensors that have to be stored in memory at the same time are \( \mathbf{Y}\text{out} \) of a maximum size of \( 16 \times d{h} \), \( \mathbf{y}{\text{int}, i} \) of size \( d{f} \) and the input \( \mathbf{\overline{Z}} \) of size \( 16 \times d_{h} \), with \( d_{h} \) being config.hidden_size \(^{3}\). Finally, it is important to remember that chunked linear layers yield a mathematically equivalent output to conventional linear layers and can therefore be applied to all transformer linear layers. Making use of config.chunk_size_feed_forward therefore allows a better trade-off between memory and speed in certain use cases. --- \( {}^1 \) For a simpler explanation, the layer norm layer which is normally applied to \( \mathbf{\overline{Z}} \) before being processed by the feed forward layers is omitted for now. \( {}^2 \) In bert-base-uncased, e.g. the intermediate dimension \( d_{f} \) is with 3072 four times larger than the output dimension \( d_{h} \). \( {}^3 \) As a reminder, the output config.num_attention_heads is assumed to be 1 for the sake of clarity and illustration in this notebook, so that the output of the self-attention layers can be assumed to be of size config.hidden_size. More information on chunked linear / feed forward layers can also be found here on the 🤗Transformers docs.
[ 0.0481509305536747, -0.05313701927661896, 0.0364254005253315, -0.008632712997496128, 0.06278526782989502, 0.05288802832365036, -0.01869897171854973, -0.001526792417280376, 0.0051676323637366295, -0.008329213596880436, -0.07016532123088837, 0.014595766551792622, 0.013920745812356472, -0.03940584138035774, -0.05142868310213089, 0.06233706697821617, 0.04886973276734352, -0.04631976783275604, -0.08152512460947037, 0.0018423693254590034, 0.025482432916760445, -0.03907056525349617, 0.08748139441013336, 0.011475381441414356, -0.003423796035349369, -0.0659220889210701, -0.0029243994504213333, -0.00185209303162992, -0.0015257628401741385, 0.0643361359834671, -0.10240718722343445, -0.04221257194876671, 0.03239612653851509, -0.08879585564136505, 0.002483563032001257, -0.05977952107787132, -0.11188109219074249, -0.03224695101380348, 0.02332654595375061, -0.04029446840286255, -0.009516842663288116, 0.009895028546452522, -0.07936122268438339, 0.0052113719284534454, 0.0027545858174562454, -0.02324201725423336, -0.15827956795692444, 0.04605589807033539, -0.06148640438914299, 0.046298880130052567, -0.05440933257341385, 0.03752771019935608, -0.04660321772098541, 0.06964204460382462, -0.017533373087644577, -0.014493759721517563, -0.0066003138199448586, 0.05687559023499489, 0.03869609907269478, 0.06064788997173309, 0.04291112348437309, 0.0260685533285141, -0.03381691500544548, 0.0397411584854126, 0.035790447145700455, -0.039417069405317307, -0.005970153026282787, 0.010826731100678444, -0.07203932106494904, -0.07004614174365997, -0.02198478952050209, 0.01328924112021923, 0.03944927826523781, -0.023814234882593155, -0.0060242461040616035, 0.02036653831601143, 0.00754040339961648, 0.033568304032087326, 0.03457457944750786, -0.0008363896049559116, -0.021093865856528282, 0.04985213279724121, 0.03084672801196575, 0.08356564491987228, 0.03484019264578819, -0.04137202724814415, 0.021556587889790535, -0.08327704668045044, 0.0024161830078810453, 0.06498900800943375, -0.0798465758562088, -0.1176721379160881, 0.029848648235201836, -0.004807236138731241, 0.07163897901773453, -0.06526262313127518, 0.006565067917108536, 0.002023139502853155, -0.04940049350261688, 0.01954095996916294, -0.038605447858572006, -0.004910552408546209, 0.05292103812098503, 0.03496328741312027, -0.003590360516682267, -0.013804536312818527, -0.004526024684309959, -0.05492037907242775, -0.06015077978372574, -0.07900620251893997, 0.02900935709476471, 0.02756575308740139, 0.040949154645204544, 0.043474823236465454, -0.04428144544363022, -0.04621171951293945, -0.06258504092693329, 0.004859937354922295, 0.008070206269621849, -0.020675169304013252, -0.031842637807130814, 0.08522290736436844, 0.07964378595352173, 0.04355711489915848, 0.0878487378358841, -0.004442648496478796, -0.06595365703105927, 0.0532812662422657, -0.0010626250877976418, -0.03371564671397209, 0.024503245949745178, 0.04148246720433235, 0.0659148097038269, -0.0303729809820652, -0.03512195125222206, -0.10348781198263168, 0.024518214166164398, -0.05070234835147858, 0.002266248222440481, -0.023701509460806847, -0.04148813709616661, 0.019137470051646233, 0.040856100618839264, -0.0402681902050972, -0.008572571910917759, -0.09636808931827545, -0.04152320697903633, 0.049541182816028595, 0.04576103389263153, 0.04613461717963219, 0.018275290727615356, 0.013427654281258583, 0.004482035990804434, -0.025842182338237762, -0.012639450840651989, 0.035609543323516846, 0.05791321396827698, -0.01903325878083706, -0.09911134093999863, 0.02675984427332878, 0.03133537247776985, 0.038985010236501694, -0.0042708516120910645, 0.05476393923163414, 0.057225145399570465, -0.06859798729419708, 0.03503070026636124, -0.04288012906908989, 0.005725903902202845, -0.00045729565317742527, 0.046444714069366455, -0.02710350975394249, 0.02602674998342991, -0.03236201032996178, -0.022320594638586044, -0.008173326030373573, 0.030076736584305763, 0.07886365056037903, -0.05518803000450134, -0.02031000889837742, -0.044056009501218796, -0.005760579835623503, 0.040849704295396805, -0.034006137400865555, 0.011346397921442986, 0.02803974226117134, 0.048072341829538345, -0.0019412362016737461, -0.02947082743048668, 0.0796535313129425, -0.025087537243962288, 0.013600490987300873, 0.004129461944103241, 0.012515483424067497, 0.06992737203836441, -0.03256044164299965, -0.06046732887625694, 0.009187878109514713, 0.06241587921977043, 0.0847061425447464, 0.03366845101118088, 0.0444897897541523, -0.020261164754629135, 0.027318617329001427, -0.023146571591496468, -0.002351698698475957, 0.0319557711482048, -0.031794991344213486, 0.047536201775074005, -0.03758356347680092, -0.06534159183502197, -0.06368716806173325, 0.0369943268597126, -0.049784451723098755, -0.04278680309653282, -0.07570803910493851, 0.013839350081980228, -0.0009919236181303859, -0.028376789763569832, 0.0394245982170105, 0.12525896728038788, -0.010115730576217175, -0.025459403172135353, 0.033438585698604584, -0.03223472088575363, -0.03592720255255699, 0.05654638260602951, 0.00988087709993124, -0.04381871595978737, -0.07280789315700531, -0.009892718866467476, -0.05242054909467697, 0.03527803719043732, -0.0019532532896846533, -0.06718378514051437, -0.08577893674373627, -0.03300488740205765, 0.03917863965034485, 0.038049958646297455, -0.0934465155005455, -0.030385635793209076, 0.016399899497628212, 0.04254283756017685, -0.01043020375072956, 0.005593859124928713, 0.051636118441820145, -0.004088720306754112, 0.026933271437883377, -0.08733957260847092, 0.053039561957120895, -0.02090676687657833, 0.09352090954780579, 0.004758012481033802, -0.10178214311599731, -0.05954599753022194, -0.010384529829025269, 0.006240895017981529, -0.005545973312109709, 0.02117324434220791, 0.006269234232604504, 0.02394913136959076, 0.006433384492993355, -0.05910845845937729, -0.04846332594752312, -0.03780190274119377, -0.04486691206693649, 0.018432969227433205, 0.018889879807829857, 0.0019183555850759149, -0.005991535261273384, -0.007382513489574194, 0.03255947679281235, -0.03980477526783943, -0.014637090265750885, 0.045221298933029175, -0.01401611976325512, 0.03995037451386452, -0.03090200386941433, 0.006617333274334669, -0.02737029641866684, -0.009269017726182938, 0.0431755930185318, 0.019978033378720284, 0.04357783496379852, -0.0063530392944812775, -0.00802229717373848, 0.009648160077631474, 0.0234009250998497, -0.017855746671557426, -0.041433852165937424, -0.005944197531789541, 0.023984095081686974, -0.0016778215067461133, -0.045503731817007065, -0.017822211608290672, 0.05195343866944313, -0.013813331723213196, -0.005606485065072775, -0.0374174527823925, -0.007058131042867899, 0.01785125583410263, -0.0074221184477210045, 0.042459793388843536, 0.002866765484213829, -0.009877946227788925, -0.007447016891092062, -0.04181315004825592, 0.08428379893302917, -0.08255600184202194, -0.07948088645935059, -0.0115278922021389, 0.019625669345259666, -0.006587876472622156, -0.07171430438756943, -0.002995846327394247, 0.03238363191485405, 0.002424011705443263, -0.01915227249264717, 0.034028224647045135, -0.016159841790795326, -0.0024360395036637783, -0.008056762628257275, -0.0005164392059668899, -0.0058845155872404575, 0.027583356946706772, -0.04082277789711952, 0.02252565696835518, -0.015995372086763382, -0.012405076995491982, 0.01052903849631548, 0.0052320403046905994, 0.02834044024348259, 0.0019791265949606895, -0.004547405522316694, 0.0491771325469017, -0.025453772395849228, 0.03342587873339653, -0.022921133786439896, -0.02205592766404152, -0.023483825847506523, 0.006327885203063488, 0.024201607331633568, -0.024953249841928482, -0.014601008035242558, 0.02288278564810753, 0.025975065305829048, 0.045305412262678146, 0.05543235316872597, 0.05648709833621979, 0.039496369659900665, 0.03754030168056488, 0.0204581618309021, 0.016156749799847603, -0.018948204815387726, 0.015021213330328465, -0.033747319132089615, -0.0012248270213603973, -0.018765004351735115, 0.0008803645032458007, -0.027595143765211105, 0.035442061722278595, 0.017260489985346794, -0.052335456013679504, -0.004017484840005636, 0.02223639190196991, 0.0024146961513906717, 0.00044435347081162035, -0.018259571865200996, -0.07563566416501999, 0.022057773545384407, -0.05502908676862717, 0.012205297127366066, -0.025139058008790016, 0.014429125003516674, -0.01824094168841839, 0.015870921313762665, 0.020038524642586708, 0.03494218736886978, 0.0047144475392997265, 0.005035600159317255, -0.0026379511691629887, -0.0018100225133821368, -0.027729155495762825, -0.009429353289306164, -0.043804001063108444, -0.005975338164716959, 0.05278968811035156, 0.021663060411810875, -0.02531394548714161, 0.019468562677502632, -0.012486462481319904, 0.040661897510290146, -0.00543988449499011, 0.04933436959981918, 0.01721482165157795, -0.018080245703458786, 0.04160628467798233, 0.008369972929358482, 0.039171550422906876, -0.013141456991434097, 0.02961721085011959, -0.020610883831977844, -0.03050255961716175, 0.032299913465976715, -0.011989682912826538, -0.006653512362390757, 0.0035152139607816935, 0.03561186417937279, 0.04709431156516075, -0.04010302573442459, -0.021479660645127296, 0.013146083801984787, 0.04795582965016365, 0.006390905473381281, -0.055044546723365784, 0.003011946799233556, 0.0532761886715889, 0.008059336803853512, 0.019244438037276268, -0.03704514726996422, -0.0260486900806427, 0.0316823348402977, 0.03089243546128273, 0.035090140998363495, -0.07167719304561615, -0.06893963366746902, -0.024298522621393204, -0.010844475589692593, 0.0046935910359025, 0.0032281409949064255, 0.027361489832401276, -0.05846899747848511, 0.02398349530994892, -0.017141100019216537, 0.03625813499093056, 0.04502987489104271, 0.004157486837357283, -0.005989871919155121, -0.018184304237365723, 0.0032456673216074705, 0.036705486476421356, -0.02607865445315838, -0.005067408550530672, 0.04851081967353821, 0.0027262642979621887, 0.029243826866149902, -0.021137457340955734, -0.032325804233551025, -0.06019393727183342, 0.02973109297454357, 0.021932531148195267, -0.032898083329200745, 0.052010707557201385, 0.014433350414037704, -0.006072295363992453, 0.04003192111849785, -0.024869898334145546, 0.010495462454855442, 0.04353444650769234, 0.025201695039868355, -0.06938394159078598, 0.010123483836650848, 0.0272412970662117, -0.0007670584600418806, -0.01565193198621273, 0.00022444751812145114, 0.04089449718594551, 0.021449489519000053, -0.008004735223948956, 0.019807564094662666, -0.06545154750347137, 0.03786586597561836, 0.03163006901741028, -0.007554812356829643, -0.047955892980098724, -0.0365695022046566, 0.02306292951107025, -0.022849109023809433, -0.037478845566511154, -0.013615456409752369, 0.006097084376960993, -0.0424923375248909, 0.001760822138749063, 0.014547298662364483, -0.01699112541973591, -0.031318120658397675, 0.008706523105502129, -0.007889733649790287, -0.023578302934765816, -0.009717586450278759, 0.06193040311336517, -0.004231968894600868, 0.013540824875235558, 0.0594203919172287, 0.01990886591374874, 0.03283022716641426, -0.013727807439863682, 0.051177896559238434, 0.05944228917360306, -0.03305332362651825, -0.004879552870988846, 0.03006099723279476, 0.008105039596557617, 0.01527542807161808, 0.052485156804323196, -0.00016111494915094227, -0.008096855133771896, -0.020558860152959824, 0.02197469398379326, 0.06169769540429115, -0.009230821393430233, -0.0154020506888628, 0.004170435946434736, -0.011938544921576977, -0.0006554013234563172, 0.023873910307884216, -0.02215571328997612, -0.022172976285219193, 0.040232203900814056, 0.013458049856126308, -0.0016424754867330194, -0.002230297541245818, -0.004668911918997765, -0.03400210663676262, -0.003609730862081051, -0.011096028611063957, 0.010668189264833927, -0.000521420210134238, -0.0012728080619126558, 0.01936940662562847, -0.026675241068005562, 0.005182499531656504, -0.0027865557931363583, -0.04299602657556534, -0.0002243467461084947, 0.02343173325061798, 0.0025691722985357046, 0.004356248304247856, 0.03487910330295563, -0.008125528693199158, 0.004128267057240009, -0.02191866561770439, -0.01995251514017582, 0.016087137162685394, -0.07074199616909027, 0.044460833072662354, 0.0023553522769361734, 0.0012981795007362962, 0.006781320553272963, 0.030905375257134438, -0.06011870130896568, 0.034532807767391205, 0.009503279812633991, 0.025402050465345383, 0.0593099445104599, -0.039413370192050934, -0.010882406495511532, -0.001653237035498023, 0.043073058128356934, -0.02988658845424652, -0.008261180482804775, -0.0028778051491826773, 0.010462467558681965, -0.00011511243064887822, 0.041770704090595245, 0.033076394349336624, 0.03148448467254639, 0.04119215905666351, 0.002769269049167633, -0.051460884511470795, -0.02986389398574829, -0.031048830598592758, -0.0007594116032123566, 0.04354386404156685, -0.04491053521633148, -0.0180173609405756, -0.01874435879290104, 0.03380661457777023, 0.0116470567882061, -0.016100261360406876, -0.028401289135217667, 0.003597007133066654, -0.028773920610547066, -0.0035344890784472227, 0.018835751339793205, 0.03253018110990524, 0.03904815763235092, 0.0050879307091236115, 0.04038155823945999, -0.009710734710097313, 0.048386480659246445, 0.03099961392581463, 0.03554636985063553, -0.015097529627382755, 0.026259826496243477, 0.011979504488408566, -0.00181284558493644, 0.037179283797740936, 0.004400438163429499, 0.0185745507478714, -0.03548339381814003, -0.011336625553667545, -0.011761358939111233, 0.038781072944402695, 0.007355261128395796, -0.04302651807665825, 0.04090588167309761, -0.012140928767621517, 0.008662991225719452, 0.014416038990020752, -0.009013256058096886, 0.012672625482082367, -0.013651727698743343, 0.04547985643148422, 0.00004864836228080094, 0.042384542524814606, 0.04038231447339058, -0.016789117828011513, -0.0276980921626091, 0.02699417807161808, -0.0022001932375133038, 0.03445187956094742, 0.016505837440490723, -0.03137775510549545, 0.03269784152507782, -0.014489073306322098, -0.02620481140911579, 0.050871122628450394, -0.004635850433260202, -0.04804559424519539, -0.012363848276436329, -0.022233974188566208, 0.00227047735825181, -0.04439150169491768, 0.005530871916562319, -0.006557140965014696, -0.0010958998464047909, 0.004934475291520357, 0.010814093984663486, 0.00034909724490717053, -0.021184349432587624, 0.019534649327397346, -0.016294071450829506, 0.014225338585674763, 0.009188681840896606, 0.005710987839847803, 0.013059886172413826, -0.036672964692115784, -0.042605943977832794, 0.057558294385671616, -0.01261966209858656, 0.05807386338710785, 0.05377213656902313, -0.03567924350500107, 0.03652392327785492, -0.03533754125237465, -0.016593527048826218, 0.04761531576514244, 0.015170494094491005, 0.0032471006270498037, -0.04207715392112732, -0.008545138873159885, 0.005688303150236607, 0.03143329918384552, -0.00292549142614007, 0.010186895728111267, 0.002177410526201129, 0.007352767512202263, -0.006755715701729059, 0.04249062389135361, -0.008853640407323837, -0.02308199554681778, -0.026308342814445496, 0.002817881992086768, 0.001627979101613164, 0.0018867218168452382, -0.03771957382559776, -0.01626608520746231, -0.01267139334231615, -0.008495301008224487, -0.02304891310632229, -0.003223285311833024, -0.03801324963569641, -0.011949156410992146, 0.02358299493789673, 0.024110646918416023, -0.03671899810433388, -0.027861671522259712, -0.0025962877552956343, -0.0006823631701990962, -0.007702382281422615, 0.06688392907381058, 0.035180557519197464, 0.03244388476014137, -0.02701897919178009, 0.024227386340498924, -0.00762570183724165, -0.03653324022889137, -0.031674016267061234, -0.03388095274567604, 0.0022754191886633635, 0.018480295315384865, 0.019099771976470947, 0.027716699987649918, -0.038912396878004074, 0.05263552442193031, -0.003015439258888364, -0.0033356461208313704, -0.0024244755040854216, 0.028663834556937218, 0.03496207669377327, -0.035203300416469574, 0.00011508278112160042, 0.014209924265742302, 0.0033148061484098434, -0.027160679921507835, 0.004698034375905991, 0.013242458924651146, 0.03699803724884987, -0.02134060487151146, 0.04553563892841339, -0.004691628739237785, 0.030451076105237007, -0.03598328307271004, -0.03893154114484787, 0.0013795054983347654, 0.01751764304935932, -0.014816777780652046, 0.021033931523561478, 0.0002598599239718169, 0.02434816211462021, 0.04099879041314125, 0.015254352241754532, 0.01371532492339611, 0.011758948676288128, 0.004384542815387249, 0.03573594242334366, -0.021957406774163246, 0.01077810488641262, 0.005699122324585915, 0.061032749712467194, 0.024752533063292503, 0.01985817588865757, 0.04812409728765488, 0.014240102842450142, 0.0186716727912426, 0.015668869018554688, 0.016374556347727776, -0.0013063553487882018, -0.06978055834770203, 0.027439171448349953, 0.017837656661868095, -0.004885585978627205, 0.013518755324184895, -0.031136177480220795, 0.037528060376644135, 0.02568807639181614, 0.00432145269587636, 0.019678324460983276, 0.006924797780811787, -0.0490475632250309, 0.04128486290574074, 0.03421713039278984, 0.015130567364394665, -0.04857005551457405, 0.04462888464331627, -0.011753601022064686, 0.022050736472010612 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
Benchmark Let's test how much memory can be saved by using chunked feed forward layers. #@title Installs and Imports # pip installs !pip -qq install git+https://github.com/huggingface/transformers.git !pip install -qq py3nvml from transformers import ReformerConfig, PyTorchBenchmark, PyTorchBenchmarkArguments Building wheel for transformers (setup.py) ... [?25l[?25hdone First, let's compare the default google/reformer-enwik8 model without chunked feed forward layers to the one with chunked feed forward layers. config_no_chunk = ReformerConfig.from_pretrained("google/reformer-enwik8") # no chunk config_chunk = ReformerConfig.from_pretrained("google/reformer-enwik8", chunk_size_feed_forward=1) # feed forward chunk benchmark_args = PyTorchBenchmarkArguments(sequence_lengths=[1024, 2048, 4096], batch_sizes=[8], models=["Reformer-No-Chunk", "Reformer-Chunk"], no_speed=True, no_env_print=True) benchmark = PyTorchBenchmark(configs=[config_no_chunk, config_chunk], args=benchmark_args) result = benchmark.run() 1 / 2 Doesn't fit on GPU. CUDA out of memory. Tried to allocate 2.00 GiB (GPU 0; 11.17 GiB total capacity; 7.85 GiB already allocated; 1.74 GiB free; 9.06 GiB reserved in total by PyTorch) 2 / 2 Doesn't fit on GPU. CUDA out of memory. Tried to allocate 2.00 GiB (GPU 0; 11.17 GiB total capacity; 7.85 GiB already allocated; 1.24 GiB free; 9.56 GiB reserved in total by PyTorch) ==================== INFERENCE - MEMORY - RESULT ==================== -------------------------------------------------------------------------------- Model Name Batch Size Seq Length Memory in MB -------------------------------------------------------------------------------- Reformer-No-Chunk 8 1024 4281 Reformer-No-Chunk 8 2048 7607 Reformer-No-Chunk 8 4096 N/A Reformer-Chunk 8 1024 4309 Reformer-Chunk 8 2048 7669 Reformer-Chunk 8 4096 N/A -------------------------------------------------------------------------------- Interesting, chunked feed forward layers do not seem to help here at all. The reason is that config.feed_forward_size is not sufficiently large to make a real difference. Only at longer sequence lengths of 4096, a slight decrease in memory usage can be seen. Let's see what happens to the memory peak usage if we increase the size of the feed forward layer by a factor of 4 and reduce the number of attention heads also by a factor of 4 so that the feed forward layer becomes the memory bottleneck. config_no_chunk = ReformerConfig.from_pretrained("google/reformer-enwik8", chunk_size_feed_forward=0, num_attention_{h}eads=2, feed_forward_size=16384) # no chuck config_chunk = ReformerConfig.from_pretrained("google/reformer-enwik8", chunk_size_feed_forward=1, num_attention_{h}eads=2, feed_forward_size=16384) # feed forward chunk benchmark_args = PyTorchBenchmarkArguments(sequence_lengths=[1024, 2048, 4096], batch_sizes=[8], models=["Reformer-No-Chunk", "Reformer-Chunk"], no_speed=True, no_env_print=True) benchmark = PyTorchBenchmark(configs=[config_no_chunk, config_chunk], args=benchmark_args) result = benchmark.run() 1 / 2 2 / 2 ==================== INFERENCE - MEMORY - RESULT ==================== -------------------------------------------------------------------------------- Model Name Batch Size Seq Length Memory in MB -------------------------------------------------------------------------------- Reformer-No-Chunk 8 1024 3743 Reformer-No-Chunk 8 2048 5539 Reformer-No-Chunk 8 4096 9087 Reformer-Chunk 8 1024 2973 Reformer-Chunk 8 2048 3999 Reformer-Chunk 8 4096 6011 -------------------------------------------------------------------------------- Now a clear decrease in peak memory usage can be seen for longer input sequences. As a conclusion, it should be noted chunked feed forward layers only makes sense for models having few attention heads and large feed forward layers.
[ 0.017997555434703827, 0.006843681447207928, 0.027014032006263733, 0.03883929178118706, -0.009731401689350605, 0.054391395300626755, 0.03645608201622963, 0.019851846620440483, -0.052488211542367935, 0.019380394369363785, -0.05633849650621414, 0.06368027627468109, -0.025584330782294273, 0.018910525366663933, 0.03665976971387863, -0.0071102348156273365, 0.0607491098344326, -0.021104319021105766, -0.08345124870538712, 0.03259855881333351, 0.05265575647354126, -0.062415383756160736, 0.07711319625377655, -0.0013280302518978715, -0.004041331820189953, -0.03548789024353027, 0.02778804861009121, -0.02774503454566002, -0.000546766328625381, -0.005553350318223238, -0.16136054694652557, -0.0022118622437119484, -0.013757333159446716, -0.05613637715578079, 0.023227103054523468, -0.024175141006708145, -0.09627921879291534, 0.06822699308395386, 0.06916532665491104, -0.004914042539894581, -0.0051503474824130535, 0.036995500326156616, -0.04301528260111809, 0.027028217911720276, 0.0019502934301272035, 0.031662631779909134, -0.08622978627681732, 0.06371577084064484, -0.06064440682530403, -0.021216008812189102, -0.08686862885951996, 0.0115570779889822, -0.024751972407102585, 0.009939339943230152, -0.00982241053134203, 0.04714648798108101, 0.028309471905231476, -0.029772423207759857, 0.01762309856712818, 0.028734833002090454, 0.04405512660741806, 0.036169249564409256, 0.044603925198316574, 0.05422541871666908, -0.015815474092960358, -0.002979285316541791, -0.02292540669441223, 0.0877079963684082, -0.0448031984269619, -0.02211780846118927, 0.00925514567643404, -0.07640133798122406, 0.03374745324254036, 0.027087919414043427, -0.040451619774103165, -0.011621365323662758, 0.0029627373442053795, -0.016985120251774788, 0.08550327271223068, 0.052527036517858505, -0.007755274418741465, 0.07145465910434723, -0.020134633406996727, -0.01923462748527527, 0.04917444661259651, -0.01050474215298891, 0.05686956271529198, -0.10172950476408005, -0.04976052790880203, 0.060375772416591644, -0.04782131314277649, -0.04584037512540817, -0.008983380161225796, -0.027028167620301247, -0.00435247179120779, 0.0012744374107569456, -0.028011808171868324, 0.0041576712392270565, -0.00019962614169344306, -0.010438445955514908, -0.02474086545407772, -0.11125989258289337, -0.002270366996526718, -0.017965564504265785, -0.0012173750437796116, 0.04721007123589516, -0.06736487150192261, -0.1426551342010498, 0.02611032873392105, 0.004107387736439705, 0.02317105419933796, 0.021912388503551483, -0.046903762966394424, 0.01634698361158371, -0.0905691385269165, -0.022812528535723686, -0.07972469925880432, -0.02374989539384842, -0.006643954198807478, 0.05059542879462242, 0.0007868111133575439, 0.07165998220443726, 0.050794266164302826, -0.018015973269939423, 0.004509703256189823, 0.010648387484252453, 0.028314733877778053, 0.03261062130331993, 0.0018126729410141706, -0.0013444921933114529, 0.05666143074631691, -0.020506450906395912, 0.06585052609443665, -0.011744343675673008, -0.04963319003582001, -0.08213602751493454, 0.014925592578947544, -0.0006938821170479059, -0.03988085314631462, -0.018193500116467476, -0.08316486328840256, 0.0725751742720604, 0.025843463838100433, -0.06817040592432022, 0.06265927851200104, -0.039712827652692795, -0.08171897381544113, 0.0601157620549202, 0.029736096039414406, -0.051613014191389084, -0.12963277101516724, 0.07156205177307129, -0.05649341270327568, -0.019685223698616028, 0.002191288862377405, 0.060038790106773376, -0.05319865047931671, -0.025752708315849304, -0.052010636776685715, -0.005153871141374111, -0.037235137075185776, 0.056572671979665756, -0.0038574249483644962, -0.015495373867452145, 0.0040161460638046265, -0.007640767376869917, 0.04542466625571251, -0.030881671234965324, -0.05089528113603592, 0.0012065238552168012, -0.00484542828053236, -0.04655758664011955, -0.0034532882273197174, -0.03634291887283325, 0.00557918893173337, 0.01663254201412201, 0.039256542921066284, 0.02655167505145073, -0.019495312124490738, -0.10036743432283401, -0.06613977998495102, 0.024824462831020355, 0.02233835868537426, 0.05277702957391739, 0.02887888438999653, -0.051877401769161224, -0.0042369128204882145, -0.0377994142472744, -0.03564407676458359, 0.05410776287317276, 0.00824730284512043, -0.057492855936288834, 0.08976458758115768, -0.022296810522675514, 0.08261546492576599, -0.00038493587635457516, 0.03749818727374077, 0.03353297710418701, 0.08423255383968353, 0.07253243029117584, -0.026075368747115135, 0.0606098435819149, 0.03539345785975456, 0.01258830912411213, -0.038469478487968445, -0.013358603231608868, -0.024962635710835457, -0.06483132392168045, 0.007138567510992289, 0.01838315650820732, 0.07439155131578445, -0.05771758779883385, 0.07304872572422028, -0.015913652256131172, -0.006256716791540384, -0.06924331188201904, -0.030368035659193993, -0.022433346137404442, 0.002689674496650696, 0.009136316366493702, 0.11560627818107605, 0.013769082725048065, -0.018988708034157753, -0.04523163661360741, 0.02261579968035221, 0.005311958957463503, -0.013494246639311314, 0.0440543033182621, 0.03407015651464462, -0.0878191590309143, -0.056462839245796204, -0.04502526670694351, -0.044596340507268906, 0.08515646308660507, -0.037340376526117325, -0.08604555577039719, -0.03285032883286476, 0.0611707866191864, 0.03355589509010315, -0.03886406868696213, -0.046209026128053665, 0.018856272101402283, 0.07313226908445358, 0.027262695133686066, 0.050042301416397095, 0.015338566154241562, -0.030646534636616707, 0.007694046013057232, -0.046195223927497864, -0.059953778982162476, -0.023933876305818558, 0.038480132818222046, 0.027125217020511627, -0.03678053990006447, -0.023810693994164467, 0.050501033663749695, -0.00880526751279831, -0.023195747286081314, -0.001733658486045897, 0.047674573957920074, 0.007321348879486322, 0.04875819757580757, -0.04892684519290924, -0.024585997685790062, 0.006971707567572594, -0.008022683672606945, -0.01184171624481678, -0.03267030045390129, 0.01800786890089512, -0.051465827971696854, 0.011574631556868553, -0.014485186897218227, 0.03191327303647995, 0.022450240328907967, 0.025318508967757225, 0.023726899176836014, 0.01817336678504944, -0.03555662930011749, -0.011733808554708958, -0.012270101346075535, -0.011221899650990963, -0.021268576383590698, -0.011237959377467632, 0.030154967680573463, -0.04227761551737785, 0.05485743284225464, 0.022145241498947144, -0.017787927761673927, -0.036252789199352264, 0.03300409018993378, 0.0309540294110775, 0.02065235562622547, 0.03899206593632698, -0.05084586888551712, -0.0010528063867241144, 0.03249644860625267, -0.04224894568324089, -0.07616405189037323, -0.007356703281402588, 0.025802381336688995, -0.029324401170015335, -0.0008409227593801916, -0.024044683203101158, -0.03592231497168541, -0.011460192501544952, -0.00381217198446393, -0.013029821217060089, 0.04007291421294212, -0.08033592253923416, -0.009374898858368397, 0.0026149561163038015, 0.01718144305050373, 0.004082781262695789, -0.03760991990566254, 0.005875641480088234, 0.020525120198726654, 0.010829654522240162, 0.02436853013932705, 0.023331135511398315, -0.004423634149134159, -0.008784670382738113, 0.02586538717150688, -0.02913099341094494, -0.010801071301102638, 0.048967838287353516, -0.013391714543104172, 0.06432337313890457, -0.037230558693408966, 0.004066881723701954, -0.0011796144535765052, -0.0020200833678245544, 0.041187215596437454, -0.014751645736396313, 0.0035580871626734734, 0.022493522614240646, -0.006309663876891136, 0.056922733783721924, -0.04440530762076378, -0.039511263370513916, -0.07157823443412781, -0.009552915580570698, 0.020521588623523712, -0.02355188876390457, -0.037781015038490295, -0.03561493009328842, 0.011515021324157715, 0.04288923740386963, 0.019696172326803207, 0.03839339688420296, -0.021491562947630882, 0.052388645708560944, 0.03465835377573967, 0.04606018587946892, 0.006725392770022154, 0.008828368969261646, -0.028483573347330093, 0.04658212512731552, -0.024010242894291878, -0.008509828709065914, -0.02095506526529789, 0.016598353162407875, 0.06324416399002075, -0.002736863447353244, -0.014680351130664349, -0.00027114167460240424, 0.0205658208578825, -0.0007085052202455699, -0.02004953660070896, -0.055931705981492996, 0.038318175822496414, -0.020684387534856796, 0.01844959147274494, -0.017484428361058235, 0.015374535694718361, -0.027223659679293633, -0.02758242003619671, -0.03077973611652851, 0.017333269119262695, -0.034427300095558167, 0.036873042583465576, 0.013611448928713799, 0.00821059849113226, -0.04641927406191826, 0.0034666371066123247, -0.054351843893527985, -0.029142208397388458, 0.03644606098532677, 0.03371257334947586, -0.017881013453006744, -0.01890181563794613, -0.0444784052670002, 0.01390467956662178, 0.012184260413050652, 0.04410756751894951, -0.007607597392052412, -0.041266556829214096, 0.05678320676088333, 0.018370872363448143, 0.02746504172682762, -0.015838969498872757, -0.003132477169856429, 0.009791865944862366, -0.0002584906469564885, -0.016508258879184723, 0.03056812472641468, 0.030527658760547638, -0.035372816026210785, 0.03442211449146271, 0.007623719051480293, -0.0747464969754219, 0.002292380202561617, 0.005339724477380514, -0.025218313559889793, 0.008479704149067402, -0.03037640079855919, -0.01047568116337061, 0.010565663687884808, 0.014272389002144337, -0.0007984542171470821, -0.02887594886124134, -0.018811704590916634, 0.006289443466812372, 0.023893840610980988, 0.07870832830667496, 0.003414687467738986, -0.020069876685738564, 0.003972297068685293, 0.016815723851323128, -0.016360372304916382, 0.0274336114525795, 0.014116900973021984, -0.03243772312998772, 0.04074309021234512, 0.0006881463341414928, 0.007804747670888901, -0.016508931294083595, -0.036168284714221954, -0.02109149843454361, -0.03958754986524582, 0.0002885641297325492, 0.02690701000392437, -0.0020478523802012205, -0.028794405981898308, 0.023265311494469643, -0.04053410515189171, -0.024624286219477654, 0.007209079805761576, -0.024586305022239685, -0.08896663039922714, 0.008479306474328041, 0.02853607013821602, -0.017345108091831207, -0.0032745986245572567, 0.027522306889295578, 0.00907993782311678, 0.04207400977611542, -0.04020697623491287, 0.020443757995963097, -0.009856955148279667, -0.01944417506456375, -0.03519497811794281, 0.04161668196320534, 0.049727264791727066, 0.028415298089385033, -0.028094233945012093, -0.00495423749089241, 0.012418992817401886, 0.001053048181347549, -0.02447613514959812, -0.018284272402524948, -0.028616303578019142, 0.018025515601038933, 0.0037977525498718023, 0.0468074195086956, 0.00512965302914381, -0.05722545087337494, 0.024633854627609253, -0.022474782541394234, 0.04636278748512268, 0.02400345727801323, -0.0042766984552145, 0.0187990739941597, 0.016563797369599342, 0.0522804781794548, 0.0024815439246594906, -0.02004883624613285, 0.02123909816145897, 0.03807816654443741, 0.01950277015566826, -0.014667927287518978, 0.016847066581249237, -0.01664559915661812, 0.017616862431168556, 0.06990783661603928, 0.0555504709482193, 0.11669767647981644, -0.027532804757356644, 0.036905329674482346, 0.014845979399979115, 0.0015094688860699534, 0.03485720604658127, -0.03795277327299118, 0.03156442940235138, -0.002010887721553445, 0.02027101255953312, -0.022781774401664734, 0.006870508659631014, -0.01885111629962921, 0.02653106115758419, 0.048933371901512146, -0.01879740320146084, -0.010438330471515656, -0.004560037516057491, 0.020886685699224472, -0.009938657283782959, -0.012924726121127605, 0.005368722602725029, -0.04547945410013199, 0.026545526459813118, -0.010185398161411285, -0.009880658239126205, 0.006645044777542353, -0.010097785852849483, 0.024994540959596634, -0.0028774382080882788, 0.03328128904104233, 0.026386139914393425, 0.01839422807097435, -0.0205319132655859, 0.01253032311797142, 0.006421245168894529, -0.040771011263132095, 0.011710151098668575, -0.028594210743904114, -0.0077565331012010574, -0.03299344703555107, -0.0015188943361863494, 0.01356610655784607, 0.009947028942406178, 0.007838168181478977, -0.004802945535629988, 0.016200795769691467, 0.0038553187623620033, 0.017018407583236694, 0.0030953090172261, 0.04110840708017349, 0.018000969663262367, -0.03740895539522171, -0.0016464911168441176, -0.005224210675805807, -0.07333684712648392, 0.009765240363776684, -0.025689179077744484, 0.013229737989604473, 0.06657525897026062, -0.02796197310090065, 0.0029436347540467978, 0.003649552119895816, 0.01649370789527893, -0.010064302943646908, 0.01948167011141777, -0.03428078442811966, 0.02315676026046276, -0.07972940057516098, -0.0022068002726882696, -0.00404521357268095, 0.017860041931271553, 0.0428001806139946, 0.02143242210149765, -0.005588376894593239, 0.01978886127471924, 0.005429673008620739, -0.008955850265920162, 0.04014110565185547, -0.02161814086139202, -0.059612080454826355, 0.00031658148509450257, 0.02371188811957836, -0.032610587775707245, 0.02176382765173912, -0.027186721563339233, 0.035478103905916214, 0.018941771239042282, 0.020355569198727608, 0.0320206955075264, 0.02347520925104618, -0.00031945278169587255, 0.0627782791852951, 0.04593578726053238, 0.04381201043725014, 0.0490913987159729, 0.01141699030995369, -0.003063106443732977, -0.030640989542007446, 0.05235258862376213, -0.014935694634914398, 0.00044773801346309483, 0.04971122369170189, 0.013873729854822159, 0.026728766039013863, -0.015430803410708904, -0.012025432661175728, -0.019183987751603127, 0.024981994181871414, 0.03636704012751579, 0.02802891843020916, 0.010474046692252159, -0.013997885398566723, 0.01928672567009926, 0.007820209488272667, -0.00158216233830899, 0.008268432691693306, 0.017043353989720345, 0.016556400805711746, 0.0048705763183534145, 0.03147820755839348, 0.03433019295334816, 0.020925035700201988, -0.013294747099280357, 0.03405525162816048, -0.010586886666715145, 0.02105860225856304, 0.02080775983631611, -0.017582708969712257, -0.010906604118645191, -0.007649714592844248, -0.018118418753147125, 0.030804118141531944, -0.012624014168977737, 0.015874410048127174, 0.0011383333476260304, 0.021711276844143867, 0.0020916168577969074, -0.0050899372436106205, 0.004511312581598759, 0.0007856503361836076, -0.002529130782932043, -0.02564285881817341, -0.05229026824235916, 0.009838445112109184, -0.04534159600734711, -0.05184462293982506, 0.002789524383842945, 0.027671296149492264, -0.031171392649412155, 0.008066731505095959, -0.012290382757782936, -0.004032203461974859, 0.01028844341635704, 0.03902135416865349, -0.04803317412734032, 0.021943770349025726, -0.027415655553340912, -0.031663499772548676, 0.020865829661488533, -0.036912426352500916, 0.0194022785872221, 0.038561075925827026, -0.009634038433432579, 0.022961189970374107, -0.02292216755449772, 0.023216284811496735, -0.016046661883592606, -0.02440832369029522, 0.06840841472148895, 0.009251422248780727, -0.021177662536501884, -0.001214998192153871, 0.05015074461698532, 0.05574196204543114, 0.024230781942605972, -0.016044167801737785, -0.024559613317251205, 0.0029343566857278347, -0.04879524186253548, -0.02163478173315525, 0.02841617353260517, 0.00891506765037775, -0.008860865607857704, -0.019951293244957924, -0.060084354132413864, -0.003967157565057278, -0.01739923097193241, -0.022687265649437904, 0.018598787486553192, -0.017896736040711403, 0.013861916027963161, -0.010248290374875069, 0.027876637876033783, 0.020552678033709526, 0.01853593997657299, 0.037175919860601425, -0.005157381296157837, 0.016013676300644875, -0.022941946983337402, 0.010013745166361332, -0.04911182075738907, -0.024235475808382034, -0.00835608970373869, -0.016301732510328293, -0.0024387992452830076, 0.025232218205928802, -0.00421435572206974, 0.033464740961790085, -0.023593196645379066, 0.017495758831501007, 0.0006181731005199254, 0.025461450219154358, 0.021699944511055946, 0.015446996316313744, 0.007915101014077663, 0.03836589306592941, 0.0671120285987854, 0.02873552031815052, -0.04969180002808571, 0.0010541575029492378, -0.013615201227366924, -0.01058869156986475, 0.053547803312540054, 0.021051490679383278, 0.027763908728957176, -0.04349430650472641, 0.0330800861120224, -0.011424420401453972, -0.053936004638671875, 0.007264645770192146, 0.017432300373911858, 0.011221680790185928, 0.007131234742701054, 0.001681643771007657, 0.007158601190894842, 0.016517549753189087, 0.06939622759819031, 0.012094049714505672, -0.02772440016269684, -0.006911318749189377, 0.044435057789087296, -0.04352720454335213, 0.008764227852225304, 0.01873517781496048, 0.037001535296440125, 0.004192187450826168, 0.014050479047000408, 0.053530532866716385, 0.04894831404089928, 0.03977641463279724, -0.005030261818319559, 0.04309407249093056, -0.059762001037597656, -0.05788552016019821, 0.000685223494656384, 0.04049639776349068, -0.011389183811843395, -0.03353460505604744, 0.010629726573824883, -0.009661559946835041, 0.029493434354662895, -0.0035429929848760366, -0.011620087549090385, -0.016394896432757378, -0.009899585507810116, 0.023005176335573196, -0.031351055949926376, -0.009704239666461945, 0.013811958022415638, 0.017008084803819656, -0.04285398870706558, 0.02312745898962021 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
# The Reformer - Pushing the limits of language modeling
[ 0.023895688354969025, 0.007616574876010418, 0.02928808704018593, -0.020240528509020805, 0.08667784184217453, 0.07272898405790329, 0.034057166427373886, -0.006437832489609718, -0.02394263818860054, -0.0053658317774534225, -0.024057067930698395, 0.00852915644645691, -0.014736661687493324, 0.07492131739854813, 0.04368617385625839, 0.013314398005604744, 0.02736341394484043, -0.0565049909055233, -0.007119208574295044, -0.021720876917243004, -0.04293249174952507, -0.05179402604699135, 0.0699969157576561, -0.02556430920958519, -0.0030214593280106783, -0.010179230943322182, 0.026356291025877, -0.03895000368356705, -0.06057409942150116, 0.022823652252554893, -0.08586668968200684, -0.015495022758841515, -0.025040272623300552, -0.004577880725264549, -0.014887193217873573, -0.013096684589982033, -0.11002976447343826, 0.028521671891212463, -0.01132320798933506, -0.030220886692404747, -0.04666934162378311, -0.02788546308875084, 0.008676552213728428, -0.0189780592918396, -0.010958447121083736, 0.005742300301790237, -0.2733168601989746, 0.08464521914720535, -0.0294809453189373, -0.026654647663235664, -0.08362177014350891, 0.060892365872859955, 0.0014050742611289024, 0.03800761327147484, -0.05240882933139801, -0.03206095099449158, 0.0025854601990431547, -0.05241335555911064, 0.003987484611570835, -0.0408010333776474, 0.0678502544760704, 0.042348477989435196, 0.027121124789118767, -0.06002865359187126, 0.011673239059746265, 0.0631178766489029, -0.019613435491919518, 0.01847437396645546, -0.10118456929922104, -0.007013348396867514, 0.003629547543823719, -0.0213667880743742, -0.048809293657541275, -0.04178775101900101, 0.06887249648571014, -0.06481924653053284, -0.016610128805041313, 0.09439001232385635, 0.06192128360271454, 0.06522458046674728, -0.04260006174445152, 0.01960691623389721, 0.12844988703727722, 0.0784049928188324, 0.03748662397265434, -0.01868561841547489, 0.06550639122724533, -0.04176929220557213, 0.02472631074488163, 0.042202647775411606, -0.026353733614087105, -0.1153440922498703, 0.01909475401043892, -0.0011846169363707304, 0.058487243950366974, -0.021224401891231537, 0.0376775786280632, 0.03204751014709473, 0.005628384184092283, 0.024477330967783928, -0.024000920355319977, 0.02929350733757019, 0.05869396775960922, 0.0006388421752490103, -0.025191394612193108, 0.035410184413194656, 0.003630557795986533, -0.04530838131904602, -0.04780252277851105, 0.013395395129919052, 0.05117066204547882, 0.06300060451030731, 0.024546543136239052, 0.009610986337065697, -0.028810912743210793, 0.04220318794250488, 0.06147708371281624, -0.034089479595422745, -0.003513182746246457, 0.026132699102163315, 0.0291092861443758, 0.056715693324804306, 0.08920250087976456, 0.04333611950278282, 0.02127997577190399, 0.044854581356048584, 0.0004320502339396626, 0.02659449726343155, -0.01854122057557106, -0.1042022705078125, 0.026767868548631668, -0.004275968298316002, 0.06899828463792801, 0.01832096092402935, -0.0074880123138427734, -0.05179833620786667, 0.03513885289430618, -0.013377536088228226, 0.0012766373110935092, 0.017532426863908768, 0.005476684775203466, -0.003354022977873683, 0.020239638164639473, 0.0352688692510128, 0.017272546887397766, -0.03684379160404205, -0.035364679992198944, 0.09613913297653198, -0.06104522570967674, -0.04774370789527893, -0.03100557252764702, 0.050964660942554474, -0.010349727235734463, -0.08032415062189102, 0.03749758005142212, 0.07585474103689194, -0.023216966539621353, 0.026498451828956604, -0.003453230019658804, 0.037352051585912704, -0.02075633965432644, 0.00980907678604126, 0.025333132594823837, -0.021363265812397003, 0.08587180078029633, -0.032026879489421844, -0.009392297826707363, -0.004217284265905619, -0.03106536529958248, -0.03763790428638458, 0.011387210339307785, -0.018276231363415718, 0.03138328716158867, -0.05781849846243858, -0.0950876921415329, 0.025331895798444748, 0.028900837525725365, 0.0311308354139328, -0.04658784344792366, 0.043412335216999054, -0.03252357989549637, 0.043125733733177185, 0.016577886417508125, 0.022184722125530243, 0.01740119978785515, -0.04432053118944168, 0.009596333838999271, -0.010563558898866177, 0.03741088882088661, 0.047632358968257904, -0.0886758416891098, -0.03914933651685715, 0.07521077990531921, 0.024362316355109215, 0.008981755003333092, -0.06440941244363785, -0.06201210245490074, 0.07300487905740738, 0.04227517917752266, 0.11340200901031494, 0.04746082052588463, 0.033931583166122437, -0.0063319518230855465, -0.0013364788610488176, -0.01786711998283863, 0.03489132598042488, 0.03110797144472599, -0.003414149396121502, -0.020136350765824318, 0.04853666201233864, 0.005864270962774754, -0.09250503033399582, 0.06007121875882149, -0.03435266390442848, -0.06267893314361572, -0.06509209424257278, -0.006957076955586672, -0.027868013828992844, -0.06424032151699066, 0.008635506965219975, 0.14460541307926178, -0.012963641434907913, -0.04683370888233185, 0.014876265078783035, -0.04696742445230484, 0.0863504633307457, 0.023455267772078514, 0.03657318651676178, 0.06888506561517715, -0.10895467549562454, -0.020628347992897034, -0.04610738530755043, 0.02050650119781494, -0.0066086058504879475, 0.0036796610802412033, 0.02784210629761219, -0.03846209496259689, 0.060290493071079254, 0.04326443001627922, -0.08152040094137192, 0.022943003103137016, -0.014477409422397614, 0.011482257395982742, 0.06146376579999924, -0.05018864944577217, -0.004144354723393917, 0.020987970754504204, 0.020312275737524033, -0.01271842047572136, 0.03810993954539299, -0.05595017597079277, 0.007986284792423248, -0.041426293551921844, -0.03256950527429581, -0.002010299591347575, 0.012243783101439476, 0.028463218361139297, -0.0015044999308884144, -0.0063001420348882675, 0.005750964395701885, 0.03210500255227089, -0.015167923644185066, -0.011126266792416573, -0.06904785335063934, -0.02537410892546177, -0.018199631944298744, 0.015113103203475475, 0.020129764452576637, 0.008198495954275131, 0.025266123935580254, -0.004102613776922226, -0.02614525519311428, 0.03176796808838844, -0.012523218058049679, 0.011046350933611393, 0.008900046348571777, 0.06812101602554321, -0.032278187572956085, -0.0170486718416214, -0.010176184587180614, -0.04842378944158554, -0.022624952718615532, 0.036164291203022, 0.009548048488795757, 0.020959682762622833, -0.019316475838422775, 0.05749654024839401, 0.02718966454267502, 0.016617463901638985, 0.04581721872091293, -0.005879031028598547, 0.0012972275726497173, -0.015202315524220467, -0.0524701252579689, 0.0640142560005188, -0.03835718333721161, 0.03332808241248131, 0.008102121762931347, -0.02880924753844738, -0.030584057793021202, 0.0050726658664643764, 0.051127295941114426, -0.00013584058615379035, 0.02584601566195488, -0.018037376925349236, 0.012952987104654312, 0.009501460008323193, 0.02675934135913849, -0.13339227437973022, -0.06709427386522293, 0.023063654080033302, 0.004456533119082451, 0.0006991536938585341, -0.03823557868599892, 0.034879185259342194, -0.02698020078241825, 0.011251059360802174, 0.002504227217286825, -0.012415239587426186, 0.01803441531956196, 0.017988793551921844, 0.012181329540908337, -0.027338461950421333, -0.002781893825158477, -0.019440511241555214, 0.0008681201725266874, -0.01896103098988533, 0.02418031543493271, -0.03751879185438156, 0.0338570699095726, 0.018898742273449898, -0.007282710634171963, 0.013681355863809586, 0.04509502649307251, 0.016190554946660995, 0.021199455484747887, 0.021588442847132683, -0.00035531562753021717, -0.04476292058825493, 0.04572337865829468, -0.03449290245771408, 0.015987548977136612, -0.016289642080664635, 0.013760427944362164, -0.0233840961009264, 0.026826689019799232, 0.007166887633502483, 0.03282696008682251, 0.030837256461381912, -0.01088064257055521, 0.03753681480884552, 0.01251894049346447, -0.03775443136692047, 0.013585063628852367, -0.016494521871209145, -0.001160339917987585, 0.02663840912282467, -0.04126042500138283, -0.01234412845224142, -0.022594228386878967, 0.04976271837949753, 0.0647328644990921, 0.019064871594309807, -0.0177402812987566, -0.024206489324569702, 0.009001366794109344, 0.02801196277141571, -0.045156896114349365, -0.03124845214188099, 0.021938983350992203, -0.004024822264909744, 0.029380831867456436, -0.07454624772071838, 0.007461064495146275, -0.027622565627098083, 0.026628533378243446, 0.016441168263554573, 0.01967737264931202, 0.022595876827836037, -0.013793785125017166, 0.000555058941245079, 0.019627761095762253, -0.012963707558810711, 0.01841113343834877, -0.00827105063945055, -0.050251975655555725, 0.07631632685661316, 0.006615353282541037, -0.025286022573709488, -0.014326673001050949, -0.021948713809251785, 0.0028882967308163643, 0.01661955937743187, 0.0008270757389254868, 0.009785555303096771, 0.008602665737271309, -0.01740974932909012, 0.066285640001297, 0.00686822971329093, -0.004988141357898712, -0.025953546166419983, 0.02028919942677021, 0.017193004488945007, 0.00029615117819048464, 0.014180746860802174, -0.01162253599613905, 0.031003911048173904, -0.010212793946266174, 0.02167191542685032, -0.03457842022180557, -0.009092156775295734, 0.01546616479754448, 0.014162779785692692, 0.04976223409175873, -0.04777887091040611, -0.018413599580526352, -0.0008135284879244864, 0.021880483254790306, -0.002595623256638646, -0.015015779994428158, -0.01076398603618145, -0.007499937899410725, 0.0009080945164896548, 0.01994217559695244, -0.040898993611335754, -0.015702538192272186, -0.024111129343509674, -0.012926437892019749, -0.010894650593400002, -0.007423073519021273, 0.0014936031075194478, 0.012579365633428097, -0.011528790928423405, -0.010905526578426361, 0.04471006616950035, 0.0019427542574703693, -0.054786380380392075, 0.0164240300655365, -0.04747132956981659, -0.020597048103809357, 0.04207788035273552, -0.0409734845161438, 0.04657845199108124, 0.027391603216528893, 0.0005433489568531513, 0.047234829515218735, -0.022161291912198067, -0.051823992282152176, -0.03703828528523445, 0.008361930027604103, 0.011070401407778263, -0.028476877138018608, 0.05616441369056702, -0.04645761102437973, -0.03341714292764664, 0.006668423302471638, 0.0012941916938871145, 0.03729787841439247, 0.01612440124154091, 0.0012670118594542146, -0.026430504396557808, -0.014185129664838314, 0.01826925203204155, 0.034565553069114685, -0.004538979846984148, 0.007652102503925562, -0.02092713676393032, 0.0706610381603241, 0.007072634994983673, -0.004797866102308035, -0.05993124842643738, 0.025601904839277267, 0.0070716617628932, -0.017263606190681458, -0.014702553860843182, -0.027738699689507484, 0.004732678644359112, 0.020871970802545547, 0.00045170035446062684, -0.004631828051060438, 0.015567425638437271, 0.0010792338289320469, 0.02471560798585415, 0.022559549659490585, 0.008996138349175453, -0.004759075120091438, -0.04309865087270737, 0.046519141644239426, -0.0030288533307611942, -0.006509749684482813, 0.030450886115431786, -0.01367190945893526, -0.009686954319477081, -0.002112217713147402, 0.04728732630610466, -0.015110214240849018, 0.0007163571426644921, 0.039096929132938385, 0.018437674269080162, -0.02893511764705181, -0.005276073236018419, -0.022540351375937462, 0.0011246997164562345, 0.008248628117144108, 0.022296052426099777, -0.01054132729768753, 0.025501834228634834, 0.004606218077242374, 0.05764823779463768, -0.00993953738361597, -0.009760333225131035, -0.0244783703237772, 0.03291354700922966, -0.028301775455474854, 0.017362171784043312, -0.037506505846977234, 0.028420601040124893, -0.003697104286402464, 0.007528979796916246, -0.008392361924052238, -0.02835925854742527, -0.04267524182796478, 0.016349034383893013, -0.0064420271664857864, 0.003594233188778162, 0.0015562120825052261, -0.019307196140289307, 0.0459928885102272, 0.009104075841605663, 0.0030105772893875837, -0.022409643977880478, 0.002412975998595357, 0.061867211014032364, -0.016797086223959923, -0.030720554292201996, 0.04788823425769806, 0.029873237013816833, 0.016716528683900833, 0.025450056418776512, 0.00140943075530231, -0.009011688642203808, 0.02911398373544216, -0.004878122825175524, -0.005983617622405291, -0.051971450448036194, 0.09671159088611603, -0.020551618188619614, -0.006536976434290409, -0.00864419061690569, -0.002562201814725995, -0.07134990394115448, -0.00331259798258543, -0.0019272445933893323, 0.0009555683354847133, 0.07412280142307281, 0.01657794415950775, -0.00779599417001009, 0.019503191113471985, 0.0015446689212694764, -0.011383227072656155, 0.002198670292273164, -0.022924097254872322, 0.040320057421922684, -0.00321864802390337, 0.040389638394117355, -0.03395392745733261, -0.01743321679532528, -0.01417879480868578, 0.018053557723760605, -0.012481952086091042, 0.007128919009119272, 0.007277949713170528, -0.050675053149461746, 0.04741593822836876, 0.036289311945438385, -0.0342368446290493, -0.03013255074620247, 0.030878854915499687, -0.007932143285870552, 0.004987845662981272, -0.020746178925037384, 0.019563762471079826, -0.004832904785871506, -0.028412308543920517, 0.03343181684613228, 0.0468265525996685, 0.025989659130573273, 0.043324004858732224, 0.02243766002357006, 0.024506861343979836, 0.03785417973995209, 0.01745462417602539, -0.009405560791492462, 0.050092123448848724, 0.03775933384895325, 0.004854078404605389, 0.004986779764294624, -0.0034493645653128624, -0.026154369115829468, -0.011417611502110958, -0.0010872463462874293, 0.005260909907519817, -0.03572246432304382, 0.025644728913903236, 0.02387511543929577, -0.024569373577833176, -0.00040997652104124427, -0.0375758558511734, 0.04722421243786812, 0.011197049170732498, 0.020230088382959366, 0.006322276312857866, -0.02594776079058647, -0.022974511608481407, 0.01756574958562851, 0.015486330725252628, 0.0427439920604229, 0.0011762527283281088, -0.02205214463174343, 0.05782737955451012, 0.014399202540516853, -0.01456343475729227, 0.005559845361858606, -0.00387856038287282, 0.017076050862669945, 0.010272444225847721, -0.033501893281936646, -0.007686276454478502, 0.014503194950520992, -0.03390143811702728, -0.015419607982039452, -0.011026124469935894, -0.025071118026971817, -0.03671625629067421, 0.003487455192953348, 0.025858035311102867, -0.022947533056139946, -0.028613941743969917, -0.051185015588998795, -0.011945736594498158, -0.01904718391597271, 0.010883014649152756, 0.009233775548636913, -0.028380190953612328, -0.007109754253178835, 0.028998995199799538, -0.0029371585696935654, -0.028330082073807716, -0.03393951803445816, 0.003936707507818937, -0.02885534055531025, -0.01866402104496956, 0.032728858292102814, -0.020285090431571007, -0.02011992782354355, -0.011713738553225994, -0.015829147771000862, 0.05305727198719978, 0.026137223467230797, 0.010209964588284492, -0.011726760305464268, -0.004350003786385059, -0.04289320111274719, 0.0317402184009552, 0.0011000360827893019, -0.06889989972114563, -0.0010585582349449396, 0.007710125297307968, 0.03083876706659794, 0.0010158021468669176, 0.03450397774577141, -0.03652919456362724, -0.031108815222978592, -0.012701580300927162, -0.012426302768290043, -0.006962390150874853, 0.032322630286216736, -0.024229105561971664, -0.01702532172203064, -0.027199266478419304, -0.017874551936984062, -0.0017847713315859437, -0.0176426749676466, -0.0025170801673084497, 0.04307851940393448, -0.0010888994438573718, -0.0034323250874876976, -0.05122067779302597, 0.03749751299619675, 0.016396982595324516, 0.013327686116099358, 0.009717942215502262, 0.044326286762952805, 0.03140164911746979, -0.030253417789936066, 0.02039833553135395, -0.031690243631601334, 0.011897562071681023, -0.0376572348177433, -0.02676507644355297, -0.0249578058719635, -0.030408794060349464, -0.00104467011988163, 0.0008081040577962995, -0.0351346917450428, 0.01142321340739727, -0.0018669029232114553, -0.01463082991540432, -0.02421415038406849, 0.019849790260195732, 0.038521893322467804, -0.011111383326351643, 0.03781338408589363, -0.022946277633309364, 0.03091403655707836, -0.02170281670987606, -0.006266006268560886, 0.03133990615606308, 0.040674880146980286, -0.027754181995987892, -0.014728219248354435, 0.03267120197415352, 0.026168955489993095, -0.03737535700201988, -0.04493306577205658, 0.03978658840060234, 0.03150729462504387, -0.016120821237564087, -0.01916547492146492, -0.003769675502553582, 0.017484625801444054, -0.016754884272813797, 0.02533562481403351, 0.00441391859203577, -0.03650256246328354, 0.007892556488513947, 0.03928571194410324, -0.05539568141102791, 0.017329763621091843, -0.015595756471157074, 0.014088310301303864, 0.049007218331098557, 0.04157085716724396, 0.025205101817846298, 0.0011068979511037469, -0.04331626370549202, -0.007574697956442833, -0.010832040570676327, -0.025072889402508736, -0.01259795855730772, -0.023627890273928642, 0.005535545758903027, -0.011264010332524776, -0.02824496291577816, 0.02336512692272663, 0.026143545284867287, 0.008384359069168568, -0.03128737583756447, 0.016522057354450226, -0.004701030906289816, -0.005746590904891491, 0.014647075906395912, 0.003630900289863348, 0.02163156308233738, 0.04525300860404968, -0.023498332127928734, 0.02699781395494938, 0.03459148108959198 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
Reversible Residual Layers in Reformer Let's start by investigating why training a model requires much more memory than the inference of the model. When running a model in inference, the required memory equals more or less the memory it takes to compute the single largest tensor in the model. On the other hand, when training a model, the required memory equals more or less the sum of all differentiable tensors. This is not surprising when considering how auto differentiation works in deep learning frameworks. These lecture slides by Roger Grosse of the University of Toronto are great to better understand auto differentiation. In a nutshell, in order to calculate the gradient of a differentiable function (e.g. a layer), auto differentiation requires the gradient of the function's output and the function's input and output tensor. While the gradients are dynamically computed and subsequently discarded, the input and output tensors (a.k.a activations) of a function are stored during the forward pass. Alright, let's apply this to a transformer model. A transformer model includes a stack of multiple so-called transformer layers. Each additional transformer layer forces the model to store more activations during the forward pass and thus increases the required memory for training. Let's take a more detailed look. A transformer layer essentially consists of two residual layers. The first residual layer represents the self-attention mechanism as explained in section 1) and the second residual layer represents the linear or feed-forward layers as explained in section 2). Using the same notation as before, the input of a transformer layer i.e. \( \mathbf{X} \) is first normalized \( ^{1} \) and subsequently processed by the self-attention layer to get the output \( \mathbf{Z} = \text{SelfAttn}(\text{LayerNorm}(\mathbf{X})) \). We will abbreviate these two layers with \( G \) so that \( \mathbf{Z} = G(\mathbf{X}) \). Next, the residual \( \mathbf{Z} \) is added to the input \( \mathbf{\overline{Z}} = \mathbf{Z} + \mathbf{X} \) and the sum is fed into the second residual layer - the two linear layers. \( \mathbf{\overline{Z}} \) is processed by a second normalization layer, followed by the two linear layers to get \( \mathbf{Y} = \text{Linear}(\text{LayerNorm}(\mathbf{Z} + \mathbf{X})) \). We will abbreviate the second normalization layer and the two linear layers with \( F \) yielding \( \mathbf{Y} = F(\mathbf{\overline{Z}}) \). Finally, the residual \( \mathbf{Y} \) is added to \( \mathbf{\overline{Z}} \) to give the output of the transformer layer \( \mathbf{\overline{Y}} = \mathbf{Y} + \mathbf{\overline{Z}} \). Let's illustrate a complete transformer layer using the example of \( \mathbf{x}1, \ldots, \mathbf{x}{16} \). To calculate the gradient of e.g. the self-attention block \( G \), three tensors have to be known beforehand: the gradient \( \partial \mathbf{Z} \), the output \( \mathbf{Z} \), and the input \( \mathbf{X} \). While \( \partial \mathbf{Z} \) can be calculated on-the-fly and discarded afterward, the values for \( \mathbf{Z} \) and \( \mathbf{X} \) have to be calculated and stored during the forward pass since it is not possible to recalculate them easily on-the-fly during backpropagation. Therefore, during the forward pass, large tensor outputs, such as the query-key dot product matrix \( \mathbf{Q}\mathbf{K}^T \) or the intermediate output of the linear layers \( \mathbf{Y}^{\text{int}} \), have to be stored in memory \( ^{2} \). Here, reversible residual layers come to our help. The idea is relatively straight-forward. The residual block is designed in a way so that instead of having to store the input and output tensor of a function, both can easily be recalculated during the backward pass so that no tensor has to be stored in memory during the forward pass. This is achieved by using two input streams \( \mathbf{X}^{(1)}, \mathbf{X}^{(2)} \), and two output streams \( \mathbf{\overline{Y}}^{(1)}, \mathbf{\overline{Y}}^{(2)} \). The first residual \( \mathbf{Z} \) is computed by the first output stream \( \mathbf{Z} = G(\mathbf{X}^{(1)}) \) and subsequently added to the input of the second input stream, so that \( \mathbf{\overline{Z}} = \mathbf{Z} + \mathbf{X}^{(2)} \). Similarly, the residual \( \mathbf{Y} = F(\mathbf{\overline{Z}}) \) is added to the first input stream again, so that the two output streams are defined by \( \mathbf{Y}^{(1)} = \mathbf{Y} + \mathbf{X}^{(1)} \) and \( \mathbf{Y}^{(2)} = \mathbf{X}^{(2)} + \mathbf{Z} = \mathbf{\overline{Z}} \). The reversible transformer layer can be visualized for \( \mathbf{x}1, \ldots, \mathbf{x}{16} \) as follows. As can be seen, the outputs \( \mathbf{\overline{Y}}^{(1)}, \mathbf{\overline{Y}}^{(2)} \) are calculated in a very similar way than \( \mathbf{\overline{Y}} \) of the non-reversible layer, but they are mathematically different. The authors of Reformer observe in some initial experiments that the performance of a reversible transformer model matches the performance of a standard transformer model. The first visible difference to the standard transformer layer is that there are two input streams and output streams \( ^{3} \), which at first slightly increases the required memory for both the forward pass. The two-stream architecture is crucial though for not having to save any activations during the forward pass. Let's explain. For backpropagation, the reversible transformer layer has to calculate the gradients \( \partial G \) and \( \partial F \). In addition to the gradients \( \partial \mathbf{Y} \) and \( \partial \mathbf{Z} \) which can be calculated on-the-fly, the tensor values \( \mathbf{Y} \), \( \mathbf{\overline{Z}} \) have to be known for \( \partial F \) and the tensor values \( \mathbf{Z} \) and \( \mathbf{X}^{(1)} \) for \( \partial G \) to make auto-differentiation work. If we assume to know \( \mathbf{\overline{Y}}^{(1)}, \mathbf{\overline{Y}}^{(2)} \), it can easily be depicted from the graph that one can calculate \( \mathbf{X}^{(1)}, \mathbf{X}^{(2)} \) as follows. \( \mathbf{X}^{(1)} = F(\mathbf{\overline{Y}}^{(1)}) - \mathbf{\overline{Y}}^{(1)} \). Great, now that \( \mathbf{X}^{(1)} \) is known, \( \mathbf{X}^{(2)} \) can be computed by \( \mathbf{X}^{(2)} = \mathbf{\overline{Y}}^{(1)} - G(\mathbf{X}^{(1)}) \). Alright now, \( \mathbf{Z} \) and \( \mathbf{Y} \) are trivial to compute via \( \mathbf{Y} = \mathbf{\overline{Y}}^{(1)} - \mathbf{X}^{(1)} \) and \( \mathbf{Z} = \mathbf{\overline{Y}}^{(2)} - \mathbf{X}^{(2)} \). So as a conclusion, if only the outputs \( \mathbf{\overline{Y}}^{(1)}, \mathbf{\overline{Y}}^{(2)} \) of the last reversible transformer layer are stored during the forward pass, all other relevant activations can be derived by making use of \( G \) and \( F \) during the backward pass and passing \( \mathbf{X}^{(1)} \) and \( \mathbf{X}^{(2)} \). The overhead of two forward passes of \( G \) and \( F \) per reversible transformer layer during the backpropagation is traded against not having to store any activations during the forward pass. Not a bad deal! Note: Since recently, major deep learning frameworks have released code that allows to store only certain activations and recompute larger ones during the backward propagation (Tensoflow here and PyTorch here). For standard reversible layers, this still means that at least one activation has to be stored for each transformer layer, but by defining which activations can dynamically be recomputed a lot of memory can be saved. --- \( ^{1} \) In the previous two sections, we have omitted the layer norm layers preceding both the self-attention layer and the linear layers. The reader should know that both \( \mathbf{X} \) and \( \mathbf{\overline{Z}} \) are both processed by layer normalization before being fed into self-attention and the linear layers respectively. \( ^{2} \) While in the design the dimension of \( \mathbf{Q}\mathbf{K} \) is written as \( n \times n \), in a LSH self-attention or local self-attention layer the dimension would only be \( n \times l_{c} \times n_{h} \) or \( n \times l_{c} \) respectively with \( l_{c} \) being the chunk length and \( n_{h} \) the number of hashes \( ^{3} \) In the first reversible transformer layer \( \mathbf{X}^{(2)} \) is set to be equal to \( \mathbf{X}^{(1)} \).
[ -0.01614665426313877, -0.011329758912324905, 0.05321266129612923, -0.022739233449101448, 0.07144734263420105, 0.024704042822122574, -0.021474149078130722, -0.03350276127457619, 0.034591611474752426, 0.012913458049297333, -0.025561751797795296, 0.08231643587350845, 0.02005191519856453, 0.0163088571280241, 0.02556171827018261, -0.03410951420664787, 0.022880980744957924, -0.06674951314926147, -0.060880303382873535, 0.05182458460330963, 0.024004457518458366, -0.06440789252519608, 0.049459442496299744, -0.009620786644518375, -0.013204988092184067, -0.025905465707182884, -0.014288440346717834, -0.03796439990401268, -0.023474307730793953, 0.02494858205318451, -0.12015283852815628, -0.010358619503676891, 0.01202343963086605, -0.03921560198068619, 0.019239209592342377, -0.05020648613572121, -0.10868479311466217, 0.023424750193953514, 0.0560569129884243, -0.04858735576272011, 0.008661860600113869, 0.01277075707912445, -0.08093664050102234, -0.016163785010576248, -0.007724130991846323, -0.01652408391237259, -0.1081080511212349, 0.03937092423439026, -0.05309812352061272, -0.006192437838762999, -0.059240926057100296, 0.029621746391057968, -0.09683725237846375, 0.07657984644174576, -0.018689455464482307, 0.00449110334739089, -0.0021373885683715343, 0.10494432598352432, 0.003460709238424897, 0.04290853813290596, 0.037823665887117386, 0.09012924879789352, 0.050703275948762894, 0.06459877640008926, -0.02155851572751999, -0.025011369958519936, -0.06857551634311676, -0.009477882646024227, -0.058739226311445236, -0.0619647279381752, -0.0388866551220417, 0.000010463534636073746, -0.01613597385585308, 0.02121143415570259, -0.04213939607143402, 0.01696794666349888, -0.013472800143063068, 0.029424702748656273, 0.036296065896749496, -0.024797920137643814, -0.05295002460479736, 0.0457647405564785, 0.05873570218682289, 0.03292737156152725, 0.025458447635173798, -0.03346181660890579, -0.006044887471944094, -0.07729201018810272, -0.009167862124741077, 0.051229119300842285, -0.06620769947767258, -0.11865084618330002, 0.038682304322719574, 0.018582919612526894, 0.05564635619521141, -0.02605035901069641, -0.018842443823814392, 0.004792386665940285, -0.02841888554394245, 0.03310810774564743, -0.028628654778003693, -0.035244062542915344, 0.038207702338695526, -0.05548277497291565, -0.022331999614834785, 0.011393053457140923, -0.022310540080070496, -0.09521473199129105, -0.031197713688015938, -0.04445761442184448, 0.0012457880657166243, 0.0005126982578076422, 0.004776769317686558, 0.02490711584687233, -0.0670538991689682, 0.0032029831781983376, 0.003760864259675145, -0.022704895585775375, 0.05019311606884003, 0.01413356140255928, -0.013985753990709782, 0.07641318440437317, 0.09385448694229126, -0.04385766014456749, -0.0004296086262911558, 0.016080977395176888, -0.0375981405377388, 0.026020484045147896, -0.0046449089422822, 0.013100387528538704, 0.008864148519933224, -0.0070155770517885685, 0.00873095914721489, 0.018427209928631783, -0.02009406127035618, -0.10902475565671921, 0.029437249526381493, -0.022487789392471313, -0.0345323421061039, -0.007884154096245766, -0.055094365030527115, -0.0022946777753531933, 0.0572143979370594, -0.059145521372556686, 0.03494171053171158, -0.06323900818824768, -0.02213921584188938, 0.06593362241983414, 0.04023345932364464, 0.028063703328371048, -0.010619291104376316, 0.048568323254585266, -0.012143710628151894, -0.08933155983686447, 0.023059898987412453, 0.05850842595100403, -0.004482069052755833, 0.022059796378016472, -0.0671195238828659, 0.019957968965172768, -0.01415278110653162, 0.009086397476494312, -0.011992772109806538, 0.1361899971961975, 0.09808449447154999, -0.023175211623311043, 0.034959424287080765, 0.01631026901304722, -0.004471291322261095, 0.03240664675831795, 0.019479509443044662, -0.06971585750579834, 0.01737380400300026, -0.06752883642911911, -0.0003023398166988045, 0.02517101541161537, -0.05035460367798805, 0.06156330555677414, -0.021632397547364235, -0.0006143789505586028, -0.022414499893784523, 0.03605978190898895, -0.02613065019249916, -0.02521243505179882, 0.06372413039207458, -0.023216508328914642, 0.03874215856194496, -0.059477511793375015, -0.031864386051893234, 0.09123247116804123, -0.07360248267650604, 0.022515753284096718, 0.027101723477244377, -0.028427841141819954, 0.06178954988718033, -0.006906944327056408, -0.04033457115292549, 0.06714604049921036, 0.04903753474354744, 0.06113715469837189, 0.021202532574534416, 0.031394112855196, -0.02450019307434559, -0.01202098187059164, 0.0491371676325798, 0.024640440940856934, 0.013587995432317257, -0.0681091696023941, 0.02891690842807293, 0.007003081496804953, -0.013357596471905708, -0.08295059204101562, 0.030378052964806557, -0.07870449125766754, -0.0685245543718338, -0.062218256294727325, 0.0019223857671022415, -0.004103358369320631, -0.03514865040779114, 0.01809285767376423, 0.0766446515917778, 0.005243165418505669, -0.060660913586616516, 0.02841370180249214, -0.06311541795730591, -0.04929470270872116, -0.01459579449146986, -0.03478938341140747, 0.009920899756252766, -0.06286772340536118, -0.0055131977424025536, -0.10145991295576096, -0.025127731263637543, -0.012957523576915264, -0.04994358867406845, -0.05003449320793152, -0.07621973007917404, -0.024578865617513657, 0.0271648820489645, -0.09754061698913574, -0.006686327513307333, 0.04922035336494446, 0.021519280970096588, 0.03498046100139618, 0.0009494015830568969, 0.0046737296506762505, -0.02174309641122818, 0.0771334171295166, -0.07099593430757523, -0.024030698463320732, -0.029405932873487473, 0.0305466465651989, -0.014536360278725624, -0.09891516715288162, -0.04011236131191254, 0.02661539614200592, -0.012657953426241875, -0.01655653491616249, 0.019691554829478264, 0.031902678310871124, -0.0003574071452021599, 0.014710832387208939, -0.03978961333632469, -0.020823420956730843, 0.0016727434704080224, -0.014755900017917156, -0.02056150883436203, -0.0050093443132936954, -0.0009658474591560662, 0.008884086273610592, 0.0009255703771486878, 0.011475258506834507, -0.012804861180484295, 0.005954909138381481, 0.024573849514126778, 0.011090182699263096, 0.056642476469278336, -0.03895922750234604, -0.006243378389626741, -0.014528261497616768, -0.03192055970430374, 0.006923105102032423, 0.028980713337659836, 0.030957195907831192, -0.025718677788972855, -0.00803053006529808, 0.0036818902008235455, -0.004971644841134548, 0.022729922086000443, 0.016396576538681984, 0.01848476007580757, 0.04340222850441933, 0.0003546199877746403, -0.03138809651136398, 0.0005731332930736244, 0.020045636221766472, -0.005500167142599821, -0.04411081224679947, -0.029523203149437904, -0.0013246495509520173, -0.007991408929228783, 0.00459632184356451, 0.09350299090147018, 0.00832638144493103, 0.0009627555846236646, -0.000919732206966728, -0.033887144178152084, 0.06550499051809311, -0.0783352181315422, -0.04451939836144447, 0.03294474259018898, 0.03244616836309433, 0.002004606183618307, -0.052304260432720184, -0.01887645199894905, 0.061905473470687866, 0.010602796450257301, -0.01903560198843479, -0.0055750226601958275, 0.004981325939297676, -0.004148032516241074, 0.026236681267619133, -0.03715059161186218, 0.024365101009607315, 0.025963423773646355, -0.035300467163324356, 0.04564046859741211, -0.03836052119731903, 0.013619295321404934, 0.021483030170202255, 0.00898307841271162, 0.032944872975349426, -0.0017029502196237445, 0.037206776440143585, 0.020234689116477966, 0.00647736107930541, 0.0196917075663805, -0.0049500311724841595, -0.02358255535364151, -0.05427198112010956, 0.0018880239222198725, 0.0049552819691598415, -0.02709965966641903, 0.021854659542441368, -0.0028354430105537176, 0.028690092265605927, 0.003454025136306882, 0.07191763073205948, 0.08720967918634415, 0.031412556767463684, 0.04778256267309189, 0.034416619688272476, 0.02503148466348648, -0.0300137959420681, -0.020105738192796707, -0.0071589043363928795, -0.001345090800896287, -0.0297759547829628, -0.005137799307703972, -0.023791125044226646, 0.00290484051220119, 0.03375297784805298, -0.004300087224692106, -0.013436523266136646, 0.04226529598236084, -0.030848493799567223, -0.014806307852268219, -0.03552308678627014, -0.023571087047457695, 0.010540016926825047, -0.014371334575116634, 0.011360691860318184, -0.011827060021460056, -0.01509504672139883, -0.0057591465301811695, 0.016233164817094803, 0.021228382363915443, 0.04736574739217758, -0.05633726716041565, 0.014380947686731815, 0.02018485590815544, 0.006658452097326517, -0.017193444073200226, -0.01303545106202364, -0.029378926381468773, -0.043363820761442184, 0.07156696170568466, 0.0037995355669409037, 0.006456795148551464, 0.012267998419702053, -0.047551702708005905, 0.03650128096342087, -0.01658126711845398, 0.03753764554858208, 0.022761818021535873, 0.0034767035394906998, 0.051228515803813934, 0.03783813863992691, 0.008030745200812817, -0.0007965736440382898, 0.016409635543823242, 0.0022326370235532522, -0.03847721219062805, -0.006586807779967785, 0.022690000012516975, 0.013559848070144653, 0.03831349313259125, 0.002509979298338294, 0.03706610947847366, -0.048352696001529694, 0.011504031717777252, -0.006623209919780493, -0.017797833308577538, -0.019922766834497452, -0.05134378746151924, 0.03852679207921028, 0.04535354673862457, -0.006760645192116499, -0.009589984081685543, 0.001703196088783443, -0.00885937549173832, 0.020206062123179436, -0.000038834125007269904, 0.05925154313445091, -0.053254276514053345, -0.019235603511333466, -0.027616271749138832, 0.016165057197213173, -0.019642043858766556, 0.03357347473502159, 0.006536724511533976, -0.04832909628748894, 0.0167599618434906, 0.0012377765960991383, 0.05124475434422493, 0.033456917852163315, -0.0425165519118309, -0.023400090634822845, -0.04067707434296608, -0.01313459686934948, 0.045984912663698196, -0.013954649679362774, -0.02521234191954136, -0.0008474563946947455, -0.020116761326789856, 0.012373522855341434, -0.0017323392676189542, -0.018273228779435158, -0.01524701714515686, 0.020560258999466896, 0.033340997993946075, -0.08139096945524216, 0.07255857437849045, -0.026724062860012054, -0.04712063819169998, 0.0020374031737446785, -0.03697516769170761, -0.0022018267773091793, 0.021570945158600807, 0.009732368402183056, -0.08334826678037643, -0.05329303443431854, 0.032379068434238434, -0.003586294362321496, 0.01866021566092968, -0.0020227604545652866, 0.03794074058532715, -0.0014765021624043584, 0.016450218856334686, 0.02318507432937622, -0.021229051053524017, 0.024033617228269577, 0.021662989631295204, 0.025015491992235184, -0.043484847992658615, -0.04101277515292168, 0.022609181702136993, 0.012235421687364578, -0.03218812122941017, -0.011758781969547272, -0.014637090265750885, -0.015059703029692173, -0.009447569958865643, 0.019510874524712563, 0.011630546301603317, -0.017574159428477287, 0.005775971803814173, -0.00886960607022047, -0.010144229978322983, -0.029630232602357864, 0.04040694236755371, -0.02024465799331665, 0.004946275148540735, 0.060927025973796844, 0.031829070299863815, 0.023495065048336983, -0.025128908455371857, 0.064333975315094, 0.08549259603023529, -0.060803938657045364, 0.04753583297133446, -0.031389348208904266, 0.02436634711921215, 0.03400934115052223, 0.07704867422580719, 0.05401894822716713, 0.024325435981154442, -0.00655062822625041, 0.03940754756331444, 0.06802999973297119, 0.022539598867297173, -0.037978388369083405, -0.005313343834131956, 0.023418525233864784, -0.007878762669861317, 0.026273377239704132, 0.0215555839240551, -0.014870241284370422, 0.051503825932741165, -0.017467599362134933, 0.006442095618695021, -0.014873780310153961, -0.0269634947180748, -0.012451711110770702, 0.0028934574220329523, 0.021859802305698395, 0.0039964234456419945, 0.045084353536367416, -0.029329214245080948, 0.023530367761850357, -0.021516064181923866, -0.00616032537072897, 0.0299284216016531, -0.06573459506034851, 0.018714843317866325, -0.021918145939707756, 0.009760864078998566, 0.003030112013220787, 0.009744864888489246, 0.019437983632087708, -0.03445105627179146, 0.011378128081560135, 0.00848270021378994, -0.027366984635591507, -0.021626455709338188, 0.037633877247571945, 0.016807859763503075, -0.001689242199063301, -0.02003387175500393, -0.00519612105563283, -0.09311109036207199, 0.038119588047266006, -0.024686546996235847, 0.05920657888054848, 0.08121231198310852, -0.03656890615820885, 0.00043520136387087405, 0.01023909356445074, -0.006152180954813957, -0.004408682696521282, 0.027188215404748917, 0.012795678339898586, 0.06273206323385239, -0.005220774561166763, 0.010079896077513695, 0.007443053647875786, 0.015404579229652882, 0.07017068564891815, 0.03431425616145134, -0.024673793464899063, 0.005362195428460836, -0.025585003197193146, -0.01225383672863245, 0.0553206168115139, 0.0026845477987080812, -0.052063826471567154, 0.012568407692015171, 0.018379343673586845, 0.030199985951185226, 0.007459532003849745, -0.004683041945099831, 0.05978313460946083, -0.05465685576200485, 0.035849299281835556, 0.004192400258034468, 0.03839421644806862, 0.00693734735250473, 0.026056619361042976, 0.03729593753814697, 0.002257657703012228, 0.06712643057107925, 0.017722293734550476, 0.03461658954620361, -0.010285255499184132, 0.04971541836857796, -0.002301688538864255, -0.01620319113135338, 0.013522105291485786, 0.01637907512485981, 0.016444101929664612, -0.002878486644476652, -0.00023221841547638178, -0.02801845222711563, 0.03672004118561745, -0.0027497049886733294, 0.002596223494037986, 0.02816840447485447, 0.014260186813771725, 0.020751480013132095, 0.052500348538160324, 0.04410939663648605, 0.05753017216920853, 0.03395164757966995, 0.03285789117217064, 0.034803830087184906, 0.03812608867883682, 0.0018924877513200045, -0.001441669650375843, -0.02332010306417942, 0.02618364244699478, -0.014327295124530792, 0.014353069476783276, -0.012504632584750652, 0.0003200097708031535, 0.03013618290424347, -0.03752811253070831, -0.033879611641168594, 0.02305116318166256, -0.016335390508174896, -0.02158200740814209, 0.012003508396446705, 0.02080903947353363, -0.023412620648741722, -0.027050048112869263, 0.04147852212190628, -0.016705194488167763, -0.022877516224980354, -0.006867180112749338, -0.011684303171932697, -0.0059502520598471165, -0.002890952629968524, 0.014285844750702381, 0.015324183739721775, -0.05222714692354202, 0.01682228408753872, 0.04538387805223465, 0.02782822959125042, -0.05485153943300247, -0.04344464838504791, 0.04338238760828972, 0.019731100648641586, 0.048691000789403915, 0.030133772641420364, -0.01732860878109932, 0.0424744077026844, -0.0247297715395689, 0.001512119430117309, 0.0052917348220944405, -0.0060369535349309444, -0.05055629462003708, -0.012858295813202858, -0.019641108810901642, -0.014530375599861145, 0.008436799049377441, 0.031354572623968124, -0.005078249145299196, -0.007573709357529879, 0.014157547615468502, 0.031843770295381546, 0.07184871286153793, 0.02278544194996357, 0.00040427292697131634, -0.041884344071149826, 0.020713696256279945, 0.016728730872273445, 0.02836393564939499, 0.0030811764299869537, -0.019719881936907768, -0.02687009610235691, -0.020163442939519882, 0.008793165907263756, -0.0039055345114320517, -0.056336503475904465, -0.03970126062631607, 0.019503628835082054, 0.05296538025140762, -0.0018029391067102551, -0.006562309339642525, -0.006774943321943283, -0.013555473648011684, -0.01838858053088188, 0.020709775388240814, 0.020203886553645134, 0.022220665588974953, -0.04243211820721626, 0.010787964798510075, -0.010715858079493046, -0.0017488753655925393, -0.00044611928751692176, -0.04124557599425316, 0.0009172508143819869, 0.023640982806682587, 0.01393639575690031, 0.02107096277177334, -0.0130972471088171, 0.014487343840301037, -0.022225625813007355, -0.029682034626603127, -0.007585437037050724, 0.028772398829460144, 0.04215753450989723, -0.0035071999300271273, 0.027392346411943436, -0.009222738444805145, -0.0042081172578036785, -0.031146854162216187, -0.033697959035634995, 0.03395935520529747, 0.008409946225583553, -0.0363585501909256, 0.03081347607076168, 0.033464863896369934, -0.00023419519129674882, -0.012386182323098183, -0.0317256785929203, -0.00048251906991936266, -0.005287388805299997, -0.01500625442713499, 0.035059042274951935, 0.024079879745841026, 0.023735376074910164, 0.015083218924701214, 0.02616690844297409, -0.013484902679920197, -0.05591166019439697, 0.018158189952373505, 0.02609173208475113, -0.0555998869240284, -0.011070129461586475, 0.00874301791191101, 0.02101997286081314, 0.047956112772226334, 0.004068936221301556, 0.05142434313893318, -0.008443325757980347, 0.012602432630956173, -0.026801610365509987, -0.035506200045347214, 0.00541482400149107, -0.041467711329460144, 0.011222105473279953, 0.000037797253753524274, -0.018773900344967842, -0.012042338959872723, -0.005860210862010717, 0.036304812878370285, 0.01901780068874359, -0.0026196022517979145, -0.008594620041549206, 0.05284213647246361, -0.03767813369631767, -0.007310820277780294, 0.0017311996780335903, 0.02496381849050522, 0.012091503478586674, 0.036528125405311584, -0.032168202102184296, 0.00023886995040811598 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
Benchmark In order to measure the effect of reversible residual layers, we will compare the memory consumption of BERT with Reformer in training for an increasing number of layers. #@title Installs and Imports # pip installs !pip -qq install git+https://github.com/huggingface/transformers.git !pip install -qq py3nvml from transformers import ReformerConfig, BertConfig, PyTorchBenchmark, PyTorchBenchmarkArguments Let's measure the required memory for the standard bert-base-uncased BERT model by increasing the number of layers from 4 to 12. config_4_layers_bert = BertConfig.from_pretrained("bert-base-uncased", num_hidden_layers=4) config_8_layers_bert = BertConfig.from_pretrained("bert-base-uncased", num_hidden_layers=8) config_12_layers_bert = BertConfig.from_pretrained("bert-base-uncased", num_hidden_layers=12) benchmark_args = PyTorchBenchmarkArguments(sequence_lengths=[512], batch_sizes=[8], models=["Bert-4-Layers", "Bert-8-Layers", "Bert-12-Layers"], training=True, no_inference=True, no_speed=True, no_env_print=True) benchmark = PyTorchBenchmark(configs=[config_4_layers_bert, config_8_layers_bert, config_12_layers_bert], args=benchmark_args) result = benchmark.run() HBox(children=(FloatProgress(value=0.0, description='Downloading', max=433.0, style=ProgressStyle(description_… 1 / 3 2 / 3 3 / 3 ==================== TRAIN - MEMORY - RESULTS ==================== -------------------------------------------------------------------------------- Model Name Batch Size Seq Length Memory in MB -------------------------------------------------------------------------------- Bert-4-Layers 8 512 4103 Bert-8-Layers 8 512 5759 Bert-12-Layers 8 512 7415 -------------------------------------------------------------------------------- It can be seen that adding a single layer of BERT linearly increases the required memory by more than 400MB. config_4_layers_reformer = ReformerConfig.from_pretrained("google/reformer-enwik8", num_hidden_layers=4, num_hashes=1) config_8_layers_reformer = ReformerConfig.from_pretrained("google/reformer-enwik8", num_hidden_layers=8, num_hashes=1) config_12_layers_reformer = ReformerConfig.from_pretrained("google/reformer-enwik8", num_hidden_layers=12, num_hashes=1) benchmark_args = PyTorchBenchmarkArguments(sequence_lengths=[512], batch_sizes=[8], models=["Reformer-4-Layers", "Reformer-8-Layers", "Reformer-12-Layers"], training=True, no_inference=True, no_speed=True, no_env_print=True) benchmark = PyTorchBenchmark(configs=[config_4_layers_reformer, config_8_layers_reformer, config_12_layers_reformer], args=benchmark_args) result = benchmark.run() 1 / 3 2 / 3 3 / 3 ==================== TRAIN - MEMORY - RESULTS ==================== -------------------------------------------------------------------------------- Model Name Batch Size Seq Length Memory in MB -------------------------------------------------------------------------------- Reformer-4-Layers 8 512 4607 Reformer-8-Layers 8 512 4987 Reformer-12-Layers 8 512 5367 -------------------------------------------------------------------------------- For Reformer, on the other hand, adding a layer adds significantly less memory in practice. Adding a single layer increases the required memory on average by less than 100MB so that a much larger 12-Layer reformer-enwik8 model requires less memory than a 12-Layer bert-base-uncased model.
[ -0.054072391241788864, 0.019718723371624947, 0.023216333240270615, -0.03917522728443146, -0.016377408057451248, 0.03226850554347038, 0.06809818744659424, -0.01509877573698759, -0.03294415399432182, -0.027893375605344772, -0.030110133811831474, 0.09124915301799774, 0.01807747781276703, 0.022209325805306435, 0.05194607377052307, -0.057811543345451355, 0.04059465974569321, -0.05931154638528824, -0.03830799087882042, 0.00422411784529686, 0.020288893952965736, -0.0851675420999527, 0.051883287727832794, -0.0277895275503397, 0.0002338352205697447, -0.09030279517173767, 0.025112394243478775, -0.05871334299445152, -0.04761626571416855, 0.010669180192053318, -0.11516527086496353, 0.006833855994045734, 0.035324547439813614, -0.021342553198337555, -0.02765669673681259, -0.026116993278265, -0.07227958738803864, 0.04914584010839462, -0.009074256755411625, 0.003596237860620022, -0.016650106757879257, 0.05534718185663223, -0.010424692183732986, -0.024022527039051056, 0.0234849750995636, 0.003646999364718795, -0.045758794993162155, 0.03080887719988823, -0.033575765788555145, 0.0038417610339820385, -0.0647374838590622, 0.06277605891227722, -0.029034430161118507, 0.06192513555288315, -0.015659064054489136, 0.00835411623120308, 0.015757283195853233, 0.045818742364645004, 0.008754802867770195, 0.033314332365989685, 0.00802682340145111, 0.008605629205703735, 0.06412456184625626, 0.07851646840572357, -0.015370535664260387, 0.04006907716393471, -0.05693834275007248, 0.03031863085925579, -0.03359850496053696, -0.023009244352579117, -0.05312461405992508, -0.019477035850286484, -0.061642102897167206, 0.019105426967144012, -0.0025272094644606113, -0.018151311203837395, -0.020157383754849434, 0.0011887988075613976, 0.03490747511386871, 0.02001083455979824, -0.016897916793823242, 0.0555146299302578, 0.0038906715344637632, 0.002319727558642626, 0.037904802709817886, -0.016706028953194618, 0.049373723566532135, -0.04171007126569748, -0.07806835323572159, 0.04418094828724861, -0.07019273191690445, -0.07150468230247498, 0.04891159012913704, -0.015544570051133633, 0.011399210430681705, -0.028752250596880913, -0.059131406247615814, 0.027460047975182533, -0.024049412459135056, 0.01833033561706543, -0.009511316195130348, -0.09958256781101227, 0.034822653979063034, -0.015613587573170662, -0.024497946724295616, -0.010091803036630154, -0.04536256939172745, -0.12687519192695618, 0.0012612990103662014, -0.017818786203861237, 0.009087027981877327, -0.009720762260258198, -0.02241886407136917, 0.06552736461162567, -0.07238250970840454, 0.03100031055510044, -0.04322366043925285, 0.007507177535444498, 0.06509512662887573, 0.035179100930690765, -0.006114673335105181, 0.07661441713571548, 0.03880557045340538, -0.05794034153223038, -0.04053940251469612, 0.0007639428949914873, -0.006075607612729073, 0.041676923632621765, 0.057010337710380554, 0.012917058542370796, 0.06402022391557693, -0.009924027137458324, 0.015924163162708282, 0.050838977098464966, -0.015678411349654198, -0.05550432205200195, -0.009068937972187996, -0.03334503248333931, -0.034115687012672424, -0.030107280239462852, -0.048684924840927124, 0.042285092175006866, 0.030554834753274918, -0.049044378101825714, 0.039308857172727585, -0.04641285911202431, -0.10840539634227753, 0.0814240351319313, 0.007742161862552166, -0.03182302787899971, -0.10442876815795898, 0.0543554350733757, -0.012621157802641392, -0.04652633145451546, 0.010006101801991463, 0.09599855542182922, -0.04287099838256836, -0.01802072674036026, -0.0723058208823204, 0.010914385318756104, -0.009746091440320015, 0.04066675528883934, -0.006319981999695301, 0.029671547934412956, 0.0956551730632782, -0.03747853636741638, 0.022519085556268692, -0.003304598154500127, -0.046886738389730453, 0.07785588502883911, -0.025473173707723618, -0.010219000279903412, 0.041696369647979736, -0.015363113954663277, -0.005501770414412022, 0.021140137687325478, 0.016800565645098686, 0.05981699004769325, -0.023337995633482933, -0.026705659925937653, -0.040574394166469574, 0.06428848952054977, -0.019141733646392822, 0.033235687762498856, 0.05137699469923973, -0.07906980067491531, 0.029194248840212822, -0.03553875908255577, -0.02178073674440384, 0.08624338358640671, -0.02837465889751911, -0.03057645820081234, 0.08097419887781143, -0.04416818171739578, 0.013335603289306164, 0.028008202090859413, 0.03964703530073166, 0.10357052832841873, 0.042793914675712585, 0.02405737340450287, 0.00039379094960168004, 0.050644129514694214, 0.03262336552143097, 0.015314197167754173, 0.004592393524944782, 0.010903528891503811, -0.021383220329880714, -0.09357710182666779, 0.01097519788891077, 0.01087159849703312, 0.053922440856695175, -0.07709413766860962, 0.0400952585041523, -0.08012250065803528, -0.03727679327130318, -0.11374609172344208, -0.06530727446079254, -0.040339384227991104, 0.0514213852584362, 0.010149152018129826, 0.08772287517786026, 0.012054439634084702, -0.0029193947557359934, -0.04313553869724274, -0.07654377818107605, -0.01924894005060196, -0.02904299832880497, -0.0069141932763159275, 0.06466436386108398, -0.09852129220962524, -0.0575905442237854, -0.09475398808717728, -0.06337913870811462, 0.057742197066545486, -0.04466572776436806, -0.058691516518592834, -0.0007097031339071691, -0.03672197088599205, 0.0451488234102726, -0.0712309181690216, -0.04542672634124756, 0.04490673542022705, 0.07470215857028961, 0.05319664999842644, 0.02254387177526951, 0.001207228284329176, -0.08572713285684586, 0.03536302596330643, -0.04399063065648079, -0.0165393128991127, -0.05736003816127777, -0.012322303839027882, -0.03418973833322525, -0.051076989620923996, 0.013874601572751999, 0.07176615297794342, -0.08236785233020782, -0.002183330710977316, -0.006263652350753546, 0.046697281301021576, -0.010509627871215343, 0.0007958787609823048, -0.0351606160402298, -0.03136056289076805, 0.01787126623094082, -0.006707599852234125, -0.02958407998085022, -0.03229720517992973, 0.025171222165226936, 0.0047699701972305775, 0.0407792292535305, 0.0018415506929159164, 0.007194089237600565, 0.01904137060046196, 0.04390338808298111, 0.0025939021725207567, 0.04248293489217758, 0.00044876179890707135, -0.04736074060201645, -0.0016269921325147152, -0.02471456676721573, -0.030721839517354965, 0.03433984890580177, 0.02109871432185173, -0.02775084786117077, 0.03189647197723389, -0.0020957260858267546, -0.009777668863534927, 0.022319374606013298, 0.029362037777900696, 0.05817735940217972, 0.04293420910835266, 0.010625151917338371, -0.053498394787311554, 0.01041644997894764, 0.006907897535711527, -0.010403132997453213, -0.04322481155395508, -0.011131998151540756, -0.02061438001692295, -0.0596308633685112, 0.017431238666176796, 0.000873089418746531, -0.002562725218012929, 0.005068926606327295, -0.004160343669354916, 0.0039640734903514385, 0.0074939788319170475, -0.0793582946062088, -0.015628619119524956, 0.021290745586156845, 0.004534711595624685, -0.02482464723289013, -0.017408495768904686, 0.001263270154595375, 0.02156958356499672, 0.01155695877969265, 0.01928766816854477, 0.003377093467861414, -0.011679263785481453, -0.016223018988966942, 0.052759718149900436, -0.032594263553619385, -0.00032603141153231263, 0.033142831176519394, -0.012979459948837757, 0.024856114760041237, -0.03707117959856987, 0.018831705674529076, 0.008236129768192768, 0.01941969059407711, 0.007108625955879688, -0.0003535821451805532, 0.0012009987840428948, 0.005396376829594374, -0.011090781539678574, 0.038483306765556335, -0.025906072929501534, -0.02068854495882988, -0.07328629493713379, 0.0011380083160474896, 0.01721944846212864, -0.05930185317993164, 0.0077019063755869865, -0.01835767552256584, 0.05060373619198799, 0.006830170284956694, 0.05089505389332771, 0.04455507919192314, 0.02522011287510395, 0.03187563642859459, 0.06185421720147133, 0.03886232525110245, -0.02072160691022873, -0.01556004211306572, -0.007405059412121773, 0.014619027264416218, 0.010032422840595245, 0.01373254507780075, 0.0006443902966566384, -0.011689084582030773, 0.06112727150321007, 0.008035330101847649, -0.007447556592524052, 0.018463313579559326, -0.01666904240846634, -0.005940545350313187, -0.04816003888845444, -0.03751935437321663, 0.021317506209015846, -0.03530643507838249, -0.002575840102508664, 0.0068088010884821415, -0.006737719755619764, -0.034731049090623856, 0.02203325554728508, -0.0038019490893930197, 0.010212749242782593, -0.013251202180981636, 0.011034605093300343, 0.011480642482638359, 0.007397378794848919, -0.04138348996639252, 0.00531874131411314, -0.014475553296506405, -0.04123967885971069, 0.04782414436340332, -0.0013612244511023164, -0.00949474424123764, -0.01722804456949234, -0.05805177986621857, 0.0024125203490257263, -0.016780536621809006, 0.030335867777466774, 0.02683931030333042, -0.01810925453901291, 0.05451245978474617, 0.014867882244288921, 0.018925223499536514, -0.02889142371714115, -0.01793964020907879, 0.020243104547262192, -0.06643225997686386, -0.04508713260293007, 0.04583979398012161, 0.01447486411780119, -0.03474317118525505, 0.04908512532711029, 0.028668338432908058, -0.04590064287185669, -0.0054613822139799595, -0.020830748602747917, -0.004430744796991348, 0.01239131297916174, -0.04243968427181244, 0.020616289228200912, 0.004874784499406815, -0.03045664355158806, -0.035425592213869095, 0.017774995416402817, -0.013796848244965076, 0.0013617741642519832, 0.040321234613657, 0.09137028455734253, -0.008516878820955753, -0.002954346127808094, -0.05010439455509186, 0.02376066893339157, -0.011990031227469444, 0.06029260903596878, 0.012013952247798443, 0.014972064644098282, 0.01632602885365486, -0.015359191223978996, 0.030186491087079048, 0.02428288757801056, -0.013403741642832756, -0.028609737753868103, -0.029042262583971024, 0.003656215500086546, 0.04935505613684654, -0.008031141944229603, -0.0013911912683397532, 0.02347136288881302, -0.016727255657315254, -0.04064080864191055, 0.011339335702359676, -0.02923251874744892, 0.020581308752298355, 0.04033529758453369, 0.030593540519475937, -0.052329741418361664, 0.01055207196623087, -0.001666465075686574, -0.025283709168434143, -0.01311542745679617, -0.03590777888894081, 0.029141366481781006, 0.03334609791636467, 0.00972054060548544, -0.06742013990879059, -0.03118792176246643, 0.047692760825157166, 0.002552561927586794, -0.003209703601896763, 0.017179718241095543, 0.048828836530447006, 0.008925963193178177, 0.004653324373066425, -0.0011180603178218007, -0.008734813891351223, 0.0119202621281147, 0.03142765164375305, 0.019623780623078346, -0.0023140006233006716, -0.03517988324165344, 0.03231806308031082, 0.012171775102615356, -0.0033861014526337385, -0.034373875707387924, -0.004146501887589693, -0.006789297331124544, 0.003155865939334035, 0.04509817808866501, -0.0023132460191845894, -0.027295323088765144, 0.029408656060695648, 0.010030049830675125, 0.017820307984948158, -0.012574928812682629, 0.01992127113044262, -0.03067004308104515, 0.002302086679264903, 0.06283385306596756, 0.058364927768707275, 0.06262513995170593, -0.021993229165673256, 0.052524469792842865, 0.03702817112207413, -0.03954746946692467, 0.046493031084537506, -0.05216245725750923, 0.028351373970508575, -0.009528625756502151, 0.024651704356074333, 0.013404078781604767, 0.000007188446488726186, 0.0006657826597802341, 0.021619800478219986, 0.03975716978311539, 0.03972328454256058, -0.04290501028299332, 0.026906926184892654, 0.01043003797531128, -0.010363114066421986, -0.03522910922765732, 0.049671757966279984, -0.054135750979185104, 0.0034394380636513233, -0.007659321650862694, -0.04081697016954422, 0.013458109460771084, -0.0006485647172667086, -0.004771985579282045, 0.01810826174914837, 0.03448551520705223, 0.05846216902136803, 0.012540695257484913, -0.05410517007112503, 0.017933839932084084, -0.025934485718607903, -0.03908398374915123, 0.022017529234290123, -0.055552855134010315, 0.008608012460172176, -0.01805165410041809, 0.01218427810817957, 0.01626729965209961, -0.0022327087353914976, 0.014357652515172958, -0.017519259825348854, 0.07038231939077377, -0.001986569259315729, 0.001168931252323091, 0.0034686822909861803, 0.0025098472833633423, 0.00019352915114723146, -0.029386332258582115, -0.0007484882371500134, -0.019792359322309494, -0.0754096657037735, 0.021647758781909943, -0.061148501932621, 0.030951499938964844, 0.07536505162715912, -0.020706461742520332, 0.001714295707643032, 0.011233218014240265, 0.009915594942867756, 0.014622746035456657, 0.021312270313501358, -0.005194154568016529, 0.07200440019369125, -0.01935284584760666, -0.012426743283867836, 0.011111145839095116, 0.0007287479820661247, 0.09954681992530823, 0.011090424843132496, -0.03957753628492355, 0.05122317373752594, 0.00937079917639494, -0.04655551165342331, 0.04546647146344185, 0.00184668751899153, -0.028192969039082527, -0.013170781545341015, 0.016820142045617104, -0.01830095425248146, 0.03381609916687012, 0.023007551208138466, 0.031549885869026184, -0.0075046285055577755, 0.013596134260296822, 0.025706948712468147, 0.0466935858130455, 0.01906934753060341, 0.03597966581583023, 0.047371260821819305, 0.022706421092152596, 0.0420304536819458, 0.015277422964572906, -0.006985424552112818, -0.00334381777793169, 0.07023881375789642, -0.013498799875378609, -0.01656896062195301, 0.04315655678510666, -0.0142838004976511, -0.019659707322716713, -0.025319436565041542, -0.00958256796002388, -0.017146054655313492, -0.02382616512477398, 0.00590528454631567, -0.043691668659448624, 0.0045621092431247234, 0.018269049003720284, 0.03050989657640457, 0.031428221613168716, 0.04870691895484924, 0.0020312501583248377, 0.053805455565452576, -0.0140135632827878, 0.02198433130979538, -0.003387496341019869, -0.019948748871684074, 0.03219839185476303, -0.01357316505163908, 0.0557306669652462, -0.011108897626399994, 0.013278520666062832, 0.0269195307046175, -0.007125964388251305, -0.001551602385006845, -0.0232357457280159, -0.024795424193143845, 0.011036737821996212, -0.02992030419409275, 0.034713421016931534, 0.013565738685429096, 0.051314178854227066, -0.012791584245860577, 0.012478829361498356, 0.015137466602027416, -0.01906576193869114, 0.004901103209704161, -0.006247043143957853, -0.01374603621661663, 0.014738715253770351, 0.011916046030819416, -0.02802751399576664, 0.015424522571265697, -0.01253694761544466, -0.021883079782128334, 0.0499105229973793, 0.008308112621307373, -0.010101406835019588, 0.011979468166828156, -0.003232478629797697, -0.0356462225317955, 0.017950383946299553, -0.004218514077365398, 0.012919333763420582, 0.007643572986125946, -0.03971222788095474, 0.031125636771321297, -0.0027142774779349566, -0.005851455964148045, -0.00795090850442648, -0.0230235755443573, -0.007951764389872551, -0.013691279105842113, 0.021316777914762497, 0.06510864943265915, -0.030102277174592018, -0.00011239119339734316, 0.027088645845651627, 0.0761946439743042, 0.07770070433616638, 0.04783325642347336, -0.010500135831534863, -0.03671623021364212, -0.006458567921072245, 0.02117583528161049, -0.010444387793540955, 0.041893571615219116, 0.004496247041970491, -0.0026374703738838434, -0.01893354393541813, -0.018401412293314934, -0.02508542872965336, -0.028595300391316414, -0.03146829456090927, 0.01668599061667919, 0.003959501162171364, 0.00013921155186835676, -0.005139603745192289, 0.019225452095270157, -0.00940216425806284, -0.020652465522289276, 0.022813254967331886, -0.006439626216888428, 0.02703121118247509, -0.03891828656196594, 0.014888817444443703, -0.011330820620059967, -0.02553490735590458, -0.00939746294170618, 0.012220075353980064, -0.004540656227618456, 0.02584909275174141, -0.0036322660744190216, 0.04256490617990494, -0.025587406009435654, 0.013177909888327122, 0.011813635937869549, 0.0076680853962898254, 0.0019456770969554782, 0.015170247294008732, 0.03908863291144371, 0.044551555067300797, 0.07671157270669937, 0.019712897017598152, -0.0479566790163517, -0.00706213153898716, -0.01885431446135044, 0.013839652761816978, 0.03452116996049881, 0.04286240413784981, 0.007108490914106369, -0.004995010327547789, -0.017069801688194275, 0.035007547587156296, -0.0178503580391407, -0.01647527888417244, 0.0070553552359342575, 0.005947819445282221, 0.01760859601199627, 0.011371172033250332, 0.02435397170484066, 0.02033342607319355, 0.05486081540584564, -0.008919657208025455, -0.034084733575582504, -0.023950668051838875, 0.02860989049077034, -0.0642564669251442, -0.02666989527642727, 0.017843089997768402, -0.00013141801173333079, 0.036774247884750366, -0.004794370383024216, 0.054154522716999054, 0.007502248045057058, -0.007771902251988649, -0.016176607459783554, -0.03599061071872711, -0.03125739097595215, -0.046783238649368286, -0.012638047337532043, 0.006938869599252939, -0.03156355395913124, -0.029622284695506096, 0.030087891966104507, 0.015402067452669144, 0.02362084947526455, -0.018811505287885666, -0.022774647921323776, 0.005806799978017807, -0.017750784754753113, 0.01853470876812935, -0.015891265124082565, 0.01851957105100155, 0.02898561581969261, 0.05145440623164177, -0.011696700938045979, 0.037688497453927994 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
2. Chunked Feed Forward Layers Transformer-based models often employ very large feed forward layers after the self-attention layer in parallel. Thereby, this layer can take up a significant amount of the overall memory and sometimes even represent the memory bottleneck of a model. First introduced in the Reformer paper, feed forward chunking is a technique that allows to effectively trade better memory consumption for increased time consumption.
[ 0.07683274894952774, -0.05798757076263428, 0.02194908820092678, 0.019522862508893013, 0.0357268862426281, 0.045972757041454315, -0.02201470173895359, 0.015277519822120667, -0.012403078377246857, 0.012754054740071297, -0.08845783770084381, 0.020050685852766037, -0.050591349601745605, 0.07017162442207336, -0.04128831997513771, 0.022251859307289124, 0.06897018104791641, -0.04060526564717293, -0.0706045851111412, 0.05028805509209633, 0.08809411525726318, -0.09606517851352692, 0.11248526722192764, 0.0024324897676706314, -0.042785681784152985, 0.0017285158392041922, -0.005637784954160452, -0.016068512573838234, -0.012654305435717106, -0.00010143529652850702, -0.10199582576751709, -0.011514903046190739, 0.036861199885606766, -0.04670209810137749, -0.03744734078645706, -0.05423333868384361, -0.06911767274141312, 0.03422202542424202, 0.0350520983338356, -0.09372252970933914, -0.039324816316366196, 0.058149974793195724, -0.030288590118288994, 0.038593001663684845, 0.03191360458731651, -0.04269365593791008, -0.07745137065649033, 0.069346122443676, -0.03414946421980858, 0.003774464363232255, -0.0758642628788948, 0.09486055374145508, -0.040832631289958954, 0.03305212780833244, 0.04558490961790085, 0.03510541096329689, -0.009083553217351437, -0.001532727270387113, 0.008313150145113468, 0.010665797628462315, 0.09284987300634384, -0.006515168119221926, -0.012419340200722218, 0.008140605874359608, 0.016093160957098007, -0.07062442600727081, 0.05546661093831062, -0.01278957724571228, -0.07526853680610657, -0.009582185186445713, -0.027695272117853165, -0.04920065030455589, -0.023363972082734108, 0.0059470366686582565, -0.003014092333614826, 0.03481768071651459, 0.04178553447127342, -0.018515752628445625, -0.03206585347652435, -0.0021653517615050077, 0.014128819108009338, 0.10857861489057541, 0.024059254676103592, 0.026111232116818428, 0.027316177263855934, 0.022046811878681183, 0.06929813325405121, -0.11817940324544907, -0.02341046929359436, 0.06018824130296707, -0.012893345206975937, -0.08667927980422974, -0.036550045013427734, -0.00986024085432291, 0.03189536929130554, -0.05279823765158653, 0.01420950423926115, -0.008883519098162651, 0.00984446331858635, -0.009970747865736485, -0.01782401278614998, -0.08226411789655685, 0.029714571312069893, -0.011366200633347034, -0.026411253958940506, 0.011579087004065514, -0.0010377876460552216, -0.12890341877937317, 0.001352702616713941, -0.014529040083289146, 0.005311109125614166, 0.016396695747971535, -0.005055715329945087, 0.03573712334036827, -0.07707922905683517, -0.05023146793246269, -0.059049587696790695, -0.012300029397010803, -0.00002979875534947496, 0.04273265600204468, -0.031157774850726128, 0.08762095868587494, 0.06270598620176315, -0.003138030879199505, 0.05174338072538376, 0.0015756279462948442, 0.03416033089160919, 0.017606796696782112, -0.0006013729725964367, 0.010870207101106644, 0.05494179576635361, 0.011998584493994713, 0.0067356424406170845, 0.026527615264058113, 0.013415816240012646, -0.06554549932479858, 0.0450793020427227, -0.025205830112099648, -0.006327854003757238, 0.04014654830098152, -0.06157117336988449, 0.022199111059308052, 0.07381635159254074, -0.08922459185123444, 0.03016197867691517, -0.13903510570526123, -0.13329839706420898, 0.06281299144029617, 0.0745745301246643, -0.02292361669242382, -0.08980593085289001, 0.05427571013569832, -0.03659846633672714, -0.04583754390478134, -0.006568878423422575, 0.04441419243812561, -0.024401377886533737, -0.07411636412143707, -0.04570186510682106, 0.0013384060002863407, 0.012622753158211708, 0.029759665951132774, -0.013643327169120312, 0.041550762951374054, 0.047746557742357254, -0.03337496146559715, 0.004768654704093933, -0.01870853267610073, -0.02165217138826847, -0.022106440737843513, 0.010849342681467533, 0.0403904914855957, -0.00732308579608798, -0.0048952605575323105, -0.008757881820201874, 0.04734739288687706, 0.01973891817033291, 0.07980387657880783, -0.028213081881403923, -0.058548349887132645, -0.034130752086639404, -0.019875701516866684, 0.017618706449866295, 0.004634672310203314, -0.008598790504038334, 0.0018266061088070273, 0.018284043297171593, -0.02203506790101528, -0.07369548827409744, 0.08084248006343842, -0.03594686836004257, 0.0018967122305184603, 0.038672350347042084, -0.04042980447411537, 0.05874734744429588, 0.007875560782849789, -0.05068342387676239, 0.007873661816120148, 0.06715669482946396, 0.09498640149831772, 0.0685521736741066, 0.0548650398850441, -0.03696950897574425, -0.008671595714986324, 0.008889904245734215, -0.03537428751587868, 0.05847884342074394, -0.028763603419065475, 0.07738412171602249, -0.021350428462028503, 0.012295437045395374, -0.055504195392131805, 0.03815881535410881, -0.00393205089494586, -0.003472790587693453, -0.06419793516397476, -0.012072823941707611, 0.01314427237957716, -0.0909491553902626, -0.004140462726354599, 0.06212227791547775, 0.014275086112320423, -0.11240329593420029, 0.013408730737864971, 0.02622300758957863, 0.00026986555894836783, 0.03972967341542244, -0.04321056604385376, 0.011685200035572052, -0.05270268768072128, -0.02632324956357479, -0.0010107815032824874, 0.012754839845001698, 0.03789341449737549, -0.009864963591098785, -0.026215573772788048, -0.057062048465013504, 0.050689730793237686, 0.0417441725730896, -0.05547266826033592, -0.08843274414539337, 0.019674817100167274, 0.05200434848666191, 0.022923646494746208, 0.05358877032995224, 0.0032280944287776947, 0.044220443814992905, 0.010492359288036823, -0.052110545337200165, 0.04161372780799866, -0.03314986079931259, 0.07520130276679993, 0.03659563139081001, -0.09249462932348251, -0.040810491889715195, 0.012746668420732021, 0.006308853626251221, -0.06426029652357101, 0.014699934981763363, 0.03949344530701637, 0.011536791920661926, 0.010235660709440708, -0.07553525269031525, -0.023205552250146866, -0.03274306654930115, -0.041848424822092056, 0.014579875394701958, -0.031877413392066956, 0.03935665264725685, -0.006647208239883184, -0.009398397989571095, -0.03148103877902031, 0.0066772024147212505, -0.0127014284953475, 0.02721363678574562, -0.0028806047048419714, 0.028300102800130844, -0.0036482748109847307, 0.04842229187488556, -0.037592239677906036, -0.031149333342909813, -0.00410280330106616, 0.04498954117298126, 0.0136528629809618, 0.006630833726376295, 0.022142522037029266, 0.01605536788702011, -0.013845985755324364, -0.033251937478780746, 0.009895029477775097, -0.004457404371351004, 0.01522551104426384, -0.03113402985036373, -0.0021525577176362276, -0.017605623230338097, 0.043997690081596375, -0.016281958669424057, -0.05556037649512291, -0.03068072348833084, -0.02547326497733593, 0.004624609835445881, 0.03349392116069794, -0.00008876172796590254, -0.02845396101474762, -0.005154415033757687, -0.02047795243561268, -0.04166104644536972, 0.03337353467941284, -0.08021777868270874, -0.07636087387800217, -0.001512455171905458, -0.029420582577586174, 0.004076173063367605, -0.0382232591509819, 0.014783110469579697, 0.008508692495524883, -0.01418973132967949, -0.013390123844146729, 0.024879440665245056, -0.008321300148963928, 0.009254188276827335, 0.008684410713613033, -0.02292412333190441, -0.02964969351887703, 0.02826773002743721, 0.007249894551932812, 0.062013279646635056, -0.026806171983480453, 0.0013405542122200131, 0.021853679791092873, 0.004759857431054115, 0.05051673948764801, -0.0071296910755336285, 0.021479126065969467, 0.012148174457252026, -0.025590449571609497, 0.020917823538184166, 0.016963722184300423, -0.037220705300569534, -0.03788844123482704, 0.0029978721868246794, 0.019666945561766624, -0.005009040702134371, -0.005464534275233746, -0.023986423388123512, 0.020772472023963928, 0.07902400195598602, 0.023583490401506424, 0.0696803405880928, -0.0013074743328616023, 0.0716182291507721, 0.008990525268018246, 0.012046626769006252, -0.002606868278235197, 0.0273708738386631, -0.046301908791065216, 0.04234030097723007, -0.02822965569794178, -0.0002244087227154523, -0.04239160194993019, 0.01990039087831974, -0.01928541250526905, -0.011615746654570103, -0.016468172892928123, 0.02572757564485073, 0.006997513119131327, 0.0075165946036577225, -0.022624218836426735, -0.025736352428793907, 0.05191187560558319, -0.013660857453942299, 0.012407021597027779, -0.028643451631069183, 0.012757744640111923, 0.01781924068927765, 0.026980964466929436, 0.011857997626066208, 0.006806522607803345, -0.04170085862278938, 0.022871632128953934, 0.007974416017532349, 0.000723683217074722, -0.014787739142775536, -0.0035691894590854645, 0.005204502958804369, -0.02096528373658657, 0.04285174980759621, 0.03258887678384781, 0.014710537157952785, 0.004837180953472853, -0.032952841371297836, -0.007226095534861088, 0.018921731039881706, 0.029925193637609482, 0.006244593299925327, 0.00623340206220746, 0.019838063046336174, 0.03482658416032791, 0.02916281297802925, -0.010367768816649914, 0.005652913823723793, -0.022254308685660362, 0.000790173769928515, 0.014042404480278492, -0.01954847201704979, 0.03610603138804436, -0.010142529383301735, -0.026317793875932693, 0.01415205653756857, -0.03944402560591698, -0.005400562658905983, 0.03208117187023163, -0.0002463912533130497, 0.02206670120358467, 0.0013109688879922032, -0.014295789413154125, 0.028966398909687996, -0.013248632661998272, -0.008612650446593761, -0.018229467794299126, -0.006918024271726608, 0.04022518917918205, 0.008204418234527111, 0.012611333280801773, -0.061553530395030975, -0.000466396362753585, 0.006882275454699993, 0.014525621198117733, -0.02877935580909252, 0.018064649775624275, 0.010012063197791576, -0.048466455191373825, 0.04359478875994682, -0.0032754584681242704, 0.003862636163830757, -0.011876496486365795, -0.002745790174230933, -0.014954191632568836, -0.03074866533279419, 0.004299502354115248, 0.05401334539055824, 0.017732398584485054, -0.02235100418329239, 0.005700529087334871, -0.05913080275058746, 0.022937949746847153, -0.0009606060921214521, -0.04826353117823601, -0.029030459001660347, 0.02366803213953972, 0.015831725671887398, -0.025914423167705536, 0.04930010437965393, 0.02366693876683712, -0.009753416292369366, 0.025861965492367744, -0.03020947054028511, 0.013765414245426655, 0.06767099350690842, 0.018394777551293373, -0.04613673686981201, 0.05222373083233833, 0.06828723102807999, 0.014134877361357212, 0.01338037010282278, 0.022210193797945976, 0.00879195798188448, -0.004142367281019688, 0.026749247685074806, -0.004671290051192045, -0.06267381459474564, 0.004973270930349827, 0.04207468777894974, 0.02104518748819828, -0.01000954955816269, -0.050729818642139435, 0.010979772545397282, -0.01227861549705267, -0.023482831194996834, 0.014226669445633888, 0.0035906322300434113, 0.015384910628199577, -0.008818547241389751, 0.006930574309080839, 0.0019766693003475666, -0.017171485349535942, 0.036870356649160385, 0.003242981620132923, -0.01784457080066204, 0.030380379408597946, 0.03546746447682381, 0.024021269753575325, 0.038413144648075104, 0.0872076004743576, 0.015190976671874523, 0.09818526357412338, -0.05022522807121277, 0.0201752707362175, 0.0562996082007885, 0.012311933562159538, -0.008757708594202995, 0.004773674998432398, 0.0454501211643219, 0.024507522583007812, 0.009387868456542492, -0.010024570859968662, -0.0344395749270916, -0.0007135138148441911, 0.028008747845888138, 0.06602907180786133, -0.007441861554980278, -0.002310172189027071, -0.010530462488532066, 0.01685963198542595, -0.02588983252644539, 0.008161861449480057, -0.022038282826542854, 0.0069176144897937775, 0.050825826823711395, 0.03283512219786644, -0.011283568106591702, -0.015843575820326805, -0.015670744702219963, 0.002219715854153037, 0.016328221186995506, 0.03496306762099266, 0.020213082432746887, 0.02403533086180687, 0.029459603130817413, -0.01439761370420456, -0.03035208024084568, -0.009356694296002388, -0.008795865811407566, -0.07445661723613739, -0.02785998210310936, -0.02248138189315796, -0.06348833441734314, 0.028862403705716133, 0.013698307797312737, 0.01997588947415352, -0.006700956262648106, -0.004699349403381348, 0.012928980402648449, -0.0032074195332825184, -0.0371861532330513, 0.06631341576576233, 0.04331200569868088, -0.014764291234314442, 0.02214030548930168, -0.011813541874289513, -0.040385615080595016, 0.030597174540162086, -0.03396671637892723, -0.01406855694949627, 0.04178311303257942, -0.03824353963136673, 0.022402582690119743, 0.026770295575261116, 0.052004631608724594, -0.030051959678530693, -0.014146793633699417, -0.007434158120304346, -0.014849679544568062, -0.03495156764984131, 0.03459692373871803, 0.016647426411509514, 0.03125669062137604, -0.007319639902561903, 0.015311220660805702, -0.012611337937414646, -0.015839898958802223, 0.007674784399569035, -0.0056641544215381145, 0.057950932532548904, -0.018095729872584343, -0.033863600343465805, -0.008436942473053932, 0.021935181692242622, 0.01462139468640089, 0.024385623633861542, -0.012030042707920074, 0.02268064208328724, -0.02123604342341423, 0.029316876083612442, 0.01708788238465786, 0.0024709373246878386, 0.015120645053684711, 0.040083982050418854, 0.04082150757312775, 0.02215411514043808, 0.06469804048538208, 0.0075813899748027325, 0.027827005833387375, -0.02148500643670559, 0.041193172335624695, -0.03214136138558388, -0.005773151759058237, 0.02534620091319084, 0.0015632034046575427, 0.006995087023824453, 0.027566993609070778, -0.009958119131624699, -0.0314122699201107, 0.020338766276836395, -0.00167093425989151, -0.019697654992341995, 0.00585961202159524, 0.016480084508657455, 0.009046565741300583, -0.005336462054401636, -0.017181897535920143, 0.007619527168571949, 0.01672927476465702, 0.02283620461821556, 0.01417700294405222, 0.046881310641765594, 0.0294128879904747, 0.017650533467531204, -0.03422785550355911, 0.01611640304327011, -0.010124827735126019, 0.013614586554467678, -0.011576869525015354, -0.025274423882365227, 0.024392422288656235, -0.034190356731414795, -0.000468519632704556, 0.00619765417650342, -0.03472718596458435, -0.028336629271507263, 0.019289517775177956, -0.01726408861577511, -0.016082119196653366, -0.025520261377096176, 0.034977179020643234, 0.0032156705856323242, -0.019255559891462326, -0.013961595483124256, -0.04168127104640007, -0.00007671847561141476, -0.018463414162397385, -0.018311897292733192, -0.0169903002679348, 0.014213232323527336, 0.003544518258422613, 0.02219235524535179, -0.0041634878143668175, -0.029316231608390808, 0.0077064200304448605, 0.037612877786159515, -0.0014462975086644292, 0.010853835381567478, 0.04627712443470955, -0.015843505039811134, 0.05496305972337723, -0.012273173779249191, -0.02971941977739334, 0.04954155534505844, -0.009999744594097137, 0.009242665953934193, -0.03914697840809822, 0.014574380591511726, -0.012187425047159195, -0.04151759296655655, 0.032913900911808014, -0.024086778983473778, 0.014036515727639198, 0.0059057362377643585, 0.033094827085733414, 0.034791745245456696, 0.03345618024468422, -0.03207128494977951, 0.010294421575963497, -0.01472387183457613, -0.04297352954745293, -0.023469720035791397, 0.014332536607980728, 0.03226408362388611, -0.01185555849224329, 0.012148887850344181, -0.04551469907164574, -0.012216994538903236, -0.01868390664458275, 0.01847602240741253, 0.023433012887835503, 0.022793689742684364, -0.04167741537094116, -0.006721364334225655, 0.007410699035972357, -0.02613084763288498, 0.004013606812804937, 0.016718795523047447, 0.03164459764957428, -0.0012007108889520168, -0.048211969435214996, 0.009007524698972702, -0.021156948059797287, -0.01544446311891079, -0.026679912582039833, -0.03110261633992195, -0.008908871561288834, 0.03941100090742111, 0.010658768005669117, 0.029536422342061996, -0.0036261051427572966, 0.05093875899910927, -0.007686998229473829, 0.013490501791238785, 0.016184931620955467, 0.025759268552064896, 0.0035671566147357225, -0.017118185758590698, 0.004139153752475977, 0.01236634235829115, -0.039826638996601105, -0.05660657957196236, -0.03151651471853256, 0.04944052919745445, 0.06428854167461395, -0.032655537128448486, 0.035219691693782806, 0.01109614223241806, -0.005595289170742035, -0.05068501457571983, -0.09336785972118378, -0.024299636483192444, 0.003288164036348462, -0.007298434618860483, -0.011383665725588799, -0.05617206171154976, 0.02441033162176609, 0.01024263072758913, 0.039982594549655914, 0.034978803247213364, -0.03046264871954918, -0.0322728231549263, 0.015620872378349304, -0.03375672921538353, -0.022028543055057526, 0.0027941002044826746, 0.04015083983540535, 0.023872943595051765, 0.014683740213513374, 0.04291028901934624, 0.030027637258172035, 0.05779075622558594, 0.02172418311238289, 0.022045256569981575, -0.02813144028186798, -0.02875588834285736, 0.04659620672464371, -0.011895778588950634, 0.00009699346264824271, -0.04537668079137802, -0.008011117577552795, 0.04204483702778816, 0.029324427247047424, -0.013626028783619404, -0.02703665941953659, -0.011855683289468288, -0.03205573186278343, 0.023724880069494247, -0.01973371021449566, -0.00014889758313074708, -0.022799907252192497, 0.034097906202077866, -0.054130587726831436, -0.022223088890314102 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
Benchmark Lastly, let's also compare the peak memory consumption of conventional positional embeddings to axial positional embeddings. #@title Installs and Imports # pip installs !pip -qq install git+https://github.com/huggingface/transformers.git !pip install -qq py3nvml from transformers import ReformerConfig, PyTorchBenchmark, PyTorchBenchmarkArguments, ReformerModel Positional embeddings depend only on two configuration parameters: The maximum allowed length of input sequences config.max_position_embeddings and config.hidden_size. Let's use a model that pushes the maximum allowed length of input sequences to half a million tokens, called google/reformer-crime-and-punishment, to see the effect of using axial positional embeddings. To begin with, we will compare the shape of axial position encodings with standard positional encodings and the number of parameters in the model. config_no_pos_axial_embeds = ReformerConfig.from_pretrained("google/reformer-crime-and-punishment", axial_pos_embds=False) # disable axial positional embeddings config_pos_axial_embeds = ReformerConfig.from_pretrained("google/reformer-crime-and-punishment", axial_pos_embds=True, axial_pos_embds_dim=(64, 192), axial_pos_shape=(512, 1024)) # enable axial positional embeddings print("Default Positional Encodings") print(20 * '-') model = ReformerModel(config_no_pos_axial_embeds) print(f"Positional embeddings shape: {model.embeddings.position_embeddings}") print(f"Num parameters of model: {model.num_parameters()}") print(20 * '-' + '\n\n') print("Axial Positional Encodings") print(20 * '-') model = ReformerModel(config_pos_axial_embeds) print(f"Positional embeddings shape: {model.embeddings.position_embeddings}") print(f"Num parameters of model: {model.num_parameters()}") print(20 * '-' + '\n\n') HBox(children=(FloatProgress(value=0.0, description='Downloading', max=1151.0, style=ProgressStyle(description… Default Positional Encodings -------------------- Positional embeddings shape: PositionEmbeddings( (embedding): Embedding(524288, 256) ) Num parameters of model: 136572416 -------------------- Axial Positional Encodings -------------------- Positional embeddings shape: AxialPositionEmbeddings( (weights): ParameterList( (0): Parameter containing: [torch.FloatTensor of size 512x1x64] (1): Parameter containing: [torch.FloatTensor of size 1x1024x192] ) ) Num parameters of model: 2584064 -------------------- Having read the theory, the shape of the axial positional encoding weights should not be a surprise to the reader. Regarding the results, it can be seen that for models being capable of processing such long input sequences, it is not practical to use default positional encodings. In the case of google/reformer-crime-and-punishment, standard positional encodings alone contain more than 100M parameters. Axial positional encodings reduce this number to just over 200K. Lastly, let's also compare the required memory at inference time. benchmark_args = PyTorchBenchmarkArguments(sequence_lengths=[512], batch_sizes=[8], models=["Reformer-No-Axial-Pos-Embeddings", "Reformer-Axial-Pos-Embeddings"], no_speed=True, no_env_print=True) benchmark = PyTorchBenchmark(configs=[config_no_pos_axial_embeds, config_pos_axial_embeds], args=benchmark_args) result = benchmark.run() 1 / 2 2 / 2 ==================== INFERENCE - MEMORY - RESULT ==================== -------------------------------------------------------------------------------- Model Name Batch Size Seq Length Memory in MB -------------------------------------------------------------------------------- Reformer-No-Axial-Pos-Embeddin 8 512 959 Reformer-Axial-Pos-Embeddings 8 512 447 -------------------------------------------------------------------------------- It can be seen that using axial positional embeddings reduces the memory requirement to approximately half in the case of google/reformer-crime-and-punishment.
[ -0.005621132906526327, 0.06044059619307518, 0.002853718353435397, -0.0029139630496501923, -0.04365549236536026, 0.043265555053949356, 0.05198361352086067, -0.03543691337108612, -0.07352297008037567, -0.012052522972226143, -0.05069165676832199, 0.027702873572707176, 0.018546422943472862, -0.004689125809818506, 0.05188644304871559, -0.04733484238386154, 0.0637362152338028, -0.00638813991099596, -0.05466166138648987, 0.00574336526915431, 0.0192443635314703, -0.0999651625752449, 0.046252280473709106, 0.004129280336201191, -0.029962509870529175, -0.07355188578367233, -0.009314117021858692, -0.053431034088134766, -0.06234307959675789, 0.023972634226083755, -0.17116709053516388, -0.026250705122947693, 0.021065382286906242, -0.0368838906288147, 0.02766450121998787, -0.02527250349521637, -0.11305902153253555, 0.08226674050092697, 0.05221690610051155, -0.02895278111100197, -0.051247451454401016, 0.01257358305156231, -0.027260446920990944, 0.026919934898614883, 0.011570286005735397, -0.0031540384516119957, -0.1280108243227005, 0.08575268089771271, -0.01840393990278244, -0.0030880740378051996, -0.09072578698396683, 0.03699716553092003, -0.028510015457868576, 0.0677860900759697, -0.01852569915354252, -0.014528452418744564, 0.034728456288576126, -0.0666901022195816, 0.023663198575377464, -0.02236763760447502, 0.03277790918946266, 0.03185047581791878, 0.056758031249046326, 0.045566532760858536, -0.0002182019961765036, 0.038032662123441696, -0.08983130007982254, 0.07023217529058456, -0.048291515558958054, -0.03776371106505394, 0.020884349942207336, 0.0181925967335701, -0.038802798837423325, -0.01458426471799612, -0.01805839315056801, -0.06210389733314514, -0.06532596051692963, 0.005052600987255573, 0.07058661431074142, 0.04541655257344246, -0.010135741904377937, 0.06402312219142914, 0.034947194159030914, 0.006840193178504705, 0.02466338872909546, 0.050744690001010895, 0.049363814294338226, 0.0008243866031989455, -0.027131378650665283, 0.04167233034968376, -0.03180034086108208, -0.07399796694517136, 0.007281001657247543, 0.028698617592453957, -0.030551230534911156, -0.0026592162903398275, 0.018524033948779106, 0.0274928230792284, -0.021134231239557266, 0.008118687197566032, -0.00542264711111784, -0.05049118027091026, 0.01133924163877964, -0.035518545657396317, 0.013196130283176899, -0.0010069920681416988, -0.061134081333875656, -0.08994528651237488, 0.017372963950037956, 0.016530103981494904, -0.06785288453102112, 0.015464328229427338, -0.03506556153297424, 0.031073058024048805, -0.10496832430362701, 0.01604776829481125, -0.0372772179543972, -0.04111194983124733, 0.005776630714535713, 0.04741198942065239, -0.014004550874233246, 0.04402288794517517, 0.033054936677217484, -0.00813909713178873, 0.01524318102747202, 0.026367897167801857, -0.0003766627924051136, 0.04786010831594467, 0.003902392229065299, -0.007507853209972382, 0.02620857208967209, 0.00954783707857132, 0.09069915860891342, 0.012722741812467575, -0.040632184594869614, -0.08115072548389435, 0.036215443164110184, -0.04041162505745888, -0.02893538400530815, -0.04066939651966095, -0.04639701917767525, 0.02924288623034954, 0.03366483747959137, -0.038666240870952606, 0.04151587188243866, -0.05798845738172531, -0.09884615242481232, 0.0809648260474205, -0.0035889900755137205, -0.05130767077207565, -0.07208354771137238, 0.07570725679397583, -0.004433684051036835, -0.014392679557204247, 0.036648813635110855, 0.04918713495135307, -0.016776302829384804, -0.03180974721908569, -0.05190061777830124, -0.030094392597675323, -0.026011770591139793, 0.006266220938414335, -0.0394805483520031, -0.004235020838677883, 0.03995387628674507, -0.020336775109171867, 0.05546083673834801, -0.03087284043431282, -0.025792177766561508, 0.02864093892276287, -0.04633276164531708, -0.007943620905280113, 0.030909011140465736, -0.005970061756670475, -0.048320479691028595, 0.03950453922152519, 0.010122734121978283, 0.07406946271657944, -0.001205346081405878, -0.051495205610990524, -0.03511693701148033, 0.08077448606491089, -0.005248938221484423, 0.08352097868919373, 0.0618952214717865, -0.08217434585094452, 0.009217150509357452, -0.03484932333230972, 0.005700604524463415, -0.006993105635046959, -0.023056941106915474, -0.03980102017521858, 0.07296950370073318, -0.023299939930438995, 0.04363606870174408, -0.011156931519508362, 0.01306035928428173, 0.05108049884438515, 0.027042414993047714, 0.010246659629046917, 0.009635502472519875, 0.054048459976911545, 0.031874075531959534, 0.025220518931746483, -0.03866824880242348, -0.04651777446269989, -0.06542427837848663, -0.05342251807451248, 0.03250114992260933, 0.03355705738067627, 0.03890584409236908, -0.10161836445331573, 0.022583719342947006, -0.021922361105680466, 0.003977373708039522, -0.07316761463880539, -0.022316824644804, 0.002485178876668215, -0.004520252346992493, -0.009934653528034687, 0.1306968629360199, -0.049361634999513626, -0.014700507745146751, -0.04171237722039223, -0.03280600532889366, 0.023829279467463493, -0.013773974031209946, 0.0659489780664444, 0.01631671003997326, -0.09084706753492355, -0.05011804401874542, -0.06720923632383347, -0.006481107324361801, 0.058167871087789536, -0.013069349341094494, -0.09072520583868027, 0.018211519345641136, 0.03729763999581337, 0.07174380868673325, -0.006516329478472471, -0.02327529713511467, -0.0075528789311647415, 0.06819386035203934, 0.04484165459871292, -0.0076682367362082005, 0.002903689630329609, -0.03864307329058647, 0.013785558752715588, -0.022028014063835144, -0.018960697576403618, -0.11399977654218674, -0.007421944756060839, 0.008380964398384094, -0.020778566598892212, 0.017178857699036598, 0.0922706127166748, -0.047602973878383636, 0.007006428670138121, -0.04442140832543373, 0.0721229612827301, 0.035364147275686264, 0.03178289532661438, -0.07302626222372055, -0.0525851845741272, -0.00910448282957077, -0.007399666588753462, -0.01871281862258911, -0.033236827701330185, 0.016285402700304985, -0.014360259287059307, 0.023536372929811478, -0.020959364250302315, 0.05145305022597313, 0.020954543724656105, 0.01990232802927494, 0.008851987309753895, 0.010846118442714214, -0.037058982998132706, -0.01484634168446064, 0.013911008834838867, -0.012929820455610752, -0.014669305644929409, 0.03141145035624504, 0.022814122959971428, -0.02794705517590046, 0.032885465770959854, 0.011719275265932083, -0.018129199743270874, -0.02906074933707714, 0.011396295391023159, 0.045838821679353714, 0.04091149941086769, 0.01866435632109642, -0.07050319761037827, 0.005193412769585848, -0.019062168896198273, -0.015843231230974197, -0.02726506069302559, -0.0024510298389941454, 0.013473047874867916, -0.03642745316028595, 0.012174975126981735, -0.028374971821904182, 0.005275542847812176, -0.005581859964877367, -0.00430191308259964, 0.005268452689051628, 0.04650607332587242, -0.08734337985515594, -0.029964979737997055, -0.002048458671197295, 0.00800007302314043, 0.0010959743522107601, -0.011821601539850235, 0.017390795052051544, -0.009875858202576637, -0.0005359204951673746, 0.01482067909091711, 0.02703176997601986, 0.0014548967592418194, 0.006618413142859936, 0.026073843240737915, -0.019063325598835945, 0.04352135211229324, 0.06223118677735329, 0.0024094947148114443, 0.014858849346637726, -0.019305510446429253, 0.021111497655510902, 0.014557143673300743, 0.010423810221254826, 0.0179466363042593, -0.004105585627257824, 0.02743852511048317, 0.01039885450154543, 0.008324647322297096, 0.03685261681675911, -0.05295427888631821, -0.05057939141988754, -0.053953468799591064, -0.02168533205986023, 0.008136008866131306, -0.049640752375125885, -0.0202006958425045, -0.03773966804146767, 0.03551965579390526, -0.016541387885808945, 0.02727072313427925, 0.03651360049843788, -0.02341952547430992, 0.029513893648982048, 0.023961249738931656, 0.06469061225652695, -0.026806369423866272, 0.0073578995652496815, -0.005568963475525379, 0.024595066905021667, -0.04045531526207924, -0.029474489390850067, 0.017469530925154686, 0.015489159151911736, 0.05763161927461624, 0.03269793465733528, -0.01105960551649332, -0.042172711342573166, 0.01711696945130825, -0.0022359348367899656, -0.017902452498674393, -0.028573155403137207, 0.025964045897126198, -0.025101574137806892, 0.020224452018737793, -0.010365656577050686, 0.02405160665512085, -0.023409413173794746, 0.012648332864046097, -0.004890854004770517, 0.014178231358528137, -0.0608147531747818, 0.013350767083466053, -0.002278931438922882, 0.01017215196043253, -0.035634882748126984, 0.011939426884055138, -0.005943764932453632, -0.04040245711803436, 0.02810443565249443, 0.005865791346877813, -0.03373611345887184, -0.019167188555002213, -0.047130756080150604, 0.02299894019961357, -0.012915496714413166, 0.031998034566640854, 0.020535003393888474, -0.025279520079493523, 0.063016876578331, -0.005156715400516987, -0.006439287681132555, 0.0048715765587985516, -0.02322692610323429, -0.005146384704858065, -0.010336949490010738, -0.05055079981684685, 0.01056783925741911, -0.011174635961651802, -0.010134060867130756, 0.04825111851096153, -0.02069590426981449, -0.0593477338552475, 0.012375522404909134, 0.008406763896346092, 0.005256760865449905, 0.018354125320911407, -0.02790304459631443, 0.021073680371046066, 0.013003874570131302, 0.0010276997927576303, -0.011798609979450703, 0.0027438474353402853, 0.006223701871931553, 0.0074126506224274635, 0.057264190167188644, 0.06271792948246002, -0.0015744593692943454, -0.02815384790301323, -0.06666840612888336, 0.008942573331296444, 0.003082879586145282, 0.01848144829273224, -0.024397140368819237, -0.003447689348831773, 0.018055247142910957, 0.010498560965061188, -0.008568682707846165, 0.04578588530421257, -0.04157020151615143, -0.02513088658452034, -0.05293223634362221, 0.02065703645348549, 0.019090626388788223, 0.008242055773735046, -0.012933098711073399, 0.06854167580604553, -0.015024230815470219, -0.017995255067944527, 0.017928676679730415, -0.018014030531048775, -0.01852496899664402, 0.013084528036415577, 0.006536812521517277, -0.025081489235162735, 0.0009993532439693809, 0.012582583352923393, -0.02623659186065197, 0.0224115252494812, -0.03335016965866089, 0.032937489449977875, 0.029532860964536667, 0.022216128185391426, -0.045891840010881424, 0.01737326942384243, 0.05686680227518082, 0.0075087593868374825, -0.02382625825703144, -0.01018373854458332, -0.03979908302426338, 0.0298728309571743, -0.012421594932675362, -0.0026822963263839483, -0.013205507770180702, -0.012663252651691437, 0.00972688291221857, 0.030790628865361214, 0.0031757911201566458, -0.043616071343421936, 0.040822841227054596, -0.011822996661067009, 0.007443998474627733, 0.012686241418123245, 0.03013750910758972, -0.0013310363283380866, 0.020890487357974052, 0.055431462824344635, -0.014397380873560905, 0.012795059010386467, -0.006369185168296099, 0.04303286597132683, 0.017340414226055145, -0.030749784782528877, 0.04199327901005745, 0.008266852237284184, 0.031133435666561127, 0.007713552564382553, 0.07359414547681808, 0.0941392257809639, -0.027325762435793877, 0.014480046927928925, 0.006340702064335346, -0.01968996785581112, 0.016736933961510658, -0.043669942766427994, 0.02934746816754341, -0.02341630309820175, 0.00947444885969162, 0.007577529177069664, 0.006962035782635212, -0.006717690732330084, 0.05625070258975029, 0.06868284940719604, -0.03356257081031799, -0.016183465719223022, 0.004995443858206272, 0.03137194365262985, 0.03275094926357269, -0.04315359517931938, 0.03498615697026253, -0.0429658442735672, 0.014028655365109444, -0.00979189109057188, -0.06583637744188309, 0.025849176570773125, 0.0338158942759037, -0.013727035373449326, -0.01942765712738037, 0.039259009063243866, 0.01399577222764492, 0.04638846218585968, -0.03074246644973755, -0.0009998753666877747, -0.03382449969649315, -0.035111840814352036, 0.04388734698295593, -0.029744772240519524, -0.016531849279999733, 0.01809149608016014, 0.03158307448029518, 0.02683822251856327, 0.00809814129024744, -0.007747473195195198, -0.01121196523308754, 0.03354085609316826, 0.015689579769968987, 0.0026223219465464354, -0.0048066661693155766, 0.028150849044322968, 0.012505244463682175, -0.031080827116966248, -0.004881029948592186, 0.02595103532075882, -0.04589153081178665, 0.039810746908187866, -0.027751032263040543, 0.036082349717617035, 0.048935748636722565, -0.011896312236785889, -0.04226810485124588, 0.009154259227216244, 0.03357167914509773, -0.007932850159704685, 0.014317046850919724, -0.05571286007761955, 0.031480900943279266, -0.0018254014430567622, -0.01813690923154354, -0.004636289086192846, 0.04273052141070366, 0.10236185044050217, -0.0008930630865506828, -0.03437010198831558, 0.032793063670396805, 0.013497582636773586, -0.0696527436375618, 0.025350702926516533, 0.0028241220861673355, -0.023652208968997, -0.006829176563769579, 0.0364830382168293, -0.024920150637626648, 0.062167346477508545, 0.022865310311317444, 0.046122580766677856, 0.018355896696448326, -0.0004910288262180984, 0.03406821936368942, 0.0737280622124672, -0.018571501597762108, 0.03461174666881561, 0.0524849072098732, 0.03251326456665993, 0.06257053464651108, -0.004622602369636297, -0.022583678364753723, 0.007274153642356396, 0.06711281090974808, 0.021428069099783897, -0.008649625815451145, 0.0056514129973948, -0.022191006690263748, 0.02013186179101467, 0.007134983316063881, 0.0029879952780902386, -0.0006390018970705569, 0.020829688757658005, 0.03373436629772186, 0.005208374932408333, 0.02244950830936432, -0.050040747970342636, 0.028022386133670807, 0.007276623044162989, 0.044018521904945374, -0.010649804025888443, 0.035870570689439774, 0.0009396937093697488, 0.0312582291662693, 0.019936662167310715, 0.006895449943840504, 0.02318933606147766, -0.01284968014806509, 0.045598018914461136, 0.006865359377115965, 0.05235985666513443, 0.027936648577451706, -0.004921095911413431, -0.01693578064441681, -0.026498692110180855, -0.052729807794094086, -0.005361640825867653, 0.010593692772090435, 0.016433805227279663, -0.0013979176292195916, 0.020386964082717896, 0.010525763034820557, 0.02183021791279316, -0.012089443393051624, 0.013336719945073128, 0.0016667046584188938, -0.003180219791829586, -0.0057619004510343075, 0.05123300850391388, -0.02152087539434433, 0.003522417740896344, 0.008398803882300854, -0.007185008842498064, -0.04650268331170082, 0.006022961810231209, -0.000001912401103254524, 0.014419958926737309, -0.010624239221215248, 0.00505599332973361, -0.007021794561296701, 0.047344889491796494, -0.04776528850197792, 0.016138026490807533, -0.00617758184671402, 0.03725374862551689, 0.01130149606615305, 0.026202693581581116, 0.011243061162531376, -0.014236151240766048, -0.03574829548597336, -0.008976981043815613, -0.01676969788968563, 0.010142204351723194, 0.040886517614126205, -0.0025536036118865013, 0.03200395405292511, 0.003938482608646154, 0.057461973279714584, 0.04433092847466469, 0.052094798535108566, -0.05730258300900459, -0.031654149293899536, 0.010059162974357605, -0.05544061213731766, -0.020365748554468155, 0.03769925609230995, 0.0015962905017659068, -0.01827317290008068, -0.0435112826526165, -0.04947896674275398, -0.03505420684814453, -0.00578094320371747, -0.013345571234822273, 0.052316173911094666, -0.014039194211363792, -0.001430339296348393, -0.03196137771010399, 0.03104451484978199, 0.017694637179374695, -0.0006120084435679018, 0.01458648405969143, 0.017048027366399765, 0.03235038369894028, -0.004758936353027821, 0.024702848866581917, -0.028912611305713654, -0.021956203505396843, -0.010841558687388897, -0.020618554204702377, -0.017236605286598206, 0.00886799767613411, 0.016010310500860214, 0.003744714427739382, -0.011356392875313759, 0.027560532093048096, -0.001252157730050385, -0.0022280600387603045, 0.0028751608915627003, 0.025749489665031433, 0.016960509121418, 0.03742338344454765, 0.07885707169771194, 0.01887626387178898, -0.028877930715680122, 0.013681750744581223, -0.021812262013554573, -0.0269399993121624, 0.06045868620276451, 0.012869952246546745, 0.012560049071907997, -0.06129991635680199, 0.014093171805143356, 0.030177641659975052, -0.03143658861517906, -0.014828604646027088, 0.003662451636046171, 0.02750295028090477, -0.013828088529407978, -0.01619034633040428, -0.00025921445921994746, 0.048721857368946075, 0.0466640368103981, -0.01576201431453228, -0.01637992449104786, -0.022001221776008606, 0.018942883238196373, -0.038398757576942444, -0.03266323357820511, -0.010993327014148235, -0.005225327331572771, 0.03187084197998047, -0.004596140701323748, 0.050882138311862946, -0.0010696835815906525, -0.0041238097473979, -0.023410335183143616, -0.01893722265958786, -0.03737587854266167, -0.0521441288292408, -0.026995709165930748, 0.06807798147201538, -0.010867041535675526, -0.04072130471467972, 0.011659200303256512, 0.007864794693887234, 0.0418219268321991, 0.004871584475040436, -0.0215427428483963, 0.005070965271443129, 0.009597547352313995, 0.018671659752726555, 0.0032110780011862516, -0.010247173719108105, 0.027927959337830544, 0.03405645117163658, -0.007147299125790596, 0.013145798817276955 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
How the Reformer uses less than 8GB of RAM to train on sequences of half a million tokens The Reformer model as introduced by Kitaev, Kaiser et al. (2020) is one of the most memory-efficient transformer models for long sequence modeling as of today. Recently, long sequence modeling has experienced a surge of interest as can be seen by the many submissions from this year alone - Beltagy et al. (2020), Roy et al. (2020), Tay et al., Wang et al. to name a few. The motivation behind long sequence modeling is that many tasks in NLP, e.g. summarization, question answering, require the model to process longer input sequences than models, such as BERT, are able to handle. In tasks that require the model to process a large input sequence, long sequence models do not have to cut the input sequence to avoid memory overflow and thus have been shown to outperform standard "BERT"-like models cf. Beltagy et al. (2020). The Reformer pushes the limit of longe sequence modeling by its ability to process up to half a million tokens at once as shown in this demo. As a comparison, a conventional bert-base-uncased model limits the input length to only 512 tokens. In Reformer, each part of the standard transformer architecture is re-engineered to optimize for minimal memory requirement without a significant drop in performance. The memory improvements can be attributed to 4 features which the Reformer authors introduced to the transformer world: 1. Reformer Self-Attention Layer - How to efficiently implement self-attention without being restricted to a local context? 2. Chunked Feed Forward Layers - How to get a better time-memory trade-off for large feed forward layers? 3. Reversible Residual Layers - How to drastically reduce memory consumption in training by a smart residual architecture? 4. Axial Positional Encodings - How to make positional encodings usable for extremely large input sequences? The goal of this blog post is to give the reader an in-depth understanding of each of the four Reformer features mentioned above. While the explanations are focussed on the Reformer, the reader should get a better intuition under which circumstances each of the four features can be effective for other transformer models as well. The four sections are only loosely connected, so they can very well be read individually. Reformer is part of the 🤗Transformers library. For all users of the Reformer, it is advised to go through this very detailed blog post to better understand how the model works and how to correctly set its configuration. All equations are accompanied by their equivalent name for the Reformer config, e.g. config.<param_name>, so that the reader can quickly relate to the official docs and configuration file. Note: Axial Positional Encodings are not explained in the official Reformer paper, but are extensively used in the official codebase. This blog post gives the first in-depth explanation of Axial Positional Encodings.
[ -0.004369569011032581, 0.006179500371217728, 0.012773562222719193, -0.028081683441996574, 0.006406466942280531, 0.013453404419124126, 0.044588603079319, -0.04410424828529358, -0.027243223041296005, 0.01543932780623436, -0.0523136667907238, 0.03341088071465492, 0.010224759578704834, 0.03883945941925049, -0.018094390630722046, -0.03685534745454788, 0.04596070200204849, -0.08098377287387848, -0.06026417389512062, -0.012685704044997692, 0.03193442150950432, -0.07990934699773788, 0.062148675322532654, -0.004592197015881538, 0.008163339458405972, -0.010945686139166355, -0.023273777216672897, -0.07022582739591599, -0.024712437763810158, 0.016798293218016624, -0.158734530210495, -0.01856098510324955, 0.021484440192580223, -0.026614518836140633, -0.005830174311995506, -0.03821832686662674, -0.12188106030225754, 0.07185349613428116, 0.04448908194899559, -0.0328887477517128, -0.05759381502866745, 0.001581875141710043, -0.03537425026297569, 0.011440224014222622, 0.014378809370100498, 0.00009903686441248283, -0.1293148249387741, 0.024259520694613457, -0.07490535080432892, -0.023324159905314445, -0.07094662636518478, 0.06275232881307602, -0.03687737509608269, 0.04022715613245964, 0.023841790854930878, -0.012847690843045712, 0.03700213506817818, 0.03834040090441704, 0.020407138392329216, 0.03147125244140625, 0.046471502631902695, 0.02057497389614582, -0.008107485249638557, -0.01760193519294262, -0.0009524732013233006, -0.00474278349429369, -0.04830694943666458, 0.046839118003845215, -0.05208909884095192, -0.05354132130742073, 0.015720698982477188, -0.029260391369462013, -0.029550891369581223, 0.024010447785258293, -0.034561555832624435, -0.08617430925369263, -0.002640702063217759, 0.058277785778045654, 0.061264362186193466, 0.03077039308845997, -0.013213240541517735, 0.08041933923959732, 0.07777845859527588, 0.02762433886528015, 0.07879133522510529, 0.03613981232047081, 0.05930810421705246, -0.08014039695262909, -0.06355587393045425, 0.07771911472082138, -0.042166683822870255, -0.1381513625383377, 0.020746979862451553, -0.037132322788238525, 0.019464759156107903, -0.026869017630815506, -0.0273661557585001, 0.0496041439473629, -0.0039838519878685474, 0.007196845021098852, -0.019489578902721405, -0.07590547949075699, 0.054245736449956894, -0.0233639944344759, -0.06481800973415375, 0.016468949615955353, 0.014461146667599678, -0.120789535343647, 0.016228865832090378, -0.04263203963637352, 0.03515329957008362, 0.07040692120790482, -0.043447572737932205, 0.05304441601037979, -0.05958571657538414, 0.02968374639749527, -0.002652121474966407, -0.021094461902976036, 0.0007480061613023281, 0.004830043297261, -0.02562388777732849, 0.1006307601928711, 0.07547097653150558, -0.021536462008953094, -0.01216045767068863, -0.012465468607842922, -0.03741992264986038, -0.016990220174193382, -0.009052906185388565, -0.06243829429149628, 0.05084359645843506, 0.008954879827797413, 0.024180948734283447, 0.012078124098479748, -0.057051580399274826, -0.01436195895075798, -0.012077640742063522, -0.03367701172828674, -0.0013018571771681309, -0.046055447310209274, -0.04128923639655113, 0.01138873677700758, 0.06648340076208115, -0.0734572559595108, 0.05418306589126587, -0.008440139703452587, -0.10674373060464859, 0.11292634159326553, 0.019140582531690598, -0.0414385087788105, -0.08716239035129547, 0.028088942170143127, -0.02454979158937931, -0.08183687180280685, 0.027356455102562904, 0.049452174454927444, -0.005517973564565182, -0.012021376751363277, -0.07139594107866287, -0.026419246569275856, -0.049979157745838165, 0.04049677029252052, -0.013807297684252262, 0.0668920949101448, 0.05071411281824112, -0.03397947549819946, 0.06110846996307373, 0.01088316272944212, -0.010793634690344334, 0.023193582892417908, 0.052354153245687485, 0.04082711413502693, 0.01961817406117916, -0.05016368255019188, -0.052088409662246704, 0.023477749899029732, 0.05518320947885513, 0.040709394961595535, -0.04180719703435898, -0.05574996769428253, -0.0032026118133217096, 0.01635492779314518, 0.02435828372836113, 0.03244374319911003, 0.0484456941485405, -0.07872012257575989, 0.05056961253285408, -0.04033970087766647, -0.03380309045314789, 0.0467991903424263, -0.014354252256453037, -0.020188312977552414, 0.05496005713939667, 0.004013987723737955, 0.027471249923110008, 0.010355574078857899, -0.009212908335030079, 0.04931690916419029, 0.03247019276022911, 0.11332415044307709, 0.03306775912642479, 0.07250016182661057, -0.02011149562895298, -0.009881395846605301, -0.014212353155016899, -0.028111806139349937, -0.024396076798439026, -0.06812752783298492, 0.08160025626420975, -0.0025023624766618013, 0.035913292318582535, -0.11384789645671844, 0.030092712491750717, -0.07143278419971466, -0.04181842878460884, -0.10299771279096603, 0.057585347443819046, -0.02039765752851963, -0.026182230561971664, 0.030053192749619484, 0.0957188755273819, -0.04109181836247444, -0.07655209302902222, 0.024534020572900772, -0.05203758552670479, 0.03318265452980995, 0.028843507170677185, -0.01117840874940157, 0.05242341011762619, -0.06695887446403503, -0.020082734525203705, -0.07415560632944107, 0.006907582748681307, -0.025766102597117424, -0.014973082579672337, -0.028738439083099365, -0.06781526654958725, 0.02757277339696884, 0.005112678278237581, -0.017131127417087555, -0.032289233058691025, 0.020079338923096657, 0.022176314145326614, 0.005837929435074329, -0.0007598138181492686, 0.011229298077523708, -0.012966281734406948, 0.0513843335211277, -0.018237419426441193, -0.03829269856214523, -0.07164440304040909, 0.03630709648132324, -0.03185895085334778, -0.0733225867152214, -0.028612909838557243, 0.04559461399912834, -0.025133443996310234, -0.013733901083469391, 0.0000678921423968859, 0.030926082283258438, 0.0048163169994950294, 0.01515506487339735, -0.0551045760512352, -0.05009227246046066, -0.016807369887828827, -0.045900363475084305, -0.02483704313635826, -0.03756833076477051, 0.029287174344062805, -0.01810203120112419, 0.023819690570235252, 0.004331391304731369, -0.006441560573875904, 0.027005471289157867, 0.02192985638976097, 0.008188161998987198, 0.05189564451575279, 0.002721450524404645, 0.013875183649361134, -0.009183546528220177, -0.014000757597386837, -0.027881374582648277, 0.031991444528102875, 0.0204451996833086, 0.00027834539650939405, 0.04411297291517258, 0.05809924378991127, -0.028590993955731392, -0.0144181028008461, 0.017060136422514915, 0.013152461498975754, 0.023736869916319847, -0.021134130656719208, -0.03824830800294876, 0.02142428793013096, 0.01034118328243494, 0.01578795164823532, -0.056747060269117355, -0.010633537545800209, 0.009478694759309292, -0.013251801952719688, 0.02138501964509487, 0.02002953737974167, 0.0035086404532194138, 0.007293506991118193, 0.01949586160480976, 0.0069246115162968636, 0.07852764427661896, -0.08300755172967911, -0.06289122998714447, -0.02226756140589714, -0.026357758790254593, -0.0064981067553162575, -0.02476157434284687, 0.034770626574754715, 0.01945188082754612, -0.0076479315757751465, -0.00763095123693347, -0.008415604941546917, 0.035690903663635254, -0.021000178530812263, -0.006373153999447823, -0.044576603919267654, 0.022232208400964737, 0.005419091787189245, -0.023241199553012848, 0.04748499020934105, -0.010606009513139725, 0.018635539337992668, 0.017322493717074394, 0.023801859468221664, 0.01687556318938732, -0.020088069140911102, 0.02207493782043457, -0.009176736697554588, 0.005281087476760149, 0.03055964782834053, -0.022471578791737556, -0.029410937801003456, -0.04513835906982422, 0.028405936434864998, 0.019860753789544106, -0.03964956849813461, 0.005869526881724596, -0.00025147837004624307, 0.060953330248594284, -0.004367792513221502, 0.032946109771728516, 0.08051943778991699, -0.04315546900033951, 0.05125352367758751, 0.03585956618189812, 0.05747674033045769, -0.019138040021061897, 0.00642327219247818, -0.020855208858847618, 0.034068942070007324, -0.04150987043976784, 0.005089796148240566, -0.018264733254909515, -0.0010412383126094937, 0.027568936347961426, 0.023128235712647438, -0.040791209787130356, -0.009934667497873306, 0.0043427846394479275, -0.0018734539626166224, -0.02031778171658516, -0.00975483562797308, -0.00847362820059061, 0.007652489934116602, 0.05199534446001053, -0.020095178857445717, 0.002851362805813551, 0.01092914491891861, 0.0034397104755043983, 0.013899555429816246, 0.027336517348885536, -0.06188333034515381, 0.02911822870373726, 0.041096944361925125, 0.0055290586315095425, -0.04736270383000374, 0.015213428996503353, -0.005010638851672411, -0.018225839361548424, 0.05770622566342354, 0.039225734770298004, -0.032248448580503464, 0.01570846326649189, -0.0685228705406189, 0.009723330847918987, 0.020514754578471184, 0.0315571203827858, 0.018850509077310562, 0.007203956600278616, 0.017984796315431595, 0.0165517907589674, -0.006628068163990974, -0.015790551900863647, -0.014610568061470985, -0.019848905503749847, -0.01028956938534975, -0.052043549716472626, 0.004630444571375847, 0.021961113438010216, 0.021376390010118484, -0.019056208431720734, 0.02489856444299221, -0.028427595272660255, -0.0012330592144280672, 0.01250425074249506, -0.017299357801675797, 0.02846313640475273, -0.04714832082390785, 0.02373393438756466, 0.015899723395705223, 0.0279169213026762, -0.019203200936317444, -0.016134334728121758, -0.027146250009536743, 0.03711564466357231, 0.06232890114188194, 0.04778715595602989, -0.018000220879912376, -0.013387280516326427, -0.02640608884394169, -0.007650312501937151, -0.009530916810035706, 0.03917708620429039, 0.004969225265085697, -0.0010369936935603619, 0.055491119623184204, 0.0033998743165284395, 0.0310687143355608, 0.025169942528009415, -0.019383832812309265, -0.01850455440580845, -0.014904490672051907, -0.009383907541632652, 0.0495285764336586, -0.013155181892216206, -0.004834903869777918, 0.03175435960292816, -0.019029248505830765, 0.01275857724249363, -0.006885523907840252, -0.032471492886543274, -0.042476918548345566, -0.010423533618450165, 0.02150985598564148, -0.06551135331392288, 0.036115821450948715, 0.020023232325911522, -0.030655963346362114, -0.015134467743337154, -0.03400348499417305, -0.0029464494436979294, 0.01954701356589794, -0.008922837674617767, -0.04679498448967934, 0.0005045198486186564, 0.03053058125078678, -0.014454098418354988, 0.0011385766556486487, 0.0467522032558918, 0.05042558163404465, 0.025114623829722404, -0.007827558554708958, 0.014433079399168491, -0.07089024782180786, 0.023700714111328125, 0.027934592217206955, -0.006508356891572475, -0.03716281056404114, -0.0313093401491642, 0.016757342964410782, 0.011127944104373455, -0.024315278977155685, -0.016721660271286964, -0.001272411784157157, -0.033780843019485474, 0.005592577159404755, 0.051276639103889465, -0.026265721768140793, -0.0006421110010705888, -0.03223917633295059, 0.014337653294205666, -0.011009790003299713, -0.004139532335102558, 0.014961048029363155, -0.016341937705874443, 0.04287365823984146, 0.01579192839562893, 0.04876686632633209, 0.07453946769237518, -0.010070585645735264, 0.028502343222498894, 0.051959503442049026, -0.030678698793053627, 0.03154655545949936, -0.01688554510474205, 0.021901778876781464, -0.0014321887865662575, 0.022005300968885422, 0.04683651775121689, -0.011160321533679962, 0.0018202788196504116, 0.052656691521406174, 0.01565324142575264, -0.02174542099237442, -0.0057748896069824696, 0.03496338427066803, -0.00881411787122488, -0.0029861347284168005, -0.02542915754020214, 0.041770823299884796, -0.04385426267981529, 0.03154529631137848, 0.01333644613623619, -0.0373452790081501, 0.021047130227088928, 0.023462355136871338, 0.00002355519973207265, 0.002091128146275878, 0.025297272950410843, 0.03239846229553223, 0.05169175565242767, -0.012765519320964813, 0.006339136511087418, -0.016494276002049446, -0.0013108084676787257, 0.022818319499492645, -0.03556191921234131, 0.01786140166223049, 0.02301984839141369, 0.010831802152097225, -0.013950107619166374, 0.016928985714912415, -0.008957982063293457, 0.005462443456053734, 0.02709200233221054, 0.002405054634436965, -0.031545426696538925, 0.013947193510830402, 0.04596269130706787, -0.0033667851239442825, 0.012688294053077698, 0.0047352369874715805, -0.005614704918116331, -0.06357041001319885, 0.0346066839993, -0.01408811192959547, 0.015728207305073738, 0.05915839970111847, -0.01625438965857029, -0.019609391689300537, 0.0034486486110836267, 0.03676006942987442, -0.03020559437572956, 0.004206468351185322, -0.014967161230742931, 0.05336671322584152, -0.014394490048289299, 0.022162601351737976, 0.014476491138339043, 0.00022086114040575922, 0.045203302055597305, 0.01542199682444334, -0.03766661137342453, 0.010921061038970947, 0.023963479325175285, -0.02423805184662342, 0.039269786328077316, 0.006992916110903025, -0.024714043363928795, 0.005318745505064726, 0.06608607620000839, -0.02941230870783329, 0.010523837059736252, -0.007410329766571522, 0.042554523795843124, -0.01894151046872139, 0.009281848557293415, 0.07181079685688019, 0.04367957264184952, 0.03401513397693634, 0.06627199798822403, 0.04812687262892723, 0.015495911240577698, 0.047916218638420105, 0.016965005546808243, 0.004476707894355059, 0.0031977067701518536, 0.04519619792699814, -0.028905950486660004, -0.0207456536591053, 0.010190658271312714, -0.03121870383620262, 0.02434009499847889, 0.0001820052129914984, 0.02056013233959675, -0.03925522416830063, -0.005005939397960901, 0.018796611577272415, -0.0010012119309976697, 0.017148634418845177, -0.011626227758824825, 0.04141421616077423, 0.045042842626571655, 0.042202021926641464, 0.01612277328968048, 0.00471458351239562, 0.015387069433927536, 0.01622038148343563, 0.055950362235307693, 0.028354689478874207, -0.01726893149316311, -0.024920079857110977, 0.025184834375977516, 0.01140032522380352, 0.0121503546833992, 0.04160303622484207, -0.038909535855054855, -0.013200313784182072, -0.01648039184510708, -0.06066974624991417, 0.034739188849925995, -0.011119452305138111, -0.029391059651970863, 0.018611188977956772, -0.013544292189180851, -0.0049736457876861095, 0.031763553619384766, -0.007668169215321541, -0.01744127832353115, -0.017269950360059738, -0.03170711547136307, -0.01448871474713087, 0.012591660022735596, -0.028173141181468964, 0.007690735626965761, 0.009416839107871056, -0.006140572484582663, 0.005220737308263779, 0.032084446400403976, -0.0003877604613080621, -0.013578617013990879, -0.01404303777962923, -0.005819803103804588, -0.0009453301317989826, 0.04148753359913826, 0.028314810246229172, -0.042255766689777374, 0.04312838986515999, -0.0039481790736317635, -0.012986079789698124, 0.052501145750284195, -0.0027526174671947956, -0.02156745083630085, -0.04085583612322807, 0.0003274520568083972, 0.003584339516237378, -0.007572100032120943, 0.019600050523877144, -0.03496384620666504, 0.05866101756691933, -0.007141269743442535, 0.045495595782995224, 0.03788513317704201, 0.02932693064212799, 0.010441097430884838, -0.004749117884784937, -0.02076852321624756, -0.032048873603343964, -0.019108306616544724, 0.004672356881201267, 0.008112125098705292, -0.007851489819586277, -0.0030241585336625576, -0.0058457450941205025, -0.03845813125371933, -0.031404465436935425, 0.010981373488903046, 0.04050467535853386, 0.01300878543406725, -0.025416871532797813, -0.031726591289043427, 0.003975564148277044, -0.0009200431522913277, -0.012220599688589573, 0.022771434858441353, 0.013975902460515499, 0.06241631507873535, -0.03626979887485504, -0.006711075082421303, -0.0353364460170269, -0.04433250427246094, -0.03129809722304344, -0.005145692732185125, -0.01976845972239971, 0.01086310762912035, -0.01345762424170971, 0.029367217794060707, -0.023321891203522682, 0.045891258865594864, -0.007876819930970669, 0.014139221981167793, -0.036829449236392975, 0.0007607393199577928, 0.04906107112765312, -0.004485567566007376, 0.0363909937441349, 0.015734825283288956, -0.027486741542816162, -0.0547369085252285, -0.01330532692372799, 0.03871593996882439, 0.07201196998357773, -0.03017846681177616, 0.028492821380496025, -0.01075852569192648, 0.011469361372292042, 0.0037396703846752644, -0.02949526533484459, -0.005157045088708401, 0.011014518328011036, -0.03233015164732933, 0.0024277428165078163, -0.000830251257866621, 0.022368168458342552, 0.012821739539504051, 0.03985163941979408, -0.027019836008548737, -0.02521405927836895, 0.040510375052690506, 0.029212040826678276, -0.0375685915350914, -0.033300720155239105, -0.015457574278116226, 0.0007496507605537772, 0.04718990996479988, -0.002745525212958455, 0.006975939031690359, 0.03074575401842594, 0.002959535690024495, 0.0011021385435014963, 0.012812444940209389, -0.018289625644683838, -0.026711411774158478, 0.03727470338344574, 0.019594231620430946, -0.022848021239042282, -0.014837129041552544, 0.03796961531043053, 0.03177720308303833, 0.018032537773251534, -0.030243944376707077, 0.010575426742434502, 0.013200689107179642, -0.005842181388288736, 0.032865971326828, 0.0007340197334997356, 0.023815583437681198, 0.007703437004238367, 0.04108549654483795, -0.01812991499900818, -0.008254367858171463 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
Axial Positional Encodings in Reformer Transformers need positional encodings to account for the order of words in the input because self-attention layers have no notion of order. Positional encodings are usually defined by a simple look-up matrix \( \mathbf{E} = \left[\mathbf{e}1, \ldots, \mathbf{e}{n_\text{max}}\right] \) The positional encoding vector \( \mathbf{e}{i} \) is then simply added to the ith input vector \( \mathbf{x}{i} + \mathbf{e}{i} \) so that the model can distinguish if an input vector (a.k.a token) is at position \( i \) or \( j \). For every input position, the model needs to be able to look up the corresponding positional encoding vector so that the dimension of \( \mathbf{E} \) is defined by the maximum length of input vectors the model can process config.max_position_embeddings, i.e. \( n\text{max} \), and the config.hidden_size, i.e. \( d_{h} \) of the input vectors. Assuming \( d_{h}=4 \) and \( n_\text{max}=49 \), such a positional encoding matrix can be visualized as follows: Here, we showcase only the positional encodings \( \mathbf{e}{1} \), \( \mathbf{e}{2} \), and \( \mathbf{e}{49} \) each of dimension, a.k.a height 4. Let's imagine, we want to train a Reformer model on sequences of a length of up to 0.5M tokens and an input vector config.hidden_size of 1024 (see notebook here). The corresponding positional embeddings have a size of \( 0.5M \times 1024 \sim 512M \) parameters, which corresponds to a size of 2GB. Such positional encodings would use an unnecessarily large amount of memory both when loading the model in memory and when saving the model on a hard drive. The Reformer authors managed to drastically shrink the positional encodings in size by cutting the config.hidden_size dimension in two and smartly factorizing the \( n\text{max} \) dimension. In Transformer, the user can decide into which shape \( n_\text{max} \) can be factorized into by setting config.axial_pos_shape to an appropriate list of two values \( n_\text{max}^1 \) and \( n_\text{max}^2 \) so that \( n_\text{max}^1 \times n_\text{max}^2 = n_\text{max} \). By setting config.axial_pos_embds_dim to an appropriate list of two values \( d_{h}^{1} \) and \( d_{h}^2 \) so that \( d_{h}^1 + d_{h}^2 = d_{h} \), the user can decide how the hidden size dimension should be cut. Now, let's visualize and explain more intuitively. One can think of factorizing \( n_{\text{max}} \) as folding the dimension into a third axis, which is shown in the following for the factorization config.axial_pos_shape = [7, 7]: Each of the three standing rectangular prisms corresponds to one of the encoding vectors \( \mathbf{e}{1}, \mathbf{e}{2}, \mathbf{e}{49} \), but we can see that the 49 encoding vectors are divided into 7 rows of 7 vectors each. Now the idea is to use only one row of 7 encoding vectors and expand those vectors to the other 6 rows, essentially reusing their values. Because it is discouraged to have the same values for different encoding vectors, each vector of dimension (a.k.a height) config.hidden_size=4 is cut into the lower encoding vector \( \mathbf{e}\text{down} \) of size \( 1 \) and \( \mathbf{e}\text{up} \) of size \( 3 \), so that the lower part can be expanded along the row dimension and the upper part can be expanded along the column dimension. Let's visualize for more clarity. We can see that we have cut the embedding vectors into \( \mathbf{e}\text{down} \) (in blue) and \( \mathbf{e}\text{up} \) (in yellow). Now for the "sub"-vectors \( \mathbf{E}\text{down} = \left[\mathbf{e}{\text{down},1}, \ldots, \mathbf{e}{\text{down},49}\right] \) only the first row, a.k.a. the width in the graphic, of \( 7 \) is kept and expanded along the column dimension, a.k.a. the depth of the graphic. Inversely, for the "sub"-vectors \( \mathbf{E}\text{up} = \left[\mathbf{e}{\text{up},1}, \ldots, \mathbf{e}{\text{up},49}\right] \) only the first column of \( 7 \) is kept and expanded along the row dimension. The resulting embedding vectors \( \mathbf{e'}{i} \) then correspond to $$\mathbf{e'}{i} = \left[ \left[\mathbf{e}{\text{down, } i \% n_\text{max}^1}\right]^T, \left[\mathbf{e}{\text{up, } \left \lfloor{\frac{i}{{n}^2{\text{max}}}}\right \rfloor} \right]^T \right]^T $$ whereas \( n_\text{max}^1 = 7 \) and \( n_\text{max}^2 = 7 \) in our example. These new encodings \( \mathbf{E'} = \left[\mathbf{e'}{1}, \ldots, \mathbf{e'}{n_\text{max}}\right] \) are called Axial Position Encodings. In the following, these axial position encodings are illustrated in more detail for our example. Now it should be more understandable how the final positional encoding vectors \( \mathbf{E'} \) are calculated only from \( \mathbf{E}{\text{down}} \) of dimension \( d{h}^1 \times n_{\text{max}^1} \) and \( \mathbf{E}{\text{up}} \) of dimension \( d{h}^2 \times n_{\text{max}}^2 \). The crucial aspect to see here is that Axial Positional Encodings make sure that none of the vectors \( \left[\mathbf{e'}1, \ldots, \mathbf{e'}{n_{\text{max}}}\right] \) are equal to each other by design and that the overall size of the encoding matrix is reduced from \( n_{\text{max}} \times d_{h} \) to \( n_{\text{max}}^1 \times d_{h}^1 + n_\text{max}^2 \times d_{h}^2 \). By allowing each axial positional encoding vector to be different by design the model is given much more flexibility to learn efficient positional representations if axial positional encodings are learned by the model. To demonstrate the drastic reduction in size, let's assume we would have set config.axial_pos_shape = [1024, 512] and config.axial_pos_embds_dim = [512, 512] for a Reformer model that can process inputs up to a length of 0.5M tokens. The resulting axial positional encoding matrix would have had a size of only \( 1024 \times 512 + 512 \times 512 \sim 800K \) parameters which corresponds to roughly 3MB. This is a drastic reduction from the 2GB a standard positional encoding matrix would require in this case. For a more condensed and math-heavy explanation please refer to the 🤗Transformers docs here.
[ 0.007814004085958004, 0.012987624853849411, 0.044391971081495285, -0.03358437120914459, -0.01833481341600418, 0.05746005102992058, 0.023154892027378082, -0.03284171596169472, -0.03165939077734947, -0.00816173292696476, -0.10370396822690964, -0.006220769137144089, -0.004598658531904221, -0.020360000431537628, -0.021782701835036278, -0.00029601887217722833, 0.06749807298183441, -0.005795860663056374, -0.06284927576780319, -0.0485067218542099, 0.0158638134598732, -0.056351616978645325, 0.05953412503004074, -0.0029804715886712074, -0.03626946732401848, -0.049582164734601974, -0.00764496112242341, -0.030072472989559174, -0.02670109085738659, 0.01873956434428692, -0.13295193016529083, -0.03698425740003586, 0.030193867161870003, -0.03866621479392052, 0.022541115060448647, -0.0158513393253088, -0.12846903502941132, 0.06357472389936447, 0.0764710009098053, -0.07998871803283691, -0.032771337777376175, 0.020038951188325882, -0.05070565640926361, 0.024405941367149353, -0.02617736905813217, -0.023004258051514626, -0.12812402844429016, 0.09038042277097702, -0.060836710035800934, -0.025133496150374413, -0.04314790293574333, -0.022492386400699615, -0.043583501130342484, 0.09177315980195999, -0.02125391736626625, -0.020233523100614548, -0.0055970135144889355, -0.04613836482167244, 0.05594266578555107, -0.01127742137759924, 0.060169413685798645, 0.06798266619443893, 0.021515170112252235, 0.032214995473623276, 0.01342057902365923, -0.005342417396605015, -0.0507206916809082, 0.0191239882260561, -0.04126833379268646, -0.0632488951086998, -0.011366618797183037, 0.03791294991970062, 0.012202169746160507, -0.0357528030872345, 0.024732554331421852, -0.05139686167240143, -0.04462539777159691, 0.03928665816783905, 0.0606379434466362, 0.013313495554029942, -0.05285513028502464, 0.05322205647826195, 0.0375274233520031, 0.09358040988445282, -0.018126042559742928, 0.07427212595939636, 0.05715233460068703, -0.03033681958913803, 0.013569965027272701, 0.07377650588750839, -0.03259774670004845, -0.12591859698295593, -0.02151671051979065, -0.011743973940610886, 0.022199193015694618, -0.03476663678884506, 0.016742154955863953, -0.0026429148856550455, -0.008766461163759232, 0.03678739815950394, 0.002595209050923586, -0.000993478111922741, 0.0630008727312088, -0.007243747357279062, 0.002598788822069764, 0.030265729874372482, 0.01472790539264679, -0.08166135102510452, -0.014492948539555073, 0.007229814305901527, -0.0017311045667156577, 0.004718154668807983, 0.03794483095407486, 0.02862459421157837, -0.056824903935194016, 0.027680499479174614, 0.0289511326700449, -0.03696957603096962, -0.02360309660434723, 0.06519901007413864, -0.02609684132039547, 0.08079303056001663, 0.07960657775402069, -0.015883801504969597, 0.012054848484694958, 0.04110836237668991, -0.06462142616510391, -0.0043767886236310005, -0.0467776395380497, -0.02952059730887413, -0.004943673964589834, 0.07659906893968582, 0.0675358697772026, -0.019181378185749054, 0.02019563503563404, -0.06232104450464249, 0.033294372260570526, -0.027127088978886604, -0.005493190139532089, -0.03881380334496498, -0.057666584849357605, -0.01752334088087082, 0.03013148345053196, -0.07286712527275085, 0.02848733402788639, -0.03252733126282692, -0.05865933746099472, 0.061353299766778946, -0.010437463410198689, 0.008752458728849888, 0.005379216279834509, 0.011319717392325401, 0.021040920168161392, -0.05369974672794342, 0.015587620437145233, -0.004929013550281525, -0.01829877682030201, 0.005679419729858637, -0.10550592094659805, -0.028588172048330307, -0.07114708423614502, 0.005141711328178644, -0.057069141417741776, 0.05885501950979233, 0.018180057406425476, -0.0886475145816803, 0.0935826450586319, -0.01032315008342266, 0.002333455951884389, -0.0038802167400717735, 0.015025262720882893, 0.021068478003144264, 0.037890199571847916, 0.04308271408081055, -0.042800068855285645, 0.01269751787185669, -0.0033854388166218996, 0.11778073012828827, -0.004101765342056751, -0.07141751050949097, -0.033936865627765656, 0.02610332891345024, -0.016236651688814163, 0.0109855430200696, 0.06535832583904266, -0.034357957541942596, 0.05168654024600983, -0.05619468167424202, -0.010945767164230347, 0.04022127762436867, -0.08489763736724854, -0.01330496184527874, 0.01577119342982769, -0.018598629161715508, 0.017374908551573753, -0.022183718159794807, -0.060398925095796585, 0.07522539049386978, 0.023886781185865402, 0.018286382779479027, 0.04711543396115303, 0.03586244583129883, 0.0329984687268734, 0.03918756544589996, 0.0341455414891243, -0.03212190419435501, -0.06142304092645645, -0.05814085155725479, 0.06116790696978569, 0.03503097593784332, -0.02463369630277157, -0.09266791492700577, 0.005273851100355387, -0.06333082169294357, -0.030685050413012505, -0.06802839040756226, 0.009792820550501347, 0.03434774652123451, -0.07735062390565872, -0.012639897875487804, 0.10864203423261642, -0.007089268881827593, -0.05352623760700226, -0.011834093369543552, -0.02134981006383896, 0.0455024316906929, 0.009980284608900547, 0.008670320734381676, 0.03126480057835579, -0.09253697097301483, -0.007889569737017155, -0.019351527094841003, 0.06162101402878761, 0.005752601660788059, -0.040109165012836456, -0.06422968953847885, -0.06455456465482712, 0.03494380787014961, 0.0714508667588234, -0.03489888086915016, -0.0005076051456853747, -0.014257152564823627, 0.0012528080260381103, 0.0008298808825202286, -0.0386783704161644, 0.021043388172984123, -0.016118086874485016, 0.0124488715082407, -0.02769416756927967, 0.020743107423186302, -0.06999649852514267, 0.037143588066101074, -0.02608129195868969, -0.09725500643253326, -0.05650554969906807, 0.07736583054065704, 0.005623669363558292, -0.012205211445689201, -0.003056972287595272, 0.016588252037763596, -0.001946020987816155, 0.03928809612989426, -0.032989513128995895, -0.06088430806994438, -0.021596938371658325, 0.02174396999180317, 0.019720174372196198, -0.01090309489518404, -0.0197304580360651, -0.005257451441138983, 0.007867402397096157, 0.01268131285905838, 0.011454077437520027, 0.02005675621330738, 0.03896530345082283, -0.013766178861260414, 0.06742168962955475, -0.015198462642729282, -0.02664949558675289, -0.007683697156608105, -0.010878954082727432, 0.01906433515250683, 0.036263607442379, 0.004341219086199999, 0.004237781278789043, 0.03043881431221962, 0.04260780289769173, -0.0002447136212140322, -0.0011549578048288822, -0.0012649650452658534, 0.009695908054709435, 0.057114046066999435, 0.009337455034255981, -0.03445345535874367, 0.013636184856295586, -0.00877328310161829, -0.008081145584583282, -0.00399354100227356, 0.014819014817476273, 0.02240132726728916, 0.013127799145877361, 0.028076959773898125, 0.03545690327882767, 0.023314470425248146, -0.008840507827699184, 0.0036450407933443785, -0.022938260808587074, 0.10419698804616928, -0.08382627367973328, -0.05527337267994881, 0.02648947946727276, 0.004053807817399502, 0.008755521848797798, -0.03340453281998634, 0.013556438498198986, 0.01781628280878067, -0.0033102401066571474, 0.0019424103666096926, 0.02903170883655548, -0.007791532203555107, 0.017261987552046776, 0.028246290981769562, 0.02841482311487198, 0.03065815567970276, 0.06430268287658691, -0.02253142185509205, 0.01951858215034008, -0.021681003272533417, 0.024790072813630104, 0.01803882233798504, 0.019926320761442184, 0.011216066777706146, -0.008953176438808441, 0.016744835302233696, 0.02356497384607792, 0.017991945147514343, 0.02436503954231739, -0.04837736859917641, -0.060763537883758545, -0.006157462019473314, -0.02585332654416561, 0.0008370305295102298, -0.05258174240589142, -0.002801158931106329, 0.0014499493408948183, 0.03154382109642029, 0.0007005009101703763, 0.03773961216211319, 0.03522667661309242, -0.009579616598784924, 0.016507532447576523, 0.017193451523780823, 0.044505033642053604, -0.01742219366133213, -0.024823438376188278, -0.0009769428288564086, 0.006878864951431751, -0.0292391125112772, 0.001294098561629653, -0.015442104078829288, 0.002629251452162862, -0.016150720417499542, 0.001140594482421875, -0.015205567702651024, -0.02813267521560192, 0.018285542726516724, -0.021713268011808395, -0.022241834551095963, -0.04495752230286598, -0.024257343262434006, -0.013329708948731422, 0.007409552577883005, -0.0039915419183671474, 0.013900461606681347, -0.017608249559998512, 0.04373689740896225, 0.014136250130832195, 0.043076690286397934, -0.03697378933429718, -0.0015179923502728343, -0.00447330204769969, -0.0007880991324782372, -0.026930421590805054, 0.017853666096925735, 0.010648823343217373, -0.01685199700295925, 0.04076596349477768, 0.022403251379728317, -0.02622978575527668, 0.018126334995031357, -0.07514072954654694, 0.06091044470667839, 0.0000954924980760552, 0.013970618136227131, 0.021628841757774353, -0.009604452177882195, 0.06556626409292221, -0.009383698925375938, -0.04090866073966026, -0.010221586562693119, 0.016565414145588875, -0.0002864669368136674, -0.007239036727696657, -0.0009787306189537048, 0.016080062836408615, -0.004630571696907282, 0.03854260593652725, 0.03208264708518982, 0.020355461165308952, -0.0628846138715744, 0.04264336824417114, -0.0008216453134082258, -0.01470491848886013, -0.008759897202253342, -0.03581041097640991, -0.00244782748632133, 0.04255881905555725, 0.032927852123975754, -0.007965593598783016, -0.026987550780177116, 0.008850513957440853, 0.03338300436735153, 0.03971555083990097, 0.01763327606022358, -0.03399903327226639, -0.03885132446885109, -0.07684919983148575, -0.02601544000208378, 0.01146253477782011, 0.015448982827365398, -0.02486274763941765, -0.007962888106703758, 0.0056584859266877174, -0.012279391288757324, -0.015870744362473488, 0.019810030236840248, -0.031327083706855774, -0.041986968368291855, -0.05051631107926369, 0.01175436656922102, 0.013710126280784607, -0.01910450868308544, -0.0049603963270783424, 0.06597631424665451, -0.01645807921886444, 0.019947165623307228, 0.0065121715888381, -0.04307108744978905, -0.02449883334338665, 0.010554186068475246, 0.018846208229660988, -0.052165575325489044, 0.04290257394313812, -0.014587736688554287, -0.02606092393398285, 0.017417017370462418, -0.01837955042719841, 0.01619141921401024, 0.05908660590648651, 0.04528915509581566, -0.07605843245983124, 0.021314993500709534, 0.032135896384716034, 0.018715262413024902, 0.0025010304525494576, -0.0055035678669810295, -0.02545858547091484, 0.017582576721906662, 0.0005242138868197799, 0.010168995708227158, -0.052682604640722275, -0.01535777561366558, 0.024902261793613434, 0.018392378464341164, -0.005321721080690622, -0.061809930950403214, 0.034378569573163986, -0.038013163954019547, -0.008944729343056679, -0.00736040435731411, 0.007953636348247528, -0.01639029011130333, 0.02330698072910309, 0.01717071235179901, -0.019804956391453743, 0.007208248600363731, -0.0473816879093647, 0.008765497244894505, -0.01659291796386242, -0.023764269426465034, 0.03129734843969345, -0.01320795901119709, -0.0029793251305818558, 0.030834315344691277, 0.0607796236872673, 0.051434993743896484, -0.005006436724215746, 0.016075609251856804, 0.030740221962332726, -0.011736392043530941, 0.04632861539721489, -0.006315409671515226, 0.016003889963030815, 0.026766518130898476, 0.03623256832361221, -0.003997075837105513, 0.004018433392047882, 0.006357953883707523, 0.02083957940340042, 0.06535384804010391, -0.04619962349534035, -0.04145767167210579, 0.008398754522204399, -0.0032585717272013426, 0.002060000319033861, -0.01951267197728157, 0.006187747232615948, -0.0001664734008954838, 0.027639493346214294, 0.015663662925362587, -0.054238129407167435, 0.012071166187524796, 0.036483537405729294, -0.011039485223591328, -0.007178294472396374, -0.0015710854204371572, 0.009227423928678036, 0.06866244226694107, -0.009660531766712666, -0.00103571149520576, -0.04254765063524246, -0.00019540540233720094, 0.04795270785689354, -0.03145341947674751, -0.003834083443507552, 0.030989257618784904, 0.026505129411816597, 0.03247258439660072, 0.028786836192011833, 0.010587732307612896, 0.004124842118471861, 0.007231713738292456, 0.019027646631002426, -0.04645005613565445, -0.005926618352532387, 0.0638691633939743, 0.03002629056572914, -0.02778525836765766, 0.03813621774315834, 0.007705485913902521, -0.058369558304548264, 0.05203895643353462, 0.02589493803679943, 0.03068653866648674, 0.06428201496601105, -0.009070899337530136, -0.02121119759976864, 0.021384133026003838, 0.05084317922592163, -0.05234603211283684, -0.0003150180564261973, -0.03092644177377224, 0.027072498574852943, 0.04224042594432831, 0.04512982442975044, 0.01835786923766136, 0.027139609679579735, 0.06904876232147217, 0.002237475709989667, -0.06415685266256332, -0.0010105784749612212, -0.0013410806423053145, -0.05469008907675743, 0.016253430396318436, 0.014712498523294926, -0.016850546002388, 0.004468843806535006, 0.06601691991090775, 0.013486457988619804, 0.028143303468823433, -0.023257987573742867, 0.05323110893368721, -0.002957236720249057, 0.011527134105563164, 0.04952729120850563, 0.0362173356115818, 0.004571199417114258, 0.024059977382421494, 0.0025117702316492796, -0.02191580832004547, 0.021044345572590828, 0.012112568132579327, 0.023850077763199806, -0.02161911129951477, 0.01424725167453289, -0.005095120053738356, 0.007834409363567829, 0.005266769789159298, 0.001561767072416842, 0.01846471056342125, 0.014621063135564327, -0.005914837587624788, -0.05734380707144737, 0.03775092586874962, -0.006571890786290169, 0.011679074726998806, 0.033747460693120956, -0.05005696788430214, 0.04432656243443489, 0.011854532174766064, 0.033865172415971756, -0.05511096119880676, 0.027944764122366905, 0.05988102778792381, -0.00045537977712228894, 0.032381538301706314, -0.007696496322751045, 0.0028263931162655354, -0.00926768034696579, -0.005121036898344755, -0.03023054264485836, 0.029208524152636528, 0.07156825810670853, 0.010872452519834042, 0.03609972074627876, -0.034383997321128845, -0.04613244906067848, 0.02650209330022335, 0.0018477517878636718, -0.006932172458618879, 0.028692107647657394, -0.005787102971225977, 0.006488626357167959, -0.004517342895269394, -0.008572028018534184, 0.02414083667099476, -0.05550219491124153, 0.014817968010902405, -0.0004528145946096629, 0.041577473282814026, -0.007890780456364155, 0.023644309490919113, -0.019282497465610504, -0.045094531029462814, -0.018618127331137657, 0.01606241799890995, 0.00410687318071723, -0.013222337700426579, -0.04434952512383461, 0.00548806507140398, 0.005831599235534668, 0.04300844296813011, -0.028159474954009056, -0.015242934226989746, 0.01821856014430523, 0.06904833018779755, -0.01984425261616707, 0.0394597090780735, 0.008122391067445278, -0.010678906925022602, -0.03750000521540642, -0.04092925414443016, -0.00960913859307766, 0.011493304744362831, 0.02050400897860527, -0.02474984899163246, 0.05395550653338432, 0.015468765050172806, 0.042970847338438034, 0.02942265197634697, 0.0019014450954273343, -0.031695690006017685, -0.0587514191865921, 0.023549219593405724, -0.02388611063361168, 0.01181249599903822, -0.001327958656474948, 0.014211044646799564, -0.016101999208331108, -0.05457387492060661, -0.022413630038499832, -0.041198648512363434, -0.025304604321718216, 0.016219595447182655, 0.03455575183033943, -0.012960472144186497, -0.005052546504884958, -0.07487811893224716, 0.029101070016622543, 0.022938137874007225, -0.00505502475425601, 0.04738832265138626, 0.04512573406100273, 0.03828646242618561, 0.02039163187146187, 0.021122582256793976, -0.02495468407869339, 0.00029555923538282514, -0.034590475261211395, -0.05024795979261398, -0.03649892285466194, 0.011527694761753082, 0.018500640988349915, -0.00637736264616251, -0.0017235558480024338, 0.048844803124666214, -0.033710408955812454, 0.005274569615721703, -0.0067795393988490105, 0.01733909361064434, 0.042016077786684036, -0.014706684276461601, 0.033027283847332, -0.010027026757597923, 0.018703700974583626, -0.021942252293229103, 0.006805356126278639, 0.014748774468898773, 0.07757260650396347, -0.026497796177864075, 0.003503895830363035, -0.02878776378929615, 0.04302618280053139, -0.01229785569012165, -0.048195451498031616, 0.009664664044976234, 0.024013018235564232, -0.008981785736978054, 0.00589680066332221, -0.00038387440145015717, 0.00872555747628212, 0.04100712016224861, 0.011296569369733334, -0.008204235695302486, 0.03815450891852379, -0.0035262187011539936, 0.00944799929857254, -0.051082219928503036, -0.015623015351593494, 0.015002014115452766, 0.025794491171836853, 0.027896882966160774, -0.02322615683078766, 0.049780260771512985, 0.009193554520606995, -0.009595684707164764, 0.0016570325242355466, -0.007095395587384701, 0.0021324215922504663, -0.03921544924378395, -0.006469454616308212, 0.05282333120703697, -0.03516041859984398, -0.03910320624709129, -0.02706659585237503, 0.04559089615941048, 0.021507054567337036, -0.002569889649748802, -0.011707542464137077, -0.00038399797631427646, -0.014515308663249016, -0.006811200641095638, 0.04539008066058159, 0.006991510279476643, -0.017762457951903343, 0.031108537688851357, -0.004341340623795986, -0.007788560818880796 ]
The Reformer - Pushing the limits of language modeling
patrickvonplaten
July 3, 2020
reformer
research, nlp
https://huggingface.co/blog/reformer
1. Reformer Self-Attention Layer Reformer uses two kinds of special self-attention layers: local self-attention layers and Locality Sensitive Hashing (LSH) self-attention layers. To better introduce these new self-attention layers, we will briefly recap conventional self-attention as introduced in Vaswani et al. 2017. This blog post uses the same notation and coloring as the popular blog post The illustrated transformer, so the reader is strongly advised to read this blog first. Important: While Reformer was originally introduced for causal self-attention, it can very well be used for bi-directional self-attention as well. In this post, Reformer's self-attention is presented for bidirectional self-attention.
[ 0.04519634693861008, -0.03754670172929764, 0.006290803197771311, -0.05670412257313728, 0.005678762681782246, 0.05700051411986351, 0.022649919614195824, -0.008458029478788376, -0.014112324453890324, -0.037397004663944244, -0.07775331288576126, 0.07723457366228104, -0.019761018455028534, -0.009281736798584461, -0.04062061756849289, 0.029125286266207695, 0.04701558127999306, -0.05183758959174156, -0.0778380036354065, 0.013453148305416107, 0.054126862436532974, -0.011257023550570011, 0.06451351940631866, -0.054330140352249146, -0.01029024738818407, -0.06298886984586716, 0.004062717780470848, -0.0007332661771215498, -0.06046592444181442, -0.0021474820096045732, -0.09302955120801926, -0.03728823363780975, 0.03149215504527092, -0.01565699279308319, 0.013408859260380268, -0.03189157322049141, -0.09680411219596863, -0.045241378247737885, -0.011488232761621475, -0.1304357796907425, -0.05019792541861534, -0.02076931670308113, -0.060415055602788925, 0.03276439756155014, 0.005068487022072077, -0.032308731228113174, -0.16568703949451447, 0.039580028504133224, -0.07596246153116226, 0.019114825874567032, -0.05500222370028496, 0.04847294092178345, 0.022959133610129356, 0.03633362799882889, 0.006999126169830561, 0.02666580118238926, 0.03784407675266266, 0.0857115313410759, 0.07172469794750214, -0.004052328877151012, 0.08827663958072662, -0.01598222926259041, -0.0468110553920269, 0.03815952688455582, 0.061918627470731735, -0.02608686499297619, -0.016931170597672462, 0.017130548134446144, -0.05634889006614685, -0.06132690608501434, -0.02846343070268631, -0.007754737976938486, -0.019445067271590233, 0.000482036208268255, 0.025828711688518524, 0.007838942110538483, -0.028727801516652107, 0.014587398618459702, -0.025597672909498215, -0.048186514526605606, 0.02287203259766102, 0.007864554412662983, 0.0929497629404068, 0.06967312842607498, -0.013998487032949924, -0.008200317621231079, -0.009849044494330883, -0.028066111728549004, -0.0063976747915148735, 0.05052383616566658, -0.054333239793777466, -0.06909319758415222, 0.0592205710709095, -0.04275967925786972, 0.08609089255332947, -0.0719151720404625, -0.0032376954331994057, -0.0038969016168266535, -0.012379242107272148, -0.05875589698553085, -0.021898847073316574, -0.0046685608103871346, 0.04893588274717331, 0.047534599900245667, 0.008479609154164791, 0.0165509395301342, 0.01984982378780842, -0.04414134845137596, -0.036159757524728775, -0.00016487936954945326, 0.0035084562841802835, 0.04184082895517349, 0.03674112632870674, 0.12974533438682556, 0.017104923725128174, 0.005605772603303194, -0.031102854758501053, -0.04868810996413231, 0.021912820637226105, -0.012002551928162575, -0.04360559582710266, 0.08220787346363068, 0.050978440791368484, 0.08082937449216843, 0.10955566167831421, -0.010085657238960266, -0.05360455811023712, 0.05693146586418152, -0.006740478333085775, -0.01380216982215643, 0.02541401982307434, 0.002412930829450488, 0.03128097951412201, -0.011949682608246803, -0.02606760896742344, -0.11078295111656189, 0.009184085763990879, -0.008720945566892624, -0.020515481010079384, -0.016388334333896637, -0.006002236623317003, -0.03602447360754013, 0.08089575916528702, -0.09241260588169098, 0.026626726612448692, -0.05229923874139786, -0.08666219562292099, 0.06295618414878845, 0.00018671104044187814, 0.017387371510267258, 0.021374212577939034, 0.06220827251672745, 0.012562236748635769, -0.03771527484059334, -0.02604471705853939, 0.040258947759866714, 0.033464252948760986, -0.01632034219801426, -0.10947063565254211, 0.010524538345634937, -0.041557781398296356, -0.003037516726180911, -0.005986006464809179, 0.11065096408128738, 0.034618932753801346, -0.037294674664735794, 0.02057250589132309, -0.03111695870757103, 0.010013251565396786, -0.03775441646575928, 0.045199789106845856, 0.05811179056763649, 0.05860978364944458, 0.014376681298017502, -0.03090580925345421, 0.02334306761622429, 0.015256165526807308, 0.036393217742443085, -0.0460507869720459, 0.04145125299692154, -0.02846948429942131, -0.01961527206003666, 0.012827528640627861, 0.0037298200186342, -0.03839271515607834, 0.022192860022187233, 0.0634395033121109, 0.013469459488987923, -0.008264672011137009, 0.04195152223110199, -0.07543431967496872, 0.013175103813409805, 0.021217450499534607, 0.03147059306502342, 0.021409815177321434, 0.013914319686591625, -0.04990839958190918, 0.033210329711437225, 0.0432242713868618, 0.0828883945941925, 0.030309781432151794, -0.020030613988637924, -0.00625029020011425, 0.027399703860282898, -0.007846467196941376, -0.005156460218131542, -0.007083198055624962, -0.006847314536571503, 0.038454268127679825, -0.09378146380186081, -0.011417427100241184, -0.12172472476959229, 0.0038414078298956156, 0.04676307365298271, -0.023302918300032616, -0.023604152724146843, 0.0204516239464283, 0.032823629677295685, -0.06452500075101852, 0.025194525718688965, 0.0885782539844513, -0.014377301558852196, -0.008285196498036385, 0.07715684920549393, -0.047345809638500214, 0.06177875027060509, 0.012874184176325798, 0.00015382477431558073, 0.07074379175901413, -0.08047063648700714, 0.018762072548270226, -0.07108195126056671, 0.02169390581548214, -0.03154062479734421, -0.02065172977745533, -0.015439748764038086, -0.014267007820308208, -0.013271392323076725, 0.019117651507258415, -0.0643690973520279, -0.026662960648536682, 0.042339690029621124, 0.03296295925974846, 0.01689254492521286, 0.008968490175902843, -0.002593686804175377, -0.02384125255048275, 0.05028776451945305, -0.05177510157227516, 0.00927086640149355, -0.10112369060516357, 0.06627561151981354, 0.027374958619475365, -0.0693991556763649, 0.014741904102265835, -0.04488362744450569, -0.017996441572904587, -0.008545770309865475, 0.015412344597280025, 0.022488757967948914, 0.03701234608888626, 0.028321925550699234, -0.03244541212916374, -0.026764271780848503, -0.03221366927027702, -0.0582222118973732, 0.024588266387581825, 0.047980304807424545, 0.08116704970598221, -0.05286649987101555, 0.004731792490929365, 0.030257398262619972, -0.01605391502380371, -0.004845569841563702, 0.03934112936258316, -0.020534973591566086, 0.04863297939300537, -0.002018981147557497, 0.020323941484093666, -0.047384075820446014, -0.05209988355636597, 0.020061135292053223, 0.05615444481372833, 0.023562157526612282, 0.032026257365942, -0.032216135412454605, 0.0031523779034614563, 0.020673718303442, -0.030803781002759933, -0.018950175493955612, -0.029551712796092033, -0.01099697221070528, -0.02442384697496891, -0.0488046258687973, -0.024666519835591316, 0.025950927287340164, 0.00429331511259079, 0.00045174919068813324, -0.026085253804922104, 0.0010892836144194007, -0.007956557907164097, 0.014405450783669949, 0.03644844889640808, 0.025667279958724976, 0.0028940485790371895, 0.023282097652554512, -0.03783183544874191, 0.06960538029670715, -0.08817293494939804, -0.09084082394838333, -0.01329072192311287, 0.029851382598280907, 0.007937208749353886, -0.04726608842611313, 0.02403736300766468, -0.004604263696819544, -0.006550882942974567, -0.02490217238664627, -0.00230483734048903, -0.03492572531104088, 0.017906904220581055, -0.041600681841373444, -0.025603529065847397, 0.048545826226472855, 0.031872984021902084, -0.013632433488965034, 0.013553067110478878, -0.05682629719376564, 0.01914038322865963, 0.03312190994620323, 0.012528160586953163, 0.013021426275372505, -0.008627231232821941, 0.05490294471383095, 0.004076703451573849, 0.021909158676862717, 0.04889509826898575, -0.0031227865256369114, -0.023942599073052406, 0.04098423942923546, -0.003540630219504237, 0.04472585767507553, -0.017783334478735924, -0.017764735966920853, -0.011214538477361202, 0.05426270142197609, 0.027809089049696922, 0.027421798557043076, 0.059402916580438614, 0.03092283569276333, 0.040027208626270294, 0.04097159206867218, 0.049529723823070526, -0.005162800662219524, 0.01555286068469286, -0.014682762324810028, -0.007314132992178202, -0.045474059879779816, -0.035327523946762085, 0.013706392608582973, 0.010798407718539238, 0.019050661474466324, -0.03170641511678696, -0.017418473958969116, -0.012386263348162174, 0.006132552400231361, -0.030762357637286186, -0.05312870815396309, -0.033605583012104034, 0.015961185097694397, -0.04342331364750862, -0.0056525943800807, -0.03622470051050186, 0.01656815968453884, -0.016187766566872597, 0.03647861257195473, 0.03038940019905567, -0.017973236739635468, -0.0012396221281960607, 0.005895853973925114, 0.011677857488393784, -0.002145993523299694, -0.0401935875415802, 0.022374823689460754, 0.00800973828881979, 0.0058442531153559685, 0.10286922752857208, 0.04026437923312187, -0.014886678196489811, -0.01956205628812313, -0.02082931436598301, 0.0139682088047266, -0.015048868954181671, 0.02834039367735386, 0.010281351394951344, 0.022313259541988373, 0.031900133937597275, -0.010530575178563595, -0.0011687524383887649, 0.016764109954237938, 0.040074486285448074, -0.042868778109550476, 0.009339702315628529, 0.03377177193760872, -0.016235388815402985, -0.023677535355091095, 0.013480550609529018, -0.021551823243498802, 0.006940104532986879, -0.03799539431929588, -0.019300611689686775, 0.05975617095828056, 0.019252005964517593, 0.028575915843248367, -0.04979786276817322, 0.014342838898301125, 0.03158840164542198, -0.00870115589350462, -0.011886942200362682, -0.02222936786711216, -0.019233012571930885, 0.008106985129415989, 0.04895301163196564, 0.008828051388263702, -0.061287470161914825, 0.007859468460083008, -0.019730819389224052, -0.0005269584362395108, -0.00392447505146265, 0.01544579491019249, 0.001110176439397037, -0.05886464938521385, 0.03751220926642418, -0.02583395130932331, 0.03831368684768677, 0.012070524506270885, 0.018689272925257683, 0.014016886241734028, -0.022450661286711693, 0.0036093425005674362, -0.010564993135631084, 0.002045281231403351, 0.0009977929294109344, 0.04195065051317215, -0.033070970326662064, 0.05576474219560623, -0.012717587873339653, -0.005526653490960598, -0.0051305401138961315, 0.002277536317706108, 0.027497470378875732, -0.041716013103723526, 0.039016518741846085, 0.007613660767674446, -0.02478267438709736, 0.013176808133721352, -0.04751260206103325, 0.030901174992322922, 0.04808459058403969, 0.012159856036305428, -0.04821104183793068, -0.0049217622727155685, 0.021917661651968956, 0.010943588800728321, 0.03308303654193878, -0.010853977873921394, 0.041895780712366104, 0.02343389205634594, 0.022461973130702972, 0.019657714292407036, -0.057186055928468704, 0.00947003997862339, 0.027928506955504417, 0.030612025409936905, -0.04372631013393402, -0.05549801141023636, 0.011821932159364223, 0.014514206908643246, -0.055813342332839966, -0.02710721828043461, -0.00431613577529788, -0.03850024566054344, 0.005627896171063185, 0.02780759520828724, -0.04812278598546982, -0.0036599065642803907, 0.002898586681112647, -0.02827799692749977, -0.00046323821879923344, 0.03760460391640663, 0.030381210148334503, -0.0020959307439625263, 0.042911481112241745, 0.013002810068428516, 0.026074735447764397, 0.00967379193753004, 0.017205795273184776, 0.026419036090373993, 0.05009156093001366, -0.0004133635957259685, 0.013115852139890194, -0.004255868494510651, 0.05253421142697334, -0.01643645018339157, 0.04670458287000656, -0.014042823575437069, -0.0038076380733400583, -0.036109041422605515, 0.036184050142765045, 0.018209321424365044, -0.002245022216811776, -0.021973084658384323, 0.02424762398004532, 0.009450151585042477, -0.0031913709826767445, 0.03292005881667137, -0.03082307241857052, -0.05192498117685318, 0.028024353086948395, 0.010894873179495335, 0.002364018000662327, -0.04420825093984604, 0.01035210583359003, -0.03573388606309891, 0.014392790384590626, -0.005821023136377335, -0.01797586679458618, 0.0017195739783346653, 0.030407601967453957, 0.03433197736740112, -0.018947837874293327, 0.014247676357626915, 0.01563452184200287, -0.04825640097260475, -0.0127566484734416, 0.04118882492184639, 0.0040261452086269855, -0.012817463837563992, 0.012801841832697392, 0.011438646353781223, 0.01851223036646843, -0.03001946210861206, -0.013456716202199459, -0.02787104621529579, -0.06936092674732208, 0.029243573546409607, 0.012613537721335888, -0.0002452991029713303, 0.011647852137684822, 0.02165108546614647, -0.03506004065275192, 0.009577920660376549, -0.004565643612295389, 0.027738675475120544, 0.046645406633615494, -0.016709808260202408, -0.009782864712178707, -0.003153925994411111, 0.02145892009139061, -0.04920318350195885, -0.011262304149568081, -0.020809592679142952, 0.029243063181638718, 0.005535418167710304, 0.021077269688248634, 0.03536159172654152, 0.003637823974713683, 0.009099666029214859, -0.04723187908530235, -0.00945888739079237, 0.008211113512516022, -0.027491198852658272, -0.030751250684261322, 0.01748282089829445, 0.01296500489115715, -0.06811973452568054, -0.04109495133161545, 0.04710874706506729, 0.00033652407000772655, -0.0183477271348238, 0.009932411834597588, -0.016168244183063507, -0.04786374792456627, -0.0037894677370786667, 0.0364975780248642, 0.026249371469020844, 0.034135863184928894, 0.026543524116277695, 0.009553429670631886, -0.021561570465564728, 0.08328106999397278, 0.02452346868813038, 0.008657493628561497, -0.04349455609917641, 0.03400096297264099, 0.017157476395368576, 0.020052887499332428, -0.018789734691381454, -0.01130024716258049, 0.012680868618190289, -0.011115794070065022, 0.011447080411016941, -0.002224589930847287, 0.035759005695581436, 0.005698176100850105, -0.010796623304486275, 0.003938409499824047, -0.006483514793217182, -0.009971272200345993, -0.0019361524609848857, 0.06273893266916275, 0.008267094381153584, 0.01759408600628376, 0.020851638168096542, 0.026336660608649254, 0.0399998314678669, 0.0007135409978218377, 0.00872449018061161, 0.00726084690541029, 0.010608128271996975, 0.02497708797454834, 0.001664356212131679, 0.03402618318796158, -0.040195439010858536, -0.002698937663808465, -0.02456533908843994, -0.05471763759851456, 0.013971700333058834, 0.00020891628810204566, -0.01880393549799919, 0.010454672388732433, -0.029392153024673462, 0.020678609609603882, -0.028505556285381317, 0.05173223465681076, -0.01985360123217106, -0.019060535356402397, -0.012205014936625957, 0.014520200900733471, -0.0326940156519413, -0.03493591025471687, 0.01063467562198639, 0.00022683219867758453, 0.03334425017237663, 0.010666612535715103, 0.04080253839492798, -0.0163553636521101, -0.051687952131032944, -0.03552807867527008, 0.00048404844710603356, 0.01608116552233696, 0.06575227528810501, 0.05591236427426338, -0.03294222429394722, 0.015675963833928108, -0.024005861952900887, -0.05816350877285004, 0.049685437232255936, 0.01383938267827034, 0.0006897297571413219, -0.028745785355567932, -0.011642453260719776, -0.00658285291865468, -0.016509028151631355, 0.012687655165791512, -0.005977152846753597, 0.03184713050723076, -0.009583454579114914, 0.05306928604841232, 0.04108886420726776, 0.002670464338734746, 0.00264535890892148, -0.003765836823731661, -0.0028506729286164045, -0.016283271834254265, -0.024376280605793, -0.013808432035148144, 0.015901930630207062, 0.005435450933873653, 0.012112487107515335, 0.007326868828386068, -0.008336753584444523, 0.017037982121109962, 0.030038150027394295, 0.05059896036982536, 0.027315711602568626, -0.02474641241133213, 0.0011375952744856477, 0.02323123998939991, 0.0005572122172452509, 0.015592630952596664, 0.007403794676065445, 0.046878691762685776, 0.0602467805147171, -0.023998992517590523, -0.023782331496477127, -0.021349739283323288, -0.019146615639328957, -0.0035225979518145323, -0.014164288528263569, 0.008723653852939606, 0.043094564229249954, 0.005339872092008591, 0.0033737532794475555, -0.05227191001176834, 0.03843187913298607, -0.01592276431620121, -0.008811295963823795, -0.013041796162724495, -0.011692933738231659, 0.04514770209789276, -0.037789542227983475, -0.0008466176223009825, 0.03561600297689438, -0.006614364683628082, -0.06438759714365005, 0.012547486461699009, 0.009482739493250847, 0.05768909677863121, -0.006088663823902607, 0.028938664123415947, -0.06005930155515671, -0.015528518706560135, -0.015952996909618378, -0.03676473721861839, -0.007797801401466131, 0.01625971309840679, 0.005861756391823292, 0.0015239373315125704, -0.003948332741856575, 0.013718071393668652, 0.06696048378944397, -0.010306048206984997, 0.0035663635935634375, -0.004888969473540783, 0.015632424503564835, 0.00679633067920804, -0.033292584121227264, -0.0004762984171975404, -0.004752202425152063, 0.0452142097055912, 0.025149134919047356, 0.007290427573025227, 0.02785193920135498, -0.020453715696930885, -0.021601682528853416, 0.008839418180286884, -0.0044049764983356, -0.04492545127868652, -0.03805290907621384, -0.009739981964230537, -0.005668128374963999, -0.027678357437253, -0.02909606508910656, 0.0038168588653206825, 0.022284913808107376, -0.004542123526334763, -0.010520834475755692, -0.025571713224053383, -0.0289628803730011, -0.04409496486186981, 0.051699813455343246, 0.06636392325162888, 0.0094098886474967, -0.01679302006959915, 0.015142480842769146, -0.03658784180879593, 0.04535688832402229 ]
Block Sparse Matrices for Smaller and Faster Language Models
madlag
Sep 10, 2020
pytorch_block_sparse
research, nlp
https://huggingface.co/blog/pytorch_block_sparse
# Block Sparse Matrices for Smaller and Faster Language Models
[ 0.022621961310505867, 0.0025572367012500763, 0.07162658870220184, -0.012944454327225685, 0.09286730736494064, 0.04118649661540985, -0.019996117800474167, 0.0018243853701278567, -0.042966462671756744, -0.03434794396162033, -0.009790652431547642, 0.058736614882946014, -0.021690912544727325, 0.04014705866575241, 0.011999606154859066, 0.008640516549348831, 0.03306913748383522, -0.025889519602060318, 0.022465147078037262, 0.019324107095599174, 0.0062271966598927975, -0.06615621596574783, 0.13689947128295898, -0.02445405162870884, 0.0191800594329834, 0.02370040863752365, 0.003003876656293869, -0.011497091501951218, -0.09483098238706589, 0.0016818923177197576, -0.07196391373872757, 0.01781143993139267, -0.003976264502853155, 0.009157265536487103, 0.004341998137533665, -0.01515332330018282, -0.06030452623963356, 0.06512685865163803, 0.012952730990946293, -0.04238742217421532, -0.013334118761122227, -0.05082657188177109, -0.03172445669770241, 0.06687350571155548, -0.05568179488182068, 0.0012448099441826344, -0.2247549444437027, 0.12757661938667297, -0.0343286469578743, -0.06049615517258644, -0.11942058801651001, 0.044537756592035294, -0.028521573171019554, 0.006841692607849836, -0.000626151857431978, -0.019216464832425117, 0.025785358622670174, -0.10841380804777145, -0.002342900261282921, -0.03864087536931038, 0.02312590181827545, 0.022404570132493973, -0.003997283987700939, 0.021012423560023308, 0.03566963970661163, 0.025192847475409508, -0.0012246444821357727, -0.017648344859480858, -0.07975555211305618, 0.002232125960290432, 0.012094771489501, 0.008851722814142704, -0.07466248422861099, 0.003092450788244605, 0.02911640889942646, -0.024979842826724052, -0.016850540414452553, 0.06832113862037659, 0.03326793015003204, 0.0634319856762886, 0.007073512300848961, 0.04585516080260277, 0.07472735643386841, 0.06374303996562958, 0.011050756089389324, -0.009909120388329029, 0.02303709276020527, -0.04946378618478775, -0.028024209663271904, 0.045387592166662216, -0.004311760887503624, -0.06875714659690857, -0.002258607652038336, 0.006244145333766937, 0.030646689236164093, -0.013157857581973076, 0.04425952211022377, 0.04932412505149841, 0.012932887300848961, 0.04487590864300728, 0.000617083627730608, -0.008936483412981033, 0.03693316504359245, -0.05187888443470001, -0.062409959733486176, 0.02435317076742649, -0.017091872170567513, -0.04355299845337868, -0.03889242187142372, 0.010320133529603481, 0.0001800472236936912, 0.05478498339653015, 0.018227990716695786, -0.0064355009235441685, -0.05392386391758919, 0.06770695000886917, 0.02709333784878254, 0.03091813623905182, -0.022013947367668152, 0.0918121188879013, -0.002632946241647005, 0.10683081299066544, 0.08627922087907791, 0.02724408730864525, 0.03896968439221382, 0.04460713267326355, 0.07027330249547958, 0.04646718129515648, -0.061766400933265686, -0.042637020349502563, 0.012214497663080692, 0.004609985742717981, 0.07359650731086731, 0.0040410771034657955, 0.01634002849459648, -0.08879607170820236, 0.021486835554242134, 0.00828336551785469, 0.0050269318744540215, -0.018991224467754364, -0.027961837127804756, 0.03039327636361122, 0.005250249523669481, 0.03536960110068321, 0.06622251868247986, -0.0641455426812172, -0.035806652158498764, 0.0563170462846756, -0.00284679071046412, -0.00987541489303112, -0.011298933066427708, 0.05475073307752609, -0.03685596212744713, -0.05737365409731865, -0.005246805492788553, 0.05366089940071106, -0.013858110643923283, -0.0014860123628750443, -0.049823932349681854, 0.0019055032171308994, -0.0441872701048851, -0.001285546226426959, -0.018375679850578308, -0.05877729505300522, 0.061167553067207336, -0.02895922213792801, 0.006454158574342728, -0.0005871871253475547, 0.029673276469111443, 0.017116090282797813, 0.00263486267067492, -0.031810835003852844, 0.0900825634598732, -0.030746519565582275, -0.10075598955154419, 0.03406146168708801, 0.026570990681648254, 0.05292408540844917, 0.041376322507858276, -0.0024013249203562737, -0.03419918939471245, 0.01144007220864296, -0.0020156381651759148, 0.0634821355342865, 0.014842085540294647, -0.03752996772527695, 0.06633535772562027, -0.007309092208743095, -0.0028344395104795694, 0.010790659114718437, -0.0745617151260376, -0.0009371781488880515, 0.12098255753517151, 0.014731119386851788, 0.027891093865036964, -0.09650710970163345, -0.05360180139541626, 0.14147727191448212, 0.07497327029705048, 0.1043226346373558, 0.016724634915590286, 0.03747233748435974, 0.0013143854448571801, 0.005382319446653128, 0.03043038211762905, 0.045669376850128174, 0.023539647459983826, 0.005032653454691172, 0.0029995720833539963, 0.01565096154808998, -0.013780121691524982, -0.08435075730085373, 0.061459772288799286, -0.08062934130430222, -0.04620952904224396, 0.008978954516351223, 0.04188309237360954, 0.022006409242749214, -0.012746227905154228, -0.043766848742961884, 0.14703306555747986, -0.03676755726337433, -0.06392063200473785, 0.014065214432775974, -0.039148978888988495, 0.08889995515346527, 0.07486487179994583, -0.01740591786801815, 0.10596399754285812, -0.05428524315357208, 0.011903153732419014, -0.006065392401069403, 0.033577483147382736, 0.09027374535799026, 0.016868731006979942, 0.022222280502319336, -0.02668182924389839, 0.02967265620827675, 0.03109523095190525, -0.05325307697057724, -0.03992898762226105, -0.041031885892152786, -0.003839474869892001, 0.0303794052451849, -0.03216176852583885, -0.023757362738251686, 0.07233346998691559, -0.034546516835689545, -0.054909419268369675, 0.03906223550438881, -0.04742858558893204, 0.03534651920199394, -0.013552483171224594, -0.03189563751220703, 0.05403444170951843, 0.01022488996386528, 0.02039223164319992, -0.03352953493595123, -0.009685587137937546, -0.008689437992870808, 0.019783886149525642, -0.009547574445605278, -0.015013037249445915, -0.053761791437864304, -0.011185241863131523, -0.0241578109562397, 0.029208578169345856, 0.002373490482568741, -0.012187589891254902, 0.03288532793521881, 0.009984302334487438, -0.023849960416555405, 0.029697533696889877, 0.009468324482440948, 0.003441454842686653, 0.03506028652191162, 0.008727969601750374, -0.049263499677181244, -0.030510108917951584, -0.013395066373050213, -0.013728456571698189, -0.025336477905511856, 0.03281838074326515, 0.01137240044772625, 0.02710457146167755, -0.01938062533736229, 0.013190368190407753, 0.0023323860950767994, 0.000025909799660439603, 0.012158477678894997, -0.017095191404223442, 0.03154238685965538, -0.04500146582722664, -0.02267308533191681, 0.02208029478788376, -0.005469661206007004, -0.018147027119994164, 0.009853948839008808, -0.018002824857831, 0.005485911387950182, 0.019334064796566963, 0.024546237662434578, -0.016488315537571907, -0.0021512547973543406, -0.047819338738918304, 0.045143697410821915, -0.013302421197295189, 0.03413664922118187, -0.13421201705932617, -0.04793395847082138, 0.010559872724115849, 0.015201838687062263, -0.0007189555326476693, -0.024674678221344948, 0.04419775679707527, -0.030579399317502975, 0.011692154221236706, -0.018593737855553627, 0.02018955536186695, 0.034963466227054596, 0.005291537847369909, 0.007482592482119799, -0.012209797278046608, -0.008342630229890347, -0.026749784126877785, 0.019725043326616287, 0.011946560814976692, 0.013512412086129189, -0.011979381553828716, 0.051511190831661224, -0.005158377345651388, -0.013814450241625309, -0.014651183038949966, 0.026450026780366898, 0.027544289827346802, 0.023325206711888313, 0.011231020092964172, -0.020619582384824753, -0.05142073333263397, 0.017962412908673286, -0.04267580434679985, 0.009512573480606079, -0.050189822912216187, 0.007154762279242277, 0.00043738321983255446, 0.027873210608959198, -0.0012638126499950886, 0.015843363478779793, 0.03071756660938263, 0.006307228934019804, 0.05190098658204079, -0.0017380922799929976, -0.02428431250154972, 0.008624653331935406, -0.023429973050951958, -0.005183784291148186, 0.03619665279984474, -0.05147005245089531, -0.03618490323424339, -0.04302753508090973, 0.023722223937511444, 0.06335119903087616, 0.0007501267828047276, 0.02331123873591423, 0.0022200383245944977, -0.004403446335345507, 0.03560369461774826, -0.010212586261332035, -0.024260681122541428, 0.03169281408190727, 0.02591664157807827, -0.015790127217769623, -0.06596289575099945, 0.036643195897340775, 0.00012938448344357312, 0.04914828762412071, -0.002320554805919528, 0.035691168159246445, 0.014227055944502354, -0.035723257809877396, 0.006002542097121477, 0.01691320352256298, 0.003860033815726638, 0.05977440997958183, -0.01668279804289341, -0.017272507771849632, 0.06710851937532425, 0.016298379749059677, -0.01621273159980774, -0.035228926688432693, -0.00803779624402523, 0.009325042366981506, -0.0059231361374258995, -0.017431404441595078, 0.002121969358995557, 0.006189554929733276, 0.014387506060302258, 0.03974073752760887, 0.00433920556679368, -0.03659855201840401, 0.02113836631178856, -0.004529026802629232, 0.017269322648644447, 0.023940322920680046, 0.036991093307733536, -0.021214554086327553, 0.01695389486849308, 0.01078959833830595, 0.05565932020545006, -0.02542109601199627, 0.00178787752520293, -0.014150700531899929, 0.001107125193811953, 0.02680201083421707, -0.06007524952292442, 0.007579189725220203, -0.01192563958466053, 0.01587003283202648, 0.013261274434626102, 0.010722175240516663, 0.0153723806142807, -0.015315263532102108, -0.020617308095097542, -0.005021141842007637, -0.044210489839315414, -0.016892289742827415, -0.021916156634688377, 0.0005930661573074758, -0.04440406337380409, 0.0072832475416362286, 0.00474914675578475, -0.01459169015288353, 0.01733650267124176, -0.02281179651618004, -0.013970676809549332, -0.0013451665872707963, -0.04273517429828644, 0.014894484542310238, -0.04335646703839302, -0.016578111797571182, 0.04157757759094238, -0.022943081334233284, 0.05526699125766754, 0.00641264533624053, -0.030277932062745094, 0.04184948652982712, -0.008027631789445877, -0.0765625387430191, -0.004378138575702906, 0.00668205926194787, 0.020959584042429924, -0.03281733766198158, 0.052025891840457916, -0.030664760619401932, -0.026400838047266006, 0.007992325350642204, -0.018195774406194687, 0.06058892607688904, 0.04020371288061142, -0.04150582477450371, -0.0330173522233963, -0.004395803902298212, 0.029991714283823967, -0.008688936941325665, 0.014934180304408073, -0.0008035029750317335, -0.024612881243228912, 0.04622245952486992, -0.004681475460529327, 0.002010249299928546, -0.07309800386428833, 0.021775776520371437, -0.0045023090206086636, -0.041155338287353516, 0.0003538180608302355, -0.0367734357714653, 0.0005331307766027749, 0.004113358445465565, -0.0076134586706757545, -0.000408421823522076, 0.002259416738525033, 0.00864762719720602, 0.021964509040117264, 0.006415809039026499, 0.02149183489382267, -0.010478759184479713, -0.01892661117017269, 0.01918303221464157, -0.014564614742994308, 0.003971973434090614, 0.024350451305508614, 0.044235825538635254, -0.00524835055693984, 0.0268617644906044, 0.02693299390375614, 0.02943245880305767, -0.005471786484122276, 0.037256620824337006, 0.010606932453811169, -0.004516424611210823, 0.029165541753172874, -0.028743186965584755, 0.022610502317547798, -0.0004622270935215056, -0.019264377653598785, 0.0021646288223564625, -0.02973964624106884, -0.00971155520528555, 0.023710200563073158, 0.0206095390021801, -0.019966283813118935, -0.007917813956737518, 0.026472385972738266, -0.00267994892783463, -0.01806536875665188, -0.039707884192466736, -0.005152746569365263, -0.026677347719669342, -0.005204624496400356, 0.010180581361055374, -0.052195027470588684, -0.04470966011285782, -0.019673125818371773, -0.033612579107284546, -0.00837611872702837, 0.015378194861114025, -0.01821257174015045, 0.03970594331622124, 0.00801287405192852, -0.029574839398264885, -0.0398024246096611, 0.021530242636799812, 0.028230754658579826, -0.009920683689415455, -0.03778322786092758, 0.03176761791110039, 0.006122168153524399, 0.04858433082699776, 0.03963451087474823, -0.01992785558104515, 0.006353984586894512, 0.01599021814763546, -0.0015412218635901809, 0.0011868283618241549, -0.03336262330412865, 0.045177020132541656, 0.031709566712379456, 0.009469735436141491, 0.002092877170071006, -0.011193321086466312, -0.04690362140536308, 0.002387136919423938, -0.03110443614423275, 0.017149677500128746, 0.04779621958732605, -0.017791926860809326, -0.0003174181329086423, 0.009144571609795094, 0.029136287048459053, -0.019547026604413986, 0.044068362563848495, 0.007977684959769249, 0.015243723057210445, 0.053816553205251694, 0.0055151404812932014, -0.06141175329685211, 0.004968726541846991, -0.01136518083512783, 0.013597642071545124, -0.0063108401373028755, 0.041831038892269135, 0.03583812713623047, -0.04498312249779701, 0.030007656663656235, 0.03780243173241615, -0.04483110085129738, 0.022076155990362167, 0.009654738940298557, 0.004793144296854734, 0.008005542680621147, -0.011750472709536552, 0.019832858815789223, 0.008404023014008999, -0.03440140187740326, 0.030406948179006577, 0.054024290293455124, 0.008843163028359413, 0.028378810733556747, -0.003916149027645588, 0.038342151790857315, 0.024370869621634483, -0.007288020104169846, -0.019992288202047348, 0.030991090461611748, 0.02279861830174923, -0.0015632194699719548, 0.015298773534595966, 0.031338971108198166, -0.008162378333508968, 0.004266870208084583, -0.029332822188735008, -0.0077332910150289536, -0.04578429087996483, 0.0375639833509922, 0.02323285862803459, 0.00004613198689185083, 0.020302705466747284, -0.07018116116523743, 0.043746184557676315, 0.025933310389518738, -0.017559608444571495, -0.015350807458162308, -0.03113657981157303, 0.01770700328052044, 0.015645476058125496, -0.00124747259542346, 0.013575971126556396, -0.020272834226489067, 0.003882309189066291, 0.06980007886886597, -0.00018091450328938663, 0.01921135000884533, 0.016378819942474365, -0.013238480314612389, 0.04260307550430298, -0.041995976120233536, -0.007144031580537558, -0.006217997055500746, 0.012109749019145966, -0.008839363232254982, -0.0197831392288208, -0.0241420678794384, -0.041991058737039566, -0.03915327787399292, -0.00376222119666636, -0.004446948878467083, -0.041785337030887604, -0.004335059784352779, -0.012688959948718548, 0.014891386963427067, 0.005571227520704269, -0.01380580198019743, -0.0030571597162634134, 0.0017621511360630393, 0.06253620237112045, 0.04201100021600723, -0.01608356460928917, -0.02333030290901661, -0.02197590470314026, 0.01832660101354122, -0.008323963731527328, -0.017209913581609726, -0.024049658328294754, -0.023894496262073517, 0.02137744426727295, 0.0011347731342539191, -0.02770495042204857, 0.07337094843387604, 0.03687115013599396, 0.023589245975017548, -0.024736983701586723, 0.02406877651810646, -0.05446845665574074, -0.01831148751080036, 0.004859540145844221, -0.034314632415771484, -0.037061456590890884, -0.027319375425577164, 0.0002630945818964392, 0.044910792261362076, 0.007710093166679144, -0.021250246092677116, -0.04131711646914482, -0.011140582151710987, -0.018761426210403442, -0.023121414706110954, 0.016447382047772408, 0.02459768019616604, -0.021961530670523643, -0.000991652486845851, -0.023602953180670738, -0.015927961096167564, -0.043355122208595276, -0.019935140386223793, 0.029885824769735336, 0.004147628787904978, -0.0035987673327326775, -0.04485919326543808, 0.06181454658508301, 0.01134428009390831, 0.009792756289243698, 0.0035941419191658497, 0.04486456140875816, 0.002943164436146617, -0.04271189868450165, 0.012008274905383587, 0.008190711960196495, 0.025506649166345596, -0.02291783131659031, -0.028983071446418762, -0.027449216693639755, -0.043355632573366165, 0.008271104656159878, -0.0014760110061615705, -0.058291029185056686, 0.00869459006935358, -0.0272524394094944, 0.015210756100714207, -0.05082404240965843, 0.016121340915560722, 0.039669714868068695, 0.03444324806332588, 0.019035009667277336, -0.031074265018105507, -0.00925846491008997, -0.013805028982460499, -0.018945176154375076, -0.0005511282361112535, 0.011743058450520039, -0.023228852078318596, -0.016972465440630913, -0.01027714740484953, 0.013006270863115788, -0.036955881863832474, -0.05776318535208702, -0.00818552728742361, 0.01532994955778122, 0.006954767741262913, -0.012161298654973507, 0.005203999578952789, 0.005998910404741764, -0.010532690212130547, 0.01818273961544037, 0.04366324096918106, -0.014372110366821289, -0.014441782608628273, -0.006043105851858854, -0.06471534073352814, -0.01046853419393301, -0.021448912099003792, 0.008440187200903893, 0.08544835448265076, 0.012583557516336441, -0.0004095565527677536, -0.013537167571485043, -0.04117044806480408, -0.01277647353708744, 0.005390665028244257, -0.017388232052326202, -0.022550849243998528, 0.0007176548824645579, -0.016273794695734978, -0.018933067098259926, -0.053707823157310486, 0.017227305099368095, 0.01674710400402546, 0.013490884564816952, -0.023765234276652336, -0.004681240301579237, 0.0008570422069169581, 0.0040365238673985004, 0.009248440153896809, -0.008873372338712215, 0.029297281056642532, 0.03390834107995033, -0.008658723905682564, -0.0008144142339006066, 0.03212807700037956 ]
Block Sparse Matrices for Smaller and Faster Language Models
madlag
Sep 10, 2020
pytorch_block_sparse
research, nlp
https://huggingface.co/blog/pytorch_block_sparse
Usage The provided BlockSparseLinear module is a drop in replacement for torch.nn.Linear, and it is trivial to use it in your models: python # from torch.nn import Linear from pytorch_block_sparse import BlockSparseLinear ... # self.fc = nn.Linear(1024, 256) self.fc = BlockSparseLinear(1024, 256, density=0.1) The extension also provides a BlockSparseModelPatcher that allows to modify an existing model "on the fly", which is shown in this example notebook. Such a model can then be trained as usual, without any change in your model source code.
[ 0.026065370067954063, -0.023656757548451424, 0.04893774911761284, 0.0021481788717210293, 0.0306947473436594, 0.03869304805994034, -0.007789705879986286, -0.01683530956506729, -0.06547579914331436, -0.01916327327489853, -0.06833042204380035, 0.0065322634764015675, 0.033450450748205185, -0.015235274098813534, 0.04530409350991249, -0.004647147376090288, 0.009335678070783615, -0.0005582379526458681, -0.014004169963300228, 0.07677152007818222, 0.0037818006239831448, -0.0944083034992218, 0.09720838069915771, -0.0021114014089107513, -0.02746451087296009, -0.0622606985270977, 0.012095951475203037, 0.02682369574904442, -0.04511936381459236, 0.03157329186797142, -0.10450788587331772, 0.006575015373528004, 0.018907716497778893, -0.07549116760492325, -0.003545978106558323, 0.03972518444061279, -0.06617587804794312, 0.02614011988043785, -0.011934539303183556, -0.006142290774732828, -0.017130594700574875, 0.07096538692712784, -0.09842626005411148, 0.08087541908025742, -0.01643606461584568, -0.046246763318777084, -0.13553853332996368, 0.09443145990371704, 0.01701582595705986, -0.05858192965388298, -0.09996408969163895, 0.022329621016979218, -0.032384179532527924, 0.009457465261220932, -0.01211989764124155, -0.03388566896319389, 0.005383017472922802, -0.03900071978569031, 0.04179099574685097, -0.0037967199459671974, 0.046068351715803146, -0.010058391839265823, 0.025844987481832504, 0.03339605778455734, 0.026950374245643616, 0.011786719784140587, 0.0288438368588686, 0.009935041889548302, -0.059090375900268555, 0.00961533933877945, 0.03348291665315628, 0.00581943616271019, -0.027907228097319603, -0.025869296863675117, -0.03671078383922577, -0.04300140589475632, 0.014660339802503586, 0.02169225923717022, 0.04937734454870224, 0.09073293954133987, 0.04454075172543526, 0.0704183429479599, 0.018075359985232353, 0.023211928084492683, -0.0001481124054407701, 0.02649698778986931, -0.026331281289458275, -0.0883895754814148, 0.05252494290471077, 0.05308505892753601, -0.058849286288022995, -0.06660572439432144, 0.016044991090893745, -0.00896972045302391, 0.04124144837260246, 0.012267041951417923, -0.011325095780193806, 0.02448810636997223, -0.007601185701787472, -0.015002320520579815, -0.03968508169054985, -0.02568511664867401, 0.021772200241684914, -0.043001167476177216, -0.05849383398890495, 0.02373208850622177, 0.0195295549929142, -0.11578445136547089, -0.038033440709114075, -0.03320219740271568, -0.01717817410826683, 0.02516699954867363, -0.031154638156294823, 0.025034813210368156, -0.052483439445495605, -0.04475446417927742, 0.015731967985630035, 0.04012100398540497, -0.019219521433115005, 0.009380138479173183, -0.06090564653277397, 0.10937732458114624, 0.05204715579748154, 0.02999083139002323, 0.08514727652072906, 0.09729330241680145, 0.04158458113670349, 0.07370780408382416, 0.0035634858068078756, -0.017722604796290398, 0.07777415961027145, 0.011296099051833153, 0.06145709007978439, -0.011183477938175201, 0.022855862975120544, -0.06245596706867218, 0.00668607372790575, -0.018658002838492393, 0.004705998580902815, -0.008365114219486713, -0.049240801483392715, 0.009967898949980736, 0.02614961564540863, 0.07110918313264847, 0.08516174554824829, -0.05536384508013725, -0.0267607644200325, 0.1104610338807106, 0.004472512286156416, -0.009328684769570827, -0.01206560991704464, 0.05249173194169998, 0.0016075274907052517, -0.050536636263132095, -0.05739179626107216, 0.01495049986988306, -0.0019959716591984034, 0.009220240637660027, -0.05116315186023712, -0.007846027612686157, -0.00699343578889966, -0.036369748413562775, -0.029652245342731476, -0.019540609791874886, 0.08910267800092697, -0.02826012670993805, 0.06527441740036011, -0.0012354861246421933, 0.003308944869786501, -0.015283799730241299, -0.0005108297918923199, -0.007031177170574665, 0.0014667061623185873, -0.016462277621030807, -0.0527496412396431, 0.0417674221098423, 0.043492838740348816, 0.09689830243587494, 0.01727104000747204, -0.06037624180316925, -0.03541944921016693, 0.0443253330886364, -0.06532318145036697, 0.04645359888672829, -0.007458914071321487, -0.04791213944554329, 0.051036857068538666, -0.01834138110280037, 0.002410904737189412, 0.0032968760933727026, -0.048520106822252274, 0.041635703295469284, 0.016938233748078346, -0.028900597244501114, 0.06979524344205856, -0.0831407830119133, -0.08628769218921661, 0.05979762598872185, 0.0015074033290147781, 0.11172980070114136, 0.045278847217559814, 0.012105733156204224, -0.04845824092626572, -0.0315580740571022, 0.04704364016652107, 0.0072906892746686935, 0.0068858228623867035, -0.021323395892977715, 0.056567203253507614, -0.051941219717264175, 0.02023608796298504, -0.11016787588596344, 0.039036497473716736, -0.09568241983652115, 0.0022536644246429205, 0.04898449406027794, -0.04848578944802284, 0.03415553644299507, -0.010998349636793137, 0.00037248810986056924, 0.1790449321269989, -0.0171958040446043, -0.030198991298675537, -0.005736267194151878, -0.08156424015760422, 0.09325052052736282, 0.06144486367702484, 0.012070381082594395, 0.03244830295443535, -0.06203373894095421, -0.019080905243754387, -0.05737260356545448, -0.017376193776726723, 0.09863366186618805, -0.021097863093018532, -0.038610633462667465, -0.009927988983690739, 0.010418349876999855, 0.01531146839261055, -0.09353943914175034, -0.017019404098391533, -0.008089101873338223, 0.02918892167508602, -0.02594054862856865, -0.045859917998313904, 0.049365490674972534, 0.039837341755628586, -0.01606934703886509, 0.040638674050569534, 0.021548770368099213, -0.01320036593824625, 0.015660272911190987, 0.02989983558654785, -0.06091941520571709, 0.019543824717402458, 0.05430053919553757, -0.02133224532008171, -0.037266138941049576, 0.03857961297035217, 0.02806270681321621, 0.03599264845252037, 0.007018790580332279, -0.054407697170972824, -0.01862420327961445, -0.032815080136060715, -0.07431311905384064, 0.025505952537059784, -0.022971175611019135, 0.007540193852037191, 0.0008537928224541247, 0.043332260102033615, -0.024053798988461494, 0.015516982413828373, -0.0033806241117417812, 0.023582281544804573, 0.014963357709348202, 0.014200996607542038, -0.07357663661241531, -0.02996472455561161, -0.06473931670188904, 0.002626471221446991, -0.04049097001552582, 0.04565994441509247, 0.018371272832155228, 0.017166391015052795, 0.01473383791744709, 0.01985984854400158, -0.03191545978188515, -0.03604612499475479, 0.03235671669244766, -0.01979440450668335, 0.01909550279378891, 0.002690064487978816, -0.012322126887738705, -0.012765457853674889, 0.031830281019210815, -0.04074035957455635, 0.018876036629080772, -0.010164480656385422, 0.01077275536954403, 0.019388914108276367, 0.02323739603161812, -0.016513824462890625, 0.032251663506031036, -0.06443846970796585, 0.023408036679029465, 0.0006560253095813096, 0.023193232715129852, -0.10424809157848358, -0.03202681243419647, 0.0008443274418823421, 0.014476077631115913, -0.03717140480875969, -0.02554391510784626, 0.01079923938959837, -0.001667526550590992, 0.025777248665690422, -0.01491436455398798, 0.017525866627693176, -0.007764896377921104, 0.017998097464442253, 0.05046367645263672, -0.03587733209133148, 0.009955476969480515, -0.0030397416558116674, 0.01681356318295002, 0.026328150182962418, -0.02444526180624962, -0.03683268651366234, 0.04318465664982796, -0.0031774912495166063, 0.009622347541153431, -0.0030217766761779785, 0.004206765443086624, 0.04365381971001625, 0.02089894749224186, -0.008264035917818546, -0.008780608884990215, -0.03534495458006859, -0.01335262879729271, 0.00604964466765523, 0.0038053689058870077, -0.010439303703606129, 0.004396772012114525, -0.017843272536993027, -0.012101788073778152, 0.02984301559627056, 0.012751472182571888, -0.007071709260344505, 0.0018718056380748749, 0.013916926458477974, -0.0420246347784996, 0.04766524210572243, -0.006748209707438946, -0.022949043661355972, 0.03125595301389694, 0.01900501735508442, -0.049529992043972015, -0.018340222537517548, -0.02600902132689953, 0.021243231371045113, 0.021656261757016182, -0.01030100230127573, 0.0007119136280380189, 0.027910206466913223, 0.037768326699733734, -0.003947494551539421, -0.011822913773357868, -0.0527169406414032, 0.04078776016831398, -0.00409039668738842, 0.014814128167927265, -0.009484173730015755, 0.06848688423633575, 0.01362141314893961, -0.003448465606197715, -0.023827197030186653, 0.0320785753428936, -0.010660039260983467, 0.006083897314965725, 0.010652055032551289, 0.01215964462608099, -0.017075054347515106, 0.0468374565243721, -0.004957511555403471, -0.0066018071956932545, 0.04728105664253235, 0.03053927794098854, 0.014888900332152843, -0.029203863814473152, 0.028856031596660614, 0.014246693812310696, -0.019317975267767906, 0.027078209444880486, 0.02333296835422516, -0.009096626192331314, 0.024105563759803772, -0.009394350461661816, -0.0006137082818895578, -0.02419605292379856, 0.026007814332842827, -0.010286863893270493, -0.024228615686297417, -0.006561542395502329, -0.006592889316380024, 0.007957647554576397, 0.04551743343472481, 0.016960348933935165, 0.03092806786298752, -0.03473684936761856, 0.02052459865808487, -0.019819658249616623, 0.015444135293364525, 0.03538248687982559, -0.053651660680770874, 0.017902275547385216, 0.020543910562992096, -0.02964756265282631, -0.0327095128595829, -0.0367278978228569, -0.00447362195700407, 0.0021339613012969494, 0.02189813368022442, -0.013172836974263191, -0.04105878993868828, -0.03463240712881088, -0.02676084078848362, -0.013881941325962543, -0.05773849040269852, 0.03886135295033455, -0.01359151117503643, -0.0226433165371418, -0.0012125198263674974, -0.01792290061712265, 0.022058026865124702, 0.030893608927726746, 0.014322234317660332, 0.004085555672645569, -0.061535581946372986, -0.00501085864380002, -0.003090441459789872, 0.019808584824204445, 0.009640180505812168, 0.06441888958215714, 0.001282909419387579, 0.040678657591342926, 0.02164209634065628, -0.048312608152627945, -0.03304325416684151, 0.012288660742342472, 0.013883681036531925, -0.041775137186050415, 0.05848485603928566, 0.004582731984555721, -0.04816336929798126, 0.0001093944811145775, -0.05873490124940872, 0.039657317101955414, 0.05417817085981369, -0.0024976972490549088, 0.00882126297801733, -0.005560545716434717, 0.031666651368141174, -0.03557249531149864, -0.0044411965645849705, 0.008227826096117496, 0.016223683953285217, 0.02643589675426483, -0.013330919668078423, -0.012874787673354149, -0.033144157379865646, 0.014574263244867325, 0.04261665418744087, -0.037908297032117844, 0.013011916540563107, -0.07350090146064758, 0.012488297186791897, 0.0071690017357468605, -0.03550597280263901, -0.018731463700532913, 0.006897955667227507, -0.03930351510643959, 0.028125666081905365, 0.07001489400863647, 0.02419811300933361, -0.012941321358084679, -0.02145032212138176, 0.040019575506448746, -0.005623249802738428, 0.0022178939543664455, 0.044787194579839706, 0.03919057920575142, -0.009233986027538776, 0.07408270239830017, 0.008792119100689888, 0.026188164949417114, 0.038563042879104614, 0.02827322483062744, 0.006234620697796345, -0.017249776050448418, 0.015817563980817795, -0.02838415652513504, 0.024194879457354546, 0.008119173347949982, -0.06871432811021805, -0.019338440150022507, 0.0030155919957906008, -0.001252225716598332, -0.012801265344023705, 0.03275717794895172, -0.028808286413550377, -0.017896423116326332, 0.0387466736137867, 0.014317729510366917, 0.03189024329185486, -0.006941012106835842, 0.011746178381145, -0.013817764818668365, -0.016885628923773766, 0.016054781153798103, -0.014837367460131645, -0.028180871158838272, -0.002118600532412529, 0.00434039207175374, -0.007104489952325821, 0.008829446509480476, 0.0047565363347530365, 0.04223513975739479, 0.011943724006414413, -0.05871393904089928, -0.038122743368148804, 0.018056808039546013, 0.03137785568833351, -0.034699831157922745, 0.0037909827660769224, 0.06609506160020828, 0.02329936996102333, 0.04611961916089058, 0.05783500894904137, -0.03458114340901375, -0.002278481610119343, -0.0005919708055444062, 0.025510894134640694, 0.002928251400589943, -0.0162257831543684, 0.05920423939824104, -0.03270578011870384, -0.012419305741786957, -0.008236352354288101, -0.00817209854722023, -0.03686898201704025, 0.031072136014699936, -0.020780712366104126, 0.018053337931632996, 0.047019071877002716, -0.015611512586474419, 0.025740869343280792, -0.03656691685318947, 0.07692445814609528, 0.01953709125518799, 0.0013557343045249581, -0.020569490268826485, -0.0014746295055374503, 0.0016662442358210683, 0.016944274306297302, 0.00037772959331050515, 0.03893185779452324, 0.016292981803417206, 0.052831318229436874, -0.05316045880317688, -0.013920944184064865, 0.017147304490208626, -0.009496652521193027, 0.027322718873620033, -0.012957265600562096, -0.02917318232357502, -0.008807087317109108, 0.010656028054654598, 0.0035070315934717655, 0.05217769369482994, 0.007813009433448315, 0.02905128337442875, -0.015382346697151661, -0.045695461332798004, -0.025952303782105446, 0.022161729633808136, -0.04828362911939621, 0.017699316143989563, -0.008806212805211544, 0.019791604951024055, 0.01688026264309883, -0.009696578606963158, -0.007526629138737917, 0.02356259897351265, 0.058078933507204056, -0.003960855770856142, 0.014971341006457806, 0.02258897013962269, -0.005317026283591986, 0.003971710801124573, -0.03199943155050278, -0.02427580952644348, -0.029237449169158936, 0.01054248958826065, 0.013166549615561962, 0.004379045683890581, 0.02308102697134018, -0.06543044000864029, 0.012448277324438095, 0.04216413199901581, 0.025671714916825294, -0.013507909141480923, 0.012370701879262924, 0.010299064218997955, 0.006328903138637543, -0.01163130160421133, 0.03941693902015686, 0.016693348065018654, -0.014170762151479721, 0.0445265993475914, -0.010439432226121426, 0.013517729006707668, -0.012723658233880997, -0.004335211589932442, 0.047148413956165314, -0.01852014660835266, -0.035904787480831146, -0.0003520408063195646, 0.009054474532604218, 0.0024367712903767824, -0.022143330425024033, 0.04088256135582924, -0.057751819491386414, -0.005677343346178532, -0.015078931115567684, 0.005813694559037685, -0.05865415558218956, 0.00020409484568517655, 0.002025031251832843, 0.00981166958808899, -0.027711641043424606, 0.05737514793872833, 0.011002815328538418, 0.006607367191463709, 0.04958324134349823, 0.02817005105316639, -0.0010574223706498742, -0.018772028386592865, -0.0008757312316447496, 0.011957347393035889, -0.006415997631847858, 0.014839337207376957, -0.015443132258951664, 0.0020768363028764725, -0.0101773077622056, 0.017672045156359673, -0.021392667666077614, 0.021607764065265656, 0.01912565529346466, 0.004159542266279459, -0.04486720636487007, 0.019165601581335068, -0.03834656998515129, -0.037653468549251556, -0.013627578504383564, -0.012870151549577713, -0.006016108673065901, 0.004233191255480051, 0.026006639003753662, 0.01825406402349472, 0.03177032247185707, -0.03048977069556713, -0.05043113976716995, -0.03739991411566734, -0.022583387792110443, -0.010951099917292595, -0.037526924163103104, 0.03775397315621376, 0.017265722155570984, 0.02625206671655178, -0.004187525250017643, -0.006966697983443737, -0.005383619107306004, -0.009034303948283195, -0.005877005867660046, 0.02914680540561676, -0.005019067786633968, -0.025759631767868996, 0.0540662556886673, -0.004624563734978437, -0.00943061150610447, 0.06340966373682022, 0.02380547486245632, 0.00001090138903236948, -0.029592420905828476, -0.009151209145784378, -0.02571471594274044, -0.0025686738081276417, -0.023536914959549904, -0.02587474137544632, -0.028481129556894302, 0.027984032407402992, -0.00008914405043469742, -0.011005271226167679, -0.02560441941022873, 0.030051659792661667, 0.000996762770228088, -0.012157252058386803, -0.04930838942527771, -0.0069742933847010136, 0.037570852786302567, 0.08182024210691452, -0.008930603042244911, -0.007474594749510288, -0.0541655458509922, 0.002879226813092828, -0.011568369343876839, 0.04695550352334976, 0.025965912267565727, -0.01635105349123478, -0.006703034043312073, -0.015861067920923233, 0.00397562375292182, 0.034676019102334976, -0.04972502216696739, -0.03437654674053192, -0.01690315082669258, -0.0193464457988739, -0.08172843605279922, 0.015361851081252098, 0.026735860854387283, 0.015276928432285786, 0.009394776076078415, 0.018104538321495056, 0.018291357904672623, -0.03749074041843414, 0.007101029623299837, -0.054556041955947876, -0.010313198901712894, -0.04197123646736145, -0.04037347063422203, 0.040848083794116974, 0.015749391168355942, 0.010832017287611961, 0.010995365679264069, -0.006149685475975275, -0.010930431075394154, 0.007510788273066282, -0.03432457149028778, -0.039221398532390594, -0.01243925467133522, 0.028831854462623596, 0.020955665037035942, -0.030783187597990036, 0.003626410849392414, 0.06414523720741272, 0.022453587502241135, 0.025895724073052406, 0.028088442981243134, 0.04217294603586197, 0.01081435102969408, 0.004192946013063192, 0.00002688028325792402, 0.011193236336112022, 0.0005254022544249892, 0.01872248947620392, -0.025376690551638603, 0.0010543735697865486 ]
Block Sparse Matrices for Smaller and Faster Language Models
madlag
Sep 10, 2020
pytorch_block_sparse
research, nlp
https://huggingface.co/blog/pytorch_block_sparse
NVIDIA CUTLASS This extension is based on the cutlass tilesparse proof of concept by Yulhwa Kim. It is using C++ CUDA templates for block-sparse matrix multiplication based on CUTLASS. CUTLASS is a collection of CUDA C++ templates for implementing high-performance CUDA kernels. With CUTLASS, approching cuBLAS performance on custom kernels is possible without resorting to assembly language code. The latest versions include all the Ampere Tensor Core primitives, providing x10 or more speedups with a limited loss of precision. Next versions of pytorch_block_sparse will make use of these primitives, as block sparsity is 100% compatible with Tensor Cores requirements.
[ -0.0035601218696683645, -0.04973497986793518, -0.049571048468351364, 0.07951098680496216, -0.0006812441861256957, 0.011779437772929668, 0.016899622976779938, 0.01594400778412819, -0.06960561871528625, -0.024251487106084824, -0.05777532979846001, 0.01983492448925972, 0.04619782418012619, 0.048759493976831436, 0.057419952005147934, -0.003516072640195489, 0.00868604052811861, -0.046153657138347626, -0.027688907459378242, 0.08770167082548141, -0.02416514791548252, -0.05059158802032471, 0.13987819850444794, 0.038273293524980545, -0.035305242985486984, 0.053452394902706146, 0.005119037348777056, 0.055244915187358856, -0.08387386798858643, 0.043310102075338364, -0.006077012978494167, 0.04003258794546127, -0.08577592670917511, -0.08366730064153671, 0.013566331937909126, -0.019303632900118828, 0.00151606067083776, -0.0015071786474436522, 0.02995830401778221, -0.022519711405038834, -0.02375870570540428, -0.017514115199446678, 0.004098138306289911, 0.08047869801521301, 0.010211932472884655, 0.02763100154697895, -0.016862504184246063, -0.0037340905983000994, -0.018111420795321465, -0.03465913236141205, -0.050063606351614, 0.04819789528846741, -0.004240167792886496, 0.0241315346211195, 0.05258310213685036, 0.03544638305902481, 0.00032453075982630253, -0.002221290487796068, 0.030680345371365547, -0.00495431711897254, 0.005647081881761551, 0.012181094847619534, -0.03397952392697334, -0.06595177948474884, 0.031180988997220993, 0.03888699412345886, 0.024460233747959137, 0.009358222596347332, -0.03437301516532898, 0.006346731912344694, 0.032495446503162384, -0.03254380449652672, -0.015096800401806831, 0.020351294428110123, -0.02339152991771698, 0.01896960474550724, -0.011383633129298687, 0.024737300351262093, 0.07658838480710983, 0.04434708133339882, -0.047268111258745193, 0.06870894134044647, 0.010666797868907452, 0.027796650305390358, -0.04480251297354698, -0.01345906313508749, -0.03818415477871895, -0.09045866131782532, -0.05053991451859474, 0.04163536801934242, 0.011143345385789871, -0.008849533274769783, 0.06396834552288055, 0.04739962890744209, 0.02060183882713318, 0.03370523825287819, -0.010317513719201088, -0.01756737194955349, 0.027144087478518486, -0.03602713719010353, 0.016699330881237984, -0.05951923504471779, -0.022120026871562004, -0.02812836319208145, -0.031006650999188423, 0.03306364268064499, -0.05212193354964256, -0.03882478550076485, -0.050446443259716034, 0.04907708987593651, 0.04123611003160477, 0.040871091187000275, 0.04180171713232994, 0.05889007821679115, -0.08177631348371506, 0.0038852684665471315, 0.01816112920641899, 0.03852171450853348, -0.04485802724957466, 0.057256024330854416, -0.0898226946592331, 0.05286915972828865, 0.05270823836326599, -0.00020759306789841503, 0.02504507079720497, 0.07446727156639099, 0.020259613171219826, 0.05033878609538078, 0.0662112906575203, -0.08752326667308807, 0.04248277470469475, 0.05375443398952484, -0.03892434015870094, -0.0012956314021721482, -0.01944785565137863, -0.06316974759101868, -0.011120680719614029, -0.06916191428899765, -0.02190910279750824, -0.06017329916357994, -0.03347345069050789, -0.03334692865610123, 0.03268374875187874, 0.012853439897298813, 0.015391651540994644, -0.030095938593149185, 0.03831088915467262, 0.036348115652799606, -0.00375376851297915, -0.00476547796279192, -0.0703602060675621, 0.005431491881608963, -0.018284160643815994, -0.019487697631120682, 0.03809545189142227, 0.018170693889260292, 0.03040851093828678, 0.0300323273986578, -0.13473451137542725, -0.0003985439252573997, 0.022186264395713806, -0.0793452262878418, 0.027492891997098923, -0.08559774607419968, -0.06436605751514435, 0.04987620189785957, 0.07958773523569107, -0.086115263402462, 0.027592282742261887, -0.01669258251786232, -0.0436435230076313, -0.04202251508831978, 0.023082787171006203, 0.004913988523185253, -0.03740251809358597, 0.005516905337572098, 0.08629991859197617, 0.05987803265452385, 0.040928684175014496, -0.07808168977499008, -0.024679183959960938, -0.01671539805829525, -0.0031506011728197336, 0.04687947407364845, -0.06105910986661911, -0.022249750792980194, 0.01650448516011238, -0.02294180914759636, 0.02371032163500786, 0.010542688891291618, -0.09454164654016495, 0.040641654282808304, 0.0092057129368186, -0.0068178786896169186, 0.025766901671886444, -0.025384588167071342, -0.08129232376813889, 0.06836971640586853, 0.06371906399726868, 0.07902152836322784, 0.02929416485130787, 0.03786192834377289, -0.03745375946164131, -0.04587121680378914, -0.005963128060102463, -0.01880710944533348, -0.03110535442829132, 0.08826103806495667, 0.04813124239444733, 0.014630026184022427, -0.05528723821043968, -0.07796589285135269, 0.09105212241411209, -0.008292889222502708, -0.01681297831237316, 0.04234996438026428, -0.013031045906245708, 0.012699875980615616, -0.006657857913523912, -0.007617306429892778, 0.12427271157503128, -0.04197177663445473, -0.0368657186627388, 0.02550402842462063, -0.12142861634492874, 0.04123619571328163, 0.04533185064792633, 0.023623555898666382, 0.0590006485581398, -0.05099814757704735, 0.10137476772069931, -0.03526630625128746, -0.01482586283236742, 0.12364382296800613, 0.012812180444598198, -0.02267228253185749, 0.05611821264028549, -0.0038737740833312273, 0.05293723940849304, -0.02268138714134693, -0.06451696902513504, 0.024608289822936058, -0.03497149050235748, -0.043392278254032135, 0.0574626587331295, -0.05113065615296364, 0.09501007944345474, -0.06322203576564789, 0.041534703224897385, -0.04910650476813316, 0.030202167108654976, 0.0514255166053772, 0.017504790797829628, -0.027742698788642883, 0.03960017114877701, 0.05662794038653374, 0.03125162795186043, -0.04866619035601616, 0.0195908322930336, 0.017277691513299942, 0.033558037132024765, -0.0001389250683132559, -0.07311946153640747, -0.054302431643009186, -0.027355428785085678, 0.0007175688515417278, 0.050327494740486145, 0.02299010008573532, -0.0101121561601758, -0.038605716079473495, 0.004909819923341274, -0.01988946832716465, -0.014160366728901863, -0.03484748303890228, 0.001014175359159708, -0.002685441169887781, -0.01800413988530636, -0.059100355952978134, -0.008921027183532715, -0.041858986020088196, -0.03806275501847267, -0.04223226010799408, 0.0011047458974644542, 0.05958876386284828, -0.00258540827780962, 0.014945208095014095, 0.04723532870411873, -0.0010757511481642723, -0.02043345756828785, 0.0021407532040029764, -0.06807612627744675, -0.0021385415457189083, 0.0017168450867757201, -0.03293244540691376, 0.03197431191802025, 0.021894967183470726, -0.03621218726038933, -0.009652671404182911, -0.024313712492585182, 0.005518859252333641, 0.025320570915937424, 0.04171140491962433, 0.0005273562273941934, -0.0036810599267482758, -0.021633043885231018, 0.06493526697158813, -0.03175981715321541, 0.026751723140478134, -0.06768066436052322, -0.01825137808918953, -0.026074202731251717, 0.02628140151500702, -0.03933361917734146, -0.0008374224998988211, -0.012977486476302147, 0.05232624709606171, 0.05713009834289551, 0.01855277083814144, 0.078221894800663, 0.04362966865301132, -0.04863027110695839, 0.0011699121678248048, 0.006574931088835001, 0.00919452216476202, 0.040695540606975555, -0.0021142573095858097, 0.0019479605834931135, 0.026086730882525444, -0.033605799078941345, 0.012927778996527195, -0.0037266553845256567, 0.03271837532520294, -0.010228653438389301, -0.016760773956775665, 0.02830655127763748, 0.011496384628117085, -0.012293187901377678, -0.0011073818895965815, -0.004843285772949457, 0.04909095913171768, -0.00858868844807148, 0.011662243865430355, -0.03322325646877289, -0.008351175114512444, -0.019735677167773247, -0.04329598695039749, 0.046180326491594315, -0.05351289361715317, -0.02791820652782917, 0.0011673743138089776, 0.0532841831445694, -0.05957288667559624, 0.03179749846458435, -0.009249112568795681, 0.03825434669852257, 0.06054350733757019, 0.0007520047365687788, -0.03009614907205105, -0.025112370029091835, -0.03117898851633072, -0.01160547323524952, 0.05677912384271622, -0.03389810398221016, 0.003713508602231741, 0.0027820831164717674, 0.018456313759088516, -0.002851452911272645, -0.01572452113032341, 0.006284402217715979, -0.018220648169517517, 0.01210735272616148, 0.010545487515628338, 0.02841494232416153, 0.003674023784697056, 0.006036109756678343, 0.01627260632812977, -0.07424680888652802, 0.028618842363357544, -0.02540862374007702, 0.03153205290436745, 0.008009889163076878, -0.0007517836056649685, -0.005716721527278423, -0.006354710552841425, 0.03599202260375023, -0.013544969260692596, 0.02441108040511608, 0.001742816180922091, 0.02783772721886635, -0.04179682210087776, 0.021091511473059654, 0.00834941677749157, 0.01743355393409729, 0.022546978667378426, -0.022887079045176506, 0.034952905029058456, 0.022456668317317963, 0.020109139382839203, 0.008237596601247787, -0.07982874661684036, 0.03644942864775658, -0.0006420414429157972, 0.030710836872458458, 0.01524632889777422, -0.01022691186517477, 0.02630172111093998, -0.007378635462373495, -0.026184143498539925, -0.00828974973410368, -0.024480167776346207, 0.03766799345612526, -0.002471870044246316, -0.022734960541129112, 0.007693033199757338, -0.012213412672281265, 0.0001988032745430246, -0.015608450397849083, 0.008120845071971416, -0.0015810610493645072, -0.046388108283281326, 0.0031655472703278065, 0.034219708293676376, 0.028071537613868713, 0.01898724026978016, -0.025548627600073814, 0.03666573017835617, -0.04298899695277214, 0.002668248023837805, 0.012717468664050102, 0.008006991818547249, 0.0030505273025482893, -0.025800809264183044, -0.001251312205567956, -0.015204663388431072, 0.008303157053887844, 0.019649190828204155, 0.04073076322674751, -0.013412650674581528, -0.04798589274287224, -0.013045040890574455, -0.006815585307776928, 0.0014982572756707668, 0.0388631671667099, -0.00694138091057539, -0.004969914443790913, -0.012920106761157513, 0.03398129716515541, 0.007263823412358761, -0.01974518597126007, 0.01673412322998047, 0.042872361838817596, -0.028773795813322067, 0.07397621870040894, 0.005284109618514776, -0.000990208238363266, 0.03413569554686546, -0.053615182638168335, 0.0658760815858841, -0.040474168956279755, -0.04943614825606346, 0.0455244779586792, -0.024946065619587898, 0.006559680216014385, 0.03508297726511955, 0.06139808148145676, 0.0012610520934686065, 0.017671920359134674, 0.03760520741343498, -0.016408808529376984, 0.02722869999706745, -0.0638432502746582, -0.019714953377842903, -0.0012894434621557593, -0.025218456983566284, 0.02277841418981552, -0.06794092804193497, -0.017071831971406937, -0.025351742282509804, -0.03834939002990723, 0.046770744025707245, -0.011827150359749794, -0.06151611730456352, 0.009957000613212585, 0.02025902085006237, 0.022176019847393036, 0.026539849117398262, 0.014307373203337193, -0.0016008807579055429, -0.05696595460176468, -0.008957023732364178, 0.03765689209103584, 0.010182924568653107, 0.00465603219345212, 0.051573965698480606, -0.05955999344587326, 0.07249065488576889, -0.01818099059164524, 0.007942144758999348, 0.043527744710445404, 0.002183889737352729, 0.0072508882731199265, -0.037358302623033524, 0.024576382711529732, -0.008864139206707478, -0.03318427503108978, -0.008636529557406902, -0.03246719017624855, -0.0081814369186759, 0.01593775302171707, -0.04781705513596535, -0.05936288833618164, 0.052788786590099335, 0.009639887139201164, 0.013914651237428188, 0.040762145072221756, -0.02380039542913437, -0.0064681414514780045, -0.016360677778720856, -0.0011779891792684793, -0.004587269853800535, 0.024380844086408615, -0.0391203835606575, -0.046775780618190765, -0.03656995669007301, 0.004152231849730015, 0.02724355459213257, -0.013732561841607094, -0.0070081972517073154, -0.005570346489548683, 0.01782325841486454, 0.010830228216946125, -0.0023631893564015627, -0.05783793330192566, 0.03481125086545944, -0.026738272979855537, 0.004010660108178854, -0.028693266212940216, 0.0427253395318985, 0.053733810782432556, -0.009701675735414028, -0.009560950100421906, -0.005621621385216713, 0.012949138879776001, -0.0178148802369833, -0.01335269957780838, 0.036278799176216125, 0.0060629406943917274, -0.034890592098236084, -0.03822128102183342, -0.04748508706688881, 0.0049216956831514835, -0.008267316035926342, -0.026039479300379753, -0.024014310911297798, 0.01981130987405777, -0.030022500082850456, -0.015387040562927723, -0.015375417657196522, 0.047057054936885834, -0.016155695542693138, -0.010466060601174831, 0.011479713022708893, 0.01213840302079916, -0.026568816974759102, 0.02084229700267315, 0.005466535221785307, -0.028137119486927986, -0.025386208668351173, 0.02424410916864872, 0.009431303478777409, -0.0124936792999506, 0.022818125784397125, -0.046896182000637054, 0.008102819323539734, -0.019246600568294525, -0.023827863857150078, 0.016282454133033752, -0.01198955811560154, -0.03788347914814949, 0.005408748518675566, 0.03322969004511833, 0.01345398835837841, -0.03564317896962166, -0.037168700248003006, -0.04859407618641853, 0.028053874149918556, 0.013964698649942875, -0.001971145858988166, -0.02909991517663002, 0.05724003538489342, -0.012250612489879131, 0.026047317311167717, -0.03883158788084984, 0.010614790953695774, 0.008037402294576168, 0.013526341877877712, 0.07541415095329285, 0.023259233683347702, -0.05859103426337242, -0.007469333242624998, 0.0554414801299572, -0.011190522462129593, -0.03900524228811264, -0.02089446410536766, 0.05038416385650635, -0.013081695884466171, 0.006424055900424719, -0.01536730956286192, 0.03958093374967575, 0.041788794100284576, -0.00668585067614913, -0.028671376407146454, 0.01010771282017231, -0.00006740244862157851, 0.0016872977139428258, -0.007850254885852337, -0.016173353418707848, 0.0041998703964054585, -0.017133455723524094, 0.037671543657779694, 0.020355861634016037, 0.004114873241633177, -0.014437318779528141, -0.019748089835047722, 0.0329984687268734, 0.015366163104772568, -0.013568580150604248, 0.0359683521091938, -0.0031309674959629774, 0.02987845055758953, 0.011281785555183887, -0.046264998614788055, -0.05071776732802391, 0.0290321484208107, 0.05325315520167351, 0.011315081268548965, 0.0119340680539608, 0.031695879995822906, -0.02957961894571781, -0.02546589821577072, 0.0023339714389294386, -0.022133925929665565, -0.010472516529262066, 0.025474855676293373, 0.005012586712837219, 0.018932059407234192, 0.011185804381966591, -0.0173837598413229, 0.032631441950798035, 0.03221915662288666, -0.035121556371450424, -0.04752449691295624, 0.00006753447814844549, 0.021782781928777695, 0.002841714071109891, -0.0027090830262750387, -0.02090214192867279, 0.003392979269847274, -0.002091054804623127, 0.03797847405076027, -0.0415688119828701, 0.022978713735938072, -0.02830696664750576, -0.03827105090022087, 0.03287482261657715, -0.008121856488287449, 0.011912724003195763, -0.014658341184258461, -0.012291166000068188, 0.01693100482225418, 0.014567054808139801, -0.010763443075120449, -0.04777403548359871, -0.04618993401527405, -0.01659397967159748, -0.02834222838282585, 0.03208562731742859, 0.0065103634260594845, 0.001276087248697877, 0.005024004261940718, -0.0076155886054039, 0.04848237708210945, 0.028712131083011627, 0.027575353160500526, 0.010781068354845047, 0.01174295786768198, -0.013153179548680782, -0.009417411871254444, 0.00879676267504692, -0.013769240118563175, -0.006868292577564716, 0.03273462504148483, 0.006415273528546095, -0.0029557489324361086, -0.021335413679480553, 0.016975324600934982, -0.03494621440768242, -0.002842869609594345, -0.02566995471715927, -0.009151712991297245, -0.05035943537950516, 0.03091946616768837, -0.014721011742949486, 0.023366186767816544, -0.06387770175933838, 0.02317127212882042, -0.009563292376697063, 0.0333171971142292, -0.04798797890543938, -0.04528842493891716, 0.021424125880002975, 0.04720967635512352, -0.004412309266626835, -0.026766236871480942, -0.051618218421936035, 0.017489880323410034, 0.014054212719202042, 0.02736448310315609, 0.02589777484536171, 0.013204379007220268, -0.00039755128091201186, -0.048252929002046585, 0.023183459416031837, 0.018200639635324478, -0.01211966760456562, -0.04372553899884224, 0.009520218707621098, 0.036993689835071564, -0.03928200900554657, -0.00724979629740119, 0.04080729931592941, -0.024756796658039093, -0.018593790009617805, 0.030314303934574127, -0.0001224763400387019, -0.006611603312194347, -0.023519005626440048, -0.03739392012357712, 0.01564023084938526, 0.0147178890183568, -0.015791302546858788, 0.014808285050094128, -0.029661409556865692, 0.005071662832051516, -0.009247100912034512, 0.04272681847214699, -0.013360105454921722, 0.001974033657461405, -0.004419195931404829, 0.015452692285180092, -0.030864769592881203, 0.020632056519389153, -0.014962933957576752, -0.03186541795730591, -0.01726975291967392, 0.04909877851605415, 0.03517548739910126, 0.03963242843747139, -0.031425587832927704, 0.038707371801137924, 0.04482724145054817, 0.008651116862893105, 0.01739398017525673, 0.006230253726243973, 0.05240906774997711, 0.013196400366723537, -0.019850749522447586, -0.004259588662534952 ]
Block Sparse Matrices for Smaller and Faster Language Models
madlag
Sep 10, 2020
pytorch_block_sparse
research, nlp
https://huggingface.co/blog/pytorch_block_sparse
Saving space and time, one zero at a time In previous blog posts we introduced sparse matrices and what they could do to improve neural networks. The basic assumption is that full dense layers are often overkill and can be pruned without a significant loss in precision. In some cases sparse linear layers can even improve precision or/and generalization. The main issue is that currently available code that supports sparse algebra computation is severely lacking efficiency. We are also still waiting for official PyTorch support. That's why we ran out of patience and took some time this summer to address this "lacuna". Today, we are excited to release the extension pytorch_block_sparse. By itself, or even better combined with other methods like distillation and quantization, this library enables networks which are both smaller and faster, something Hugging Face considers crucial to let anybody use neural networks in production at low cost, and to improve the experience for the end user.
[ 0.0587846040725708, -0.028690306469798088, 0.04305073618888855, 0.0256342850625515, 0.00916850846260786, 0.00623107748106122, 0.017135411500930786, -0.0018920234870165586, -0.03637981414794922, -0.04450840875506401, -0.05359296500682831, 0.0032616963144391775, 0.023975854739546776, -0.004087598994374275, -0.025958441197872162, -0.059978172183036804, 0.049585629254579544, -0.00032095404458232224, -0.007082337513566017, 0.04447062313556671, 0.02715306356549263, -0.07154958695173264, 0.12248926609754562, 0.01462922990322113, -0.04480503499507904, -0.04137955605983734, -0.008589542470872402, -0.011642676778137684, -0.016870465129613876, 0.06997966021299362, -0.14233973622322083, -0.010268389247357845, -0.020501919090747833, -0.035063520073890686, 0.046715617179870605, -0.007657278794795275, -0.0644315555691719, 0.0968005433678627, 0.015250364318490028, -0.003819920588284731, -0.01554003544151783, 0.021102299913764, -0.0850309208035469, 0.049559108912944794, -0.06825296580791473, -0.03356758505105972, -0.09718315303325653, 0.08804310858249664, -0.03515668213367462, -0.06603212654590607, -0.07673562318086624, 0.05714871734380722, -0.010992434807121754, 0.005488318856805563, -0.04176563024520874, -0.009367838501930237, 0.007376946974545717, -0.0491442009806633, 0.021893100813031197, -0.008496033027768135, -0.015942834317684174, -0.022718990221619606, 0.0036985184997320175, 0.021907677873969078, -0.008901682682335377, -0.008729595690965652, -0.0030768192373216152, -0.017811963334679604, -0.08495141565799713, 0.04099429398775101, 0.04958999902009964, 0.07454100251197815, -0.058748356997966766, -0.02790680155158043, -0.0017090382752940059, 0.0588955283164978, -0.012879330664873123, -0.01714380644261837, 0.04471093416213989, 0.03432382643222809, 0.013267102651298046, 0.06736455112695694, 0.04042518883943558, 0.08051619678735733, 0.046831268817186356, 0.014708544127643108, -0.03126240149140358, -0.08472906053066254, -0.055949341505765915, 0.08154319226741791, -0.015381610952317715, -0.09958361834287643, 0.05334760248661041, -0.0016959183849394321, 0.013972213491797447, -0.018756624311208725, -0.009757999330759048, 0.015742285177111626, 0.015163625590503216, -0.01933709904551506, -0.007193998899310827, -0.08787069469690323, -0.01138598658144474, -0.04855456203222275, -0.0634443536400795, 0.029996275901794434, 0.004759831819683313, -0.06328394263982773, 0.0074914610013365746, 0.01422153040766716, -0.009256117977201939, 0.048828817903995514, 0.020680049434304237, 0.04051610454916954, -0.05549049377441406, 0.03764998912811279, -0.02220873348414898, 0.014147583395242691, -0.025698944926261902, 0.06527113914489746, -0.030955083668231964, 0.11036700010299683, 0.04035872220993042, 0.00675536971539259, 0.04556645080447197, 0.03083520196378231, 0.004500377457588911, 0.040074944496154785, 0.057826269418001175, -0.009542184881865978, -0.0046767741441726685, 0.007928131148219109, 0.10127680748701096, -0.01263884361833334, 0.030597470700740814, -0.08468148857355118, 0.01261717639863491, -0.008859789930284023, 0.029140448197722435, -0.014898437075316906, -0.036610279232263565, 0.08386772125959396, 0.030900293961167336, 0.015163282863795757, 0.057854022830724716, -0.08349933475255966, -0.03456004336476326, 0.03609119728207588, 0.04090632125735283, -0.03607791289687157, -0.06352859735488892, 0.041803304105997086, -0.053259413689374924, -0.03570688143372536, -0.04141177982091904, 0.05581708252429962, -0.04993990808725357, -0.009947876445949078, -0.02768781967461109, -0.02607354335486889, -0.0421697236597538, -0.08392529934644699, -0.014640772715210915, -0.06167539954185486, 0.07456500083208084, -0.02135402150452137, 0.06517297774553299, 0.025260189548134804, 0.005237361881881952, 0.04731542989611626, 0.015278254635632038, -0.04417385533452034, 0.027480164542794228, -0.0873933732509613, -0.08577702194452286, 0.04678928852081299, 0.04761233925819397, 0.06392692029476166, 0.015535073354840279, -0.018796853721141815, -0.06487665325403214, 0.06264740973711014, 0.007162736728787422, 0.03585837781429291, 0.006099194288253784, -0.06864875555038452, 0.052805401384830475, 0.022144900634884834, 0.00024712359299883246, 0.04388585686683655, -0.051058050245046616, 0.06341030448675156, 0.01207801979035139, -0.052506301552057266, 0.034574057906866074, -0.011841269209980965, -0.09050720930099487, 0.11977499723434448, 0.03840629383921623, 0.030545825138688087, 0.035878736525774, 0.02261815220117569, -0.006423437502235174, -0.016810083761811256, 0.06330154091119766, 0.03380018472671509, -0.004485192243009806, -0.01978931948542595, -0.016011137515306473, -0.027275629341602325, 0.006979105528444052, -0.1251879185438156, 0.03094642050564289, -0.04720620438456535, -0.007232032250612974, 0.0010283776791766286, 0.009819132275879383, 0.006984821055084467, -0.030213424935936928, 0.000293018005322665, 0.15999726951122284, -0.06797733902931213, -0.04196687042713165, 0.037774380296468735, -0.0205011498183012, 0.0649920403957367, 0.09752620756626129, 0.022494245320558548, 0.038150765001773834, -0.034012019634246826, 0.028451932594180107, -0.08538960665464401, -0.05888337641954422, 0.09833215177059174, -0.0028607971034944057, -0.028451265767216682, 0.002045657951384783, -0.026789549738168716, -0.013661222532391548, -0.08329150825738907, -0.022726694121956825, -0.0027105254121124744, 0.054010409861803055, 0.006023919675499201, -0.03616798669099808, -0.02198736183345318, 0.06204259768128395, -0.03999799117445946, -0.0027619036845862865, 0.04395189881324768, -0.04260820150375366, 0.04944070056080818, -0.027806224301457405, 0.017113814130425453, 0.024159055203199387, 0.06001271307468414, 0.0163849089294672, -0.024773485958576202, 0.02213781327009201, 0.046066515147686005, 0.016583876684308052, -0.0011932997731491923, -0.01785639487206936, -0.049969300627708435, -0.01961659826338291, -0.032666392624378204, 0.01171443797647953, -0.03413662314414978, 0.048273149877786636, -0.02189004421234131, 0.06040095537900925, -0.031700510531663895, 0.04383428394794464, 0.004067749250680208, 0.05576860532164574, -0.002513889456167817, -0.007577537093311548, -0.04151211306452751, 0.01137410756200552, -0.05942811071872711, -0.0090993857011199, -0.025340426713228226, 0.04855190962553024, 0.01005795132368803, 0.022970182821154594, 0.010929468087852001, 0.011735006235539913, -0.00323237176053226, -0.011495254933834076, 0.005092227831482887, -0.013317575678229332, 0.03550881892442703, -0.02917175181210041, -0.06038077920675278, -0.008879263885319233, 0.019387830048799515, -0.00176720239687711, 0.01423403900116682, -0.017613697797060013, 0.029988205060362816, -0.011188514530658722, -0.013897869735956192, -0.027297265827655792, 0.01265209261327982, -0.0039665354415774345, 0.024905208498239517, 0.03733939304947853, 0.021619172766804695, -0.09074282646179199, -0.02084791660308838, -0.030682042241096497, 0.005220610182732344, -0.06429129093885422, -0.035282306373119354, 0.0019286024617031217, 0.0032044807448983192, 0.01890132576227188, -0.01295112632215023, 0.026700105518102646, 0.000863104360178113, -0.03631047531962395, 0.01518840529024601, -0.01973589137196541, -0.019643334671854973, -0.0027880873531103134, 0.011747980490326881, 0.044027771800756454, -0.024776821956038475, -0.00991913117468357, 0.05709073320031166, 0.006177362985908985, -0.017131995409727097, 0.01569606550037861, -0.00034924130886793137, 0.0371842160820961, 0.038721129298210144, 0.004560630302876234, -0.022601870819926262, -0.04002600908279419, -0.008904758840799332, 0.005702377296984196, -0.011315345764160156, -0.0424472950398922, -0.009543852880597115, -0.019144868478178978, -0.0387912355363369, 0.051681749522686005, 0.023326272144913673, 0.02143040858209133, 0.01122855581343174, 0.030240783467888832, -0.00241536065004766, 0.009489107877016068, -0.007962399162352085, -0.006378752179443836, -0.015981310978531837, 0.028682680800557137, -0.04067433625459671, -0.017682252451777458, -0.01084231212735176, 0.017059344798326492, 0.04351674020290375, -0.007980688475072384, 0.024394512176513672, -0.0064305211417376995, 0.014823506586253643, 0.0035430851858109236, 0.006730961613357067, -0.04175292328000069, 0.05849263072013855, 0.0021874099038541317, -0.02196030505001545, -0.03683824837207794, 0.052500754594802856, -0.01642557419836521, 0.002581582637503743, 0.00901489146053791, 0.042036376893520355, -0.019632810726761818, -0.013028288260102272, -0.026857897639274597, 0.009094536304473877, -0.022106867283582687, 0.02395188994705677, -0.0005802831146866083, 0.01395705621689558, 0.04992985725402832, 0.04749136045575142, -0.002210264792665839, -0.057723768055438995, 0.02868545427918434, 0.013907444663345814, -0.017454590648412704, 0.005574940703809261, 0.003742978908121586, -0.040651895105838776, 0.019527757540345192, 0.04197147116065025, 0.014870407991111279, -0.04553493857383728, 0.003817872377112508, -0.009169353172183037, -0.02766653522849083, 0.029694993048906326, 0.04358210042119026, 0.012811639346182346, 0.05188896507024765, 0.02364189736545086, 0.04257750138640404, -0.05167044326663017, -0.01704290881752968, -0.06261995434761047, 0.0014681764878332615, 0.004659916274249554, -0.05047718808054924, 0.03337133303284645, 0.0035069368313997984, 0.03586208447813988, -0.025917019695043564, 0.0378754660487175, -0.0031590876169502735, 0.0007274405215866864, 0.06260976195335388, -0.0037806974723935127, -0.040110837668180466, -0.025291860103607178, -0.015448825433850288, 0.026204165071249008, -0.028673572465777397, 0.02447841316461563, 0.021096132695674896, -0.00979312788695097, 0.016581805422902107, -0.01946026086807251, -0.02805611863732338, 0.01443629339337349, 0.008828450925648212, -0.03806059807538986, -0.03647531569004059, 0.01606104150414467, 0.007280054502189159, 0.013109422288835049, 0.011530683375895023, 0.027756858617067337, -0.01650135964155197, 0.04092717543244362, -0.052774738520383835, -0.0547749400138855, -0.01210717111825943, 0.03089849464595318, 0.023282334208488464, -0.03860324248671532, 0.04909973591566086, 0.022753454744815826, -0.02303135395050049, 0.00947474967688322, -0.040739692747592926, 0.043839212507009506, 0.03478943929076195, -0.040811434388160706, -0.033374346792697906, 0.020249634981155396, 0.06392413377761841, -0.04274532198905945, -0.006854844745248556, 0.01608232781291008, 0.039994947612285614, 0.038692496716976166, -0.02210306189954281, -0.0038450811989605427, -0.03242441639304161, 0.02003520168364048, 0.027782084420323372, -0.057553980499506, 0.010614234022796154, -0.02781957946717739, -0.01273744273930788, -0.022922944277524948, -0.043935373425483704, 0.0027369195595383644, -0.02597637288272381, -0.028707092627882957, 0.04620177298784256, 0.01534948032349348, 0.025258470326662064, -0.01205638237297535, -0.0008670869283378124, 0.006510741077363491, 0.0010975749464705586, 0.01611969992518425, 0.07044690102338791, 0.04931290075182915, 0.03682728111743927, 0.053267184644937515, 0.00004211765553918667, 0.06026390939950943, -0.03313290700316429, 0.0022926758974790573, 0.009712030179798603, -0.018360013142228127, 0.043370045721530914, -0.022578442469239235, 0.031017228960990906, 0.013022038154304028, -0.03216082975268364, -0.01010929699987173, -0.016915397718548775, 0.005185780115425587, -0.006635158322751522, 0.013678129762411118, -0.05813567712903023, 0.03173285722732544, 0.040710754692554474, 0.022640714421868324, -0.039922457188367844, -0.010446249507367611, 0.030439915135502815, -0.05101117864251137, 0.02587655559182167, -0.007547194138169289, 0.004498980939388275, -0.044206760823726654, -0.019822711125016212, -0.018829364329576492, -0.047391071915626526, 0.020670663565397263, -0.014495845884084702, 0.005703423637896776, 0.0010758874705061316, -0.02737968973815441, -0.02927933633327484, -0.011930924840271473, 0.0016005089273676276, -0.019136635586619377, -0.0561956912279129, 0.019497552886605263, -0.006791513878852129, 0.0283370278775692, 0.03608413413167, -0.0035144330468028784, 0.010752245783805847, 0.006335630547255278, -0.018136410042643547, -0.0020196433179080486, -0.002999323420226574, 0.04124579206109047, 0.010141902603209019, -0.04831429198384285, -0.018254825845360756, -0.0193718783557415, -0.007997823879122734, 0.006214037071913481, -0.03817451372742653, 0.037969090044498444, 0.05195504054427147, -0.004698367323726416, 0.016023147851228714, 0.0032156547531485558, 0.05931592360138893, -0.010402214713394642, 0.002779314061626792, -0.01012913603335619, 0.03911086916923523, 0.01094803586602211, -0.009739270433783531, -0.01674085110425949, 0.003468848066404462, 0.014186937361955643, 0.02859191782772541, -0.0724717229604721, -0.008548066020011902, 0.0062217446975409985, 0.00022658688249066472, 0.016788329929113388, 0.024167079478502274, -0.05355551093816757, 0.03359965607523918, -0.016440974548459053, 0.003155635902658105, 0.05059082433581352, -0.00942246150225401, 0.04642190411686897, -0.021709317341446877, -0.016805021092295647, 0.012504915706813335, 0.023583989590406418, -0.0075556072406470776, 0.006358507554978132, 0.012045064941048622, 0.013243625871837139, 0.020860128104686737, 0.011709338054060936, -0.0036979373544454575, -0.023445459082722664, 0.026795532554388046, 0.02346879243850708, 0.03674051910638809, 0.044712621718645096, -0.015034722164273262, -0.01080674584954977, 0.027530856430530548, -0.042783088982105255, -0.029575038701295853, 0.0010301077272742987, 0.04028518870472908, -0.0010074274614453316, 0.010648075491189957, -0.05146336555480957, 0.047019749879837036, 0.033944401890039444, 0.011922694742679596, 0.00363346841186285, 0.01931951381266117, 0.0362628772854805, 0.015485640615224838, -0.022166645154356956, 0.01625274494290352, 0.02044379897415638, -0.032559387385845184, 0.04908780753612518, 0.020503994077444077, 0.049817491322755814, -0.0017982502467930317, -0.012245994992554188, 0.0067996736615896225, -0.02601565420627594, 0.03515392169356346, 0.011687135323882103, -0.013495915569365025, 0.017016258090734482, 0.000675140880048275, 0.006684593390673399, -0.01577281765639782, 0.03342944011092186, -0.008546639233827591, 0.04080142080783844, -0.0388159453868866, 0.022959547117352486, -0.012139559723436832, 0.009090838022530079, 0.00449327053502202, -0.000538225460331887, 0.04398277401924133, -0.002476103138178587, 0.07832299917936325, 0.03738187253475189, -0.05657275393605232, -0.06008123233914375, 0.009800012223422527, 0.014017238281667233, 0.01323803048580885, 0.0070183188654482365, -0.030646270141005516, -0.014995532110333443, 0.00503814872354269, 0.02371598407626152, 0.012003626674413681, 0.0011286480585113168, 0.012096641585230827, 0.01269429363310337, -0.05026983097195625, 0.00013305740139912814, -0.005247647874057293, -0.0232562143355608, 0.017549190670251846, -0.023589245975017548, -0.052155282348394394, -0.01580335944890976, -0.0019680075347423553, -0.0028254028875380754, 0.008616571314632893, -0.038019608706235886, -0.0495394766330719, -0.0022196280770003796, -0.021259672939777374, -0.026422416791319847, -0.004070231691002846, -0.0037383281160146, -0.016582999378442764, -0.010791251435875893, -0.041166096925735474, -0.03342524170875549, -0.03586816042661667, 0.019529975950717926, 0.05785465985536575, 0.01934523694217205, -0.009684829972684383, -0.011910660192370415, 0.046360231935977936, 0.01988469436764717, -0.018769901245832443, 0.01543593779206276, 0.01554832886904478, -0.021198544651269913, -0.059004805982112885, 0.0024508340284228325, -0.0006431596120819449, -0.01632210798561573, -0.012783617712557316, -0.0034327134490013123, -0.016274958848953247, -0.0029279158916324377, 0.046350255608558655, 0.0021270394790917635, -0.05010044947266579, 0.01915936917066574, -0.015011647716164589, 0.005769656039774418, -0.04050314798951149, -0.011692502535879612, 0.03271669149398804, 0.06755265593528748, -0.014932218007743359, -0.01941658928990364, -0.02592962048947811, -0.004851086065173149, 0.022104062139987946, 0.03810076415538788, 0.008195786736905575, -0.04301903396844864, -0.0006805931916460395, -0.02564248815178871, -0.030663758516311646, 0.053517475724220276, -0.036385420709848404, -0.037149496376514435, 0.014249788597226143, 0.024551497772336006, -0.031070560216903687, 0.03262241929769516, 0.02869080938398838, -0.027478588744997978, 0.0323374941945076, 0.0003069413942284882, -0.01848587766289711, 0.002932837000116706, 0.015870878472924232, -0.06036432459950447, 0.003045173827558756, -0.027478421106934547, 0.0007700001588091254, 0.05206746980547905, -0.013090517371892929, 0.03485429286956787, -0.0012261258671060205, -0.003146575763821602, 0.007128498051315546, -0.007839599624276161, -0.015904568135738373, -0.007694360334426165, 0.00753035768866539, 0.03268580511212349, -0.0024918692652136087, -0.03225141391158104, 0.004828713368624449, 0.047223981469869614, 0.02994040586054325, -0.00001418731153535191, -0.0029148291796445847, 0.02151361294090748, 0.004099709913134575, 0.02403550036251545, 0.0038925406988710165, 0.031107336282730103, 0.012595940381288528, 0.018877383321523666, -0.026109011843800545, 0.0007067181286402047 ]
Block Sparse Matrices for Smaller and Faster Language Models
madlag
Sep 10, 2020
pytorch_block_sparse
research, nlp
https://huggingface.co/blog/pytorch_block_sparse
Performance At the current stage of the library, the performances for sparse matrices are roughly two times slower than their cuBLAS optimized dense counterpart, and we are confident that we can improve this in the future. This is a huge improvement on PyTorch sparse matrices: their current implementation is an order of magnitude slower than the dense one. But the more important point is that the performance gain of using sparse matrices grows with the sparsity, so a 75% sparse matrix is roughly 2x faster than the dense equivalent. The memory savings are even more significant: for 75% sparsity, memory consumption is reduced by 4x as you would expect.
[ 0.05603835731744766, 0.038520365953445435, 0.0285977553576231, 0.026866722851991653, -0.011210176162421703, -0.04603636637330055, -0.010985740460455418, 0.01282923948019743, -0.04328387603163719, -0.07418747246265411, 0.032737769186496735, 0.031032953411340714, 0.014741957187652588, 0.008859828114509583, 0.0236408282071352, -0.03929424285888672, 0.06487686187028885, -0.01928102597594261, 0.029509849846363068, 0.0317663699388504, 0.007329177111387253, -0.0472550243139267, 0.11508946865797043, -0.006402993109077215, 0.012754198163747787, 0.01631220057606697, -0.024564120918512344, 0.000685203995089978, -0.08746372908353806, -0.007000642362982035, -0.1434076875448227, -0.01595894992351532, 0.011498089879751205, -0.05601612851023674, 0.030681084841489792, -0.003124302951619029, -0.04539395123720169, 0.10039577633142471, 0.06495422124862671, -0.012146607972681522, 0.010935315862298012, 0.007884367369115353, -0.05950687825679779, 0.06660737842321396, -0.0917573869228363, -0.0047822087071835995, -0.09220810234546661, 0.04939733445644379, -0.029991308227181435, -0.07766298204660416, -0.11519250273704529, 0.009729997254908085, 0.0024366946890950203, 0.033155206590890884, -0.006961690727621317, -0.011661388911306858, -0.0006264561670832336, 0.012188076972961426, 0.04598046466708183, 0.011790349148213863, -0.01441086083650589, 0.0083848861977458, -0.011969218030571938, 0.032781656831502914, 0.02236347272992134, -0.0011924460995942354, 0.026823192834854126, 0.04153284430503845, -0.04894799739122391, 0.06059886887669563, 0.032544638961553574, 0.046461232006549835, -0.018551306799054146, 0.017566323280334473, -0.038529861718416214, 0.010588943026959896, 0.005436159670352936, 0.01601635292172432, 0.03492587059736252, 0.02361789345741272, -0.0036673026625066996, 0.05766335874795914, 0.050391536206007004, 0.01589849963784218, 0.02042519487440586, 0.013957660645246506, -0.017976930364966393, -0.054942741990089417, -0.051685746759176254, 0.06689822673797607, 0.0049208831042051315, -0.0671040415763855, 0.05696776509284973, 0.04768679663538933, 0.023140234872698784, -0.01827194169163704, 0.02034933492541313, 0.018205808475613594, -0.022691499441862106, 0.06931917369365692, 0.01008582767099142, -0.03971767798066139, 0.01982715167105198, -0.06382153183221817, -0.022966282442212105, 0.011866176500916481, -0.052026573568582535, -0.09847413748502731, 0.026507021859288216, 0.07225767523050308, -0.04021402820944786, 0.06665103137493134, 0.007562217302620411, -0.006253908853977919, -0.04411807283759117, 0.01595381647348404, 0.03755881264805794, 0.02356385439634323, -0.036951471120119095, 0.10369375348091125, -0.04749608784914017, 0.1540333479642868, 0.02879447117447853, -0.0016227762680500746, 0.037560950964689255, 0.048292964696884155, 0.07423815131187439, 0.051043976098299026, 0.029935069382190704, 0.0005745477392338216, 0.05101100355386734, 0.032281890511512756, 0.07116301357746124, -0.007104144897311926, 0.009589046239852905, -0.09210166335105896, -0.017813561484217644, 0.002901588100939989, -0.02589672990143299, -0.060421306639909744, -0.07880370318889618, 0.035805922001600266, 0.036414895206689835, 0.09202089160680771, 0.06504245102405548, -0.0850229263305664, -0.0041704243049025536, 0.03936447948217392, 0.00027040307759307325, -0.05060109496116638, -0.07169774174690247, 0.06614096462726593, -0.06181449070572853, -0.042812783271074295, -0.022332744672894478, 0.052521657198667526, -0.023452142253518105, -0.04224422201514244, -0.07083645462989807, 0.003189970040693879, -0.021447790786623955, -0.019436044618487358, 0.005907991901040077, -0.08531610667705536, -0.0021964479237794876, -0.006388220936059952, 0.04430560767650604, -0.028519200161099434, 0.031070053577423096, 0.0538550429046154, -0.001224230625666678, -0.01867171749472618, 0.03955313190817833, -0.01822185516357422, -0.07103979587554932, 0.05967345088720322, 0.02783164009451866, 0.059980373829603195, 0.0013511829311028123, -0.05713469907641411, -0.047343358397483826, 0.03339751437306404, -0.05978306755423546, 0.03874829784035683, -0.03959263488650322, -0.08510035276412964, 0.05405242368578911, 0.018163755536079407, 0.031901877373456955, -0.0321674644947052, -0.061730679124593735, 0.00789107196033001, 0.022755030542612076, -0.03639831021428108, 0.09436890482902527, -0.02828729711472988, -0.003614981658756733, 0.10509703308343887, 0.022621192038059235, 0.02200300432741642, 0.027623094618320465, 0.00451522646471858, -0.05086994916200638, 0.004120943136513233, 0.04046567901968956, 0.000648396962787956, -0.000347883120412007, 0.013503200374543667, 0.04951360821723938, -0.019721152260899544, -0.026439324021339417, -0.12433627247810364, 0.006405573338270187, -0.07016129046678543, 0.008707499131560326, 0.005552679765969515, 0.06586066633462906, 0.021490493789315224, -0.026698745787143707, 0.025324225425720215, 0.1671917587518692, -0.025898460298776627, -0.028024161234498024, 0.030514376237988472, -0.034937772899866104, 0.05152567848563194, 0.044979482889175415, -0.026243342086672783, 0.07593384385108948, -0.04078209400177002, 0.00877353549003601, -0.08719746023416519, -0.02312524802982807, 0.1326320767402649, 0.010544970631599426, -0.0303810965269804, -0.02391485497355461, 0.01467188447713852, 0.027272827923297882, -0.04165581241250038, -0.05106111615896225, -0.014055694453418255, 0.046504855155944824, 0.040220677852630615, -0.03485003858804703, -0.03889184072613716, 0.029661288484930992, -0.056189727038145065, 0.011464627459645271, -0.005569860804826021, -0.06750202178955078, -0.031068984419107437, 0.01941065862774849, 0.002102985279634595, 0.04539070650935173, 0.06347031146287918, 0.004350751172751188, -0.08661582320928574, 0.01917283609509468, 0.005035312380641699, 0.035000622272491455, 0.009997081942856312, -0.024524884298443794, -0.017421722412109375, -0.008559828624129295, -0.02060881443321705, -0.014528402127325535, -0.026831353083252907, 0.02283497340977192, -0.031932566314935684, 0.014733798801898956, -0.039109792560338974, 0.039341188967227936, -0.006924986839294434, 0.034794170409440994, -0.023971684277057648, -0.007965515367686749, -0.09042714536190033, -0.012529649771749973, -0.03026469796895981, 0.003592899302020669, -0.008239525370299816, 0.06332015991210938, 0.003163124667480588, 0.0023699651937931776, 0.0005227071233093739, 0.021304821595549583, -0.015057609416544437, -0.052977800369262695, -0.006620793603360653, -0.016020819544792175, 0.001990030985325575, -0.0063961888663470745, -0.04743587225675583, -0.02143479883670807, 0.011451703496277332, -0.02271496318280697, -0.01638886146247387, 0.00028273751377128065, 0.004109987523406744, -0.033187638968229294, 0.015077894553542137, -0.016277406364679337, -0.02073962800204754, -0.048823509365320206, 0.01870793290436268, -0.0003595992166083306, 0.027904128655791283, -0.10175742208957672, -0.0015600224724039435, -0.006876802537590265, 0.003923971205949783, -0.03587519749999046, 0.0003819122794084251, -0.009449592791497707, -0.00112161785364151, 0.03572680801153183, -0.03037826158106327, -0.004437333904206753, 0.013088952749967575, -0.023055508732795715, 0.04258262738585472, -0.013137996196746826, 0.014827052131295204, 0.028794968500733376, 0.044665031135082245, 0.0178398247808218, 0.008977158926427364, 0.012253624387085438, 0.031481388956308365, -0.013397245667874813, -0.0009465569746680558, -0.0494232252240181, 0.013099053874611855, -0.005364883691072464, 0.00835481844842434, -0.0022616626229137182, -0.03485450893640518, -0.025913072749972343, -0.008911913260817528, 0.0003240930673200637, -0.03531702980399132, -0.04308294132351875, -0.008060927502810955, -0.011142591945827007, -0.006405415944755077, 0.020706241950392723, 0.03268083184957504, 0.005331427790224552, 0.03954027220606804, 0.03813378885388374, 0.005259334109723568, 0.018333731219172478, 0.04062904790043831, 0.0036187609657645226, -0.011778868734836578, 0.043347086757421494, -0.035556986927986145, -0.02111639268696308, 0.002017059363424778, 0.005634688306599855, 0.06086394190788269, 0.0019748087506741285, -0.019929692149162292, 0.010679190047085285, 0.03583092987537384, 0.028036097064614296, -0.007071436382830143, -0.009433089755475521, 0.0461655929684639, 0.024558618664741516, 0.0018875092500820756, -0.0446687750518322, 0.0197308249771595, 0.01243178453296423, 0.012229986488819122, -0.0011386398691684008, -0.008860493078827858, -0.04564232751727104, -0.02235882543027401, -0.011506264097988605, 0.020720601081848145, -0.014728142879903316, 0.027991540729999542, 0.00696594500914216, 0.015562334097921848, 0.047661300748586655, 0.0319066047668457, -0.017477933317422867, -0.04448823258280754, 0.005505948793143034, -0.012866574339568615, -0.028857601806521416, 0.019931362941861153, 0.008702298626303673, 0.006234955042600632, 0.0158745888620615, 0.00450778566300869, 0.0062715704552829266, -0.050806473940610886, 0.014760160818696022, 0.005216817371547222, 0.0098070427775383, 0.004216903820633888, 0.05170600488781929, 0.013349217362701893, 0.027882270514965057, 0.04041193798184395, 0.06779546290636063, -0.001005089608952403, -0.00478002056479454, -0.010085991583764553, -0.00482915248721838, 0.008342400193214417, -0.03915867954492569, 0.0169456135481596, 0.01792176067829132, 0.01842108555138111, 0.022723982110619545, -0.007059586700052023, 0.013562968000769615, -0.02108016237616539, 0.0354190319776535, 0.004525478463619947, -0.012251594103872776, -0.01866043172776699, -0.03130921721458435, 0.06149575114250183, -0.07076548784971237, 0.03607355058193207, -0.009780620224773884, 0.0014649488730356097, -0.007894954644143581, -0.0042289975099265575, -0.011748328804969788, 0.012352289631962776, 0.005484619177877903, -0.050639376044273376, -0.0272672101855278, 0.001951695652678609, 0.006103726103901863, -0.004424368496984243, 0.0021916688419878483, 0.0012250153813511133, -0.00888330489397049, 0.026639299467206, -0.014367327094078064, -0.05758483335375786, -0.021259887143969536, 0.0015192452119663358, 0.008988790214061737, -0.029955675825476646, 0.07465986907482147, 0.016364479437470436, -0.06002582609653473, 0.008924733847379684, -0.06922326236963272, 0.04806290194392204, 0.05759534612298012, -0.03995463252067566, -0.0053163249976933, 0.009118868969380856, 0.0191266480833292, -0.04042491689324379, 0.004633412696421146, 0.00986296683549881, 0.0369250625371933, 0.018527580425143242, -0.02292570099234581, 0.01838378794491291, -0.03238380700349808, -0.0009021190344356, 0.012920155189931393, -0.03334027901291847, 0.029133964329957962, -0.03165419027209282, 0.021054094657301903, -0.0110001340508461, 0.02651466801762581, 0.01181249599903822, -0.02088266611099243, -0.031186701729893684, 0.06529403477907181, -0.016384828835725784, -0.01600985787808895, -0.030452579259872437, 0.03344206511974335, 0.011593722738325596, -0.020525751635432243, 0.0002627326175570488, 0.0374196395277977, -0.0028264711145311594, 0.01683523692190647, 0.019913578405976295, -0.020974546670913696, 0.0515604205429554, -0.010679371654987335, 0.007353144697844982, 0.018239151686429977, -0.009114325046539307, 0.05001939460635185, -0.06519806385040283, 0.05322609096765518, -0.03863964229822159, -0.002110671019181609, -0.014190491288900375, -0.022255253046751022, 0.042631227523088455, 0.0032413408625870943, -0.003220426384359598, -0.029779501259326935, 0.006753191351890564, 0.016368193551898003, 0.026866652071475983, 0.007281928323209286, -0.02901737578213215, 0.00392521545290947, -0.052638161927461624, 0.03517650440335274, -0.014238685369491577, -0.03849860280752182, -0.035373613238334656, 0.01588556356728077, -0.014057248830795288, -0.07013265788555145, 0.015475115738809109, -0.015841543674468994, 0.028191816061735153, 0.00423031160607934, -0.03954044729471207, -0.03979877382516861, -0.022938156500458717, -0.01090421061962843, 0.024410346522927284, -0.02010159380733967, 0.014782829210162163, -0.024262860417366028, 0.054388582706451416, 0.041454069316387177, -0.040264926850795746, 0.02045055478811264, -0.01926785707473755, 0.005364546552300453, 0.01183410082012415, 0.0067848023027181625, 0.037149012088775635, 0.0036314374301582575, -0.002451260108500719, -0.045692041516304016, -0.028671052306890488, -0.03559280186891556, 0.02630261518061161, -0.06082828715443611, 0.019036803394556046, 0.0671037882566452, -0.027162009850144386, -0.014248307794332504, 0.0050687906332314014, 0.037289299070835114, -0.013294185511767864, 0.01425199955701828, -0.028050268068909645, 0.027979718521237373, 0.043554190546274185, -0.014998700469732285, -0.04213565215468407, 0.00878160446882248, 0.02061999775469303, 0.05051656812429428, -0.034806933254003525, 0.019909383729100227, 0.04464198276400566, -0.033580511808395386, 0.009190966375172138, 0.04290799796581268, -0.06174858659505844, 0.022181842476129532, -0.01853913813829422, -0.0021826059091836214, 0.049871351569890976, -0.012427768670022488, 0.036935146898031235, -0.010968423448503017, -0.03895978629589081, -0.028551984578371048, 0.04110037907958031, -0.021855460479855537, 0.052084844559431076, 0.0019821731839329004, 0.036417264491319656, 0.004017791710793972, 0.01325681246817112, -0.02555100806057453, 0.007640983443707228, 0.01350346114486456, -0.010556950233876705, 0.040458355098962784, 0.04359383508563042, -0.027416670694947243, 0.00048726802924647927, 0.004160476382821798, -0.01602587103843689, -0.03379618003964424, 0.016596492379903793, 0.022098207846283913, 0.021222533658146858, 0.016399996355175972, -0.07200415432453156, -0.004726909101009369, 0.0254512932151556, 0.025684596970677376, -0.031191544607281685, 0.01965213567018509, 0.005870553199201822, 0.029037121683359146, -0.008923486806452274, -0.012657327577471733, 0.001621793257072568, -0.011734198778867722, 0.05291455239057541, 0.04059794545173645, 0.037961445748806, -0.0012952475808560848, -0.03271130472421646, 0.003619176335632801, 0.011102798394858837, 0.005962224677205086, 0.03628377243876457, -0.011525198817253113, -0.006842153612524271, 0.03170965611934662, -0.012858254835009575, -0.023624055087566376, 0.028454424813389778, 0.01611003279685974, -0.007612047716975212, -0.010091761127114296, -0.00101226638071239, -0.01810433343052864, 0.027989771217107773, -0.018831562250852585, -0.0013125871773809195, -0.0028367345221340656, 0.024161148816347122, 0.03900323808193207, 0.03755774348974228, -0.032019034028053284, -0.019380168989300728, 0.03727768361568451, 0.017848141491413116, -0.02422763966023922, 0.002218658570200205, -0.06312468647956848, 0.01643151044845581, 0.016484538093209267, 0.014043502509593964, -0.018864331766963005, 0.018965691328048706, -0.008530237711966038, 0.009864365682005882, -0.07550796121358871, 0.0321115143597126, -0.03318777307868004, -0.007678457535803318, 0.019639570266008377, 0.008731584995985031, -0.016177887097001076, -0.023658668622374535, 0.0403224341571331, 0.027656493708491325, -0.015000489540398121, -0.014411075972020626, -0.0460386648774147, -0.005841976497322321, -0.04450013488531113, 0.0010730784852057695, -0.010265965946018696, 0.031351808458566666, -0.0010834361892193556, 0.017744358628988266, -0.06560220569372177, 0.00508430041372776, -0.018922703340649605, 0.012839714996516705, 0.045507561415433884, -0.0053337146528065205, 0.0009462290327064693, -0.025595350190997124, 0.050456829369068146, -0.01186579093337059, -0.011869854293763638, 0.049339935183525085, 0.008702617138624191, -0.019639072939753532, -0.05280245468020439, 0.01898631639778614, 0.018009886145591736, -0.014264620840549469, 0.019788028672337532, -0.03329559415578842, -0.02281826175749302, -0.024643246084451675, 0.015641208738088608, 0.009201412089169025, -0.04715866222977638, 0.03451235592365265, 0.0008213877445086837, 0.015081056393682957, -0.06263324618339539, -0.017608631402254105, 0.046207696199417114, 0.0818188264966011, -0.014512689784169197, -0.005336319096386433, -0.03849447891116142, -0.014214265160262585, -0.002961269346997142, 0.0035932075697928667, 0.008273168466985226, -0.006647242698818445, -0.024503203108906746, -0.03842005133628845, 0.004083619453012943, 0.020709142088890076, -0.006513363681733608, -0.014876595698297024, 0.009136791341006756, 0.010402821004390717, 0.002914677606895566, -0.010678581893444061, 0.015589817427098751, -0.00430265674367547, 0.055985745042562485, 0.009887994267046452, 0.0032016397453844547, 0.00922163762152195, -0.00012691476149484515, -0.03621905669569969, -0.020026884973049164, -0.010238010436296463, 0.0031070190016180277, 0.057561032474040985, -0.002079133875668049, 0.03167461231350899, -0.016969623044133186, -0.003974570892751217, 0.003649509744718671, 0.00039297048351727426, -0.00970893632620573, -0.07418495416641235, -0.02302367426455021, 0.027488654479384422, -0.00037403826718218625, -0.06803625077009201, 0.011181573383510113, 0.0018966239877045155, 0.027663391083478928, 0.02213088609278202, 0.025276867672801018, -0.008181320503354073, 0.0317995548248291, 0.020787551999092102, -0.00984139833599329, 0.03540228679776192, 0.0022925869561731815, 0.02461341582238674, -0.0003787707246374339, -0.006227412726730108 ]
Block Sparse Matrices for Smaller and Faster Language Models
madlag
Sep 10, 2020
pytorch_block_sparse
research, nlp
https://huggingface.co/blog/pytorch_block_sparse
Future work Being able to efficiently train block-sparse linear layers was just the first step. The sparsity pattern is currenly fixed at initialization, and of course optimizing it during learning will yield large improvements. So in future versions, you can expect tools to measure the "usefulness" of parameters to be able to optimize the sparsity pattern. NVIDIA Ampere 50% sparse pattern within blocks will probably yield another significant performance gain, just as upgrading to more recent versions of CUTLASS does. So, stay tuned for more sparsity goodness in a near future!
[ 0.05828782543540001, -0.059852905571460724, 0.02830982580780983, 0.07345510274171829, 0.03394237533211708, -0.0026873936876654625, -0.02886098250746727, 0.026262551546096802, -0.09130092710256577, -0.09766731411218643, -0.018021531403064728, 0.06315033882856369, 0.03206024318933487, 0.00661757355555892, 0.027671797201037407, -0.019437899813055992, 0.035209186375141144, -0.03725650534033775, -0.0306452177464962, 0.06340529024600983, -0.0096818208694458, -0.0600736178457737, 0.14815190434455872, 0.005211178679019213, 0.014784885570406914, -0.030957210808992386, -0.007533425465226173, 0.02565721608698368, -0.049747273325920105, 0.028414050117135048, -0.0695343017578125, 0.040695738047361374, -0.05598372220993042, -0.07523197680711746, -0.052970029413700104, -0.00933102797716856, -0.05625470355153084, 0.002801926340907812, 0.04306997358798981, -0.017070239409804344, -0.008724996820092201, -0.030177751556038857, -0.027791785076260567, 0.05655520781874657, -0.05190553516149521, -0.004876572638750076, -0.09806600213050842, 0.03065849281847477, -0.014596698805689812, -0.05314560607075691, -0.06457522511482239, 0.0707089826464653, -0.006868582218885422, 0.016176346689462662, 0.008045482449233532, -0.05426901578903198, 0.023400716483592987, 0.01931125484406948, 0.027212893590331078, -0.04725347086787224, 0.023330621421337128, 0.01842120662331581, -0.03568850830197334, -0.009619375690817833, 0.011376348324120045, -0.008057383820414543, 0.0245254784822464, 0.03320090472698212, -0.07001768797636032, 0.0034010575618594885, 0.06909748911857605, -0.025230098515748978, 0.029423056170344353, -0.0008154794340953231, -0.05061440169811249, 0.04247499629855156, 0.012880231253802776, 0.03960197791457176, 0.04714730381965637, 0.044105011969804764, 0.018913548439741135, 0.05225927755236626, 0.02245432883501053, 0.05269995704293251, -0.01447433140128851, -0.019397126510739326, -0.0026334519498050213, -0.058231763541698456, -0.07419712841510773, 0.06864655762910843, 0.002444943878799677, -0.09708864241838455, 0.0682249367237091, 0.027114862576127052, 0.030457304790616035, -0.015436958521604538, -0.006491555832326412, 0.0014659195439890027, -0.0087652038782835, 0.017910612747073174, -0.01962805725634098, -0.06596489250659943, 0.01066576223820448, -0.027515310794115067, -0.05686153098940849, 0.009717288427054882, -0.04997233673930168, -0.09475622326135635, -0.013931399211287498, 0.05739797651767731, 0.001835160655900836, 0.01685420051217079, 0.04909256100654602, 0.017893852666020393, -0.08334209769964218, 0.009499575011432171, -0.003605418372899294, 0.02864709310233593, -0.029867608100175858, 0.050055745989084244, -0.038525402545928955, 0.11819762736558914, 0.04948732256889343, -0.0008072616765275598, -0.008864893577992916, 0.027578718960285187, 0.048506464809179306, 0.07030706852674484, 0.0453130304813385, -0.03334059938788414, 0.013914634473621845, 0.03599704056978226, -0.008442784659564495, 0.03531209006905556, 0.004001098219305277, -0.09118971973657608, -0.013038655743002892, 0.006851315498352051, -0.027905981987714767, -0.048237577080726624, -0.12457209825515747, 0.01218409463763237, 0.028696367517113686, 0.014178660698235035, 0.07548188418149948, -0.07107662409543991, 0.017573587596416473, 0.02082287147641182, 0.049703940749168396, 0.006432196591049433, -0.00001376407908537658, 0.030718831345438957, -0.0669826865196228, -0.06934450566768646, 0.03076433204114437, -0.011630184017121792, -0.03005209006369114, -0.013449017889797688, -0.07271285355091095, -0.009322591125965118, -0.03274296596646309, -0.05164347589015961, 0.014454254880547523, 0.002576692495495081, 0.05421704053878784, -0.02907412312924862, 0.08910387754440308, -0.03838413208723068, 0.022287314757704735, 0.030994674190878868, -0.021174170076847076, 0.01652643270790577, 0.010405349545180798, -0.044784072786569595, -0.08664289861917496, 0.014807475730776787, 0.016518978402018547, 0.12329985946416855, 0.017569266259670258, -0.03241189941763878, -0.04407375305891037, 0.009093108586966991, -0.024722835049033165, 0.07395830005407333, -0.015083997510373592, -0.08702035248279572, 0.033072348684072495, 0.003890788881108165, -0.03351764380931854, 0.002570173004642129, -0.04979889839887619, 0.05192237347364426, 0.04962819814682007, -0.029008757323026657, 0.05372793972492218, -0.06320468336343765, -0.05864708125591278, 0.09499988704919815, 0.03425000607967377, 0.08090133965015411, 0.09177868068218231, 0.004181270021945238, -0.040361400693655014, -0.014672703109681606, -0.0003056857967749238, -0.006766920909285545, 0.008996226824820042, 0.05649469047784805, 0.060049086809158325, -0.016815435141324997, -0.04276230186223984, -0.10117443650960922, -0.00420505553483963, 0.0005800631479360163, -0.0042593954131007195, 0.013739721849560738, 0.028631458058953285, 0.007211126387119293, -0.04479270428419113, -0.027132995426654816, 0.13263222575187683, 0.01948998123407364, -0.048173800110816956, 0.04403838887810707, -0.08494003117084503, 0.008973796851933002, 0.08122207969427109, 0.009686186909675598, 0.04224485903978348, -0.06776217371225357, 0.03394464775919914, -0.056062981486320496, -0.04406779259443283, 0.16221670806407928, -0.012853412888944149, 0.007287308573722839, 0.019017955288290977, -0.020242473110556602, 0.09510574489831924, -0.05394725129008293, -0.035431016236543655, -0.01203335914760828, 0.023939035832881927, 0.0003933260159101337, -0.0009069641819223762, -0.04300989583134651, 0.08963831514120102, -0.028924981132149696, -0.011546616442501545, -0.0010543428361415863, -0.028079938143491745, 0.05281667038798332, -0.026893682777881622, -0.031157543882727623, 0.034564998000860214, -0.004387758672237396, 0.005603729747235775, -0.04606075957417488, 0.010927402414381504, 0.0038236347027122974, 0.021451028063893318, -0.0036088968627154827, -0.04961594194173813, -0.008373312652111053, 0.010729510337114334, -0.01465122401714325, 0.02544158510863781, -0.04873869568109512, 0.02415747568011284, -0.007699511479586363, 0.017192013561725616, -0.02336898259818554, 0.018839465454220772, -0.03115105628967285, -0.0030417582020163536, -0.023383384570479393, -0.024178193882107735, -0.09415555000305176, 0.017283838242292404, -0.04507104679942131, 0.00327245588414371, -0.02213248983025551, 0.027629034593701363, 0.012129598297178745, -0.007488455157727003, 0.020517975091934204, 0.011027650907635689, -0.00571512570604682, -0.018919775262475014, -0.007951292209327221, -0.020027436316013336, 0.011048770509660244, -0.003290677908807993, -0.020307179540395737, -0.0009050266235135496, 0.03487975895404816, -0.02199726365506649, -0.029509248211979866, -0.004187397193163633, -0.001849820837378502, -0.012090761214494705, 0.04184466600418091, 0.014280738309025764, -0.011365608312189579, -0.031362757086753845, 0.023002468049526215, 0.0032106225844472647, 0.06198753044009209, -0.09863332659006119, -0.03828522935509682, 0.015113676898181438, 0.02884361334145069, -0.06666716933250427, -0.03480274975299835, 0.010250426828861237, 0.01539426390081644, 0.06720654666423798, -0.02238127402961254, 0.02485385537147522, 0.03557422384619713, -0.04164045676589012, 0.0321686826646328, -0.03169774264097214, 0.0004215109220240265, 0.02642061375081539, 0.0003610990534070879, 0.004201195668429136, -0.023026589304208755, -0.02016470953822136, 0.039076413959264755, 0.0126764802262187, 0.019126582890748978, -0.010009978897869587, 0.008535707369446754, 0.03360934928059578, 0.03691541776061058, 0.017371345311403275, -0.04060285910964012, -0.031255725771188736, 0.020638147369027138, -0.013982649892568588, 0.01567443646490574, -0.007250867318361998, -0.00574121531099081, -0.004350009374320507, -0.027527710422873497, 0.05590075999498367, 0.02606671117246151, -0.004696382209658623, -0.007181946188211441, 0.04095252975821495, -0.011826244182884693, 0.05078591778874397, 0.004893093835562468, 0.02178412489593029, 0.019021768122911453, 0.050209615379571915, -0.03511704504489899, -0.04406219720840454, -0.029903527349233627, -0.005611602682620287, 0.05770110711455345, -0.03320347145199776, -0.0020377824548631907, 0.02410290576517582, 0.033136531710624695, 0.008807525970041752, -0.02966914512217045, -0.02398514561355114, 0.019619038328528404, 0.007226632442325354, 0.042597852647304535, -0.022174600511789322, 0.04496873915195465, 0.0033914141822606325, 0.030266473069787025, -0.015573016367852688, 0.010679295286536217, -0.012940675020217896, 0.02623961865901947, -0.010666093789041042, 0.00017290405230596662, -0.01914725825190544, 0.020280133932828903, 0.011489556171000004, 0.018745195120573044, 0.041830938309431076, 0.030947962775826454, 0.017427412793040276, -0.02439884841442108, 0.015164241194725037, -0.026688704267144203, -0.015006772242486477, 0.021795019507408142, 0.03144330158829689, -0.009271880611777306, 0.02672511152923107, 0.025820566341280937, 0.029779203236103058, -0.059096526354551315, 0.005268226843327284, -0.045016542077064514, 0.02320932224392891, 0.016307901591062546, 0.01805521361529827, 0.0014350938145071268, 0.023730631917715073, -0.0034671335015445948, 0.05309807509183884, -0.04682575538754463, 0.045694414526224136, -0.010553832165896893, -0.00403056712821126, 0.02360011264681816, -0.005172202829271555, -0.012342819944024086, 0.008356762118637562, -0.00412027956917882, 0.0009776130318641663, -0.01687541976571083, -0.008305606432259083, 0.0008487835293635726, 0.052797041833400726, 0.011310789734125137, -0.05672341212630272, 0.04606442525982857, -0.023219991475343704, 0.012817233800888062, -0.038413144648075104, 0.008053258992731571, -0.006405199877917767, -0.012891837395727634, 0.03869025781750679, -0.02182285115122795, -0.0074800411239266396, 0.015697427093982697, 0.01720120944082737, -0.010267529636621475, -0.041975222527980804, -0.0347764790058136, 0.001222925609908998, 0.026494236662983894, -0.005031968466937542, 0.004382836166769266, -0.026936346665024757, 0.025959137827157974, 0.021289411932229996, -0.049099400639534, -0.001413067919202149, 0.024312051013112068, 0.01787819340825081, -0.02936016209423542, 0.12354768067598343, 0.020871983841061592, -0.024349920451641083, 0.002085501793771982, -0.013801408931612968, 0.05035139247775078, -0.009499849751591682, -0.058076370507478714, -0.03765273466706276, 0.01607544906437397, 0.015286790207028389, -0.03400028869509697, 0.0003003540332429111, -0.003054022789001465, 0.020264048129320145, 0.027857676148414612, -0.013581453822553158, 0.002769435988739133, -0.04995802789926529, -0.01115313172340393, -0.0030416662339121103, -0.043337494134902954, 0.022943133488297462, -0.02343720570206642, 0.0001656646782066673, -0.014103827066719532, 0.0017510619945824146, -0.028565099462866783, 0.02616809867322445, -0.04903683811426163, 0.05105157196521759, -0.013518941588699818, -0.016109896823763847, 0.00012896338012069464, 0.05456490442156792, -0.011885830201208591, -0.015899881720542908, 0.0002859843662008643, 0.04820174723863602, 0.010797572322189808, -0.0003412362129893154, 0.03315427154302597, -0.004737718962132931, 0.08527489006519318, -0.012234778143465519, 0.01797395758330822, 0.06751692295074463, -0.002549896016716957, 0.02468045987188816, -0.05655413493514061, 0.01320984959602356, 0.014373448677361012, 0.008141594007611275, -0.01693604327738285, -0.03336590528488159, 0.017489396035671234, -0.02579359896481037, 0.019059032201766968, -0.016570737585425377, 0.021451881155371666, -0.01355839241296053, 0.06455887854099274, 0.011394031345844269, -0.007935036905109882, -0.0283917635679245, -0.0402127243578434, -0.01440772507339716, -0.004377311561256647, -0.000654081639368087, -0.03806320205330849, 0.003539371769875288, -0.014305264689028263, -0.014527210965752602, 0.014609797857701778, 0.025557784363627434, -0.006383594591170549, -0.01544843427836895, 0.004033403936773539, -0.052533917129039764, -0.01670086570084095, -0.005480151157826185, 0.02266688272356987, -0.016485735774040222, 0.010595984756946564, -0.003333509899675846, 0.05318281427025795, 0.04065650328993797, -0.03343944251537323, -0.000814324535895139, 0.008367374539375305, 0.01770213432610035, 0.008171666413545609, -0.01319716963917017, 0.04400317370891571, 0.0007920627249404788, -0.03677574545145035, -0.0009528457885608077, -0.03045901469886303, -0.016011875122785568, 0.016723746433854103, -0.04846698045730591, 0.04409540817141533, 0.04586104676127434, -0.038905009627342224, -0.020123956725001335, 0.026869170367717743, 0.06999003142118454, -0.00186687964014709, 0.0057517453096807, 0.011743694543838501, 0.006049315445125103, -0.01281596627086401, -0.005841830279678106, -0.012521266005933285, -0.02047708071768284, 0.0007714293315075338, 0.0319233164191246, -0.04729527607560158, 0.033744145184755325, 0.017357908189296722, -0.034080106765031815, 0.025800250470638275, -0.016234425827860832, -0.04618532955646515, 0.03531437739729881, -0.006011148449033499, -0.014677125960588455, 0.02766362577676773, 0.02842189185321331, 0.0320318341255188, -0.05557478964328766, -0.06377460062503815, -0.03461335971951485, 0.03446825593709946, 0.0022959543857723475, 0.0060073076747357845, -0.03539923578500748, 0.05783643573522568, 0.01765962690114975, 0.024341290816664696, -0.019651269540190697, -0.0051460107788443565, 0.00948823057115078, 0.020764099434018135, 0.05239098146557808, 0.007512047421187162, -0.003544387174770236, -0.014461434446275234, 0.026826826855540276, -0.04130040854215622, -0.02854379452764988, -0.012536630034446716, -0.019947605207562447, -0.02392592839896679, 0.02276017889380455, -0.04133714362978935, -0.02221202664077282, 0.06485350430011749, -0.011727472767233849, -0.03588933125138283, 0.028403157368302345, 0.045778632164001465, 0.021208155900239944, -0.02252320386469364, 0.031047428026795387, -0.013925652951002121, -0.046331387013196945, 0.045245666056871414, 0.003019615076482296, 0.04440157860517502, 0.010193396359682083, -0.025496119633316994, 0.06445048749446869, 0.0012447648914530873, -0.0008616425911895931, 0.03444293886423111, -0.02257571741938591, 0.008800369687378407, 0.04281600937247276, 0.016611339524388313, -0.03896551951766014, 0.005830379202961922, 0.0114195067435503, 0.0027634233701974154, -0.00894180592149496, 0.020170655101537704, -0.008470071479678154, 0.0009981285547837615, -0.03448835760354996, 0.012941780500113964, -0.012999395839869976, -0.001138355117291212, 0.05073876306414604, 0.01836574263870716, 0.018632346764206886, -0.06323767453432083, 0.04330464079976082, 0.007252658251672983, 0.020971408113837242, 0.02628825046122074, -0.002920325379818678, -0.0037551401183009148, -0.006277419626712799, -0.004307824186980724, -0.010380275547504425, 0.0036530657671391964, -0.0054112630896270275, -0.040486957877874374, -0.054269902408123016, 0.023119432851672173, -0.028372008353471756, -0.021590135991573334, 0.00436912477016449, -0.014140128158032894, -0.0023406848777085543, -0.04416054114699364, -0.007981695234775543, 0.021080585196614265, 0.01733483374118805, -0.025749962776899338, -0.015237451530992985, -0.048732709139585495, -0.038842953741550446, 0.011940117925405502, -0.02904980257153511, 0.02143087051808834, -0.0278178658336401, -0.010862024500966072, 0.01868537813425064, 0.002149811713024974, -0.013828535564243793, 0.06652557849884033, -0.00024320551892742515, -0.003693879581987858, -0.021499767899513245, -0.011418432928621769, 0.06330537796020508, 0.0029566569719463587, 0.009664184413850307, 0.02464594878256321, 0.03430696576833725, 0.002106815343722701, -0.045546505600214005, 0.024437708780169487, 0.020968299359083176, 0.015173171646893024, -0.010145055130124092, -0.024564679712057114, -0.03684017062187195, 0.0031811497174203396, -0.014637477695941925, -0.03227287530899048, -0.02420674078166485, 0.0320359542965889, -0.009209358133375645, 0.02234431356191635, -0.05816993489861488, -0.011951941065490246, 0.03153884410858154, 0.03715295344591141, 0.003735405160114169, 0.011634658090770245, -0.06370827555656433, -0.027924634516239166, 0.027920154854655266, 0.05374351888895035, 0.026574058458209038, 0.02572661265730858, -0.0025778026320040226, -0.05053064227104187, 0.0017475899076089263, -0.004837318789213896, -0.035639889538288116, -0.023502878844738007, 0.037093475461006165, 0.003197151469066739, -0.026574810966849327, -0.020418301224708557, 0.010603638365864754, 0.005439318250864744, 0.02736152522265911, 0.02175683155655861, -0.014520561322569847, -0.005382020957767963, 0.028545841574668884, -0.01941753551363945, -0.009860754944384098, -0.0071304780431091785, 0.03181269019842148, 0.06238348409533501, 0.009911001659929752, 0.004033755976706743, -0.00035228204797022045, -0.015440670773386955, -0.01111291628330946, 0.007855341769754887, -0.007754836697131395, -0.03374158963561058, 0.010551780462265015, 0.01523671392351389, 0.005104498937726021, -0.04789220914244652, -0.01589387282729149, 0.053044408559799194, 0.03307650610804558, 0.011856471188366413, -0.008176859468221664, 0.025239180773496628, 0.05412201210856438, 0.011947537772357464, -0.02450508065521717, 0.03152842819690704, 0.04452802613377571, 0.027027292177081108, -0.0037759176921099424, -0.011159052141010761 ]
Transformer-based Encoder-Decoder Models
patrickvonplaten
October 10, 2020
encoder-decoder
research, nlp
https://huggingface.co/blog/encoder-decoder
Decoder As mentioned in the Encoder-Decoder section, the transformer-based decoder defines the conditional probability distribution of a target sequence given the contextualized encoding sequence: $$ p_{\theta_{dec}}(\mathbf{Y}{1: m} | \mathbf{\overline{X}}{1:n}), $$ which by Bayes\' rule can be decomposed into a product of conditional distributions of the next target vector given the contextualized encoding sequence and all previous target vectors: $$ p_{\theta_{dec}}(\mathbf{Y}{1:m} | \mathbf{\overline{X}}{1:n}) = \prod_{i=1}^{m} p_{\theta_{dec}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{\overline{X}}_{1:n}). $$ Let\'s first understand how the transformer-based decoder defines a probability distribution. The transformer-based decoder is a stack of decoder blocks followed by a dense layer, the \"LM head\". The stack of decoder blocks maps the contextualized encoding sequence \(\mathbf{\overline{X}}_{1:n}\) and a target vector sequence prepended by the \(\text{BOS}\) vector and cut to the last target vector, i.e. \(\mathbf{Y}{0:i-1}\), to an encoded sequence of target vectors \(\mathbf{\overline{Y}}{0: i-1}\). Then, the \"LM head\" maps the encoded sequence of target vectors \(\mathbf{\overline{Y}}{0: i-1}\) to a sequence of logit vectors \(\mathbf{L}{1:n} = \mathbf{l}1, \ldots, \mathbf{l}_n\), whereas the dimensionality of each logit vector \(\mathbf{l}_i\) corresponds to the size of the vocabulary. This way, for each \(i \in {1, \ldots, n}\) a probability distribution over the whole vocabulary can be obtained by applying a softmax operation on \(\mathbf{l}_i\). These distributions define the conditional distribution: $$p{\theta_{dec}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{\overline{X}}_{1:n}), \forall i \in {1, \ldots, n},$$ respectively. The \"LM head\" is often tied to the transpose of the word embedding matrix, i.e. \(\mathbf{W}{\text{emb}}^{\intercal} = \left[\mathbf{y}^1, \ldots, \mathbf{y}^{\text{vocab}}\right]^{\intercal}\) \({}^1\). Intuitively this means that for all \(i \in {0, \ldots, n - 1}\) the \"LM Head\" layer compares the encoded output vector \(\mathbf{\overline{y}}_i\) to all word embeddings in the vocabulary \(\mathbf{y}^1, \ldots, \mathbf{y}^{\text{vocab}}\) so that the logit vector \(\mathbf{l}{i+1}\) represents the similarity scores between the encoded output vector and each word embedding. The softmax operation simply transformers the similarity scores to a probability distribution. For each \(i \in {1, \ldots, n}\), the following equations hold: $$ p_{\theta_{dec}}(\mathbf{y} | \mathbf{\overline{X}}{1:n}, \mathbf{Y}{0:i-1})$$ $$ = \text{Softmax}(f_{\theta_{\text{dec}}}(\mathbf{\overline{X}}{1:n}, \mathbf{Y}{0:i-1}))$$ $$ = \text{Softmax}(\mathbf{W}{\text{emb}}^{\intercal} \mathbf{\overline{y}}{i-1})$$ $$ = \text{Softmax}(\mathbf{l}i). $$ Putting it all together, in order to model the conditional distribution of a target vector sequence \(\mathbf{Y}{1: m}\), the target vectors \(\mathbf{Y}_{1:m-1}\) prepended by the special \(\text{BOS}\) vector, i.e. \(\mathbf{y}0\), are first mapped together with the contextualized encoding sequence \(\mathbf{\overline{X}}{1:n}\) to the logit vector sequence \(\mathbf{L}{1:m}\). Consequently, each logit target vector \(\mathbf{l}_i\) is transformed into a conditional probability distribution of the target vector \(\mathbf{y}_i\) using the softmax operation. Finally, the conditional probabilities of all target vectors \(\mathbf{y}_1, \ldots, \mathbf{y}_m\) multiplied together to yield the conditional probability of the complete target vector sequence: $$ p{\theta_{dec}}(\mathbf{Y}{1:m} | \mathbf{\overline{X}}{1:n}) = \prod_{i=1}^{m} p_{\theta_{dec}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{\overline{X}}_{1:n}).$$ In contrast to transformer-based encoders, in transformer-based decoders, the encoded output vector \(\mathbf{\overline{y}}_i\) should be a good representation of the next target vector \(\mathbf{y}{i+1}\) and not of the input vector itself. Additionally, the encoded output vector \(\mathbf{\overline{y}}_i\) should be conditioned on all contextualized encoding sequence \(\mathbf{\overline{X}}{1:n}\). To meet these requirements each decoder block consists of a uni-directional self-attention layer, followed by a cross-attention layer and two feed-forward layers \({}^2\). The uni-directional self-attention layer puts each of its input vectors \(\mathbf{y'}j\) only into relation with all previous input vectors \(\mathbf{y'}_i, \text{ with } i \le j\) for all \(j \in {1, \ldots, n}\) to model the probability distribution of the next target vectors. The cross-attention layer puts each of its input vectors \(\mathbf{y''}_j\) into relation with all contextualized encoding vectors \(\mathbf{\overline{X}}{1:n}\) to condition the probability distribution of the next target vectors on the input of the encoder as well. Alright, let\'s visualize the transformer-based decoder for our English to German translation example. We can see that the decoder maps the input \(\mathbf{Y}_{0:5}\) \"BOS\", \"Ich\", \"will\", \"ein\", \"Auto\", \"kaufen\" (shown in light red) together with the contextualized sequence of \"I\", \"want\", \"to\", \"buy\", \"a\", \"car\", \"EOS\", i.e. \(\mathbf{\overline{X}}{1:7}\) (shown in dark green) to the logit vectors \(\mathbf{L}{1:6}\) (shown in dark red). Applying a softmax operation on each \(\mathbf{l}1, \mathbf{l}_2, \ldots, \mathbf{l}_5\) can thus define the conditional probability distributions: $$ p{\theta_{dec}}(\mathbf{y} | \text{BOS}, \mathbf{\overline{X}}{1:7}), $$ $$ p{\theta_{dec}}(\mathbf{y} | \text{BOS Ich}, \mathbf{\overline{X}}{1:7}), $$ $$ \ldots, $$ $$ p{\theta_{dec}}(\mathbf{y} | \text{BOS Ich will ein Auto kaufen}, \mathbf{\overline{X}}{1:7}). $$ The overall conditional probability of: $$ p{\theta_{dec}}(\text{Ich will ein Auto kaufen EOS} | \mathbf{\overline{X}}{1:n})$$ can therefore be computed as the following product: $$ p{\theta_{dec}}(\text{Ich} | \text{BOS}, \mathbf{\overline{X}}{1:7}) \times \ldots \times p{\theta_{dec}}(\text{EOS} | \text{BOS Ich will ein Auto kaufen}, \mathbf{\overline{X}}{1:7}). $$ The red box on the right shows a decoder block for the first three target vectors \(\mathbf{y}_0, \mathbf{y}_1, \mathbf{y}_2\). In the lower part, the uni-directional self-attention mechanism is illustrated and in the middle, the cross-attention mechanism is illustrated. Let\'s first focus on uni-directional self-attention. As in bi-directional self-attention, in uni-directional self-attention, the query vectors \(\mathbf{q}_0, \ldots, \mathbf{q}{m-1}\) (shown in purple below), key vectors \(\mathbf{k}0, \ldots, \mathbf{k}{m-1}\) (shown in orange below), and value vectors \(\mathbf{v}0, \ldots, \mathbf{v}{m-1}\) (shown in blue below) are projected from their respective input vectors \(\mathbf{y'}0, \ldots, \mathbf{y'}{m-1}\) (shown in light red below). However, in uni-directional self-attention, each query vector \(\mathbf{q}_i\) is compared only to its respective key vector and all previous ones, namely \(\mathbf{k}_0, \ldots, \mathbf{k}_i\) to yield the respective attention weights. This prevents an output vector \(\mathbf{y''}j\) (shown in dark red below) to include any information about the following input vector \(\mathbf{y}_i, \text{ with } i > j\) for all \(j \in {0, \ldots, m - 1 }\). As is the case in bi-directional self-attention, the attention weights are then multiplied by their respective value vectors and summed together. We can summarize uni-directional self-attention as follows: $$\mathbf{y''}_i = \mathbf{V}{0: i} \textbf{Softmax}(\mathbf{K}_{0: i}^\intercal \mathbf{q}_i) + \mathbf{y'}_i. $$ Note that the index range of the key and value vectors is \(0:i\) instead of \(0: m-1\) which would be the range of the key vectors in bi-directional self-attention. Let\'s illustrate uni-directional self-attention for the input vector \(\mathbf{y'}_1\) for our example above. As can be seen \(\mathbf{y''}_1\) only depends on \(\mathbf{y'}_0\) and \(\mathbf{y'}_1\). Therefore, we put the vector representation of the word \"Ich\", i.e. \(\mathbf{y'}_1\) only into relation with itself and the \"BOS\" target vector, i.e. \(\mathbf{y'}_0\), but not with the vector representation of the word \"will\", i.e. \(\mathbf{y'}2\). So why is it important that we use uni-directional self-attention in the decoder instead of bi-directional self-attention? As stated above, a transformer-based decoder defines a mapping from a sequence of input vector \(\mathbf{Y}{0: m-1}\) to the logits corresponding to the next decoder input vectors, namely \(\mathbf{L}_{1:m}\). In our example, this means, e.g. that the input vector \(\mathbf{y}1\) = \"Ich\" is mapped to the logit vector \(\mathbf{l}_2\), which is then used to predict the input vector \(\mathbf{y}_2\). Thus, if \(\mathbf{y'}_1\) would have access to the following input vectors \(\mathbf{Y'}{2:5}\), the decoder would simply copy the vector representation of \"will\", i.e. \(\mathbf{y'}2\), to be its output \(\mathbf{y''}_1\). This would be forwarded to the last layer so that the encoded output vector \(\mathbf{\overline{y}}_1\) would essentially just correspond to the vector representation \(\mathbf{y}_2\). This is obviously disadvantageous as the transformer-based decoder would never learn to predict the next word given all previous words, but just copy the target vector \(\mathbf{y}_i\) through the network to \(\mathbf{\overline{y}}{i-1}\) for all \(i \in {1, \ldots, m }\). In order to define a conditional distribution of the next target vector, the distribution cannot be conditioned on the next target vector itself. It does not make much sense to predict \(\mathbf{y}i\) from \(p(\mathbf{y} | \mathbf{Y}{0:i}, \mathbf{\overline{X}})\) because the distribution is conditioned on the target vector it is supposed to model. The uni-directional self-attention architecture, therefore, allows us to define a causal probability distribution, which is necessary to effectively model a conditional distribution of the next target vector. Great! Now we can move to the layer that connects the encoder and decoder - the cross-attention mechanism! The cross-attention layer takes two vector sequences as inputs: the outputs of the uni-directional self-attention layer, i.e. \(\mathbf{Y''}{0: m-1}\) and the contextualized encoding vectors \(\mathbf{\overline{X}}{1:n}\). As in the self-attention layer, the query vectors \(\mathbf{q}0, \ldots, \mathbf{q}{m-1}\) are projections of the output vectors of the previous layer, i.e. \(\mathbf{Y''}{0: m-1}\). However, the key and value vectors \(\mathbf{k}_0, \ldots, \mathbf{k}{m-1}\) and \(\mathbf{v}0, \ldots, \mathbf{v}{m-1}\) are projections of the contextualized encoding vectors \(\mathbf{\overline{X}}_{1:n}\). Having defined key, value, and query vectors, a query vector \(\mathbf{q}_i\) is then compared to all key vectors and the corresponding score is used to weight the respective value vectors, just as is the case for bi-directional self-attention to give the output vector \(\mathbf{y'''}i\) for all \(i \in {0, \ldots, m-1}\). Cross-attention can be summarized as follows: $$ \mathbf{y'''}_i = \mathbf{V}{1:n} \textbf{Softmax}(\mathbf{K}{1: n}^\intercal \mathbf{q}_i) + \mathbf{y''}_i. $$ Note that the index range of the key and value vectors is \(1:n\) corresponding to the number of contextualized encoding vectors. Let\'s visualize the cross-attention mechanism for the input vector \(\mathbf{y''}_1\) for our example above. We can see that the query vector \(\mathbf{q}_1\) (shown in purple) is derived from \(\mathbf{y''}_1\)(shown in red) and therefore relies on a vector representation of the word \"Ich\". The query vector \(\mathbf{q}_1\) is then compared to the key vectors \(\mathbf{k}_1, \ldots, \mathbf{k}_7\) (shown in yellow) corresponding to the contextual encoding representation of all encoder input vectors \(\mathbf{X}{1:n}\) = \"I want to buy a car EOS\". This puts the vector representation of \"Ich\" into direct relation with all encoder input vectors. Finally, the attention weights are multiplied by the value vectors \(\mathbf{v}1, \ldots, \mathbf{v}_7\) (shown in turquoise) to yield in addition to the input vector \(\mathbf{y''}_1\) the output vector \(\mathbf{y'''}_1\) (shown in dark red). So intuitively, what happens here exactly? Each output vector \(\mathbf{y'''}_i\) is a weighted sum of all value projections of the encoder inputs \(\mathbf{v}{1}, \ldots, \mathbf{v}_7\) plus the input vector itself \(\mathbf{y''}_i\) (c.f. illustrated formula above). The key mechanism to understand is the following: Depending on how similar a query projection of the input decoder vector \(\mathbf{q}_i\) is to a key projection of the encoder input vector \(\mathbf{k}j\), the more important is the value projection of the encoder input vector \(\mathbf{v}_j\). In loose terms this means, the more \"related\" a decoder input representation is to an encoder input representation, the more does the input representation influence the decoder output representation. Cool! Now we can see how this architecture nicely conditions each output vector \(\mathbf{y'''}_i\) on the interaction between the encoder input vectors \(\mathbf{\overline{X}}{1:n}\) and the input vector \(\mathbf{y''}i\). Another important observation at this point is that the architecture is completely independent of the number \(n\) of contextualized encoding vectors \(\mathbf{\overline{X}}{1:n}\) on which the output vector \(\mathbf{y'''}i\) is conditioned on. All projection matrices \(\mathbf{W}^{\text{cross}}{k}\) and \(\mathbf{W}^{\text{cross}}_{v}\) to derive the key vectors \(\mathbf{k}_1, \ldots, \mathbf{k}_n\) and the value vectors \(\mathbf{v}_1, \ldots, \mathbf{v}_n\) respectively are shared across all positions \(1, \ldots, n\) and all value vectors \( \mathbf{v}_1, \ldots, \mathbf{v}_n \) are summed together to a single weighted averaged vector. Now it becomes obvious as well, why the transformer-based decoder does not suffer from the long-range dependency problem, the RNN-based decoder suffers from. Because each decoder logit vector is directly dependent on every single encoded output vector, the number of mathematical operations to compare the first encoded output vector and the last decoder logit vector amounts essentially to just one. To conclude, the uni-directional self-attention layer is responsible for conditioning each output vector on all previous decoder input vectors and the current input vector and the cross-attention layer is responsible to further condition each output vector on all encoded input vectors. To verify our theoretical understanding, let\'s continue our code example from the encoder section above. ------------------------------------------------------------------------ \({}^1\) The word embedding matrix \(\mathbf{W}_{\text{emb}}\) gives each input word a unique context-independent vector representation. This matrix is often fixed as the \"LM Head\" layer. However, the \"LM Head\" layer can very well consist of a completely independent \"encoded vector-to-logit\" weight mapping. \({}^2\) Again, an in-detail explanation of the role the feed-forward layers play in transformer-based models is out-of-scope for this notebook. It is argued in Yun et. al, (2017) that feed-forward layers are crucial to map each contextual vector \(\mathbf{x'}_i\) individually to the desired output space, which the self-attention layer does not manage to do on its own. It should be noted here, that each output token \(\mathbf{x'}\) is processed by the same feed-forward layer. For more detail, the reader is advised to read the paper. python from transformers import MarianMTModel, MarianTokenizer import torch tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-de") model = MarianMTModel.from_pretrained("Helsinki-NLP/opus-mt-en-de") embeddings = model.get_input_embeddings() # create token ids for encoder input input_ids = tokenizer("I want to buy a car", return_tensors="pt").input_ids # pass input token ids to encoder encoder_output_vectors = model.base_model.encoder(input_ids, return_dict=True).last_hidden_state # create token ids for decoder input decoder_input_ids = tokenizer("<pad> Ich will ein", return_tensors="pt", add_special_tokens=False).input_ids # pass decoder input ids and encoded input vectors to decoder decoder_output_vectors = model.base_model.decoder(decoder_input_ids, encoder_hidden_states=encoder_output_vectors).last_hidden_state # derive embeddings by multiplying decoder outputs with embedding weights lm_logits = torch.nn.functional.linear(decoder_output_vectors, embeddings.weight, bias=model.final_logits_bias) # change the decoder input slightly decoder_input_ids_perturbed = tokenizer("<pad> Ich will das", return_tensors="pt", add_special_tokens=False).input_ids decoder_output_vectors_perturbed = model.base_model.decoder(decoder_input_ids_perturbed, encoder_hidden_states=encoder_output_vectors).last_hidden_state lm_logits_perturbed = torch.nn.functional.linear(decoder_output_vectors_perturbed, embeddings.weight, bias=model.final_logits_bias) # compare shape and encoding of first vector print(f"Shape of decoder input vectors {embeddings(decoder_input_ids).shape}. Shape of decoder logits {lm_logits.shape}") # compare values of word embedding of "I" for input_ids and perturbed input_ids print("Is encoding for `Ich` equal to its perturbed version?: ", torch.allclose(lm_logits[0, 0], lm_logits_perturbed[0, 0], atol=1e-3)) Output: Shape of decoder input vectors torch.Size([1, 5, 512]). Shape of decoder logits torch.Size([1, 5, 58101]) Is encoding for `Ich` equal to its perturbed version?: True We compare the output shape of the decoder input word embeddings, i.e. embeddings(decoder_input_ids) (corresponds to \(\mathbf{Y}{0: 4}\), here <pad> corresponds to BOS and \"Ich will das\" is tokenized to 4 tokens) with the dimensionality of the lm_logits(corresponds to \(\mathbf{L}{1:5}\)). Also, we have passed the word sequence \"<pad> Ich will ein\" and a slightly perturbated version \"<pad> Ich will das\" together with the encoder_output_vectors through the decoder to check if the second lm_logit, corresponding to \"Ich\", differs when only the last word is changed in the input sequence (\"ein\" -> \"das\"). As expected the output shapes of the decoder input word embeddings and lm_logits, i.e. the dimensionality of \(\mathbf{Y}{0: 4}\) and \(\mathbf{L}{1:5}\) are different in the last dimension. While the sequence length is the same (=5), the dimensionality of a decoder input word embedding corresponds to model.config.hidden_size, whereas the dimensionality of a lm_logit corresponds to the vocabulary size model.config.vocab_size, as explained above. Second, it can be noted that the values of the encoded output vector of \(\mathbf{l}1 = \text{"Ich"}\) are the same when the last word is changed from \"ein\" to \"das\". This however should not come as a surprise if one has understood uni-directional self-attention. On a final side-note, _auto-regressive models, such as GPT2, have the same architecture as transformer-based decoder models if one removes the cross-attention layer because stand-alone auto-regressive models are not conditioned on any encoder outputs. So auto-regressive models are essentially the same as auto-encoding models but replace bi-directional attention with uni-directional attention. These models can also be pre-trained on massive open-domain text data to show impressive performances on natural language generation (NLG) tasks. In Radford et al. (2019), the authors show that a pre-trained GPT2 model can achieve SOTA or close to SOTA results on a variety of NLG tasks without much fine-tuning. All auto-regressive models of 🤗Transformers can be found here. Alright, that\'s it! Now, you should have gotten a good understanding of transformer-based encoder-decoder models and how to use them with the 🤗Transformers library. Thanks a lot to Victor Sanh, Sasha Rush, Sam Shleifer, Oliver Åstrand, ‪Ted Moskovitz and Kristian Kyvik for giving valuable feedback.
[ 0.03537491336464882, 0.01233337726444006, 0.06202572211623192, -0.019714578986167908, 0.09158548712730408, 0.061693187803030014, 0.02175789140164852, 0.03355993330478668, -0.017041482031345367, 0.025425026193261147, -0.07943876832723618, 0.034651175141334534, 0.01181337982416153, 0.0702233761548996, -0.038797955960035324, -0.007306226994842291, 0.03161470592021942, -0.08142906427383423, 0.015033058822154999, -0.016598081216216087, 0.015372516587376595, -0.09788516163825989, 0.023839261382818222, -0.020587176084518433, -0.030289912596344948, -0.010485916398465633, -0.021481243893504143, 0.007555370219051838, -0.06296125054359436, 0.043841298669576645, -0.1097121313214302, -0.00039659618050791323, 0.01007165852934122, -0.04291880130767822, -0.003079500515013933, -0.01447746716439724, -0.16014325618743896, -0.057364825159311295, 0.025211207568645477, 0.036703698337078094, -0.018406447023153305, -0.008452663198113441, -0.059406645596027374, 0.005582219455391169, -0.025329526513814926, -0.05282111093401909, -0.18113496899604797, 0.08478216826915741, -0.054955486208200455, -0.059596605598926544, -0.027277279645204544, 0.023363834246993065, -0.03548625111579895, 0.09354303777217865, 0.006549866404384375, -0.038321830332279205, 0.01631135120987892, -0.07364201545715332, 0.049229007214307785, -0.020153334364295006, 0.011837393045425415, 0.002854984486475587, 0.03068576753139496, 0.011670948937535286, 0.007736230734735727, 0.020903224125504494, 0.015312859788537025, 0.019151361659169197, 0.029632961377501488, -0.018727071583271027, -0.06561657041311264, 0.014416616410017014, -0.025005189701914787, -0.005932121071964502, -0.005713325459510088, 0.01767493598163128, -0.010818981565535069, 0.03270361199975014, 0.041771046817302704, -0.0014009459409862757, 0.023180363699793816, 0.04338495805859566, 0.03794237598776817, 0.08960617333650589, 0.05597732961177826, 0.026059679687023163, 0.07356240600347519, -0.050934482365846634, -0.048707492649555206, 0.10108238458633423, -0.016810230910778046, -0.12187380343675613, -0.0050226435996592045, 0.0015882488805800676, 0.05908088758587837, -0.004143082536756992, 0.02138107270002365, 0.046476371586322784, -0.021639110520482063, -0.020830437541007996, 0.01497550681233406, 0.01921090856194496, 0.07815749943256378, -0.03387811407446861, -0.01777496375143528, 0.004426664672791958, -0.005503058433532715, -0.05389254167675972, -0.03998975828289986, 0.015171080827713013, 0.01459044124931097, -0.05866531282663345, 0.03043649159371853, 0.01889044977724552, -0.06857141107320786, -0.0061038159765303135, 0.03899333253502846, 0.0007229560287669301, 0.005489293485879898, 0.03699972853064537, -0.03492363169789314, 0.10919485241174698, 0.02267508953809738, -0.03881707787513733, -0.06112256646156311, -0.053477443754673004, -0.02342466451227665, -0.009223194792866707, -0.009405395947396755, -0.0421135239303112, 0.05479693040251732, -0.04966896027326584, 0.03157632052898407, 0.008075259625911713, -0.07645656913518906, -0.04536528140306473, -0.0178799070417881, -0.015583566389977932, -0.03053221106529236, -0.04659520462155342, -0.09260404109954834, 0.04299187287688255, 0.001708921161480248, -0.02597893588244915, 0.004506553988903761, -0.041700609028339386, -0.06680245697498322, 0.05815112218260765, 0.05757186561822891, 0.045082248747348785, 0.0009706920245662332, 0.03541405871510506, 0.021395819261670113, -0.07244514673948288, 0.01610264927148819, 0.02063174359500408, -0.005713417660444975, -0.03666882589459419, -0.10629023611545563, 0.008949995040893555, 0.008185634389519691, 0.01517014391720295, -0.0016184841515496373, 0.01358942873775959, 0.0431942418217659, -0.087541364133358, 0.028444498777389526, 0.03840728476643562, -0.01928490400314331, 0.017178107053041458, 0.0023858705535531044, -0.048587583005428314, 0.02396349236369133, 0.013180798850953579, -0.014126146212220192, 0.04087112843990326, 0.012593703344464302, 0.08666130155324936, 0.03433406352996826, -0.06602899730205536, -0.06950010359287262, -0.00465398607775569, 0.027484284713864326, -0.028994830325245857, -0.029534243047237396, -0.04984298348426819, -0.023207534104585648, -0.053276535123586655, -0.01706819422543049, 0.08868779242038727, -0.08973681181669235, -0.07208722829818726, 0.03779180720448494, -0.055159177631139755, 0.026200829073786736, -0.057383760809898376, -0.03014119155704975, 0.0890573188662529, 0.08879794925451279, 0.03521811217069626, 0.03394269943237305, 0.019156472757458687, 0.005050611682236195, -0.033097606152296066, 0.017067071050405502, -0.006752608343958855, -0.009672033600509167, -0.007618951611220837, 0.06988494098186493, -0.0059653036296367645, -0.005611967761069536, -0.03444617986679077, -0.01273295097053051, -0.10502051562070847, 0.011970870196819305, -0.043165598064661026, -0.033419981598854065, 0.024587197229266167, 0.015721924602985382, -0.030463114380836487, 0.12344615161418915, -0.06142738461494446, -0.04728436842560768, -0.01795925199985504, 0.05618178844451904, 0.02641274221241474, 0.0546271875500679, -0.06964367628097534, 0.038954030722379684, -0.08456512540578842, -0.011558454483747482, -0.02363506704568863, 0.07551489770412445, 0.02320202626287937, -0.04156462103128433, -0.07353014498949051, -0.029516160488128662, 0.027504296973347664, 0.02329832874238491, -0.0363217368721962, 0.030214743688702583, 0.03359620273113251, 0.00756035465747118, -0.012504491955041885, -0.07236922532320023, -0.004671136382967234, 0.05164169892668724, -0.0479888841509819, 0.010229489766061306, 0.03682216629385948, -0.08887220919132233, 0.06991342455148697, 0.006965657230466604, -0.08810844272375107, 0.006327503826469183, 0.08839356899261475, 0.01548006571829319, -0.01877407170832157, -0.02263326570391655, 0.016733625903725624, -0.017018290236592293, -0.022309772670269012, -0.02867691032588482, -0.05425487458705902, -0.032080505043268204, 0.009802225977182388, 0.024862445890903473, 0.03887895122170448, -0.03197178244590759, 0.03200773894786835, 0.0040929848328232765, 0.014418967068195343, 0.016668586060404778, -0.01014637015759945, 0.03022903949022293, -0.04579804092645645, 0.05226108431816101, -0.017974408343434334, -0.021793676540255547, -0.007130427751690149, -0.021797098219394684, -0.0022525638341903687, 0.039613910019397736, 0.05432042106986046, 0.0012328863376751542, 0.014024145901203156, 0.007591418921947479, 0.01112269051373005, 0.005813575815409422, 0.026403386145830154, 0.03286134824156761, 0.045803409069776535, 0.029975872486829758, -0.008448596112430096, -0.02948804385960102, -0.007596351206302643, -0.007868990302085876, -0.008113784715533257, -0.023384984582662582, 0.005318140611052513, -0.0009276363998651505, 0.03733913600444794, 0.04463934898376465, -0.012876847758889198, -0.019060486927628517, 0.011205996386706829, 0.025197869166731834, 0.09813638776540756, -0.09195876866579056, -0.03580740839242935, 0.005615942645817995, -0.010868172161281109, 0.011172812432050705, -0.0403660424053669, 0.05961313471198082, -0.0027460313867777586, -0.027327273041009903, -0.018672620877623558, 0.06183154508471489, -0.00099269044585526, 0.006281863898038864, -0.015780802816152573, 0.007797883823513985, -0.05546443164348602, -0.004923737142235041, 0.012529396452009678, 0.05308886989951134, -0.016265416517853737, 0.015202573500573635, 0.01082076970487833, -0.011275408789515495, 0.03188224881887436, -0.02835926041007042, 0.009678819216787815, 0.043688636273145676, 0.006082603242248297, -0.004460436291992664, 0.010649673640727997, -0.0573449470102787, -0.0012032802915200591, -0.0006594326114282012, -0.00046326342271640897, -0.01810803823173046, 0.013347983360290527, 0.03706284239888191, -0.015269745141267776, -0.002619189443066716, 0.048516273498535156, -0.0011978043476119637, 0.011094028130173683, 0.000373876333469525, -0.012318284250795841, 0.03968578204512596, -0.020251838490366936, 0.008015059866011143, -0.04294399544596672, 0.001575231901369989, -0.05864766240119934, -0.020429162308573723, -0.02158348821103573, -0.00836738757789135, 0.020213430747389793, 0.024737050756812096, 0.022696195170283318, 0.013264544308185577, -0.003619341179728508, 0.02015906572341919, 0.01882890798151493, -0.02225504443049431, 0.048217661678791046, 0.018172895535826683, -0.01280925516039133, -0.029238950461149216, 0.05453141778707504, 0.021115364506840706, 0.049551479518413544, -0.014343108050525188, 0.048151880502700806, 0.016877802088856697, 0.02807743102312088, -0.015213428065180779, 0.001382889342494309, 0.011610966175794601, 0.02955043874680996, -0.032172203063964844, 0.005391119979321957, 0.10726302862167358, 0.01879747211933136, 0.0018520705634728074, -0.006442777346819639, -0.050576984882354736, 0.015039860270917416, -0.0194151159375906, 0.04028909653425217, -0.008785109035670757, 0.01717912033200264, 0.01570967212319374, -0.028324276208877563, 0.019381379708647728, -0.015174365602433681, 0.0018901920411735773, 0.016431989148259163, -0.02473956160247326, 0.052228428423404694, 0.0010092380689457059, 0.02111327461898327, 0.02063782513141632, 0.02160523645579815, 0.06166592985391617, -0.08783777803182602, -0.03473013639450073, -0.020396247506141663, -0.030117111280560493, 0.023631377145648003, 0.009130965918302536, -0.012511184439063072, 0.04983437806367874, -0.0048498488031327724, 0.05347117781639099, 0.002103910082951188, 0.0022299785632640123, 0.03269726037979126, 0.036122798919677734, -0.027485456317663193, -0.021335918456315994, -0.0800173208117485, 0.0035705443006008863, 0.016609547659754753, -0.016674943268299103, -0.019112635403871536, -0.0007344653713516891, 0.009870404377579689, 0.013209285214543343, 0.0013543276581913233, 0.014677975326776505, 0.018373722210526466, -0.008444778621196747, -0.03672907501459122, -0.032172366976737976, 0.01338234730064869, 0.05375023931264877, 0.0038921479135751724, 0.028779268264770508, 0.022866375744342804, 0.02698500268161297, 0.015143182128667831, 0.011281690560281277, -0.06026969477534294, -0.03384208306670189, 0.04257693886756897, 0.04276936128735542, -0.024162570014595985, 0.029663771390914917, -0.011280291713774204, -0.00883086584508419, -0.005498999264091253, -0.03400753065943718, -0.0169407669454813, 0.040343716740608215, 0.013504674658179283, -0.03559597581624985, 0.0039332215674221516, 0.0171196348965168, -0.03674875944852829, -0.009535210207104683, 0.0326901450753212, 0.012161076068878174, 0.012328516691923141, -0.01021844893693924, 0.009470845572650433, -0.04427044093608856, -0.0020468556322157383, -0.023657580837607384, 0.030103497207164764, -0.031204046681523323, -0.025688165798783302, 0.009607856161892414, 0.060380592942237854, -0.022615909576416016, -0.02691744826734066, 0.022593125700950623, 0.002324992325156927, -0.05184958502650261, 0.012977538630366325, -0.014045142568647861, 0.01036880910396576, -0.014442958869040012, -0.016715170815587044, 0.013847216963768005, -0.02505355514585972, 0.006179638672620058, 0.0026216956321150064, -0.00839943066239357, 0.046232786029577255, 0.03552115336060524, 0.04221309348940849, -0.0058226389810442924, 0.04755740240216255, 0.04189884290099144, -0.020188959315419197, 0.03692182898521423, -0.03472185134887695, -0.019986385479569435, 0.02760273404419422, 0.038723770529031754, 0.026263527572155, 0.0011435729684308171, 0.02268240600824356, 0.04601730778813362, 0.02579864300787449, 0.016252104192972183, 0.0006187812541611493, -0.022128375247120857, -0.06225486844778061, -0.03440961241722107, 0.006340223364531994, -0.019555337727069855, -0.019792132079601288, 0.037299420684576035, -0.02165323495864868, -0.04086734354496002, 0.010751327499747276, -0.01983789913356304, -0.01366904191672802, -0.034604430198669434, 0.014670375734567642, 0.037662968039512634, 0.05684138834476471, -0.01931067928671837, -0.010007972829043865, -0.003485198598355055, 0.027563419193029404, 0.0352376289665699, -0.01786825619637966, 0.00779671361669898, 0.030626680701971054, -0.019875770434737206, -0.010988553985953331, 0.04788752645254135, -0.022681396454572678, -0.01161630917340517, 0.052164725959300995, 0.010583673603832722, -0.011370024643838406, -0.013957350514829159, 0.03424973785877228, 0.0034824812319129705, 0.028987474739551544, 0.01802063174545765, -0.03390621393918991, 0.0063576665706932545, 0.0695238783955574, -0.04565944895148277, 0.02407313510775566, 0.04612036049365997, -0.018740525469183922, 0.011055710725486279, -0.004997259937226772, 0.04501292109489441, -0.012681706808507442, -0.017191048711538315, 0.01835489459335804, 0.02396983653306961, 0.03707270324230194, 0.025577230378985405, 0.012005437165498734, -0.01671692728996277, 0.045024324208498, 0.0066002365201711655, -0.04527119919657707, -0.023521486669778824, 0.023406703025102615, -0.039678025990724564, 0.014737160876393318, 0.002990594832226634, 0.004773321561515331, -0.006562989670783281, -0.007517203688621521, 0.01409988384693861, 0.05202402174472809, -0.025203006342053413, 0.02684987150132656, -0.0024844335857778788, -0.028650131076574326, 0.01095669250935316, 0.06494998931884766, 0.0006724825943820179, 0.04161786288022995, 0.01604064553976059, -0.018864724785089493, 0.06249084696173668, 0.02531309425830841, 0.00810796394944191, 0.030086683109402657, 0.030566617846488953, -0.02217884175479412, 0.025010215118527412, -0.004349775146692991, 0.019962770864367485, -0.003262902842834592, -0.02900463156402111, -0.02535017393529415, -0.033184975385665894, 0.018246134743094444, 0.014740495011210442, 0.00481027876958251, 0.032993752509355545, -0.03387289121747017, 0.03985520079731941, 0.06570319086313248, 0.011312868446111679, -0.0021899936255067587, 0.008584877476096153, 0.05127822980284691, 0.03267977386713028, -0.0005602724850177765, 0.011110637336969376, -0.028801973909139633, -0.00897352583706379, 0.04620913416147232, -0.006812738720327616, 0.04045784845948219, 0.028610631823539734, -0.0420796163380146, 0.00581089872866869, 0.01843009516596794, -0.034962721168994904, 0.00744198402389884, -0.011770063079893589, -0.04953017085790634, -0.006706984713673592, 0.018085986375808716, -0.04139075428247452, 0.019649621099233627, 0.026094483211636543, 0.019645847380161285, -0.02853470668196678, -0.014703177846968174, -0.006018337327986956, 0.04129685088992119, -0.017984863370656967, 0.006758409086614847, -0.04690206050872803, -0.026445960626006126, 0.01111817266792059, -0.0034509652759879827, -0.018642807379364967, -0.0051864273846149445, -0.015724685043096542, -0.03414333611726761, -0.02232198603451252, 0.020548401400446892, -0.0011710835387930274, -0.01908688247203827, 0.04441649839282036, 0.020814791321754456, -0.0005670267273671925, 0.03745405375957489, -0.016085732728242874, -0.002988531719893217, -0.03902643918991089, -0.021947352215647697, 0.014678698033094406, -0.004490485414862633, 0.009408357553184032, -0.02460654452443123, -0.014480218291282654, -0.007800651248544455, 0.021445343270897865, 0.0016270909691229463, 0.02963302470743656, -0.023341160267591476, -0.05011976137757301, -0.06170635297894478, -0.01941448636353016, 0.0033331289887428284, 0.01636880449950695, -0.004311114549636841, 0.012291447259485722, 0.00251751602627337, -0.031499989330768585, -0.019024979323148727, -0.013735022395849228, 0.02709048241376877, 0.04130619391798973, 0.006859134417027235, -0.0034231890458613634, -0.0332336463034153, 0.03465043008327484, 0.0020434751641005278, 0.018124792724847794, 0.045470934361219406, 0.03920029476284981, 0.0006280597881413996, -0.05832316726446152, 0.013361629098653793, -0.02989094890654087, -0.008823083713650703, -0.025652602314949036, -0.06846880167722702, -0.022828638553619385, 0.013034559786319733, -0.000916610995773226, 0.011774888262152672, -0.016937658190727234, -0.01923302374780178, 0.012388298287987709, 0.03411378711462021, -0.00021945258777122945, 0.016497373580932617, 0.02713916078209877, -0.02205982245504856, 0.0409049354493618, -0.017273638397455215, -0.0071424623019993305, -0.03575180470943451, -0.00806714128702879, 0.000008095707016764209, 0.07758080214262009, 0.024447904899716377, 0.028263313695788383, -0.023452987894415855, 0.011916082352399826, -0.01740877889096737, -0.02866298146545887, 0.001212450792081654, 0.022091694176197052, -0.010932829231023788, 0.0054780603386461735, 0.03345559537410736, 0.025523465126752853, -0.01684259995818138, 0.009390805847942829, 0.027224237099289894, 0.029289765283465385, -0.04419546574354172, -0.006863547954708338, -0.029452141374349594, -0.026952898129820824, 0.010751585476100445, 0.019390959292650223, 0.008541492745280266, 0.004707811400294304, 0.01681900955736637, 0.026553191244602203, -0.008673553355038166, -0.0024011998903006315, 0.020894577726721764, 0.03995165228843689, -0.010622574016451836, -0.0008213879191316664, -0.000429404666647315, -0.02181602455675602, -0.03707369789481163, 0.008212307468056679, 0.03364948555827141, -0.007041905540972948, -0.003795660100877285, -0.028255645185709, 0.007636561524122953, -0.011185919865965843, 0.009147217497229576, 0.018549541011452675, 0.056076399981975555, -0.01736215502023697, 0.03175982087850571, 0.02485206350684166, -0.0008633231045678258 ]
Transformer-based Encoder-Decoder Models
patrickvonplaten
October 10, 2020
encoder-decoder
research, nlp
https://huggingface.co/blog/encoder-decoder
Encoder-Decoder In 2017, Vaswani et al. introduced the Transformer and thereby gave birth to transformer-based encoder-decoder models. Analogous to RNN-based encoder-decoder models, transformer-based encoder-decoder models consist of an encoder and a decoder which are both stacks of residual attention blocks. The key innovation of transformer-based encoder-decoder models is that such residual attention blocks can process an input sequence \(\mathbf{X}{1:n}\) of variable length \(n\) without exhibiting a recurrent structure. Not relying on a recurrent structure allows transformer-based encoder-decoders to be highly parallelizable, which makes the model orders of magnitude more computationally efficient than RNN-based encoder-decoder models on modern hardware. As a reminder, to solve a sequence-to-sequence problem, we need to find a mapping of an input sequence \(\mathbf{X}{1:n}\) to an output sequence \(\mathbf{Y}{1:m}\) of variable length \(m\). Let\'s see how transformer-based encoder-decoder models are used to find such a mapping. Similar to RNN-based encoder-decoder models, the transformer-based encoder-decoder models define a conditional distribution of target vectors \(\mathbf{Y}{1:n}\) given an input sequence \(\mathbf{X}{1:n}\): $$ p_{\theta_{\text{enc}}, \theta_{\text{dec}}}(\mathbf{Y}{1:m} | \mathbf{X}{1:n}). $$ The transformer-based encoder part encodes the input sequence \(\mathbf{X}{1:n}\) to a sequence of hidden states \(\mathbf{\overline{X}}{1:n}\), thus defining the mapping: $$ f_{\theta_{\text{enc}}}: \mathbf{X}{1:n} \to \mathbf{\overline{X}}{1:n}. $$ The transformer-based decoder part then models the conditional probability distribution of the target vector sequence \(\mathbf{Y}{1:n}\) given the sequence of encoded hidden states \(\mathbf{\overline{X}}{1:n}\): $$ p_{\theta_{dec}}(\mathbf{Y}{1:n} | \mathbf{\overline{X}}{1:n}).$$ By Bayes\' rule, this distribution can be factorized to a product of conditional probability distribution of the target vector \(\mathbf{y}i\) given the encoded hidden states \(\mathbf{\overline{X}}{1:n}\) and all previous target vectors \(\mathbf{Y}{0:i-1}\): $$ p{\theta_{dec}}(\mathbf{Y}{1:n} | \mathbf{\overline{X}}{1:n}) = \prod_{i=1}^{n} p_{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{\overline{X}}{1:n}). $$ The transformer-based decoder hereby maps the sequence of encoded hidden states \(\mathbf{\overline{X}}{1:n}\) and all previous target vectors \(\mathbf{Y}{0:i-1}\) to the logit vector \(\mathbf{l}_i\). The logit vector \(\mathbf{l}_i\) is then processed by the softmax operation to define the conditional distribution \(p{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{\overline{X}}{1:n})\), just as it is done for RNN-based decoders. However, in contrast to RNN-based decoders, the distribution of the target vector \(\mathbf{y}_i\) is explicitly (or directly) conditioned on all previous target vectors \(\mathbf{y}_0, \ldots, \mathbf{y}{i-1}\) as we will see later in more detail. The 0th target vector \(\mathbf{y}0\) is hereby represented by a special \"begin-of-sentence\" \(\text{BOS}\) vector. Having defined the conditional distribution \(p{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{\overline{X}}{1:n})\), we can now auto-regressively generate the output and thus define a mapping of an input sequence \(\mathbf{X}{1:n}\) to an output sequence \(\mathbf{Y}{1:m}\) at inference. Let\'s visualize the complete process of auto-regressive generation of transformer-based encoder-decoder models. The transformer-based encoder is colored in green and the transformer-based decoder is colored in red. As in the previous section, we show how the English sentence \"I want to buy a car\", represented by \(\mathbf{x}_1 = \text{I}\), \(\mathbf{x}_2 = \text{want}\), \(\mathbf{x}_3 = \text{to}\), \(\mathbf{x}_4 = \text{buy}\), \(\mathbf{x}_5 = \text{a}\), \(\mathbf{x}_6 = \text{car}\), and \(\mathbf{x}_7 = \text{EOS}\) is translated into German: \"Ich will ein Auto kaufen\" defined as \(\mathbf{y}_0 = \text{BOS}\), \(\mathbf{y}_1 = \text{Ich}\), \(\mathbf{y}_2 = \text{will}\), \(\mathbf{y}_3 = \text{ein}\), \(\mathbf{y}_4 = \text{Auto}, \mathbf{y}_5 = \text{kaufen}\), and \(\mathbf{y}_6=\text{EOS}\). To begin with, the encoder processes the complete input sequence \(\mathbf{X}{1:7}\) = \"I want to buy a car\" (represented by the light green vectors) to a contextualized encoded sequence \(\mathbf{\overline{X}}{1:7}\). E.g. \(\mathbf{\overline{x}}_4\) defines an encoding that depends not only on the input \(\mathbf{x}_4\) = \"buy\", but also on all other words \"I\", \"want\", \"to\", \"a\", \"car\" and \"EOS\", i.e. the context. Next, the input encoding \(\mathbf{\overline{X}}{1:7}\) together with the BOS vector, i.e. \(\mathbf{y}0\), is fed to the decoder. The decoder processes the inputs \(\mathbf{\overline{X}}{1:7}\) and \(\mathbf{y}0\) to the first logit \(\mathbf{l}_1\) (shown in darker red) to define the conditional distribution of the first target vector \(\mathbf{y}_1\): $$ p{\theta_{enc, dec}}(\mathbf{y} | \mathbf{y}0, \mathbf{X}{1:7}) = p_{\theta_{enc, dec}}(\mathbf{y} | \text{BOS}, \text{I want to buy a car EOS}) = p_{\theta_{dec}}(\mathbf{y} | \text{BOS}, \mathbf{\overline{X}}{1:7}). $$ Next, the first target vector \(\mathbf{y}_1\) = \(\text{Ich}\) is sampled from the distribution (represented by the grey arrows) and can now be fed to the decoder again. The decoder now processes both \(\mathbf{y}_0\) = \"BOS\" and \(\mathbf{y}_1\) = \"Ich\" to define the conditional distribution of the second target vector \(\mathbf{y}_2\): $$ p{\theta_{dec}}(\mathbf{y} | \text{BOS Ich}, \mathbf{\overline{X}}{1:7}). $$ We can sample again and produce the target vector \(\mathbf{y}_2\) = \"will\". We continue in auto-regressive fashion until at step 6 the EOS vector is sampled from the conditional distribution: $$ \text{EOS} \sim p{\theta_{dec}}(\mathbf{y} | \text{BOS Ich will ein Auto kaufen}, \mathbf{\overline{X}}{1:7}). $$ And so on in auto-regressive fashion. It is important to understand that the encoder is only used in the first forward pass to map \(\mathbf{X}{1:n}\) to \(\mathbf{\overline{X}}{1:n}\). As of the second forward pass, the decoder can directly make use of the previously calculated encoding \(\mathbf{\overline{X}}{1:n}\). For clarity, let\'s illustrate the first and the second forward pass for our example above. As can be seen, only in step \(i=1\) do we have to encode \"I want to buy a car EOS\" to \(\mathbf{\overline{X}}{1:7}\). At step \(i=2\), the contextualized encodings of \"I want to buy a car EOS\" are simply reused by the decoder. In 🤗Transformers, this auto-regressive generation is done under-the-hood when calling the .generate() method. Let\'s use one of our translation models to see this in action. python from transformers import MarianMTModel, MarianTokenizer tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-de") model = MarianMTModel.from_pretrained("Helsinki-NLP/opus-mt-en-de") # create ids of encoded input vectors input_ids = tokenizer("I want to buy a car", return_tensors="pt").input_ids # translate example output_ids = model.generate(input_ids)[0] # decode and print print(tokenizer.decode(output_ids)) _Output: <pad> Ich will ein Auto kaufen Calling .generate() does many things under-the-hood. First, it passes the input_ids to the encoder. Second, it passes a pre-defined token, which is the \(\text{}\) symbol in the case of MarianMTModel along with the encoded input_ids to the decoder. Third, it applies the beam search decoding mechanism to auto-regressively sample the next output word of the last decoder output \({}^1\). For more detail on how beam search decoding works, one is advised to read this blog post. In the Appendix, we have included a code snippet that shows how a simple generation method can be implemented \"from scratch\". To fully understand how auto-regressive generation works under-the-hood, it is highly recommended to read the Appendix. To sum it up: - The transformer-based encoder defines a mapping from the input sequence \(\mathbf{X}{1:n}\) to a contextualized encoding sequence \(\mathbf{\overline{X}}{1:n}\). - The transformer-based decoder defines the conditional distribution \(p_{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{\overline{X}}{1:n})\). - Given an appropriate decoding mechanism, the output sequence \(\mathbf{Y}{1:m}\) can auto-regressively be sampled from \(p_{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{\overline{X}}{1:n}), \forall i \in {1, \ldots, m}\). Great, now that we have gotten a general overview of how transformer-based encoder-decoder models work, we can dive deeper into both the encoder and decoder part of the model. More specifically, we will see exactly how the encoder makes use of the self-attention layer to yield a sequence of context-dependent vector encodings and how self-attention layers allow for efficient parallelization. Then, we will explain in detail how the self-attention layer works in the decoder model and how the decoder is conditioned on the encoder\'s output with cross-attention layers to define the conditional distribution \(p{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{\overline{X}}{1:n})\). Along, the way it will become obvious how transformer-based encoder-decoder models solve the long-range dependencies problem of RNN-based encoder-decoder models. ------------------------------------------------------------------------ \({}^1\) In the case of "Helsinki-NLP/opus-mt-en-de", the decoding parameters can be accessed here, where we can see that model applies beam search with num_beams=6.
[ 0.05794487148523331, -0.029841676354408264, 0.08482501655817032, 0.0062196520157158375, 0.04830582067370415, 0.05355459079146385, 0.0054015712812542915, 0.004823475610464811, -0.04687770456075668, -0.008146415464580059, -0.04342680424451828, 0.08679112046957016, -0.028524432331323624, 0.0793076604604721, -0.003829000052064657, -0.01457685511559248, 0.03668627142906189, -0.05302664637565613, -0.0018933111568912864, 0.006707446649670601, 0.025776632130146027, -0.078278549015522, 0.0658874586224556, -0.06272660195827484, -0.02508406713604927, 0.010900533758103848, 0.005293240305036306, -0.055003710091114044, -0.07816275209188461, 0.07526817917823792, -0.11869409680366516, 0.049365635961294174, 0.030293544754385948, -0.03001311607658863, -0.04184043034911156, -0.04215757176280022, -0.1475595384836197, 0.002790082711726427, 0.026636453345417976, -0.014476219192147255, -0.024806153029203415, -0.05737978219985962, -0.09366176277399063, 0.013207548297941685, -0.03505866602063179, -0.003732201876118779, -0.1759387105703354, 0.07897378504276276, -0.06273097544908524, -0.03323405981063843, -0.0187199916690588, 0.06055920943617821, -0.04061061516404152, 0.0762970820069313, -0.00444826390594244, -0.0006436978001147509, 0.017752882093191147, -0.07474225014448166, 0.04409869387745857, -0.010992728173732758, 0.06415954977273941, 0.019948666915297508, -0.0006478669820353389, 0.044435054063797, 0.015529138036072254, -0.0019688091706484556, 0.018034031614661217, 0.014866692014038563, 0.013653665781021118, -0.009473547339439392, -0.0499439463019371, -0.04760759696364403, -0.004455046262592077, 0.0041000922210514545, -0.01200340036302805, -0.058176327496767044, -0.0031931765843182802, 0.07132869213819504, 0.08314148336648941, 0.027086976915597916, 0.017607232555747032, 0.04395849630236626, 0.08370364457368851, 0.05286535993218422, 0.024770691990852356, 0.03650235757231712, 0.048225291073322296, -0.07700028270483017, -0.02312813326716423, 0.09171205759048462, -0.04192283749580383, -0.12989191710948944, -0.0035277828574180603, -0.017640797421336174, 0.03668138012290001, -0.021498393267393112, 0.025206468999385834, 0.007430113386362791, -0.00872116070240736, 0.0037538986653089523, 0.0531013123691082, 0.014470442198216915, 0.09587699174880981, -0.06496065855026245, 0.01645779050886631, 0.009439720772206783, -0.027033606544137, -0.0640474408864975, -0.0411604642868042, -0.020939165726304054, -0.007025314029306173, 0.010274002328515053, 0.03444027155637741, 0.012061701156198978, -0.08109894394874573, 0.03582606837153435, 0.015768226236104965, 0.015957221388816833, -0.01718122698366642, -0.0016090115532279015, -0.021108092740178108, 0.06680545955896378, 0.03661542758345604, -0.03494078665971756, -0.019424499943852425, 0.03789814934134483, -0.031636081635951996, 0.00461428752169013, -0.002822954673320055, -0.04276446998119354, 0.06598766148090363, -0.02276006154716015, 0.052261125296354294, 0.03440432250499725, -0.023404480889439583, -0.07094988971948624, -0.010823739692568779, -0.06662709265947342, -0.03511533513665199, -0.00021156002185307443, -0.0668223425745964, 0.01658177375793457, 0.07047727704048157, -0.000551894714590162, 0.04974723979830742, -0.024582689628005028, -0.0977226048707962, 0.05590143799781799, 0.09369459748268127, -0.002468639984726906, -0.02267572283744812, -0.0021184422075748444, -0.04407082125544548, -0.06437378376722336, -0.027790028601884842, 0.009388691745698452, 0.011641458608210087, 0.004462176468223333, -0.07784508913755417, -0.014386892318725586, -0.04192311316728592, 0.03205867111682892, 0.03107842244207859, 0.04511595517396927, 0.0026251075323671103, -0.10903795063495636, 0.06119329482316971, 0.08515355736017227, -0.01888544298708439, 0.023325661197304726, -0.031386859714984894, 0.01778240129351616, 0.04514377564191818, 0.013899018056690693, -0.04998859763145447, 0.016018623486161232, -0.01616140827536583, 0.08262262493371964, 0.012102523818612099, -0.058596931397914886, -0.023817196488380432, -0.033777136355638504, 0.02686436101794243, 0.019072478637099266, -0.009275468066334724, -0.04288787022233009, -0.011723514646291733, -0.04126052185893059, -0.060017235577106476, 0.06350520253181458, -0.03967221453785896, -0.03022925928235054, 0.043974630534648895, 0.000011513812751218211, 0.09385981410741806, 0.010346604511141777, -0.05679535120725632, 0.08045007288455963, 0.07499092072248459, 0.08684565126895905, 0.06356880813837051, 0.005862273741513491, 0.04030796140432358, -0.04690986126661301, -0.03868293762207031, -0.0013513038866221905, 0.005307214334607124, -0.0036168231163173914, 0.0373222790658474, -0.04765024408698082, 0.027193766087293625, -0.04991647228598595, -0.02084893174469471, -0.06098796799778938, 0.03164539858698845, -0.0011773928999900818, -0.01832645945250988, 0.0007778233266435564, -0.028548182919621468, -0.013901054859161377, 0.1155632883310318, -0.033109527081251144, -0.06037596985697746, -0.00011788773554144427, 0.008792680688202381, 0.0492357574403286, 0.06500401347875595, -0.06812858581542969, 0.05041337013244629, -0.01222506444901228, -0.007959802635014057, -0.0467287041246891, 0.02745392918586731, -0.025846583768725395, -0.002627946436405182, -0.05825049802660942, -0.0681975707411766, 0.013761382550001144, 0.0014934861101210117, -0.04019008204340935, 0.024957876652479172, 0.018736345693469048, 0.022518552839756012, 0.003624953096732497, -0.05272112041711807, 0.010870452038943768, 0.04333376884460449, -0.018516255542635918, 0.0008859660010784864, -0.0014987671747803688, -0.10550600290298462, 0.06633605808019638, -0.02088877558708191, -0.09288478642702103, 0.041520729660987854, 0.07452590763568878, -0.007588766515254974, -0.017351603135466576, -0.0009950266685336828, -0.0007444992079399526, -0.03525867313146591, -0.01651936210691929, -0.000554426631424576, -0.06333068758249283, -0.07637624442577362, -0.04214280843734741, -0.009454638697206974, 0.010755670256912708, 0.00999758206307888, 0.018287943676114082, -0.00948897935450077, -0.0037092375569045544, 0.028782522305846214, 0.01590634696185589, 0.025440549477934837, 0.007898001931607723, 0.05714811384677887, -0.030893567949533463, -0.02951771579682827, -0.023021964356303215, -0.023465126752853394, -0.0030056361574679613, 0.05559190735220909, 0.04361315071582794, 0.015887215733528137, 0.020240766927599907, 0.015126329846680164, 0.012082917615771294, 0.006394523195922375, 0.010991327464580536, 0.028966043144464493, 0.025500817224383354, 0.004390256013721228, -0.021038992330431938, -0.03472181037068367, 0.011499482207000256, -0.0022746226750314236, -0.01669429987668991, -0.03311004489660263, -0.007605898194015026, 0.015963612124323845, 0.05745169520378113, -0.001949397148564458, -0.005443527363240719, -0.02089696191251278, 0.005874413996934891, 0.043703507632017136, 0.07399697601795197, -0.1031096950173378, -0.05429648980498314, -0.0298759788274765, 0.008102712221443653, -0.014689684845507145, -0.04967489838600159, 0.03858450427651405, 0.007205731701105833, -0.02024521864950657, -0.013983533717691898, 0.034467339515686035, 0.012514995411038399, -0.007580403238534927, 0.01318153366446495, -0.03938039019703865, -0.04529843106865883, 0.012688755989074707, 0.01970129832625389, 0.04848681762814522, -0.000527377356775105, 0.029512379318475723, 0.02100219763815403, 0.019619978964328766, 0.028024854138493538, -0.033030904829502106, 0.0036818506196141243, 0.08007314801216125, -0.02194909006357193, 0.008603217080235481, -0.011268063448369503, -0.049561284482479095, 0.004899593535810709, 0.023917723447084427, 0.004459702409803867, -0.04631608724594116, 0.02174062468111515, 0.06064562126994133, -0.020211495459079742, -0.0005742033245041966, 0.060721758753061295, 0.03018747642636299, -0.007426895201206207, -0.007913938723504543, -0.025399979203939438, 0.030715417116880417, 0.0012341871624812484, 0.02483438514173031, -0.009794749319553375, -0.003443079302087426, -0.0548563115298748, -0.02717062644660473, -0.024102089926600456, 0.004929186310619116, 0.014497443102300167, 0.004558281507343054, 0.014714243821799755, -0.012667611241340637, -0.01733405329287052, 0.01828976720571518, 0.03089980222284794, -0.0021517968270927668, 0.04667285084724426, 0.0061055985279381275, 0.01760035939514637, -0.07215391099452972, 0.05337096378207207, -0.0012040856527164578, 0.02047426626086235, 0.00671770703047514, 0.04001729190349579, -0.03045710362493992, 0.00927830021828413, 0.0032233791425824165, 0.007825437933206558, -0.008142264559864998, 0.03289162740111351, -0.025734800845384598, 0.013073829002678394, 0.08481425791978836, 0.009247461333870888, 0.003011459019035101, -0.035063471645116806, -0.03417881578207016, 0.03014872781932354, 0.030410628765821457, 0.04596275836229324, -0.016058947890996933, 0.007182830944657326, 0.03884614631533623, 0.0007348314393311739, 0.00007432776328641921, -0.04044384881854057, 0.03076406940817833, -0.013378279283642769, 0.027394453063607216, 0.025943662971258163, 0.013435306027531624, -0.0047380090691149235, 0.03677535802125931, 0.026035672053694725, 0.03388893976807594, -0.06965061277151108, -0.003896355861797929, -0.007394908461719751, -0.018063602969050407, 0.013045279309153557, -0.05461796745657921, -0.004653706680983305, 0.010308479890227318, 0.009022166021168232, 0.03421374037861824, -0.03678819164633751, 0.01063566654920578, 0.011874549090862274, 0.03291061893105507, -0.022260598838329315, -0.01067417673766613, -0.07394572347402573, -0.013413996435701847, 0.0066516767255961895, -0.03507591411471367, 0.005810570437461138, -0.000048237194278044626, -0.0010774873662739992, 0.032839320600032806, 0.017488664016127586, 0.019144007936120033, 0.013913062401115894, -0.0188191756606102, -0.011200838722288609, -0.019152292981743813, 0.02080010063946247, 0.0014247642830014229, -0.014858441427350044, 0.040160078555345535, 0.051432982087135315, 0.031638938933610916, 0.014189167879521847, -0.025614770129323006, -0.05614890903234482, -0.04402080550789833, 0.031622424721717834, 0.03867049887776375, -0.02183014154434204, 0.025516048073768616, -0.0233171284198761, -0.02801339328289032, -0.009330599568784237, -0.014100209809839725, 0.0012554891873151064, 0.037666212767362595, -0.02106986939907074, -0.028331775218248367, 0.014262738637626171, 0.013443021103739738, -0.014788869768381119, -0.01895456202328205, 0.032546933740377426, 0.009487607516348362, 0.007517436984926462, 0.013836879283189774, 0.015232972800731659, -0.031514301896095276, 0.012639328837394714, 0.006234545726329088, 0.022373536601662636, -0.0363251231610775, -0.047557685524225235, 0.011538105085492134, 0.025860849767923355, 0.01457647792994976, -0.029615264385938644, 0.030939439311623573, -0.015938380733132362, -0.0396578349173069, 0.04183341935276985, -0.013667421415448189, 0.02016321010887623, -0.010051304474473, 0.011900155805051327, -0.017978480085730553, 0.003206222550943494, 0.011009257286787033, 0.017450831830501556, 0.009261238388717175, -0.0029496774077415466, 0.05492716282606125, 0.05644964426755905, 0.005974822677671909, 0.014264032244682312, 0.0670260414481163, 0.0008643271867185831, 0.013617206364870071, -0.025587154552340508, 0.00928555428981781, -0.010666264221072197, 0.022932065650820732, 0.00843662116676569, -0.009511145763099194, 0.01581341214478016, 0.0505976639688015, 0.0185864195227623, 0.018783921375870705, -0.007393900770694017, 0.017138322815299034, -0.026277931407094002, 0.00011441582319093868, 0.016611699014902115, -0.015734106302261353, -0.015496239997446537, 0.018929889425635338, 0.010929513722658157, -0.04858469218015671, 0.007553062401711941, -0.028373077511787415, -0.03658117353916168, -0.01838478073477745, -0.009452509693801403, 0.03693327680230141, 0.04038738086819649, -0.039601173251867294, 0.004302308429032564, -0.007395128253847361, 0.000778414192609489, 0.003368186764419079, -0.01567157730460167, -0.005817316472530365, 0.05010908097028732, -0.01270346064120531, 0.009443875402212143, 0.05845175310969353, -0.01849421113729477, -0.03569343686103821, 0.023041950538754463, -0.008890115655958652, -0.04264414682984352, -0.020337780937552452, 0.0513249896466732, 0.009474378079175949, 0.015050981193780899, -0.012168158777058125, -0.04325644671916962, -0.018187498673796654, 0.034077756106853485, -0.05638379231095314, 0.014801639132201672, 0.058981604874134064, -0.020672978833317757, 0.013876467943191528, 0.0001870084524853155, 0.06324903666973114, -0.012072086334228516, -0.007660102564841509, 0.01565401814877987, 0.004564602859318256, 0.02531690150499344, 0.02484259381890297, -0.017545340582728386, 0.0006850670324638486, 0.0038904391694813967, 0.0062225074507296085, -0.0277315154671669, -0.007683673407882452, 0.0017380820354446769, -0.01397972647100687, 0.033345792442560196, -0.00265028839930892, -0.01618669554591179, 0.025930097326636314, 0.016945399343967438, 0.03251398727297783, 0.02487751841545105, -0.012159262783825397, 0.006947705522179604, -0.023638205602765083, -0.01883351244032383, 0.013194277882575989, 0.06750568747520447, -0.004287354648113251, 0.04960877448320389, 0.034528423100709915, 0.008067791350185871, 0.05071540176868439, 0.012987762689590454, -0.019441287964582443, 0.01109272986650467, 0.031102757900953293, -0.024728920310735703, 0.00875118002295494, -0.0056869941763579845, -0.004207015037536621, -0.0007121346425265074, -0.006948517169803381, -0.0033242215868085623, -0.04658810794353485, 0.03904644772410393, -0.006663735490292311, -0.004035551100969315, 0.04298429936170578, -0.04474407806992531, 0.040342386811971664, 0.05195913836359978, 0.010442649945616722, 0.0036400582175701857, 0.03915931656956673, 0.04857021942734718, 0.03631937876343727, 0.04757266119122505, -0.014510528184473515, -0.02031419239938259, 0.017703212797641754, 0.03838638588786125, 0.01112530566751957, 0.03154897317290306, -0.02115769125521183, -0.04174879565834999, 0.020743411034345627, 0.00678126560524106, -0.04340701177716255, -0.015271943062543869, 0.00318331946618855, 0.0005734643200412393, 0.005282754078507423, -0.02468040958046913, -0.04186795651912689, 0.015537654049694538, 0.059938132762908936, 0.005604361183941364, -0.028310000896453857, 0.006583529990166426, -0.004079337231814861, 0.05171200633049011, -0.04945740848779678, 0.013905232772231102, -0.022569850087165833, -0.008212371729314327, 0.0011748247779905796, 0.02031840570271015, 0.002280395245179534, -0.010559243150055408, -0.01744021847844124, 0.002182472962886095, -0.01649772934615612, 0.049758635461330414, -0.027597395703196526, -0.020056527107954025, 0.05228812247514725, -0.0013644769787788391, -0.01000834722071886, 0.01642361469566822, 0.006656318437308073, 0.008198249153792858, -0.040609173476696014, 0.010369458235800266, -0.014728564769029617, -0.013607342727482319, -0.0025223649572581053, -0.038973014801740646, 0.030887631699442863, -0.025694208219647408, 0.04746149480342865, 0.03849940001964569, 0.03207554295659065, -0.030822759494185448, -0.01952361688017845, -0.0029029366560280323, -0.0015487631317228079, 0.0036503304727375507, -0.014928331598639488, -0.007252435199916363, 0.01933876797556877, 0.01773085631430149, 0.0034971600398421288, -0.009599464945495129, -0.030988303944468498, 0.014462028630077839, 0.0039682029746472836, -0.006884357426315546, -0.020433107390999794, -0.03859998285770416, 0.03334692120552063, 0.00039913918590173125, 0.014849727973341942, 0.01974966563284397, 0.04610820487141609, 0.03012886270880699, -0.06618849188089371, -0.015000469982624054, -0.011324213817715645, -0.015860512852668762, -0.0466177724301815, -0.04728981852531433, -0.012569078244268894, 0.04343041405081749, 0.008969499729573727, 0.022866100072860718, -0.021478040143847466, 0.03694700822234154, -0.04006514698266983, -0.028500868007540703, 0.014058712869882584, 0.029824240133166313, 0.048520758748054504, -0.016080360859632492, 0.024315422400832176, -0.05942689627408981, -0.044204231351614, -0.036842186003923416, -0.022783979773521423, 0.010785388760268688, 0.0491829439997673, -0.015993574634194374, 0.018914520740509033, -0.01748252846300602, -0.04452735185623169, -0.009620054624974728, 0.0020894233603030443, -0.0013064125087112188, 0.008865405805408955, -0.010224893689155579, -0.0008335691527463496, -0.002491299295797944, -0.03207510709762573, -0.002442495198920369, 0.008622360415756702, 0.00013691485219169408, -0.03558898717164993, 0.0021633619908243418, 0.001881955424323678, -0.020542193204164505, -0.03139324486255646, 0.003730801632627845, 0.007818462327122688, 0.024057038128376007, 0.029096992686390877, 0.019905924797058105, 0.02647535316646099, -0.022050494328141212, 0.0175480917096138, 0.01992303691804409, 0.011806518770754337, -0.01832842454314232, -0.012645111419260502, -0.00036253462894819677, -0.023161279037594795, -0.03681237995624542, 0.0226125568151474, 0.026235653087496758, -0.01863495074212551, 0.023261912167072296, -0.034791044890880585, 0.006582324858754873, -0.04452260211110115, 0.02789943292737007, -0.020540453493595123, 0.0731222927570343, -0.017328357324004173, 0.0397997684776783, 0.02163788489997387, -0.010568803176283836 ]
Transformer-based Encoder-Decoder Models
patrickvonplaten
October 10, 2020
encoder-decoder
research, nlp
https://huggingface.co/blog/encoder-decoder
# Transformers-based Encoder-Decoder Models # Transformer-based Encoder-Decoder Models bash !pip install transformers==4.2.1 !pip install sentencepiece==0.1.95 The transformer-based encoder-decoder model was introduced by Vaswani et al. in the famous Attention is all you need paper and is today the de-facto standard encoder-decoder architecture in natural language processing (NLP). Recently, there has been a lot of research on different pre-training objectives for transformer-based encoder-decoder models, e.g. T5, Bart, Pegasus, ProphetNet, Marge, etc..., but the model architecture has stayed largely the same. The goal of the blog post is to give an in-detail explanation of how the transformer-based encoder-decoder architecture models sequence-to-sequence problems. We will focus on the mathematical model defined by the architecture and how the model can be used in inference. Along the way, we will give some background on sequence-to-sequence models in NLP and break down the transformer-based encoder-decoder architecture into its encoder and decoder parts. We provide many illustrations and establish the link between the theory of transformer-based encoder-decoder models and their practical usage in 🤗Transformers for inference. Note that this blog post does not explain how such models can be trained - this will be the topic of a future blog post. Transformer-based encoder-decoder models are the result of years of research on representation learning and model architectures. This notebook provides a short summary of the history of neural encoder-decoder models. For more context, the reader is advised to read this awesome blog post by Sebastion Ruder. Additionally, a basic understanding of the self-attention architecture is recommended. The following blog post by Jay Alammar serves as a good refresher on the original Transformer model here. At the time of writing this notebook, 🤗Transformers comprises the encoder-decoder models T5, Bart, MarianMT, and Pegasus, which are summarized in the docs under model summaries. The notebook is divided into four parts: - Background - A short history of neural encoder-decoder models is given with a focus on RNN-based models. - Encoder-Decoder - The transformer-based encoder-decoder model is presented and it is explained how the model is used for inference. - Encoder - The encoder part of the model is explained in detail. - Decoder - The decoder part of the model is explained in detail. Each part builds upon the previous part, but can also be read on its own.
[ 0.02254650555551052, -0.017314523458480835, 0.045832645148038864, -0.0002922908461187035, 0.025016168132424355, 0.08846232295036316, 0.04747406765818596, 0.033598702400922775, -0.03828566521406174, 0.03883416950702667, -0.08414851129055023, 0.11564814299345016, -0.03673581779003143, 0.05161769315600395, -0.0034605616237968206, -0.02782573364675045, 0.06104351952672005, -0.04649513214826584, -0.01312324684113264, 0.019781257957220078, 0.02226145938038826, -0.07011451572179794, 0.02932104654610157, -0.061645377427339554, -0.006224667653441429, -0.023259475827217102, -0.020257189869880676, 0.01009956281632185, -0.08008962869644165, 0.04780164361000061, -0.12318229675292969, 0.03776266798377037, 0.01486425381153822, -0.05566253140568733, -0.009565876796841621, -0.03561253845691681, -0.13995307683944702, 0.02392290160059929, 0.004667371045798063, -0.03783915191888809, -0.029933670535683632, -0.025402242317795753, -0.09996297210454941, -0.006299600936472416, -0.03882870450615883, -0.021656671538949013, -0.17785459756851196, 0.059204958379268646, -0.037862833589315414, -0.036836571991443634, -0.03205793723464012, 0.06556276232004166, -0.003876056056469679, 0.047359317541122437, 0.027837609872221947, 0.00371661433018744, 0.0371362566947937, -0.08069972693920135, 0.055289678275585175, -0.016216455027461052, 0.051167406141757965, 0.015773095190525055, -0.009923454374074936, 0.0299980565905571, 0.01787099428474903, 0.011009540408849716, -0.011719533242285252, 0.04539943486452103, -0.010814892128109932, 0.007131827063858509, -0.0387771837413311, -0.082270048558712, -0.009946371428668499, 0.017170529812574387, -0.028322862461209297, -0.07077135145664215, 0.053729087114334106, 0.03966924920678139, 0.061415743082761765, 0.05226702615618706, -0.016290215775370598, 0.038856666535139084, 0.04380646347999573, 0.07145514339208603, 0.06909097731113434, 0.04422484338283539, 0.04922657459974289, -0.030366724357008934, -0.056102603673934937, 0.06422194838523865, -0.028293361887335777, -0.17673128843307495, -0.01756778173148632, -0.029793333262205124, 0.007372293621301651, 0.01324974000453949, 0.026752106845378876, 0.011765489354729652, -0.01827167347073555, -0.05020746961236, 0.0071787238121032715, -0.043080445379018784, 0.09301220625638962, -0.06944891810417175, 0.012638756074011326, 0.010756618343293667, 0.02370527759194374, -0.05784609541296959, -0.04610343649983406, -0.029779262840747833, 0.005602493416517973, -0.017918340861797333, -0.016012366861104965, 0.07201499491930008, -0.0790533795952797, 0.037343185395002365, 0.0028263397980481386, -0.0013146456331014633, -0.01771247386932373, 0.01075633056461811, 0.003131914185360074, 0.01493512187153101, 0.07493513077497482, -0.03915764018893242, 0.022955071181058884, 0.04968038946390152, -0.05998678505420685, -0.012311725877225399, -0.022123025730252266, -0.006947102956473827, 0.08891633152961731, -0.01841476745903492, 0.07306475192308426, 0.014164460822939873, -0.028431912884116173, -0.06578195840120316, -0.019502630457282066, -0.07133849710226059, -0.0046386984176933765, 0.011026834137737751, -0.026167288422584534, 0.040609393268823624, 0.050082527101039886, 0.006586925592273474, 0.038090094923973083, -0.012719542719423771, -0.0877041295170784, 0.06302658468484879, 0.05444485694169998, 0.011998035944998264, -0.04499505087733269, 0.009983062744140625, -0.010413505136966705, -0.06899752467870712, -0.004527769982814789, 0.043501466512680054, -0.01055148709565401, -0.0070034414529800415, -0.07265211641788483, -0.036738548427820206, -0.00794460903853178, -0.03177208825945854, -0.0010299335699528456, 0.04528316482901573, 0.011886483989655972, -0.09174513071775436, 0.0176849365234375, 0.05952533707022667, 0.02059047482907772, 0.02122609131038189, -0.025080030784010887, 0.027191689237952232, 0.07199510186910629, -0.02534419111907482, -0.03542834892868996, 0.018221229314804077, -0.017741726711392403, 0.057006314396858215, -0.01312324684113264, -0.07843603938817978, -0.02520030550658703, -0.01049885991960764, 0.0030764394905418158, 0.02026878483593464, 0.05053487792611122, -0.04892832040786743, 0.011341326870024204, -0.038316380232572556, -0.04217750206589699, 0.032526180148124695, -0.06442286819219589, -0.02487359754741192, 0.06432528048753738, -0.014988415874540806, 0.0748816430568695, -0.02914528176188469, -0.07963516563177109, 0.11029304563999176, 0.05736985057592392, 0.052205681800842285, 0.07741973549127579, -0.034863218665122986, 0.03379344567656517, -0.03718648850917816, -0.027970056980848312, -0.025839166715741158, -0.026408951729536057, -0.017602961510419846, 0.0767330527305603, -0.005234439857304096, 0.002915801713243127, -0.06568068265914917, -0.02098902314901352, -0.06935939192771912, 0.020630519837141037, -0.06975755840539932, -0.010991611517965794, 0.020328056067228317, 0.013906856998801231, -0.006548132747411728, 0.10157381743192673, -0.06139872223138809, -0.01600172370672226, 0.0014661967288702726, 0.022390013560652733, 0.017918501049280167, 0.054522961378097534, -0.026387911289930344, 0.046810634434223175, -0.05291135981678963, -0.0023232989478856325, -0.019290205091238022, 0.01850385032594204, -0.011742238886654377, -0.0006754951318725944, -0.042871247977018356, -0.03481321781873703, 0.05635213106870651, -0.003782696556299925, -0.022534584626555443, 0.04427740350365639, 0.0025372786913067102, -0.009029311127960682, 0.016309499740600586, -0.06919856369495392, 0.007713207975029945, 0.04389828070998192, -0.028889618813991547, -0.014175564050674438, -0.009383282624185085, -0.11526485532522202, 0.06632576882839203, 0.00207054172642529, -0.05186091363430023, 0.05159294605255127, 0.09868696331977844, -0.01276896521449089, 0.0029683136381208897, 0.005615757778286934, 0.025355743244290352, -0.0327199250459671, -0.003207036294043064, 0.00038017044425942004, -0.05952164903283119, -0.062367748469114304, -0.02867332100868225, 0.0001998559309868142, 0.010713562369346619, 0.02424095943570137, 0.02619708701968193, -0.015262914821505547, -0.012695855461061, 0.049727022647857666, 0.0014202659949660301, 0.017803799360990524, 0.014348342083394527, 0.04163677617907524, -0.013222379609942436, -0.003278526244685054, -0.031024737283587456, -0.022944997996091843, -0.018393846228718758, 0.03453148901462555, 0.033635463565588, -0.001469501294195652, -0.00552720669656992, 0.024582507088780403, -0.011170082725584507, 0.005209748167544603, 0.031197212636470795, 0.016797658056020737, 0.008765071630477905, -0.01604798063635826, -0.02366085723042488, 0.00013740971917286515, 0.02014649659395218, -0.012578184716403484, -0.019849302247166634, -0.010760006494820118, 0.009389678947627544, -0.0022353322710841894, 0.03693682700395584, 0.02765781059861183, -0.015561374835669994, -0.012386603280901909, 0.021311644464731216, 0.027977535501122475, 0.04787975922226906, -0.09768712520599365, -0.046841904520988464, -0.02030267007648945, -0.016049634665250778, 0.009402900002896786, -0.01594115048646927, 0.07909325510263443, 0.015624651685357094, -0.027266860008239746, 0.0010961315128952265, 0.0021696300245821476, -0.0008879530942067504, 0.0037002183962613344, 0.011309251189231873, -0.008241882547736168, -0.020272020250558853, 0.01755249686539173, 0.004335617180913687, 0.04431456699967384, -0.007702328264713287, 0.015395773574709892, 0.03464595973491669, 0.016126025468111038, 0.014078622683882713, -0.027403689920902252, -0.007730067707598209, 0.03570723533630371, 0.008385456167161465, 0.013405578210949898, 0.0005718861939385533, -0.0023811999708414078, -0.013321605511009693, -0.019665036350488663, 0.024351123720407486, -0.04345760866999626, 0.015584168955683708, 0.02943447045981884, -0.011582653969526291, 0.041000910103321075, 0.05916823074221611, 0.00007344677578657866, -0.015181225724518299, -0.015849465504288673, -0.019857287406921387, 0.06321466714143753, -0.017181791365146637, 0.018229560926556587, -0.008530361577868462, -0.008147909305989742, -0.0411800891160965, -0.05271390080451965, -0.008147266693413258, -0.018900450319051743, 0.015352173708379269, 0.039003875106573105, -0.0045145475305616856, -0.023730212822556496, -0.010195954702794552, 0.0035391647834330797, -0.012608115561306477, -0.038200050592422485, 0.06459566205739975, -0.01704239472746849, -0.013577589765191078, -0.02390507608652115, 0.05275656282901764, -0.007802226115018129, 0.03417332470417023, 0.01992884837090969, 0.009598190896213055, -0.02574361301958561, 0.02859678864479065, 0.016587579622864723, 0.006544229108840227, -0.02684779092669487, 0.0329042486846447, -0.008576001040637493, 0.015556832775473595, 0.08882831782102585, 0.0048619601875543594, -0.041289038956165314, -0.034400686621665955, -0.04920568689703941, 0.015996642410755157, 0.02014506608247757, 0.0455857552587986, 0.0012909655924886465, -0.012676648795604706, 0.01981705240905285, 0.005578869953751564, 0.016170088201761246, -0.00914518442004919, 0.026136737316846848, 0.000761656672693789, 0.017719533294439316, 0.00697312643751502, 0.009072265587747097, -0.005050095729529858, 0.031706083565950394, 0.005134893581271172, 0.03185322880744934, -0.05878474563360214, -0.005414910614490509, 0.03477325290441513, -0.03949132561683655, 0.02080138958990574, -0.05604647099971771, -0.024793490767478943, -0.005483220797032118, -0.025645382702350616, 0.022155025973916054, -0.028741370886564255, 0.008136817254126072, 0.012644822709262371, 0.01827950030565262, -0.003243412356823683, -0.008602729067206383, -0.06633973866701126, -0.04056692495942116, -0.008900793269276619, -0.004893213044852018, 0.03605741262435913, 0.006268528290092945, -0.024855462834239006, 0.023961586877703667, 0.01931675150990486, 0.05800743028521538, 0.00371268717572093, -0.028998734429478645, -0.014371341094374657, -0.04435485973954201, 0.004018051084131002, 0.014976896345615387, -0.017185214906930923, 0.008619054220616817, 0.04351316764950752, -0.018147744238376617, 0.0168914794921875, -0.006728651933372021, -0.0055926102213561535, -0.038263991475105286, -0.0012200813507661223, 0.06120753660798073, -0.04202251881361008, 0.024828536435961723, -0.004887689370661974, -0.028838571161031723, -0.008861545473337173, -0.013390569016337395, 0.010149715468287468, 0.03414630517363548, -0.0035098628140985966, 0.0045540970750153065, 0.00815823394805193, 0.01871110312640667, -0.02605222910642624, 0.0018368309829384089, 0.0450114905834198, 0.013728240504860878, 0.05139961093664169, 0.020203618332743645, 0.027856772765517235, -0.02606818452477455, -0.005552053451538086, 0.013859599828720093, 0.031392697244882584, -0.07766064256429672, -0.0745605081319809, 0.016811633482575417, 0.028331296518445015, -0.006984445732086897, -0.020832916721701622, 0.03295944631099701, 0.009180466644465923, -0.02567857690155506, 0.007438261527568102, 0.015332845970988274, 0.03720010817050934, -0.03393964841961861, 0.00883563607931137, 0.0027651109267026186, -0.011143173091113567, 0.008871681056916714, 0.020999850705266, 0.02881481684744358, -0.025920985266566277, 0.06529902666807175, 0.072193443775177, -0.011798410676419735, 0.032383326441049576, 0.04940992593765259, 0.01587532088160515, 0.025666913017630577, -0.004256133921444416, 0.002858211752027273, -0.007829930633306503, 0.006920891813933849, 0.03003315068781376, -0.02487284503877163, 0.02887784317135811, 0.013635187409818172, 0.02627302147448063, -0.002058556070551276, -0.024305880069732666, 0.042095474898815155, -0.024731827899813652, -0.006363748572766781, -0.017227713018655777, 0.027232948690652847, -0.045136719942092896, 0.02655811607837677, 0.003369932761415839, -0.030027564615011215, -0.001721798675134778, -0.013736146502196789, -0.029033031314611435, -0.009707407094538212, 0.0319819450378418, -0.009533942677080631, 0.04914778098464012, -0.032477349042892456, -0.01796981319785118, -0.02849777787923813, 0.03132760152220726, 0.028086770325899124, -0.05548262596130371, -0.001370672951452434, 0.031788844615221024, 0.0012911675730720162, -0.009113479405641556, 0.03453606367111206, 0.008029963821172714, -0.01269658375531435, 0.010835245251655579, -0.014738046564161777, -0.00897463969886303, -0.038464225828647614, 0.03981849551200867, 0.018170708790421486, -0.0040817055851221085, 0.004534131847321987, -0.010037107393145561, -0.025462238118052483, 0.03526079282164574, -0.04028718173503876, 0.027775069698691368, 0.08315352350473404, -0.022532256320118904, -0.007801264524459839, 0.0159391388297081, 0.04830656573176384, 0.009170488454401493, -0.025021135807037354, 0.01216848660260439, 0.003035023109987378, 0.017962053418159485, 0.026863370090723038, -0.015677159652113914, 0.018584171310067177, 0.015204295516014099, 0.02112625166773796, -0.022445544600486755, 0.01412522979080677, 0.017117399722337723, -0.00532356696203351, 0.02047743648290634, 0.029385380446910858, -0.04035358875989914, 0.006382032763212919, -0.00991048477590084, 0.03114069066941738, 0.03124082274734974, -0.013223856687545776, 0.006822720170021057, -0.007587122265249491, -0.025525763630867004, 0.01457961741834879, 0.08855617791414261, -0.0014556776732206345, 0.043416399508714676, 0.036537785083055496, 0.004841402173042297, 0.03997807204723358, 0.015133699402213097, -0.027967825531959534, 0.0027444136794656515, 0.05954834818840027, -0.03223711624741554, 0.015694353729486465, -0.004519762005656958, -0.011066210456192493, 0.002912222407758236, -0.018162887543439865, -0.02403327450156212, -0.02978970669209957, 0.0285041406750679, 0.027249466627836227, 0.0020883623510599136, 0.05131787434220314, -0.03366805985569954, 0.045526280999183655, 0.037779301404953, 0.017632808536291122, 0.01571204885840416, 0.04063975438475609, 0.056825101375579834, 0.02499053068459034, 0.025237223133444786, 0.02240074798464775, -0.018579917028546333, -0.003136041574180126, 0.04253488406538963, 0.03871056064963341, 0.04219280928373337, 0.014968493953347206, -0.030106928199529648, -0.004925527144223452, -0.008676850236952305, -0.047533538192510605, -0.006631616503000259, 0.0069113969802856445, -0.02760527841746807, -0.01121505070477724, 0.006012230645865202, -0.034175775945186615, 0.02772691287100315, 0.011098599061369896, -0.020729027688503265, -0.006628836039453745, -0.01968684233725071, -0.00976335909217596, 0.06419509649276733, 0.008404762484133244, -0.011492853052914143, -0.04038189351558685, -0.006565887946635485, -0.012441694736480713, 0.026607468724250793, -0.0027143910992890596, -0.03035738319158554, -0.02049177885055542, -0.0029725395143032074, -0.050405096262693405, 0.04036921635270119, -0.03680875897407532, -0.028356531634926796, 0.06582831591367722, -0.024083390831947327, -0.03455381095409393, 0.0048011853359639645, 0.016719641163945198, 0.02552475966513157, -0.037408776581287384, 0.02563582919538021, -0.0037094582803547382, -0.014929602853953838, -0.010943603701889515, -0.04725285619497299, 0.03233921900391579, -0.005674994550645351, 0.03428906574845314, 0.01694306544959545, 0.03593266010284424, -0.008475027047097683, -0.01824994757771492, -0.004298812244087458, -0.0019714038353413343, 0.0001476942707085982, 0.012868097051978111, 0.00985972210764885, 0.018314342945814133, 0.005490313284099102, -0.0352296382188797, -0.002019232837483287, -0.026006998494267464, 0.021804489195346832, 0.006884176284074783, -0.016341308131814003, -0.020520489662885666, -0.04825136438012123, 0.028156640008091927, 0.017170002683997154, 0.027606189250946045, 0.06334306299686432, 0.019788997247815132, 0.03860333189368248, -0.05338786914944649, -0.022299865260720253, -0.04410352557897568, 0.004601216409355402, -0.037678156048059464, -0.06252240389585495, -0.01655249483883381, 0.05137273669242859, -0.003964077215641737, 0.034937549382448196, -0.04046729579567909, 0.01581009104847908, -0.04836292937397957, -0.013570761308073997, 0.029209330677986145, 0.021800870075821877, 0.01771601289510727, 0.012762891128659248, 0.03327622264623642, -0.0177773404866457, -0.03800370171666145, -0.049686845391988754, -0.02829783223569393, -0.009872551076114178, 0.049046020954847336, -0.006368127651512623, 0.021046975627541542, -0.03778693452477455, -0.045626200735569, -0.008349400945007801, -0.044973816722631454, 0.0072864084504544735, 0.03598998859524727, -0.03303034231066704, 0.00526023842394352, 0.008384762331843376, -0.007449904456734657, -0.008004347793757915, -0.014946896582841873, 0.021388409659266472, -0.02932647056877613, -0.002552678110077977, -0.0007320111617445946, -0.02995436079800129, -0.021241502836346626, -0.0001254787785001099, -0.0028692809864878654, 0.0008788229315541685, 0.05628059431910515, 0.04186898097395897, -0.003712457139045, 0.020510196685791016, -0.003799993544816971, 0.005966209340840578, -0.0037790751084685326, -0.04012703895568848, -0.012314314022660255, 0.026697654277086258, -0.033946551382541656, -0.03252474591135979, 0.05441154167056084, 0.027442656457424164, -0.023438872769474983, 0.006074883975088596, 0.000059798523579956964, -0.032201118767261505, -0.012951614335179329, 0.030345816165208817, 0.001669345423579216, 0.0783873125910759, 0.031232189387083054, 0.022850872948765755, 0.02248513698577881, 0.003598990850150585 ]
Transformer-based Encoder-Decoder Models
patrickvonplaten
October 10, 2020
encoder-decoder
research, nlp
https://huggingface.co/blog/encoder-decoder
Background Tasks in natural language generation (NLG), a subfield of NLP, are best expressed as sequence-to-sequence problems. Such tasks can be defined as finding a model that maps a sequence of input words to a sequence of target words. Some classic examples are summarization and translation. In the following, we assume that each word is encoded into a vector representation. \(n\) input words can then be represented as a sequence of \(n\) input vectors: $$\mathbf{X}{1:n} = {\mathbf{x}_1, \ldots, \mathbf{x}_n}.$$ Consequently, sequence-to-sequence problems can be solved by finding a mapping \(f\) from an input sequence of \(n\) vectors \(\mathbf{X}{1:n}\) to a sequence of \(m\) target vectors \(\mathbf{Y}{1:m}\), whereas the number of target vectors \(m\) is unknown apriori and depends on the input sequence: $$ f: \mathbf{X}{1:n} \to \mathbf{Y}{1:m}. $$ Sutskever et al. (2014) noted that deep neural networks (DNN)s, \"despite their flexibility and power can only define a mapping whose inputs and targets can be sensibly encoded with vectors of fixed dimensionality.\" \({}^1\) Using a DNN model \({}^2\) to solve sequence-to-sequence problems would therefore mean that the number of target vectors \(m\) has to be known apriori and would have to be independent of the input \(\mathbf{X}{1:n}\). This is suboptimal because, for tasks in NLG, the number of target words usually depends on the input \(\mathbf{X}{1:n}\) and not just on the input length \(n\). E.g., an article of 1000 words can be summarized to both 200 words and 100 words depending on its content. In 2014, Cho et al. and Sutskever et al. proposed to use an encoder-decoder model purely based on recurrent neural networks (RNNs) for sequence-to-sequence tasks. In contrast to DNNS, RNNs are capable of modeling a mapping to a variable number of target vectors. Let\'s dive a bit deeper into the functioning of RNN-based encoder-decoder models. During inference, the encoder RNN encodes an input sequence \(\mathbf{X}{1:n}\) by successively updating its hidden state \({}^3\). After having processed the last input vector \(\mathbf{x}n\), the encoder\'s hidden state defines the input encoding \(\mathbf{c}\). Thus, the encoder defines the mapping: $$ f{\theta_{enc}}: \mathbf{X}{1:n} \to \mathbf{c}. $$ Then, the decoder\'s hidden state is initialized with the input encoding and during inference, the decoder RNN is used to auto-regressively generate the target sequence. Let\'s explain. Mathematically, the decoder defines the probability distribution of a target sequence \(\mathbf{Y}{1:m}\) given the hidden state \(\mathbf{c}\): $$ p_{\theta_{dec}}(\mathbf{Y}{1:m} |\mathbf{c}). $$ By Bayes\' rule the distribution can be decomposed into conditional distributions of single target vectors as follows: $$ p{\theta_{dec}}(\mathbf{Y}{1:m} |\mathbf{c}) = \prod{i=1}^{m} p_{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{c}). $$ Thus, if the architecture can model the conditional distribution of the next target vector, given all previous target vectors: $$ p_{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{c}), \forall i \in {1, \ldots, m},$$ then it can model the distribution of any target vector sequence given the hidden state \(\mathbf{c}\) by simply multiplying all conditional probabilities. So how does the RNN-based decoder architecture model \(p_{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{c})\)? In computational terms, the model sequentially maps the previous inner hidden state \(\mathbf{c}{i-1}\) and the previous target vector \(\mathbf{y}{i-1}\) to the current inner hidden state \(\mathbf{c}i\) and a logit vector \(\mathbf{l}_i\) (shown in dark red below): $$ f{\theta_{\text{dec}}}(\mathbf{y}{i-1}, \mathbf{c}{i-1}) \to \mathbf{l}i, \mathbf{c}_i.$$ \(\mathbf{c}_0\) is thereby defined as \(\mathbf{c}\) being the output hidden state of the RNN-based encoder. Subsequently, the softmax operation is used to transform the logit vector \(\mathbf{l}_i\) to a conditional probablity distribution of the next target vector: $$ p(\mathbf{y}_i | \mathbf{l}_i) = \textbf{Softmax}(\mathbf{l}_i), \text{ with } \mathbf{l}_i = f{\theta_{\text{dec}}}(\mathbf{y}{i-1}, \mathbf{c}{\text{prev}}). $$ For more detail on the logit vector and the resulting probability distribution, please see footnote \({}^4\). From the above equation, we can see that the distribution of the current target vector \(\mathbf{y}i\) is directly conditioned on the previous target vector \(\mathbf{y}{i-1}\) and the previous hidden state \(\mathbf{c}{i-1}\). Because the previous hidden state \(\mathbf{c}{i-1}\) depends on all previous target vectors \(\mathbf{y}0, \ldots, \mathbf{y}{i-2}\), it can be stated that the RNN-based decoder implicitly (e.g. indirectly) models the conditional distribution \(p_{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{c})\). The space of possible target vector sequences \(\mathbf{Y}{1:m}\) is prohibitively large so that at inference, one has to rely on decoding methods \({}^5\) that efficiently sample high probability target vector sequences from \(p{\theta_{dec}}(\mathbf{Y}{1:m} |\mathbf{c})\). Given such a decoding method, during inference, the next input vector \(\mathbf{y}_i\) can then be sampled from \(p{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{c})\) and is consequently appended to the input sequence so that the decoder RNN then models \(p_{\theta_{\text{dec}}}(\mathbf{y}{i+1} | \mathbf{Y}{0: i}, \mathbf{c})\) to sample the next input vector \(\mathbf{y}{i+1}\) and so on in an auto-regressive fashion. An important feature of RNN-based encoder-decoder models is the definition of special vectors, such as the \(\text{EOS}\) and \(\text{BOS}\) vector. The \(\text{EOS}\) vector often represents the final input vector \(\mathbf{x}_n\) to \"cue\" the encoder that the input sequence has ended and also defines the end of the target sequence. As soon as the \(\text{EOS}\) is sampled from a logit vector, the generation is complete. The \(\text{BOS}\) vector represents the input vector \(\mathbf{y}_0\) fed to the decoder RNN at the very first decoding step. To output the first logit \(\mathbf{l}_1\), an input is required and since no input has been generated at the first step a special \(\text{BOS}\) input vector is fed to the decoder RNN. Ok - quite complicated! Let\'s illustrate and walk through an example. The unfolded RNN encoder is colored in green and the unfolded RNN decoder is colored in red. The English sentence \"I want to buy a car\", represented by \(\mathbf{x}_1 = \text{I}\), \(\mathbf{x}_2 = \text{want}\), \(\mathbf{x}_3 = \text{to}\), \(\mathbf{x}_4 = \text{buy}\), \(\mathbf{x}_5 = \text{a}\), \(\mathbf{x}_6 = \text{car}\) and \(\mathbf{x}_7 = \text{EOS}\) is translated into German: \"Ich will ein Auto kaufen\" defined as \(\mathbf{y}_0 = \text{BOS}\), \(\mathbf{y}_1 = \text{Ich}\), \(\mathbf{y}_2 = \text{will}\), \(\mathbf{y}_3 = \text{ein}\), \(\mathbf{y}_4 = \text{Auto}, \mathbf{y}_5 = \text{kaufen}\) and \(\mathbf{y}_6=\text{EOS}\). To begin with, the input vector \(\mathbf{x}_1 = \text{I}\) is processed by the encoder RNN and updates its hidden state. Note that because we are only interested in the final encoder\'s hidden state \(\mathbf{c}\), we can disregard the RNN encoder\'s target vector. The encoder RNN then processes the rest of the input sentence \(\text{want}\), \(\text{to}\), \(\text{buy}\), \(\text{a}\), \(\text{car}\), \(\text{EOS}\) in the same fashion, updating its hidden state at each step until the vector \(\mathbf{x}_7={EOS}\) is reached \({}^6\). In the illustration above the horizontal arrow connecting the unfolded encoder RNN represents the sequential updates of the hidden state. The final hidden state of the encoder RNN, represented by \(\mathbf{c}\) then completely defines the encoding of the input sequence and is used as the initial hidden state of the decoder RNN. This can be seen as conditioning the decoder RNN on the encoded input. To generate the first target vector, the decoder is fed the \(\text{BOS}\) vector, illustrated as \(\mathbf{y}_0\) in the design above. The target vector of the RNN is then further mapped to the logit vector \(\mathbf{l}_1\) by means of the LM Head feed-forward layer to define the conditional distribution of the first target vector as explained above: $$ p{\theta_{dec}}(\mathbf{y} | \text{BOS}, \mathbf{c}). $$ The word \(\text{Ich}\) is sampled (shown by the grey arrow, connecting \(\mathbf{l}1\) and \(\mathbf{y}_1\)) and consequently the second target vector can be sampled: $$ \text{will} \sim p{\theta_{dec}}(\mathbf{y} | \text{BOS}, \text{Ich}, \mathbf{c}). $$ And so on until at step \(i=6\), the \(\text{EOS}\) vector is sampled from \(\mathbf{l}6\) and the decoding is finished. The resulting target sequence amounts to \(\mathbf{Y}{1:6} = {\mathbf{y}1, \ldots, \mathbf{y}_6}\), which is \"Ich will ein Auto kaufen\" in our example above. To sum it up, an RNN-based encoder-decoder model, represented by \(f{\theta_{\text{enc}}}\) and \( p_{\theta_{\text{dec}}} \) defines the distribution \(p(\mathbf{Y}{1:m} | \mathbf{X}{1:n})\) by factorization: $$ p_{\theta_{\text{enc}}, \theta_{\text{dec}}}(\mathbf{Y}{1:m} | \mathbf{X}{1:n}) = \prod_{i=1}^{m} p_{\theta_{\text{enc}}, \theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{X}{1:n}) = \prod{i=1}^{m} p_{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i-1}, \mathbf{c}), \text{ with } \mathbf{c}=f_{\theta_{enc}}(X). $$ During inference, efficient decoding methods can auto-regressively generate the target sequence \(\mathbf{Y}{1:m}\). The RNN-based encoder-decoder model took the NLG community by storm. In 2016, Google announced to fully replace its heavily feature engineered translation service by a single RNN-based encoder-decoder model (see here). Nevertheless, RNN-based encoder-decoder models have two pitfalls. First, RNNs suffer from the vanishing gradient problem, making it very difficult to capture long-range dependencies, cf. Hochreiter et al. (2001). Second, the inherent recurrent architecture of RNNs prevents efficient parallelization when encoding, cf. Vaswani et al. (2017). ------------------------------------------------------------------------ \({}^1\) The original quote from the paper is \"Despite their flexibility and power, DNNs can only be applied to problems whose inputs and targets can be sensibly encoded with vectors of fixed dimensionality\", which is slightly adapted here. \({}^2\) The same holds essentially true for convolutional neural networks (CNNs). While an input sequence of variable length can be fed into a CNN, the dimensionality of the target will always be dependent on the input dimensionality or fixed to a specific value. \({}^3\) At the first step, the hidden state is initialized as a zero vector and fed to the RNN together with the first input vector \(\mathbf{x}_1\). \({}^4\) A neural network can define a probability distribution over all words, i.e. \(p(\mathbf{y} | \mathbf{c}, \mathbf{Y}{0: i-1})\) as follows. First, the network defines a mapping from the inputs \(\mathbf{c}, \mathbf{Y}{0: i-1}\) to an embedded vector representation \(\mathbf{y'}\), which corresponds to the RNN target vector. The embedded vector representation \(\mathbf{y'}\) is then passed to the \"language model head\" layer, which means that it is multiplied by the word embedding matrix, i.e. \(\mathbf{Y}^{\text{vocab}}\), so that a score between \(\mathbf{y'}\) and each encoded vector \(\mathbf{y} \in \mathbf{Y}^{\text{vocab}}\) is computed. The resulting vector is called the logit vector \( \mathbf{l} = \mathbf{Y}^{\text{vocab}} \mathbf{y'} \) and can be mapped to a probability distribution over all words by applying a softmax operation: \(p(\mathbf{y} | \mathbf{c}) = \text{Softmax}(\mathbf{Y}^{\text{vocab}} \mathbf{y'}) = \text{Softmax}(\mathbf{l})\). \({}^5\) Beam-search decoding is an example of such a decoding method. Different decoding methods are out of scope for this notebook. The reader is advised to refer to this interactive notebook on decoding methods. \({}^6\) Sutskever et al. (2014) reverses the order of the input so that in the above example the input vectors would correspond to \(\mathbf{x}_1 = \text{car}\), \(\mathbf{x}_2 = \text{a}\), \(\mathbf{x}_3 = \text{buy}\), \(\mathbf{x}_4 = \text{to}\), \(\mathbf{x}_5 = \text{want}\), \(\mathbf{x}_6 = \text{I}\) and \(\mathbf{x}_7 = \text{EOS}\). The motivation is to allow for a shorter connection between corresponding word pairs such as \(\mathbf{x}_6 = \text{I}\) and \(\mathbf{y}_1 = \text{Ich}\). The research group emphasizes that the reversal of the input sequence was a key reason for their model\'s improved performance on machine translation.
[ 0.049829233437776566, -0.02904207445681095, 0.05616100877523422, -0.015232784673571587, 0.04972921684384346, 0.06738903373479843, -0.013544832356274128, 0.046393152326345444, -0.08895696699619293, -0.03272078558802605, -0.07803066819906235, 0.054094668477773666, -0.0015540359308943152, 0.029255466535687447, -0.007306880317628384, 0.040410857647657394, 0.050482165068387985, 0.010315082967281342, 0.016003841534256935, -0.02038581669330597, -0.034475430846214294, -0.014546811580657959, 0.06950168311595917, -0.013864945620298386, 0.05142577365040779, -0.0502915196120739, -0.0048519400879740715, -0.0420907661318779, -0.026079950854182243, 0.07815823704004288, -0.1781845986843109, -0.006036348640918732, -0.021610110998153687, 0.04742606729269028, -0.0005531895440071821, -0.030085235834121704, -0.11089563369750977, 0.04643843322992325, 0.017452368512749672, -0.04749755933880806, -0.031224379315972328, 0.04161204397678375, -0.08803579956293106, 0.012095976620912552, -0.01997012086212635, 0.030042823404073715, -0.17356495559215546, 0.06196354329586029, -0.05892588198184967, -0.06450863927602768, -0.09048507362604141, 0.037341244518756866, -0.025861209258437157, -0.03692326694726944, -0.03519941866397858, 0.03130585327744484, 0.004187267739325762, -0.1307830512523651, 0.03734603524208069, -0.023667827248573303, 0.006202644668519497, -0.002036585006862879, 0.0055083585903048515, 0.011733983643352985, -0.00319785438477993, 0.015104765072464943, 0.009576531127095222, 0.015666432678699493, -0.09089280664920807, 0.023600542917847633, -0.026747949421405792, -0.04681401699781418, -0.028158877044916153, -0.008376958779990673, -0.0229501873254776, -0.024000050500035286, 0.0005654365522786975, 0.010440773330628872, 0.04221596568822861, 0.026503732427954674, -0.012619704008102417, 0.10016290098428726, 0.062119919806718826, 0.057899340987205505, 0.027482399716973305, 0.007507510483264923, 0.06032336875796318, -0.044686656445264816, -0.044737521559000015, 0.0948738157749176, -0.0009959094459190965, -0.14242467284202576, 0.002049722708761692, -0.009157292544841766, 0.0491366870701313, -0.015238913707435131, 0.030281294137239456, 0.06487240642309189, -0.007976370863616467, 0.014742656610906124, 0.01628749445080757, -0.02394706942141056, 0.06544531881809235, -0.04716368019580841, -0.1039268895983696, 0.04888058081269264, 0.003970241639763117, -0.06483857333660126, -0.07332981377840042, 0.0060390932485461235, -0.013584701344370842, 0.06784090399742126, 0.06460076570510864, 0.04024385288357735, -0.061282820999622345, 0.037108827382326126, 0.019168563187122345, 0.0335138775408268, -0.022630926221609116, -0.02570902369916439, 0.05350825935602188, 0.04011780023574829, 0.032272275537252426, 0.0004857101012021303, -0.024657249450683594, -0.01336017157882452, 0.0074411556124687195, -0.06480443477630615, -0.06605610996484756, -0.052060022950172424, -0.015551344491541386, 0.0036876180674880743, 0.05862369015812874, 0.040616683661937714, -0.009945318102836609, 0.012212548404932022, 0.004769408609718084, -0.04171409457921982, -0.012361915782094002, -0.009355628862977028, -0.04391886666417122, 0.053813304752111435, 0.005996559746563435, 0.014454060234129429, 0.06439875066280365, -0.03580858185887337, -0.02743684872984886, 0.00339337345212698, 0.010489353910088539, 0.04865041375160217, -0.009880512952804565, 0.0809694454073906, -0.0330619178712368, -0.05501990765333176, 0.015479693189263344, 0.057120371609926224, -0.0310478787869215, -0.023582827299833298, -0.058451224118471146, -0.017814571037888527, -0.032182224094867706, 0.020508764311671257, 0.007942602969706059, 0.010297332890331745, 0.01757311075925827, -0.09783866256475449, 0.034377265721559525, 0.07850722223520279, 0.0004704707534983754, -0.01237138919532299, -0.008852820843458176, 0.002730581909418106, 0.006919809151440859, -0.020388547331094742, 0.00549250328913331, 0.0025681068655103445, -0.019760293886065483, 0.013525301590561867, 0.04161177948117256, 0.002794852014631033, -0.050576724112033844, -0.03126323223114014, 0.018204744905233383, -0.019197793677449226, 0.031797103583812714, -0.10296347737312317, 0.001897342735901475, 0.0014748240355402231, -0.04461213946342468, 0.03426407277584076, -0.08113517612218857, -0.03522118180990219, 0.06511371582746506, 0.010327245108783245, -0.014843114651739597, -0.07586000114679337, 0.005881433840841055, 0.18111515045166016, 0.02489500865340233, 0.07828827202320099, 0.06391030550003052, 0.032513346523046494, 0.04188867285847664, -0.022059759125113487, -0.03181429207324982, 0.054735638201236725, -0.055529505014419556, -0.03061565011739731, 0.019054820761084557, 0.003218558384105563, 0.021015383303165436, -0.09044183045625687, 0.02822181209921837, -0.10835997015237808, 0.01583370566368103, -0.0018867931794375181, 0.01698901876807213, 0.02053278684616089, 0.026666635647416115, -0.01232511643320322, 0.16159780323505402, -0.04067886248230934, -0.013411266729235649, 0.012520348653197289, -0.0286271832883358, 0.0706494078040123, 0.04020330682396889, 0.007067093160003424, 0.01776062324643135, -0.0831066370010376, 0.0028018273878842592, -0.01846042461693287, 0.007838237099349499, 0.034473780542612076, -0.020095279440283775, -0.008384774439036846, -0.016561485826969147, -0.003679015440866351, -0.011679830960929394, 0.01615072786808014, 0.03304191306233406, 0.05557320639491081, -0.026660187169909477, 0.036039695143699646, -0.06944535672664642, -0.01609039306640625, 0.05445113778114319, -0.012484900653362274, -0.009359550662338734, -0.02697293646633625, -0.07023104280233383, 0.08116044849157333, 0.01122595276683569, 0.0022353765089064837, 0.01770026609301567, 0.06307976692914963, 0.006030111573636532, -0.01798461563885212, 0.0028496901504695415, 0.004796638153493404, -0.035419464111328125, -0.016005152836441994, -0.0033642188645899296, -0.049309611320495605, -0.014466994442045689, -0.021080438047647476, 0.0234497282654047, -0.03005051054060459, 0.0027882929425686598, 0.02538280189037323, 0.012715332210063934, 0.01431394275277853, -0.007530206348747015, 0.037776168435811996, -0.015730349346995354, -0.016243884339928627, 0.03336456045508385, -0.0427425354719162, -0.027577867731451988, -0.03579774498939514, -0.018990572541952133, -0.012413407675921917, 0.039570823311805725, 0.04167168214917183, 0.03699234873056412, -0.016392987221479416, 0.028497908264398575, -0.03240161016583443, -0.013118015602231026, 0.011771684512495995, 0.012293129228055477, 0.019542230293154716, -0.021999267861247063, -0.03067745640873909, 0.003464157460257411, 0.004490075167268515, -0.0069736577570438385, -0.005082675721496344, 0.019287198781967163, 0.026890018954873085, 0.011415661312639713, -0.0033713041339069605, -0.0019842751789838076, 0.010765548795461655, -0.035550426691770554, 0.039174702018499374, 0.0315450057387352, 0.031806088984012604, -0.10922553390264511, -0.03157346323132515, 0.008812927640974522, 0.024264777079224586, 0.01022376585751772, -0.004338093567639589, 0.032929759472608566, -0.01775210350751877, 0.0066978042013943195, -0.010042603127658367, -0.002444889396429062, 0.018641598522663116, 0.03406935930252075, -0.007575985509902239, 0.02346125803887844, -0.02004668116569519, -0.020787030458450317, -0.022053122520446777, 0.037788040935993195, 0.03592246025800705, 0.0031443259213119745, 0.020925821736454964, -0.006184055469930172, -0.0023988557513803244, -0.05787624046206474, -0.014462233521044254, 0.03215082734823227, 0.006430090870708227, 0.03153984621167183, -0.03577406331896782, -0.055414676666259766, 0.022997858002781868, -0.019735101610422134, 0.012795739807188511, -0.017028020694851875, -0.02091122977435589, 0.03173379972577095, -0.0008991607464849949, 0.015935976058244705, 0.040827445685863495, 0.0031937328167259693, -0.04088765010237694, -0.036549776792526245, -0.010499207302927971, -0.025380074977874756, -0.02090584672987461, -0.007515823468565941, 0.0023890763986855745, 0.02542470209300518, -0.05584152042865753, -0.010048030875623226, -0.028536980971693993, 0.007458825595676899, 0.05187862366437912, 0.028025496751070023, 0.02079392597079277, -0.022457551211118698, -0.009623836725950241, 0.03543594107031822, -0.004887647461146116, -0.006799960043281317, 0.020782453939318657, 0.002758744405582547, -0.032519370317459106, -0.021732155233621597, 0.0842534676194191, -0.016177840530872345, 0.030037716031074524, 0.026829339563846588, 0.0798071101307869, -0.008152859285473824, 0.056610461324453354, 0.012232563458383083, -0.00018416985403746367, -0.02873242273926735, 0.010672048665583134, -0.03757626563310623, -0.021950483322143555, 0.06351689994335175, 0.0075219725258648396, -0.006014936603605747, -0.007762925233691931, -0.053683340549468994, 0.0030587087385356426, 0.016247456893324852, 0.032834261655807495, 0.012121101841330528, 0.015748612582683563, 0.0119705805554986, 0.013429799117147923, 0.005728720221668482, -0.01699173077940941, 0.015238093212246895, 0.019591109827160835, -0.006606273353099823, -0.045257847756147385, 0.006522562820464373, -0.02762497030198574, 0.03381846100091934, 0.006497830618172884, 0.019077716395258904, -0.05224316939711571, -0.00590700376778841, -0.01964862085878849, -0.025136534124612808, 0.014197216369211674, -0.03256228193640709, 0.020765263587236404, 0.014100592583417892, 0.008600457571446896, -0.015725957229733467, -0.02941819280385971, 0.029233573004603386, -0.030331896618008614, 0.03353650122880936, -0.005703360307961702, -0.004840820096433163, -0.030414719134569168, -0.06651416420936584, -0.013639797456562519, -0.0393792949616909, 0.006077776197344065, 0.018786253407597542, 0.0010441647609695792, 0.016041498631238937, -0.009095745161175728, 0.017742270603775978, 0.00504846079275012, 0.006873934529721737, 0.027406824752688408, 0.013251835480332375, 0.010375871323049068, 0.01852896437048912, -0.003659550566226244, 0.0203044805675745, 0.018420256674289703, -0.01329005602747202, -0.007988582365214825, -0.03862226754426956, -0.0401449128985405, 0.005126690957695246, 0.025148915126919746, 0.020908648148179054, -0.016604814678430557, 0.02086343988776207, 0.0009878113633021712, -0.003943562973290682, 0.013606484979391098, -0.00008654411067254841, 0.020626245066523552, 0.034257929772138596, 0.03470846265554428, -0.03506874665617943, 0.026676712557673454, 0.06123719364404678, -0.032686952501535416, -0.0008763095829635859, 0.04696998372673988, 0.003955161664634943, 0.04049625247716904, -0.019782843068242073, -0.05818648636341095, -0.016687363386154175, 0.0381661057472229, 0.011531650088727474, 0.009909200482070446, -0.013025375083088875, -0.026751410216093063, 0.008206394501030445, 0.010015237145125866, 0.016612978652119637, -0.043115291744470596, -0.021197011694312096, -0.02027292363345623, 0.003597470698878169, 0.02669047936797142, 0.030440522357821465, -0.0004820764879696071, -0.013581070117652416, 0.04534311220049858, -0.0036251824349164963, -0.002398573560640216, 0.01932421140372753, 0.00024655525339767337, 0.05182402953505516, -0.003892293432727456, 0.07692757248878479, 0.04448347166180611, 0.027622375637292862, 0.03252391889691353, -0.004770382307469845, 0.015875568613409996, 0.030482083559036255, -0.05443457514047623, -0.00447249598801136, 0.034714002162218094, 0.012052941136062145, 0.022717583924531937, -0.014756601303815842, 0.016025442630052567, -0.01611761376261711, 0.022205369547009468, 0.003926992882043123, -0.028340961784124374, -0.004138960037380457, 0.004067644011229277, -0.03679808974266052, -0.029828473925590515, -0.016143422573804855, -0.021885588765144348, -0.04264308512210846, -0.0031805275939404964, -0.051327183842659, -0.038268085569143295, -0.006227477453649044, -0.03264489769935608, -0.02536090463399887, 0.05575832352042198, 0.02515149861574173, 0.07008098810911179, -0.008208573795855045, -0.0028749590273946524, 0.022380663082003593, 0.015906983986496925, 0.02415953204035759, -0.0033965990878641605, -0.018387414515018463, -0.0207681804895401, 0.023906029760837555, 0.03403293713927269, 0.03566649556159973, -0.04237564653158188, 0.008885184302926064, 0.009531480260193348, -0.004306721966713667, -0.03749817609786987, -0.0010891702258959413, 0.06908649951219559, 0.017850853502750397, -0.009998495690524578, 0.004742571618407965, -0.00933568924665451, -0.023540863767266273, 0.027137085795402527, -0.03859804570674896, 0.04110192880034447, 0.04547589272260666, -0.013975955545902252, -0.026690028607845306, 0.007831824012100697, 0.05859377607703209, -0.044536106288433075, -0.006949913688004017, 0.021086685359477997, 0.009350327774882317, 0.03664169833064079, -0.0015493707032874227, -0.0013553401222452521, -0.0040574208833277225, 0.0014619191642850637, -0.0010473006404936314, -0.0499979630112648, 0.010864360257983208, 0.02860235795378685, -0.04759572073817253, -0.008125033229589462, -0.010846883058547974, -0.023807870224118233, 0.042801495641469955, 0.06081375107169151, 0.01666335202753544, 0.011958462186157703, -0.03258514404296875, 0.03348546475172043, -0.006764973048120737, 0.007388652767986059, -0.013533473014831543, 0.030543528497219086, 0.011658341623842716, 0.050660792738199234, 0.01103142462670803, 0.027439726516604424, 0.04757724702358246, -0.009352452121675014, 0.015363607555627823, 0.012615702114999294, 0.05856039747595787, 0.0008533441578038037, 0.024780843406915665, -0.029795804992318153, -0.013540987856686115, -0.018395353108644485, -0.014392801560461521, -0.025347711518406868, -0.05735092982649803, 0.022392122074961662, 0.04011500999331474, -0.01780051924288273, 0.049557339400053024, -0.016264230012893677, 0.021109474822878838, 0.04444415122270584, -0.015080675482749939, 0.008556392975151539, -0.018224185332655907, 0.030923210084438324, 0.007887644693255424, 0.021582158282399178, 0.016503620892763138, 0.002769282553344965, 0.009188991039991379, 0.06082196906208992, 0.04398224875330925, 0.024586329236626625, -0.005503455642610788, -0.025245441123843193, 0.025165032595396042, 0.001629021018743515, 0.023662472143769264, 0.025266200304031372, 0.013903699815273285, -0.017461009323596954, -0.015735097229480743, -0.003592828521504998, -0.03536536917090416, 0.04643405228853226, -0.014044912531971931, 0.0008064015419222414, -0.0008974230149760842, -0.02453693002462387, -0.013438964262604713, 0.05472432076931, -0.02423946000635624, -0.026419008150696754, -0.008342470042407513, -0.03108581155538559, 0.006292696576565504, -0.001851749373599887, -0.007611770648509264, 0.0012605293886736035, -0.006492930930107832, -0.033205095678567886, 0.019566504284739494, -0.005502417683601379, -0.02968772128224373, -0.04360328987240791, 0.030709415674209595, 0.016003744676709175, -0.037118833512067795, 0.04316510632634163, 0.013104439713060856, 0.02925674058496952, -0.010303475894033909, 0.012156674638390541, -0.04942930489778519, 0.03209115192294121, -0.0014512495836243033, -0.035054657608270645, -0.015620973892509937, -0.026820767670869827, 0.026353495195508003, 0.014615826308727264, 0.04082072898745537, -0.04429249092936516, -0.015365980565547943, -0.007337052840739489, -0.012515740469098091, 0.01500556617975235, -0.0000805195959401317, 0.005029141437262297, 0.016364408656954765, 0.007286513224244118, -0.01650199666619301, -0.04696269705891609, -0.027731793001294136, -0.00918413233011961, 0.03121001459658146, -0.01359379943460226, -0.02034025453031063, -0.03142022341489792, 0.04635460302233696, 0.018206052482128143, 0.01962471194565296, 0.05586054176092148, 0.033728018403053284, 0.011718669906258583, -0.03077082335948944, 0.045128077268600464, -0.010957367718219757, 0.04833569750189781, -0.04475961998105049, -0.07443615794181824, -0.039829034358263016, 0.0296464953571558, 0.0025421183090656996, 0.005228016525506973, -0.028902195394039154, 0.009590829722583294, -0.038370855152606964, 0.008755767717957497, -0.047548808157444, -0.013765156269073486, 0.05515860393643379, 0.03457007557153702, 0.018394462764263153, -0.028715912252664566, 0.015225213021039963, 0.004011808428913355, 0.009592905640602112, 0.015410502441227436, 0.0425601601600647, -0.011298350058495998, -0.008553453721106052, -0.012709700502455235, 0.022751841694116592, -0.06397261470556259, -0.009209267795085907, 0.020782355219125748, 0.0536482110619545, -0.018324941396713257, 0.017391642555594444, 0.014787448570132256, -0.027352748438715935, -0.007155152037739754, 0.026593554764986038, -0.000747035606764257, -0.024530183523893356, 0.022455235943198204, -0.007407747209072113, -0.04865449294447899, -0.014263985678553581, 0.022445768117904663, -0.006777153816074133, 0.04086418077349663, 0.015847399830818176, 0.03321181610226631, -0.005732478108257055, -0.045100562274456024, -0.0020422355737537146, 0.01931612938642502, 0.015999335795640945, -0.024342847988009453, 0.02824063040316105, 0.028744002804160118, -0.02119218371808529, -0.02968757413327694, 0.023258088156580925, 0.010791814886033535, 0.00045562488958239555, -0.022762946784496307, 0.0057466416619718075, -0.005637073423713446, -0.04987788945436478, 0.025163063779473305, -0.01570327952504158, 0.05761868879199028, 0.044876016676425934, -0.007151809521019459, 0.0034538833424448967, 0.0038229834754019976 ]
Transformer-based Encoder-Decoder Models
patrickvonplaten
October 10, 2020
encoder-decoder
research, nlp
https://huggingface.co/blog/encoder-decoder
Appendix As mentioned above, the following code snippet shows how one can program a simple generation method for transformer-based encoder-decoder models. Here, we implement a simple greedy decoding method using torch.argmax to sample the target vector. python from transformers import MarianMTModel, MarianTokenizer import torch tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-de") model = MarianMTModel.from_pretrained("Helsinki-NLP/opus-mt-en-de") # create ids of encoded input vectors input_ids = tokenizer("I want to buy a car", return_tensors="pt").input_ids # create BOS token decoder_input_ids = tokenizer("<pad>", add_special_tokens=False, return_tensors="pt").input_ids assert decoder_input_ids[0, 0].item() == model.config.decoder_start_token_id, "`decoder_input_ids` should correspond to `model.config.decoder_start_token_id`" # STEP 1 # pass input_ids to encoder and to decoder and pass BOS token to decoder to retrieve first logit outputs = model(input_ids, decoder_input_ids=decoder_input_ids, return_dict=True) # get encoded sequence encoded_sequence = (outputs.encoder_last_hidden_state,) # get logits lm_logits = outputs.logits # sample last token with highest prob next_decoder_input_ids = torch.argmax(lm_logits[:, -1:], axis=-1) # concat decoder_input_ids = torch.cat([decoder_input_ids, next_decoder_input_ids], axis=-1) # STEP 2 # reuse encoded_inputs and pass BOS + "Ich" to decoder to second logit lm_logits = model(None, encoder_outputs=encoded_sequence, decoder_input_ids=decoder_input_ids, return_dict=True).logits # sample last token with highest prob again next_decoder_input_ids = torch.argmax(lm_logits[:, -1:], axis=-1) # concat again decoder_input_ids = torch.cat([decoder_input_ids, next_decoder_input_ids], axis=-1) # STEP 3 lm_logits = model(None, encoder_outputs=encoded_sequence, decoder_input_ids=decoder_input_ids, return_dict=True).logits next_decoder_input_ids = torch.argmax(lm_logits[:, -1:], axis=-1) decoder_input_ids = torch.cat([decoder_input_ids, next_decoder_input_ids], axis=-1) # let's see what we have generated so far! print(f"Generated so far: {tokenizer.decode(decoder_input_ids[0], skip_special_tokens=True)}") # This can be written in a loop as well. Outputs: Generated so far: Ich will ein In this code example, we show exactly what was described earlier. We pass an input \"I want to buy a car\" together with the \(\text{BOS}\) token to the encoder-decoder model and sample from the first logit \(\mathbf{l}_1\) (i.e.* the first lm_logits line). Hereby, our sampling strategy is simple: greedily choose the next decoder input vector that has the highest probability. In an auto-regressive fashion, we then pass the sampled decoder input vector together with the previous inputs to the encoder-decoder model and sample again. We repeat this a third time. As a result, the model has generated the words \"Ich will ein\". The result is spot-on - this is the beginning of the correct translation of the input. In practice, more complicated decoding methods are used to sample the lm_logits. Most of which are covered in this blog post.
[ 0.017948029562830925, 0.016749555245041847, 0.018312562257051468, -0.003837289521470666, 0.010432821698486805, 0.07480823248624802, 0.05509888753294945, -0.02648375928401947, -0.04487813636660576, 0.03700028359889984, -0.10049944370985031, 0.039042405784130096, -0.009632190689444542, 0.06560436636209488, -0.021733462810516357, -0.06093139946460724, 0.006511966232210398, 0.005732680205255747, 0.016441281884908676, 0.015257496386766434, 0.03351064398884773, -0.06817598640918732, 0.034891046583652496, 0.007132051046937704, 0.06929858028888702, -0.04115261137485504, 0.008293136022984982, -0.004645821638405323, -0.04909293353557587, 0.060901183634996414, -0.0896935760974884, 0.004801157861948013, 0.014265880919992924, -0.02321331761777401, -0.014358099550008774, 0.011032461188733578, -0.13286912441253662, -0.0010376989375799894, 0.024336077272892, -0.017971221357584, -0.012715263292193413, 0.004393909126520157, -0.030276022851467133, 0.051510605961084366, 0.04009300470352173, -0.01611177623271942, -0.1605544090270996, 0.08265304565429688, -0.07997677475214005, -0.08463997393846512, -0.04648878052830696, 0.024165796115994453, -0.04350863769650459, 0.027621150016784668, -0.006591512821614742, 0.032109908759593964, 0.007810985203832388, -0.10752595216035843, 0.033169738948345184, 0.008554400876164436, 0.007437517400830984, 0.037094298750162125, 0.03194832056760788, 0.05031929165124893, 0.023138996213674545, 0.03953685238957405, -0.02856706641614437, 0.03337275609374046, -0.017902281135320663, -0.04095908999443054, 0.015135510824620724, -0.06483983248472214, -0.04754946380853653, 0.018582619726657867, 0.008573772385716438, -0.07689651846885681, 0.02780657447874546, 0.012502182275056839, 0.08896000683307648, 0.12360818684101105, -0.017970915883779526, 0.05814475566148758, 0.04809943214058876, -0.01403608825057745, 0.07588479667901993, 0.03813078626990318, 0.005364437587559223, -0.0013336288975551724, 0.010931846685707569, 0.07311467826366425, -0.07699549943208694, -0.16103433072566986, -0.018070640042424202, -0.02616405487060547, 0.04454352706670761, -0.009528794325888157, 0.022436227649450302, 0.038523685187101364, -0.04282863065600395, -0.0343136265873909, 0.03736218437552452, -0.02644965797662735, 0.032044634222984314, -0.045957937836647034, -0.09410247951745987, 0.0064352587796747684, 0.005416924599558115, -0.06071129068732262, -0.014826000668108463, -0.01580958440899849, 0.006166235078126192, -0.013058836571872234, 0.00960768386721611, 0.07523009926080704, -0.03883722797036171, -0.05360815301537514, -0.0075430055148899555, -0.01721169799566269, -0.05563509464263916, -0.018668293952941895, -0.03797178715467453, 0.08183085173368454, -0.021953554823994637, -0.014045952819287777, -0.03408109024167061, 0.05623064190149307, 0.0007181544788181782, 0.018596332520246506, -0.012814868241548538, -0.002953944029286504, 0.04334692284464836, -0.009053850546479225, 0.0441989041864872, 0.026466554030776024, -0.0019718732219189405, -0.001967892050743103, 0.015461679548025131, -0.050284259021282196, -0.05462212488055229, -0.014238887466490269, -0.04860999435186386, 0.02010340243577957, -0.019241878762841225, -0.004215813707560301, -0.025024907663464546, -0.028444306924939156, -0.04759162291884422, 0.1246228888630867, 0.05596572160720825, 0.053722482174634933, -0.03562522679567337, 0.019153043627738953, 0.018781526014208794, -0.028473997488617897, -0.016857357695698738, 0.034236762672662735, -0.053293850272893906, 0.018600061535835266, -0.09191568940877914, -0.03287968784570694, 0.007178108207881451, 0.036425746977329254, -0.02771880477666855, 0.028522759675979614, -0.03282734751701355, -0.07449009269475937, 0.0018808323657140136, 0.0725887194275856, -0.036962345242500305, 0.02507062815129757, 0.01316017471253872, 0.02246621623635292, 0.02749595418572426, 0.013656634837388992, -0.006651099305599928, 0.027771275490522385, 0.00968200247734785, 0.07410221546888351, -0.010536909103393555, -0.06050601974129677, -0.0519520603120327, 0.024580901488661766, -0.04089432209730148, 0.05006720498204231, 0.06646961718797684, -0.04435774311423302, -0.04106879606842995, 0.0023803766816854477, -0.02767309732735157, 0.034018903970718384, -0.0515722893178463, -0.03939218819141388, 0.04923729598522186, -0.010929656215012074, 0.03927898779511452, -0.029914669692516327, -0.04440102353692055, 0.06755782663822174, 0.01369110681116581, 0.044269248843193054, 0.011856256052851677, 0.0038640196435153484, 0.006731526460498571, -0.02067389339208603, -0.02831907942891121, -0.031169943511486053, -0.059321075677871704, -0.05712733417749405, 0.06831896305084229, 0.06675287336111069, 0.02669716812670231, -0.06255954504013062, -0.01951643079519272, -0.11144369095563889, 0.027266239747405052, -0.00997689925134182, -0.0718812495470047, 0.013289457187056541, 0.03670187667012215, 0.018879113718867302, 0.1392594873905182, -0.07338336855173111, 0.002165938029065728, -0.038068439811468124, -0.024804560467600822, 0.06424658745527267, 0.051616571843624115, 0.00023188504565041512, 0.0580313466489315, -0.07546959072351456, 0.003664139425382018, -0.06305907666683197, -0.042846620082855225, 0.05760670453310013, -0.08681873977184296, -0.07692665606737137, 0.02237367443740368, 0.0325937494635582, -0.026368161663413048, 0.002460246440023184, 0.007607543375343084, 0.03129645064473152, -0.03221548721194267, 0.03141452372074127, -0.020987462252378464, -0.008399066515266895, 0.06736702471971512, -0.031200144439935684, -0.002583883237093687, 0.023270267993211746, -0.07014442980289459, 0.08025828003883362, -0.036082345992326736, -0.09142020344734192, 0.020827045664191246, 0.043428752571344376, -0.022789228707551956, -0.02214721217751503, -0.007511592470109463, 0.03566926717758179, -0.0053785997442901134, -0.014219527132809162, -0.05280674248933792, -0.06653546541929245, -0.03299243003129959, -0.018230238929390907, 0.01917816884815693, 0.031885165721178055, -0.00307342573069036, 0.024925757199525833, -0.0008709401590749621, 0.0009587160311639309, 0.03115769661962986, 0.011314363218843937, 0.022066300734877586, 0.04784722626209259, 0.0336545929312706, -0.023920612409710884, -0.03728242963552475, -0.004331506323069334, -0.04536992684006691, -0.029885463416576385, 0.024308960884809494, 0.028286786749958992, -0.0029900388326495886, 0.011375727131962776, -0.02079436369240284, -0.021516162902116776, -0.000022931373678147793, 0.033791057765483856, 0.0006042413879185915, 0.059969909489154816, -0.005574529059231281, 0.009810416959226131, -0.019168341532349586, 0.01568768359720707, -0.002573629142716527, -0.01074659638106823, -0.03355640172958374, 0.01864081621170044, -0.05247264727950096, -0.012729635462164879, -0.014265477657318115, -0.010915403254330158, -0.048018403351306915, -0.01384101714938879, 0.06305532902479172, 0.03424028307199478, -0.08616776764392853, -0.032425060868263245, -0.012462682090699673, -0.019416505470871925, 0.012374652549624443, -0.0171734057366848, 0.032614484429359436, -0.0010621928377076983, -0.02162989228963852, 0.008144066669046879, 0.010748213157057762, 0.019289186224341393, -0.01641996204853058, 0.021367721259593964, -0.017378684133291245, -0.05262674391269684, 0.01347595825791359, 0.03424685820937157, 0.010668973438441753, -0.008419200778007507, 0.011274576187133789, 0.011230128817260265, -0.0004412440466694534, 0.023210326209664345, -0.04764380306005478, -0.009441649541258812, 0.035336147993803024, -0.0035239991266280413, 0.019819997251033783, 0.001562759978696704, -0.03811963275074959, -0.015041771344840527, -0.003074139356613159, -0.006835645530372858, -0.03153620660305023, -0.022222010418772697, 0.02334989421069622, -0.028827840462327003, 0.008677766658365726, 0.018972424790263176, -0.0023548761382699013, -0.0400470532476902, 0.00465012900531292, -0.014787334017455578, 0.020312374457716942, -0.011630658060312271, -0.0392252542078495, -0.005510276183485985, 0.0018418739782646298, -0.03501494601368904, -0.04556204378604889, 0.005972266662865877, 0.01474951021373272, 0.0362280011177063, 0.03439655527472496, 0.030540060251951218, -0.008236153051257133, 0.04916363209486008, 0.04843776300549507, 0.04780696704983711, -0.05250091850757599, 0.03531539440155029, -0.010267449542880058, -0.031167691573500633, -0.014905030839145184, 0.08221518248319626, 0.01735299453139305, 0.004866546019911766, -0.006868941243737936, 0.050267525017261505, 0.0024009367916733027, -0.0017222686437889934, -0.009108081459999084, 0.00769004924222827, -0.025263484567403793, 0.04435467720031738, -0.024926824495196342, -0.024511782452464104, 0.0620247907936573, -0.010322630405426025, -0.015408424660563469, -0.04521454870700836, -0.0611998550593853, -0.012284083291888237, -0.012578161433339119, 0.025329777970910072, 0.03149794414639473, -0.0230585727840662, 0.046518903225660324, -0.030116219073534012, 0.027607135474681854, -0.044947102665901184, 0.01467503234744072, -0.007930930703878403, -0.025273239240050316, -0.01933324709534645, -0.018298156559467316, 0.0061672646552324295, 0.017771568149328232, -0.01240847259759903, 0.02041485160589218, -0.08941426128149033, -0.009738546796143055, 0.013375531882047653, -0.019206520169973373, -0.0010856707813218236, -0.04946783185005188, -0.003548956476151943, 0.02011280320584774, -0.024560101330280304, -0.004880702123045921, -0.03656229376792908, 0.011451820842921734, -0.00717872753739357, 0.02074257843196392, 0.01619107648730278, 0.008677625097334385, -0.0643199160695076, 0.01650959625840187, -0.005380946211516857, -0.049879223108291626, 0.018240876495838165, 0.01817885972559452, -0.01683378778398037, 0.05313761532306671, -0.03588220849633217, 0.037334877997636795, 0.03588053956627846, -0.013158011250197887, 0.005498369224369526, -0.02485952340066433, 0.00381432194262743, 0.0563817135989666, 0.0001365530479233712, -0.00472057843580842, 0.047837622463703156, 0.0023256326094269753, -0.02084597386419773, 0.013331319205462933, -0.012014828622341156, -0.023166297003626823, 0.023401284590363503, 0.0473656952381134, -0.016500314697623253, 0.022778430953621864, 0.015135969035327435, 0.00929673109203577, -0.018378188833594322, -0.009641768410801888, -0.006303679198026657, 0.0516078919172287, -0.012332800775766373, -0.016130397096276283, -0.015323856845498085, 0.02299276739358902, -0.000505376432556659, 0.0023262242320924997, 0.07257277518510818, 0.023586608469486237, -0.0018226061947643757, -0.02478078380227089, -0.031667690724134445, -0.0228157639503479, 0.014309307560324669, 0.009482676163315773, 0.011579442769289017, -0.040919698774814606, -0.04306952655315399, 0.014023925177752972, 0.02582002617418766, -0.003711626399308443, -0.018465958535671234, 0.03610703721642494, -0.03607587516307831, -0.0152791328728199, 0.059466686099767685, 0.01248061005026102, 0.007940203882753849, -0.03482770174741745, 0.011862796731293201, 0.003392050974071026, -0.012682932429015636, 0.015058854594826698, 0.008783156983554363, 0.012363254092633724, 0.0217850673943758, 0.06550749391317368, 0.019299926236271858, 0.05715916305780411, 0.007358708418905735, -0.013722383417189121, -0.02104729786515236, 0.033950816839933395, -0.006810340099036694, -0.048260465264320374, 0.03835693374276161, -0.03120558150112629, 0.020630182698369026, -0.009652280248701572, 0.015117515809834003, 0.016824519261717796, 0.0390605553984642, 0.015610841102898121, -0.012063739821314812, 0.026215193793177605, -0.027623172849416733, -0.007891247980296612, -0.006658212281763554, -0.020274806767702103, -0.06274883449077606, 0.003017853247001767, 0.028843775391578674, -0.018148627132177353, 0.03689609095454216, 0.011105003766715527, -0.002758890390396118, -0.02337699942290783, -0.005007321015000343, 0.012516317889094353, 0.06253720819950104, -0.02578439563512802, -0.04115910828113556, 0.01578211970627308, 0.027501991018652916, 0.04576323553919792, 0.00006825095624662936, 0.012803329154849052, 0.031584806740283966, 0.013641596771776676, -0.015372991561889648, 0.04493435099720955, -0.02422219328582287, -0.004927186761051416, 0.05515854433178902, 0.014899030327796936, -0.025916360318660736, 0.01889660768210888, 0.037086375057697296, -0.002539754146710038, 0.013031807728111744, 0.050347212702035904, -0.03870661184191704, -0.024600962176918983, 0.05320186913013458, -0.04635239019989967, 0.04446709528565407, 0.01988900639116764, -0.003519551595672965, 0.005354872439056635, 0.00028227982693351805, 0.05811271443963051, 0.005920446943491697, -0.04176799952983856, -0.0031745960004627705, 0.02985640987753868, 0.006265150848776102, 0.026875952258706093, 0.013892155140638351, -0.007959435693919659, 0.038616497069597244, 0.03599914163351059, -0.03847947716712952, 0.0014822306111454964, 0.05091974884271622, -0.029680518433451653, 0.05047731474041939, -0.022024868056178093, -0.01873503439128399, -0.003474803175777197, -0.024743566289544106, 0.0471547394990921, 0.027552053332328796, 0.014022085815668106, 0.04007163643836975, 0.008864754810929298, -0.0059984419494867325, 0.006249900907278061, 0.06814800947904587, -0.028238767758011818, 0.047100502997636795, -0.014422479085624218, 0.013543164357542992, 0.014796189032495022, 0.04289114475250244, 0.02275768853724003, 0.040307290852069855, 0.07257352769374847, 0.01865164376795292, -0.007390468847006559, -0.019550198689103127, 0.02839215099811554, 0.004179053939878941, -0.04115261510014534, 0.0058177984319627285, 0.017668569460511208, -0.012696435675024986, 0.029631871730089188, -0.03807546943426132, 0.03948243707418442, -0.014603419229388237, 0.04576197266578674, 0.026952320709824562, 0.011536982841789722, -0.027073947712779045, 0.05016637593507767, 0.04778778925538063, 0.02485087141394615, 0.034588687121868134, 0.01994219236075878, 0.04252694919705391, 0.00722948694601655, 0.036479152739048004, -0.0014582652365788817, 0.004734157118946314, 0.054178837686777115, -0.035265713930130005, -0.0018560055177658796, -0.0368257574737072, -0.02239011600613594, -0.005321502219885588, 0.01747928559780121, 0.015075444243848324, -0.014080828055739403, 0.027007747441530228, -0.025851354002952576, 0.033878669142723083, -0.027533158659934998, -0.03720085695385933, -0.005795375443994999, -0.005305387079715729, -0.04152285307645798, 0.0689091831445694, -0.013993536122143269, -0.02643500827252865, 0.010096452198922634, -0.005721799097955227, 0.026777192950248718, 0.03257771581411362, -0.025670604780316353, -0.006605091970413923, -0.040194202214479446, -0.01925606094300747, -0.024690989404916763, -0.03395002335309982, -0.030173294246196747, -0.011998040601611137, 0.022412022575736046, 0.01727265678346157, -0.007945386692881584, 0.04873332008719444, 0.025220301002264023, 0.009324440732598305, -0.02673855610191822, -0.0019790027290582657, 0.00847606547176838, 0.005483975633978844, 0.036004770547151566, -0.030973613262176514, 0.004716217517852783, 0.008686401881277561, 0.043380219489336014, -0.0007734629325568676, 0.033529624342918396, -0.045272450894117355, -0.05206248164176941, -0.004349877126514912, 0.0019653518684208393, -0.025567196309566498, 0.01626693829894066, -0.03040521964430809, 0.01976666785776615, 0.029473399743437767, -0.022434646263718605, -0.006242753006517887, 0.001452391967177391, -0.009973756037652493, 0.07829248905181885, 0.0000983723730314523, -0.03026602417230606, -0.027505477890372276, 0.05481325834989548, 0.00743489945307374, 0.002476721303537488, 0.052668169140815735, 0.0161756481975317, 0.014279971830546856, 0.0027205636724829674, 0.004406910855323076, -0.02541370503604412, -0.025663210079073906, -0.04673685133457184, -0.05981796607375145, 0.005951357539743185, 0.03657269850373268, -0.008874687366187572, 0.03658803924918175, -0.0431392565369606, 0.030469253659248352, -0.05301884561777115, -0.010110463947057724, -0.05131199210882187, 0.009308104403316975, 0.04509793594479561, 0.0059453509747982025, 0.03916866332292557, -0.0022461393382400274, -0.04191888868808746, -0.03155224025249481, -0.01075813826173544, 0.0028565609827637672, 0.03810165822505951, 0.007828054949641228, 0.04708511382341385, -0.059398312121629715, -0.0017945722211152315, 0.008786872960627079, -0.0009921920718625188, 0.023657364770770073, 0.004399989265948534, -0.035452958196401596, -0.00578265031799674, 0.02058892510831356, 0.01138017512857914, 0.0072824168018996716, -0.00807102955877781, -0.0014884325210005045, -0.004678530618548393, -0.02279157005250454, 0.013907973654568195, -0.025150340050458908, -0.003960833419114351, -0.0023644494358450174, -0.0194855947047472, 0.0074860225431621075, 0.024009350687265396, 0.030110495164990425, 0.01940065622329712, -0.012711930088698864, -0.018746187910437584, 0.027768459171056747, 0.020160628482699394, -0.024150852113962173, -0.009539132937788963, 0.03967569023370743, -0.0010031589772552252, -0.025980712845921516, 0.048392899334430695, 0.028834640979766846, -0.0263026412576437, 0.027958663180470467, -0.009961089119315147, -0.0052492935210466385, 0.02460993453860283, -0.005930355750024319, 0.011780188418924809, 0.06868702173233032, -0.006563700735569, -0.011610982939600945, 0.021721409633755684, 0.0001749441580614075 ]
Transformer-based Encoder-Decoder Models
patrickvonplaten
October 10, 2020
encoder-decoder
research, nlp
https://huggingface.co/blog/encoder-decoder
Encoder As mentioned in the previous section, the transformer-based encoder maps the input sequence to a contextualized encoding sequence: $$ f{\theta_{\text{enc}}}: \mathbf{X}{1:n} \to \mathbf{\overline{X}}{1:n}. $$ Taking a closer look at the architecture, the transformer-based encoder is a stack of residual encoder blocks. Each encoder block consists of a bi-directional self-attention layer, followed by two feed-forward layers. For simplicity, we disregard the normalization layers in this notebook. Also, we will not further discuss the role of the two feed-forward layers, but simply see it as a final vector-to-vector mapping required in each encoder block \({}^1\). The bi-directional self-attention layer puts each input vector \(\mathbf{x'}j, \forall j \in {1, \ldots, n}\) into relation with all input vectors \(\mathbf{x'}_1, \ldots, \mathbf{x'}_n\) and by doing so transforms the input vector \(\mathbf{x'}_j\) to a more \"refined\" contextual representation of itself, defined as \(\mathbf{x''}_j\). Thereby, the first encoder block transforms each input vector of the input sequence \(\mathbf{X}{1:n}\) (shown in light green below) from a context-independent vector representation to a context-dependent vector representation, and the following encoder blocks further refine this contextual representation until the last encoder block outputs the final contextual encoding \(\mathbf{\overline{X}}{1:n}\) (shown in darker green below). Let\'s visualize how the encoder processes the input sequence \"I want to buy a car EOS\" to a contextualized encoding sequence. Similar to RNN-based encoders, transformer-based encoders also add a special \"end-of-sequence\" input vector to the input sequence to hint to the model that the input vector sequence is finished \({}^2\). Our exemplary transformer-based encoder is composed of three encoder blocks, whereas the second encoder block is shown in more detail in the red box on the right for the first three input vectors \(\mathbf{x}_1, \mathbf{x}_2 and \mathbf{x}_3\). The bi-directional self-attention mechanism is illustrated by the fully-connected graph in the lower part of the red box and the two feed-forward layers are shown in the upper part of the red box. As stated before, we will focus only on the bi-directional self-attention mechanism. As can be seen each output vector of the self-attention layer \(\mathbf{x''}_i, \forall i \in {1, \ldots, 7}\) depends directly on all input vectors \(\mathbf{x'}_1, \ldots, \mathbf{x'}_7\). This means, e.g. that the input vector representation of the word \"want\", i.e. \(\mathbf{x'}_2\), is put into direct relation with the word \"buy\", i.e. \(\mathbf{x'}_4\), but also with the word \"I\",i.e. \(\mathbf{x'}_1\). The output vector representation of \"want\", i.e. \(\mathbf{x''}_2\), thus represents a more refined contextual representation for the word \"want\". Let\'s take a deeper look at how bi-directional self-attention works. Each input vector \(\mathbf{x'}_i\) of an input sequence \(\mathbf{X'}{1:n}\) of an encoder block is projected to a key vector \(\mathbf{k}i\), value vector \(\mathbf{v}_i\) and query vector \(\mathbf{q}_i\) (shown in orange, blue, and purple respectively below) through three trainable weight matrices \(\mathbf{W}_q, \mathbf{W}_v, \mathbf{W}_k\): $$ \mathbf{q}_i = \mathbf{W}_q \mathbf{x'}_i,$$ $$ \mathbf{v}_i = \mathbf{W}_v \mathbf{x'}_i,$$ $$ \mathbf{k}_i = \mathbf{W}_k \mathbf{x'}_i, $$ $$ \forall i \in {1, \ldots n }.$$ Note, that the same weight matrices are applied to each input vector \(\mathbf{x}_i, \forall i \in {i, \ldots, n}\). After projecting each input vector \(\mathbf{x}_i\) to a query, key, and value vector, each query vector \(\mathbf{q}_j, \forall j \in {1, \ldots, n}\) is compared to all key vectors \(\mathbf{k}_1, \ldots, \mathbf{k}_n\). The more similar one of the key vectors \(\mathbf{k}_1, \ldots \mathbf{k}_n\) is to a query vector \(\mathbf{q}_j\), the more important is the corresponding value vector \(\mathbf{v}_j\) for the output vector \(\mathbf{x''}_j\). More specifically, an output vector \(\mathbf{x''}_j\) is defined as the weighted sum of all value vectors \(\mathbf{v}_1, \ldots, \mathbf{v}_n\) plus the input vector \(\mathbf{x'}_j\). Thereby, the weights are proportional to the cosine similarity between \(\mathbf{q}_j\) and the respective key vectors \(\mathbf{k}_1, \ldots, \mathbf{k}_n\), which is mathematically expressed by \(\textbf{Softmax}(\mathbf{K}{1:n}^\intercal \mathbf{q}j)\) as illustrated in the equation below. For a complete description of the self-attention layer, the reader is advised to take a look at this blog post or the original paper. Alright, this sounds quite complicated. Let\'s illustrate the bi-directional self-attention layer for one of the query vectors of our example above. For simplicity, it is assumed that our exemplary transformer-based decoder uses only a single attention head config.num_heads = 1 and that no normalization is applied. On the left, the previously illustrated second encoder block is shown again and on the right, an in detail visualization of the bi-directional self-attention mechanism is given for the second input vector \(\mathbf{x'}_2\) that corresponds to the input word \"want\". At first all input vectors \(\mathbf{x'}_1, \ldots, \mathbf{x'}_7\) are projected to their respective query vectors \(\mathbf{q}_1, \ldots, \mathbf{q}_7\) (only the first three query vectors are shown in purple above), value vectors \(\mathbf{v}_1, \ldots, \mathbf{v}_7\) (shown in blue), and key vectors \(\mathbf{k}_1, \ldots, \mathbf{k}_7\) (shown in orange). The query vector \(\mathbf{q}_2\) is then multiplied by the transpose of all key vectors, i.e. \(\mathbf{K}{1:7}^{\intercal}\) followed by the softmax operation to yield the self-attention weights. The self-attention weights are finally multiplied by the respective value vectors and the input vector \(\mathbf{x'}2\) is added to output the \"refined\" representation of the word \"want\", i.e. \(\mathbf{x''}_2\) (shown in dark green on the right). The whole equation is illustrated in the upper part of the box on the right. The multiplication of \(\mathbf{K}{1:7}^{\intercal}\) and \(\mathbf{q}2\) thereby makes it possible to compare the vector representation of \"want\" to all other input vector representations \"I\", \"to\", \"buy\", \"a\", \"car\", \"EOS\" so that the self-attention weights mirror the importance each of the other input vector representations \(\mathbf{x'}_j \text{, with } j \ne 2\) for the refined representation \(\mathbf{x''}_2\) of the word \"want\". To further understand the implications of the bi-directional self-attention layer, let\'s assume the following sentence is processed: \"The house is beautiful and well located in the middle of the city where it is easily accessible by public transport\". The word \"it\" refers to \"house\", which is 12 \"positions away\". In transformer-based encoders, the bi-directional self-attention layer performs a single mathematical operation to put the input vector of \"house\" into relation with the input vector of \"it\" (compare to the first illustration of this section). In contrast, in an RNN-based encoder, a word that is 12 \"positions away\", would require at least 12 mathematical operations meaning that in an RNN-based encoder a linear number of mathematical operations are required. This makes it much harder for an RNN-based encoder to model long-range contextual representations. Also, it becomes clear that a transformer-based encoder is much less prone to lose important information than an RNN-based encoder-decoder model because the sequence length of the encoding is kept the same, i.e. \(\textbf{len}(\mathbf{X}{1:n}) = \textbf{len}(\mathbf{\overline{X}}_{1:n}) = n\), while an RNN compresses the length from \(\textbf{len}((\mathbf{X}{1:n}) = n\) to just \(\textbf{len}(\mathbf{c}) = 1\), which makes it very difficult for RNNs to effectively encode long-range dependencies between input words. In addition to making long-range dependencies more easily learnable, we can see that the Transformer architecture is able to process text in parallel.Mathematically, this can easily be shown by writing the self-attention formula as a product of query, key, and value matrices: $$\mathbf{X''}{1:n} = \mathbf{V}{1:n} \text{Softmax}(\mathbf{Q}{1:n}^\intercal \mathbf{K}{1:n}) + \mathbf{X'}{1:n}. $$ The output \(\mathbf{X''}{1:n} = \mathbf{x''}_1, \ldots, \mathbf{x''}_n\) is computed via a series of matrix multiplications and a softmax operation, which can be parallelized effectively. Note, that in an RNN-based encoder model, the computation of the hidden state \(\mathbf{c}\) has to be done sequentially: Compute hidden state of the first input vector \(\mathbf{x}_1\), then compute the hidden state of the second input vector that depends on the hidden state of the first hidden vector, etc. The sequential nature of RNNs prevents effective parallelization and makes them much more inefficient compared to transformer-based encoder models on modern GPU hardware. Great, now we should have a better understanding of a) how transformer-based encoder models effectively model long-range contextual representations and b) how they efficiently process long sequences of input vectors. Now, let\'s code up a short example of the encoder part of our MarianMT encoder-decoder models to verify that the explained theory holds in practice. ------------------------------------------------------------------------ \({}^1\) An in-detail explanation of the role the feed-forward layers play in transformer-based models is out-of-scope for this notebook. It is argued in Yun et. al, (2017) that feed-forward layers are crucial to map each contextual vector \(\mathbf{x'}_i\) individually to the desired output space, which the _self-attention layer does not manage to do on its own. It should be noted here, that each output token \(\mathbf{x'}\) is processed by the same feed-forward layer. For more detail, the reader is advised to read the paper. \({}^2\) However, the EOS input vector does not have to be appended to the input sequence, but has been shown to improve performance in many cases. In contrast to the 0th \(\text{BOS}\) target vector of the transformer-based decoder is required as a starting input vector to predict a first target vector. python from transformers import MarianMTModel, MarianTokenizer import torch tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-de") model = MarianMTModel.from_pretrained("Helsinki-NLP/opus-mt-en-de") embeddings = model.get_input_embeddings() # create ids of encoded input vectors input_ids = tokenizer("I want to buy a car", return_tensors="pt").input_ids # pass input_ids to encoder encoder_hidden_states = model.base_model.encoder(input_ids, return_dict=True).last_hidden_state # change the input slightly and pass to encoder input_ids_perturbed = tokenizer("I want to buy a house", return_tensors="pt").input_ids encoder_hidden_states_perturbed = model.base_model.encoder(input_ids_perturbed, return_dict=True).last_hidden_state # compare shape and encoding of first vector print(f"Length of input embeddings {embeddings(input_ids).shape[1]}. Length of encoder_hidden_states {encoder_hidden_states.shape[1]}") # compare values of word embedding of "I" for input_ids and perturbed input_ids print("Is encoding for `I` equal to its perturbed version?: ", torch.allclose(encoder_hidden_states[0, 0], encoder_hidden_states_perturbed[0, 0], atol=1e-3)) Outputs: Length of input embeddings 7. Length of encoder_hidden_states 7 Is encoding for `I` equal to its perturbed version?: False We compare the length of the input word embeddings, i.e. embeddings(input_ids) corresponding to \(\mathbf{X}{1:n}\), with the length of the encoder_hidden_states, corresponding to \(\mathbf{\overline{X}}{1:n}\). Also, we have forwarded the word sequence \"I want to buy a car\" and a slightly perturbated version \"I want to buy a house\" through the encoder to check if the first output encoding, corresponding to \"I\", differs when only the last word is changed in the input sequence. As expected the output length of the input word embeddings and encoder output encodings, i.e. \(\textbf{len}(\mathbf{X}{1:n})\) and \(\textbf{len}(\mathbf{\overline{X}}{1:n})\), is equal. Second, it can be noted that the values of the encoded output vector of \(\mathbf{\overline{x}}1 = \text{"I"}\) are different when the last word is changed from \"car\" to \"house\". This however should not come as a surprise if one has understood bi-directional self-attention. On a side-note, _autoencoding models, such as BERT, have the exact same architecture as transformer-based encoder models. Autoencoding models leverage this architecture for massive self-supervised pre-training on open-domain text data so that they can map any word sequence to a deep bi-directional representation. In Devlin et al. (2018), the authors show that a pre-trained BERT model with a single task-specific classification layer on top can achieve SOTA results on eleven NLP tasks. All autoencoding models of 🤗Transformers can be found here.
[ 0.039302073419094086, -0.01409150566905737, 0.08670409768819809, 0.0025014474522322416, 0.07266676425933838, 0.028486210852861404, -0.019741177558898926, 0.05136651545763016, -0.006705278530716896, -0.02622048184275627, -0.10144269466400146, 0.06614845991134644, 0.017483152449131012, 0.023185474798083305, -0.028099220246076584, 0.029712559655308723, 0.04568856954574585, -0.02075839228928089, -0.03087249957025051, -0.004698301199823618, -0.007818112149834633, -0.04251505434513092, 0.04269031062722206, -0.022699203342199326, -0.003103321883827448, -0.0009418099652975798, -0.018575072288513184, -0.007476138416677713, -0.08483926951885223, 0.09063158929347992, -0.08494146913290024, 0.003261969890445471, -0.013336961157619953, -0.05680442973971367, -0.007585257291793823, -0.04642106965184212, -0.12326636165380478, 0.0035230950452387333, 0.015238365158438683, -0.02286951243877411, 0.009239337407052517, -0.0036037424579262733, -0.057061657309532166, 0.034559063613414764, -0.03367084264755249, -0.006221902556717396, -0.17439758777618408, 0.10366266965866089, -0.07291198521852493, 0.009076736867427826, -0.05170843377709389, 0.03281490504741669, -0.06280115991830826, 0.10394955426454544, -0.0065125287510454655, 0.018013132736086845, -0.03122878074645996, -0.028203465044498444, 0.04813607037067413, -0.004382398445159197, 0.051792044192552567, 0.011255313642323017, -0.02528608776628971, 0.0853019580245018, 0.02370758168399334, 0.011211773380637169, -0.06558869779109955, 0.013440446928143501, -0.018590334802865982, -0.031338922679424286, -0.057118505239486694, -0.0064507839269936085, 0.02988326922059059, 0.014679419808089733, -0.012166673317551613, -0.06236577779054642, 0.02499409019947052, 0.027588605880737305, 0.09430018067359924, 0.030620887875556946, 0.026734106242656708, 0.04725947231054306, 0.07704151421785355, 0.10007263720035553, 0.033823639154434204, 0.023887084797024727, 0.05375821143388748, -0.06170349568128586, -0.009083420969545841, 0.07694016396999359, -0.0568886324763298, -0.14371539652347565, -0.035539884120225906, 0.002607170259580016, 0.02365001104772091, -0.07169704884290695, 0.0496281199157238, 0.02131149359047413, 0.0035159229300916195, 0.04875197634100914, 0.027526911348104477, -0.0012162727070972323, 0.08088105916976929, -0.06011144816875458, -0.010290336795151234, 0.022567378357052803, -0.00496255699545145, -0.07485554367303848, -0.05832693725824356, -0.008762326091527939, -0.00962901022285223, 0.027541136369109154, 0.009077885188162327, 0.02316356636583805, -0.07902009785175323, -0.006001427303999662, 0.005568415857851505, -0.038829971104860306, -0.026613973081111908, 0.011345747858285904, -0.024770550429821014, 0.08169057965278625, 0.07044023275375366, -0.02728588692843914, -0.020164400339126587, 0.0437481515109539, -0.047582026571035385, -0.03356378525495529, -0.05985759571194649, -0.05664858967065811, 0.03172287717461586, -0.00009115428110817447, 0.05644107982516289, 0.03230280056595802, -0.040026936680078506, -0.04808800667524338, -0.0019300547428429127, -0.07797057926654816, -0.014453832991421223, 0.006761213298887014, -0.06767420470714569, 0.022944355383515358, 0.03581104800105095, 0.0003918750153388828, 0.010123725049197674, -0.05134141445159912, -0.03232337161898613, 0.059327468276023865, 0.05478810891509056, 0.02753092162311077, 0.0011020742822438478, -0.004942505620419979, -0.014280184172093868, -0.07302175462245941, -0.017501717433333397, 0.03739256039261818, 0.03723056986927986, 0.0037249920424073935, -0.08279242366552353, 0.0029288323130458593, 0.012484720908105373, 0.0074732061475515366, 0.025399204343557358, 0.025367656722664833, 0.05563078820705414, -0.10143914073705673, 0.0466047041118145, 0.04913575202226639, -0.02080102078616619, 0.026973431929945946, 0.0024436211679130793, -0.03387676551938057, 0.023024380207061768, 0.010593339800834656, -0.027651621028780937, 0.03651278093457222, -0.007854912430047989, 0.058521173894405365, 0.030627112835645676, -0.012437650002539158, -0.057181745767593384, -0.011354942806065083, 0.017168836668133736, -0.02877046912908554, -0.00939894001930952, -0.044762350618839264, -0.0336102731525898, -0.004263709299266338, -0.08759527653455734, 0.05879342555999756, -0.04716698080301285, -0.018931424245238304, -0.011095362715423107, -0.05113578960299492, 0.03828798979520798, -0.030205579474568367, -0.04471443220973015, 0.09817197918891907, 0.0845528393983841, 0.04128861427307129, 0.036032021045684814, 0.013512829318642616, 0.08571863919496536, -0.019260302186012268, 0.008564161136746407, -0.013166902586817741, 0.010738493874669075, -0.05743991956114769, 0.08206170052289963, -0.03246729075908661, -0.01058045681566, -0.028898706659674644, 0.0067869313061237335, -0.10502157360315323, 0.010456332936882973, -0.07132644206285477, -0.0383736826479435, -0.01176996249705553, -0.03840160369873047, 0.023009167984128, 0.12403948605060577, -0.02910601906478405, -0.022527001798152924, -0.04537292569875717, 0.03234551101922989, 0.021389443427324295, 0.04799855127930641, -0.06942611932754517, 0.03705057129263878, -0.05909483879804611, -0.021700290963053703, -0.023648729547858238, 0.04011590778827667, 0.004339344799518585, -0.014091651886701584, -0.03735162317752838, -0.017580445855855942, 0.005764756351709366, 0.031233230605721474, -0.059306561946868896, 0.04683470353484154, 0.021425487473607063, -0.013534238561987877, -0.0016364086186513305, -0.09175329655408859, -0.0009526703506708145, 0.0019823673646897078, -0.006931970827281475, -0.04704759642481804, 0.03169887512922287, -0.10312432050704956, 0.06505543738603592, -0.029702410101890564, -0.09757483750581741, -0.028697576373815536, 0.10039303451776505, 0.0015037888661026955, -0.026551194489002228, -0.0077811614610254765, 0.012660972774028778, -0.05507947877049446, -0.014295159839093685, 0.00548844737932086, -0.06811810284852982, -0.04561701789498329, -0.028171230107545853, -0.005577804520726204, 0.03682197257876396, -0.0010292878141626716, 0.036214377731084824, -0.004580250941216946, -0.0029856921173632145, 0.022137248888611794, 0.0055776117369532585, 0.011680287308990955, 0.0004979323712177575, 0.047910451889038086, -0.04105120152235031, -0.027246272191405296, -0.029958713799715042, -0.02061360329389572, -0.014233201742172241, 0.04904913529753685, 0.03861592710018158, 0.03352551907300949, 0.002970572328194976, -0.01191270537674427, 0.03419459983706474, 0.005187449511140585, -0.010288529098033905, 0.015351044945418835, 0.05747126787900925, 0.010266166180372238, -0.006882024463266134, -0.029308421537280083, -0.012804611586034298, -0.0017832976300269365, -0.0020883996039628983, -0.0330423004925251, -0.01504203025251627, 0.017330264672636986, 0.018140364438295364, 0.04757803678512573, -0.023795515298843384, -0.01544834952801466, 0.02199358306825161, 0.04714992269873619, 0.09181157499551773, -0.10118073225021362, -0.025875331833958626, -0.012132409028708935, 0.021285811439156532, 0.007054322399199009, -0.04664861038327217, 0.03575332462787628, 0.016321100294589996, -0.039884477853775024, -0.008812552317976952, 0.03166430816054344, 0.000766269862651825, 0.002674615476280451, -0.00492504658177495, -0.010912259109318256, -0.03763461858034134, 0.005654172971844673, 0.023826923221349716, 0.038038138300180435, 0.012258660048246384, -0.0018985610222443938, -0.001468941569328308, -0.0041120401583611965, 0.03089568018913269, -0.025477413088083267, -0.007969800382852554, 0.05157602205872536, -0.009958881884813309, 0.016742506995797157, -0.0034785703755915165, -0.03564221411943436, -0.010414582677185535, 0.0035309428349137306, -0.028543513268232346, -0.04621382802724838, -0.014078841544687748, 0.04655681923031807, -0.02531985193490982, -0.005201590247452259, 0.07181830704212189, 0.022452637553215027, 0.03255468234419823, 0.007770891766995192, 0.015648912638425827, 0.022929923608899117, -0.004346107132732868, 0.03040459379553795, -0.0420510433614254, 0.024192271754145622, -0.01970432698726654, -0.038716237992048264, -0.03196943923830986, -0.0033435882069170475, 0.03472210466861725, 0.004466642625629902, 0.016939673572778702, -0.013946914114058018, -0.0065833344124257565, 0.01748567447066307, -0.0016337876440957189, -0.02536904439330101, 0.021478373557329178, -0.000812775338999927, 0.011637939140200615, -0.052780281752347946, 0.05422290414571762, 0.0013719446724280715, 0.03218236565589905, -0.003378218272700906, 0.04084568843245506, -0.02624962478876114, -0.012684397399425507, 0.015476640313863754, 0.014085366390645504, -0.009470519609749317, 0.009781495667994022, -0.033758558332920074, -0.01714916154742241, 0.08254484087228775, -0.006174752954393625, 0.00807532574981451, 0.00858002807945013, -0.04623684659600258, 0.025739194825291634, -0.00308424886316061, 0.04691779613494873, -0.010993355885148048, -0.010469830594956875, 0.026180822402238846, -0.008855682797729969, 0.024038299918174744, -0.01232890598475933, 0.025391820818185806, 0.006314662750810385, -0.01149483397603035, 0.008720259182155132, 0.01676708273589611, -0.009511243551969528, 0.03338679298758507, 0.04700934886932373, 0.06670183688402176, -0.0629061907529831, -0.02447296679019928, -0.01688631996512413, -0.0059668333269655704, -0.008881233632564545, -0.04793046414852142, 0.018141519278287888, 0.02996581792831421, 0.025192881003022194, 0.03026093915104866, -0.03854672238230705, 0.021741719916462898, 0.027571337297558784, 0.01908987946808338, -0.0021501444280147552, -0.0377080999314785, -0.09635662287473679, -0.037227023392915726, -0.003712419653311372, 0.007485636975616217, 0.006254140287637711, 0.02179219201207161, -0.015172055922448635, 0.011501352302730083, 0.030158624053001404, 0.051752619445323944, 0.025124168023467064, -0.04409860447049141, -0.010635715909302235, -0.021413564682006836, 0.00796147994697094, 0.019477909430861473, -0.00011879394151037559, 0.009695962071418762, 0.05734970048069954, 0.048652809113264084, 0.016738254576921463, -0.009674842469394207, -0.07907655835151672, -0.031082576140761375, 0.031041990965604782, 0.06014210730791092, 0.009252127259969711, 0.031321749091148376, -0.03126806020736694, -0.014719951897859573, 0.013170985504984856, -0.024927286431193352, 0.03072761744260788, 0.06244461238384247, 0.03254019841551781, -0.03880065307021141, 0.019794704392552376, 0.014644288457930088, -0.01408467348664999, 0.01824513077735901, 0.025967583060264587, 0.032764021307229996, 0.021526923403143883, -0.005521503277122974, 0.016757486388087273, -0.05071466788649559, 0.008005158044397831, 0.005006076768040657, 0.0520181879401207, -0.06871405243873596, -0.04838339984416962, 0.017056286334991455, 0.01229320839047432, 0.007677068468183279, -0.010066204704344273, -0.0038804493378847837, -0.02719339169561863, -0.022034145891666412, 0.0038742218166589737, 0.0007680276758037508, -0.007121657952666283, 0.004910554736852646, -0.004847219679504633, -0.009176082909107208, 0.013917529955506325, 0.034661468118429184, -0.020376792177557945, 0.017778310924768448, 0.006238063331693411, 0.03504088148474693, 0.06073128804564476, -0.009170026518404484, 0.03592510521411896, 0.05334610864520073, -0.0013412066036835313, 0.0007543179672211409, -0.0008550370112061501, -0.011007373221218586, 0.005258210003376007, 0.01667158305644989, 0.013309827074408531, -0.024209529161453247, -0.020618192851543427, 0.03446762636303902, 0.04096393659710884, 0.02468733675777912, -0.0037860535085201263, 0.023157931864261627, -0.024967815726995468, -0.008005025796592236, -0.0034410664811730385, -0.01000169012695551, -0.01879752427339554, 0.028751490637660027, -0.011416862718760967, -0.03954632207751274, -0.0038627900648862123, 0.002439642557874322, -0.04762894660234451, -0.05673578754067421, -0.025399543344974518, 0.03397131338715553, 0.04686570167541504, -0.020266138017177582, 0.016941700130701065, -0.003407273441553116, 0.009306318126618862, 0.010277793742716312, -0.029356691986322403, 0.017270660027861595, 0.01357328798621893, -0.017611749470233917, 0.0070250495336949825, 0.06045069172978401, -0.008377309888601303, -0.029373563826084137, 0.008576175197958946, 0.007164908107370138, -0.016776826232671738, -0.02426520176231861, 0.04348079487681389, 0.023894112557172775, 0.024564264342188835, 0.0052441321313381195, -0.03166068345308304, -0.04072568938136101, 0.0739055722951889, -0.014254141598939896, 0.057043351233005524, 0.07899206131696701, 0.013066238723695278, 0.014926973730325699, 0.014846054837107658, 0.053185779601335526, -0.0112337376922369, -0.022329475730657578, 0.011171633377671242, 0.016797086223959923, 0.01342062558978796, 0.029760245233774185, 0.0049759759567677975, 0.04429701343178749, 0.027143923565745354, 0.03580401465296745, -0.045158859342336655, -0.01146733295172453, -0.009943491779267788, -0.011937196366488934, 0.04486163333058357, 0.015328961424529552, -0.011686316691339016, 0.011805389076471329, 0.011385459452867508, 0.05593002960085869, 0.016003185883164406, -0.02824297733604908, 0.026955608278512955, -0.0017892769537866116, -0.005695465952157974, 0.013378914445638657, 0.05791950225830078, -0.0008232981781475246, 0.020398862659931183, 0.014764978550374508, -0.012391362339258194, 0.04533730819821358, 0.005061081610620022, 0.005806249100714922, 0.027887491509318352, 0.059011321514844894, -0.025407548993825912, 0.03608107939362526, 0.0004384484200272709, 0.0005005846032872796, 0.017199290916323662, -0.012042461894452572, -0.02086123451590538, -0.04355660825967789, 0.03752411529421806, 0.012280330993235111, -0.017838962376117706, 0.029347717761993408, -0.05326845124363899, 0.035685572773218155, 0.03672150894999504, -0.004247760865837336, 0.015363717451691628, 0.012253707274794579, 0.032068684697151184, 0.02620372176170349, 0.018164286389946938, 0.039170991629362106, 0.003461511805653572, 0.02495596930384636, 0.030615532770752907, -0.012324943207204342, 0.041682660579681396, 0.024752343073487282, -0.034122586250305176, 0.02130454033613205, 0.010913594625890255, -0.022622236981987953, 0.01850009709596634, 0.019070997834205627, -0.04112773388624191, -0.015291564166545868, -0.02997363731265068, -0.03539985045790672, 0.00384464836679399, 0.020123058930039406, 0.01436118595302105, -0.04546414688229561, -0.004909397102892399, -0.01305511686950922, 0.06439590454101562, -0.010043365880846977, -0.00015230424469336867, -0.03776852414011955, 0.003450484946370125, -0.016005609184503555, 0.011679679155349731, -0.006336309481412172, -0.022165963426232338, -0.03659607470035553, 0.0021285791881382465, -0.0195644311606884, 0.01629921793937683, 0.005967976525425911, -0.040623921900987625, 0.020329391583800316, 0.014454868622124195, -0.016225062310695648, -0.0053747789934277534, -0.00881008431315422, -0.0035482137463986874, -0.027028584852814674, -0.033891189843416214, -0.013551886193454266, -0.011874360963702202, 0.001362806768156588, -0.02932383120059967, 0.012629748322069645, -0.01078422274440527, 0.04251664876937866, 0.0465356670320034, 0.009548199363052845, -0.040001556277275085, -0.05368153750896454, -0.0077914027497172356, -0.009531501680612564, -0.003691923338919878, 0.0024493965320289135, 0.010553565807640553, 0.0079537658020854, -0.032929323613643646, -0.022308025509119034, -0.002800285816192627, -0.037941884249448776, -0.0016829262021929026, 0.02250862494111061, 0.03301199525594711, -0.03169829025864601, -0.031593792140483856, 0.024938242509961128, 0.012852553278207779, 0.0400543175637722, 0.05207836627960205, 0.03582610562443733, 0.016849426552653313, -0.05889289826154709, -0.001384632894769311, 0.002451632171869278, -0.011981568299233913, -0.05396141856908798, -0.0520474873483181, -0.022373370826244354, 0.023176072165369987, -0.006855966988950968, 0.03148507699370384, -0.011507436633110046, 0.0244490634649992, -0.023755576461553574, -0.015657465904951096, 0.013767745345830917, 0.03314123675227165, 0.04156569391489029, -0.020966239273548126, 0.016406845301389694, -0.016524117439985275, -0.01903989538550377, -0.03272039443254471, -0.003090478712692857, -0.018581939861178398, 0.050342902541160583, -0.005609080195426941, 0.008425210602581501, -0.00422431668266654, 0.009275984019041061, -0.0436069630086422, -0.03576699271798134, 0.013091843575239182, 0.004196362104266882, -0.012568552978336811, 0.014773383736610413, 0.015019313432276249, 0.0009550267131999135, 0.02352442964911461, 0.004947412759065628, -0.011571073904633522, -0.011986051686108112, -0.037390340119600296, 0.010011709295213223, -0.015194111503660679, 0.0030045274179428816, 0.021072350442409515, -0.01292618177831173, 0.05966629460453987, 0.007054684218019247, 0.05140109360218048, 0.024766504764556885, -0.002059655962511897, 0.008897984400391579, 0.02044515311717987, 0.005364866461604834, 0.01440842542797327, 0.005896610673516989, 0.001548346015624702, -0.030915945768356323, -0.007792843505740166, 0.008722254075109959, 0.021514082327485085, 0.005908322054892778, -0.009146356023848057, -0.02620665729045868, -0.0010591993341222405, -0.039821937680244446, 0.010941820219159126, -0.02043025754392147, 0.0478687547147274, -0.00375324091874063, 0.011511679738759995, 0.03458656743168831, -0.013809161260724068 ]
Hyperparameter Search with Transformers and Ray Tune
ray-project
November 2, 2020
ray-tune
open-source-collab, nlp
https://huggingface.co/blog/ray-tune
A guest blog post by Richard Liaw from the Anyscale team With cutting edge research implementations, thousands of trained models easily accessible, the Hugging Face transformers library has become critical to the success and growth of natural language processing today. For any machine learning model to achieve good performance, users often need to implement some form of parameter tuning. Yet, nearly everyone (1, 2) either ends up disregarding hyperparameter tuning or opting to do a simplistic grid search with a small search space. However, simple experiments are able to show the benefit of using an advanced tuning technique. Below is a recent experiment run on a BERT model from Hugging Face transformers on the RTE dataset. Genetic optimization techniques like PBT can provide large performance improvements compared to standard hyperparameter optimization techniques. Algorithm Best Val Acc. Best Test Acc. Total GPU min Total $ cost Grid Search 74% 65.4% 45 min $2.30 Bayesian Optimization +Early Stop 77% 66.9% 104 min $5.30 Population-based Training 78% 70.5% 48 min $2.45 If you’re leveraging Transformers, you’ll want to have a way to easily access powerful hyperparameter tuning solutions without giving up the customizability of the Transformers framework. In the Transformers 3.1 release, Hugging Face Transformers and Ray Tune teamed up to provide a simple yet powerful integration. Ray Tune is a popular Python library for hyperparameter tuning that provides many state-of-the-art algorithms out of the box, along with integrations with the best-of-class tooling, such as Weights and Biases and tensorboard. To demonstrate this new Hugging Face + Ray Tune integration, we leverage the Hugging Face Datasets library to fine tune BERT on MRPC. To run this example, please first run: pip install "ray[tune]" transformers datasets scipy sklearn torch Simply plug in one of Ray’s standard tuning algorithms by just adding a few lines of code. python from datasets import load_dataset, load_metric from transformers import (AutoModelForSequenceClassification, AutoTokenizer, Trainer, TrainingArguments) tokenizer = AutoTokenizer.from_pretrained('distilbert-base-uncased') dataset = load_dataset('glue', 'mrpc') metric = load_metric('glue', 'mrpc') def encode(examples): outputs = tokenizer( examples['sentence1'], examples['sentence2'], truncation=True) return outputs encoded_dataset = dataset.map(encode, batched=True) def model_init(): return AutoModelForSequenceClassification.from_pretrained( 'distilbert-base-uncased', return_dict=True) def compute_metrics(eval_pred): predictions, labels = eval_pred predictions = predictions.argmax(axis=-1) return metric.compute(predictions=predictions, references=labels) # Evaluate during training and a bit more often # than the default to be able to prune bad trials early. # Disabling tqdm is a matter of preference. training_args = TrainingArguments( "test", evaluation_strategy="steps", eval_steps=500, disable_tqdm=True) trainer = Trainer( args=training_args, tokenizer=tokenizer, train_dataset=encoded_dataset["train"], eval_dataset=encoded_dataset["validation"], model_init=model_init, compute_metrics=compute_metrics, ) # Default objective is the sum of all metrics # when metrics are provided, so we have to maximize it. trainer.hyperparameter_search( direction="maximize", backend="ray", n_trials=10 # number of trials ) By default, each trial will utilize 1 CPU, and optionally 1 GPU if available. You can leverage multiple GPUs for a parallel hyperparameter search by passing in a resources_per_trial argument. You can also easily swap different parameter tuning algorithms such as HyperBand, Bayesian Optimization, Population-Based Training: To run this example, first run: pip install hyperopt python from ray.tune.suggest.hyperopt import HyperOptSearch from ray.tune.schedulers import ASHAScheduler trainer = Trainer( args=training_args, tokenizer=tokenizer, train_dataset=encoded_dataset["train"], eval_dataset=encoded_dataset["validation"], model_init=model_init, compute_metrics=compute_metrics, ) best_trial = trainer.hyperparameter_search( direction="maximize", backend="ray", # Choose among many libraries: # https://docs.ray.io/en/latest/tune/api_docs/suggestion.html search_alg=HyperOptSearch(metric="objective", mode="max"), # Choose among schedulers: # https://docs.ray.io/en/latest/tune/api_docs/schedulers.html scheduler=ASHAScheduler(metric="objective", mode="max")) It also works with Weights and Biases out of the box!
[ -0.01552203856408596, -0.012096226215362549, -0.020312996581196785, 0.054628029465675354, -0.04240579158067703, 0.07288691401481628, 0.07863915711641312, 0.03780806064605713, -0.009518168866634369, -0.004176983144134283, -0.1153622567653656, 0.06947683542966843, -0.020131494849920273, 0.09606090188026428, 0.039298783987760544, -0.044617507606744766, -0.00014741357881575823, -0.008002969436347485, -0.0458713062107563, 0.05573924258351326, 0.02264772541821003, -0.05879312381148338, 0.07496128976345062, 0.015273860655725002, 0.018782321363687515, -0.05371663346886635, -0.003133076475933194, 0.007246894296258688, 0.03316161036491394, 0.05840692296624184, -0.10824804753065109, -0.038715627044439316, -0.053059447556734085, -0.06287063658237457, 0.028719089925289154, 0.04783498868346214, -0.06344833225011826, 0.000710973225068301, 0.002665095031261444, -0.006821077782660723, -0.0037048521917313337, -0.03289277106523514, -0.04602173715829849, 0.05776330828666687, 0.05559367686510086, 0.004632940981537104, -0.08747728168964386, 0.05229853466153145, -0.007528951391577721, -0.041147224605083466, -0.02558746002614498, 0.03345649689435959, 0.02836764231324196, 0.010819745250046253, 0.004095891024917364, -0.008924832567572594, 0.0075599756091833115, -0.029030146077275276, -0.029637014493346214, 0.018244823440909386, -0.015106710605323315, 0.013591118156909943, 0.016241958364844322, -0.01742333546280861, 0.024012064561247826, -0.0004101094091311097, -0.06480608880519867, 0.0642738789319992, -0.07614143192768097, -0.04862603545188904, 0.02351955883204937, -0.043499480932950974, 0.017581233754754066, -0.012705164030194283, -0.010571597144007683, -0.00006196451431605965, -0.021402787417173386, -0.04875333234667778, 0.008788076229393482, 0.020633639767766, 0.008727867156267166, 0.020727306604385376, -0.03735680133104324, 0.030758680775761604, 0.06861649453639984, 0.0230695940554142, 0.054658714681863785, -0.05718645825982094, -0.055069707334041595, 0.04678037017583847, -0.0654267966747284, -0.1116475835442543, -0.02847140096127987, -0.004282742273062468, 0.06423202902078629, -0.05400117114186287, -0.04234742373228073, -0.01704946905374527, -0.026407737284898758, -0.01865491457283497, -0.0016177371144294739, -0.03383532539010048, 0.03775129094719887, -0.05609457939863205, -0.06938039511442184, 0.04247785359621048, 0.0048732515424489975, -0.09048336744308472, -0.029905231669545174, 0.07062455266714096, -0.01789274998009205, -0.030191807076334953, -0.025899209082126617, 0.11908481270074844, -0.047602344304323196, 0.028575565665960312, 0.016593607142567635, 0.019099010154604912, -0.024856096133589745, -0.019240276888012886, -0.024892758578062057, 0.05035881698131561, 0.05058532580733299, -0.0034972061403095722, -0.014778975397348404, 0.08138696104288101, 0.03441346436738968, 0.058515097945928574, 0.09599757194519043, 0.050162479281425476, 0.020944781601428986, -0.03615625947713852, 0.05970600247383118, -0.006664117332547903, 0.03145410120487213, 0.014101194217801094, 0.021564051508903503, -0.021728966385126114, -0.0367664135992527, 0.008368292823433876, 0.010432792827486992, 0.004445032216608524, -0.025700954720377922, -0.06706015765666962, 0.07707091420888901, 0.016587426885962486, -0.07594048231840134, 0.10025642067193985, -0.0073345680721104145, 0.05796403810381889, -0.04541466757655144, 0.08146455883979797, 0.051578495651483536, 0.02975979447364807, -0.0010735971154645085, 0.07707560807466507, -0.038429077714681625, -0.05440952256321907, -0.04339369758963585, -0.001750004244968295, -0.016060784459114075, 0.005818284582346678, -0.0416252426803112, -0.02696751058101654, -0.012530048377811909, -0.02010207250714302, 0.005943310912698507, 0.04575526714324951, -0.024671092629432678, 0.0016556886257603765, 0.02891477197408676, 0.0061446321196854115, 0.034103430807590485, -0.062113892287015915, -0.03567708656191826, 0.011270157061517239, 0.03607010468840599, 0.07990200817584991, -0.005709455814212561, -0.03776035085320473, -0.06638243049383163, 0.061205990612506866, 0.07063543796539307, 0.11113735288381577, 0.04450497403740883, -0.07647578418254852, 0.04798738285899162, -0.0027331579476594925, 0.012445759028196335, -0.03650283068418503, -0.017892487347126007, 0.020757675170898438, 0.11212890595197678, -0.043441470712423325, 0.0496278740465641, -0.05085178464651108, -0.007828007452189922, 0.06427314877510071, 0.08531789481639862, -0.02475762367248535, 0.026831798255443573, -0.02786969393491745, 0.04854336008429527, -0.03866405040025711, -0.03887646645307541, -0.08014247566461563, -0.018381956964731216, -0.036301277577877045, -0.01026841625571251, 0.02680366486310959, 0.0192063357681036, -0.1439630687236786, -0.01419594045728445, -0.06468447297811508, -0.016537226736545563, -0.025250732898712158, -0.06677309423685074, -0.014776243828237057, 0.009084872901439667, -0.006023182068020105, 0.16117452085018158, -0.037462521344423294, -0.008098863065242767, -0.00710530998185277, -0.00829839613288641, 0.04566524550318718, 0.07055839896202087, 0.05606956034898758, 0.055214397609233856, -0.04162619635462761, -0.045892227441072464, -0.07573144882917404, -0.020024441182613373, 0.052754662930965424, -0.05541089177131653, -0.06626483798027039, 0.012498724274337292, -0.02928238920867443, -0.008472573012113571, 0.02518959902226925, -0.0756426751613617, 0.01703706569969654, -0.0014538916293531656, 0.04737420007586479, 0.016254255548119545, 0.020483972504734993, 0.021441230550408363, 0.01309844572097063, -0.010902087204158306, -0.03953905403614044, -0.0358169749379158, 0.018229732289910316, 0.004052738193422556, -0.04630366712808609, -0.0001871368003776297, 0.04486202076077461, 0.002687062369659543, 0.00506897596642375, -0.02027343399822712, 0.06158199906349182, 0.021092426031827927, -0.008111363276839256, -0.0482303760945797, -0.00654385332018137, -0.004434354603290558, -0.04308633878827095, -0.009882823564112186, 0.06443199515342712, 0.017513977363705635, -0.059369046241045, 0.009066645987331867, -0.0006693954928778112, 0.010653295554220676, 0.011013776995241642, 0.05575443059206009, 0.06381436437368393, 0.037106648087501526, -0.011310138739645481, -0.04674607142806053, 0.003418390406295657, -0.022515323013067245, -0.04276684299111366, 0.03761837258934975, 0.06435368955135345, -0.023152392357587814, 0.04682030901312828, -0.031750570982694626, -0.034179478883743286, -0.009711035527288914, 0.015819966793060303, -0.000791893049608916, 0.004455840215086937, 0.031906094402074814, -0.033492669463157654, 0.004904261790215969, -0.01993737369775772, 0.009985709562897682, -0.05174557492136955, 0.016794420778751373, -0.0014689669478684664, 0.015274246223270893, -0.028499290347099304, -0.009262092411518097, -0.0040320116095244884, -0.02311486192047596, -0.0010857481975108385, 0.013314931653439999, 0.02752930298447609, -0.06876654177904129, -0.009929388761520386, -0.06031511723995209, 0.0005959549453109503, 0.011313720606267452, -0.054173003882169724, 0.011589824222028255, -0.009193511679768562, -0.020013196393847466, 0.007171513047069311, -0.004442980047315359, 0.027156610041856766, 0.031006239354610443, 0.027778800576925278, 0.0214760173112154, -0.03336655721068382, 0.0030643665231764317, -0.03205164521932602, 0.03805160894989967, 0.026861896738409996, 0.003843626007437706, 0.021676793694496155, -0.007594405673444271, 0.025206733494997025, 0.004487503785640001, 0.0018399717519059777, 0.0444389246404171, -0.03784995153546333, 0.001676610903814435, -0.003664136864244938, 0.015762096270918846, -0.014658337458968163, -0.009482381865382195, 0.03939080610871315, 0.01937628909945488, -0.030271530151367188, 0.024260956794023514, 0.014174961484968662, -0.007827210240066051, 0.009887151420116425, 0.012247473932802677, -0.004663827363401651, -0.0035515506751835346, 0.015338512137532234, 0.04599275067448616, -0.04214957728981972, 0.004129650536924601, -0.0055218893103301525, 0.0029468138236552477, -0.0455121248960495, -0.002083664759993553, -0.025980520993471146, 0.0040701329708099365, 0.036534734070301056, -0.006285462994128466, 0.028612880036234856, 0.020018499344587326, -0.021842388436198235, -0.0028075275477021933, 0.058139730244874954, -0.021867448464035988, 0.033310260623693466, -0.004811704158782959, -0.00861020851880312, -0.011763622984290123, -0.0075959074310958385, -0.002348187379539013, -0.019741984084248543, -0.0571785606443882, 0.03426318243145943, 0.005497670266777277, 0.01265631802380085, -0.003693248378112912, -0.00003708466101670638, -0.004936108365654945, -0.013790007680654526, 0.004816087894141674, -0.045197855681180954, 0.017700590193271637, 0.02950993739068508, -0.07459332793951035, -0.03368552401661873, -0.05250966176390648, 0.005625191610306501, 0.01879437454044819, 0.012035795487463474, 0.02286350168287754, -0.07779350876808167, -0.010250518098473549, 0.012608046643435955, -0.0022804662585258484, -0.050711944699287415, -0.019300727173686028, -0.027323348447680473, -0.02278677374124527, -0.00007864397048251703, 0.02418389916419983, 0.03608603775501251, -0.008631925098598003, -0.000576180755160749, 0.0002820618392433971, 0.007681327871978283, 0.03977930545806885, 0.0194515660405159, -0.012830628082156181, 0.024289553984999657, -0.056913334876298904, -0.04790287837386131, 0.015113861300051212, -0.015055149793624878, -0.011776931583881378, -0.014200109988451004, -0.03275110572576523, -0.00576443038880825, 0.0649697333574295, 0.011935098096728325, 0.016794724389910698, 0.013784757815301418, -0.02300935424864292, 0.025862906128168106, 0.004932622890919447, 0.036709148436784744, -0.009461130946874619, -0.021023165434598923, 0.030030367895960808, 0.001999050844460726, 0.016546495258808136, 0.025489049032330513, -0.029784681275486946, -0.030416060239076614, -0.05024905130267143, -0.0366838276386261, 0.03241826593875885, -0.017157454043626785, -0.02551453560590744, 0.009812154807150364, -0.017858687788248062, -0.01757289096713066, -0.032802410423755646, -0.00715292664244771, 0.016226239502429962, -0.013121525757014751, 0.027875736355781555, -0.05136391520500183, 0.039085954427719116, 0.0024731983430683613, -0.0008169905631802976, 0.012486713007092476, -0.029012398794293404, 0.0010903608053922653, 0.02709713764488697, 0.0023081928957253695, 0.00026464805705472827, -0.004744316916912794, 0.03656940534710884, -0.039645157754421234, -0.019170472398400307, 0.009378920309245586, -0.011293549090623856, 0.01775885932147503, 0.016070188954472542, -0.01888061873614788, -0.06452734023332596, -0.008056260645389557, 0.012449119240045547, 0.036604143679142, 0.04239983111619949, 0.005008873529732227, -0.015005444176495075, -0.03617988899350166, -0.005190058145672083, 0.020470421761274338, 0.013137873262166977, -0.015624795109033585, -0.0330086350440979, 0.047796864062547684, 0.02764870785176754, -0.017874643206596375, -0.015617511235177517, 0.04714904725551605, 0.010457984171807766, -0.03220865875482559, -0.01151538547128439, 0.03364240378141403, 0.003796944860368967, 0.0686769112944603, 0.016944050788879395, 0.07948822528123856, -0.0063028838485479355, -0.013016634620726109, -0.01566324755549431, -0.03026270680129528, 0.0066411299630999565, -0.047111958265304565, 0.004896107129752636, -0.012141196988523006, 0.0065426998771727085, 0.005268820561468601, 0.00958439614623785, -0.02604174055159092, 0.010935921221971512, 0.03219904750585556, -0.057061322033405304, -0.03557481989264488, 0.06153036653995514, -0.004037392325699329, 0.020955951884388924, -0.004049806855618954, 0.012757034972310066, -0.03201477229595184, 0.014348200522363186, -0.01977444253861904, -0.0007934574969112873, -0.003967919386923313, 0.032534193247556686, -0.010304946452379227, -0.02890537679195404, 0.03796355053782463, 0.04963168129324913, 0.0024873765651136637, -0.039489276707172394, -0.03194486349821091, 0.009481596760451794, -0.02629045955836773, 0.014013242907822132, -0.0697316899895668, 0.03154910355806351, -0.006218567490577698, -0.0031110960990190506, 0.025582194328308105, 0.025449007749557495, -0.013996944762766361, -0.04717345908284187, 0.048183705657720566, 0.009038814343512058, -0.049482814967632294, -0.013071199879050255, 0.0801541656255722, 0.04611799865961075, -0.022914299741387367, 0.014280134811997414, 0.0039750803261995316, -0.036133017390966415, -0.02032540924847126, -0.06060699746012688, 0.0575602650642395, 0.08684054017066956, 0.004473435692489147, -0.002718936186283827, -0.005472992081195116, 0.030958009883761406, 0.01756170764565468, -0.037005484104156494, 0.011687749065458775, -0.024866828694939613, 0.028629440814256668, 0.0024332094471901655, -0.0007443512440659106, 0.02430059388279915, 0.05443308502435684, 0.03155965730547905, -0.03814755752682686, 0.04153783619403839, 0.014041426591575146, -0.038528744131326675, 0.009463176131248474, -0.007963143289089203, -0.034512802958488464, -0.003094129031524062, -0.014515312388539314, -0.00781636219471693, -0.0008171205408871174, 0.013054965995252132, 0.02512795850634575, 0.0015604209620505571, -0.00519908033311367, -0.006568086799234152, 0.05454002693295479, -0.0007858448661863804, 0.019696319475769997, 0.024304719641804695, 0.016648128628730774, 0.047106679528951645, -0.009169826284050941, 0.012781500816345215, -0.008653312921524048, 0.055573463439941406, 0.03037439100444317, 0.03338951617479324, 0.05220453813672066, -0.0035770582035183907, 0.007121304050087929, -0.016918014734983444, -0.0057590981014072895, -0.004977694246917963, -0.028494803234934807, 0.07958248257637024, -0.02452949993312359, 0.014979416504502296, -0.01196117140352726, 0.04504461959004402, 0.03291857987642288, 0.03916521370410919, -0.01972721889615059, 0.04668915644288063, 0.02810063399374485, 0.011311834678053856, -0.009057469666004181, 0.055336277931928635, 0.043254703283309937, -0.04808364808559418, 0.031115401536226273, -0.0034646312706172466, 0.021808572113513947, 0.008976277895271778, -0.00040829702629707754, 0.02763337455689907, -0.033258501440286636, -0.02539672516286373, 0.022543177008628845, -0.007202670909464359, 0.0229103434830904, 0.022432643920183182, 0.004654797725379467, -0.04227752611041069, 0.04365134239196777, -0.015753507614135742, -0.02081868052482605, -0.020353464409708977, 0.007894860580563545, 0.016016997396945953, 0.024398891255259514, -0.012440940365195274, -0.04741161689162254, 0.01767902448773384, 0.012289019301533699, 0.018533652648329735, 0.05525777116417885, -0.0019752976950258017, -0.04736282303929329, -0.05278853699564934, -0.03756769746541977, -0.0004897069884464145, 0.017447223886847496, -0.009925601072609425, -0.018133318051695824, -0.03692297637462616, 0.009437689557671547, 0.005838977172970772, 0.03395077958703041, 0.00363531825132668, 0.003461020067334175, -0.06590446084737778, 0.026744786649942398, -0.013292567804455757, -0.024359123781323433, 0.0605488121509552, -0.052643876522779465, -0.03690941631793976, -0.009762218222022057, -0.014441587962210178, 0.003835726296529174, 0.039678119122982025, -0.027889415621757507, -0.024278488010168076, 0.024879131466150284, -0.01164980884641409, -0.010505635291337967, 0.05330590903759003, 0.015177552588284016, -0.0283714160323143, -0.010060991160571575, -0.003243175568059087, 0.007556569296866655, -0.005803677253425121, -0.014634678140282631, 0.05074063315987587, -0.0283628199249506, -0.029531944543123245, -0.016624053940176964, 0.004343802109360695, 0.014697577804327011, -0.01656266860663891, 0.04410437494516373, -0.008874786086380482, 0.03501276671886444, -0.004345091991126537, 0.03596096858382225, -0.027883255854249, -0.004909132607281208, -0.008147007785737514, 0.017049593850970268, -0.0049204034730792046, 0.017800500616431236, -0.022557567805051804, 0.049654919654130936, -0.03388660028576851, 0.011043595150113106, -0.04361465573310852, -0.04165835678577423, -0.013178994879126549, 0.0034504407085478306, 0.06610655039548874, 0.0380866676568985, 0.02962084673345089, 0.04083053395152092, -0.005745736416429281, -0.008873328566551208, -0.01280805841088295, 0.004350758623331785, 0.07004502415657043, 0.028122683987021446, -0.012671425938606262, -0.08385994285345078, -0.006659762468189001, 0.047266826033592224, -0.07193438708782196, 0.015065841376781464, 0.03186580538749695, 0.02503199689090252, -0.011951008811593056, 0.006103763356804848, 0.02656400017440319, 0.006077311467379332, 0.01939604990184307, -0.013391006737947464, 0.013973728753626347, -0.006019621156156063, 0.01265033334493637, -0.029980070888996124, 0.02107255719602108, -0.0028850268572568893, -0.03436591103672981, 0.028405550867319107, 0.015230372548103333, 0.03847957402467728, -0.007274623028934002, -0.0244132187217474, -0.005335023161023855, -0.005489743780344725, -0.06509416550397873, -0.01562442909926176, -0.015573408454656601, 0.03560180962085724, 0.0022224364802241325, -0.03366128355264664, -0.00010657971870386973, 0.02076306752860546, -0.04059864208102226, 0.04697968810796738, -0.027219297364354134, 0.005445640068501234, -0.03653716668486595, -0.019019264727830887, 0.02927352860569954, 0.008181427605450153, 0.02078142762184143, -0.012932850979268551, -0.04755650833249092, 0.009552997536957264 ]
Hyperparameter Search with Transformers and Ray Tune
ray-project
November 2, 2020
ray-tune
open-source-collab, nlp
https://huggingface.co/blog/ray-tune
Try it out today: * pip install -U ray * pip install -U transformers datasets * Check out the Hugging Face documentation and Discussion thread * End-to-end example of using Hugging Face hyperparameter search for text classification If you liked this blog post, be sure to check out: * Transformers + GLUE + Ray Tune example * Our Weights and Biases report on Hyperparameter Optimization for Transformers * The simplest way to serve your NLP model from scratch
[ 0.0047001647762954235, -0.02565193921327591, 0.053861670196056366, 0.02455233596265316, 0.008973094634711742, 0.10691018402576447, 0.0602838508784771, 0.07280603796243668, -0.01150436419993639, -0.028050998225808144, -0.13599394261837006, 0.10267509520053864, 0.0025963152293115854, 0.0951831042766571, 0.030528457835316658, -0.0025676842778921127, 0.017226245254278183, 0.03530286252498627, -0.02280150167644024, 0.04375840723514557, -0.018512554466724396, -0.029752783477306366, 0.057318419218063354, -0.029446667060256004, 0.05192210525274277, -0.07014128565788269, 0.02962910570204258, 0.02667255885899067, 0.010086284019052982, 0.03632751852273941, -0.1391841024160385, -0.015874840319156647, -0.03612084314227104, -0.051879122853279114, -0.016928311437368393, 0.09744062274694443, -0.11362670361995697, 0.025553205981850624, 0.03246385231614113, -0.06396795064210892, -0.01541034784168005, -0.02675316296517849, -0.08641330897808075, 0.023638427257537842, 0.0025801907759159803, -0.035684965550899506, -0.1870494931936264, 0.07646168768405914, -0.021050069481134415, 0.0013973215827718377, -0.04922262951731682, 0.034291476011276245, 0.003465713234618306, -0.02358470857143402, 0.0007790295640006661, 0.008628916926681995, -0.0038571427576243877, -0.05877626687288284, 0.0005533102666959167, 0.050219062715768814, 0.020528491586446762, 0.02259027399122715, -0.0032898609060794115, 0.031165631487965584, 0.02160080522298813, 0.0192171148955822, -0.06005750969052315, 0.009241411462426186, -0.0670802891254425, -0.03485654667019844, 0.05152264982461929, -0.038876283913850784, 0.00808490626513958, -0.03945227712392807, -0.016243867576122284, -0.0346723273396492, 0.019312817603349686, -0.0014753623399883509, 0.0417124405503273, 0.059660475701093674, 0.027867186814546585, -0.01380806416273117, 0.04270585626363754, 0.06472814083099365, 0.04980169236660004, 0.043351177126169205, 0.03725963085889816, -0.02243298478424549, -0.07042700797319412, 0.09953903406858444, -0.023021075874567032, -0.09887126088142395, -0.025610435754060745, 0.004907911643385887, 0.060379818081855774, -0.059054721146821976, -0.0015246813418343663, -0.006677116267383099, -0.054679132997989655, 0.021242324262857437, -0.01802133210003376, -0.013773726299405098, 0.06571372598409653, -0.05082188919186592, -0.059992603957653046, 0.02206500433385372, 0.009496510960161686, -0.06807969510555267, -0.053337421268224716, 0.025475353002548218, -0.034463200718164444, -0.0034403065219521523, -0.02233385667204857, 0.06438740342855453, -0.0926201194524765, 0.0352136567234993, 0.030597055330872536, -0.004744784440845251, 0.00351031799800694, 0.01796356774866581, -0.017444249242544174, 0.08288094401359558, 0.036928679794073105, 0.0031744528096169233, -0.00030856611556373537, 0.09152384102344513, 0.02212396077811718, 0.03257008269429207, 0.04625468701124191, 0.01267105434089899, 0.02844739332795143, -0.04339516535401344, 0.055286649614572525, -0.019814226776361465, -0.004123599734157324, -0.06579665094614029, 0.017834782600402832, -0.035590481013059616, -0.009130125865340233, -0.004192246589809656, -0.00011489544704090804, 0.05154849588871002, 0.00381089118309319, 0.01610148698091507, 0.05049934238195419, -0.023596810176968575, -0.0720759853720665, 0.0895724967122078, -0.017126481980085373, 0.018466755747795105, -0.03881917893886566, 0.0989844799041748, 0.023348959162831306, 0.01214558258652687, -0.010337704792618752, 0.061615511775016785, -0.006719205062836409, -0.007842201739549637, -0.05105438455939293, -0.005634257569909096, -0.01017297524958849, 0.013112868182361126, -0.07064996659755707, 0.014736596494913101, 0.016698870807886124, -0.044597234576940536, -0.023947905749082565, 0.02396351657807827, -0.023754151538014412, 0.031277645379304886, 0.007359625305980444, -0.029988856986165047, 0.057298727333545685, -0.02562701515853405, -0.013418246060609818, -0.004172648768872023, 0.04907086491584778, 0.07283605635166168, -0.03197810426354408, -0.044211696833372116, -0.040313273668289185, 0.05630045384168625, 0.006530012935400009, 0.06190391257405281, 0.03162398561835289, -0.04774460196495056, 0.01153755746781826, 0.01055721752345562, 0.03340676799416542, 0.016427643597126007, -0.02168186940252781, -0.07408463954925537, 0.07504603266716003, -0.018556121736764908, 0.0567280650138855, -0.052824944257736206, -0.0034162618685513735, 0.13244618475437164, 0.017168935388326645, 0.03924817964434624, -0.008371856063604355, -0.002289146650582552, 0.05128350481390953, -0.04724607989192009, -0.0222393237054348, -0.025425812229514122, -0.0006199067574925721, -0.04657020419836044, 0.00490039074793458, 0.0122231962159276, 0.007317276671528816, -0.13366568088531494, 0.01932484470307827, -0.07561461627483368, -0.004165250808000565, -0.023409461602568626, -0.029148830100893974, 0.012491120956838131, -0.0022735416423529387, 0.008656718768179417, 0.17231237888336182, -0.016349907964468002, -0.010910112410783768, -0.02108386531472206, -0.03215637430548668, 0.053173139691352844, 0.1128908097743988, 0.05844186618924141, 0.07086671143770218, -0.08270105719566345, -0.03054983913898468, -0.027210228145122528, 0.014452983625233173, 0.09899140894412994, -0.022420212626457214, -0.041499968618154526, 0.056621383875608444, -0.03327621519565582, 0.0018870629137381911, 0.004790082573890686, 0.0197694543749094, -0.04537051543593407, -0.0035995335783809423, 0.03318290039896965, -0.02202552556991577, -0.026468772441148758, 0.0456731952726841, 0.02394992671906948, -0.05111944302916527, -0.028422607108950615, -0.05472967401146889, 0.04706769809126854, 0.005832003895193338, -0.03329658508300781, 0.008494794368743896, 0.0684128999710083, -0.011067978106439114, -0.019639046862721443, -0.02528863027691841, 0.06421606242656708, 0.032344426959753036, 0.021715302020311356, -0.035258062183856964, -0.041945669800043106, -0.02771451324224472, -0.035484712570905685, 0.010572348721325397, 0.014945998787879944, 0.009611944667994976, -0.004093509167432785, -0.01300504244863987, -0.016658587381243706, 0.04270877689123154, 0.011895134113729, 0.007031079847365618, 0.02827608957886696, 0.049456071108579636, -0.020271241664886475, -0.025722401216626167, -0.014098227955400944, -0.012178001925349236, -0.02926407754421234, 0.04598044231534004, 0.048686012625694275, -0.0030571415554732084, 0.0025634088087826967, -0.01932292990386486, -0.05227409303188324, -0.0055008577182888985, 0.019083039835095406, -0.01905721239745617, 0.036530639976263046, -0.01655230112373829, -0.044000349938869476, -0.008208319544792175, -0.012401066720485687, 0.0007155471248552203, 0.004875647369772196, 0.0007892027497291565, 0.032682742923498154, 0.0055275727063417435, 0.02504728175699711, -0.0012771907495334744, -0.005115058738738298, -0.04277848079800606, 0.033603884279727936, 0.028268322348594666, 0.019930996000766754, -0.11033300310373306, -0.020209576934576035, -0.0211066585034132, 0.018010642379522324, 0.005764374975115061, -0.02656339667737484, 0.04905183985829353, -0.019660217687487602, -0.018473109230399132, -0.021800151094794273, -0.006419793237000704, 0.008747564628720284, 0.018967069685459137, 0.03531793877482414, 0.006138661876320839, -0.03317408636212349, 0.016499491408467293, 0.0018998145824298263, 0.04914156720042229, 0.028974242508411407, -0.011859196238219738, 0.06495969742536545, 0.024321308359503746, 0.01775265485048294, -0.012561150826513767, -0.0003019865835085511, 0.047021105885505676, 0.013832321390509605, 0.014399994164705276, -0.04706645756959915, 0.010468012653291225, -0.010287104174494743, -0.03763328865170479, 0.032685890793800354, -0.01383386179804802, -0.0017403379315510392, 0.005588016007095575, -0.0022012200206518173, -0.006413470488041639, 0.029292171820998192, -0.014535504393279552, -0.0032197555992752314, 0.000511080608703196, -0.0330655612051487, -0.010700240731239319, -0.009444616734981537, -0.03613375872373581, 0.006608832627534866, 0.0220574252307415, -0.045007552951574326, -0.018453126773238182, -0.021734187379479408, -0.006229178514331579, 0.02346646599471569, 0.02533181570470333, 0.005746880080550909, 0.007692041341215372, 0.026680871844291687, 0.021857069805264473, 0.009619727730751038, -0.04964519664645195, 0.03816121816635132, -0.018334215506911278, -0.04061919450759888, -0.02270582504570484, 0.05218593403697014, 0.01588495820760727, 0.0175560861825943, -0.025003988295793533, 0.014169474132359028, 0.013886832632124424, 0.019164811819791794, 0.003454927820712328, 0.010971717536449432, -0.030042216181755066, 0.007330353371798992, -0.012394540011882782, -0.039082735776901245, 0.04535292461514473, 0.03761005401611328, -0.06851968914270401, -0.04189605638384819, -0.05309322848916054, -0.022402383387088776, -0.008050311356782913, -0.013423570431768894, 0.015038412995636463, -0.054278817027807236, 0.04224734008312225, 0.006667562760412693, -0.021802296862006187, -0.053071849048137665, 0.007260694168508053, -0.03133764863014221, -0.02177131175994873, -0.015319020487368107, 0.05017440393567085, -0.016065509989857674, -0.0021959601435810328, 0.017577847465872765, 0.0010178431402891874, -0.012875296175479889, 0.008091086521744728, 0.017042437568306923, 0.006186134181916714, 0.006849548779428005, -0.04176221415400505, -0.03180800750851631, 0.014332200400531292, -0.027488745748996735, 0.007425133138895035, -0.024460695683956146, -0.04324698448181152, -0.0015330056194216013, 0.020761331543326378, 0.021275589242577553, -0.013870096765458584, -0.026981979608535767, -0.042254287749528885, 0.05234667286276817, -0.0031608841381967068, 0.03485528379678726, -0.02449214830994606, -0.024497216567397118, 0.001353415078483522, -0.006574070081114769, 0.05064569413661957, 0.04981646686792374, -0.027834733948111534, 0.017018629238009453, -0.012525174766778946, -0.05310789495706558, 0.04171421006321907, -0.006148083601146936, 0.0029179658740758896, 0.02132249064743519, -0.012160523794591427, 0.020700683817267418, -0.015209334902465343, -0.02268555946648121, -0.020342400297522545, -0.012131228111684322, 0.045857541263103485, -0.019453618675470352, 0.05431195721030235, -0.0027757014613598585, -0.06056314334273338, -0.008580549620091915, -0.018688056617975235, 0.018015827983617783, 0.033426206558942795, 0.012045842595398426, 0.00013489443517755717, 0.047543399035930634, 0.01984863355755806, -0.02510550059378147, -0.012114078737795353, 0.033413734287023544, 0.003809308633208275, 0.035682160407304764, 0.011557499878108501, -0.011174695566296577, -0.04216158017516136, 0.006475589703768492, 0.020132726058363914, 0.009284824132919312, 0.021744806319475174, -0.047183360904455185, 0.003433358622714877, 0.00390873895958066, -0.005349102430045605, 0.008360451087355614, 0.03291827067732811, -0.03776538372039795, -0.04441959783434868, 0.04292185232043266, 0.0330473855137825, 0.013939623720943928, -0.0073797740042209625, 0.03821003437042236, -0.014278436079621315, -0.015783987939357758, -0.0072603533044457436, 0.0054464396089315414, -0.015170532278716564, 0.04200850427150726, 0.04994655400514603, 0.062142543494701385, -0.002054888056591153, 0.00010935233876807615, -0.007218398153781891, -0.034328389912843704, 0.019089877605438232, -0.03979439660906792, -0.0008922207052819431, -0.0176713764667511, 0.008627810515463352, -0.020474832504987717, -0.003109223209321499, -0.020168211311101913, 0.018904251977801323, 0.040309492498636246, -0.019353432580828667, -0.03438345342874527, 0.03711806237697601, -0.01440985407680273, 0.0045584747567772865, -0.013199269771575928, 0.03297220543026924, -0.04675297439098358, -0.005532735027372837, -0.014164491556584835, -0.017279256135225296, -0.023934384807944298, -0.007373481057584286, -0.009831342846155167, -0.023197321221232414, 0.005366086959838867, 0.03317974880337715, 0.042814306914806366, -0.008897796273231506, -0.010687872767448425, -0.0026575762312859297, -0.008602255955338478, 0.017694175243377686, -0.0391891710460186, 0.017457779496908188, -0.008068347349762917, 0.0016355131519958377, 0.04522184655070305, 0.03840690106153488, -0.00750527111813426, -0.015681514516472816, 0.04107455536723137, 0.004613972268998623, -0.014489850029349327, -0.03489308804273605, 0.06120874360203743, 0.03871949762105942, -0.015133285894989967, -0.004878165666013956, -0.013033256866037846, -0.03413000702857971, 0.009542795829474926, -0.026318322867155075, 0.04239810258150101, 0.07872752100229263, 0.007736136671155691, 0.0053934683091938496, -0.00317483302205801, 0.01637531816959381, 0.008319332264363766, -0.031048651784658432, 0.013735855929553509, 0.018333658576011658, 0.03292138874530792, -0.00912002194672823, -0.0011576487449929118, -0.0005609812797047198, 0.04462757706642151, 0.02772979997098446, -0.05748094618320465, 0.042851515114307404, 0.011483732610940933, -0.05032985657453537, -0.0030010468326509, -0.0006077747093513608, 0.008440066128969193, -0.013961462303996086, 0.01859275810420513, -0.00032420974457636476, 0.04286741465330124, 0.004499049857258797, 0.008543197996914387, -0.031361281871795654, -0.008981511928141117, 0.01441376842558384, 0.04494255781173706, -0.02146318554878235, 0.03495620936155319, 0.02420670911669731, 0.01712678000330925, 0.026369616389274597, -0.013907365500926971, -0.002768115373328328, 0.01143677718937397, 0.07448865473270416, 0.018368404358625412, 0.04342480003833771, 0.031929612159729004, -0.00014290983381215483, 0.008579609915614128, -0.028158830478787422, -0.014208875596523285, -0.016484493389725685, 0.02346862480044365, 0.0266982764005661, -0.014110666699707508, -0.0039194505661726, -0.021693825721740723, 0.05718085914850235, 0.031104372814297676, 0.04294431582093239, -0.009102588519454002, 0.024956317618489265, 0.04376902058720589, 0.015002217143774033, -0.0018024715827777982, 0.05265407636761665, 0.019286271184682846, -0.018202699720859528, 0.05657751485705376, 0.009648339822888374, 0.038766782730817795, 0.010520372539758682, -0.004809353966265917, 0.015443972311913967, -0.020343482494354248, -0.022455723956227303, -0.006417649332433939, 0.02906913496553898, 0.007863778620958328, -0.01086255069822073, 0.03386303409934044, -0.06502639502286911, 0.014037867076694965, -0.030565908178687096, 0.013006215915083885, -0.0162795502692461, -0.026503372937440872, -0.005293247289955616, 0.047743625938892365, -0.005435122177004814, 0.002580872969701886, 0.008237200789153576, 0.002710376400500536, 0.007679338566958904, 0.020104559138417244, -0.026195034384727478, -0.04028977081179619, -0.043590378016233444, -0.01264206413179636, -0.03626738488674164, -0.014202107675373554, -0.02109752781689167, -0.03209986165165901, -0.03311382979154587, 0.04122414439916611, -0.0010419826721772552, 0.01656477339565754, 0.034080490469932556, 0.02427309937775135, -0.04908068850636482, 0.025942618027329445, -0.032108042389154434, -0.012842389754951, -0.01141536794602871, -0.025057408958673477, -0.019037140533328056, -0.02921447716653347, -0.004810369573533535, 0.014172760769724846, 0.05157427862286568, -0.02937033399939537, -0.04318438842892647, 0.00734899053350091, -0.006773266475647688, -0.022482478991150856, 0.02989022806286812, -0.005816359538584948, -0.012925781309604645, -0.0032967727165669203, 0.010287479497492313, 0.0048848786391317844, -0.006664216052740812, 0.006145837716758251, 0.01747892238199711, -0.014760257676243782, -0.030170895159244537, -0.008470874279737473, 0.025594111531972885, 0.03373446688055992, -0.0015349702443927526, 0.040904659777879715, 0.0016786777414381504, 0.02547081559896469, -0.030393322929739952, 0.030473556369543076, -0.02131403610110283, 0.012871080078184605, -0.03522849828004837, -0.03344479203224182, -0.012459277175366879, -0.015016252174973488, -0.0031238060910254717, 0.03175598382949829, -0.06735165417194366, -0.0007456305320374668, -0.028947634622454643, -0.030771302059292793, -0.018475694581866264, 0.00702071376144886, 0.060916610062122345, 0.042835649102926254, 0.009119069203734398, 0.03099600225687027, -0.006073520053178072, 0.016285786405205727, 0.007198874372988939, 0.013921459205448627, 0.049074336886405945, 0.02621079422533512, -0.006057281047105789, -0.07498100399971008, -0.002035018289461732, -0.011684058234095573, -0.07207952439785004, 0.003237049328163266, 0.020185377448797226, -0.029301611706614494, -0.017381496727466583, -0.00834513921290636, 0.01762976683676243, 0.029514750465750694, 0.034958772361278534, -0.04766123369336128, -0.015432266518473625, -0.0011486551957204938, 0.015727141872048378, -0.05995408818125725, 0.05616914480924606, -0.019720397889614105, -0.04785199835896492, 0.02951737865805626, 0.019531143829226494, 0.03520886227488518, 0.0026060135569423437, -0.018940621986985207, -0.02303382195532322, 0.012323723174631596, -0.0616503544151783, -0.045943550765514374, -0.0029215437825769186, 0.04798353835940361, -0.019597085192799568, -0.03218455612659454, 0.020819520577788353, -0.004117950797080994, -0.03518395870923996, 0.02202368527650833, -0.03140245005488396, -0.015352142043411732, -0.021012594923377037, 0.02779530920088291, 0.010671778582036495, 0.03558791056275368, 0.022054079920053482, -0.0026720266323536634, -0.004503907170146704, 0.00582673167809844 ]
Hyperparameter Search with Transformers and Ray Tune
ray-project
November 2, 2020
ray-tune
open-source-collab, nlp
https://huggingface.co/blog/ray-tune
# Hyperparameter Search with Transformers and Ray Tune
[ 0.04973425716161728, -0.020596999675035477, 0.10134916752576828, 0.02864486165344715, 0.010653316974639893, 0.05226883664727211, 0.06901779025793076, 0.010060022585093975, 0.023221438750624657, -0.02282828837633133, -0.07446477562189102, 0.07545126974582672, -0.0016302700387313962, 0.07910776883363724, 0.025469165295362473, 0.037953346967697144, -0.010553540661931038, -0.00702751474454999, 0.006950440816581249, 0.03907736763358116, -0.013318024575710297, -0.030577626079320908, 0.077385812997818, -0.02467971481382847, 0.03630273789167404, -0.020632905885577202, -0.013087337836623192, -0.008520357310771942, -0.011645297519862652, 0.06720852851867676, -0.0772075355052948, 0.025019675493240356, -0.014750977046787739, -0.07404705137014389, -0.0455746129155159, 0.08117713034152985, -0.08936047554016113, -0.029132291674613953, -0.01690131053328514, -0.07280652225017548, -0.07699627429246902, -0.07304731756448746, 0.0031693261116743088, 0.01761556975543499, 0.041338756680488586, 0.0119577432051301, -0.22107382118701935, 0.07364632189273834, -0.04675048217177391, -0.02519809640944004, 0.0063447123393416405, 0.040345896035432816, -0.003297539195045829, 0.011291689239442348, -0.019025234505534172, 0.025356309488415718, 0.020135419443249702, -0.040541186928749084, -0.010182789526879787, -0.014512190595269203, 0.053160399198532104, 0.018958626314997673, 0.01108578685671091, 0.010154824703931808, 0.021653706207871437, 0.023202642798423767, -0.04983286187052727, 0.020559174939990044, -0.07069297879934311, -0.030672796070575714, 0.023744774982333183, -0.022424837574362755, 0.005185345187783241, -0.01625659130513668, -0.009510931558907032, -0.03710240498185158, -0.03754639998078346, 0.040406886488199234, 0.03976568207144737, 0.10124818980693817, 0.013911447487771511, -0.029857978224754333, 0.06311590224504471, 0.0606284998357296, 0.01572362147271633, 0.010211944580078125, 0.06561655551195145, 0.004156013019382954, -0.011122246272861958, 0.06463957577943802, -0.010726639069616795, -0.15562796592712402, -0.03140360862016678, 0.02296222746372223, 0.03596392646431923, -0.059356652200222015, 0.004684873856604099, -0.0571131706237793, -0.03852137178182602, 0.08201994001865387, -0.025384537875652313, 0.017106058076024055, 0.08492901176214218, -0.031210416927933693, -0.060890235006809235, -0.005992190446704626, 0.01735701970756054, -0.09416027367115021, -0.058297671377658844, 0.058205511420965195, -0.054059743881225586, 0.05747681111097336, 0.03581208735704422, 0.05473218113183975, -0.03200061246752739, 0.018007731065154076, 0.022499890998005867, -0.017764372751116753, 0.012086126022040844, 0.008066946640610695, -0.038450200110673904, 0.12850981950759888, 0.07562558352947235, 0.0440339669585228, 0.0034471957478672266, 0.05994559824466705, 0.05298231169581413, 0.05246826261281967, -0.0019240201218053699, 0.021232830360531807, 0.027559561654925346, -0.036166511476039886, 0.03828207775950432, 0.0009324508137069643, -0.01694335602223873, -0.09961845725774765, -0.0007941430667415261, 0.011847644113004208, -0.03996305912733078, 0.00579100614413619, 0.014727453701198101, -0.011522369459271431, -0.0037201710510998964, -0.020466245710849762, 0.025890346616506577, -0.0390017069876194, -0.017680693417787552, 0.06979444622993469, -0.005843915045261383, 0.041003670543432236, 0.015967583283782005, 0.12238504737615585, 0.008215918205678463, -0.01092747412621975, 0.0007053612498566508, 0.042025044560432434, 0.0029691150411963463, -0.011635431088507175, -0.05157685652375221, 0.011847431771457195, -0.01734752766788006, 0.02600930817425251, -0.02947833575308323, 0.025618556886911392, 0.018247971311211586, -0.03217313066124916, -0.03209593519568443, 0.01698007620871067, -0.0394575297832489, -0.023905867710709572, -0.030449924990534782, -0.014604493044316769, 0.04731491580605507, -0.048862528055906296, -0.05771833285689354, 0.0027811669278889894, 0.06656752526760101, 0.0748458132147789, -0.004316635895520449, -0.033385224640369415, -0.02829211764037609, 0.0284599456936121, 0.003288848325610161, 0.06957069039344788, 0.009583490900695324, -0.017330419272184372, -0.002181492280215025, -0.0004279871645849198, 0.058364562690258026, 0.0013586716959252954, -0.034933850169181824, -0.07942388951778412, 0.09676072746515274, -0.025170378386974335, 0.03979730233550072, -0.06037597730755806, -0.021608654409646988, 0.07030099630355835, 0.07580973953008652, 0.07116904854774475, -0.02069351263344288, 0.016383295878767967, 0.035742029547691345, -0.05248701199889183, -0.029294775798916817, 0.009570291265845299, 0.05832728371024132, -0.033941902220249176, 0.02612133137881756, 0.02035846747457981, -0.008305946364998817, -0.15119881927967072, 0.003936351742595434, -0.07956524938344955, 0.011700882576406002, -0.013328715227544308, -0.06610345840454102, -0.026808882132172585, -0.034747105091810226, -0.02850153110921383, 0.09856752306222916, 0.016040271148085594, -0.04809193313121796, 0.018338080495595932, -0.005866155028343201, 0.07594070583581924, 0.10860928893089294, 0.01928546279668808, 0.03294932842254639, -0.06348223239183426, -0.026005249470472336, 0.03521651029586792, 0.01513735018670559, 0.1130528375506401, 0.006666891276836395, 0.019111905246973038, 0.004225475247949362, -0.03627265617251396, 0.03027619794011116, -0.03426928445696831, 0.02148357778787613, 0.016614381223917007, -0.0004431253473740071, 0.09983918070793152, -0.04376000538468361, -0.040177494287490845, 0.053868360817432404, 0.004973309114575386, -0.029686586931347847, -0.027090441435575485, -0.06297024339437485, 0.00545675540342927, 0.012775197625160217, -0.0866352766752243, 0.049287036061286926, -0.0008620492881163955, -0.022118056192994118, -0.03601275011897087, -0.03917296230792999, 0.06107894331216812, 0.051680777221918106, 0.02294333651661873, 0.0012579469475895166, -0.04764031618833542, -0.0011729635298252106, -0.00958030205219984, 0.01891510561108589, 0.04774501919746399, -0.014398657716810703, 0.002296323422342539, -0.023436827585101128, -0.023680681362748146, 0.03221582993865013, -0.0023912678007036448, 0.018831569701433182, -0.006418291945010424, 0.0474458709359169, 0.0030957318376749754, -0.00038290279917418957, 0.016725925728678703, -0.00960761122405529, -0.0017778087640181184, 0.03306576609611511, 0.021925831213593483, -0.007756665349006653, -0.0030615231953561306, 0.0030816521029919386, -0.017128130421042442, 0.03136080503463745, 0.011471849866211414, -0.012535860762000084, 0.009273350238800049, 0.005828300025314093, 0.019888779148459435, 0.007875395007431507, -0.03822949901223183, 0.001476538134738803, -0.027002671733498573, -0.02404792234301567, -0.014835885725915432, 0.007717667613178492, 0.016011489555239677, -0.02575385384261608, 0.0015061823651194572, -0.03588304668664932, 0.021860415115952492, -0.0013854975113645196, 0.045511770993471146, -0.12729309499263763, -0.04457361251115799, -0.025303777307271957, 0.020492855459451675, 0.009640492498874664, -0.006919107399880886, 0.018845589831471443, -0.04247177392244339, -0.013731186278164387, -0.02660158835351467, -0.001960556022822857, 0.022984951734542847, 0.007849221117794514, 0.026502909138798714, -0.0009273409959860146, -0.03461678698658943, 0.010682262480258942, 0.02913733571767807, 0.01784227415919304, -0.013136366382241249, -0.005614439956843853, 0.06190737709403038, 0.0066096605733036995, 0.023602137342095375, 0.00484011834487319, 0.03241389989852905, 0.04615012928843498, 0.04143659397959709, -0.003432845463976264, 0.009551405906677246, -0.004218027926981449, 0.02601478435099125, -0.048676371574401855, 0.05482976511120796, 0.013971098698675632, -0.00022409441589843482, -0.007651660591363907, -0.031923092901706696, -0.0006535211578011513, 0.047429513186216354, 0.019639916718006134, 0.009268631227314472, 0.017730267718434334, -0.018879903480410576, -0.04361126944422722, -0.013571785762906075, -0.03449913486838341, 0.028722144663333893, 0.03030947409570217, -0.06385688483715057, -0.04150553047657013, -0.029776576906442642, -0.0016075004823505878, 0.003686100011691451, 0.0030286468099802732, -0.018222767859697342, 0.0035837420728057623, 0.012440923601388931, 0.049044035375118256, 0.006559233646839857, -0.033087000250816345, -0.0002548954507801682, 0.00557651836425066, 0.0029925093986094, -0.06550927460193634, 0.04292241111397743, 0.023412901908159256, 0.04976010322570801, -0.027956167235970497, 0.02516055852174759, 0.013688405975699425, -0.008580447174608707, -0.024114249274134636, 0.01760692708194256, -0.018891913816332817, 0.034643080085515976, -0.01668407768011093, -0.04330765828490257, 0.0361873023211956, -0.000887060712557286, -0.06464921683073044, -0.035291802138090134, -0.0411226861178875, -0.008857416920363903, 0.01429549790918827, 0.004597032908350229, 0.01536596566438675, -0.041938066482543945, 0.020327067002654076, 0.01617530733346939, -0.010976986028254032, -0.03168044984340668, -0.007057256996631622, -0.035138215869665146, -0.006484782323241234, 0.033037129789590836, 0.05123898759484291, -0.017114022746682167, -0.005581020377576351, 0.025043081492185593, 0.013889973051846027, -0.031619489192962646, 0.015669895336031914, 0.017859945073723793, 0.012244253419339657, 0.011330888606607914, -0.014524067752063274, -0.03489397466182709, -0.011520205065608025, -0.013292081654071808, 0.014932852238416672, -0.054556045681238174, -0.050293490290641785, -0.01288713701069355, 0.014936164021492004, 0.012204919941723347, -0.027490464970469475, -0.025987951084971428, -0.028897255659103394, 0.04397818073630333, -0.013480680994689465, 0.015670958906412125, -0.0034761130809783936, -0.016918359324336052, -0.014449231326580048, -0.014084303751587868, 0.016849005594849586, 0.031572528183460236, -0.03140535578131676, 0.018311599269509315, -0.045726239681243896, -0.026254568248987198, 0.046712301671504974, -0.014981633983552456, 0.001980296801775694, 0.02425239235162735, 0.004328101873397827, 0.01718742586672306, -0.00627630902454257, -0.04658525437116623, 0.010534602217376232, 0.003985149785876274, 0.0015936135314404964, -0.03255344182252884, 0.08154888451099396, -0.0105378907173872, -0.02031208574771881, -0.005713251885026693, -0.01803160272538662, 0.004209720063954592, 0.03935425728559494, -0.017343053594231606, -0.025705117732286453, -0.0026053141336888075, 0.01676936261355877, -0.015724757686257362, 0.01924797333776951, -0.004817319102585316, -0.0044844429939985275, 0.04108113795518875, 0.031011853367090225, -0.016023514792323112, -0.07382310926914215, -0.0003822454600594938, -0.0007876234012655914, 0.008176811970770359, 0.02909967117011547, -0.01666620932519436, 0.004208722617477179, -0.01553878653794527, -0.010942649096250534, 0.003899096045643091, 0.05662652850151062, -0.03687134012579918, -0.026128161698579788, 0.028458507731556892, 0.023448044434189796, 0.014185893349349499, 0.026530634611845016, 0.015194167383015156, 0.020738689228892326, 0.0012114146957173944, -0.01117576751857996, 0.02067062444984913, -0.0007219078252092004, 0.01912805065512657, 0.04769403114914894, 0.030890000984072685, 0.005368527490645647, -0.0058962502516806126, 0.007356944028288126, -0.015793755650520325, -0.00955234095454216, -0.03432388976216316, 0.007378408219665289, -0.018846092745661736, 0.035639550536870956, -0.01828054152429104, -0.018779480829834938, -0.00978349894285202, 0.05806542560458183, 0.013164867646992207, -0.006997458636760712, -0.03982001170516014, 0.013604744337499142, -0.014671172015368938, 0.02607991173863411, 0.012597130611538887, -0.00827658548951149, -0.007559103891253471, 0.020227858796715736, -0.014158590696752071, -0.0377323217689991, -0.042251769453287125, 0.004367861431092024, -0.02930937148630619, -0.028395237401127815, -0.005710545461624861, 0.04105677455663681, 0.008928154595196247, 0.0015764734707772732, -0.010824821889400482, 0.029638417065143585, 0.015948621556162834, 0.03387375921010971, -0.010685957036912441, 0.020494315773248672, 0.010210378095507622, -0.004367492161691189, 0.054325614124536514, 0.027044180780649185, -0.0038401151541620493, -0.055605459958314896, 0.04027925804257393, 0.016514450311660767, -0.004127703607082367, -0.058934856206178665, 0.07883718609809875, 0.041893120855093, -0.01168479211628437, 0.0175361055880785, -0.0034520504996180534, -0.04204261675477028, -0.013690900057554245, -0.03877923637628555, 0.015526285395026207, 0.06569008529186249, 0.024616453796625137, -0.005273615475744009, -0.00934695452451706, 0.04538732394576073, -0.0013866283698007464, -0.039309754967689514, 0.01844852603971958, 0.01827978901565075, 0.03939347714185715, -0.017005680128932, -0.026897605508565903, 0.009921352379024029, 0.023077379912137985, 0.032815512269735336, -0.026012206450104713, 0.02444363757967949, 0.02242274396121502, -0.025175102055072784, 0.038172971457242966, -0.012004716321825981, 0.017564278095960617, -0.018783951178193092, 0.011605651117861271, -0.026954522356390953, 0.030614754185080528, 0.0009831043425947428, 0.016872931271791458, 0.002881597261875868, -0.014203732833266258, 0.004591900389641523, 0.04769793897867203, 0.010344769805669785, 0.016270333901047707, 0.009169500321149826, 0.025685865432024002, 0.035812199115753174, -0.02353750728070736, -0.018332023173570633, 0.03906545042991638, 0.05368521064519882, 0.013818691484630108, 0.0341765321791172, 0.03500227630138397, 0.016033872961997986, 0.002362314146012068, -0.0042924401350319386, -0.01903350278735161, -0.04628191888332367, 0.02787710167467594, 0.04218418523669243, -0.028547216206789017, -0.005446836352348328, -0.033282745629549026, 0.06224896013736725, -0.0029641601722687483, 0.004725079517811537, 0.0024276648182421923, 0.004937594290822744, 0.03044840320944786, 0.027650635689496994, 0.0033240218181163073, 0.043952878564596176, 0.001416487037204206, -0.005702738184481859, 0.05044049024581909, -0.030084209516644478, 0.005411391146481037, 0.010933020152151585, -0.004718678537756205, 0.038270287215709686, -0.02210458554327488, -0.05033976212143898, 0.026767442002892494, 0.043831177055835724, 0.014096802100539207, 0.022597335278987885, 0.029661061242222786, -0.05176888033747673, -0.04445027559995651, -0.009573775343596935, 0.0232224240899086, -0.04948442429304123, -0.023371107876300812, -0.022220682352781296, 0.017882633954286575, -0.023786261677742004, 0.010266009718179703, -0.01661653257906437, -0.0029902691021561623, 0.02973823994398117, 0.05530113726854324, -0.03604675829410553, -0.028754647821187973, -0.04719778522849083, 0.002099517732858658, 0.017043564468622208, -0.025532038882374763, -0.022604908794164658, -0.01344394776970148, -0.030461817979812622, 0.022122738882899284, -0.021861454471945763, 0.02255842462182045, 0.011088070459663868, 0.00278747477568686, -0.04741624742746353, 0.036782871931791306, -0.05580150708556175, -0.007795460056513548, -0.004387575201690197, 0.0025145350955426693, -0.018171250820159912, 0.0020496766082942486, 0.0003595745947677642, -0.0023851762525737286, 0.021428870037198067, -0.04927903413772583, -0.007592129986733198, 0.020392684265971184, -0.04241207242012024, -0.009781704284250736, 0.011002610437572002, 0.004183311015367508, -0.011628520675003529, -0.003194688819348812, 0.01726800948381424, 0.028827914968132973, -0.036732014268636703, -0.004495886620134115, 0.012681501917541027, -0.016931379213929176, -0.023400967940688133, -0.017565365880727768, 0.040052760392427444, 0.02332938276231289, 0.005733088124543428, 0.02334105782210827, 0.02308904007077217, 0.0015591157134622335, -0.030575010925531387, 0.00993529986590147, -0.006607816554605961, 0.011179071851074696, -0.008885436691343784, -0.029948672279715538, -0.00213205860927701, -0.012597063556313515, -0.023309536278247833, 0.033430807292461395, -0.059976283460855484, -0.016613565385341644, -0.01404542475938797, -0.04759477823972702, -0.05100163817405701, 0.03647404536604881, 0.06301156431436539, 0.018257828429341316, 0.05071840062737465, -0.014531265012919903, -0.010899615474045277, -0.0181167870759964, 0.007631706073880196, 0.04127689078450203, 0.039579011499881744, 0.027508387342095375, -0.02259782887995243, -0.08499931544065475, 0.040113117545843124, -0.043667346239089966, -0.062385376542806625, 0.0015198671026155353, 0.03631027042865753, -0.04257841035723686, -0.011507752351462841, -0.013894498348236084, -0.0040687317959964275, 0.007369250059127808, 0.04486726224422455, -0.01355480682104826, -0.011441711336374283, -0.0030215694569051266, 0.013337373733520508, -0.037954434752464294, 0.03508175164461136, -0.009336242452263832, -0.028652144595980644, 0.023688605055212975, 0.036266446113586426, 0.0024837441742420197, -0.00477229431271553, -0.038989514112472534, -0.006921329069882631, -0.012256352230906487, -0.03688795492053032, -0.0344044454395771, 0.003942884039133787, 0.007639592979103327, -0.03509688004851341, -0.03874741867184639, 0.031141823157668114, -0.007591817062348127, -0.03595853969454765, 0.04397697001695633, -0.02252424880862236, -0.009064343757927418, 0.00486394390463829, 0.03617865964770317, -0.015498068183660507, 0.016467556357383728, 0.025685463100671768, 0.0021972181275486946, 0.02281227894127369, -0.009449642151594162 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Links to the github versions of files In order to ensure that all links work if you read this article much later after it has been written, the links were made to a specific SHA version of the code and not necessarily the latest version. This is so that if files were renamed or removed you will still find the code this article is referring to. If you want to ensure you're looking at the latest version of the code, replace the hash code in the links withmaster`. For example, a link: https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/src/transformers/modeling_fsmt.py becomes: https://github.com/huggingface/transformers/blob/master/src/transformers/convert_fsmt_original_pytorch_checkpoint_to_pytorch.py Thank you for reading!
[ 0.056104280054569244, 0.008185600861907005, 0.031990110874176025, 0.021923158317804337, 0.038289688527584076, -0.021382106468081474, -0.025365935638546944, 0.03819078952074051, -0.0322720967233181, -0.0386800542473793, -0.06032419949769974, 0.04042534902691841, -0.06281166523694992, 0.09180504828691483, -0.02204839698970318, -0.01676039583981037, 0.037206798791885376, -0.01537787914276123, -0.017367685213685036, 0.0400829054415226, 0.0018352755578234792, -0.003840393852442503, -0.0014912511687725782, -0.06383538246154785, -0.012900610454380512, -0.025799209251999855, 0.0018027238547801971, 0.05258966237306595, -0.07619921863079071, -0.010990140028297901, -0.08635710179805756, -0.017225220799446106, 0.04808427765965462, -0.036018870770931244, -0.05665198341012001, 0.021078556776046753, -0.08892827481031418, 0.0031583805102854967, 0.06832951307296753, -0.025336187332868576, -0.014018538407981396, -0.0073193772695958614, -0.10107331722974777, 0.006006318610161543, 0.011051788926124573, 0.03704604506492615, -0.15590068697929382, 0.10133666545152664, -0.003369227983057499, 0.005253912415355444, -0.036817993968725204, -0.010568885132670403, 0.0016117286868393421, -0.03836395964026451, -0.04143163189291954, 0.0026823340449482203, 0.005057882517576218, -0.0166679248213768, 0.039653386920690536, 0.044215671718120575, 0.08530645072460175, -0.023072540760040283, -0.018023241311311722, 0.07959252595901489, 0.03855948522686958, 0.008368647657334805, 0.03308148309588432, 0.06682880967855453, -0.029642337933182716, 0.00045376212801784277, 0.06247637793421745, 0.02774493210017681, 0.00911443680524826, -0.03950151056051254, -0.03417547047138214, -0.022885577753186226, -0.057618942111730576, 0.08218687027692795, 0.04170095548033714, 0.008270046673715115, 0.0213776845484972, 0.06374672055244446, -0.005040439311414957, 0.07874151319265366, 0.00023542509006801993, 0.03311387076973915, 0.006764718797057867, -0.026583317667245865, -0.05018682777881622, 0.06344995647668839, 0.045233018696308136, -0.08551789820194244, -0.023019587621092796, 0.01449107751250267, 0.07932860404253006, -0.01440610270947218, -0.030584746971726418, 0.005140241701155901, 0.06769058108329773, 0.004956451710313559, -0.003656919812783599, -0.0440516471862793, -0.00792679563164711, -0.051044657826423645, -0.03650739789009094, 0.012973610311746597, -0.010795600712299347, -0.03232802450656891, -0.020332597196102142, -0.034628137946128845, -0.031142456457018852, -0.017417291179299355, 0.041701652109622955, 0.015810994431376457, 0.027653174474835396, 0.05837031826376915, -0.025821154937148094, -0.034214287996292114, 0.011295455507934093, 0.03459896892309189, -0.019722940400242805, 0.11666779220104218, 0.053968027234077454, 0.044224757701158524, 0.11530351638793945, 0.10753145813941956, -0.03150450438261032, 0.027697117999196053, -0.05546318739652634, -0.06963664293289185, 0.03314399719238281, 0.03873767331242561, 0.043499745428562164, -0.05376525595784187, 0.03753466159105301, -0.017475441098213196, -0.038128528743982315, -0.016752462834119797, 0.006440282333642244, -0.016394808888435364, -0.03384939208626747, 0.021574096754193306, -0.059093303978443146, 0.05495751276612282, -0.025166211649775505, 0.014402080327272415, -0.10169342160224915, 0.028460118919610977, 0.022850919514894485, 0.052507299929857254, 0.051370769739151, 0.08791524171829224, -0.02797817438840866, -0.05345433950424194, -0.01622922532260418, 0.104400634765625, -0.005863432306796312, 0.021870534867048264, -0.09373385459184647, -0.025805719196796417, -0.011212600395083427, 0.02680622972548008, -0.044777240604162216, -0.0536850206553936, 0.02408125437796116, 0.0021822110284119844, -0.019322505220770836, 0.04471339285373688, 0.030043402686715126, -0.008422133512794971, 0.03455931320786476, -0.03818705677986145, 0.07672909647226334, -0.038894835859537125, 0.03406188637018204, 0.043287552893161774, 0.037407469004392624, 0.021949421614408493, -0.0037129013799130917, -0.049251407384872437, -0.029227986931800842, 0.07442743331193924, -0.013860806822776794, -0.014975717291235924, 0.015745695680379868, -0.06358340382575989, -0.0012507439823821187, -0.00692309346050024, 0.011222315952181816, 0.06574005633592606, -0.11913744360208511, -0.05827007815241814, 0.0471021793782711, 0.03185049071907997, 0.06936007738113403, 0.022855212911963463, 0.019636904820799828, 0.10834135115146637, 0.04838491976261139, 0.03339149430394173, 0.02526184916496277, -0.07886072993278503, -0.03803858533501625, -0.03735175356268883, -0.007631618529558182, 0.029757020995020866, 0.06135769560933113, -0.12096734344959259, 0.02822781540453434, 0.018931977450847626, 0.06128011271357536, -0.014935002662241459, 0.06838971376419067, -0.04375634714961052, 0.05784537270665169, -0.04343855381011963, -0.020691081881523132, 0.017475808039307594, -0.027913536876440048, -0.009413131512701511, 0.18462751805782318, 0.010421233251690865, 0.015090497210621834, 0.0008576156105846167, -0.03165188804268837, 0.0729367658495903, 0.06048239767551422, 0.08244792371988297, 0.026460999622941017, -0.008473160676658154, -0.010947611182928085, -0.09228537231683731, 0.0019362985622137785, 0.06844411045312881, 0.00618456257507205, -0.05404705926775932, -0.020671339705586433, 0.006191416177898645, -0.04690557345747948, -0.023265812546014786, 0.029795128852128983, 0.024114955216646194, 0.08348812907934189, 0.009639879688620567, 0.010309845209121704, -0.03800523653626442, 0.04427788406610489, -0.02465038187801838, -0.01179126650094986, -0.007209836505353451, -0.06952893733978271, -0.018394896760582924, -0.009213878773152828, 0.010898049920797348, 0.039899129420518875, 0.021446892991662025, -0.007867291569709778, -0.004085029475390911, -0.001581754069775343, 0.04814211279153824, -0.004298233427107334, -0.0045644803903996944, -0.027844520285725594, -0.012698790058493614, -0.03775393217802048, -0.01576939783990383, -0.006458699237555265, 0.010221676900982857, -0.00576817337423563, -0.015599898062646389, 0.002513265935704112, -0.00020444599795155227, -0.00576649559661746, 0.0004191615153104067, -0.006175945978611708, -0.004820944741368294, 0.026769913733005524, -0.012129699811339378, -0.02969907782971859, -0.00804684218019247, -0.012169836089015007, 0.0041955746710300446, 0.03137320280075073, 0.006048098672181368, 0.016932375729084015, 0.017674097791314125, 0.0018298382638022304, -0.0010434213327243924, -0.044308848679065704, 0.03781822323799133, -0.02359449304640293, 0.020512022078037262, 0.0236128568649292, 0.00637329276651144, 0.014112030155956745, -0.005570034496486187, -0.0013972952729091048, 0.0025422926992177963, -0.0053649661131203175, 0.009197909384965897, -0.015599505044519901, 0.02527715638279915, 0.03265870362520218, -0.05868292972445488, -0.03884395211935043, 0.061423420906066895, 0.02649715542793274, 0.002256956184282899, -0.10714726895093918, -0.01803913339972496, 0.03175543621182442, 0.0258043110370636, -0.036818727850914, -0.0032424950040876865, 0.01968676783144474, 0.010716347023844719, 0.012002406641840935, -0.011961744166910648, -0.024329567328095436, 0.012325710617005825, 0.038840264081954956, 0.009504003450274467, -0.04305689409375191, -0.03583649545907974, -0.02647584117949009, 0.025214798748493195, 0.03498007357120514, -0.013076003640890121, -0.03902158886194229, 0.009197593666613102, -0.026620466262102127, -0.04758165404200554, -0.051639631390571594, -0.008835602551698685, 0.04757370799779892, 0.048293158411979675, -0.0010516551556065679, -0.07483063638210297, -0.009272419847548008, 0.005364181008189917, -0.0004147798754274845, -0.006795972585678101, -0.06793703138828278, 0.001208182773552835, 0.005237560719251633, 0.008423993363976479, -0.015249175950884819, 0.02731308341026306, 0.014243226498365402, 0.000492955616209656, -0.010803033597767353, 0.0009330532629974186, 0.016889872029423714, -0.026143809780478477, -0.01571829989552498, -0.00014257286966312677, 0.0064892820082604885, -0.012703988701105118, -0.008924240246415138, -0.019728178158402443, 0.021716423332691193, 0.03453991562128067, 0.018770460039377213, 0.0037238255608826876, -0.004506794270128012, 0.015032509341835976, 0.05656259506940842, -0.0024641468189656734, -0.015232084318995476, 0.0020800011698156595, -0.007137299980968237, -0.022436898201704025, -0.0556294210255146, 0.04099632427096367, -0.026037734001874924, -0.006689711008220911, -0.018868401646614075, 0.04572981968522072, -0.007538714911788702, 0.015602326951920986, -0.008356820791959763, 0.010494252666831017, -0.04341965168714523, -0.013363776728510857, -0.04507122561335564, -0.01729302667081356, 0.045011114329099655, 0.033143457025289536, -0.019011661410331726, -0.007095328997820616, -0.026837510988116264, 0.036568060517311096, -0.00939924642443657, -0.0008658329024910927, 0.04102732241153717, -0.009870919398963451, 0.042068175971508026, -0.0072691068053245544, -0.003161050146445632, -0.017407625913619995, 0.018966400995850563, -0.02651958353817463, -0.04376843199133873, -0.0037989590782672167, 0.022613108158111572, 0.029943736270070076, -0.004968294873833656, 0.024586647748947144, 0.021818773820996284, 0.008168097585439682, -0.0005845764535479248, -0.03221941739320755, -0.010133740492165089, 0.015141652897000313, -0.013054694049060345, -0.029403023421764374, -0.007991809397935867, -0.010858410969376564, 0.011498572304844856, -0.05108986422419548, 0.012843669392168522, 0.008928785100579262, 0.017766674980521202, -0.008893279358744621, 0.024028290063142776, -0.014199746772646904, -0.05382140725851059, 0.048536937683820724, -0.05763247236609459, 0.0367993526160717, 0.019478293135762215, -0.03103669360280037, -0.017724253237247467, 0.014653267338871956, 0.02559824474155903, 0.007285005878657103, -0.010988244786858559, 0.02947237715125084, -0.034111928194761276, 0.0014225495979189873, 0.006405878812074661, -0.024236159399151802, -0.017370931804180145, 0.026894021779298782, 0.007378096226602793, 0.02011238783597946, -0.03216885030269623, -0.09306129068136215, -0.05131486803293228, 0.015367433428764343, 0.04675998166203499, -0.0414728969335556, 0.022342713549733162, 0.014783626422286034, -0.01759323664009571, 0.038482509553432465, -0.03598485887050629, 0.011913744732737541, 0.06691046804189682, -0.024245820939540863, 0.016032623127102852, 0.043279796838760376, 0.0165263619273901, -0.0012966232607141137, -0.01868933066725731, -0.000018009624909609556, -0.004355431068688631, 0.07181189954280853, -0.008080828003585339, 0.0016604955308139324, -0.02578776143491268, 0.02559746988117695, -0.004272297490388155, 0.0023026668932288885, 0.04547956958413124, -0.09169796854257584, -0.03720826283097267, -0.014548217877745628, -0.008141729980707169, -0.02543497644364834, -0.012302907183766365, -0.027551377192139626, -0.002022849628701806, -0.011298935860395432, 0.05124685913324356, 0.037557609379291534, 0.014335429295897484, 0.0020383289083838463, -0.007648299913853407, 0.0059167020954191685, 0.04403354227542877, -0.0006284051341935992, 0.008265175856649876, 0.024559499695897102, -0.0018649097764864564, 0.05156278610229492, -0.0117972856387496, 0.01408741157501936, -0.011435072869062424, -0.03501192852854729, 0.025629086419939995, -0.003218320431187749, 0.030285241082310677, -0.04587589576840401, 0.04652451351284981, -0.026752430945634842, 0.010939591564238071, -0.00835329294204712, 0.03190197795629501, 0.0806523859500885, -0.04254298284649849, -0.01708340272307396, 0.004762293770909309, -0.04821241274476051, -0.0049076564610004425, 0.005675652530044317, 0.026050712913274765, -0.00464522372931242, 0.04839133843779564, -0.03538262099027634, -0.018405180424451828, -0.017792129889130592, -0.0025328011251986027, -0.03588765114545822, -0.016177276149392128, 0.0025560189969837666, -0.036807943135499954, 0.037182316184043884, -0.01202128455042839, 0.003961698152124882, -0.0011478608939796686, 0.03366358205676079, 0.02482447400689125, -0.02688099630177021, -0.001991098280996084, 0.04442618042230606, 0.011115957982838154, -0.027187153697013855, 0.04442226141691208, -0.02406187169253826, 0.0284257959574461, 0.029764952138066292, 0.0018830022308975458, 0.010832021944224834, -0.0005702433991245925, 0.007810528855770826, 0.013973712921142578, -0.0432911291718483, -0.01409944985061884, -0.028809232637286186, -0.06340306997299194, 0.009672456420958042, -0.04712561145424843, 0.00925726629793644, 0.08493836969137192, 0.012856920249760151, 0.07386878877878189, -0.0024221197236329317, 0.06290999054908752, 0.003427838208153844, -0.0381905697286129, 0.03505722060799599, -0.012581001967191696, 0.046689655631780624, -0.00264643388800323, 0.030823076143860817, -0.01279523316770792, -0.045042507350444794, 0.028820447623729706, -0.06918642669916153, -0.03931078687310219, 0.009843125008046627, 0.016141343861818314, -0.001043315976858139, -0.0010293694213032722, -0.06575169414281845, -0.028430527076125145, -0.0006167421233840287, 0.02969730831682682, 0.02864905819296837, 0.011255699209868908, -0.001972267171368003, -0.03666044399142265, -0.02317476086318493, 0.006970045156776905, 0.025579599663615227, -0.011427260003983974, 0.04563920199871063, 0.033135347068309784, 0.0023188027553260326, 0.04190179705619812, -0.007133199833333492, 0.016610663384199142, 0.01281184982508421, 0.06010705605149269, 0.03011298179626465, 0.05116404592990875, 0.01491870079189539, -0.04967401549220085, -0.021386705338954926, -0.034979138523340225, -0.01650298945605755, -0.04491817206144333, -0.0021887768525630236, -0.019032718613743782, -0.002511637983843684, 0.019949594512581825, -0.012932932004332542, 0.05141348019242287, 0.01273089274764061, 0.04241868853569031, 0.002355643780902028, 0.0037760541308671236, 0.008224531076848507, -0.0002985919709317386, 0.017488986253738403, 0.06583493202924728, 0.030754026025533676, 0.006730710156261921, 0.04367874935269356, -0.006818566471338272, 0.008353588171303272, 0.018873702734708786, 0.012326229363679886, -0.0013998018112033606, -0.04219440370798111, -0.009280580095946789, 0.00838087685406208, -0.03839157894253731, 0.002046983689069748, -0.03270117938518524, -0.0015179506735876203, -0.008076004683971405, -0.015297232195734978, 0.001039080903865397, 0.026325874030590057, -0.018340449780225754, -0.00978048238903284, -0.008505923673510551, 0.010811274871230125, 0.018522590398788452, -0.016103431582450867, 0.0005111014470458031, -0.004444778896868229, 0.028880272060632706, -0.010901414789259434, -0.022322358563542366, -0.01744845323264599, -0.037650641053915024, 0.011431220918893814, -0.015823155641555786, 0.0010643097339197993, -0.02553352154791355, 0.003744889050722122, -0.014217895455658436, 0.0010212811175733805, -0.055264685302972794, 0.01895751990377903, 0.03816721588373184, 0.04189983382821083, -0.03079349361360073, 0.01994423195719719, -0.016140194609761238, -0.0301943551748991, 0.006407103035598993, 0.007063453085720539, 0.014196071773767471, -0.0356186106801033, 0.05623982846736908, -0.00010087530972668901, -0.02103540673851967, -0.020705264061689377, -0.03413057699799538, 0.010751388967037201, -0.06156202405691147, -0.03382014483213425, 0.007884807884693146, 0.02121860347688198, 0.020631063729524612, 0.043991606682538986, -0.002213836880400777, 0.03160066157579422, -0.018033262342214584, -0.006478415802121162, 0.022869843989610672, 0.001200346159748733, 0.005362468305975199, 0.010174165479838848, 0.06312370300292969, 0.030195089057087898, 0.0629018098115921, 0.011599579825997353, 0.008453375659883022, 0.012319906614720821, -0.036121152341365814, 0.045714836567640305, -0.04067838937044144, -0.008652490563690662, 0.016203878447413445, -0.0324014313519001, -0.02083197422325611, 0.0029087793081998825, -0.02068505994975567, 0.0006633271113969386, -0.05923759937286377, 0.006088781636208296, -0.013370361179113388, -0.02411537431180477, -0.04968224838376045, 0.005454121623188257, 0.01761890947818756, 0.06022244691848755, -0.014741841703653336, -0.01208944246172905, -0.018990011885762215, 0.01240044366568327, -0.02502157725393772, 0.0374058336019516, 0.005973087623715401, 0.008306089788675308, -0.01713828556239605, 0.03267911449074745, 0.036905765533447266, -0.043366074562072754, 0.0011508965399116278, -0.0004620383260771632, -0.0035133473575115204, 0.0064928848296403885, -0.029705215245485306, -0.008221247233450413, -0.015437544323503971, 0.004770574625581503, -0.013349169865250587, 0.0011168880155310035, -0.013846308924257755, 0.046428438276052475, -0.007103689014911652, -0.023169685155153275, -0.02642534114420414, -0.009561331011354923, 0.04094948247075081, -0.009985672309994698, 0.004632006864994764, -0.0011077674571424723, -0.009804779663681984, -0.002974197268486023, 0.0436982735991478, -0.014943060465157032, -0.05316769331693649, -0.06405579298734665, -0.03504348546266556, 0.011780336499214172, -0.057150304317474365, -0.05162622407078743, 0.037216443568468094, -0.0002483219432178885, -0.05445818975567818, 0.02524038776755333, 0.028068751096725464, 0.006151246372610331, -0.010958799161016941, 0.0165233351290226, 0.01732039265334606, 0.027778200805187225, -0.03602316230535507, -0.006689881440252066, -0.007086910307407379, -0.010471689514815807 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
fairseq model and its support files Let's first look at what data we get with the fairseq pre-trained model. We are going to use the convenient torch.hub API, which makes it very easy to deploy models submitted to that hub: import torch torch.hub.load('pytorch/fairseq', 'transformer.wmt19.en-ru', checkpoint_file='model4.pt', tokenizer='moses', bpe='fastbpe') This code downloads the pre-trained model and its support files. I found this information at the page corresponding to fairseq on the pytorch hub. To see what's inside the downloaded files, we have to first hunt down the right folder under ~/.cache. ls -1 ~/.cache/torch/hub/pytorch_fairseq/ shows: 15bca559d0277eb5c17149cc7e808459c6e307e5dfbb296d0cf1cfe89bb665d7.ded47c1b3054e7b2d78c0b86297f36a170b7d2e7980d8c29003634eb58d973d9 15bca559d0277eb5c17149cc7e808459c6e307e5dfbb296d0cf1cfe89bb665d7.ded47c1b3054e7b2d78c0b86297f36a170b7d2e7980d8c29003634eb58d973d9.json You may have more than one entry there if you have been using the hub for other models. Let's make a symlink so that we can easily refer to that obscure cache folder name down the road: ln -s /code/data/cache/torch/hub/pytorch_fairseq/15bca559d0277eb5c17149cc7e808459c6e307e5dfbb296d0cf1cfe89bb665d7.ded47c1b3054e7b2d78c0b86297f36a170b7d2e7980d8c29003634eb58d973d9 \ ~/porting/pytorch_fairseq_model Note: the path could be different when you try it yourself, since the hash value of the model could change. You will find the right one in ~/.cache/torch/hub/pytorch_fairseq/ If we look inside that folder: ls -l ~/porting/pytorch_fairseq_model/ total 13646584 -rw-rw-r-- 1 stas stas 532048 Sep 8 21:29 bpecodes -rw-rw-r-- 1 stas stas 351706 Sep 8 21:29 dict.en.txt -rw-rw-r-- 1 stas stas 515506 Sep 8 21:29 dict.ru.txt -rw-rw-r-- 1 stas stas 3493170533 Sep 8 21:28 model1.pt -rw-rw-r-- 1 stas stas 3493170532 Sep 8 21:28 model2.pt -rw-rw-r-- 1 stas stas 3493170374 Sep 8 21:28 model3.pt -rw-rw-r-- 1 stas stas 3493170386 Sep 8 21:29 model4.pt we have: 1. model*.pt - 4 checkpoints (pytorch state_dict with all the pre-trained weights, and various other things) 2. dict.*.txt - source and target dictionaries 3. bpecodes - special map file used by the tokenizer We are going to investigate each of these files in the following sections.
[ 0.03636036068201065, -0.013846618123352528, 0.06070105358958244, -0.0024959740694612265, 0.09938976913690567, 0.06285207718610764, 0.011841078288853168, 0.07736674696207047, 0.004833099897950888, -0.0038075963966548443, -0.07621679455041885, 0.038339726626873016, 0.01457628607749939, 0.025622650980949402, -0.007507422473281622, -0.022363005205988884, 0.012295408174395561, -0.006533595267683268, -0.060879528522491455, 0.05802194029092789, 0.00864799227565527, -0.042802538722753525, 0.053724780678749084, 0.00914763007313013, -0.011160295456647873, -0.08064820617437363, -0.01264248974621296, 0.05585096776485443, -0.01559360884130001, 0.008330971002578735, -0.11208150535821915, -0.035904768854379654, 0.02349386177957058, -0.08299987763166428, -0.02088947780430317, 0.05927607789635658, -0.05974061042070389, 0.03807957470417023, 0.051798924803733826, -0.04083864763379097, -0.01818937435746193, -0.009058402851223946, -0.03809664398431778, 0.1225888580083847, 0.017229588702321053, 0.0017553623765707016, -0.0681048259139061, 0.037451401352882385, -0.010098665952682495, 0.00501872505992651, -0.08134391158819199, 0.015190341509878635, -0.06211728975176811, 0.044425442814826965, 0.030956093221902847, 0.045727599412202835, -0.05766015127301216, 0.021160518750548363, 0.06505890935659409, 0.019870087504386902, 0.03171925246715546, 0.04430398717522621, -0.005209809634834528, 0.020882979035377502, 0.013399706222116947, -0.05440027639269829, -0.003577593481168151, 0.010035851038992405, 0.006498644128441811, -0.04227997735142708, 0.04020464047789574, 0.014635936357080936, -0.01545822061598301, -0.06704355031251907, -0.0455334298312664, -0.053364306688308716, -0.04398493468761444, 0.007019141223281622, 0.028363943099975586, 0.04575759917497635, -0.004239222034811974, 0.0423833429813385, 0.004897711332887411, 0.0009051247034221888, 0.01943536289036274, -0.013257764279842377, -0.02087506465613842, -0.04187588021159172, -0.036719173192977905, 0.013460375368595123, -0.009311078116297722, -0.11939956247806549, -0.05098413676023483, 0.007838591001927853, -0.005481166299432516, 0.01616947539150715, 0.03987295180559158, 0.032552916556596756, 0.005792940501123667, -0.008351589553058147, -0.05692422389984131, -0.09383264183998108, 0.03985576331615448, -0.0694010928273201, -0.009048517793416977, 0.043691735714673996, -0.007591618690639734, -0.09004126489162445, -0.03697793185710907, 0.004374607466161251, 0.020366981625556946, -0.04610166698694229, -0.09192217886447906, 0.038813523948192596, -0.04052656888961792, 0.026302125304937363, 0.004842751193791628, -0.031103426590561867, 0.03599568456411362, 0.02590957097709179, -0.08756585419178009, 0.10356612503528595, 0.03946675732731819, 0.01619051583111286, 0.06841892749071121, 0.13590700924396515, 0.024058762937784195, 0.0009962213225662708, -0.0633450448513031, -0.03508954495191574, 0.045911066234111786, -0.030250538140535355, 0.05117034912109375, -0.04196181520819664, 0.044383853673934937, -0.04103298485279083, -0.03073367103934288, -0.007267963606864214, 0.01746968738734722, 0.022526662796735764, -0.08249062299728394, 0.06036684289574623, 0.021570121869444847, 0.05976919084787369, 0.050205111503601074, -0.038167063146829605, -0.029759181663393974, 0.10803976655006409, -0.008701398968696594, 0.024777915328741074, -0.03820740804076195, 0.03792136162519455, 0.03533660247921944, -0.09694241732358932, -0.012696088291704655, 0.01673399657011032, -0.01689058169722557, -0.029038798063993454, -0.05381191894412041, -0.06036938354372978, -0.06354478001594543, -0.003380772890523076, -0.049031928181648254, -0.02963055483996868, -0.03628133237361908, -0.00919847097247839, -0.02075183391571045, -0.050596803426742554, 0.07473374903202057, 0.021828720346093178, 0.015507332980632782, -0.0764060840010643, 0.10119803994894028, -0.012216057628393173, -0.013997356407344341, 0.07194095104932785, 0.03734784573316574, 0.0511256642639637, 0.03926714509725571, -0.009444273076951504, -0.06327373534440994, 0.036668386310338974, -0.057639021426439285, 0.014186752960085869, 0.04177672043442726, -0.07871346175670624, 0.00020082580158486962, -0.024458223953843117, -0.008167052641510963, 0.0782804936170578, -0.05593874678015709, 0.016285303980112076, 0.0960402563214302, -0.04924369603395462, 0.028328565880656242, 0.0021333834156394005, 0.0037136070895940065, 0.06858181208372116, 0.02208610251545906, 0.013132545165717602, 0.040959302335977554, -0.014343668706715107, -0.014050270430743694, -0.028360433876514435, -0.017755690962076187, 0.04877952113747597, -0.012904472649097443, -0.05208189785480499, 0.043228235095739365, 0.0058670323342084885, 0.04197174683213234, -0.08540748804807663, 0.03390762582421303, -0.07793724536895752, 0.029068181291222572, -0.034077391028404236, -0.031928956508636475, 0.014251384884119034, 0.02492419071495533, -0.007003049366176128, 0.17796365916728973, 0.031615205109119415, -0.005486480426043272, -0.00914459303021431, -0.00294036534614861, 0.0679314136505127, 0.05734807625412941, 0.02298630401492119, 0.0441930927336216, -0.0686776265501976, 0.019959235563874245, -0.05354743078351021, -0.05679430067539215, 0.10322340577840805, -0.005532319191843271, -0.03768119215965271, 0.004214423708617687, -0.009863360784947872, 0.00613925326615572, -0.011678594164550304, 0.06024318188428879, 0.0437203086912632, -0.008366030640900135, 0.018538955599069595, 0.027582766488194466, -0.004377216566354036, 0.011489027179777622, 0.012349508702754974, -0.03942436724901199, -0.013752499595284462, -0.020553285256028175, 0.0485413558781147, -0.00553411478176713, -0.060619812458753586, 0.04551442712545395, 0.05086703971028328, 0.028746074065566063, -0.03402267396450043, 0.014172288589179516, 0.051560692489147186, 0.018564123660326004, -0.012968388386070728, -0.047641102224588394, -0.027754565700888634, -0.0013800219167023897, -0.052087150514125824, -0.018863342702388763, -0.02193239890038967, 0.019025739282369614, -0.0217741671949625, 0.02623790130019188, -0.015756573528051376, -0.0038270442746579647, 0.006609224248677492, 0.024244919419288635, 0.06512352079153061, 0.003972476348280907, -0.04249617084860802, -0.026993095874786377, -0.020936738699674606, 0.00452709523960948, -0.008651374839246273, 0.0009694932959973812, 0.03047907166182995, -0.001110323704779148, 0.031586382538080215, 0.00890098325908184, -0.051559243351221085, -0.03266351670026779, -0.002142316661775112, -0.019047915935516357, 0.017932632938027382, 0.036297302693128586, -0.01213859859853983, -0.036011431366205215, -0.019104138016700745, -0.0023070902097970247, -0.0037315187510102987, 0.012678750790655613, 0.00789455883204937, -0.009226531721651554, -0.016400286927819252, -0.014302649535238743, -0.01194043643772602, -0.015087895095348358, 0.03280999884009361, 0.004113439936190844, 0.02083425596356392, -0.0968114361166954, 0.00974959135055542, -0.013217166997492313, 0.024177590385079384, -0.01424984261393547, -0.03375693038105965, 0.00270692165941, 0.030667880550026894, 0.012123201042413712, 0.029932599514722824, 0.043707285076379776, -0.021636683493852615, 0.026138605549931526, 0.03385614603757858, -0.04200492054224014, 0.036746736615896225, -0.018199650570750237, 0.056396156549453735, 0.03078974410891533, -0.01741345226764679, -0.04542165249586105, 0.013724831864237785, -0.02752622216939926, -0.01837114803493023, -0.030139213427901268, 0.028169535100460052, 0.05100591480731964, 0.02755775861442089, -0.01212193351238966, -0.056598056107759476, -0.018731392920017242, -0.00983258057385683, 0.013565312139689922, 0.00377989886328578, -0.024486543610692024, -0.05046495422720909, -0.009936880320310593, -0.0040900190360844135, -0.018865004181861877, 0.013965507969260216, -0.0399971529841423, 0.019604215398430824, 0.023462744429707527, -0.0034446227364242077, 0.009146906435489655, 0.013435671105980873, -0.027131499722599983, 0.0014021791284903884, 0.017266269773244858, -0.043044563382864, -0.030704621225595474, -0.02850579097867012, -0.02872215211391449, 0.06441254913806915, 0.01567196659743786, -0.02632361464202404, 0.0063853878527879715, 0.03270656615495682, 0.06263631582260132, 0.009049356915056705, -0.07900078594684601, 0.014868777245283127, -0.04025765508413315, -0.054642919450998306, -0.0447658896446228, 0.047513507306575775, 0.04366264119744301, -0.058320075273513794, -0.0414898619055748, -0.03705059364438057, -0.06762643903493881, 0.05458671972155571, -0.007245188113301992, 0.012647080235183239, -0.02768009714782238, 0.02077874355018139, -0.025541001930832863, -0.03776872903108597, 0.04487339034676552, 0.028213944286108017, -0.014254827983677387, -0.0207911916077137, -0.029983529821038246, -0.049375906586647034, -0.011714705266058445, -0.03138553351163864, 0.012011688202619553, -0.038761530071496964, 0.027651773765683174, 0.014310389757156372, -0.006971766706556082, -0.009127034805715084, 0.021389484405517578, 0.0038084571715444326, -0.014979255385696888, -0.03634795546531677, -0.012915482744574547, 0.03366465121507645, -0.015517587773501873, 0.008982721716165543, 0.011914452537894249, -0.02493278868496418, -0.04271779954433441, 0.0008040122338570654, -0.021027760580182076, 0.0020029577426612377, -0.03031671792268753, 0.0002631795941852033, -0.03192560747265816, 0.0002610528899822384, 0.008761278353631496, -0.005744018591940403, -0.001167986891232431, 0.007027362938970327, 0.03380700200796127, 0.016352016478776932, -0.0009474853286519647, -0.00592766935005784, 0.0031678685918450356, 0.01588349975645542, -0.03738108277320862, 0.013101625256240368, 0.013261335901916027, -0.049456387758255005, -0.01549559086561203, -0.008572472259402275, 0.04599311947822571, 0.007339085452258587, 0.023756198585033417, 0.0021667799446731806, -0.053959231823682785, -0.003386701224371791, 0.04889632761478424, 0.028364090248942375, -0.005419216118752956, 0.03736299276351929, -0.03093957155942917, 0.022902656346559525, 0.010191087611019611, -0.03253274783492088, -0.028950653970241547, 0.009157364256680012, 0.018514756113290787, -0.005867600440979004, 0.029402952641248703, 0.01450373511761427, -0.014671224169433117, -0.00562068959698081, -0.05853603780269623, -0.004759079311043024, 0.07247083634138107, -0.010402483865618706, -0.010813198983669281, 0.004392887465655804, 0.021680282428860664, -0.0069286818616092205, 0.005349148530513048, 0.023624340072274208, 0.0388912633061409, 0.028599292039871216, -0.0025493630673736334, -0.02655329927802086, -0.02158229611814022, 0.03753230720758438, 0.008811896666884422, -0.011670439504086971, 0.007921497337520123, -0.09797819703817368, -0.03194395452737808, 0.00988745130598545, -0.037746213376522064, -0.007803183048963547, 0.006598150823265314, -0.040139090269804, 0.028001178056001663, 0.045318059623241425, 0.03552486002445221, 0.02117713913321495, 0.025170134380459785, -0.027580490335822105, -0.0055508739314973354, 0.021453572437167168, 0.05530691519379616, 0.0018768252339214087, -0.020604966208338737, 0.010892296209931374, 0.0199586134403944, 0.032860200852155685, 0.006706782151013613, -0.008912540040910244, 0.01418662816286087, -0.009269802831113338, 0.007436780259013176, -0.0031815709080547094, -0.03518245741724968, -0.011549616232514381, -0.015909675508737564, 0.0027447978500276804, 0.013433640822768211, -0.015327542088925838, 0.02636285126209259, 0.056242626160383224, -0.024001063778996468, 0.003946468699723482, 0.023039313033223152, -0.023904548957943916, -0.013861175626516342, -0.027409739792346954, 0.03024805150926113, -0.029115820303559303, 0.00897841714322567, 0.02988291159272194, 0.010579025372862816, -0.0036470124032348394, -0.03257675841450691, -0.014500292018055916, -0.017349017783999443, 0.0615977868437767, 0.026034479960799217, 0.048282161355018616, -0.003290051594376564, -0.03849344700574875, 0.009155893698334694, 0.03390178456902504, -0.008301563560962677, -0.03925589844584465, -0.009459542110562325, -0.010551786050200462, -0.007570710498839617, 0.030266208574175835, 0.03490535914897919, 0.011786222457885742, 0.03468966484069824, 0.001436864142306149, -0.0010508244158700109, 0.007084180135279894, -0.006481362972408533, 0.030780356377363205, 0.02872493304312229, 0.004460742697119713, 0.0005422739777714014, -0.04765140637755394, -0.028674397617578506, 0.005933240056037903, -0.03125216066837311, 0.04791273549199104, 0.06399243324995041, -0.014904431998729706, 0.04752787575125694, 0.011395563371479511, 0.014210952445864677, -0.0014369046548381448, 0.011644100770354271, 0.0097822155803442, 0.002668380970135331, 0.03776570037007332, 0.04476172477006912, 0.002446657046675682, 0.0050511714071035385, 0.017111944034695625, 0.04832952842116356, -0.041701145470142365, -0.00041924495599232614, 0.00030428136233240366, -0.009616601280868053, 0.034680962562561035, -0.030286036431789398, -0.029262078925967216, 0.015198895707726479, -0.01817019283771515, 0.02969585917890072, 0.011391396634280682, 0.020316921174526215, 0.010260241106152534, -0.04307490587234497, 0.005819607991725206, 0.06018833816051483, 0.05355057865381241, -0.036808013916015625, 0.039209917187690735, -0.010789618827402592, 0.016388921067118645, -0.006839808076620102, 0.0036591612733900547, 0.006117907352745533, 0.02125007100403309, 0.08469553291797638, 0.03309500217437744, 0.03583303466439247, 0.03586442768573761, 0.029727831482887268, -0.02816004492342472, -0.053842440247535706, -0.03802599757909775, -0.009478887543082237, 0.036131951957941055, 0.031140880659222603, 0.001222532824613154, 0.03505329415202141, -0.030076852068305016, 0.04120207950472832, 0.03905976191163063, 0.041897326707839966, 0.005307577084749937, 0.0801999419927597, 0.00456160819157958, 0.007907443679869175, 0.03398430347442627, -0.011736590415239334, 0.002475406276062131, 0.00924273394048214, 0.030857855454087257, 0.03955298662185669, -0.009175778366625309, -0.0028821940068155527, -0.01978873647749424, 0.0012197749456390738, -0.01486608199775219, -0.031674470752477646, 0.012773629277944565, 0.047710057348012924, -0.0440569743514061, -0.032230477780103683, 0.06916191428899765, -0.0025138703640550375, 0.0111905662342906, -0.021993132308125496, -0.006782428827136755, -0.024674370884895325, -0.0044349320232868195, -0.02700066566467285, 0.023535212501883507, 0.005885234102606773, -0.005898586940020323, -0.032404735684394836, 0.04858560860157013, 0.012053019367158413, 0.03946816548705101, 0.016764432191848755, -0.018191689625382423, -0.012090403586626053, 0.000007698845365666784, 0.005769788287580013, 0.005826212931424379, 0.002683478407561779, 0.028709804639220238, 0.01071291696280241, 0.013465414755046368, 0.01897392049431801, 0.011451363563537598, 0.008604749105870724, 0.01903732679784298, 0.005168844945728779, 0.01857876405119896, -0.028140753507614136, -0.038064248859882355, 0.03749234974384308, -0.015496168285608292, -0.0020793762523680925, -0.019278256222605705, 0.0006621006759814918, 0.0639423057436943, 0.0410095676779747, -0.021665485575795174, -0.08743413537740707, -0.0074986801482737064, -0.04617338255047798, -0.02985180728137493, 0.01406730804592371, 0.012369424104690552, 0.0384233221411705, 0.02505696564912796, 0.0072690341621637344, -0.0013065189123153687, -0.017409661784768105, -0.02500339038670063, 0.024448171257972717, 0.02439061738550663, 0.028012102469801903, -0.009696018882095814, 0.08525944501161575, 0.01730506122112274, 0.018523933365941048, 0.04949966445565224, 0.03230297565460205, -0.00244367984123528, -0.010191347450017929, -0.002622051630169153, -0.029655924066901207, 0.004878026898950338, -0.0208743866533041, -0.0444091334939003, -0.008570011705160141, -0.004707531537860632, -0.03955161198973656, 0.022267665714025497, -0.01289240550249815, -0.010287320241332054, -0.030383937060832977, -0.03984113782644272, -0.007834263145923615, 0.010231479071080685, 0.08278276771306992, 0.030083905905485153, -0.021612301468849182, -0.0035871462896466255, -0.041687462478876114, 0.007892693392932415, -0.007422591559588909, 0.01793745905160904, 0.04954387992620468, 0.008410888724029064, 0.01375237014144659, -0.0017926462460309267, 0.0055794441141188145, -0.017282811924815178, -0.03595925495028496, -0.015053754672408104, -0.01036845799535513, 0.037424538284540176, -0.07626500725746155, 0.029770761728286743, 0.022420162335038185, -0.02847215160727501, 0.0313437320291996, -0.030731892213225365, 0.02243778109550476, -0.009577852673828602, -0.004537925124168396, -0.06685233116149902, 0.010042852722108364, -0.049663957208395004, -0.03664587810635567, 0.014057802967727184, -0.01715898886322975, 0.0007314344402402639, 0.01177830807864666, -0.024795809760689735, -0.019880525767803192, 0.0030618796590715647, -0.003658725181594491, -0.0525285080075264, -0.029080504551529884, 0.021673861891031265, -0.03873314708471298, -0.0445711612701416, 0.017434747889637947, -0.012498987838625908, -0.036511726677417755, 0.005938922520726919, 0.01349233090877533, 0.027556193992495537, 0.0012866585748270154, 0.025213871151208878, 0.026364516466856003, 0.051333002746105194, 0.0010516601614654064, -0.02791595086455345, -0.04108680039644241, 0.0012198779731988907 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Tokenizer decoder porting Once I had the portedgeneratefunction produce pretty similar results tofairseq'sgenerateI next needed to complete the last stage of decoding the outputs into the human readable text. This allowed me to use my eyes for a quick comparison and the quality of translation - something I couldn't do with output ids. Similar to the encoding process, this one was done in reverse. The steps were: 1. convert output ids into text strings 2. remove BPE encodings 3. detokenize - handle escaped characters, etc. After doing some more debugging here, I had to change the way BPE was dealt with from the original approach intokenization_xlm.pyand also run the outputs through themosesdetokenizer. ``` def convert_tokens_to_string(self, tokens): """ Converts a sequence of tokens (string) in a single string. """ - out_string = "".join(tokens).replace("</w>", " ").strip() - return out_string + # remove BPE + tokens = [t.replace(" ", "").replace("</w>", " ") for t in tokens] + tokens = "".join(tokens).split() + # detokenize + text = self.moses_detokenize(tokens, self.tgt_lang) + return text ``` And all was good.
[ 0.04244346171617508, 0.057779163122177124, 0.005030727945268154, -0.005198913160711527, 0.031753841787576675, 0.058806877583265305, 0.01299053244292736, -0.009831245057284832, -0.050436832010746, -0.006279271095991135, -0.029764702543616295, -0.007595923263579607, 0.01657458022236824, 0.05304476246237755, 0.007254694122821093, 0.05067427083849907, 0.013484696857631207, -0.038609109818935394, 0.033909525722265244, -0.09660396724939346, 0.022091493010520935, 0.01666291616857052, 0.035347796976566315, 0.040586646646261215, -0.022405708208680153, -0.01701921410858631, -0.020266709849238396, -0.012931759469211102, -0.06473449617624283, -0.0069542862474918365, -0.045847337692976, 0.022529171779751778, -0.01679334230720997, -0.06700564920902252, -0.036678481847047806, 0.021742740646004677, -0.12452666461467743, -0.013641498982906342, 0.0023750823456794024, 0.03171798959374428, -0.04041003808379173, -0.02667180821299553, 0.0374327152967453, 0.09916122257709503, 0.02954251877963543, 0.031061656773090363, -0.1687692403793335, 0.05655309185385704, -0.0006342438282445073, -0.03412851318717003, -0.041881874203681946, -0.011061756871640682, -0.032782506197690964, -0.007551148999482393, 0.004601790104061365, 0.0164310522377491, -0.04691771790385246, -0.040298543870449066, 0.03638726472854614, 0.01419012900441885, 0.002745614154264331, 0.007024560123682022, 0.036118004471063614, 0.05643373355269432, 0.027584942057728767, 0.02599465474486351, -0.03659161552786827, 0.052369698882102966, 0.026525937020778656, -0.04172110930085182, -0.06717442721128464, -0.02267003245651722, -0.04230049252510071, -0.03057279624044895, 0.04338200390338898, -0.06756626069545746, 0.008982532657682896, 0.027588333934545517, 0.036678001284599304, 0.02628471702337265, -0.00008959160186350346, 0.03831201791763306, 0.08015590906143188, -0.01497875340282917, 0.07886428385972977, 0.0005517749232240021, 0.03230837360024452, -0.01884406991302967, -0.0017985423328354955, -0.006216070614755154, -0.025440890341997147, -0.14450180530548096, -0.048432607203722, 0.044874630868434906, 0.013760430738329887, 0.04929962754249573, 0.012165636755526066, 0.09011867642402649, -0.0021349117159843445, 0.02966274693608284, 0.001569467131048441, -0.10858514904975891, -0.012956355698406696, -0.04879314452409744, -0.00372587563470006, 0.018898138776421547, -0.011105927638709545, -0.07185762375593185, 0.011894828639924526, -0.018748551607131958, 0.03621874377131462, -0.01834094151854515, -0.02095794305205345, 0.043569162487983704, -0.00570704834535718, 0.038643937557935715, -0.027051234617829323, 0.0365055575966835, -0.025349605828523636, 0.018345540389418602, 0.015492905862629414, 0.07241606712341309, 0.02607877366244793, -0.10483524203300476, -0.009891914203763008, 0.023681920021772385, 0.03761153295636177, 0.07849227637052536, 0.016902050003409386, -0.016171565279364586, -0.049978479743003845, 0.07659986615180969, 0.06392938643693924, 0.019861476495862007, -0.029470976442098618, -0.0661301389336586, -0.008884516544640064, -0.03646315261721611, -0.04349751025438309, -0.058197926729917526, -0.0519072599709034, 0.030920490622520447, -0.03352808579802513, 0.04228837043046951, -0.042942192405462265, 0.07733424752950668, -0.06707945466041565, 0.0877363458275795, 0.013451864011585712, -0.03432508185505867, -0.053055912256240845, -0.07673025876283646, 0.0064549874514341354, -0.008328721858561039, 0.015292574651539326, 0.05414170026779175, -0.019443288445472717, -0.024028223007917404, -0.09613999724388123, 0.009712861850857735, -0.010886600241065025, 0.0346311554312706, -0.02979234792292118, -0.01988452672958374, 0.02497626654803753, 0.010545163415372372, -0.0003390668425709009, 0.043505750596523285, 0.037583161145448685, -0.010545735247433186, 0.09380724281072617, -0.013760670088231564, 0.046022679656744, 0.015901226550340652, 0.017450248822569847, -0.02399870753288269, 0.0628664568066597, 0.03408104553818703, -0.021794172003865242, -0.03236392140388489, -0.012093551456928253, 0.03207635506987572, -0.04589490592479706, 0.02836056984961033, 0.0021858145482838154, -0.03040807507932186, -0.005272083915770054, -0.09499261528253555, 0.02900778315961361, 0.04424475505948067, -0.1085556223988533, -0.0681484192609787, 0.06064020097255707, -0.01969478279352188, 0.013662747107446194, -0.019487589597702026, -0.0007604890852235258, 0.058310750871896744, -0.024003056809306145, 0.047433771193027496, 0.054248206317424774, 0.007161911576986313, -0.01823415234684944, -0.06727707386016846, -0.036886800080537796, 0.008204308338463306, 0.02831847034394741, -0.06752441078424454, 0.038982074707746506, 0.017299463972449303, 0.03302909433841705, -0.06630115956068039, -0.013180413283407688, -0.1221807524561882, 0.0018416548846289515, 0.02863028086721897, -0.053605906665325165, 0.026554498821496964, 0.0236941147595644, -0.064520463347435, 0.12067131698131561, -0.11476953327655792, 0.07425200939178467, -0.0236598439514637, 0.01441460195928812, 0.044770821928977966, 0.07930441945791245, 0.026269569993019104, 0.07783999294042587, -0.06268855929374695, -0.058268480002880096, -0.03300169110298157, 0.015644188970327377, -0.05337940901517868, -0.07713281363248825, -0.026539089158177376, 0.029665514826774597, 0.02169976755976677, 0.012450803071260452, -0.026855027303099632, 0.026107586920261383, 0.04561566561460495, -0.07572956383228302, -0.07146399468183517, -0.02420223504304886, 0.06620725244283676, 0.08554321527481079, -0.08070294559001923, -0.008417253382503986, 0.0006242053932510316, 0.016619868576526642, 0.08448062092065811, -0.0328819714486599, -0.061457324773073196, 0.07233923673629761, 0.03505377098917961, 0.010852944105863571, -0.029644550755620003, 0.027628673240542412, 0.025931624695658684, -0.027586152777075768, -0.0277387835085392, -0.010183675214648247, -0.06034107133746147, 0.024010298773646355, -0.017193373292684555, 0.0031774076633155346, 0.027038689702749252, -0.03134063258767128, 0.01960652880370617, -0.014989483170211315, -0.004925877321511507, 0.0046471585519611835, -0.006636809557676315, 0.03609384596347809, 0.02079424262046814, -0.0012463401071727276, -0.046594493091106415, -0.02524750307202339, 0.017662113532423973, 0.044633250683546066, -0.0373598113656044, 0.01763848029077053, 0.03277940675616264, -0.0069900876842439175, 0.03004308231174946, -0.011551599949598312, 0.007233037613332272, -0.03460845351219177, 0.028923822566866875, 0.031293511390686035, 0.0009277442586608231, 0.021581990644335747, 0.020037047564983368, 0.01462570670992136, 0.0015098099829629064, -0.018526986241340637, 0.008606553077697754, 0.001916382578201592, 0.028227511793375015, -0.04636251926422119, 0.021411094814538956, -0.022521456703543663, -0.004589788615703583, -0.06947753578424454, 0.028108684346079826, 0.007574872113764286, -0.023265371099114418, -0.08667906373739243, 0.03494057431817055, 0.013834387995302677, 0.02574976719915867, -0.01135195605456829, -0.01629684865474701, 0.050948068499565125, -0.014694818295538425, 0.010319785214960575, 0.002113873604685068, 0.035468026995658875, 0.01884211227297783, -0.0006546346703544259, -0.024685515090823174, -0.021745992824435234, 0.0049944426864385605, -0.0032847688999027014, 0.004800498951226473, 0.01890496350824833, -0.01464580837637186, 0.01467437669634819, 0.004906580783426762, -0.02017364092171192, -0.03142181783914566, -0.02182832732796669, -0.012368137016892433, 0.042679671198129654, -0.012766009196639061, -0.02213786542415619, -0.02053706906735897, -0.005821545608341694, -0.03371261805295944, 0.01795235276222229, -0.053801361471414566, -0.038118112832307816, -0.024974316358566284, -0.017725076526403427, -0.047465573996305466, -0.015346168540418148, 0.014793668873608112, 0.0035050748847424984, 0.016454728320240974, 0.05011369660496712, -0.04699057713150978, 0.015831051394343376, -0.00428525498136878, -0.023289090022444725, -0.03153238072991371, 0.01448402926325798, -0.016030866652727127, -0.011944279074668884, -0.05500086396932602, 0.006951428484171629, 0.041111432015895844, 0.036576300859451294, -0.00939659308642149, -0.010259040631353855, 0.0609804131090641, 0.04560402035713196, 0.00811678171157837, -0.05169353261590004, -0.0035280503798276186, -0.0183451846241951, -0.026297016069293022, -0.05714357644319534, 0.10504714399576187, -0.018043402582406998, 0.017577027902007103, -0.003946235403418541, 0.03685162961483002, -0.012551204301416874, 0.03668714314699173, -0.01632213406264782, 0.007159509230405092, -0.01265076082199812, 0.005320474971085787, -0.046896886080503464, -0.04015136510133743, 0.010488396510481834, 0.015241310000419617, -0.006956641096621752, -0.009149562567472458, -0.027845706790685654, -0.006191030144691467, 0.018395481631159782, 0.04138863831758499, -0.042410023510456085, 0.01425662636756897, 0.0020508484449237585, 0.013318589888513088, 0.04779833182692528, -0.01258690096437931, -0.019123591482639313, 0.015449927188456059, -0.026844646781682968, 0.02083844132721424, 0.016021570190787315, -0.02675667777657509, 0.03162701800465584, 0.0014053303748369217, 0.0013720868155360222, -0.07177398353815079, -0.038018010556697845, 0.0025651941541582346, 0.01564033329486847, 0.03288523852825165, -0.055948272347450256, -0.037524957209825516, 0.019929345697164536, -0.01327479723840952, -0.01061048824340105, -0.004916306119412184, -0.03103630803525448, -0.010780544951558113, 0.0407288521528244, 0.009660879150032997, 0.03800157830119133, -0.03065424971282482, 0.021421775221824646, -0.03707791119813919, -0.019508706405758858, -0.014602134004235268, 0.03632637858390808, 0.011401792988181114, -0.005951060447841883, 0.003929915372282267, 0.054417748004198074, 0.014333296567201614, 0.027783460915088654, -0.044012028723955154, -0.012832590378820896, 0.017822226509451866, 0.01698954962193966, 0.018773037940263748, 0.049471572041511536, 0.015749435871839523, 0.02060694992542267, -0.02323595993220806, 0.06500287353992462, -0.020033523440361023, -0.02936123125255108, -0.02350807748734951, -0.004404514096677303, -0.05091340094804764, 0.004584914539009333, 0.0524577833712101, 0.0041372887790203094, 0.01548533234745264, 0.021539699286222458, 0.002888075076043606, 0.01932527683675289, -0.011786297895014286, -0.022431328892707825, -0.028670094907283783, 0.010589242912828922, -0.013769841752946377, 0.01921517588198185, 0.018897540867328644, 0.01230231299996376, -0.012203874066472054, 0.019273191690444946, 0.017525076866149902, 0.010398627258837223, 0.031761717051267624, 0.012421934865415096, -0.051757313311100006, 0.005594728514552116, -0.0211923960596323, 0.003125410992652178, 0.0003228503337595612, -0.02323000133037567, 0.03159832954406738, 0.03347422927618027, -0.0051482003182172775, 0.005901863798499107, 0.0356355644762516, -0.008724951185286045, 0.04563508182764053, -0.055946312844753265, -0.006407011765986681, -0.025942344218492508, 0.0038272985257208347, 0.026847293600440025, -0.04931056126952171, -0.02971775457262993, 0.023207999765872955, 0.07247522473335266, 0.028052931651473045, 0.009384098462760448, 0.06258399039506912, -0.03619137778878212, 0.007335739675909281, -0.0071822237223386765, 0.008166749030351639, -0.03515861928462982, -0.029737574979662895, -0.02922738529741764, 0.022393066436052322, -0.04757749289274216, 0.005862108897417784, 0.02570788748562336, 0.016860531643033028, 0.07113856822252274, -0.05108252540230751, 0.021769482642412186, -0.03455231338739395, -0.00047425253433175385, -0.030856184661388397, 0.022453075274825096, -0.0554208867251873, 0.053064897656440735, 0.018944213166832924, -0.06118746101856232, 0.026185834780335426, 0.02509777806699276, 0.02563989721238613, 0.012241668999195099, 0.0211640615016222, -0.03826130926609039, 0.041044048964977264, -0.00033524291939102113, -0.026762567460536957, -0.02554192766547203, 0.05346115678548813, 0.03159274533390999, 0.0016774567775428295, 0.013773527927696705, 0.01885189861059189, -0.01478687021881342, 0.01261318102478981, 0.026008356362581253, -0.01662990264594555, 0.007575251627713442, 0.04405984655022621, -0.0020758467726409435, -0.02860039472579956, -0.006733159068971872, 0.011898832395672798, 0.01859333924949169, -0.010628823190927505, 0.022743714973330498, 0.0016816607676446438, -0.002946431515738368, 0.026172077283263206, -0.017916468903422356, 0.01806357316672802, 0.01692233793437481, -0.011459507048130035, 0.02884676679968834, 0.04311690106987953, 0.06414161622524261, 0.007386321201920509, 0.018915848806500435, -0.006121146492660046, 0.012667135335505009, 0.007021259982138872, 0.072406105697155, -0.009406599216163158, 0.009438669309020042, -0.03772399201989174, 0.0186101496219635, -0.041578054428100586, -0.01096632331609726, -0.013262615539133549, 0.009348787367343903, 0.030094444751739502, -0.005697785411030054, -0.057990457862615585, -0.0008461672114208341, 0.01966022327542305, 0.01976635307073593, 0.005686690099537373, -0.004970165900886059, 0.012197253294289112, -0.009857837110757828, -0.04992179945111275, -0.03219267353415489, 0.09200523048639297, -0.004160543438047171, 0.06422790884971619, -0.006150379776954651, 0.022504756227135658, 0.02230697125196457, 0.04909554496407509, 0.01369588915258646, 0.008296307176351547, 0.040416169911623, 0.012810591608285904, -0.021307270973920822, 0.021511249244213104, 0.02924622967839241, 0.004290635231882334, -0.06329362839460373, 0.01332663930952549, 0.020486995577812195, 0.018552124500274658, 0.011931199580430984, -0.03651624917984009, 0.014176053926348686, -0.02147374115884304, 0.0735846608877182, 0.0220582727342844, 0.04184741899371147, -0.03802396357059479, 0.04138283059000969, 0.03229515999555588, 0.0056606316938996315, 0.013829730451107025, -0.018025187775492668, -0.0009570926777087152, 0.04674255847930908, 0.0461692214012146, 0.010385523550212383, -0.01010816264897585, -0.012968461960554123, 0.026645150035619736, 0.003528090426698327, -0.005487208720296621, -0.04511433467268944, 0.008574058301746845, 0.0006897748098708689, -0.01569337397813797, 0.030559493228793144, -0.0045797680504620075, -0.010213657282292843, -0.034715794026851654, -0.015858061611652374, -0.045459091663360596, -0.016560083255171776, 0.0194660983979702, 0.008497124537825584, 0.02708885818719864, 0.02264447510242462, -0.04351983964443207, -0.014391434378921986, 0.009441718459129333, 0.02871735394001007, 0.022194605320692062, -0.012229666113853455, 0.019112005829811096, -0.010860082693397999, 0.008195466361939907, -0.04863964766263962, -0.0419558621942997, -0.03064909018576145, 0.021184703335165977, 0.018880141898989677, 0.019376391544938087, 0.024289479479193687, 0.024541322141885757, -0.0017851069569587708, 0.046299275010824203, -0.048847999423742294, 0.005974780302494764, -0.019289778545498848, -0.03045881725847721, -0.002892888616770506, -0.017785871401429176, 0.017421338707208633, 0.009962025098502636, 0.014904937706887722, -0.0004995380877517164, 0.03626390919089317, -0.05864884331822395, -0.041451677680015564, -0.0011817675549536943, -0.005406292621046305, -0.02732669562101364, -0.0013343108585104346, 0.00031824730103835464, 0.04089442640542984, -0.0013284786837175488, -0.004273776896297932, 0.00029079895466566086, 0.014942270703613758, -0.013741999864578247, 0.050078071653842926, -0.016775840893387794, -0.02075100690126419, -0.03593004122376442, 0.0451582670211792, 0.02522200345993042, 0.006372155621647835, 0.03826116770505905, 0.009479425847530365, 0.044298723340034485, 0.01387140154838562, 0.010158581659197807, -0.058505017310380936, -0.0408894419670105, -0.029004590585827827, -0.043636396527290344, -0.024753345176577568, 0.006818839348852634, 0.009146740660071373, 0.024695057421922684, -0.019873637706041336, 0.020264482125639915, -0.010561631061136723, -0.048465974628925323, -0.012452979572117329, 0.0046232338063418865, 0.059583816677331924, -0.01071377843618393, -0.009730195626616478, 0.04909864440560341, -0.006302692927420139, -0.005708286538720131, 0.020911766216158867, 0.04589540883898735, 0.038389354944229126, 0.0344650037586689, -0.005505562759935856, 0.0114557184278965, 0.016734043136239052, -0.0198146253824234, 0.01495598815381527, 0.016151994466781616, 0.01642034947872162, -0.07329069077968597, -0.025539960712194443, 0.04883958399295807, 0.008746236562728882, -0.043889231979846954, -0.0038123922422528267, 0.036146700382232666, 0.0040380870923399925, 0.026394350454211235, 0.013334259390830994, -0.05836975574493408, -0.030817320570349693, -0.013363293372094631, 0.019009046256542206, -0.004796523600816727, -0.004018318373709917, 0.01578460820019245, 0.014835426583886147, -0.0384342260658741, -0.01788639836013317, -0.0042597465217113495, 0.013426523655653, -0.022704510018229485, -0.00836294237524271, 0.041014544665813446, -0.02518741972744465, -0.014786058105528355, 0.07383006811141968, 0.0035439792554825544, -0.016328975558280945, 0.027225380763411522, 0.023748081177473068, 0.008672685362398624, -0.017085304483771324, -0.01764586754143238, 0.016847757622599602, 0.028141887858510017, -0.0008109226473607123, 0.017208514735102654, 0.00997599121183157, 0.0257122740149498 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
A guest blog post by Stas Bekman This article is an attempt to document how fairseq wmt19 translation system was ported to transformers. I was looking for some interesting project to work on and Sam Shleifer suggested I work on porting a high quality translator. I read the short paper: Facebook FAIR's WMT19 News Translation Task Submission that describes the original system and decided to give it a try. Initially, I had no idea how to approach this complex project and Sam helped me to break it down to smaller tasks, which was of a great help. I chose to work with the pre-trained en-ru/ru-en models during porting as I speak both languages. It'd have been much more difficult to work with de-en/en-de pairs as I don't speak German, and being able to evaluate the translation quality by just reading and making sense of the outputs at the advanced stages of the porting process saved me a lot of time. Also, as I did the initial porting with the en-ru/ru-en models, I was totally unaware that the de-en/en-de models used a merged vocabulary, whereas the former used 2 separate vocabularies of different sizes. So once I did the more complicated work of supporting 2 separate vocabularies, it was trivial to get the merged vocabulary to work.
[ 0.03923000022768974, -0.05211571231484413, 0.03107818216085434, -0.014141774736344814, 0.06225140765309334, 0.058814190328121185, 0.03117096610367298, 0.04967828467488289, 0.0587213970720768, 0.012692366726696491, -0.02714722789824009, 0.05285368859767914, 0.040851008147001266, 0.0686727836728096, 0.0008468616870231926, -0.010327386669814587, -0.01168669480830431, -0.04344550892710686, 0.03461054340004921, -0.014608312398195267, -0.039442289620637894, -0.05808013305068016, 0.0987560823559761, -0.0003371904604136944, 0.07586119323968887, -0.034083396196365356, 0.007452974561601877, 0.04705297201871872, -0.036280203610658646, 0.008065732195973396, -0.04685452952980995, -0.037620123475790024, -0.059330474585294724, -0.10086510330438614, -0.07302263379096985, 0.051744695752859116, -0.03195023164153099, 0.04796780273318291, -0.03383834660053253, -0.1091253012418747, -0.0024844196159392595, 0.026006082072854042, -0.037418268620967865, 0.05766793712973595, 0.0073153916746377945, 0.021496547386050224, -0.0816119909286499, 0.011638257652521133, -0.0559464730322361, -0.00757945328950882, -0.010544428601861, 0.01627308689057827, 0.021666768938302994, 0.06254138797521591, -0.021212350577116013, 0.06379351019859314, -0.027259554713964462, -0.049268655478954315, -0.004655058961361647, 0.012007820419967175, -0.007194461300969124, 0.013787375763058662, 0.019098039716482162, 0.022161409258842468, -0.027549024671316147, -0.04194793105125427, -0.03886728733778, 0.02191784605383873, -0.007490052375942469, -0.018686121329665184, -0.04844388738274574, -0.034546006470918655, -0.03302813693881035, -0.06635630130767822, -0.013897650875151157, -0.07055556774139404, 0.011729416437447071, -0.003545115003362298, 0.019067885354161263, 0.07248718291521072, -0.041012927889823914, 0.04807715117931366, 0.05755673348903656, 0.026649709790945053, 0.05610789358615875, -0.062365900725126266, 0.06939078122377396, -0.048320624977350235, -0.055727098137140274, 0.03496488928794861, -0.005475276615470648, -0.1278296858072281, -0.11009470373392105, -0.0011383582605049014, 0.08775123208761215, 0.006245121359825134, 0.056001897901296616, 0.09971688687801361, -0.028531448915600777, 0.023777823895215988, -0.0009474458056502044, 0.02690950036048889, 0.10343343019485474, -0.011220092885196209, -0.008507371880114079, -0.003689574310556054, -0.036003150045871735, -0.1357833296060562, 0.04411519318819046, 0.03368299454450607, 0.03041490726172924, -0.0015676973853260279, 0.022042974829673767, 0.044229019433259964, -0.020829210057854652, 0.01213020272552967, 0.033801786601543427, -0.0337224006652832, -0.008741033263504505, 0.02030111849308014, 0.04457038268446922, 0.0894598439335823, 0.0019524802919477224, -0.012151344679296017, 0.010904325172305107, 0.030309630557894707, 0.06627681851387024, -0.02783970534801483, -0.0709751769900322, -0.031467292457818985, 0.018220121040940285, 0.03538906201720238, 0.04880175366997719, 0.0340806245803833, -0.0537400059401989, -0.07201912254095078, 0.065965436398983, 0.011838319711387157, -0.02593531645834446, -0.0369393564760685, 0.00029641727451235056, 0.05680330470204353, -0.04531220346689224, 0.01403999887406826, -0.027824627235531807, 0.057002488523721695, -0.10625022649765015, 0.038217268884181976, 0.023194342851638794, 0.022294940426945686, -0.007295773830264807, -0.0008532926440238953, -0.012839345261454582, -0.06385691463947296, 0.045481786131858826, 0.0010864170035347342, -0.01430426724255085, -0.06502928584814072, -0.06869245320558548, -0.04463138431310654, -0.05684833973646164, 0.03822408989071846, -0.05124044790863991, -0.020624235272407532, -0.04732857644557953, -0.06723512709140778, -0.052518580108881, 0.03907039389014244, 0.05200032517313957, 0.018521783873438835, 0.08085935562849045, 0.026937538757920265, 0.07664402574300766, -0.0020681461319327354, -0.06564398109912872, 0.03816823661327362, 0.05143243074417114, 0.04321293532848358, 0.039167869836091995, -0.02635463885962963, -0.08325834572315216, 0.026876799762248993, -0.010005520656704903, 0.040307845920324326, 0.031889088451862335, -0.015944553539156914, -0.003553957911208272, -0.006874452345073223, -0.08250194042921066, 0.016742711886763573, -0.09026581048965454, -0.031755950301885605, 0.07663395255804062, -0.01717137172818184, -0.017310969531536102, 0.018981900066137314, 0.011655943468213081, 0.08354850113391876, 0.030995691195130348, 0.07882242649793625, 0.10637212544679642, -0.03670240938663483, -0.00743398442864418, -0.01080418098717928, 0.0008120340062305331, 0.01048910804092884, 0.004436278250068426, -0.030673282220959663, -0.030530810356140137, 0.044904373586177826, 0.032164834439754486, -0.05697895586490631, 0.03338483348488808, -0.007315604481846094, -0.012264220044016838, -0.050019752234220505, -0.026164183393120766, 0.015498649328947067, -0.002169431885704398, -0.057142723351716995, 0.08188082277774811, -0.022050730884075165, -0.08473770320415497, 0.0004272283404134214, 0.03416811302304268, 0.0029424726963043213, 0.07556020468473434, 0.02627427875995636, 0.0175494235008955, -0.017585279420018196, -0.034041982144117355, 0.03180032968521118, 0.029727552086114883, -0.024193640798330307, -0.07041984796524048, -0.05685156583786011, -0.021272648125886917, -0.02730325609445572, 0.014490787871181965, -0.03872537985444069, 0.04098427668213844, 0.0452723391354084, 0.0123578617349267, 0.014981869608163834, -0.028412623330950737, 0.018735680729150772, 0.08064985275268555, 0.022820712998509407, 0.05593631789088249, -0.013882149942219257, -0.03481799736618996, 0.06114013493061066, 0.007032916881144047, -0.06071414053440094, 0.046743281185626984, -0.02111181616783142, 0.029807476326823235, 0.002559776185080409, 0.04704154655337334, 0.017485376447439194, -0.010363523848354816, 0.008672937750816345, -0.018192527815699577, -0.060334961861371994, 0.025822561234235764, -0.055273059755563736, -0.012986295856535435, 0.003967260010540485, -0.019838564097881317, -0.009450732730329037, -0.05259096994996071, -0.008236682042479515, 0.03195575624704361, -0.03856632485985756, 0.008843116462230682, -0.019103800877928734, -0.017667412757873535, -0.002244026167318225, 0.0022760871797800064, 0.005635601468384266, -0.014080422930419445, 0.01147743035107851, 0.030775705352425575, 0.011600740253925323, 0.0026110922917723656, -0.0037426860071718693, 0.006043892819434404, -0.024977710098028183, -0.01170257292687893, 0.03347393870353699, 0.007092387415468693, 0.002684319159016013, -0.00917106680572033, 0.024839388206601143, -0.04063842445611954, -0.0004361575411166996, -0.0014792496804147959, -0.026621129363775253, -0.0013115667970851064, 0.03712109103798866, -0.022867361083626747, 0.025390470400452614, -0.0034955188166350126, 0.0496147982776165, -0.053731322288513184, -0.02354130707681179, -0.024591505527496338, -0.00712253712117672, -0.08722740411758423, -0.014201119542121887, -0.025816157460212708, 0.03986813500523567, -0.019351426512002945, -0.008517883718013763, -0.0014688086230307817, -0.03254477307200432, 0.00682772696018219, 0.044796865433454514, 0.011933136731386185, 0.0029558190144598484, 0.011820504441857338, 0.01372469961643219, -0.0080541567876935, -0.000958577380515635, -0.024127639830112457, 0.032688308507204056, 0.033184830099344254, 0.007098538335412741, -0.02312617190182209, 0.008160625584423542, 0.026907572522759438, -0.003737775143235922, -0.005792512558400631, 0.0003039894509129226, 0.028377674520015717, -0.010317898355424404, -0.019003337249159813, -0.006519865710288286, -0.009566630236804485, 0.03568658232688904, 0.041938960552215576, 0.007008852902799845, -0.019985567778348923, -0.0186576209962368, 0.010735630989074707, 0.03287005051970482, -0.024106120690703392, 0.024962756782770157, -0.013125337660312653, 0.010871863923966885, 0.022617744281888008, -0.05182689055800438, 0.0009817277314141393, 0.0006412786315195262, -0.011613419279456139, -0.020001953467726707, 0.03151107579469681, 0.006028416100889444, -0.034784946590662, -0.011564379557967186, 0.004540193360298872, 0.06650563329458237, -0.03607245907187462, -0.023963944986462593, 0.010954681783914566, -0.008965831249952316, 0.013868423178792, 0.017197219654917717, -0.035885028541088104, 0.007265008520334959, -0.0796734020113945, -0.013632909394800663, -0.03501545637845993, 0.08529089391231537, 0.02181938849389553, 0.048660311847925186, 0.027128666639328003, 0.02396511100232601, -0.02991958148777485, 0.02241295948624611, -0.0020562359131872654, -0.002334224060177803, 0.01694798655807972, 0.03243957832455635, -0.020377445966005325, -0.02620517835021019, 0.019466182217001915, -0.0022331445943564177, -0.028689175844192505, -0.02354581281542778, -0.03606989607214928, -0.03230193629860878, 0.025753909721970558, 0.004536750726401806, 0.016620967537164688, -0.0178687646985054, -0.014314541593194008, 0.016786392778158188, 0.02703872136771679, -0.0565640851855278, -0.017521502450108528, -0.014652104116976261, 0.007390894927084446, -0.061243411153554916, -0.005102778784930706, -0.010573315434157848, -0.0072254398837685585, 0.0029806913807988167, 0.01868402399122715, -0.038400743156671524, -0.025210123509168625, -0.006617500446736813, 0.030044784769415855, 0.05703415349125862, -0.03629094734787941, -0.020306793972849846, 0.02119298093020916, 0.04988441616296768, 0.0069739725440740585, -0.013312846422195435, -0.06924653053283691, 0.024078642949461937, 0.042819853872060776, -0.0019748485647141933, -0.013206138275563717, -0.07191270589828491, 0.011815257370471954, -0.0051354458555579185, -0.002595665864646435, -0.04710731655359268, 0.024237658828496933, -0.014020264148712158, -0.05212929844856262, -0.00434004096314311, 0.03224456310272217, 0.04558271914720535, -0.05161673575639725, 0.0179617740213871, -0.02527199685573578, -0.015857256948947906, 0.025111157447099686, -0.0045576454140245914, 0.04187988489866257, 0.05019047483801842, 0.016138503327965736, 0.01928989589214325, -0.018199080601334572, -0.023170724511146545, -0.007422628812491894, -0.003510670270770788, 0.043603260070085526, -0.044492583721876144, 0.01704142987728119, 0.021528879180550575, 0.02997768484055996, -0.02814040146768093, -0.013044217601418495, 0.007328779436647892, 0.031890567392110825, -0.03749358654022217, -0.028033388778567314, 0.03313619643449783, 0.008655969984829426, -0.013136843219399452, 0.026075441390275955, 0.007799473591148853, 0.028329728171229362, 0.015708107501268387, 0.004680412355810404, -0.0084048667922616, -0.06303288787603378, 0.015971962362527847, 0.010134011507034302, -0.036013297736644745, 0.01639128103852272, -0.04088782146573067, -0.006503019016236067, 0.02097582444548607, -0.013218852691352367, -0.022711874917149544, 0.03952636942267418, -0.011621375568211079, -0.004131143447011709, 0.061956971883773804, -0.024336060509085655, 0.005610916763544083, 0.0017936077201738954, -0.05000557005405426, 0.012547090649604797, 0.04310882091522217, 0.003014196874573827, -0.0032005012035369873, -0.05667663365602493, 0.029772600159049034, 0.008501958101987839, 0.06616109609603882, 0.008937857113778591, 0.009054109454154968, -0.008195250295102596, 0.006131745409220457, -0.0180390402674675, -0.018311847001314163, -0.023707648739218712, -0.038335274904966354, 0.03398676961660385, -0.015016094781458378, -0.022531813010573387, 0.040279123932123184, 0.02827974408864975, 0.0366818793118, 0.012323572300374508, 0.0024570380337536335, 0.02786153368651867, -0.03291571885347366, -0.01692674681544304, -0.0461997427046299, 0.015468806028366089, -0.0568302720785141, -0.025402894243597984, 0.014806798659265041, 0.02112344279885292, -0.02332949824631214, -0.009030025452375412, -0.06475304067134857, -0.005523308180272579, 0.033503856509923935, 0.003935433924198151, 0.03461311757564545, -0.007842312566936016, 0.005519692320376635, -0.0072084469720721245, 0.023451050743460655, 0.004103876184672117, -0.008667733520269394, 0.0153877642005682, -0.03008500300347805, 0.030218465253710747, -0.019029924646019936, 0.016853652894496918, 0.0017979651456698775, -0.014935625717043877, 0.037151999771595, 0.03599674627184868, -0.04069490358233452, 0.014819098636507988, 0.013483935967087746, 0.010206051170825958, 0.037118129432201385, 0.04720363765954971, -0.05174897983670235, 0.012157035060226917, 0.04091202840209007, -0.006756992544978857, 0.04623287543654442, 0.04652802646160126, -0.008774605579674244, -0.0013468691613525152, -0.009857142344117165, -0.009219122119247913, 0.0217116791754961, -0.0034827773924916983, 0.01623576506972313, -0.00029151057242415845, 0.012397636659443378, 0.04215541481971741, 0.04696102440357208, 0.012185475789010525, -0.039385195821523666, 0.055072326213121414, -0.025620965287089348, -0.04546790197491646, 0.029391268268227577, -0.02269534021615982, 0.03134093061089516, 0.005799612496048212, 0.0014868128346279263, 0.0013251026393845677, 0.008318834006786346, 0.03274217247962952, 0.00395513791590929, 0.03201465308666229, 0.05448603257536888, -0.004055429715663195, -0.05217260867357254, 0.04536254703998566, 0.02364291623234749, 0.033679135143756866, -0.00344385439530015, 0.027678798884153366, -0.00599611084908247, 0.012801487930119038, -0.03386101871728897, 0.01611527055501938, 0.033070776611566544, 0.05465294048190117, 0.012860463932156563, 0.004005948547273874, -0.02485029399394989, -0.014297060668468475, -0.06030399724841118, -0.014746278524398804, -0.008365378715097904, -0.04256604239344597, 0.032767098397016525, 0.03193025663495064, -0.011462482623755932, -0.00607100035995245, 0.030865633860230446, 0.07725093513727188, 0.023656269535422325, 0.037115633487701416, -0.0007526818080805242, 0.051696039736270905, 0.06122894585132599, 0.010206243954598904, 0.04908361658453941, 0.01133028231561184, -0.004313080105930567, 0.022272931411862373, 0.04220091179013252, -0.03253662958741188, 0.03169006481766701, -0.041374798864126205, -0.009223558939993382, -0.0243854820728302, -0.02878222055733204, -0.005074433516710997, 0.03714432939887047, -0.011854133568704128, -0.04427533224225044, 0.007996976375579834, 0.05768975615501404, -0.013826802372932434, 0.02437206171452999, 0.008937894366681576, -0.02539367415010929, -0.04782529175281525, -0.027396297082304955, -0.018895374611020088, 0.06090804561972618, -0.029565127566456795, -0.04626517742872238, -0.028609678149223328, -0.022129597142338753, 0.028471311554312706, 0.030704839155077934, 0.03371955081820488, 0.04350888356566429, -0.046814847737550735, -0.012441200204193592, -0.002875076374039054, -0.051031239330768585, 0.017800629138946533, 0.009423344396054745, 0.03616471588611603, 0.019554520025849342, -0.010441223159432411, 0.030363962054252625, -0.010791395790874958, 0.01820659264922142, -0.037015482783317566, 0.03791675716638565, 0.00886594969779253, -0.03587418049573898, 0.05562436208128929, -0.0622105598449707, -0.03011433035135269, 0.024704257026314735, -0.02574295550584793, 0.032836511731147766, 0.04939109832048416, -0.023868920281529427, -0.03405363857746124, 0.0072350529953837395, -0.00848319660872221, -0.021076321601867676, -0.007740625645965338, 0.01043604128062725, 0.01806921325623989, 0.04024243354797363, -0.024379059672355652, 0.020112419500947, 0.011844854801893234, -0.03664695844054222, 0.03703668713569641, -0.035012129694223404, 0.021853100508451462, -0.0627966895699501, 0.05460160970687866, 0.021112333983182907, 0.021599596366286278, 0.06057476997375488, 0.005677510052919388, 0.0032471641898155212, 0.005736209452152252, -0.024702072143554688, 0.020859362557530403, 0.0155009925365448, 0.0075794123113155365, -0.05015718191862106, -0.015140527859330177, 0.02288016304373741, -0.013535518199205399, 0.04299807921051979, -0.028639432042837143, 0.021550804376602173, -0.06687020510435104, -0.039755094796419144, 0.006698034703731537, 0.02346344292163849, 0.0893760547041893, 0.00786497350782156, 0.005851794965565205, -0.004196716006845236, -0.01010610070079565, -0.03263828158378601, -0.012358022853732109, 0.017377136275172234, 0.07079154253005981, -0.014740905724465847, 0.01585736870765686, 0.034450747072696686, 0.01278862077742815, -0.037078019231557846, -0.048972006887197495, -0.009800967760384083, 0.02713930793106556, 0.004135390277951956, -0.0025627745781093836, 0.029739923775196075, 0.02804824523627758, -0.030668342486023903, -0.03997384384274483, -0.05081380158662796, 0.008390665054321289, 0.0021866909228265285, -0.009699833579361439, -0.04664825275540352, -0.0065325540490448475, -0.0005557808908633888, 0.026276007294654846, -0.012149247340857983, 0.002703909296542406, -0.003568109590560198, 0.019408533349633217, -0.008307085372507572, -0.010824988596141338, 0.01818658597767353, 0.010733622126281261, -0.03496857360005379, 0.014931333251297474, 0.04440220072865486, -0.04235361889004707, -0.07925335317850113, 0.03578655794262886, 0.01535622775554657, -0.02760341577231884, -0.020523929968476295, -0.009035960771143436, -0.07202676683664322, -0.0550936721265316, 0.0008456427021883428, 0.04765109717845917, 0.024860262870788574, -0.01158341858536005, -0.014422189444303513, 0.03171582520008087, -0.008615351282060146 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Porting the core translation functionality Having had a relatively quick success with porting the tokenizer (obviously, thanks to most of the code being there already), the next stage was much more complex. This is thegenerate()function which takes inputs ids, runs them through the model and returns output ids. I had to break it down into multiple sub-tasks. I had to 1. port the model weights. 2. makegenerate()work for a single beam (i.e. return just one result). 3. and then multiple beams (i.e. return multiple results). I first researched which of the existing architectures were the closest to my needs. It was BART that fit the closest, so I went ahead and did: ``` cp modeling_bart.py modeling_fsmt.py perl -pi -e 's|Bart|FSMT|ig; s|bart|fsmt|g;' modeling_fsmt.py ``` This was my starting point that I needed to tweak to work with the model weights provided byfairseq.
[ 0.050141334533691406, 0.02390271984040737, 0.004708299413323402, -0.05249166116118431, 0.026403872296214104, 0.09524404257535934, -0.013870038092136383, 0.016978545114398003, -0.010556532070040703, 0.02484409138560295, -0.021132808178663254, -0.041030652821063995, 0.011120045557618141, 0.015359828248620033, 0.0364324115216732, 0.014271711930632591, 0.03015204705297947, -0.0631282776594162, 0.030837876722216606, -0.02276694029569626, 0.035916972905397415, -0.04966617375612259, 0.054276153445243835, 0.005924227647483349, -0.0491534098982811, -0.0014003944816067815, -0.007200355641543865, 0.06612195819616318, -0.060144681483507156, 0.03261197730898857, -0.0605262815952301, 0.0219461377710104, 0.003106992691755295, -0.05896400660276413, -0.039408378303050995, 0.022240741178393364, -0.11010439693927765, 0.04488168656826019, 0.004350672475993633, -0.059136565774679184, -0.0008538338006474078, 0.04293264448642731, -0.004335741046816111, 0.023173736408352852, -0.016322605311870575, 0.05276559293270111, -0.1251431554555893, 0.033861394971609116, 0.003956473898142576, -0.03786248713731766, -0.08191588521003723, 0.01644294708967209, -0.025701167061924934, -0.004674439784139395, 0.0447380356490612, -0.0014223295729607344, -0.05217314139008522, -0.09293293952941895, -0.016886353492736816, 0.030979091301560402, -0.0517069473862648, 0.04059511423110962, 0.029989659786224365, 0.06464656442403793, 0.03544340282678604, 0.05795034393668175, -0.03685484081506729, -0.022782625630497932, -0.052674565464258194, 0.028943514451384544, -0.013016512617468834, 0.019735729321837425, -0.02149116061627865, -0.043209321796894073, 0.03281794860959053, -0.06053107604384422, -0.0073476224206388, 0.03501540794968605, 0.061677344143390656, 0.044899098575115204, 0.031730715185403824, 0.08283962309360504, 0.04848352074623108, -0.01803419552743435, 0.07190842926502228, -0.0029543519485741854, 0.035734131932258606, -0.08170963823795319, -0.014187311753630638, 0.031209737062454224, -0.05054761841893196, -0.13740801811218262, -0.07376612722873688, 0.02712630294263363, 0.07201983779668808, 0.007392281200736761, -0.01184639148414135, 0.05245819315314293, 0.05705279856920242, 0.02482415735721588, 0.01674111746251583, -0.05131393298506737, 0.039848342537879944, -0.007361983880400658, 0.006829921156167984, 0.03957786038517952, 0.016893522813916206, -0.12000422179698944, -0.05138237401843071, -0.01921023614704609, 0.015630509704351425, 0.008196983486413956, -0.016642194241285324, 0.06841257959604263, -0.0012883853632956743, -0.006539241410791874, -0.004018108826130629, -0.00005976484317216091, 0.01764315739274025, -0.0026102561969310045, 0.019730817526578903, 0.03166354075074196, 0.07023221999406815, -0.06582861393690109, 0.06063656136393547, 0.044312916696071625, 0.06625983864068985, 0.010771716013550758, -0.0018701145891100168, -0.028703764081001282, 0.008498438633978367, -0.014427751302719116, 0.07825850695371628, 0.03524308279156685, -0.014711438678205013, -0.10096950083971024, -0.015358315780758858, -0.026709621772170067, -0.0167271476238966, -0.05861744284629822, -0.017010988667607307, -0.012290491722524166, -0.022927146404981613, 0.014192737638950348, -0.00808286014944315, 0.03030732087790966, -0.05628030002117157, 0.04581964388489723, 0.03104659914970398, -0.027000224217772484, -0.06475616246461868, 0.016758505254983902, -0.04829670116305351, -0.06313937902450562, 0.02635093592107296, 0.06503941118717194, 0.028494594618678093, -0.026037968695163727, -0.03878090903162956, 0.0022568260319530964, -0.03493814915418625, 0.02886239066720009, -0.04697086662054062, -0.05288354679942131, 0.013429474085569382, -0.01604164019227028, 0.005001204088330269, 0.02641487494111061, 0.07110115885734558, 0.032515134662389755, 0.06568273156881332, 0.004442100878804922, 0.08654831349849701, -0.019613390788435936, -0.027449585497379303, -0.02464587241411209, 0.027901582419872284, 0.037448424845933914, -0.032133836299180984, -0.005606553982943296, -0.02729222923517227, 0.023087354376912117, -0.02822425775229931, -0.0005975415697321296, -0.03450460359454155, -0.06087786331772804, 0.014955560676753521, -0.06651969999074936, 0.00838709156960249, 0.035376206040382385, -0.1166987344622612, -0.022824764251708984, 0.0800248235464096, -0.006003331858664751, 0.007587190717458725, -0.03154844045639038, -0.01816275343298912, 0.08556942641735077, 0.012105490081012249, 0.08104109019041061, 0.057835903018713, 0.018825436010956764, 0.03648151457309723, -0.03436484560370445, 0.005781501065939665, 0.037957947701215744, -0.046892017126083374, -0.05990235134959221, 0.038248635828495026, 0.06798205524682999, 0.008975678123533726, -0.08574412018060684, -0.0037066671065986156, -0.07849141955375671, -0.05389627441763878, -0.037835512310266495, -0.055122096091508865, 0.03265863656997681, -0.03731769695878029, -0.03548960015177727, 0.165334552526474, -0.08178887516260147, -0.00020191776275169104, -0.03157855570316315, -0.028654634952545166, 0.06436145305633545, 0.11398713290691376, 0.016729068011045456, 0.001825970015488565, -0.044865187257528305, -0.004470745101571083, -0.023116908967494965, 0.04729152470827103, 0.05596061795949936, -0.06532115489244461, 0.01550295576453209, -0.004506121389567852, -0.0041615329682827, 0.03953211382031441, -0.0041537173092365265, 0.0063756126910448074, 0.05941009148955345, -0.06657246500253677, -0.030840357765555382, 0.009538373909890652, 0.06580003350973129, 0.07031592726707458, -0.02812529169023037, -0.016461258754134178, -0.01283499225974083, -0.021847302094101906, 0.06792832165956497, -0.012934443540871143, -0.05454498529434204, 0.09016552567481995, 0.02536013536155224, 0.015607365407049656, -0.004067476373165846, 0.012229323387145996, -0.004596681334078312, -0.05444290116429329, 0.03288749232888222, -0.06066152825951576, -0.07301674038171768, 0.004825202282518148, -0.027708224952220917, 0.023754602298140526, -0.030295033007860184, -0.03866966813802719, -0.006949853617697954, -0.002751005347818136, -0.024925801903009415, -0.006001865956932306, -0.005155245773494244, 0.01616079732775688, 0.041066523641347885, 0.022818539291620255, -0.03703205659985542, -0.046579357236623764, -0.004000348970293999, -0.016536813229322433, -0.04225138947367668, 0.014686372131109238, 0.019443150609731674, -0.007213504984974861, -0.013447936624288559, -0.0013240976259112358, -0.024545129388570786, -0.02712012641131878, 0.032858844846487045, 0.04996798560023308, -0.03564634546637535, 0.011861691251397133, 0.01323285885155201, -0.017265794798731804, -0.006559399422258139, -0.015922484919428825, 0.004509435500949621, 0.0038186172023415565, 0.009606488980352879, -0.024708690121769905, 0.038601987063884735, 0.005861932877451181, 0.04272935166954994, -0.07433284819126129, 0.00722276559099555, 0.030200893059372902, -0.01167169027030468, -0.09339603781700134, -0.0004443442157935351, -0.01873083971440792, 0.05115175247192383, -0.014678115025162697, -0.024633489549160004, 0.020556114614009857, -0.021260447800159454, 0.0047141388058662415, -0.0012392697390168905, 0.03354249522089958, 0.008386928588151932, 0.022336948662996292, -0.0008602703455835581, -0.03007020428776741, 0.013572323136031628, -0.033808812499046326, 0.004606314469128847, 0.04586610198020935, 0.032237857580184937, 0.007264610379934311, -0.00538904732093215, 0.014675315469503403, -0.03871634230017662, -0.01676478423178196, -0.0439520925283432, 0.035973336547613144, -0.011110453866422176, -0.005570945329964161, -0.029486387968063354, -0.023660631850361824, -0.012157711200416088, 0.03239910677075386, -0.03927086293697357, -0.023361964151263237, -0.02579416148364544, 0.0064287204295396805, 0.026455670595169067, 0.003960424568504095, 0.04807405173778534, 0.007344221230596304, -0.00010400010796729475, 0.03474298119544983, -0.0474618524312973, 0.01928620971739292, -0.025624612346291542, -0.0038159708492457867, 0.023256998509168625, 0.026589293032884598, -0.04693048447370529, -0.015378906391561031, -0.053934287279844284, 0.024639414623379707, 0.06629475206136703, -0.004280589055269957, -0.044673435389995575, -0.013572655618190765, 0.04733056575059891, 0.02955903857946396, 0.008474205620586872, -0.0505637489259243, 0.007568991277366877, 0.012309245765209198, -0.028495213016867638, -0.027662670239806175, 0.09456276893615723, -0.00302048958837986, 0.009967373684048653, 0.02240627445280552, 0.053757455199956894, 0.0036672172136604786, 0.027046194300055504, -0.018248945474624634, 0.0035365927033126354, -0.006644356530159712, 0.038498908281326294, -0.018654851242899895, -0.05074172094464302, 0.019192364066839218, 0.01871786266565323, -0.01118784211575985, -0.038684673607349396, -0.05964253842830658, -0.006900732405483723, 0.02435608208179474, 0.015237775631248951, 0.005421712528914213, -0.03631586208939552, 0.0042921253480017185, 0.024916714057326317, 0.03108418546617031, -0.029612887650728226, -0.006524693686515093, 0.012834173627197742, -0.02912527695298195, -0.00981515645980835, 0.036457356065511703, -0.00813579373061657, 0.00622218381613493, -0.026224935427308083, 0.036266062408685684, -0.061254315078258514, -0.035970885306596756, -0.015276153571903706, 0.021966708824038506, -0.004486981313675642, -0.06478659808635712, -0.012035229243338108, -0.0019520402420312166, 0.036621641367673874, -0.055144745856523514, 0.0017698664451017976, -0.0216531865298748, 0.018253544345498085, 0.02254364639520645, 0.025745967403054237, -0.016953932121396065, -0.027471143752336502, -0.025851445272564888, 0.0045033954083919525, -0.04623572528362274, 0.022781606763601303, 0.06285158544778824, 0.008643378503620625, -0.0042907376773655415, -0.025651924312114716, 0.036170996725559235, 0.0034508483950048685, 0.015199086628854275, -0.026144012808799744, -0.010782708413898945, 0.015693282708525658, 0.03894072398543358, 0.008868556469678879, 0.054653797298669815, 0.035408854484558105, 0.016362005844712257, 0.005532173439860344, 0.04383212700486183, -0.029108013957738876, -0.02623363584280014, 0.023356851190328598, -0.010955441743135452, -0.03181818127632141, 0.027141228318214417, 0.036083683371543884, 0.0008044651476666331, 0.005143218673765659, -0.01440249290317297, 0.03916573524475098, 0.02586626634001732, 0.019965380430221558, -0.03278372809290886, -0.04005344212055206, 0.02598155103623867, -0.009267686866223812, 0.03460359945893288, 0.01314560230821371, -0.018642349168658257, 0.04822632670402527, 0.011754386126995087, -0.036233507096767426, 0.0011365573154762387, -0.016578540205955505, 0.0035668490454554558, -0.013651975430548191, 0.009109213948249817, -0.03420661389827728, -0.03583616763353348, -0.007508613169193268, -0.013669919222593307, 0.02781398594379425, 0.01884792558848858, -0.045388586819171906, -0.012262780219316483, 0.05153195559978485, -0.027317313477396965, 0.005935952998697758, -0.030171623453497887, -0.0036405278369784355, -0.03888408839702606, -0.02296259254217148, 0.033347487449645996, 0.02942497842013836, -0.012385574169456959, 0.027133788913488388, 0.038866229355335236, 0.022230688482522964, 0.0313478484749794, 0.0018226000247523189, -0.0055013722740113735, 0.005743852350860834, -0.009199783205986023, -0.0037326400633901358, -0.021738329902291298, -0.008390266448259354, -0.039330702275037766, 0.030986515805125237, -0.051832228899002075, 0.02060435526072979, 0.009055701084434986, 0.03276354819536209, 0.03948574885725975, -0.0488799586892128, 0.04363003745675087, -0.027190519496798515, -0.046319711953401566, -0.05976557359099388, 0.015396108850836754, -0.043005168437957764, 0.028011564165353775, 0.015558714978396893, -0.05370109900832176, 0.007387677673250437, 0.06006474420428276, -0.02746463194489479, 0.027441004291176796, 0.02164057083427906, -0.012408645823597908, 0.0438358336687088, 0.029983585700392723, -0.035183440893888474, -0.01396489143371582, 0.06538059562444687, 0.01286044530570507, -0.006605811417102814, -0.005579906981438398, 0.03368144854903221, 0.0037934097927063704, 0.03176824748516083, 0.033590398728847504, -0.04042534902691841, 0.032919298857450485, 0.01478439662605524, 0.017534703016281128, -0.0452277697622776, -0.0005993263912387192, 0.030422884970903397, 0.022363772615790367, 0.0030868800822645426, 0.04133636876940727, 0.01880292408168316, 0.01060421485453844, 0.006546949967741966, -0.038452085107564926, 0.036586228758096695, 0.05551997944712639, -0.022366512566804886, 0.03369692340493202, 0.028632808476686478, 0.03835209086537361, 0.020900091156363487, 0.021826067939400673, 0.023425433784723282, -0.012332906946539879, -0.007606484927237034, 0.05009285733103752, -0.016666460782289505, 0.041402678936719894, 0.0062315636314451694, 0.035535216331481934, -0.027774648740887642, -0.012104441411793232, 0.013526548631489277, -0.006299779284745455, -0.009754293598234653, -0.008040294051170349, -0.03653375804424286, -0.003283908823505044, 0.001648818957619369, 0.020434008911252022, 0.020433785393834114, -0.017507808282971382, 0.029564494267106056, -0.02740621007978916, -0.026928069069981575, 0.002503340831026435, 0.05128270387649536, 0.023488199338316917, 0.036157578229904175, 0.010838779620826244, 0.07277696579694748, 0.026683367788791656, 0.0471588559448719, 0.033134575933218, 0.028873709961771965, 0.04208953306078911, 0.01844778284430504, -0.014430681243538857, 0.04492975398898125, 0.03235789015889168, 0.0035387768875807524, -0.06577606499195099, -0.017416689544916153, -0.010949089191854, 0.02500987984240055, 0.03134661167860031, 0.02794884517788887, 0.004137578420341015, -0.03379574418067932, 0.06851179152727127, 0.05546887591481209, 0.04348777234554291, 0.006577508058398962, -0.015060042031109333, 0.027546675875782967, 0.021983420476317406, 0.006600772961974144, 0.021828847005963326, 0.021203916519880295, 0.016313716769218445, 0.04522933438420296, -0.006508817430585623, -0.011377433314919472, -0.0033706622198224068, 0.019995108246803284, -0.0032512058969587088, -0.03637852892279625, -0.0031646559946238995, 0.0616622194647789, -0.037407368421554565, 0.006118154618889093, 0.018707560375332832, 0.0184833575040102, -0.05978221073746681, -0.044210173189640045, -0.011565929278731346, -0.012942599132657051, -0.04702625423669815, 0.0033600826282054186, -0.03971529006958008, -0.01181316189467907, 0.014281569048762321, -0.04074467718601227, -0.0045852563343942165, 0.006150567904114723, 0.009489724412560463, 0.03530685231089592, 0.023705067113041878, 0.028616562485694885, -0.018236536532640457, 0.03343686833977699, -0.019061628729104996, -0.01198777835816145, 0.02552391216158867, 0.03864852339029312, 0.03258136287331581, 0.03999347239732742, 0.000536694482434541, 0.03860335424542427, -0.012955441139638424, 0.01075230073183775, -0.02325380966067314, -0.008936960250139236, -0.019204655662178993, -0.01655627228319645, 0.0037209836300462484, -0.0501115620136261, 0.014612938277423382, 0.021627875044941902, 0.02424701862037182, 0.01969527266919613, 0.018130594864487648, -0.019225677475333214, -0.049229081720113754, 0.0030554772820323706, -0.0014584140153601766, -0.009234427474439144, -0.006232255604118109, -0.00979811605066061, 0.014648662880063057, 0.027677884325385094, -0.04092680290341377, 0.030896902084350586, -0.026274899020791054, -0.01029814500361681, 0.019634690135717392, -0.014361760579049587, 0.00521554471924901, -0.07443168759346008, 0.05068167299032211, -0.0011521241394802928, 0.010689922608435154, 0.035973530262708664, 0.012474648654460907, 0.01860629953444004, 0.017816010862588882, -0.0018810499459505081, 0.002240576548501849, 0.025583822280168533, -0.05549066141247749, -0.06924755871295929, -0.004602967761456966, 0.012643790803849697, -0.011011652648448944, 0.00944300927221775, -0.011986597441136837, 0.0008408832363784313, -0.033923689275979996, -0.07377161830663681, -0.04968465864658356, 0.013427110388875008, 0.07021425664424896, 0.0410902202129364, 0.011341972276568413, 0.0017300948966294527, -0.03709310665726662, -0.005939177703112364, -0.04471781104803085, 0.04501360282301903, 0.05463805049657822, 0.0022472431883215904, -0.028772929683327675, -0.017530616372823715, 0.0316770076751709, -0.006669769994914532, -0.06251472234725952, -0.0020542312413454056, 0.005179783795028925, -0.019157864153385162, -0.04952764883637428, 0.03673253953456879, 0.02570955641567707, -0.035026103258132935, 0.01549422089010477, 0.012277467176318169, -0.021788768470287323, 0.01751377433538437, -0.023154234513640404, -0.08878494799137115, -0.035572607070207596, -0.0005576419644057751, -0.03170759230852127, 0.010314514860510826, 0.0005016804207116365, 0.010215518064796925, 0.02479466237127781, -0.006465987302362919, -0.0004361259052529931, -0.009803032502532005, 0.022891657426953316, -0.03179579973220825, -0.018390513956546783, 0.003947473131120205, -0.0361924022436142, -0.014050484634935856, 0.041753944009542465, 0.012490036897361279, -0.02168581448495388, -0.008316805586218834, 0.01386099960654974, 0.0002971333742607385, -0.039852455258369446, -0.024533355608582497, 0.008199824951589108, 0.0020583022851496935, 0.03555414080619812, 0.0033892602659761906, -0.017604969441890717, 0.0046166605316102505 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Porting new models After uploading the 4 fairseq models here it was then suggested to port 3 wmt16 and 2 wmt19 AllenAI models (Jungo Kasai, et al). The porting was a breeze, as I only had to figure out how to put all the source files together, since they were spread out through several unrelated archives. Once this was done the conversion worked without a hitch. The only issue I discovered after porting is that I was getting a lower BLEU score than the original. Jungo Kasai, the creator of these models, was very helpful at suggesting that a custom hyper-parameterlength_penalty=0.6 was used, and once I plugged that in I was getting much better results. This discovery lead me to write a new script: [run_eval_search.py](https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/examples/seq2seq/run_eval_search.py), which can be used to search various hyper-parameters that would lead to the best BLEU scores. Here is an example of its usage: ``` # search space export PAIR=ru-en export DATA_DIR=data/$PAIR export SAVE_DIR=data/$PAIR export BS=32 mkdir -p $DATA_DIR sacrebleu -t wmt19 -l $PAIR --echo src > $DATA_DIR/val.source sacrebleu -t wmt19 -l $PAIR --echo ref > $DATA_DIR/val.target PYTHONPATH="src:examples/seq2seq" python examples/seq2seq/run_eval_search.py stas/wmt19-$PAIR \ $DATA_DIR/val.source $SAVE_DIR/test_translations.txt --reference_path $DATA_DIR/val.target \ --score_path $SAVE_DIR/test_bleu.json --bs $BS --task translation \ --search="num_beams=5:8:11:15 length_penalty=0.6:0.7:0.8:0.9:1.0:1.1 early_stopping=true:false" ``` Here it searches though all the possible combinations ofnum_beams,length_penaltyandearly_stopping. Once finished executing it reports: ``` bleu | num_beams | length_penalty | early_stopping ----- | --------- | -------------- | -------------- 39.20 | 15 | 1.1 | 0 39.13 | 11 | 1.1 | 0 39.05 | 5 | 1.1 | 0 39.05 | 8 | 1.1 | 0 39.03 | 15 | 1.0 | 0 39.00 | 11 | 1.0 | 0 38.93 | 8 | 1.0 | 0 38.92 | 15 | 1.1 | 1 [...] ``` You can see that in the case oftransformersearly_stopping=Falseperforms better (fairsequses theearly_stopping=Trueequivalent). So for the 5 new models I used this script to find the best default parameters and I used those when converting the models. User can still override these parameters, when invokinggenerate(), but why not provide the best defaults. You will find the 5 ported AllenAI models [here](https://huggingface.co/models?filter=allenai&tag=fsmt).
[ 0.009741680696606636, -0.007882121950387955, -0.026630956679582596, -0.01995922438800335, 0.0159281175583601, 0.032596077769994736, 0.04808793589472771, 0.008107590489089489, -0.009694261476397514, -0.03679661080241203, -0.04763660579919815, -0.006072397343814373, 0.0030197612941265106, 0.03940161317586899, 0.059343479573726654, -0.06153847649693489, -0.04606204852461815, -0.06423678994178772, -0.009026004932820797, -0.0029452918097376823, 0.03159129247069359, -0.02682417444884777, 0.0678740069270134, 0.029551032930612564, -0.023194048553705215, -0.022900382056832314, 0.022978508844971657, 0.06703651696443558, -0.0010249008191749454, 0.033872123807668686, -0.0216201338917017, -0.018955852836370468, -0.08379015326499939, -0.05798191949725151, -0.019022341817617416, 0.10171996802091599, -0.06426328420639038, 0.044774219393730164, 0.0325947031378746, -0.04481298476457596, 0.012544685043394566, 0.019895996898412704, -0.0061674565076828, 0.0624866783618927, 0.051210422068834305, -0.0003887704515364021, -0.05085548385977745, -0.04063298553228378, -0.02453232742846012, 0.04507547616958618, 0.012499554082751274, 0.017021814361214638, -0.005128584336489439, 0.013109661638736725, 0.01175670512020588, 0.013799840584397316, -0.013704868964850903, -0.06399208307266235, -0.019116424024105072, 0.03094329498708248, -0.014613303355872631, 0.0007354567642323673, 0.01666727289557457, 0.03071090392768383, -0.012124361470341682, -0.03581935167312622, -0.041604239493608475, -0.0022461547050625086, -0.03047790378332138, -0.024694012477993965, 0.02927236258983612, 0.0075611695647239685, -0.006226109340786934, -0.09215649217367172, -0.04427133500576019, -0.06228182837367058, -0.04136228561401367, 0.007429761812090874, 0.0698014572262764, 0.07141420245170593, 0.0005572038353420794, 0.039415352046489716, 0.03137127682566643, 0.011585098691284657, 0.03503844514489174, 0.053186237812042236, 0.01484895683825016, -0.06465910375118256, -0.06586651504039764, 0.03176528960466385, -0.05327775701880455, -0.11952096223831177, -0.051253143697977066, 0.05332643538713455, 0.07228919118642807, 0.034213390201330185, 0.015297798439860344, 0.040857117623090744, -0.004072402138262987, 0.0232267864048481, 0.024872111156582832, 0.025061801075935364, 0.04759455472230911, -0.039257947355508804, 0.002916293917223811, 0.020466474816203117, -0.027810685336589813, -0.12642508745193481, -0.021029772236943245, -0.011886068619787693, 0.018710553646087646, -0.012674999423325062, -0.02205066755414009, 0.05937276780605316, -0.030092502012848854, 0.043684594333171844, 0.022208550944924355, -0.03964637964963913, -0.016618642956018448, 0.06290343403816223, 0.03876430168747902, 0.07421848922967911, 0.02766847424209118, -0.01493904646486044, 0.09017669409513474, 0.09114883095026016, 0.04587552696466446, 0.006668616086244583, -0.004948056768625975, -0.04332822188735008, 0.06399931013584137, -0.0032483134418725967, 0.05049516260623932, 0.019821668043732643, -0.03729511424899101, -0.04235998913645744, 0.01038341037929058, -0.013693373650312424, 0.015149162150919437, -0.04010867327451706, -0.01472749188542366, 0.12047199159860611, -0.004534399136900902, -0.0021494680549949408, 0.03233850747346878, 0.06595757603645325, -0.0831240713596344, 0.1194395050406456, -0.0004919713828712702, 0.021495549008250237, -0.055527426302433014, 0.035521648824214935, 0.02810002490878105, -0.05967104062438011, 0.0015741705428808928, 0.0216542799025774, 0.0025126200634986162, -0.02716769091784954, -0.007804610766470432, -0.009887071326375008, -0.03853268921375275, 0.025737816467881203, -0.05301481485366821, -0.07979598641395569, 0.0063149770721793175, -0.009203499183058739, -0.01417043898254633, 0.016640841960906982, 0.033993545919656754, 0.0509335994720459, 0.09007386118173599, -0.009532725438475609, 0.09532975405454636, -0.01498484332114458, -0.021323012188076973, 0.04409533366560936, 0.0709185004234314, 0.06566554307937622, -0.014027091674506664, -0.04069056361913681, -0.07151494175195694, 0.06227827072143555, -0.03952176123857498, 0.05561976879835129, 0.030981292948126793, -0.035696566104888916, 0.030692381784319878, 0.0009163401555269957, -0.017151467502117157, 0.0016110664000734687, -0.09632252901792526, -0.026415666565299034, 0.10203415900468826, 0.005103130824863911, 0.02012011595070362, 0.0021764072589576244, 0.014766547828912735, 0.06868442893028259, 0.07946696132421494, 0.022327205166220665, 0.027018917724490166, 0.04216006398200989, 0.030276812613010406, -0.035546571016311646, 0.003939931746572256, 0.07584498822689056, -0.016421496868133545, -0.09375730156898499, -0.03290273994207382, 0.0271807461977005, 0.021286362782120705, -0.08243360370397568, 0.023711081594228745, -0.046407267451286316, 0.02112606167793274, -0.018571749329566956, -0.055777277797460556, -0.04144905135035515, 0.0006014277460053563, -0.01957223378121853, 0.13800811767578125, 0.01718328706920147, -0.026711607351899147, -0.0002068714238703251, 0.03361038863658905, 0.0529642328619957, 0.08304012566804886, 0.0593516044318676, 0.031208639964461327, -0.04644738510251045, 0.004566270858049393, -0.0244975034147501, 0.008615950122475624, 0.05997365340590477, -0.011065906845033169, -0.06462569534778595, 0.046038947999477386, -0.04237412288784981, -0.022018903866410255, -0.04315313696861267, 0.050336044281721115, 0.07945466041564941, 0.002082093618810177, -0.0137074189260602, -0.020101919770240784, -0.009395912289619446, 0.06586304306983948, -0.009917916730046272, -0.025821920484304428, -0.02991531789302826, -0.05016709491610527, 0.08322018384933472, 0.0034179019276052713, -0.06675507873296738, 0.024796511977910995, 0.05283007770776749, -0.0027425645384937525, 0.003911289852112532, -0.006050969008356333, 0.04637797176837921, -0.00873781368136406, 0.049119070172309875, -0.045283470302820206, -0.050085488706827164, 0.017132066190242767, -0.05819031968712807, -0.013609250076115131, -0.006737215910106897, -0.020565686747431755, -0.025324376299977303, -0.010190144181251526, -0.027377892285585403, 0.011609136126935482, -0.006823536939918995, 0.028299270197749138, -0.022166842594742775, 0.007192505057901144, -0.026954151690006256, -0.056490346789360046, -0.01836881786584854, 0.018167009577155113, -0.04310620576143265, 0.002282386412844062, 0.006403994280844927, 0.01942918635904789, 0.017947688698768616, -0.003852232825011015, -0.031488992273807526, -0.008819500915706158, 0.026978563517332077, 0.03279683738946915, -0.013029629364609718, 0.009600299410521984, -0.0062767812050879, -0.04914357140660286, -0.01889101415872574, 0.01648694835603237, -0.00725567014887929, 0.019754352048039436, 0.039157237857580185, -0.016914764419198036, 0.04152911156415939, -0.013204662129282951, 0.03076395019888878, -0.017252203077077866, -0.004309531766921282, 0.02295621857047081, -0.025562867522239685, -0.07679405063390732, 0.027812769636511803, -0.04798714071512222, 0.03406636416912079, -0.04203890264034271, 0.007714245934039354, 0.01535440981388092, -0.019715379923582077, -0.00039162521716207266, -0.005180498585104942, 0.025050610303878784, 0.015521197579801083, 0.02427472360432148, 0.024774329736828804, -0.025249922648072243, 0.022903788834810257, -0.06283672153949738, 0.01761840656399727, 0.024479057639837265, -0.013820379041135311, -0.020847629755735397, -0.01385902427136898, -0.028540315106511116, -0.006966123357415199, 0.028290491551160812, -0.0034901632461696863, 0.05366417020559311, 0.017382677644491196, -0.054386839270591736, -0.051523882895708084, -0.008306127972900867, -0.010684088803827763, 0.05572710186243057, -0.012755009345710278, -0.00999049749225378, -0.06285611540079117, 0.019357649609446526, 0.01796552911400795, -0.006234939210116863, 0.03659292683005333, 0.01619054190814495, -0.005134273786097765, 0.026410510763525963, -0.03429177403450012, 0.007296158000826836, -0.00957401841878891, 0.02069089002907276, 0.02581796981394291, 0.010250485502183437, -0.0072344820946455, -0.042434800416231155, -0.022774668410420418, -0.017776966094970703, 0.06086442619562149, -0.017416637390851974, -0.015592110343277454, 0.023961693048477173, 0.040997255593538284, -0.007270933128893375, 0.009911252185702324, -0.05665336176753044, 0.015230491757392883, -0.06605859100818634, -0.04814346507191658, 0.019765814766287804, 0.08530037850141525, 0.010870274156332016, 0.010777798481285572, -0.028227942064404488, -0.01644023507833481, -0.0584358349442482, 0.015416140668094158, -0.03523270785808563, -0.0008434682385995984, -0.034380681812763214, 0.0039373477920889854, -0.048196837306022644, -0.08008969575166702, 0.0079589132219553, 0.04412845894694328, -0.0054222578182816505, -0.019342871382832527, -0.052875615656375885, -0.014274376444518566, 0.03483390808105469, -0.020262736827135086, -0.015475393272936344, -0.04800330102443695, 0.006270734593272209, 0.029414102435112, 0.0014589776983484626, -0.05087941512465477, -0.03524477407336235, -0.01183521281927824, -0.012221720069646835, -0.09223025292158127, 0.009759590029716492, 0.03310752287507057, -0.0006595770246349275, 0.034860044717788696, -0.0191706120967865, -0.054270707070827484, -0.023047978058457375, -0.017117870971560478, 0.009460615925490856, 0.03161129355430603, -0.008416851982474327, -0.013333306647837162, -0.019562842324376106, 0.004772503394633532, -0.05410449206829071, -0.001402580295689404, -0.04953034594655037, 0.010417019948363304, 0.034590400755405426, -0.030469389632344246, -0.013884447515010834, -0.024324173107743263, -0.030188703909516335, 0.02834996208548546, -0.021297670900821686, -0.03777817264199257, -0.008784284815192223, -0.06947807967662811, 0.008066819980740547, 0.035104624927043915, 0.015328423120081425, 0.018281346186995506, -0.022802799940109253, 0.0076271346770226955, -0.028544314205646515, -0.010574833489954472, 0.049938783049583435, 0.014116276055574417, 0.056484609842300415, 0.0469009093940258, 0.0025111304130405188, 0.007843646220862865, 0.008612174540758133, -0.008146712556481361, 0.0032640425488352776, -0.0062222229316830635, -0.017393512651324272, -0.03786282613873482, 0.005563821643590927, 0.052784837782382965, 0.010309807024896145, 0.0011046049185097218, -0.040063247084617615, 0.04071621969342232, 0.057398032397031784, -0.04835113510489464, -0.019021758809685707, -0.002655437681823969, 0.016830207780003548, -0.017062215134501457, 0.028266524896025658, -0.014013019390404224, 0.018817177042365074, 0.041214294731616974, -0.011282240971922874, -0.018214674666523933, -0.03825642913579941, 0.06339790672063828, 0.005127535667270422, -0.006036011036485434, 0.033343974500894547, -0.07673804461956024, -0.03672082722187042, 0.0186932235956192, -0.04534000903367996, -0.019459344446659088, 0.0461760088801384, -0.06634008884429932, -0.04556252062320709, 0.07051776349544525, 0.023470109328627586, 0.01794837787747383, -0.036856573075056076, -0.018674449995160103, -0.021534180268645287, 0.013490507379174232, 0.030468091368675232, -0.014337139204144478, -0.036846794188022614, 0.047175534069538116, 0.03700261190533638, 0.06417980045080185, 0.009574887342751026, -0.013256811536848545, 0.003432933473959565, 0.031009359285235405, 0.029526956379413605, -0.030880840495228767, -0.05510585755109787, -0.037427403032779694, 0.03292131423950195, -0.047043707221746445, 0.011363914236426353, -0.011114351451396942, 0.05104873329401016, 0.02241581678390503, -0.009425490163266659, -0.042614273726940155, 0.03232908248901367, -0.04637012258172035, -0.025095311924815178, -0.007491114549338818, 0.03035097010433674, -0.05860774219036102, 0.031320590525865555, 0.019852932542562485, -0.00535785173997283, -0.017973994836211205, 0.034803494811058044, -0.05958155170083046, -0.005893436260521412, 0.05722517892718315, 0.013403953053057194, 0.027673611417412758, -0.009162764064967632, -0.03266787528991699, -0.021558750420808792, -0.020644893869757652, -0.028209203854203224, -0.03687307983636856, 0.01021620538085699, -0.00780484126880765, -0.0014882959658280015, 0.014078163541853428, 0.012427744455635548, -0.024774380028247833, -0.0017528602620586753, 0.018535660579800606, 0.02668634243309498, 0.001877989387139678, -0.04617103561758995, 0.036092329770326614, 0.04518381878733635, 0.004160856828093529, 0.032034363597631454, -0.025195546448230743, -0.017138579860329628, -0.015209304168820381, -0.024470578879117966, 0.06163869425654411, 0.027732528746128082, 0.001026142737828195, 0.008724614977836609, 0.004873268771916628, 0.01945948228240013, 0.04191569983959198, -0.0006129827816039324, 0.03198840469121933, 0.0034420578740537167, -0.0010725418105721474, 0.015228447504341602, -0.01592070609331131, 0.01540710125118494, 0.012187347747385502, 0.027736475691199303, -0.03249431028962135, -0.03164062649011612, 0.03881583362817764, -0.02753979153931141, 0.03007008507847786, -0.017273303121328354, -0.027525441721081734, 0.016512013971805573, -0.02233613282442093, -0.008881396614015102, 0.014430848881602287, -0.015847815200686455, 0.005874983500689268, -0.009149101562798023, -0.010162361897528172, 0.03650883957743645, 0.009704801253974438, 0.012754121795296669, -0.006286324467509985, 0.00595852080732584, 0.01006598211824894, 0.02678840421140194, -0.0009599659824743867, 0.04994712397456169, 0.024326125159859657, 0.09224144369363785, 0.03710967302322388, 0.01652454398572445, 0.0407426618039608, -0.012928595766425133, 0.006518721580505371, -0.046188835054636, -0.0343841016292572, -0.007928921841084957, 0.0288772564381361, 0.032088182866573334, -0.019842812791466713, -0.010488545522093773, -0.011386305093765259, 0.0725344642996788, 0.021719589829444885, 0.044649213552474976, 0.01910317875444889, 0.03719864413142204, 0.029135679826140404, -0.04294601455330849, -0.006424959748983383, -0.004749245475977659, -0.008571222424507141, -0.0075070965103805065, 0.029046079143881798, -0.005655275657773018, -0.003600127063691616, -0.03360256925225258, 0.022179316729307175, -0.04225745052099228, -0.0027556652203202248, -0.018781602382659912, 0.009000490419566631, 0.011234300211071968, 0.0006833531078882515, -0.012007296085357666, 0.057701919227838516, 0.021436329931020737, 0.00667959451675415, -0.01985189877450466, 0.008779579773545265, -0.04851534217596054, 0.01059748511761427, -0.02554289624094963, 0.01745627447962761, 0.012321848422288895, -0.044598665088415146, -0.037361204624176025, -0.012916602194309235, 0.016895247623324394, 0.045034512877464294, 0.03240547329187393, 0.018714308738708496, -0.03479038178920746, 0.0059199207462370396, -0.027447765693068504, -0.012111010029911995, -0.03617800027132034, 0.011183562688529491, 0.008552685379981995, 0.054033391177654266, 0.01792304404079914, 0.03501298651099205, 0.010092198848724365, 0.0409461110830307, -0.04988538846373558, -0.00038303661858662963, -0.029318049550056458, -0.037919629365205765, 0.03286144137382507, -0.03239542990922928, -0.029462609440088272, 0.0025357615668326616, 0.03945111483335495, 0.042352791875600815, 0.04049428924918175, 0.004734524991363287, -0.01984514854848385, 0.004722471348941326, -0.011538087390363216, -0.01862587407231331, 0.018698662519454956, -0.03149718418717384, 0.04033679887652397, 0.026864338666200638, -0.023209232836961746, 0.014317529276013374, 0.017143303528428078, -0.026817621663212776, 0.029374388977885246, -0.0011406997218728065, -0.014090258628129959, -0.03687867894768715, 0.07647278159856796, 0.02337508089840412, 0.022358987480401993, 0.04472237825393677, -0.023127900436520576, 0.011401606723666191, 0.005231715273112059, -0.005127245560288429, -0.01596715673804283, 0.00015227099356707186, -0.025409020483493805, -0.06678489595651627, -0.03068029321730137, 0.003164386609569192, -0.024936925619840622, 0.020481051877141, -0.042915914207696915, -0.011753661558032036, -0.05627812445163727, -0.07525136321783066, -0.016443908214569092, 0.01804138906300068, 0.09112318605184555, 0.046749841421842575, -0.016058415174484253, -0.0005466858856379986, -0.015325715765357018, 0.021085312590003014, -0.006256516557186842, 0.045115355402231216, 0.06436328589916229, 0.01984381303191185, -0.005149517208337784, -0.00016245665028691292, 0.04772947356104851, 0.01564757525920868, -0.026494724676012993, -0.03483516722917557, 0.010241784155368805, -0.047592516988515854, -0.08463793992996216, 0.0370565801858902, 0.012184514664113522, 0.0034103619400411844, -0.025098590180277824, 0.01429254375398159, 0.004275056067854166, 0.01669931970536709, -0.007588593754917383, -0.052955783903598785, -0.0007339758449234068, -0.02687990665435791, 0.0028100174386054277, -0.015450434759259224, -0.032637856900691986, -0.03186824172735214, -0.008984995074570179, -0.03675182908773422, 0.010163793340325356, -0.020179426297545433, 0.0009215165046043694, 0.0020078467205166817, 0.014253648929297924, 0.04352690279483795, -0.03444409370422363, -0.03415157273411751, 0.03433550149202347, 0.01315395813435316, -0.022894755005836487, 0.023000961169600487, -0.009574449621140957, 0.003338838694617152, -0.022712010890245438, -0.0010022611822932959, 0.00039358483627438545, 0.0019902901258319616, 0.018173959106206894, -0.007804499007761478, -0.019279632717370987, 0.018233725801110268 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Porting the architecture code Now that we have the model weights and the model configuration ported, we *just* need to adjust the code copied frommodeling_bart.pyto matchfairseq's functionality. The first step was to take a sentence, encode it and then feed to thegeneratefunction - forfairseqand fortransformers. After a few very failing attempts to get somewhere (*) - I quickly realized that with the current level of complexity usingprintas debugging method will get me nowhere, and neither will the basicpdbdebugger. In order to be efficient and to be able to watch multiple variables and have watches that are code-evaluations I needed a serious visual debugger. I spent a day trying all kinds of python debuggers and only when I triedpycharmI realized that it was the tool that I needed. It was my first time usingpycharm, but I quickly figured out how to use it, as it was quite intuitive. * footnote: the model was generating 'nononono' in Russian - that was fair and hilarious! Over time I found a great feature inpycharmthat allowed me to group breakpoints by functionality and I could turn whole groups on and off depending on what I was debugging. For example, here I have beam-search related break-points off and decoder ones on: ![break point group](./assets/07_porting_fsmt/pycharm-break-point-groups.png) Now that I have used this debugger to port FSMT, I know that it would have taken me many times over to use pdb to do the same - I may have even given it up. I started with 2 scripts: * [fseq-translate](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/scripts/fseq-translate.py) * [fsmt-translate](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/scripts/fsmt-translate.py) (without thedecodepart first) running both side by side, stepping through with debugger on each side and comparing values of relevant variables - until I found the first divergence. I then studied the code, made adjustments insidemodeling_fsmt.py, restarted the debugger, quickly jumped to the point of divergence and re-checked the outputs. This cycle has been repeated multiple times until the outputs matched. The first things I had to change was to remove a few layers that weren't used byfairseqand then add some new layers it was using instead. And then the rest was primarily figuring out when to switch tosrc_vocab_sizeand when totgt_vocab_size- since in the core modules it's justvocab_size, which weren't accounting for a possible model that has 2 dictionaries. Finally, I discovered that a few hyperparameter configurations weren't the same, and so those were changed too. I first did this process for the simpler no-beam search, and once the outputs were 100% matching I repeated it with the more complicated beam search. Here, for example, I discovered thatfairseqwas using the equivalent ofearly_stopping=True, whereastransformershas it asFalseby default. When early stopping is enabled it stops looking for new candidates as soon as there are as many candidates as the beam size, whereas when it's disabled, the algorithm stops searching only when it can't find higher probability candidates than what it already has. Thefairseqpaper mentions that a huge beam size of 50 was used, which compensates for using early stopping.
[ 0.05140739306807518, 0.0364992693066597, -0.011396395042538643, -0.006738150026649237, 0.03581136465072632, 0.05904744565486908, 0.039670418947935104, 0.04959164559841156, -0.011825447902083397, 0.00017907262372318655, -0.05274277180433273, -0.005498927552253008, -0.010695272125303745, 0.062713123857975, 0.08145357668399811, -0.046003591269254684, 0.034578412771224976, -0.07758501172065735, 0.005695202387869358, 0.008705826476216316, 0.046266697347164154, -0.06579697132110596, 0.024716634303331375, 0.06571150571107864, -0.07488111406564713, -0.04359474778175354, 0.016370560973882675, 0.09752274304628372, -0.11349282413721085, 0.06796569377183914, -0.051126569509506226, -0.010208270512521267, -0.041869014501571655, -0.041726406663656235, -0.03474460542201996, 0.02403928153216839, -0.105863556265831, 0.04513939842581749, -0.016455473378300667, -0.07162418216466904, 0.0060660261660814285, -0.011354595422744751, 0.024271195754408836, 0.049219585955142975, 0.02179429866373539, 0.07678139209747314, -0.08495642244815826, 0.06369219720363617, -0.043263863772153854, -0.015910981222987175, -0.00019752192019950598, 0.03945484384894371, -0.02300249971449375, -0.00804358534514904, -0.024530699476599693, -0.0171000137925148, -0.008025179617106915, -0.06528635323047638, 0.0037956908345222473, 0.033110104501247406, -0.004068015608936548, 0.009643767029047012, 0.05039828643202782, 0.020785758271813393, 0.009736677631735802, 0.015928469598293304, -0.049134761095047, 0.052877508103847504, -0.010376992635428905, 0.03982411324977875, -0.06531781703233719, -0.0027267104014754295, -0.013467230834066868, -0.04642942547798157, -0.005331418011337519, -0.08838619291782379, -0.06596214324235916, 0.008829731494188309, 0.06689886003732681, 0.02661331556737423, 0.0026115132495760918, 0.05591792240738869, -0.0015591453993692994, 0.0006456256960518658, 0.11633899807929993, -0.0011346860555931926, 0.05399084463715553, -0.04157816246151924, 0.001903340220451355, 0.043090056627988815, -0.0354066863656044, -0.07351364940404892, -0.06892815977334976, 0.02321719191968441, 0.032814182341098785, 0.014661213383078575, -0.0063599818386137486, 0.08042149245738983, 0.015972040593624115, 0.0046073319390416145, 0.01037370041012764, -0.03776733949780464, -0.01204313337802887, -0.09024671465158463, 0.004983574151992798, 0.06062375009059906, 0.04948480799794197, -0.10349638015031815, -0.03823583945631981, -0.015945440158247948, -0.0326482392847538, 0.005379855632781982, -0.05201004073023796, 0.06242610141634941, -0.011712738312780857, 0.03275260329246521, 0.06388842314481735, -0.05544867366552353, -0.024997787550091743, 0.005403938237577677, 0.02176203951239586, 0.0696566179394722, 0.0449177548289299, -0.05981047824025154, 0.0804600715637207, 0.024229474365711212, 0.0674404427409172, 0.0766354352235794, -0.019827499985694885, -0.06478527188301086, 0.031332824379205704, -0.024861712008714676, 0.0362120121717453, -0.013575242832303047, 0.012987526133656502, -0.035338375717401505, -0.024865174666047096, -0.006189980078488588, -0.018350141122937202, 0.0011002966202795506, 0.028281129896640778, 0.02750987559556961, 0.0038680178113281727, 0.033814698457717896, -0.05993720516562462, -0.007567132357507944, -0.09664870798587799, 0.040453724563121796, 0.03128078952431679, -0.03305080160498619, -0.022400952875614166, 0.01883852481842041, -0.03726062923669815, -0.037337519228458405, -0.03955112397670746, 0.049054741859436035, 0.011004854924976826, -0.08521340042352676, -0.08550623804330826, 0.033774927258491516, 0.03761535510420799, 0.05517130717635155, -0.058458007872104645, -0.05264898017048836, -0.016594868153333664, 0.014277110807597637, 0.06284498423337936, -0.01540922001004219, 0.02507617138326168, 0.054456617683172226, 0.01309843361377716, -0.036953117698431015, 0.11775761097669601, 0.005954512860625982, -0.023021768778562546, 0.0048879412934184074, -0.004606970585882664, 0.009617218747735023, -0.03328539431095123, -0.03245154023170471, -0.036775633692741394, 0.02351616881787777, -0.03193896263837814, 0.0020658913999795914, -0.00872417539358139, -0.021759353578090668, 0.044541895389556885, -0.0864265039563179, -0.040480319410562515, 0.004719010088592768, -0.10586392134428024, 0.012168357148766518, 0.10275327414274216, -0.0015761347021907568, 0.044596824795007706, -0.030862795189023018, -0.020217735320329666, 0.06057346612215042, 0.07002952694892883, 0.025279778987169266, 0.06971842050552368, -0.05730607733130455, 0.008593142032623291, 0.041814252734184265, 0.035767894238233566, 0.026974257081747055, 0.018758658319711685, -0.03625796362757683, 0.024930207058787346, 0.051000889390707016, 0.005680846516042948, -0.08054511994123459, -0.0014072040794417262, -0.04400330409407616, 0.0557858981192112, -0.04187432676553726, -0.03389333188533783, -0.017307979986071587, -0.017017167061567307, -0.010353391058743, 0.11831521987915039, -0.057740528136491776, -0.05363047122955322, -0.0288353580981493, -0.0219779834151268, 0.028159253299236298, 0.07957077026367188, 0.07480596005916595, 0.06339438259601593, -0.0498436838388443, -0.030604183673858643, 0.01320585235953331, 0.009673643857240677, 0.01064764242619276, -0.030178144574165344, -0.017527442425489426, 0.001074333325959742, 0.014132081530988216, 0.05100485682487488, -0.05843657627701759, 0.06500322371721268, 0.03371622785925865, -0.01210301835089922, -0.016520457342267036, -0.0027345046401023865, -0.023747095838189125, 0.0426415279507637, -0.03666895627975464, 0.006123772356659174, -0.039084501564502716, 0.013472188264131546, 0.04997922107577324, -0.027948526665568352, -0.046709947288036346, 0.04491277411580086, -0.0009878884302452207, 0.02877955138683319, 0.005339362192898989, -0.03380655124783516, 0.06520704180002213, -0.043629810214042664, 0.026503711938858032, -0.028077442198991776, -0.07567567378282547, -0.006560491397976875, -0.01826239749789238, 0.007011357229202986, -0.01797972247004509, -0.03513838350772858, -0.0008334420272149146, -0.0025566068943589926, -0.04286173731088638, 0.0047381604090332985, -0.011819335632026196, 0.048652131110429764, 0.0012716149212792516, -0.03301548212766647, -0.02685081586241722, -0.049403659999370575, -0.010987840592861176, -0.023535355925559998, -0.03132312744855881, 0.003849239554256201, 0.010256830602884293, 0.010859689675271511, 0.003259564284235239, -0.0036068016197532415, 0.017261430621147156, -0.020486466586589813, 0.041186537593603134, 0.07394901663064957, 0.01973319798707962, 0.011686796322464943, 0.014059042558073997, -0.00858499575406313, 0.003502140287309885, -0.0015314160846173763, -0.031358812004327774, -0.0071908580139279366, 0.04346960783004761, -0.05547935515642166, 0.0040918500162661076, -0.004458789248019457, -0.014997321180999279, -0.07379169017076492, -0.015645014122128487, 0.02118978649377823, 0.006233503110706806, -0.08843886852264404, 0.027206245809793472, -0.031566813588142395, 0.002122236881405115, -0.019958265125751495, -0.0014151778304949403, 0.0008430723682977259, -0.028917238116264343, -0.007971777580678463, 0.007632487919181585, 0.02023010514676571, 0.003587607992812991, 0.02587939240038395, 0.01567268557846546, -0.036368273198604584, 0.028375159949064255, -0.03201606124639511, 0.015468046069145203, 0.04641183838248253, -0.039413802325725555, 0.003562338650226593, 0.012844264507293701, -0.020835118368268013, -0.027171848341822624, -0.015137648209929466, -0.034454796463251114, 0.013706060126423836, -0.024042952805757523, -0.020904861390590668, -0.025111664086580276, 0.017026925459504128, -0.015051821246743202, 0.007969827391207218, -0.020069841295480728, -0.018657134845852852, -0.025219712406396866, -0.023611335083842278, 0.014395257458090782, -0.002256415318697691, 0.03502664715051651, 0.003757300553843379, 0.019456233829259872, 0.024671345949172974, 0.013281469233334064, 0.04503187909722328, 0.012900675646960735, -0.002949554705992341, 0.009028807282447815, 0.010908880271017551, -0.0016066639218479395, -0.03325998783111572, -0.020675070583820343, -0.00788668543100357, 0.0821322426199913, -0.0017268153605982661, -0.02208196185529232, -0.004331726115196943, 0.004241583403199911, 0.04623188450932503, 0.011907755397260189, -0.0467708557844162, 0.05442454293370247, -0.011936327442526817, -0.05462353304028511, -0.00787094235420227, 0.0511392317712307, 0.012829077430069447, 0.01562529243528843, -0.017646921798586845, -0.009509935043752193, 0.006442775018513203, -0.00019988056737929583, 0.005336860194802284, -0.0019665989093482494, -0.03496631979942322, 0.027969907969236374, -0.06342485547065735, -0.06006144732236862, 0.02552420273423195, 0.01799406111240387, 0.028105562552809715, -0.045393384993076324, -0.05304286256432533, -0.020539533346891403, 0.05092928558588028, 0.023416360840201378, -0.01585123874247074, -0.02906523272395134, 0.009115724824368954, 0.005555071868002415, 0.02983124926686287, -0.03886301442980766, -0.015779171139001846, -0.007841920480132103, -0.02952762506902218, 0.003939621150493622, -0.0016691945493221283, -0.021760525181889534, -0.003076235530897975, 0.02686249651014805, -0.013075027614831924, -0.06372887641191483, -0.03781477361917496, -0.004376100841909647, 0.023171424865722656, 0.01608225889503956, -0.053535059094429016, 0.003289339132606983, -0.005628904327750206, -0.007909570820629597, -0.057837437838315964, 0.03206256031990051, 0.002787800971418619, -0.006252205464988947, 0.034195952117443085, 0.02403370849788189, 0.023909954354166985, -0.055511001497507095, -0.026829559355974197, 0.021345658227801323, -0.03441017121076584, -0.040369912981987, 0.015279142186045647, -0.036056458950042725, -0.006573338992893696, -0.02040577307343483, 0.05769564211368561, 0.02461724914610386, 0.000927812303416431, -0.0070279366336762905, -0.020745661109685898, -0.008019199594855309, 0.045756030827760696, 0.013703844510018826, 0.05003424733877182, 0.0389581099152565, 0.045056700706481934, -0.004461741074919701, 0.03123783878982067, -0.007550612557679415, -0.01167924515902996, -0.014841725118458271, 0.01927327737212181, -0.021851684898138046, 0.005290060304105282, 0.015631800517439842, 0.0014597018016502261, 0.045986782759428024, -0.040542393922805786, 0.04226769506931305, 0.02021723985671997, -0.02333659864962101, -0.008424132131040096, -0.03615150600671768, 0.037257906049489975, 0.0014284311328083277, 0.03182884305715561, 0.028250284492969513, 0.001328907092101872, 0.03569602221250534, 0.01967473328113556, 0.008739807642996311, -0.014070226810872555, 0.004930255468934774, -0.0060441140085458755, 0.03117869794368744, 0.036855265498161316, -0.04488981515169144, -0.024545850232243538, 0.007130000740289688, -0.07742655277252197, 0.037809353321790695, 0.026345882564783096, -0.039982087910175323, 0.01024678722023964, 0.07463904470205307, -0.0034372524823993444, 0.03511649742722511, -0.06050726771354675, -0.021547013893723488, -0.02171989157795906, -0.014103744179010391, 0.005231468006968498, 0.016022779047489166, 0.003808363573625684, 0.05305902287364006, 0.017037898302078247, 0.03944569081068039, -0.02309424802660942, 0.027282660827040672, 0.027138197794556618, 0.02752581797540188, 0.01633453369140625, 0.006689711008220911, -0.019165396690368652, -0.03246428072452545, 0.016595635563135147, -0.03870036453008652, -0.01223402377218008, 0.00861433707177639, 0.009679632261395454, 0.032700058072805405, 0.014487413689494133, -0.05906103551387787, 0.04028170555830002, 0.01350462157279253, -0.026657110080122948, -0.04391103610396385, 0.02590971253812313, -0.008929123170673847, 0.08212359249591827, 0.009794222190976143, -0.04180840402841568, 0.015442189760506153, 0.023508425801992416, -0.03409934416413307, -0.018943872302770615, -0.0015666570980101824, -0.014983395114541054, 0.005109706427901983, 0.020151732489466667, -0.04853752627968788, -0.03469454497098923, 0.05843999981880188, 0.0006805027951486409, -0.017185214906930923, -0.006714681629091501, -0.0071311951614916325, 0.01962178200483322, 0.03898584097623825, 0.04088381305336952, -0.01624910905957222, 0.017250770702958107, 0.047844048589468, 0.026120508089661598, -0.0839795470237732, -0.057289909571409225, 0.003008500440046191, 0.027641860768198967, -0.00901732500642538, 0.005997306667268276, -0.036280885338783264, 0.01689213141798973, 0.003503774292767048, -0.022481953725218773, 0.033456508070230484, 0.05231097340583801, -0.003435450838878751, 0.021082714200019836, 0.0283046867698431, 0.021490897983312607, 0.03577118739485741, 0.04337030649185181, -0.013201078400015831, -0.010978242382407188, 0.0036553852260112762, 0.02851399965584278, 0.011903079226613045, 0.06563308835029602, 0.00020923090050928295, -0.004748559556901455, -0.054418716579675674, -0.007908171974122524, 0.026398826390504837, -0.005290191154927015, -0.013055712915956974, 0.020701460540294647, -0.05808008089661598, -0.01022225059568882, -0.032912079244852066, 0.013271268457174301, 0.019051391631364822, 0.028649527579545975, 0.008276782929897308, 0.003390828613191843, -0.04224640130996704, 0.011429009959101677, 0.041102755814790726, 0.028158267959952354, -0.003843532642349601, 0.0056068808771669865, 0.032437749207019806, 0.00835565384477377, -0.017237156629562378, 0.05652720481157303, 0.023025183007121086, 0.05872279778122902, 0.04234959930181503, -0.0027129151858389378, 0.04712964594364166, -0.010724298655986786, 0.006395547650754452, -0.08486592769622803, -0.020551523193717003, -0.03246953338384628, 0.016140876337885857, 0.03795987740159035, -0.02774830535054207, 0.010190614499151707, -0.021259641274809837, 0.06998030841350555, 0.02979620173573494, 0.0009677725029177964, 0.009756030514836311, 0.030432596802711487, 0.020667770877480507, -0.0064093307591974735, -0.0035812004934996367, -0.00958190392702818, 0.0309726744890213, -0.018534671515226364, 0.03442865610122681, -0.01866876520216465, -0.007898872718214989, 0.0011668078368529677, 0.02848629467189312, -0.026647690683603287, -0.007098648697137833, -0.0061982679180800915, 0.05371427536010742, 0.0020352951250970364, 0.010193263180553913, 0.006998257711529732, -0.009205845184624195, -0.02162592113018036, -0.020815730094909668, -0.03223494812846184, -0.025026071816682816, -0.03361473232507706, 0.018296338617801666, -0.04926645755767822, 0.015613057650625706, -0.003638154361397028, -0.001243444625288248, -0.015344073064625263, -0.011926131322979927, -0.007596906740218401, 0.0033723029773682356, 0.05884098634123802, 0.013155537657439709, -0.0013026909437030554, 0.014888948760926723, -0.037479475140571594, 0.011058120056986809, -0.04386226832866669, 0.029295790940523148, 0.05956719443202019, 0.016628598794341087, -0.014230377040803432, 0.061518918722867966, -0.005355712026357651, 0.021638913080096245, -0.04346342384815216, 0.008664537221193314, -0.002238529035821557, -0.06960473954677582, 0.03180655092000961, 0.004368519876152277, -0.00973824318498373, 0.027859732508659363, -0.0065688034519553185, -0.0020692634861916304, 0.02643411234021187, -0.02374027483165264, -0.09097818285226822, 0.022948574274778366, -0.004393791779875755, -0.007717805914580822, -0.00409501139074564, -0.00018059965805150568, 0.018881039693951607, 0.042086176574230194, -0.05543997138738632, 0.06046384945511818, 0.008256116881966591, -0.014555712230503559, 0.03686972334980965, -0.05144134536385536, 0.007798990700393915, -0.03650832176208496, 0.09099370986223221, 0.03075604885816574, 0.034336548298597336, 0.007721107918769121, 0.03835294768214226, 0.02193927764892578, 0.005119169130921364, 0.007033287547528744, -0.009024432860314846, 0.0077092526480555534, -0.04766147583723068, -0.03329344838857651, 0.0291889775544405, 0.04099077358841896, -0.013530745171010494, 0.021061208099126816, 0.020614568144083023, -0.002889252034947276, -0.021876826882362366, -0.051231469959020615, 0.008348843082785606, 0.011156236752867699, 0.054837245494127274, 0.03939838707447052, 0.005251820664852858, 0.024106841534376144, -0.035000719130039215, 0.011975616216659546, -0.036006104201078415, 0.00923344399780035, 0.044340830296278, 0.009853478521108627, -0.02317078597843647, 0.004744912032037973, 0.0006738482625223696, 0.00941283255815506, -0.018901865929365158, -0.03695601969957352, 0.03183980658650398, -0.045962464064359665, -0.08776727318763733, -0.029822954908013344, 0.024494795128703117, -0.03664067015051842, 0.010856871493160725, 0.01260001864284277, 0.018893441185355186, -0.004051233176141977, -0.027234146371483803, -0.08144071698188782, -0.04322630167007446, -0.006781165953725576, 0.02796553075313568, -0.00014400325017049909, 0.0011229906231164932, -0.022132031619548798, 0.002344638342037797, -0.0026158310938626528, 0.02750418521463871, 0.0046435147523880005, -0.022003835067152977, 0.006584998685866594, -0.012365603819489479, 0.035711757838726044, -0.022153187543153763, -0.04202721267938614, 0.026263652369379997, 0.03911127895116806, -0.03579546511173248, 0.0184733085334301, 0.02840697020292282, 0.004908696748316288, -0.02166864089667797, 0.001870836247690022, 0.011553163640201092, 0.029011724516749382, 0.030605625361204147, -0.002108781598508358, 0.01580105535686016, 0.023943256586790085 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
AutoConfig, AutoTokenizer, etc. One other change I needed to do is to plug the newly ported model into the automated modeltransformerssystem. This is used primarily on the [models website](https://huggingface.co/models) to load the model configuration, tokenizer and the main class without providing any specific class names. For example, in the case ofFSMTone can do: ``` from transformers import AutoTokenizer, AutoModelWithLMHead mname = "facebook/wmt19-en-ru" tokenizer = AutoTokenizer.from_pretrained(mname) model = AutoModelWithLMHead.from_pretrained(mname) ``` There are 3autofiles that have mappings to enable that: ``` -rw-rw-r-- 1 stas stas 16K Sep 23 13:53 src/transformers/configuration_auto.py -rw-rw-r-- 1 stas stas 65K Sep 23 13:53 src/transformers/modeling_auto.py -rw-rw-r-- 1 stas stas 13K Sep 23 13:53 src/transformers/tokenization_auto.py ``` Then the are the pipelines, which completely hide all the NLP complexities from the end user and provide a very simple API to just pick a model and use it for a task at hand. For example, here is how one could perform a summarization task usingpipeline: ``` summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base") summary = summarizer("Some long document here", min_length=5, max_length=20) print(summary) ``` The translation pipelines are a work in progress as of this writing, watch [this document](https://huggingface.co/transformers/main_classes/pipelines.html) for updates for when translation will be supported (currently only a few specific models/languages are supported). Finally, there issrc/transforers/init.pyto edit so that one could do: ``` from transformers import FSMTTokenizer, FSMTForConditionalGeneration ``` instead of: ``` from transformers.tokenization_fsmt import FSMTTokenizer from transformers.modeling_fsmt import FSMTForConditionalGeneration ``` but either way works. To find all the places I needed to plug FSMT in, I mimickedBartConfig,BartForConditionalGenerationandBartTokenizer. I justgrepped which files had it and inserted corresponding entries forFSMTConfig,FSMTForConditionalGenerationandFSMTTokenizer. ``` $ egrep -l "(BartConfig|BartForConditionalGeneration|BartTokenizer)" src/transformers/*.py \ | egrep -v "(marian|bart|pegasus|rag|fsmt)" src/transformers/configuration_auto.py src/transformers/generation_utils.py src/transformers/__init__.py src/transformers/modeling_auto.py src/transformers/pipelines.py src/transformers/tokenization_auto.py ``` In thegrepsearch I excluded the files that also include those classes.
[ 0.011006715707480907, -0.009839639067649841, 0.00028425725759007037, -0.03892533481121063, 0.04587654396891594, 0.070457324385643, 0.049711234867572784, 0.04543032497167587, -0.04088575392961502, 0.003264590399339795, -0.0901782438158989, 0.04801294952630997, -0.01751272939145565, 0.04928626865148544, 0.03648179769515991, -0.024988679215312004, 0.00020057093934156, -0.0028139548376202583, -0.004724579863250256, 0.00014127847680356354, 0.004651768133044243, -0.07581033557653427, 0.05572362616658211, 0.02485726773738861, -0.03027159906923771, -0.07901106774806976, 0.03847535699605942, 0.05073767527937889, -0.07464040815830231, 0.05384570732712746, -0.08149153739213943, -0.022235097363591194, -0.037657491862773895, -0.021558178588747978, 0.0020483157131820917, 0.030178550630807877, -0.1038973331451416, 0.016978729516267776, 0.03841950371861458, -0.026313794776797295, -0.026534060016274452, -0.002954476047307253, -0.021755576133728027, 0.06887415051460266, 0.025606507435441017, 0.012517928145825863, -0.19963614642620087, 0.07457779347896576, 0.015805479139089584, -0.04033065214753151, -0.04110606387257576, 0.02151656523346901, -0.02465863525867462, -0.00240995897911489, 0.025103336200118065, -0.00656497897580266, -0.009363668970763683, -0.05264557525515556, -0.0014099028194323182, -0.030914142727851868, 0.01156898308545351, 0.010820416733622551, 0.008561850525438786, 0.0599261038005352, 0.021912412717938423, -0.004139626398682594, -0.08513372391462326, -0.05686458572745323, -0.05179503560066223, -0.034764185547828674, 0.0020451101008802652, -0.05841368809342384, -0.018877379596233368, -0.06142594665288925, 0.0035837902687489986, -0.05336543172597885, 0.011637087911367416, 0.0024604478385299444, 0.043059900403022766, 0.06944138556718826, 0.020929692313075066, 0.05551178753376007, 0.022400392219424248, 0.061581168323755264, 0.03895726427435875, -0.01308394130319357, 0.022213347256183624, -0.04091571643948555, -0.02143232524394989, 0.01560092531144619, -0.015141499228775501, -0.11685524135828018, -0.003288073232397437, -0.0031848761718720198, 0.07495354115962982, -0.016464034095406532, -0.006616718135774136, 0.03179968520998955, 0.0048347534611821175, -0.04545203223824501, 0.005154885351657867, -0.06010935828089714, -0.023927001282572746, -0.06762594729661942, -0.018498467281460762, 0.019771046936511993, 0.023723013699054718, -0.09272781014442444, -0.03154461830854416, -0.002852779347449541, 0.02111600711941719, -0.059710677713155746, 0.009357198141515255, 0.09465161710977554, -0.07273983955383301, 0.011852987110614777, -0.030456870794296265, -0.04207099974155426, 0.012352601625025272, 0.04507865384221077, 0.028290342539548874, 0.08476172387599945, 0.06242884323000908, -0.02808496169745922, 0.038830965757369995, 0.09070871770381927, 0.061782244592905045, 0.04716422036290169, 0.009610766544938087, -0.0767645388841629, -0.00012036867701681331, 0.0017276976723223925, 0.09456157684326172, 0.0283284243196249, -0.0010143688414245844, -0.0386844165623188, 0.013408712111413479, -0.059945493936538696, 0.02389112487435341, 0.00020461274834815413, -0.013774525374174118, 0.06187155470252037, -0.050584595650434494, 0.028576157987117767, 0.013141331262886524, 0.01521483063697815, -0.10333278775215149, 0.0705408826470375, -0.050122592598199844, 0.02268028073012829, -0.059342801570892334, 0.03020278923213482, -0.04522312059998512, -0.018810514360666275, 0.03461873158812523, 0.06286714971065521, -0.00141853594686836, -0.027822008356451988, -0.07024136930704117, -0.01660725846886635, 0.013933985494077206, 0.04408068209886551, -0.0555051825940609, -0.018069060519337654, 0.020269334316253662, -0.0037087812088429928, -0.021602997556328773, 0.0552108995616436, 0.06700460612773895, -0.029373999685049057, 0.06029129773378372, -0.05672241002321243, 0.05965216085314751, -0.025036191567778587, 0.014109057374298573, 0.06876808404922485, 0.04962825030088425, 0.04971583932638168, -0.030104009434580803, 0.010052510537207127, -0.07492996007204056, 0.09491434693336487, -0.036944352090358734, 0.03655504807829857, 0.04306212440133095, -0.07223141193389893, 0.027159733697772026, -0.010290078818798065, -0.027078377082943916, -0.00017080399265978485, -0.03420092910528183, -0.028945837169885635, 0.07249483466148376, 0.016613254323601723, 0.0571005679666996, -0.03666383773088455, -0.014743681065738201, 0.13067102432250977, 0.01993262581527233, 0.08118771016597748, 0.04966805875301361, -0.007394228596240282, -0.005716288462281227, -0.002908530877903104, -0.006327418144792318, 0.03919316828250885, -0.02573642134666443, -0.08180264383554459, 0.025343038141727448, 0.003939653281122446, 0.018317537382245064, -0.11723949015140533, 0.045283813029527664, -0.049485430121421814, -0.021429238840937614, -0.07768852263689041, -0.06485410779714584, 0.0014473513001576066, 0.00917850062251091, -0.01250505167990923, 0.15210236608982086, -0.06685805320739746, -0.006381022743880749, -0.0380290150642395, -0.05646431818604469, 0.02783230133354664, 0.09070060402154922, 0.07364314049482346, 0.08054666966199875, -0.060846131294965744, -0.038849882781505585, -0.0622614249587059, -0.02254515141248703, 0.027717454358935356, -0.00342247704975307, 0.002027029637247324, -0.002938712714239955, -0.020259639248251915, -0.00825429242104292, -0.006262816023081541, 0.01947370357811451, -0.01531550195068121, 0.0546884723007679, 0.0001122520916396752, -0.027332613244652748, 0.047378815710544586, 0.0682162344455719, 0.01559544075280428, -0.05058423429727554, -0.02174324542284012, -0.04485226795077324, 0.05926881730556488, 0.034974902868270874, -0.05713970214128494, 0.06474673748016357, 0.02243483066558838, -0.02177402377128601, 0.04533897340297699, -0.031229620799422264, 0.0601230263710022, 0.01158301904797554, -0.005219900980591774, -0.04987599700689316, -0.04014790058135986, -0.02146824821829796, -0.052090346813201904, -0.013918229378759861, 0.008298716507852077, -0.0032648942433297634, 0.026238294318318367, 0.018004754558205605, -0.013840802013874054, 0.007517671212553978, 0.02612735517323017, 0.03445947915315628, 0.03944239392876625, 0.025788582861423492, -0.013500082306563854, -0.04526996985077858, -0.006902766413986683, 0.0024919083807617426, -0.03374246507883072, 0.010670485906302929, 0.02935979887843132, 0.00236560613848269, -0.02368561550974846, -0.01594841107726097, -0.033143024891614914, -0.04963906481862068, 0.011658694595098495, 0.02807016856968403, 0.027718067169189453, 0.02039787545800209, -0.0003731496981345117, -0.005215844139456749, 0.023933492600917816, 0.03361652046442032, -0.011036921292543411, -0.0015336282085627317, 0.06487855315208435, -0.0000032396135338785825, 0.004877496510744095, 0.01356715802103281, 0.03095489740371704, -0.0343451201915741, 0.050395432859659195, 0.02531610243022442, -0.007003756705671549, -0.11196140944957733, -0.02847595140337944, -0.005678724031895399, 0.04009436070919037, 0.005292775109410286, -0.02230316586792469, 0.03332076966762543, -0.002614029450342059, -0.010109730996191502, 0.01831011474132538, -0.003994074650108814, 0.006125745363533497, 0.032992780208587646, -0.0028062209021300077, -0.037129469215869904, 0.01207172404974699, -0.036177922040224075, -0.028172684833407402, 0.02662106789648533, 0.015346242114901543, -0.028348391875624657, 0.012707562185823917, 0.005850468762218952, 0.004097826778888702, 0.0016754674725234509, -0.01785936765372753, 0.04952754080295563, 0.029042795300483704, 0.018360311165452003, -0.017133383080363274, 0.00959920696914196, 0.006954179611057043, 0.01809169165790081, 0.003778517711907625, -0.004534944426268339, -0.012800588272511959, -0.012120862491428852, 0.04056905582547188, -0.00883643701672554, 0.018893858417868614, 0.020022470504045486, -0.00924511719495058, 0.033870525658130646, -0.004370053764432669, 0.008414759300649166, -0.023029062896966934, -0.004039329010993242, 0.001388006960041821, 0.01785397343337536, -0.004489388782531023, -0.031246790662407875, -0.01936277188360691, 0.027718808501958847, 0.07120750844478607, 0.005003162659704685, -0.022944027557969093, -0.03308255597949028, 0.026743803173303604, 0.009409847669303417, -0.01848197914659977, -0.05425771698355675, 0.0024719638749957085, -0.03891373798251152, 0.00016140364459715784, -0.04415414482355118, 0.07636024057865143, -0.0022655411157757044, 0.018863091245293617, -0.011477074585855007, 0.033316854387521744, -0.027307631447911263, 0.06563349068164825, -0.0037882502656430006, 0.0071578179486095905, -0.027641121298074722, 0.0062350076623260975, -0.05789874121546745, -0.07989195734262466, 0.05722469091415405, 0.03494696691632271, 0.0007321937591768801, -0.0022540180943906307, -0.018913568928837776, 0.004181440453976393, -0.026225496083498, -0.00034660653909668326, 0.030781036242842674, 0.0006860438152216375, 0.018260641023516655, 0.061797093600034714, 0.01712913066148758, -0.029379818588495255, 0.011628812178969383, -0.03143302723765373, -0.029980964958667755, -0.013500549830496311, -0.0020723817870020866, -0.0011920921970158815, 0.012827145867049694, 0.012347318232059479, 0.03418401628732681, -0.029899831861257553, -0.017505120486021042, -0.018081389367580414, 0.004875007551163435, 0.020335642620921135, -0.059133827686309814, -0.04653763025999069, 0.015355485491454601, -0.014021388255059719, 0.009974039159715176, -0.023902377113699913, -0.011145344004034996, -0.039793167263269424, 0.033605750650167465, 0.04304209351539612, -0.017653971910476685, -0.03307135030627251, -0.03733537346124649, 0.02043762244284153, -0.02154422737658024, 0.0018745369743555784, 0.004871393088251352, -0.020012805238366127, 0.004986633080989122, 0.003881108248606324, 0.04807962849736214, 0.06582897901535034, -0.00004846749288844876, 0.0010800458258017898, -0.03741637244820595, -0.006628344301134348, 0.03778747096657753, 0.016222668811678886, 0.021462436765432358, 0.024535948410630226, 0.006355177145451307, 0.018284451216459274, 0.029347816482186317, -0.006810181308537722, -0.03926258906722069, -0.0005613109678961337, 0.011895931325852871, -0.03040376864373684, 0.0396309532225132, 0.006715264171361923, -0.04009385034441948, -0.00469245295971632, -0.012697458267211914, 0.02672182023525238, 0.028441868722438812, -0.018766378983855247, -0.03752487152814865, 0.0019481494091451168, 0.039352815598249435, -0.011696024797856808, -0.0044305757619440556, 0.021808378398418427, -0.006350749637931585, 0.0409030020236969, -0.028261465951800346, -0.010007085278630257, -0.020787518471479416, 0.02494852803647518, 0.02173091657459736, 0.009252103976905346, -0.010761186480522156, -0.07065801322460175, -0.014712903648614883, 0.01914934068918228, -0.035030875355005264, 0.005380938295274973, 0.0038313104305416346, -0.04879894480109215, -0.010729256086051464, 0.0518152117729187, 0.04135424643754959, 0.017207808792591095, -0.03490310162305832, -0.02112518437206745, -0.0023852449376136065, -0.015063637867569923, 0.005861880257725716, -0.009160629473626614, -0.02050943300127983, 0.03160439431667328, 0.05549284443259239, 0.049562718719244, 0.027824964374303818, 0.04820040613412857, -0.013947611674666405, -0.007360423449426889, -0.010547344572842121, -0.03416664898395538, -0.012489594519138336, -0.020995192229747772, 0.020476488396525383, 0.019743885844945908, 0.011952740140259266, -0.01415977068245411, 0.024715103209018707, 0.05977195128798485, -0.010362226516008377, -0.05656343325972557, 0.03199109062552452, 0.014555249363183975, 0.03552567586302757, -0.05317047983407974, 0.04813363403081894, -0.028204774484038353, 0.009096414782106876, -0.009242038242518902, -0.0019132656743749976, 0.004033620003610849, 0.02458941377699375, -0.003517050761729479, -0.02115785703063011, 0.03753921017050743, 0.020608998835086823, 0.028800776228308678, 0.0068311854265630245, -0.025088336318731308, -0.019451720640063286, -0.0018040803261101246, 0.03472704440355301, -0.02130199410021305, 0.0024290727451443672, 0.003715764731168747, -0.03382458537817001, 0.018017727881669998, 0.006578434724360704, 0.011514303274452686, -0.01777111180126667, 0.041080135852098465, 0.03225792571902275, -0.02576782926917076, -0.05160515755414963, 0.031149432063102722, 0.037342965602874756, -0.022714538499712944, 0.018589308485388756, -0.0038670573849231005, -0.04524365812540054, -0.011236601509153843, -0.04353057220578194, 0.03463534265756607, 0.047507308423519135, 0.012556909583508968, 0.008624991402029991, 0.009779488667845726, 0.02172992192208767, 0.045984361320734024, -0.024214722216129303, -0.010097550228238106, 0.0049307518638670444, 0.01660156063735485, 0.00833909586071968, 0.05652739480137825, 0.01948796771466732, -0.009357905015349388, 0.02704560197889805, -0.06997424364089966, -0.01769130676984787, 0.00845697708427906, -0.0019907646346837282, 0.003799916012212634, 0.008191398344933987, -0.05053144320845604, 0.0003388752229511738, 0.0180197823792696, 0.008089997805655003, 0.03675535321235657, 0.022550372406840324, 0.01491718553006649, -0.018572978675365448, -0.023892050608992577, 0.018805937841534615, 0.05176252871751785, -0.025644350796937943, 0.032722193747758865, 0.01312192715704441, 0.028467079624533653, 0.04850175604224205, 0.016635768115520477, 0.012015222571790218, 0.010361555963754654, 0.07854828238487244, 0.026484062895178795, -0.008329727686941624, 0.021401746198534966, 0.0072526102885603905, 0.009112587198615074, -0.03946772962808609, 0.0246876273304224, 0.015361903235316277, 0.004646271001547575, 0.033542487770318985, -0.007779364939779043, 0.006417563185095787, 0.0025466084480285645, 0.06004388630390167, 0.032609373331069946, -0.0019345475593581796, 0.0017354623414576054, 0.02179730497300625, 0.02344515733420849, -0.016486871987581253, 0.026297086849808693, 0.026698578149080276, 0.021025652065873146, -0.004333143122494221, 0.056580156087875366, -0.0021407988388091326, 0.03148306906223297, -0.028169913217425346, 0.02118425816297531, 0.021355804055929184, -0.06374812126159668, -0.03797013685107231, 0.014871147461235523, -0.0042486730962991714, -0.018092330545186996, -0.014010454528033733, 0.028020387515425682, -0.05192137509584427, 0.01188313215970993, 0.005945974495261908, -0.01923319324851036, -0.031199265271425247, -0.0023063444532454014, 0.0032893891911953688, 0.0484808087348938, 0.002974536269903183, -0.0021911687217652798, 0.013105925172567368, 0.007456175982952118, 0.01627221889793873, 0.013790356926620007, 0.0246206596493721, -0.022659597918391228, -0.011083830147981644, -0.016725096851587296, -0.016905473545193672, 0.009445184841752052, 0.006198224611580372, -0.02663455344736576, 0.0102273840457201, 0.029083438217639923, 0.0001291770167881623, 0.033337514847517014, 0.007299460470676422, 0.01106642372906208, -0.04911871254444122, -0.001587121281772852, -0.011555563658475876, -0.013756615109741688, 0.019281966611742973, -0.06497503072023392, -0.009317458607256413, -0.016504677012562752, 0.015360569581389427, 0.040778085589408875, 0.03781694546341896, -0.023313531652092934, -0.0494898222386837, 0.006745691876858473, -0.015319518744945526, -0.042400144040584564, 0.0514608770608902, -0.008540082722902298, 0.014156891964375973, 0.015039958991110325, -0.014327514916658401, -0.02892846055328846, -0.007446031551808119, -0.005633853841573, 0.04617445170879364, 0.009347064420580864, -0.017470013350248337, 0.020642053335905075, 0.04435240477323532, 0.023160582408308983, 0.01689775660634041, 0.03367156907916069, 0.003695594146847725, 0.02657572738826275, -0.02639824151992798, 0.004512808285653591, -0.04028201848268509, 0.020729511976242065, -0.04116590693593025, -0.05523912236094475, -0.005804357584565878, -0.005074481479823589, -0.0028417266439646482, 0.028786493465304375, -0.0578937754034996, -0.004525910597294569, -0.036591894924640656, -0.03703201189637184, -0.00423802062869072, 0.01243550144135952, 0.051181793212890625, 0.03840620815753937, -0.015641339123249054, 0.04159621149301529, -0.04856901615858078, 0.02112744376063347, -0.027388716116547585, 0.025170139968395233, 0.07101428508758545, 0.01847284846007824, -0.008302011527121067, -0.001886530313640833, 0.0390971302986145, -0.00921177864074707, -0.06260304152965546, 0.00416524987667799, -0.00010138346260646358, -0.011042503640055656, -0.058366842567920685, 0.006592401769012213, 0.025003906339406967, -0.023823654279112816, 0.019522277638316154, -0.00030620512552559376, -0.03594902530312538, -0.003590760985389352, 0.024856355041265488, -0.06408428400754929, -0.007166759576648474, -0.014502095058560371, 0.01861819252371788, 0.03809178248047829, 0.01840302161872387, 0.018808122724294662, 0.007110254839062691, -0.035291869193315506, -0.002037349622696638, 0.0021862818393856287, -0.03801429644227028, -0.038954973220825195, -0.01277155987918377, 0.044064585119485855, -0.027836153283715248, -0.03234494850039482, 0.040445730090141296, 0.010339826345443726, -0.03417131304740906, -0.024865098297595978, 0.002870813710615039, 0.002983418293297291, -0.011758877895772457, -0.02249912917613983, -0.018212512135505676, -0.0031049109529703856, 0.02727438509464264, -0.02614486776292324, -0.03333485499024391, 0.011111892759799957 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Let's cheat The first step was to cheat, of course. Why make a big effort when one can make a little one. So I wrote a short notebook that in a few lines of code provided a proxy to fairseq and emulated transformers API. If no other things, but basic translation, was required, this would have been enough. But, of course, we wanted to have the full porting, so after having this small victory, I moved onto much harder things.
[ 0.053527820855379105, -0.0419640876352787, 0.09116620570421219, -0.009373298846185207, 0.10125631093978882, 0.0054716491140425205, 0.05307148024439812, 0.06847117841243744, 0.05006761476397514, -0.04415980726480484, -0.03296712785959244, 0.021611491218209267, -0.03525272384285927, 0.026624470949172974, 0.02750580944120884, -0.00038472283631563187, -0.020311038941144943, -0.04763190075755119, 0.0046804058365523815, -0.01969798654317856, -0.031331948935985565, -0.06369698792695999, 0.07981288433074951, 0.012706772424280643, 0.025749383494257927, -0.06383734941482544, 0.019609209150075912, 0.04803512617945671, -0.04280644282698631, 0.05210612714290619, -0.041244201362133026, -0.029570862650871277, 0.028470652177929878, -0.07971961051225662, -0.11264568567276001, 0.00504440488293767, -0.03885004669427872, 0.011027278378605843, 0.01687997207045555, -0.040671851485967636, 0.0008089791517704725, 0.007473631761968136, 0.0575062595307827, 0.05274936929345131, -0.04421844705939293, 0.010048888623714447, -0.17419129610061646, 0.0913102924823761, -0.062117625027894974, -0.007620303891599178, -0.026378802955150604, 0.021883273497223854, -0.030087901279330254, 0.043707508593797684, 0.03777085617184639, 0.04161437973380089, -0.003946484066545963, -0.03175422549247742, -0.0345957949757576, -0.015052531845867634, 0.07608965039253235, 0.047803305089473724, 0.04177875071763992, 0.008682656101882458, 0.03348352387547493, 0.003990399185568094, 0.0028811118099838495, 0.023132525384426117, -0.04104957357048988, -0.03788653388619423, -0.007423219736665487, -0.05306585505604744, -0.05700434744358063, -0.036057665944099426, 0.04023805633187294, -0.08707921952009201, -0.0335608646273613, 0.049342766404151917, 0.09914745390415192, 0.11712634563446045, -0.015065108425915241, -0.009608770720660686, 0.10316178947687149, -0.00702394125983119, 0.013196016661822796, -0.037713270634412766, 0.00011679565068334341, 0.011750646866858006, -0.04139615595340729, 0.02799561433494091, -0.004727809689939022, -0.09516356140375137, -0.1193988099694252, -0.0190802663564682, -0.006428849883377552, -0.01691301167011261, 0.045436255633831024, 0.04582684859633446, 0.029732314869761467, 0.02622624672949314, -0.043965358287096024, 0.0321129634976387, -0.011521236039698124, -0.06423790007829666, -0.027308225631713867, -0.013202263042330742, 0.028490344062447548, -0.10890936106443405, -0.015027414076030254, 0.033881328999996185, 0.04303155839443207, 0.022528624162077904, 0.03727255016565323, 0.07891329377889633, -0.017374834045767784, 0.05837463587522507, -0.009486192837357521, -0.008496684022247791, -0.03331626206636429, 0.006583549547940493, 0.018960122019052505, 0.06547959893941879, 0.053183529525995255, -0.011763074435293674, 0.05160963162779808, 0.04882786050438881, 0.01241272035986185, 0.03421129658818245, -0.053434111177921295, -0.047256916761398315, 0.04649249091744423, 0.0677526593208313, 0.07818036526441574, 0.0032789139077067375, -0.032754577696323395, -0.04976124316453934, 0.05700378492474556, 0.03002914786338806, -0.0023840416688472033, 0.004792899824678898, -0.03724793344736099, 0.0209775622934103, 0.033046990633010864, 0.054853033274412155, -0.016252903267741203, 0.027379818260669708, -0.06164511665701866, 0.05948793143033981, 0.014358283020555973, 0.006130231078714132, -0.007421786431223154, 0.027900272980332375, -0.02420373074710369, -0.07928171008825302, -0.016395006328821182, 0.02306554839015007, 0.02005442976951599, 0.016881264746189117, -0.0743500366806984, -0.0008161491132341325, -0.03729574754834175, -0.0525108240544796, -0.04288118705153465, -0.058142829686403275, -0.007986921817064285, -0.05087566003203392, -0.022821884602308273, -0.012832657434046268, 0.03135333210229874, 0.045866530388593674, -0.0031838184222579002, -0.04713639244437218, 0.07211250811815262, -0.050879787653684616, -0.02262135222554207, 0.047995127737522125, 0.08745881170034409, 0.027414409443736076, 0.08096114546060562, 0.00949882809072733, -0.06179281324148178, -0.0060690538957715034, 0.00900377705693245, 0.0692039206624031, -0.011158144101500511, 0.03481864929199219, 0.012665245682001114, -0.03696282207965851, -0.04834473505616188, -0.03717707842588425, -0.12093684077262878, 0.03818875923752785, 0.1268230676651001, -0.03973541408777237, -0.03946148231625557, -0.016583725810050964, -0.06004065275192261, 0.06614302098751068, 0.08345599472522736, 0.07022931426763535, 0.05096551030874252, -0.00343750580213964, 0.03413838893175125, 0.004205439705401659, 0.00014466913125943393, 0.01683749444782734, 0.012149305082857609, 0.008904736489057541, -0.010102827101945877, 0.02304137498140335, 0.013208048418164253, -0.03367353230714798, 0.023014485836029053, -0.0826503336429596, -0.0075109112076461315, -0.053587961941957474, -0.0026567988097667694, 0.014160108752548695, 0.0004995502531528473, -0.0016214285278692842, 0.04279544577002525, -0.003122146474197507, -0.040383052080869675, 0.004846168216317892, 0.03784473240375519, 0.06716343015432358, 0.09128651767969131, 0.017253579571843147, 0.012798681855201721, -0.09153616428375244, 0.004085559397935867, -0.005765064619481564, -0.0433177724480629, 0.06497801840305328, -0.07982800155878067, -0.012295080348849297, 0.04101753607392311, -0.06677475571632385, 0.018415667116642, -0.012272949330508709, 0.046839646995067596, 0.08316102623939514, -0.025038521736860275, 0.041768185794353485, 0.02936159446835518, -0.00579513143748045, 0.02654566615819931, 0.02686840109527111, 0.03059215284883976, 0.03214775770902634, -0.11353591084480286, 0.03249506652355194, 0.028395388275384903, -0.07350803911685944, 0.02288343757390976, -0.004747663624584675, -0.00019767055346164852, 0.021344363689422607, -0.016726544126868248, 0.024664636701345444, -0.020956888794898987, -0.011363901197910309, -0.034573379904031754, -0.05457872524857521, 0.0077667622826993465, -0.0027145796921104193, -0.019656352698802948, 0.05894988775253296, -0.022225433960556984, 0.023604921996593475, -0.020148158073425293, -0.07089117914438248, 0.016533568501472473, -0.03965751826763153, 0.047649845480918884, 0.020990222692489624, -0.016398154199123383, 0.009132158942520618, 0.027036545798182487, -0.028479987755417824, -0.022483976557850838, 0.009195487946271896, -0.009877491742372513, -0.015426172874867916, 0.0024437732063233852, 0.003042809199541807, 0.004307270981371403, 0.011993644759058952, 0.013538560830056667, -0.01897474192082882, -0.011411615647375584, 0.058030612766742706, 0.0031777189578861, 0.00020882452372461557, -0.017935870215296745, -0.045719075947999954, -0.014352100901305676, -0.051745232194662094, -0.027293847873806953, -0.004788887221366167, 0.0063986387103796005, -0.02361297607421875, 0.0055609578266739845, 0.016128849238157272, -0.02073194831609726, -0.021145911887288094, 0.003945642150938511, -0.03679890185594559, -0.11279378831386566, -0.020262889564037323, 0.006588739342987537, 0.03177031874656677, -0.00828173290938139, -0.024348558858036995, 0.02712402492761612, -0.0670471340417862, 0.025018587708473206, 0.02083691582083702, 0.025802848860621452, -0.0028694425709545612, -0.010574733838438988, 0.024236831814050674, 0.004993167705833912, -0.04136437177658081, -0.0017083868151530623, 0.031206313520669937, 0.018230179324746132, -0.035873375833034515, -0.014099882915616035, 0.031152669340372086, 0.0014025093987584114, 0.009825125336647034, 0.006127411499619484, -0.011074412614107132, 0.01978018507361412, 0.013853991404175758, 0.005287586711347103, -0.006288560107350349, -0.02271345816552639, 0.0345684252679348, 0.0007508294656872749, 0.02087317407131195, -0.06085933744907379, -0.08002308756113052, -0.0002985379833262414, -0.019050035625696182, 0.00459793396294117, 0.015307765454053879, 0.00218921503983438, -0.009206459857523441, 0.03960718587040901, 0.025785017758607864, -0.014316841959953308, 0.021060224622488022, -0.019282622262835503, 0.00803083460777998, 0.0431782603263855, -0.0418480783700943, -0.039724886417388916, 0.032543133944272995, -0.018513303250074387, 0.06546852737665176, -0.009837309829890728, -0.003280293196439743, -0.011369842104613781, 0.013716249726712704, 0.03823364898562431, -0.017366478219628334, -0.020184583961963654, -0.018035925924777985, 0.0013269672635942698, -0.022389087826013565, -0.050042834132909775, 0.08913290500640869, 0.009368207305669785, 0.0006997346645221114, 0.010032550431787968, 0.026405228301882744, -0.03282928094267845, 0.025450382381677628, 0.003114357590675354, 0.008056608960032463, -0.012950214557349682, 0.047354064881801605, -0.018294354900717735, -0.04141063988208771, 0.03389099985361099, 0.005906311329454184, 0.0015983536140993237, -0.05379379540681839, -0.02360476367175579, 0.004954674281179905, -0.0031469808891415596, 0.004314505960792303, 0.01693381741642952, -0.02351648546755314, -0.00558529794216156, 0.02879006788134575, 0.06526888161897659, -0.008840678259730339, -0.01119257602840662, -0.004687015432864428, 0.017557386308908463, -0.0022932642605155706, 0.04616410285234451, 0.01348299253731966, 0.024374505504965782, -0.011395059525966644, 0.03387346491217613, -0.044950708746910095, -0.023817341774702072, 0.039113134145736694, -0.009591675363481045, 0.009632812812924385, -0.031557597219944, -0.006287583149969578, 0.0026727020740509033, 0.0348312109708786, -0.0009824885055422783, -0.024825848639011383, -0.020051440224051476, -0.02893812209367752, 0.0059607261791825294, -0.03218493238091469, 0.005829037632793188, 0.015831174328923225, -0.01166968047618866, -0.015543247573077679, -0.02422005869448185, 0.008025083690881729, 0.04821190983057022, -0.012790028937160969, -0.006386709399521351, -0.0451037622988224, 0.015920225530862808, 0.07391384243965149, -0.01704062521457672, 0.01110170315951109, -0.027844583615660667, -0.015355045907199383, 0.016604900360107422, -0.0030056554824113846, 0.020785659551620483, 0.055944379419088364, -0.02431114763021469, -0.01123191136866808, -0.007346619386225939, -0.03301432356238365, 0.024698588997125626, -0.028482481837272644, 0.008240793831646442, -0.02611318603157997, 0.03512465953826904, -0.02478322759270668, 0.019978629425168037, -0.002514561405405402, -0.008564213290810585, 0.02319270744919777, 0.06779990345239639, -0.024437623098492622, -0.028098994866013527, 0.011335683055222034, -0.02535180002450943, 0.012959744781255722, 0.01583707146346569, -0.0006441142177209258, -0.030027907341718674, 0.01842479780316353, -0.01914108917117119, -0.0066667646169662476, -0.06059170514345169, 0.04336746037006378, -0.00018070860824082047, -0.019476767629384995, 0.02032833732664585, -0.043414514511823654, 0.008393965661525726, -0.049077462404966354, -0.04323620721697807, 0.0012049955548718572, 0.03946375101804733, -0.02963295206427574, -0.004151161294430494, 0.04285309836268425, -0.018144501373171806, 0.01002521812915802, 0.023863688111305237, -0.028007181361317635, -0.012157971039414406, 0.011444834992289543, 0.03811546415090561, -0.01562797650694847, -0.020582327619194984, 0.03118198551237583, 0.06543311476707458, 0.048147983849048615, -0.022073956206440926, 0.003259578486904502, -0.026318376883864403, -0.014028461650013924, 0.007448672782629728, -0.014205045066773891, 0.049584511667490005, -0.047904547303915024, -0.008505416102707386, -0.04046105220913887, -0.04091982915997505, -0.010179970413446426, 0.03930016979575157, 0.05979660898447037, -0.005125367548316717, 0.005194181110709906, 0.062414057552814484, -0.0029670530930161476, 0.015774374827742577, -0.010416261851787567, -0.0018569357926025987, -0.06051623821258545, 0.006094546522945166, 0.012782990001142025, -0.0009971256367862225, -0.04375927522778511, -0.0009996872395277023, -0.02839662693440914, 0.027789967134594917, 0.06211326643824577, -0.0072740777395665646, 0.017784513533115387, 0.013340081088244915, -0.02196972817182541, -0.020995723083615303, 0.04211778566241264, 0.03808392956852913, -0.036292608827352524, -0.010279646143317223, -0.03133225813508034, 0.029086066409945488, -0.010847811587154865, 0.03868720680475235, 0.035161882638931274, -0.011309763416647911, 0.01345282606780529, 0.013991540297865868, -0.015617634169757366, -0.03700881451368332, 0.02817763388156891, 0.05885068699717522, -0.003084119176492095, 0.009705536998808384, -0.06636109948158264, -0.026764623820781708, -0.013277808204293251, -0.01343384850770235, 0.04242334142327309, 0.05809752643108368, 0.01081391703337431, -0.0029804331716150045, -0.00033697643084451556, 0.0025497782044112682, 0.018096499145030975, -0.008080809377133846, 0.029363537207245827, 0.019210712984204292, -0.009469821117818356, 0.03668743744492531, 0.007333811838179827, 0.032049860805273056, 0.004260461777448654, 0.02680552564561367, -0.010453489609062672, -0.02710895612835884, 0.0366256907582283, -0.02377372235059738, 0.028136877343058586, -0.010317324660718441, 0.0075411442667245865, -0.014826023019850254, -0.0416201613843441, 0.004114283248782158, 0.01815502904355526, 0.06744340807199478, 0.014519844204187393, -0.0019220092799514532, -0.05328337103128433, 0.04191671684384346, 0.03444206714630127, 0.02067532204091549, 0.006385312881320715, 0.01467873901128769, 0.01134971622377634, 0.01773638278245926, -0.03481876105070114, 0.005333009175956249, 0.04507597163319588, 0.052285920828580856, -0.024988999590277672, 0.03380107879638672, 0.04985200986266136, -0.0008130015921778977, -0.003636252135038376, 0.005179137457162142, 0.01141625177115202, -0.04058760032057762, 0.032402753829956055, -0.02136288955807686, -0.04251297190785408, -0.03421676531434059, -0.03000149130821228, 0.046756330877542496, 0.0070264386013150215, 0.009719491004943848, 0.010904773138463497, 0.044503867626190186, 0.028522372245788574, -0.012167774140834808, 0.029437463730573654, -0.05574284866452217, -0.000619180325884372, -0.012319155968725681, 0.04197205603122711, -0.039245665073394775, -0.05070222541689873, -0.05787200480699539, -0.008585356175899506, -0.01528370101004839, -0.00013594745541922748, -0.022448662668466568, 0.032890237867832184, 0.011644813232123852, -0.05080834776163101, 0.010007530450820923, -0.014138000085949898, -0.03317372128367424, -0.034637246280908585, -0.020100953057408333, -0.012718233279883862, -0.0064036608673632145, 0.00036389895831234753, 0.007427150383591652, 0.013290729373693466, 0.015319768339395523, 0.002119154669344425, -0.0308991651982069, 0.04175138846039772, 0.03789833188056946, 0.04421684518456459, 0.006288447417318821, 0.020515432581305504, -0.036023616790771484, 0.010283094830811024, 0.028338655829429626, -0.006813721265643835, -0.020318765193223953, -0.027936330065131187, 0.04984220862388611, 0.01905854046344757, 0.01846958138048649, 0.02791995368897915, 0.0006369446055032313, 0.019699936732649803, -0.028275026008486748, 0.02877294458448887, -0.021084243431687355, -0.03388146311044693, 0.0007574111223220825, -0.011832078918814659, 0.015180782414972782, 0.033761534839868546, -0.011757640168070793, 0.002728772349655628, 0.03564581647515297, -0.018422992900013924, -0.042017366737127304, 0.031029386445879936, -0.012664668262004852, -0.057431597262620926, -0.0004619651008397341, 0.004601992201060057, 0.019565831869840622, -0.00813848152756691, 0.009985367767512798, 0.03722073882818222, -0.0035122744739055634, -0.026422671973705292, 0.014175213873386383, 0.007959045469760895, -0.03772176802158356, -0.03355628252029419, 0.0524568110704422, -0.01749352365732193, 0.02469329722225666, 0.06808269023895264, 0.03563991189002991, 0.0031024273484945297, -0.002958164783194661, -0.036888692528009415, 0.0048272619023919106, 0.04317513853311539, -0.038536760956048965, -0.04124155640602112, -0.0002264487702632323, -0.00601814454421401, 0.007677173241972923, 0.006595928221940994, -0.021492522209882736, 0.009395425207912922, -0.03781432285904884, -0.046729058027267456, 0.010945512913167477, 0.0073804124258458614, 0.07628924399614334, 0.006628960836678743, 0.03593141958117485, -0.006253426894545555, 0.006315859034657478, -0.028115680441260338, -0.005957257002592087, 0.020998075604438782, 0.0444205105304718, 0.008619819767773151, 0.005876138340681791, -0.05060681328177452, -0.019747823476791382, -0.050881195813417435, -0.05322059616446495, 0.010500903241336346, 0.01663520187139511, -0.0021928634960204363, -0.035048916935920715, 0.06337866187095642, 0.021739615127444267, 0.008601467125117779, -0.006381131708621979, -0.017919914796948433, 0.024251576513051987, 0.008143791928887367, -0.01349715981632471, -0.04950619488954544, -0.0020898703951388597, -0.03703397884964943, 0.013186866417527199, -0.002387838438153267, 0.01882317289710045, -0.03431740030646324, 0.03087649680674076, -0.036349739879369736, 0.01611366868019104, 0.018887601792812347, -0.006724056787788868, 0.028016472235322, -0.005561074707657099, -0.013522514142096043, -0.0418415293097496, -0.057225827127695084, 0.027439052239060402, -0.007551612798124552, 0.0075280433520674706, 0.009932063519954681, 0.026178909465670586, -0.0030579171143472195, 0.009948226623237133, 0.022145630791783333, -0.027347302064299583, 0.009054581634700298, 0.011475160717964172, -0.009487351402640343, -0.031888365745544434, -0.0013732367660850286 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
SinusoidalPositionalEmbeddingfairseqused a slightly different implementation ofSinusoidalPositionalEmbeddingthan the one used bytransformers. Initially I copied thefairseqimplementation. But when trying to get the test suite to work I couldn't get thetorchscripttests to pass.SinusoidalPositionalEmbeddingwas written so that it won't be part ofstate_dictand not get saved with the model weights - all the weights generated by this class are deterministic and are not trained.fairseqused a trick to make this work transparently by not making its weights a parameter or a buffer, and then duringforwardswitching the weights to the correct device.torchscriptwasn't taking this well, as it wanted all the weights to be on the correct device before the firstforwardcall. I had to rewrite the implementation to convert it to a normalnn.Embeddingsubclass and then add functionality to not save these weights duringsave_pretrained()and forfrom_pretrained()to not complain if it can't find those weights during thestate_dictloading.
[ -0.05038021504878998, -0.024438051506876945, 0.029849639162421227, 0.02171996608376503, -0.02205848880112171, 0.08345575630664825, 0.02524389699101448, -0.012404017150402069, -0.03667785972356796, -0.05547676235437393, -0.0031710516195744276, 0.04363306239247322, -0.0028724807780236006, 0.0009288479923270643, -0.004878619685769081, -0.007657620590180159, 0.07075756043195724, -0.0030012913048267365, -0.03835735097527504, 0.025149451568722725, -0.013569320552051067, -0.024993104860186577, 0.0009529366507194936, -0.05513611435890198, -0.047536615282297134, -0.07971319556236267, -0.00733934948220849, 0.06925234943628311, -0.07824601978063583, 0.06259580701589584, -0.02137555554509163, 0.027330053970217705, 0.03206224367022514, -0.10168642550706863, -0.025119461119174957, 0.023786256089806557, -0.06273048371076584, 0.012043663300573826, -0.02055663801729679, -0.040355753153562546, -0.05866548418998718, -0.05250772461295128, -0.04034338891506195, 0.08916950970888138, 0.023518256843090057, -0.026065051555633545, -0.09750017523765564, 0.08607461303472519, -0.052072081714868546, -0.028077678754925728, -0.09611709415912628, 0.028294619172811508, -0.08614641427993774, 0.011420502327382565, 0.034153591841459274, 0.04370123893022537, 0.011693870648741722, 0.010804512538015842, 0.018829718232154846, -0.0077846054919064045, 0.042799029499292374, -0.020125148817896843, -0.05627019330859184, 0.03221577778458595, 0.08877483010292053, 0.01200750470161438, 0.05221884697675705, 0.05797988176345825, -0.014760332182049751, -0.09636665880680084, 0.013916239142417908, -0.029171600937843323, 0.034462109208106995, -0.005524565931409597, -0.024236368015408516, -0.004648711532354355, -0.037989694625139236, 0.026240382343530655, 0.05902683362364769, 0.07916458696126938, -0.06487394124269485, 0.005033954046666622, 0.03881991654634476, 0.07198093831539154, -0.04804756119847298, -0.018352791666984558, 0.08149594813585281, 0.006277194246649742, 0.08323629200458527, -0.031427428126335144, -0.01369781605899334, -0.02334640733897686, -0.02326573245227337, 0.11136122792959213, 0.051833588629961014, 0.027110284194350243, -0.015242277644574642, 0.022040676325559616, -0.016655385494232178, -0.0004055120807606727, -0.0011377440532669425, -0.02636771649122238, -0.011402196250855923, -0.060749854892492294, 0.03324232995510101, 0.06905380636453629, -0.014430742710828781, -0.03893226012587547, -0.004143071826547384, 0.0967160165309906, -0.04433740675449371, -0.020017387345433235, 0.0241682268679142, 0.041798319667577744, -0.029750041663646698, -0.08445056527853012, 0.013139074668288231, 0.001410537282936275, -0.03622904419898987, -0.000974890252109617, 0.03238563612103462, 0.11968059092760086, -0.015144210308790207, -0.004576611332595348, 0.04667862877249718, 0.07418984174728394, 0.04373566433787346, -0.00558817433193326, -0.008300097659230232, 0.02955549769103527, 0.0041620139963924885, 0.01694936864078045, 0.07597970217466354, 0.02023155428469181, 0.025831038132309914, -0.03228256478905678, -0.0643027126789093, -0.003842780599370599, -0.04295962303876877, 0.04040990769863129, -0.056873172521591187, 0.007631184533238411, 0.030386969447135925, -0.025770563632249832, -0.019682183861732483, -0.07025080919265747, -0.04160204529762268, 0.08442946523427963, -0.021969540044665337, 0.07477019727230072, -0.04517251253128052, 0.07977268844842911, -0.039366163313388824, -0.02141808718442917, -0.06189559027552605, 0.047218821942806244, -0.03990078344941139, -0.004063057713210583, -0.0409974530339241, -0.03567126393318176, -0.011091293767094612, 0.030926687642931938, -0.044232990592718124, 0.004991534166038036, 0.03653556481003761, -0.02593105286359787, 0.042841505259275436, 0.017439618706703186, 0.0704931691288948, 0.04126932471990585, 0.0020809073466807604, -0.028436344116926193, 0.01313132606446743, 0.023850012570619583, -0.023083027452230453, 0.03093249537050724, -0.06610166281461716, 0.031397152692079544, -0.018256423994898796, -0.020931754261255264, -0.027864351868629456, 0.003839212702587247, -0.024169595912098885, 0.02314024232327938, -0.00049187196418643, -0.07900337874889374, 0.04993799701333046, -0.03703254088759422, -0.03281017392873764, 0.08585251122713089, -0.05962570756673813, 0.010642020963132381, 0.037125539034605026, -0.07451584190130234, 0.03712616488337517, -0.031068315729498863, -0.03312387317419052, 0.0607992559671402, 0.05027303472161293, 0.015457265079021454, 0.02133091725409031, 0.03900380805134773, 0.015621867030858994, -0.016340740025043488, 0.012746605090796947, 0.005924955941736698, 0.015357025898993015, -0.06098740175366402, 0.00788398738950491, 0.03999587893486023, 0.026966063305735588, -0.07154233008623123, 0.051745567470788956, -0.005941757932305336, 0.00009652580047259107, -0.05440225452184677, -0.06592272967100143, -0.004511192906647921, -0.028973961248993874, -0.05784483253955841, 0.0770319476723671, 0.06083158403635025, 0.054235171526670456, -0.06746230274438858, -0.03668215125799179, 0.06461478024721146, 0.002856804057955742, 0.046063877642154694, 0.07363419234752655, -0.1418650597333908, -0.014897001907229424, -0.08130154013633728, -0.048510387539863586, 0.06417824327945709, 0.005869008135050535, -0.0576399527490139, -0.015530264936387539, 0.03715735673904419, -0.055429309606552124, -0.010820364579558372, 0.07329206168651581, 0.08880200237035751, -0.03515249118208885, 0.07111945748329163, -0.0768594816327095, 0.038145650178194046, 0.01832076907157898, 0.00812156405299902, -0.007805476430803537, 0.020235979929566383, -0.12287753075361252, 0.018477560952305794, 0.0182555690407753, -0.022437550127506256, 0.02759561501443386, 0.08471571654081345, -0.028362976387143135, -0.006920625455677509, -0.02053731493651867, -0.008460624143481255, 0.017637722194194794, 0.0228283628821373, -0.012860669754445553, 0.005762778222560883, -0.008375559002161026, -0.0604642778635025, 0.005183442961424589, -0.027382196858525276, 0.010238906368613243, 0.019445452839136124, -0.04355165734887123, -0.03265644237399101, 0.02607796899974346, -0.012157903052866459, -0.0007940257200971246, 0.0668756440281868, 0.04391093552112579, -0.03352116420865059, -0.07700956612825394, 0.02355681173503399, -0.05779462307691574, -0.040764544159173965, 0.03943318873643875, -0.013653915375471115, -0.0070882136933505535, 0.02026931382715702, 0.011555100791156292, -0.013867097906768322, 0.021629370748996735, 0.02120775543153286, 0.005563877057284117, 0.014041830785572529, 0.08816133439540863, 0.015414570458233356, -0.05639731138944626, 0.009584375657141209, -0.014788821339607239, -0.015643859282135963, 0.023807616904377937, -0.005623019300401211, -0.01446189358830452, 0.008641168475151062, -0.007705632131546736, 0.018594423308968544, -0.01675586774945259, -0.023210186511278152, 0.0011173819657415152, 0.02858300320804119, -0.08481597155332565, 0.01906634122133255, 0.009681414812803268, 0.041103046387434006, 0.011438741348683834, -0.012915180064737797, 0.021928252652287483, -0.031382959336042404, 0.023902911692857742, 0.04227381572127342, 0.002333021955564618, 0.0018402659334242344, -0.013109165243804455, 0.02134927548468113, 0.00319796078838408, 0.009804602712392807, -0.0027385021094232798, 0.016017917543649673, 0.010406582616269588, 0.021209461614489555, -0.020929858088493347, 0.005704335402697325, 0.006944266613572836, -0.01512120384722948, -0.05104577913880348, 0.08076610416173935, 0.04094524681568146, 0.06744571775197983, -0.0015475136460736394, -0.04168478026986122, -0.03148673102259636, -0.013042032718658447, -0.0015356179792433977, 0.03589056804776192, -0.008247502148151398, -0.014179470017552376, -0.012960249558091164, 0.02921207807958126, 0.0026888023130595684, -0.017599983140826225, 0.007138804532587528, 0.007855696603655815, -0.017440538853406906, 0.01924997754395008, 0.03778168559074402, -0.009514649398624897, -0.02202422544360161, 0.021857570856809616, 0.01169721968472004, -0.0072213043458759785, 0.0016500269994139671, -0.02988247014582157, -0.044056717306375504, 0.009053321555256844, -0.024297380819916725, -0.016802316531538963, 0.022757241502404213, 0.03459998592734337, 0.034246522933244705, -0.052153002470731735, -0.05491560325026512, 0.006481933873146772, -0.007203272078186274, 0.009429508820176125, -0.017887534573674202, 0.0633184090256691, 0.0660095289349556, 0.00553453853353858, -0.014374875463545322, -0.013345430605113506, -0.0064955768175423145, 0.04639226943254471, 0.04335438832640648, 0.00012658876948989928, -0.017569532617926598, 0.00014982237189542502, -0.016457434743642807, -0.01776937022805214, 0.013175508007407188, 0.015203149989247322, -0.004064186010509729, -0.01936452090740204, -0.00026742357295006514, 0.008006736636161804, 0.009455806575715542, -0.000299670995445922, -0.03136361762881279, 0.009644297882914543, 0.028165269643068314, -0.015903549268841743, 0.06292519718408585, -0.008311151526868343, 0.018455855548381805, -0.027056213468313217, -0.02379940077662468, 0.003977594897150993, 0.019572533667087555, -0.0002694639842957258, 0.0022337569389492273, -0.01393208559602499, -0.011991603299975395, -0.03376154229044914, 0.015197671949863434, 0.03928154334425926, 0.012578469701111317, -0.04062248393893242, -0.04774308204650879, -0.009308221749961376, -0.032775506377220154, -0.03217474743723869, 0.010436356998980045, -0.01808014139533043, -0.00036130979424342513, -0.002805594587698579, 0.04762878641486168, 0.009180746041238308, 0.007754475809633732, -0.003219222417101264, -0.013797687366604805, 0.01564926840364933, -0.04993695765733719, 0.03922373056411743, 0.03332802280783653, -0.02929704263806343, 0.04734030365943909, 0.0010320027358829975, -0.005053260363638401, 0.040219034999608994, 0.027043689042329788, -0.0026601338759064674, -0.06088153272867203, 0.0009334333008155227, 0.04954429343342781, 0.04642138257622719, -0.013910073786973953, 0.02366190403699875, -0.008791872300207615, 0.01507674902677536, 0.0219575148075819, -0.030245887115597725, -0.012152636423707008, -0.004491062369197607, 0.03290815278887749, -0.028097307309508324, 0.029170788824558258, -0.011762578971683979, 0.02369779162108898, 0.04505802318453789, -0.049424998462200165, -0.0059658740647137165, 0.033629994839429855, 0.038029249757528305, -0.008402767591178417, -0.03811747953295708, 0.047540534287691116, 0.024862240999937057, 0.00513515854254365, -0.01458876021206379, -0.028327545151114464, 0.021943191066384315, 0.02134646847844124, 0.022554578259587288, -0.03498299792408943, 0.01254382822662592, 0.017175128683447838, 0.01179669238626957, -0.03372884914278984, -0.0673879012465477, 0.049318794161081314, 0.008249454200267792, -0.03139544650912285, 0.013087254017591476, -0.007202243898063898, -0.017748650163412094, 0.02519458346068859, -0.0012641963548958302, 0.008596998639404774, 0.005655830726027489, -0.05016973242163658, 0.025482958182692528, 0.042395565658807755, 0.014890498481690884, 0.04406418278813362, -0.015951398760080338, -0.00639240862801671, 0.000009028819476952776, 0.026079069823026657, 0.029799601063132286, 0.01801956072449684, 0.027209248393774033, -0.01641889102756977, 0.010484283789992332, -0.022047655656933784, -0.064200758934021, 0.02458023652434349, 0.013122211210429668, 0.024275686591863632, 0.0410146526992321, -0.0023735344875603914, -0.05867622420191765, 0.014570420607924461, 0.0368642620742321, 0.0033718496561050415, -0.03631705418229103, 0.03466568514704704, -0.017639588564634323, -0.002292458899319172, 0.0089588463306427, -0.006595516111701727, -0.004865520168095827, 0.0000660303485346958, 0.03394278511404991, 0.008007758297026157, -0.01747538521885872, 0.004191689658910036, -0.04068106785416603, -0.058570053428411484, 0.010618285275995731, 0.009111623279750347, 0.037266604602336884, -0.011256261728703976, 0.0075309183448553085, 0.053815197199583054, 0.04047746583819389, 0.04994635283946991, -0.06801013648509979, -0.00223566428758204, 0.021580230444669724, 0.013360882177948952, 0.024186449125409126, 0.0036766722332686186, 0.045546483248472214, -0.007870680652558804, 0.008735294453799725, -0.0036557612475007772, 0.004866152536123991, 0.015373937785625458, 0.054146308451890945, 0.005855506286025047, -0.014700300991535187, 0.024230197072029114, -0.0032486545387655497, -0.015893250703811646, 0.03349888324737549, 0.007959317415952682, 0.042575642466545105, 0.05940720811486244, -0.02283981814980507, 0.033559344708919525, -0.0012870605569332838, 0.006256051827222109, 0.037750452756881714, -0.059764135628938675, -0.010870798490941525, -0.02096930332481861, -0.028333371505141258, 0.04930785670876503, -0.023388134315609932, -0.03377876803278923, 0.011155247688293457, 0.014277718961238861, -0.08781100064516068, -0.02596038579940796, -0.001619202783331275, -0.045090530067682266, 0.020814523100852966, 0.042470723390579224, -0.04295564815402031, 0.016486147418618202, -0.017007069662213326, 0.022322682663798332, 0.03400136157870293, 0.06036480888724327, -0.011185679584741592, 0.022069251164793968, -0.021805504336953163, 0.041353490203619, -0.017590221017599106, 0.013933411799371243, 0.005896059330552816, -0.009708116762340069, 0.016247909516096115, -0.020991139113903046, 0.017817268148064613, 0.008044876158237457, 0.00736588891595602, 0.0824865773320198, -0.025609001517295837, -0.03908323869109154, 0.012065533548593521, 0.016314830631017685, 0.008621918968856335, 0.017208747565746307, -0.05402188375592232, -0.03343503177165985, 0.044108934700489044, 0.00028991044382564723, -0.014470855705440044, 0.005306714214384556, -0.04051080718636513, 0.00985078513622284, 0.01252010092139244, 0.057729266583919525, 0.02228505350649357, 0.04093952849507332, 0.01760893128812313, 0.05983675643801689, -0.0002839361841324717, 0.005111618433147669, 0.008788777515292168, -0.05491491034626961, 0.0025626143906265497, -0.017864275723695755, -0.0017441685777157545, 0.02078927308320999, -0.020863700658082962, 0.04111947864294052, 0.02088291384279728, -0.010327464900910854, 0.03775356337428093, -0.021492289379239082, 0.04391852766275406, -0.0030844334978610277, 0.0033973490353673697, -0.012541758827865124, -0.015469253063201904, 0.0009011797374114394, -0.021922945976257324, -0.06781177222728729, 0.01882876083254814, -0.05947217717766762, 0.0572342649102211, 0.018766319379210472, -0.030967501923441887, 0.011033262126147747, 0.025687070563435555, -0.009151876904070377, -0.005017154850065708, -0.011618774384260178, -0.003243180923163891, -0.017311010509729385, -0.022577011957764626, 0.049316950142383575, 0.017183812335133553, -0.009267080575227737, -0.0008973676012828946, 0.02972959727048874, 0.011625418439507484, -0.025722628459334373, -0.0021763464901596308, 0.00701905507594347, 0.03499283641576767, -0.03125401958823204, -0.009443373419344425, -0.030758816748857498, -0.018369322642683983, -0.0013998274225741625, -0.02040059305727482, -0.030066978186368942, 0.006552309263497591, 0.013199645094573498, 0.020580783486366272, 0.02667410485446453, -0.02637275867164135, -0.08330951631069183, -0.04488861560821533, 0.024817071855068207, 0.0013092650333419442, -0.027627142146229744, -0.00045787665294483304, 0.0267113596200943, -0.01978212408721447, -0.00041803851490840316, 0.02586575597524643, 0.01754733920097351, -0.019810466095805168, 0.02966402843594551, -0.0303338635712862, -0.014370705001056194, -0.006237149704247713, 0.0675598755478859, -0.0011265733046457171, -0.05952196940779686, -0.004575914237648249, -0.021878037601709366, -0.0001434425648767501, -0.024204375222325325, -0.01742277294397354, -0.056614719331264496, 0.0025311969220638275, 0.005387803539633751, -0.045230232179164886, -0.034218110144138336, 0.04868243634700775, 0.022540176287293434, 0.011560069397091866, -0.0037049888633191586, 0.003579153213649988, 0.008140369318425655, -0.024620313197374344, -0.0007093062740750611, -0.0004858634783886373, 0.06571527570486069, 0.04490252584218979, -0.034538671374320984, 0.023177634924650192, -0.01963328756392002, 0.020108144730329514, -0.01711791753768921, -0.002267365576699376, 0.04908152297139168, -0.005318829324096441, 0.032847948372364044, -0.0557699128985405, 0.00542839290574193, 0.008108883164823055, -0.027816325426101685, -0.04051386937499046, 0.037170711904764175, -0.002096934709697962, -0.08199633657932281, -0.023087283596396446, 0.001006441074423492, 0.026103630661964417, 0.03291924670338631, 0.006209824699908495, 0.00768165523186326, 0.0031020892783999443, 0.02234368585050106, -0.050613533705472946, -0.009790204465389252, -0.04620508477091789, -0.035876963287591934, -0.0027598822489380836, 0.006071547511965036, 0.02568036876618862, -0.009221740998327732, 0.024040326476097107, 0.02996012568473816, 0.014804067090153694, 0.0023480115924030542, -0.06038366258144379, -0.029595086351037025, -0.010920848697423935, -0.0065418751910328865, -0.04066397622227669, -0.004105036146938801, -0.029991745948791504, -0.04074082896113396, -0.024567442014813423, 0.00933885108679533, 0.004424101673066616, 0.016671448945999146, -0.005263784434646368, 0.00544720608741045, 0.008438987657427788, -0.006162421312183142, -0.04950355738401413, -0.003210555063560605, -0.00557467807084322 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Manual testing Until now I was primarily using my own scripts to do the testing. Once I had the translator working, I converted the reversedru-enmodel and then wrote two paraphrase scripts: * [fseq-paraphrase](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/scripts/fseq-paraphrase.py) * [fsmt-paraphrase](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/scripts/fsmt-paraphrase.py) which took a sentence in the source language, translated it to another language and then translated the result of that back to the original language. This process usually results in a paraphrased outcome, due to differences in how different languages express similar things. With the help of these scripts I found some more problems with the detokenizer, stepped through with the debugger and made the fsmt script produce the same results as thefairseqversion. At this stage no-beam search was producing mostly identical results, but there was still some divergence in the beam search. In order to identify the special cases, I wrote a [fsmt-port-validate.py](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/scripts/fsmt-port-validate.py) script that used as inputssacrebleutest data and it run that data through bothfairseqandtransformerstranslation and reported only mismatches. It quickly identified a few remaining problems and observing the patterns I was able to fix those issues as well.
[ 0.026897335425019264, -0.0212445966899395, 0.014969262294471264, 0.040179818868637085, 0.05685414373874664, 0.08648636937141418, 0.1001821830868721, -0.010849284939467907, 0.01018797792494297, -0.018955208361148834, -0.0811537653207779, 0.05481870099902153, 0.02892930619418621, 0.024811692535877228, -0.011919430457055569, 0.015686117112636566, 0.0031675989739596844, -0.07522068917751312, 0.017452478408813477, 0.008675817400217056, 0.05206112191081047, -0.012658804655075073, 0.02825549617409706, -0.006531958002597094, -0.0013152043102309108, -0.06006127595901489, 0.01823957823216915, 0.07211438566446304, -0.06901224702596664, 0.020032117143273354, -0.02887977473437786, 0.03297756239771843, 0.011273134499788284, -0.08287832885980606, -0.0363597571849823, 0.04376596584916115, -0.11156535893678665, 0.018851524218916893, -0.01492676604539156, -0.04481343924999237, -0.01804927922785282, -0.009896974079310894, 0.03434697166085243, -0.008211215026676655, -0.015549729578197002, 0.11315196752548218, -0.10171274840831757, 0.03513610363006592, -0.05089657008647919, -0.018541887402534485, -0.08040416240692139, -0.02348240278661251, -0.04390600323677063, -0.07567816972732544, 0.02260747179389, 0.037324000149965286, -0.043258775025606155, -0.00023814548330847174, 0.05043311417102814, 0.022788675501942635, 0.015522916801273823, 0.003158708568662405, 0.008852321654558182, 0.03938864544034004, 0.047776855528354645, 0.022244395688176155, 0.012277534231543541, 0.043927885591983795, -0.009977025911211967, -0.015519913285970688, -0.03610427305102348, -0.014953403733670712, -0.03095448762178421, -0.01947595924139023, 0.06273481994867325, -0.07003548741340637, -0.05492245778441429, 0.0945693850517273, -0.00042757601477205753, 0.03263905271887779, 0.002864765701815486, 0.021150680258870125, 0.01905987784266472, 0.025746747851371765, 0.009034819900989532, 0.031693845987319946, 0.07259328663349152, -0.04476262256503105, -0.028798284009099007, 0.03128162771463394, -0.03206362575292587, -0.0721735805273056, -0.069738008081913, 0.05038266256451607, 0.012772813439369202, 0.02344007045030594, -0.023202944546937943, 0.09337010234594345, -0.013751601800322533, 0.03369476646184921, -0.023977022618055344, 0.04764268547296524, 0.04401172325015068, -0.04084917530417442, 0.021685607731342316, -0.01593688316643238, -0.048132166266441345, -0.039087504148483276, -0.05066461116075516, 0.03660961613059044, 0.02209889516234398, -0.000614628370385617, -0.00023685750784352422, 0.04223911464214325, -0.059869542717933655, 0.05103866010904312, -0.0011256206780672073, -0.004227814264595509, -0.017397139221429825, 0.04653244838118553, 0.03244812414050102, 0.031229568645358086, 0.002219276735559106, -0.02721216343343258, 0.04073282331228256, 0.025009023025631905, 0.06609606742858887, 0.05180812254548073, -0.04931497946381569, -0.016378013417124748, -0.0073819891549646854, -0.004598479252308607, 0.08877617120742798, 0.01813817210495472, -0.018201390281319618, -0.020741991698741913, 0.028769107535481453, -0.007783766370266676, -0.030259916558861732, 0.05580693855881691, -0.03818780928850174, -0.04893791303038597, -0.043573349714279175, 0.025723805651068687, -0.0401991531252861, 0.04200126603245735, -0.06436505913734436, 0.06966955959796906, 0.0068566445261240005, 0.07964741438627243, -0.052707232534885406, 0.04597562924027443, -0.004636701196432114, -0.05236072093248367, -0.020274728536605835, 0.06810146570205688, -0.023042799904942513, -0.001646959106437862, -0.07532114535570145, 0.028867749497294426, -0.04447045177221298, 0.03146934136748314, -0.023060372099280357, -0.038519587367773056, -0.021575868129730225, 0.0037557396572083235, 0.010571709834039211, 0.05823320522904396, 0.03940751403570175, 0.07718109339475632, 0.04198088124394417, 0.01361736562103033, 0.11206460744142532, -0.04157707095146179, 0.012953238561749458, 0.027580982074141502, 0.015809163451194763, -0.01639665476977825, -0.002721939003095031, -0.042318206280469894, -0.03246920183300972, 0.0448375903069973, -0.0143365990370512, 0.08117165416479111, -0.07958018779754639, -0.030521711334586143, 0.059060607105493546, -0.007238836959004402, -0.029926814138889313, 0.00566108850762248, -0.10384079813957214, -0.044523146003484726, 0.0971655398607254, -0.05106397718191147, 0.008857185952365398, -0.006430000998079777, 0.022787604480981827, 0.09852657467126846, 0.058890100568532944, 0.042951177805662155, 0.019028309732675552, 0.02671419270336628, 0.024804864078760147, -0.044726043939590454, 0.033474914729595184, 0.0610235258936882, 0.07125317305326462, -0.0913759246468544, -0.007893833331763744, 0.031146859750151634, 0.07372868806123734, -0.06804423034191132, -0.01454911008477211, -0.02051650546491146, -0.024477235972881317, -0.032883018255233765, -0.07810036838054657, -0.026365697383880615, -0.023086054250597954, 0.03311176970601082, 0.10714420676231384, -0.0035565784201025963, -0.01549976971000433, -0.024291563779115677, -0.01663253828883171, 0.05569210276007652, 0.05871891975402832, 0.08835294097661972, 0.043638624250888824, 0.01424227561801672, -0.01857091672718525, -0.015884237363934517, 0.05769522860646248, 0.06449354439973831, -0.0353926382958889, -0.09866207838058472, -0.021554166451096535, -0.006757399532943964, -0.002626754343509674, 0.0020420702639967203, 0.033971499651670456, 0.020080721005797386, 0.029692254960536957, 0.09078067541122437, -0.02685326337814331, 0.04354603588581085, 0.021823208779096603, 0.027904368937015533, -0.019233182072639465, 0.0010343517642468214, -0.012507454492151737, 0.048804037272930145, -0.06528940051794052, -0.03117598220705986, 0.06865883618593216, -0.07074308395385742, 0.013709754683077335, 0.05412466451525688, -0.005083832889795303, 0.018465733155608177, -0.00011078147508669645, 0.0031084062065929174, -0.031343188136816025, -0.05281110107898712, 0.027905138209462166, -0.04284972697496414, 0.02177579700946808, -0.013110257685184479, -0.041265979409217834, 0.01167958602309227, -0.03193894401192665, -0.03084111399948597, 0.02348952367901802, -0.015398935414850712, 0.01989131048321724, 0.005776877980679274, 0.010612688027322292, -0.06696140766143799, -0.026024453341960907, 0.018706930801272392, -0.043110888451337814, -0.007666084449738264, 0.01484959851950407, 0.004265092313289642, 0.013890738599002361, 0.028622301295399666, -0.04059205576777458, 0.007350851781666279, -0.015132822096347809, 0.011715026572346687, 0.0552249476313591, 0.007995886728167534, 0.03815695643424988, 0.013420045375823975, -0.01905204728245735, 0.015840647742152214, -0.025308676064014435, -0.02468918450176716, -0.017692988738417625, 0.037095025181770325, -0.009355360642075539, 0.015487303026020527, -0.009690718725323677, -0.015171734616160393, -0.07402515411376953, 0.0330798514187336, 0.0022733488585799932, 0.011759468354284763, -0.08962492644786835, 0.03284783661365509, 0.019592266529798508, -0.015155265107750893, -0.003859063843265176, -0.023170024156570435, 0.02706444449722767, 0.005188408307731152, 0.0039253998547792435, 0.004458978772163391, 0.01464543491601944, 0.020338522270321846, 0.0360616073012352, 0.05431241914629936, -0.049942076206207275, -0.024484101682901382, -0.020201684907078743, 0.0012196744792163372, 0.014589929021894932, -0.03441367298364639, 0.003399993060156703, -0.006878361571580172, -0.0021115164272487164, 0.019402632489800453, -0.04315291345119476, -0.03963177278637886, 0.0419202484190464, 0.014733104035258293, 0.015490046702325344, -0.05146246403455734, 0.033826448023319244, 0.01157761737704277, -0.03485577926039696, -0.0040250071324408054, -0.03520861640572548, -0.052378732711076736, 0.012639445252716541, 0.035075414925813675, 0.023764556273818016, 0.03626532480120659, 0.05289587751030922, 0.030591515824198723, 0.0058297524228692055, 0.0007699666311964393, 0.013593911193311214, -0.020222092047333717, -0.003655396867543459, 0.0017365235835313797, 0.03135383874177933, -0.03651329502463341, -0.019787149503827095, -0.020275898277759552, 0.010417521931231022, 0.06309843808412552, 0.004144371021538973, 0.0023946696892380714, -0.004915249068289995, -0.0013440155889838934, 0.03424229845404625, 0.05111386626958847, -0.008750328794121742, 0.00844530202448368, -0.012203584425151348, -0.03650142252445221, -0.019473645836114883, 0.0617280974984169, -0.012222405523061752, 0.01534947007894516, -0.019837262108922005, -0.02249322645366192, -0.004619976039975882, 0.035422082990407944, 0.013673131354153156, -0.0002189034130424261, -0.0033051923383027315, -0.03748976066708565, -0.05678339675068855, -0.06978165358304977, -0.009488479234278202, 0.031176049262285233, 0.011567522771656513, -0.04091322049498558, -0.05379386991262436, 0.0045392136089503765, 0.029157306998968124, 0.012873631902039051, -0.02066436968743801, -0.03604302927851677, 0.023284928873181343, -0.024833302944898605, 0.0005957121029496193, -0.06111518666148186, -0.034875981509685516, -0.021248962730169296, -0.013783914037048817, 0.011410624720156193, 0.02457955665886402, -0.021005496382713318, 0.03746069595217705, 0.035007767379283905, -0.0006765964790247381, -0.03211600333452225, -0.009999943897128105, -0.026168756186962128, 0.04293280839920044, 0.0025959175545722246, -0.0864294096827507, -0.008782496675848961, -0.04134451970458031, 0.043219417333602905, 0.004153077024966478, 0.028638195246458054, -0.029951827600598335, 0.04791951924562454, 0.04950068145990372, 0.06235373392701149, 0.01911633461713791, -0.023172181099653244, -0.06637492030858994, 0.002251832513138652, -0.0635354220867157, -0.03664466738700867, 0.00787607952952385, 0.004674915689975023, 0.004688830580562353, 0.006673172116279602, 0.010595732368528843, 0.0048195538111031055, -0.017352132126688957, -0.03303426131606102, -0.00938279926776886, 0.013489733450114727, 0.05123099684715271, -0.013686398975551128, 0.02441616728901863, -0.018057456240057945, 0.05659240856766701, -0.0010711102513596416, -0.06143587455153465, -0.06742353737354279, 0.019516736268997192, 0.014492655172944069, -0.020749704912304878, -0.048421695828437805, 0.05439441651105881, -0.03365945443511009, 0.05909816175699234, 0.014024007134139538, -0.06513993442058563, 0.03537973016500473, 0.029536845162510872, -0.05895887687802315, 0.009459483437240124, -0.007721633650362492, 0.016319362446665764, -0.014800985343754292, 0.030289113521575928, 0.021955005824565887, 0.013886398635804653, 0.04736175015568733, 0.007036684546619654, -0.004130285698920488, -0.014934297651052475, 0.008155208081007004, -0.020324479788541794, 0.00683944346383214, -0.006206341553479433, -0.03625108301639557, -0.001122125657275319, -0.002356681739911437, -0.031801410019397736, 0.001690280856564641, 0.007639816030859947, 0.0010017778258770704, 0.0024156866129487753, 0.08265573531389236, -0.014989670366048813, 0.012345271185040474, 0.007861655205488205, -0.01861441135406494, 0.018219605088233948, 0.045130886137485504, 0.03757861629128456, 0.010669219307601452, -0.02881435863673687, 0.02113776095211506, 0.028147133067250252, 0.011363182216882706, 0.003152713878080249, 0.026464099064469337, -0.034705303609371185, -0.013587974943220615, 0.011539006605744362, 0.0029439327772706747, 0.05058170109987259, -0.026287537068128586, -0.003990793135017157, 0.009543366730213165, -0.01710638776421547, -0.046153925359249115, 0.04708695784211159, 0.010019971989095211, -0.01998850703239441, -0.022665590047836304, 0.05108644440770149, -0.024569105356931686, -0.015191269107162952, -0.023438651114702225, -0.007573028560727835, -0.041022296994924545, 0.009089100174605846, -0.01998598873615265, -0.05577963963150978, 0.0022672940976917744, 0.021087700501084328, -0.06147153303027153, -0.008069458417594433, -0.0024422486312687397, 0.008889802731573582, 0.02456771768629551, -0.0036328292917460203, -0.02977990172803402, 0.02978435717523098, 0.037189971655607224, 0.037146925926208496, -0.009104457683861256, 0.034205272793769836, -0.00651928735896945, 0.03546968102455139, 0.006041978020220995, 0.02557949163019657, 0.03689800202846527, 0.006330220960080624, 0.004388908855617046, 0.04166505113244057, -0.019837243482470512, -0.013299679383635521, -0.001401477144099772, 0.015477423556149006, -0.04884717985987663, 0.05128743126988411, -0.03392265737056732, -0.009122172370553017, 0.02172558754682541, -0.03895586356520653, 0.05190466716885567, 0.04777146875858307, 0.02272189036011696, 0.04179253429174423, -0.004868560470640659, 0.012659195810556412, 0.047971319407224655, -0.0008614893304184079, 0.028483569622039795, 0.007077638525515795, 0.011975116096436977, 0.0006308185984380543, 0.035350196063518524, -0.0403633639216423, -0.011004039086401463, 0.03170468285679817, -0.04890122264623642, -0.008505976758897305, 0.003742729313671589, -0.03596016764640808, 0.01246167253702879, 0.011019082739949226, -0.0692821741104126, -0.02541029267013073, 0.004282629583030939, 0.028968539088964462, -0.032606322318315506, 0.0169847272336483, 0.03043307736515999, -0.01476593129336834, -0.04728440195322037, -0.009557392448186874, 0.03623495250940323, 0.03904961794614792, 0.016873199492692947, 0.0011102888965979218, 0.04448363184928894, 0.020429683849215508, 0.0029507058206945658, -0.02354104444384575, 0.0033021466806530952, 0.04458516836166382, 0.015250281430780888, -0.031330641359090805, -0.03909865766763687, -0.01391792856156826, -0.016365721821784973, -0.05164838582277298, -0.023326369002461433, -0.019953250885009766, 0.040150731801986694, -0.035923704504966736, 0.024860823526978493, -0.02279576100409031, -0.020975979045033455, 0.06378673762083054, -0.016354477033019066, 0.06879575550556183, -0.011946206912398338, 0.005974484141916037, 0.02911299280822277, 0.010844177566468716, 0.00957636907696724, 0.05861746519804001, 0.01912006177008152, 0.0031280540861189365, 0.062098391354084015, -0.058212365955114365, 0.020354824140667915, -0.018306151032447815, 0.04888271540403366, -0.00911643821746111, -0.011057241819798946, -0.019537510350346565, 0.05121121555566788, 0.0033459814731031656, 0.011888401582837105, -0.002564155263826251, 0.021997341886162758, -0.036654844880104065, -0.05562116205692291, -0.008539866656064987, -0.062032751739025116, -0.015588754788041115, -0.01793128252029419, -0.014227109961211681, 0.0008161375299096107, -0.016644762828946114, -0.020865900442004204, -0.02413247898221016, -0.002533186227083206, 0.03104173019528389, -0.01350625604391098, 0.031126348301768303, 0.0210101418197155, -0.02717064879834652, -0.004091940354555845, -0.015280310064554214, 0.02873528189957142, -0.01034635677933693, -0.009344430640339851, 0.0036500387359410524, 0.0288381427526474, 0.018166081979870796, 0.02265321835875511, -0.017558762803673744, -0.010066674090921879, -0.012850592844188213, 0.010166189633309841, -0.013882690109312534, -0.018001578748226166, 0.019611334428191185, -0.020592069253325462, -0.03160053491592407, 0.009639838710427284, 0.0028670046012848616, -0.005322040989995003, 0.02631680853664875, -0.004457518924027681, -0.03692507743835449, -0.03717244043946266, -0.00033338923822157085, -0.009824683889746666, 0.009642476215958595, -0.026275528594851494, 0.031798724085092545, -0.01748512126505375, -0.05298885703086853, 0.0011671651154756546, 0.003939614165574312, -0.02757885865867138, -0.0027784842532128096, -0.05911467969417572, -0.05376867577433586, 0.0018335465574637055, 0.04646528139710426, 0.007664996664971113, 0.019929571077227592, -0.003318116068840027, -0.047279492020606995, 0.018141983076930046, 0.015379049815237522, 0.0007411267142742872, -0.030335742980241776, 0.08816401660442352, -0.030380021780729294, -0.023332105949521065, -0.02349647879600525, 0.0024348930455744267, -0.0017287543741986156, 0.004247609991580248, -0.010813846252858639, 0.006407523527741432, -0.013503197580575943, -0.04597043991088867, -0.004408601205796003, 0.02100077085196972, 0.07860405743122101, 0.00003686712807393633, 0.006734011694788933, 0.00019086744578089565, -0.0340937040746212, -0.03167499229311943, -0.05062416195869446, 0.06469423323869705, 0.014943385496735573, 0.06788305938243866, -0.004419732838869095, 0.01496712863445282, 0.031593888998031616, 0.0049174875020980835, -0.046715304255485535, -0.04416780546307564, 0.05904724821448326, -0.03757474571466446, -0.012934605590999126, -0.030435943976044655, 0.007832587696611881, 0.00933830626308918, 0.0018232830334454775, 0.0043037086725234985, 0.015475778840482235, 0.003905183868482709, -0.016724156215786934, -0.08856627345085144, -0.035752564668655396, 0.005043793469667435, 0.03697730228304863, -0.03567036986351013, 0.0069596790708601475, -0.002529403194785118, 0.014353104867041111, 0.004937186371535063, 0.018769770860671997, -0.006983473431318998, -0.016161682084202766, -0.025832222774624825, 0.00706867128610611, -0.03875706344842911, -0.011182567104697227, -0.02972533367574215, 0.05243028327822685, -0.026003841310739517, -0.053091637790203094, -0.009827996604144573, 0.011821475811302662, -0.03205665200948715, -0.04599904641509056, 0.0158205758780241, 0.013447823002934456, 0.0039502461440861225, 0.027097051963210106, -0.02145320735871792, -0.0572221614420414, 0.03966687247157097 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
# Porting fairseq wmt19 translation system to transformers
[ 0.03440055251121521, -0.011070167645812035, 0.11674471944570541, -0.0038040648214519024, 0.06199541687965393, -0.0017517046071588993, 0.009281550534069538, 0.049461185932159424, 0.054351989179849625, -0.017599815502762794, -0.00015799308312125504, 0.06724432855844498, 0.02346983551979065, 0.04234754666686058, -0.005181822460144758, 0.040726181119680405, -0.02341584302484989, -0.026482418179512024, -0.002856303472071886, -0.01814177818596363, -0.013556204736232758, -0.04070863872766495, 0.14789192378520966, 0.0032054418697953224, 0.02820459194481373, -0.023473376408219337, -0.004395110998302698, 0.04396825283765793, -0.09468499571084976, 0.031609512865543365, -0.026322489604353905, -0.00034333986695855856, -0.0233173631131649, -0.05742858722805977, -0.07893107831478119, 0.06261586397886276, -0.06488019227981567, 0.03837902098894119, -0.03300215303897858, -0.0763680711388588, -0.06648558378219604, 0.01190027967095375, 0.009773430414497852, 0.048677556216716766, -0.013994122855365276, 0.025830889120697975, -0.1753789782524109, 0.04565523937344551, -0.058547139167785645, -0.024212075397372246, 0.003449877956882119, 0.0312998965382576, 0.004581001121550798, 0.0641007125377655, 0.014776753261685371, 0.04339885339140892, -0.042051829397678375, -0.02093794196844101, -0.037716809660196304, -0.024960041046142578, 0.03236202150583267, 0.015658695250749588, -0.020938966423273087, 0.04148900881409645, -0.006582172587513924, -0.015979019924998283, -0.033485591411590576, -0.008513864129781723, -0.03323466330766678, -0.007406207732856274, -0.021335335448384285, 0.001414377591572702, -0.03338668867945671, -0.07893923670053482, 0.013055432587862015, -0.08151465654373169, -0.028235578909516335, 0.004813419189304113, 0.06083969399333, 0.1510290950536728, -0.028045281767845154, 0.003043885575607419, 0.0661451518535614, 0.020126787945628166, 0.031997933983802795, -0.0366799533367157, 0.06307440996170044, -0.03380398079752922, -0.04429011046886444, 0.048534199595451355, 0.02397596463561058, -0.1351025104522705, -0.10669542104005814, -0.002319611608982086, 0.03662053868174553, 0.011435486376285553, 0.06169663369655609, 0.061282772570848465, -0.020999351516366005, 0.03618721663951874, -0.032028183341026306, 0.015305559150874615, 0.15011274814605713, -0.010453169234097004, -0.00342944567091763, -0.036508720368146896, -0.009363051503896713, -0.14207302033901215, 0.02146746963262558, 0.01628214120864868, 0.018259909003973007, -0.00578069593757391, 0.025560205802321434, 0.023323213681578636, -0.0025631003081798553, 0.051312051713466644, 0.051457446068525314, -0.04508555307984352, 0.049119845032691956, 0.050805095583200455, 0.04269709810614586, 0.04723117873072624, 0.015052414499223232, 0.029973221942782402, 0.028491949662566185, 0.045862700790166855, 0.03079495020210743, 0.019091477617621422, -0.055530447512865067, -0.04912305623292923, 0.03826358541846275, -0.0010416104923933744, 0.014474048279225826, -0.0018120395252481103, -0.04499978944659233, -0.09295374155044556, 0.0453517846763134, -0.017860569059848785, -0.02386714518070221, -0.04561997205018997, 0.016044314950704575, 0.06555810570716858, 0.006585338152945042, 0.07924924045801163, -0.031698331236839294, 0.01141393557190895, -0.11708975583314896, 0.07415961474180222, 0.018138224259018898, 0.04330061003565788, 0.0017337731551378965, 0.0400882214307785, -0.0489378497004509, -0.09512070566415787, 0.008501257747411728, -0.0053171212784945965, 0.021330121904611588, -0.04213991388678551, -0.07992175966501236, -0.0661851018667221, -0.0635562315583229, 0.05291293188929558, -0.01902187615633011, -0.049725599586963654, -0.007498983293771744, -0.04719248041510582, -0.008536257781088352, -0.005613501649349928, 0.08132310956716537, -0.03190305829048157, 0.037979625165462494, -0.038524921983480453, 0.034039758145809174, -0.027740225195884705, -0.06951431185007095, -0.0011255608405917883, 0.046863384544849396, 0.07101427763700485, 0.010366474278271198, 0.008651327341794968, -0.038943976163864136, 0.019400805234909058, -0.02513723447918892, 0.021506106480956078, 0.06813783198595047, -0.016945118084549904, -0.011947853490710258, -0.011483409442007542, -0.0161663256585598, 0.019424568861722946, -0.0897558182477951, -0.05995102599263191, 0.04515611380338669, -0.0495283305644989, 0.002885749563574791, 0.022269880399107933, -0.004319347906857729, 0.0820135697722435, 0.03437386825680733, 0.098509281873703, 0.05116783082485199, -0.03045053221285343, 0.024340195581316948, -0.03907029330730438, -0.01844467595219612, 0.06520672142505646, 0.015143588185310364, 0.010550186038017273, 0.012872997671365738, 0.0308847539126873, 0.0049513643607497215, -0.09346497058868408, 0.031048350036144257, -0.04629690200090408, 0.011704170145094395, -0.056738678365945816, -0.05195939540863037, -0.00042638261220417917, 0.017237048596143723, -0.05630291998386383, 0.0950668603181839, 0.011761642061173916, -0.04955609142780304, 0.030560331419110298, 0.005899239331483841, 0.0417109876871109, 0.059123679995536804, 0.002689941553398967, 0.03510423004627228, -0.0684804916381836, -0.006226564757525921, 0.014887885190546513, 0.010435076430439949, 0.0510316826403141, -0.020139606669545174, -0.013703680597245693, 0.002398077165707946, -0.01691991649568081, 0.06965513527393341, -0.01942535676062107, 0.06068073958158493, 0.02005501091480255, 0.0012181684141978621, 0.04290156811475754, -0.02169601432979107, -0.0005136398249305785, 0.02087503671646118, 0.0009334163041785359, 0.03799973800778389, -0.02793322689831257, -0.0449969619512558, 0.03140091523528099, 0.014867476187646389, -0.08306257426738739, 0.06464686244726181, -0.0019631560426205397, -0.008185225538909435, -0.01688973605632782, 0.021169152110815048, 0.03368039429187775, 0.004075321834534407, 0.002048791851848364, 0.00036219650064595044, -0.05921513959765434, 0.014526482671499252, -0.0457717590034008, -0.025580700486898422, 0.049064140766859055, -0.0406666062772274, 0.014853370375931263, -0.023351719602942467, -0.03859115391969681, 0.016954442486166954, -0.02462032437324524, 0.02444528229534626, -0.013403368182480335, 0.023239731788635254, -0.013205085881054401, -0.019097525626420975, 0.010495994240045547, 0.005358248483389616, 0.014070830307900906, 0.019922172650694847, 0.01066078245639801, 0.007093103136867285, -0.0011077596573159099, 0.022381700575351715, -0.044507838785648346, -0.0041267890483140945, 0.008379055187106133, -0.018824443221092224, 0.008066565729677677, -0.01495664194226265, 0.006316306535154581, -0.004684684798121452, -0.012529398314654827, -0.00998164527118206, -0.013111850246787071, 0.004223894793540239, -0.0070849210023880005, -0.003511241404339671, 0.015152090229094028, -0.006436613388359547, 0.0213181059807539, -0.07112997025251389, -0.004910366144031286, -0.009096790105104446, -0.003995843697339296, -0.1135590672492981, -0.028844352811574936, -0.020727653056383133, 0.05327044427394867, -0.018841715529561043, -0.039696261286735535, 0.007765636313706636, -0.011108502745628357, -0.008618664927780628, 0.02385518327355385, 0.030471742153167725, 0.017621099948883057, 0.018157972022891045, 0.008342350833117962, -0.004034467041492462, -0.01218082569539547, -0.02016213722527027, 0.04416520521044731, 0.01777598448097706, -0.015065552666783333, -0.019719092175364494, 0.03162004053592682, -0.0008569795172661543, 0.0008830542792566121, 0.01757175847887993, 0.02429821714758873, 0.03066275455057621, 0.012129048816859722, -0.018944211304187775, -0.016315413638949394, -0.021229930222034454, 0.04419694095849991, 0.01907048188149929, 0.01445428840816021, 0.010187104344367981, -0.025343621149659157, 0.022004785016179085, 0.011043219827115536, 0.0014793532900512218, 0.003236850257962942, 0.009805978275835514, 0.01806323044002056, 0.0074806734919548035, -0.057596828788518906, -0.012766777537763119, -0.017606060951948166, -0.020753011107444763, 0.021542156115174294, 0.04200189933180809, -0.019747620448470116, -0.01912052370607853, -0.02469916269183159, -0.024014880880713463, 0.046151649206876755, 0.00019294919911772013, -0.03010663017630577, -0.0036901619751006365, 0.0144714480265975, 0.041572265326976776, -0.00016540865181013942, -0.03783586621284485, -0.002601932967081666, -0.032085563987493515, -0.025986159220337868, -0.06984756886959076, 0.11153335869312286, 0.007527581416070461, 0.043714940547943115, 0.033758003264665604, 0.017939720302820206, -0.012072423473000526, 0.010290798731148243, 0.012575927190482616, 0.008742847479879856, -0.007503722794353962, 0.07115912437438965, -0.023831933736801147, -0.017979437485337257, 0.0450538694858551, -0.0269640926271677, -0.02223854884505272, -0.008300230838358402, -0.004379180260002613, -0.009825547225773335, 0.004896453116089106, 0.005585846025496721, 0.009414592757821083, -0.011732518672943115, 0.005992196965962648, 0.06336523592472076, 0.008765295147895813, -0.05893958732485771, 0.005545282270759344, -0.03772059828042984, 0.006642052438110113, -0.021283002570271492, 0.023136265575885773, -0.017859740182757378, -0.03458667919039726, 0.015506168827414513, 0.007215003948658705, -0.052925363183021545, -0.011625011451542377, 0.0052776094526052475, -0.00156837806571275, 0.034313738346099854, -0.028322342783212662, -0.018017925322055817, -0.010974408127367496, 0.056033603847026825, 0.016851287335157394, -0.02149241417646408, -0.03185545653104782, -0.023637644946575165, -0.007661378476768732, -0.02565252035856247, 0.00005733195212087594, -0.06666960567235947, -0.030883638188242912, 0.0141043271869421, -0.010691051371395588, -0.0007382247713394463, 0.019001496955752373, -0.015095319598913193, -0.04201577976346016, -0.010740311816334724, 0.05490304157137871, 0.024994023144245148, -0.036101095378398895, 0.016249995678663254, -0.044416651129722595, -0.024385618045926094, 0.03669973090291023, 0.0011304120998829603, 0.05896810069680214, 0.019857455044984818, 0.02867533639073372, 0.015933869406580925, -0.008127273991703987, -0.018172310665249825, 0.00860572885721922, 0.007393487263470888, 0.027632905170321465, -0.033764276653528214, 0.054057154804468155, 0.013791315257549286, -0.02026769146323204, -0.00843884702771902, 0.0033095963299274445, 0.009537218138575554, 0.05155356600880623, -0.04555228352546692, -0.021651258692145348, 0.008079366758465767, 0.014161667786538601, -0.007933158427476883, 0.048356298357248306, -0.010114694014191628, 0.017467988654971123, 0.04088335856795311, 0.011905129998922348, -0.0005673070554621518, -0.0671895369887352, 0.025824014097452164, 0.009337597526609898, -0.016573786735534668, 0.03686170652508736, -0.048678893595933914, 0.006230268161743879, 0.016318896785378456, 0.0020907283760607243, -0.016307059675455093, 0.02784869633615017, -0.025766422972083092, -0.015480167232453823, 0.05457300320267677, -0.005777263082563877, 0.03188713267445564, 0.022141603752970695, -0.0423286110162735, 0.018658487126231194, 0.00882638804614544, 0.02738299034535885, 0.01626293919980526, -0.060059718787670135, 0.009149184450507164, 0.032469574362039566, 0.03580455109477043, -0.0018650342244654894, -0.0076781208626925945, 0.02094372920691967, -0.011281104758381844, -0.0361715666949749, -0.040218889713287354, -0.014313970692455769, -0.05333433300256729, 0.05615793168544769, -0.011832879856228828, -0.025503451004624367, 0.03210638463497162, 0.047775644809007645, 0.03903644159436226, 0.00984746403992176, -0.02074761874973774, 0.027355771511793137, -0.03349844738841057, -0.002300397027283907, -0.03006153367459774, 0.010295508429408073, -0.036537718027830124, 0.007400468923151493, 0.04314317926764488, -0.02309620939195156, -0.038775019347667694, -0.014795267023146152, -0.05747857317328453, -0.006898161023855209, 0.03274499624967575, 0.002601233310997486, 0.005739351734519005, 0.012351474724709988, 0.033591751009225845, -0.008250530809164047, 0.028159944340586662, 0.018232131376862526, 0.013471090234816074, -0.0016911319689825177, -0.012266142293810844, 0.026644406840205193, 0.031740158796310425, 0.008421107195317745, 0.010333595797419548, 0.0054390751756727695, 0.03881506994366646, 0.028851978480815887, 0.003375634551048279, -0.03844800218939781, 0.04085693135857582, -0.0007770303054712713, 0.014979291707277298, 0.04261459782719612, -0.06311576813459396, -0.0005048751481808722, -0.01607159525156021, -0.004593751393258572, 0.0112628024071455, 0.06290337443351746, 0.014464177191257477, -0.009611341170966625, -0.009463343769311905, -0.0048728445544838905, 0.015043321065604687, 0.007862268947064877, 0.005126551724970341, 0.014871137216687202, 0.02516547404229641, 0.029983382672071457, 0.008302884176373482, 0.02392854355275631, -0.014275465160608292, 0.02110460214316845, 0.0008692620904184878, -0.01874389685690403, 0.021393222734332085, -0.014489551074802876, 0.05661746859550476, -0.018851565197110176, 0.014633051119744778, 0.006237057037651539, 0.03165719658136368, 0.0026645208708941936, 0.005710209719836712, 0.031496562063694, 0.03863266482949257, 0.03319276124238968, -0.0665031149983406, 0.03864620253443718, 0.04096885398030281, -0.004506169818341732, 0.022296564653515816, 0.0029394098091870546, 0.02046380005776882, -0.008046326227486134, -0.02061360888183117, -0.024369992315769196, 0.04511205479502678, 0.039635565131902695, -0.013019450940191746, 0.012951482087373734, 0.006985973101109266, 0.01846788451075554, -0.05409466102719307, -0.0019181495299562812, -0.020198874175548553, -0.05213457718491554, 0.04179183393716812, 0.030803106725215912, -0.0009642276563681662, 0.003068322781473398, 0.008808447979390621, 0.051711734384298325, -0.003263734746724367, 0.009779607877135277, -0.04070437699556351, 0.01605629362165928, 0.03521861508488655, 0.015217212960124016, 0.02402004599571228, -0.0030961139127612114, -0.006138900760561228, 0.031385693699121475, 0.053929589688777924, -0.02127661556005478, 0.008213570341467857, -0.016925211995840073, -0.03307104483246803, -0.007265271153301001, -0.007495193742215633, -0.03909870609641075, 0.04060431197285652, 0.0162503644824028, -0.0711137056350708, -0.013481908477842808, 0.05268682911992073, 0.009058097377419472, -0.002675866475328803, 0.003176490543410182, -0.013204585760831833, -0.046091143041849136, -0.03791937977075577, -0.02922830358147621, 0.04730227217078209, -0.011361275799572468, 0.010205883532762527, -0.019462449476122856, 0.002925567328929901, 0.03492473065853119, 0.036063600331544876, 0.012898365966975689, 0.016419436782598495, -0.03484213352203369, -0.0073992908000946045, -0.03687448799610138, -0.04060786962509155, -0.0025053888093680143, 0.0029328458476811647, 0.026296133175492287, 0.003559189848601818, -0.025568459182977676, 0.03697231784462929, 0.01911250129342079, 0.010280841030180454, -0.05889518931508064, 0.013623695820569992, -0.04493023827672005, 0.005081568844616413, 0.016484644263982773, -0.03697223588824272, 0.029178909957408905, 0.02550417371094227, -0.026890283450484276, 0.0404885970056057, 0.030477294698357582, -0.04748132452368736, -0.028575021773576736, 0.03255103528499603, -0.02301410771906376, -0.01826423406600952, 0.0063840062357485294, -0.011113252490758896, -0.0029650891665369272, 0.011873920448124409, -0.010939166881144047, 0.034845832735300064, 0.006759237498044968, -0.005778432358056307, 0.006552624050527811, -0.03276794031262398, 0.013181979767978191, -0.036036454141139984, 0.0706866979598999, 0.022484682500362396, -0.003933081869035959, 0.026590583845973015, 0.01739693619310856, -0.01935189962387085, -0.0367913618683815, 0.01368201244622469, 0.0012597223976626992, 0.018251605331897736, -0.010491358116269112, -0.03963929042220116, -0.01837717369198799, -0.018372679129242897, -0.0019227860029786825, 0.04139880836009979, -0.012992125004529953, 0.01732805371284485, -0.04851725697517395, -0.030484715476632118, -0.01135341078042984, 0.04319688305258751, 0.0968765914440155, 0.03405607119202614, 0.023071343079209328, -0.019550269469618797, 0.015321707352995872, -0.017810126766562462, 0.0028980497736483812, 0.0167155172675848, 0.03367904946208, 0.02735638990998268, 0.0027181017212569714, 0.005861984100192785, 0.030286593362689018, -0.06278082728385925, -0.03400805592536926, -0.005458279512822628, 0.019152095541357994, -0.01006669458001852, -0.06229550018906593, 0.02365415170788765, 0.00699913315474987, -0.03159724920988083, 0.008651111274957657, -0.02867068350315094, 0.006326689384877682, -0.009044560603797436, -0.008961140178143978, -0.02091340348124504, 0.02303112857043743, -0.029989195987582207, -0.007770533207803965, -0.004064622335135937, 0.007492111995816231, 0.00610673613846302, -0.024507857859134674, -0.0199069082736969, 0.0036121385637670755, -0.011930620297789574, 0.016680316999554634, -0.02126362919807434, 0.018394850194454193, 0.02194228395819664, -0.0637921690940857, -0.09906893968582153, 0.04708701744675636, -0.022075045853853226, -0.026044128462672234, -0.0002084881125483662, -0.00961764995008707, -0.0341612808406353, -0.02611861191689968, 0.021379008889198303, 0.01311112754046917, 0.015482168644666672, -0.0012350238393992186, -0.001330914325080812, 0.03441135585308075, -0.010396627709269524 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Notes
[ 0.028027374297380447, 0.012788386084139347, 0.09174474328756332, -0.00026896054623648524, 0.13416025042533875, 0.033358555287122726, 0.023211823776364326, 0.05978379026055336, -0.028068432584404945, -0.11835234612226486, -0.021310407668352127, 0.046831827610731125, -0.009888211265206337, 0.0016095915343612432, 0.018662771210074425, 0.07244382798671722, 0.066151924431324, -0.0263504795730114, -0.009384449571371078, -0.01715809479355812, 0.004101545549929142, -0.029699595645070076, 0.0664641335606575, 0.031718481332063675, 0.032286472618579865, -0.004335189703851938, 0.013717475347220898, -0.005863669794052839, -0.08984801173210144, 0.05077337101101875, -0.042844656854867935, -0.005739353597164154, 0.07311423122882843, -0.0005958229885436594, -0.03221350163221359, -0.004922519903630018, -0.06466829031705856, 0.009226411581039429, -0.020423132926225662, -0.040169745683670044, 0.04600309953093529, -0.07435914874076843, -0.0019758292473852634, 0.07414864748716354, -0.03912263363599777, 0.017209909856319427, -0.29145655035972595, 0.07556803524494171, -0.034457653760910034, -0.004789621103554964, -0.05436119809746742, 0.011874338611960411, 0.027088208124041557, 0.010951920412480831, 0.030672280117869377, 0.008907669223845005, 0.028817716985940933, -0.01898159272968769, 0.01262355875223875, -0.06855694949626923, 0.08490382879972458, -0.01507400069385767, 0.015709681436419487, -0.000150521460454911, 0.06181953847408295, 0.033920448273420334, 0.009067240171134472, 0.03327794000506401, -0.059545088559389114, 0.006145469844341278, 0.02936876006424427, -0.020904848352074623, -0.03958069533109665, -0.018795525655150414, 0.05449267849326134, -0.07892889529466629, -0.03549135848879814, 0.014118255116045475, 0.04486808553338051, 0.0861123725771904, 0.01981176622211933, -0.015113990753889084, 0.10807331651449203, 0.1012880802154541, -0.003561008023098111, -0.05343317240476608, 0.04229070991277695, -0.01695353165268898, -0.009923957288265228, -0.009478324092924595, -0.04663188382983208, -0.07315772771835327, 0.03228450566530228, 0.05198412016034126, -0.010459830053150654, -0.050567686557769775, 0.054788947105407715, 0.00770063791424036, 0.03320717811584473, 0.02231976017355919, -0.017470810562372208, 0.026765335351228714, 0.013713446445763111, -0.03858673572540283, -0.027163619175553322, 0.0019153180764988065, -0.00568007118999958, -0.04996189847588539, -0.05148720368742943, 0.029328610748052597, -0.01973693259060383, 0.0346267968416214, 0.06531863659620285, -0.04731827974319458, -0.03843199089169502, 0.046648528426885605, 0.014058632776141167, -0.007323367986828089, 0.007954168133437634, 0.05293754115700722, 0.005824950989335775, 0.11550561338663101, 0.08428347110748291, 0.03401296213269234, 0.03509039804339409, -0.0015220120549201965, 0.04249268397688866, 0.06388711929321289, -0.08584223687648773, -0.03983795642852783, -0.008404634892940521, 0.006156184710562229, 0.060366641730070114, -0.016265224665403366, -0.04201693460345268, -0.053673941642045975, -0.009665736928582191, -0.0040297438390553, 0.010098802857100964, 0.004054030403494835, 0.008007710799574852, 0.04683854058384895, -0.002417359733954072, 0.06033114716410637, 0.030853375792503357, -0.021611623466014862, -0.042442694306373596, 0.019024113193154335, -0.002193951979279518, -0.015141826122999191, 0.029152795672416687, 0.05726143717765808, -0.014463723637163639, -0.054681673645973206, -0.02925339713692665, 0.05509050935506821, 0.03673464059829712, 0.03801092505455017, -0.06558158993721008, -0.021102434024214745, 0.039121922105550766, 0.029487773776054382, 0.02506723254919052, 0.017763465642929077, 0.05377906560897827, -0.023179015144705772, 0.019367827102541924, -0.003512087743729353, -0.01479597669094801, -0.07569324225187302, -0.043518099933862686, -0.022999130189418793, 0.0688234493136406, -0.03808455169200897, -0.07937484979629517, 0.03712157532572746, 0.05276715010404587, 0.021653512492775917, 0.01264543179422617, 0.016071636229753494, -0.03800220414996147, 0.015433178283274174, -0.015385515987873077, 0.03543112054467201, 0.008725413121283054, -0.025305241346359253, 0.03892927244305611, -0.009768516756594181, -0.01181675773113966, 0.03442078083753586, -0.1422044038772583, -0.05211444944143295, 0.08884018659591675, -0.010496243834495544, 0.003150366945192218, -0.0969359427690506, -0.02000274695456028, 0.10559118539094925, 0.0670652687549591, 0.04200677573680878, 0.045983389019966125, 0.07168760895729065, 0.07754197716712952, -0.009892617352306843, -0.05102993920445442, 0.05889228358864784, 0.05893780291080475, -0.02245783805847168, 0.02677067182958126, 0.004858769942075014, -0.03718813136219978, -0.0999060720205307, 0.047009099274873734, -0.06656325608491898, -0.007210082840174437, -0.024747241288423538, -0.00799567624926567, -0.00596257159486413, 0.028398707509040833, -0.06898493319749832, 0.0684167668223381, 0.02975194714963436, -0.022783907130360603, 0.08268192410469055, -0.04618532583117485, 0.08594461530447006, 0.06308696419000626, -0.001470291637815535, 0.04195426031947136, -0.07098577916622162, -0.04440317302942276, -0.017367495223879814, -0.010528868064284325, 0.09363950788974762, 0.03614779934287071, 0.059144943952560425, -0.014610948041081429, -0.02964402362704277, 0.04058201611042023, -0.04155087471008301, 0.030505001544952393, 0.009049219079315662, -0.017433838918805122, 0.04247814416885376, -0.03519199788570404, -0.06140262261033058, 0.02058393321931362, 0.0299519095569849, -0.05278688669204712, -0.016508188098669052, -0.043236780911684036, 0.10178875178098679, 0.007201254367828369, -0.022997373715043068, 0.05756084993481636, -0.041268203407526016, 0.018347013741731644, -0.026001878082752228, -0.02375183440744877, 0.010612135753035545, 0.02043149620294571, -0.013200086541473866, -0.006093727424740791, -0.07174508273601532, -0.011743836104869843, -0.01138259656727314, 0.01774013787508011, 0.016380878165364265, -0.0044607603922486305, 0.04752042144536972, -0.02795073203742504, -0.022596009075641632, 0.03521520271897316, 0.0068553294986486435, 0.001108567463234067, 0.007135647814720869, 0.044609688222408295, -0.012867992743849754, -0.02114848978817463, -0.009881576523184776, 0.0017800739733502269, -0.027578067034482956, 0.009078755974769592, 0.011899548582732677, 0.027564793825149536, -0.01602439396083355, 0.01515913661569357, 0.011732816696166992, -0.0012735130731016397, 0.0157226100564003, -0.006491032894700766, 0.042690958827733994, 0.00003679875590023585, -0.027137625962495804, 0.04414843022823334, -0.01758204959332943, -0.020440896973013878, 0.018106140196323395, -0.03729689493775368, -0.019417621195316315, 0.02541486546397209, 0.0021438661497086287, -0.009331370703876019, 0.01810758002102375, -0.060069601982831955, 0.028396930545568466, -0.009373851120471954, 0.006465313024818897, -0.16850441694259644, -0.049521300941705704, 0.02498788945376873, 0.026879269629716873, -0.010353604331612587, -0.027129055932164192, 0.03520500287413597, -0.032838668674230576, -0.030006982386112213, -0.03145195543766022, 0.032330043613910675, 0.015145980753004551, 0.02060956507921219, -0.014296546578407288, -0.013339458033442497, 0.006369435228407383, -0.02974766679108143, -0.007116521708667278, 0.0008085798472166061, -0.009517130441963673, -0.017821049317717552, 0.053006019443273544, -0.020489221438765526, -0.01725950837135315, -0.028333410620689392, 0.0483146496117115, 0.03188818693161011, 0.03854689002037048, -0.0026129046455025673, -0.01349685899913311, -0.02449735440313816, 0.049949951469898224, -0.01917663961648941, 0.029256463050842285, -0.0011814292520284653, 0.002860143780708313, 0.0006873132078908384, -0.023378120735287666, -0.00764196552336216, 0.037104323506355286, 0.02897697128355503, -0.0005634274566546082, 0.03311458230018616, 0.04211705923080444, -0.03353002667427063, 0.013627564534544945, -0.01357616763561964, -0.018770642578601837, 0.05402867868542671, -0.014758646488189697, -0.045778099447488785, 0.005194190889596939, -0.018110649660229683, 0.03640027716755867, -0.026277555152773857, -0.0036460421979427338, -0.03606610745191574, 0.01981138437986374, 0.059977948665618896, -0.027291331440210342, -0.009530854411423206, 0.005483729764819145, 0.00608135387301445, -0.0014850220177322626, -0.02554088830947876, 0.051310691982507706, -0.028250008821487427, 0.013603725470602512, -0.03657446429133415, 0.03532911837100983, 0.0011805081740021706, 0.009411250241100788, -0.015314623713493347, 0.013794837519526482, 0.002924335189163685, 0.018902014940977097, -0.0351729653775692, -0.022850453853607178, 0.06337237358093262, -0.019044511020183563, 0.016818605363368988, -0.012448074296116829, -0.01762840338051319, -0.004385217092931271, 0.0033861238043755293, 0.03843296691775322, 0.002894288394600153, 0.03006177395582199, 0.0014320943737402558, 0.026658078655600548, 0.02406025491654873, 0.005869191139936447, 0.006235314533114433, -0.0085463160648942, -0.005089967045933008, 0.02113642357289791, 0.042050108313560486, -0.0167009849101305, 0.007641145493835211, 0.016171952709555626, 0.019755065441131592, -0.012788955122232437, -0.010859081521630287, 0.014248128980398178, 0.0036288693081587553, 0.03275638818740845, -0.02773207053542137, -0.030804358422756195, -0.01186093408614397, 0.02644978277385235, 0.026577558368444443, -0.050855252891778946, 0.011514357291162014, -0.05000872164964676, -0.03262946009635925, -0.01301547884941101, -0.014317517168819904, -0.0470740906894207, -0.0554501935839653, 0.0043848357163369656, -0.02888338826596737, 0.019171401858329773, 0.02441238798201084, -0.03321622312068939, 0.0015607106033712626, 0.0113868722692132, -0.0011610519140958786, -0.010717786848545074, -0.024829452857375145, -0.008651715703308582, -0.015539384447038174, -0.0319814532995224, 0.056755345314741135, -0.01600501872599125, 0.03397494927048683, 0.003534469986334443, -0.017439788207411766, 0.05149801820516586, -0.0058936006389558315, -0.07307802885770798, 0.009641219861805439, -0.004608278162777424, 0.008861779235303402, -0.025885673239827156, 0.026290833950042725, -0.019660931080579758, -0.010774948634207249, -0.00466703437268734, -0.01563160866498947, 0.02032594196498394, 0.03171695023775101, -0.038904912769794464, -0.025564083829522133, -0.01223663054406643, -0.005858090240508318, 0.014215365052223206, 0.016178391873836517, -0.029686106368899345, -0.018052075058221817, 0.06653787940740585, -0.023278405889868736, -0.005533135961741209, -0.05518646165728569, 0.03373757377266884, -0.03539296239614487, -0.0013993683969601989, 0.004933407064527273, 0.0030631476547569036, 0.009269186295568943, -0.0024269521236419678, -0.010991686023771763, -0.014006425626575947, 0.03851368650794029, -0.007593222893774509, 0.0420132540166378, 0.019210467115044594, 0.011198561638593674, 0.015179199166595936, 0.038224559277296066, 0.029141563922166824, 0.006215250585228205, -0.007205341476947069, 0.031501058489084244, 0.009763669222593307, 0.00341614056378603, -0.00926070474088192, 0.0040023052133619785, -0.015639813616871834, -0.008626703172922134, 0.05921158194541931, -0.0430404394865036, -0.035575635731220245, -0.01765589974820614, -0.010545392520725727, 0.00975979957729578, 0.00659227604046464, 0.016742296516895294, -0.01245490275323391, -0.018434058874845505, 0.004951785318553448, 0.03381526842713356, 0.015397568233311176, -0.0026356554590165615, -0.013782311230897903, 0.0019335283432155848, 0.03302205353975296, 0.01638532057404518, -0.024645527824759483, 0.005355010740458965, -0.0036549055948853493, -0.012610683217644691, 0.014528224244713783, -0.04505337402224541, -0.03243381530046463, -0.014823732897639275, -0.025282688438892365, -0.050416603684425354, 0.0232000183314085, -0.001187894493341446, 0.012592781335115433, 0.005569768138229847, 0.017042305320501328, -0.01434705313295126, 0.049568820744752884, 0.05588562786579132, -0.002730144653469324, -0.010159437544643879, 0.025886904448270798, -0.011709798127412796, 0.04148486629128456, 0.022684426978230476, 0.013022590428590775, -0.015249808318912983, 0.01886470802128315, 0.043143052607774734, 0.02775205858051777, -0.07622271776199341, 0.024716200307011604, -0.009720002301037312, 0.014502671547234058, 0.009124545380473137, -0.007711887359619141, -0.010329747572541237, -0.02181454561650753, -0.01482444629073143, 0.025960130617022514, 0.049040600657463074, -0.03158658742904663, 0.01587156392633915, 0.016589371487498283, 0.0022743463050574064, -0.002666828688234091, -0.007030527573078871, -0.019998081028461456, -0.009217272512614727, 0.0028649824671447277, -0.0019190709572285414, -0.014905862510204315, 0.009373546577990055, -0.009009208530187607, 0.013791321776807308, 0.0019881674088537693, 0.025018634274601936, 0.005290319211781025, -0.022480493411421776, 0.029713062569499016, 0.002221229951828718, -0.008195974864065647, 0.033422015607357025, 0.028220398351550102, -0.009650658816099167, -0.0010379459708929062, 0.03032596781849861, -0.04715413972735405, 0.008176347240805626, -0.0003915909619536251, 0.03591887652873993, 0.024672824889421463, -0.0031833171378821135, -0.004605359397828579, 0.01855572871863842, 0.013313746079802513, 0.01798507757484913, -0.013755857944488525, -0.023502575233578682, 0.02503596991300583, 0.009622922167181969, 0.012581630609929562, 0.022315146401524544, 0.006217750255018473, 0.007954216562211514, -0.0007980235968716443, -0.01620384305715561, 0.020982662215828896, -0.02085813507437706, 0.02509632520377636, 0.0018853099318221211, -0.03719120845198631, 0.03307117894291878, -0.026857923716306686, 0.03527787700295448, 0.014765774831175804, -0.008966359309852123, 0.007365860510617495, -0.029292117804288864, 0.00744180753827095, 0.028463199734687805, -0.022591110318899155, -0.015123234130442142, -0.03238794952630997, 0.01511291228234768, 0.06488046795129776, -0.026612814515829086, -0.01677791215479374, 0.005101669114083052, -0.06994922459125519, 0.04246237874031067, -0.013275370933115482, -0.013108804821968079, -0.0043393406085669994, 0.052170004695653915, -0.024566087871789932, -0.00928876269608736, -0.02529044821858406, -0.03813647851347923, -0.06852932274341583, 0.014829730615019798, 0.0009386791498400271, -0.009285864420235157, -0.010136309079825878, 0.006184225901961327, 0.016310451552271843, -0.022682534530758858, -0.006580878980457783, -0.01576278917491436, 0.051014937460422516, 0.015648001804947853, 0.04122215509414673, 0.004974853713065386, -0.01750447228550911, -0.012711163610219955, -0.01766112819314003, 0.02316223457455635, 0.0074196308851242065, 0.01283235289156437, -0.0135579789057374, -0.013735629618167877, -0.009332827292382717, -0.033403366804122925, 0.018756233155727386, 0.027685293927788734, 0.009400869719684124, 0.010211012326180935, 0.036486800760030746, -0.019716361537575722, 0.006079173646867275, -0.024455292150378227, -0.0038720746524631977, 0.009777294471859932, -0.005265701096504927, -0.010013054125010967, 0.03048783913254738, 0.01788274012506008, -0.027432279661297798, -0.042732492089271545, 0.006645104847848415, -0.03614438325166702, -0.000038024376408429816, 0.00922723114490509, 0.013829555362462997, -0.024710366502404213, -0.04197824373841286, 0.019952546805143356, 0.018729370087385178, -0.02688930369913578, -0.018255257979035378, -0.0271319467574358, -0.01649099960923195, -0.010434690862894058, -0.030686067417263985, 0.07277613133192062, 0.024812964722514153, 0.019936958327889442, 0.013498703017830849, 0.038703713566064835, -0.006355222314596176, -0.03201553225517273, -0.002679432276636362, 0.021674426272511482, 0.027712229639291763, -0.018147172406315804, -0.014486518688499928, -0.02410205826163292, -0.05628323182463646, 0.009297280572354794, -0.009729651734232903, -0.0438765250146389, -0.0074978480115532875, -0.0018429390620440245, 0.00016586897254455835, -0.0523207001388073, 0.02129368670284748, 0.0442439541220665, -0.0017541574779897928, 0.005581275559961796, -0.010928483679890633, 0.003621840151026845, -0.024063939228653908, 0.006851782090961933, -0.008281738497316837, 0.02955031953752041, 0.029033521190285683, -0.0040604411624372005, -0.054945413023233414, 0.05111176520586014, -0.03680140897631645, -0.04821976274251938, -0.005397979170084, 0.0559336319565773, -0.006153871770948172, -0.026361409574747086, 0.0034680701792240143, 0.0160282664000988, 0.01758766733109951, 0.007210663519799709, 0.03883141651749611, -0.01898817904293537, -0.0022899266332387924, 0.012957865372300148, -0.0408673994243145, -0.003519822144880891, 0.008965256623923779, 0.01982722245156765, 0.04851245507597923, 0.03237730637192726, -0.03564130514860153, -0.012334581464529037, -0.06910089403390884, 0.010478338226675987, 0.0015751640312373638, -0.0051530576311051846, -0.006242085248231888, 0.029967596754431725, -0.05023040995001793, -0.024165937677025795, -0.05690677836537361, 0.03485836461186409, 0.017304591834545135, -0.01792672462761402, -0.00496267294511199, -0.018438218161463737, 0.009436938911676407, 0.010264971293509007, 0.03063715249300003, 0.0017643719911575317, 0.03932764381170273, 0.021622061729431152, -0.010978436097502708, 0.014361514709889889, 0.018384959548711777 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Tokenizer porting The first step was to port the encoder part of the tokenizer, where text is converted to ids. The decoder part won't be needed until the very end.
[ 0.03453950956463814, 0.019679537042975426, 0.050508927553892136, 0.006192856002599001, 0.051974695175886154, 0.04363332688808441, -0.018672360107302666, -0.005458842031657696, -0.011670242995023727, -0.02392537333071232, -0.029224669560790062, 0.02283618040382862, -0.014849012717604637, 0.01512124016880989, -0.008453208953142166, 0.057059478014707565, 0.028701862320303917, -0.07010214775800705, 0.054575365036726, -0.04324769601225853, 0.009355700574815273, -0.047806259244680405, 0.04121873900294304, 0.007096966728568077, -0.0007434330764226615, 0.018617382273077965, -0.0251357052475214, 0.013469582423567772, -0.055388886481523514, 0.014549652114510536, -0.021058550104498863, 0.0052434541285037994, 0.01655466854572296, -0.03369901329278946, -0.035737764090299606, 0.007894817739725113, -0.13513213396072388, 0.006360162049531937, -0.015218078158795834, 0.00362395029515028, -0.0910441130399704, -0.018460579216480255, -0.0074869305826723576, 0.0633130744099617, -0.001074454514309764, 0.018020588904619217, -0.29105523228645325, 0.08249954134225845, 0.02539340779185295, -0.04243241623044014, -0.03974474221467972, 0.0247415192425251, -0.03201962262392044, 0.055645450949668884, 0.024160198867321014, -0.012260613031685352, -0.03715323284268379, -0.1003190279006958, 0.025778576731681824, 0.013811539858579636, 0.08202890306711197, -0.040526799857616425, -0.002580241998657584, 0.016540486365556717, 0.058294035494327545, 0.050186268985271454, -0.04038234427571297, 0.03054148703813553, -0.007461889181286097, -0.013798361644148827, 0.0041685388423502445, -0.028738899156451225, -0.01371089369058609, -0.013035486452281475, 0.027192028239369392, -0.034035574644804, 0.03229451924562454, 0.02953934296965599, 0.03916260227560997, 0.09996050596237183, -0.015366122126579285, 0.026589643210172653, 0.09577756375074387, 0.007311954163014889, 0.08466466516256332, 0.009424951858818531, 0.029278399422764778, -0.017195038497447968, 0.020474905148148537, 0.028111735358834267, -0.04019167646765709, -0.15848585963249207, -0.021869033575057983, 0.03548477962613106, 0.03378035128116608, 0.0013276240788400173, 0.042603157460689545, 0.06943680346012115, 0.024668799713253975, 0.026502201333642006, 0.012667223811149597, -0.03160625696182251, 0.010770349763333797, -0.024419374763965607, -0.01919795572757721, -0.0016202663537114859, -0.012907685711979866, -0.09596429765224457, 0.010883125476539135, -0.01598288118839264, 0.03354548290371895, 0.013949211686849594, 0.033016182482242584, 0.044385988265275955, -0.06579028069972992, 0.06970347464084625, 0.0297681987285614, -0.0006538305315189064, 0.02259381115436554, 0.04250052571296692, 0.019260384142398834, 0.08013279736042023, 0.046758703887462616, -0.038866858929395676, -0.01901409588754177, 0.017521832138299942, 0.04669468104839325, 0.034444231539964676, -0.010978744365274906, -0.033257488161325455, -0.023755550384521484, 0.05517558753490448, 0.01690107211470604, 0.03419571742415428, -0.028388258069753647, -0.09194779396057129, -0.02967749536037445, -0.0381535179913044, -0.0010130174923688173, -0.05620233342051506, -0.03820427507162094, 0.052905358374118805, -0.03482355177402496, 0.04192548245191574, -0.010911540128290653, 0.029411092400550842, -0.06632153689861298, 0.03530506789684296, -0.010128621011972427, 0.023232879117131233, -0.048554182052612305, -0.014082099311053753, 0.03262154757976532, -0.036342233419418335, 0.024684643372893333, 0.061372339725494385, 0.03357870131731033, -0.04373208060860634, -0.10466727614402771, 0.039070650935173035, -0.015960192307829857, 0.03614043444395065, 0.015496212057769299, 0.007534682285040617, 0.019447289407253265, -0.05112139508128166, -0.0020004340913146734, 0.018584121018648148, 0.03902561217546463, -0.0377483032643795, 0.045905761420726776, -0.001384433708153665, 0.05101612210273743, -0.05375736951828003, 0.012033696286380291, 0.013186569325625896, 0.0212408397346735, 0.06574437022209167, -0.01178323570638895, -0.020330382511019707, -0.02372625283896923, 0.011530443094670773, -0.04480305686593056, 0.009404515847563744, -0.01422410923987627, -0.053051259368658066, 0.006068771705031395, -0.029956022277474403, -0.051974277943372726, -0.006055259611457586, -0.058743517845869064, -0.05451643466949463, 0.03442400321364403, 0.016373533755540848, 0.014814990572631359, -0.041884228587150574, -0.02968604862689972, 0.09781613200902939, -0.013414149172604084, 0.09012152999639511, 0.04707029461860657, 0.0070797051303088665, -0.00024112930987030268, -0.028967591002583504, -0.0016183359548449516, 0.002767932368442416, 0.04355078563094139, -0.05464428290724754, 0.04728149250149727, 0.024396656081080437, 0.027992676943540573, -0.08785733580589294, 0.018405884504318237, -0.0955452099442482, 0.0042548710480332375, 0.006361111532896757, -0.006592541467398405, 0.03652730956673622, -0.01910661719739437, -0.10364500433206558, 0.14461301267147064, -0.0933808907866478, 0.025779016315937042, -0.013846439309418201, -0.0187810268253088, 0.09888150542974472, 0.06189019978046417, 0.01373703870922327, 0.0686710849404335, -0.049853187054395676, -0.04981109872460365, -0.04022672399878502, 0.005896810442209244, -0.015154806897044182, -0.03371188044548035, 0.046331215649843216, -0.00009048868378158659, 0.0005078965332359076, 0.05765296146273613, -0.03751125931739807, 0.037962641566991806, -0.046552084386348724, -0.025081155821681023, -0.04094209149479866, -0.0036173746921122074, 0.05577850714325905, 0.09373848140239716, -0.06538114696741104, -0.05057429149746895, -0.02416284568607807, -0.040526069700717926, 0.04580249264836311, -0.026948265731334686, -0.07561149448156357, 0.124468594789505, 0.004537542816251516, -0.012900905683636665, -0.02557731233537197, 0.026440013200044632, 0.011777359060943127, 0.005072946194559336, -0.004841802641749382, -0.03158457949757576, -0.07586505264043808, -0.013843823224306107, -0.045669831335544586, -0.03670158609747887, 0.054761260747909546, -0.04276180639863014, 0.023140359669923782, -0.01254851371049881, -0.01865370012819767, 0.02352774888277054, 0.012907552532851696, 0.0161433108150959, 0.002964345971122384, 0.026176977902650833, -0.0462859682738781, -0.03346993774175644, -0.0019521923968568444, 0.032159458845853806, -0.055019788444042206, 0.019873183220624924, 0.030452223494648933, 0.00786601658910513, -0.011849438771605492, -0.0034341486170887947, 0.016759691759943962, -0.044616974890232086, 0.019576868042349815, 0.028541093692183495, -0.0029540539253503084, 0.002491297200322151, 0.03541957214474678, 0.05361749976873398, -0.0027345248963683844, -0.009559259749948978, 0.03010816127061844, -0.002562198555096984, 0.017058974131941795, -0.02688884548842907, 0.04518509283661842, -0.013820678927004337, -0.030942320823669434, -0.08701974153518677, 0.031198063865303993, 0.022891763597726822, 0.008109594695270061, -0.12026871740818024, -0.03213714435696602, 0.013831282034516335, 0.05025414749979973, -0.010655825026333332, -0.006547136232256889, 0.03945308178663254, -0.023905247449874878, 0.0016131040174514055, -0.011292025446891785, 0.04101553559303284, 0.020258596166968346, 0.021612783893942833, -0.01820368692278862, -0.041990045458078384, -0.017041681334376335, -0.010163799859583378, 0.01705343835055828, 0.01628657802939415, 0.003758511273190379, -0.026459962129592896, 0.03723008558154106, 0.006669620983302593, 0.018124157562851906, -0.018313126638531685, -0.0010159261291846633, 0.054404377937316895, 0.0011081299744546413, 0.02011546865105629, 0.022837553173303604, -0.00613949541002512, -0.007626014295965433, 0.016413377597928047, -0.013672319240868092, -0.032308634370565414, -0.009103305637836456, -0.010798655450344086, -0.0057447743602097034, -0.00847696140408516, 0.03738456964492798, 0.020200397819280624, 0.015392919071018696, 0.04914160072803497, -0.018519582226872444, 0.03781270608305931, -0.009006890468299389, 0.009726565331220627, 0.003700722474604845, 0.04865069314837456, -0.03082582913339138, 0.015711523592472076, -0.043745823204517365, 0.0050853765569627285, 0.033987585455179214, -0.00605980958789587, -0.02034754492342472, -0.026905842125415802, 0.05108718201518059, 0.028785118833184242, -0.016624072566628456, -0.043381091207265854, -0.009176316671073437, 0.002196050016209483, -0.031028514727950096, -0.07833302021026611, 0.08514166623353958, 0.015766525641083717, 0.032665301114320755, 0.02764965035021305, 0.0693131759762764, 0.001231307745911181, 0.007120280526578426, 0.009833892807364464, 0.01728038489818573, -0.011447600089013577, 0.032779376953840256, -0.0408305786550045, -0.025005482137203217, 0.020671389997005463, 0.012258561328053474, 0.005603444296866655, 0.033637817949056625, -0.003966412972658873, -0.006161412224173546, -0.0030400671530514956, 0.011379359290003777, 0.004793665371835232, 0.02793152816593647, -0.026663079857826233, 0.04363019019365311, 0.04575531929731369, -0.016966665163636208, -0.008912494406104088, 0.012893173843622208, -0.009021786041557789, 0.012764948420226574, 0.030439699068665504, -0.0041067106649279594, 0.017855791375041008, 0.021700352430343628, 0.03043045848608017, -0.036660876125097275, -0.024131372570991516, -0.026716776192188263, 0.0015792024787515402, 0.010508226230740547, -0.029502278193831444, -0.038705725222826004, 0.037032175809144974, -0.009432646445930004, 0.020767342299222946, -0.002640574937686324, -0.028418036177754402, -0.03827276453375816, 0.010339280590415001, -0.0066043720580637455, 0.003814423456788063, -0.034024324268102646, -0.00965467281639576, -0.005658954381942749, -0.036377254873514175, 0.017550857737660408, 0.02621564455330372, 0.016178613528609276, 0.01257470902055502, -0.02959548868238926, 0.051426734775304794, 0.012789285741746426, -0.004870150703936815, -0.011854036711156368, -0.018432078883051872, 0.015974223613739014, 0.005368185229599476, -0.00037296346272341907, 0.03846758231520653, -0.012363043613731861, -0.020591411739587784, 0.008240004070103168, 0.036219242960214615, -0.031177638098597527, -0.0403742715716362, -0.004768393002450466, 0.030649464577436447, -0.019859017804265022, 0.04538602754473686, 0.01766805909574032, -0.021580127999186516, 0.009994286112487316, 0.008297688327729702, 0.017199542373418808, 0.029163964092731476, -0.020577305927872658, -0.030700040981173515, 0.0042331828735768795, -0.0175166055560112, -0.02647627331316471, 0.01473425142467022, -0.025024469941854477, -0.017261946573853493, 0.030936768278479576, 0.0033736189361661673, -0.005324712023139, -0.03498058766126633, -0.004116916563361883, -0.0013384916819632053, -0.05348018929362297, -0.022848844528198242, -0.01578088104724884, -0.022019188851118088, 0.001770423841662705, -0.024474645033478737, 0.025208625942468643, 0.037994105368852615, -0.010174328461289406, 0.018445415422320366, 0.007554505951702595, -0.0040803332813084126, 0.03187263756990433, -0.02207402139902115, 0.009202881716191769, -0.014152894727885723, -0.0036697392351925373, 0.02160031348466873, -0.0031528782565146685, -0.021983632817864418, -0.003700566478073597, 0.06675516068935394, 0.027891503646969795, -0.0126569839194417, 0.042074352502822876, -0.011170463636517525, 0.003729513380676508, -0.008193925954401493, -0.029580960050225258, -0.014858654700219631, -0.03515658900141716, -0.006362034007906914, 0.0003741391992662102, -0.0619550421833992, 0.01609918102622032, 0.015348927117884159, 0.05163668468594551, 0.015428182668983936, -0.014964213594794273, 0.0011859586229547858, -0.016854943707585335, 0.02335568331182003, -0.03286851942539215, 0.020108886063098907, -0.01486459095031023, 0.03155231848359108, 0.0004983745166100562, -0.043704066425561905, -0.011507679708302021, 0.03867358714342117, -0.014179300516843796, -0.03536539897322655, 0.024705855175852776, 0.004351383075118065, 0.05032682046294212, 0.05322705954313278, 0.00013712084910366684, -0.04348136484622955, 0.06036682799458504, 0.04340411350131035, -0.013602547347545624, 0.003994293976575136, 0.03432491049170494, -0.015305513516068459, 0.023395247757434845, 0.020272890105843544, -0.04070083424448967, 0.013790315017104149, 0.0532207153737545, 0.0015220196219161153, -0.0023166583850979805, -0.021137520670890808, 0.032854028046131134, 0.01594260148704052, -0.0058513241820037365, 0.033612921833992004, -0.008807304315268993, -0.04285081848502159, -0.008022703230381012, -0.03032422810792923, -0.025070248171687126, 0.04733657091856003, 0.022902723401784897, 0.011791151948273182, 0.05505373328924179, 0.02795381098985672, -0.009585000574588776, 0.015226160176098347, -0.007098061498254538, 0.016306491568684578, 0.011541258543729782, 0.05687912926077843, -0.007090642116963863, -0.013302064500749111, -0.04839562624692917, -0.016300976276397705, -0.03249138593673706, 0.025582360103726387, 0.004169214051216841, -0.0006727658328600228, 0.026039347052574158, -0.023553840816020966, -0.031448837369680405, -0.017507091164588928, 0.015450441278517246, 0.02298819087445736, 0.014369047246873379, 0.0026062852703034878, -0.007232485339045525, 0.008311453275382519, -0.022595632821321487, 0.015058833174407482, 0.06602582335472107, -0.01387776155024767, 0.05904604494571686, 0.014428453519940376, 0.050406958907842636, 0.04295364022254944, 0.05047590658068657, 0.005131272133439779, 0.030071137472987175, 0.015524121932685375, -0.021801207214593887, -0.019487032666802406, -0.0037356780376285315, 0.02329116500914097, -0.0009528780356049538, -0.026147468015551567, 0.032787226140499115, -0.01900688000023365, -0.008726450614631176, 0.004015197511762381, 0.0031638287473469973, 0.016581853851675987, -0.022101081907749176, 0.0757206529378891, 0.038109391927719116, 0.0006555726868100464, -0.042255938053131104, 0.019832439720630646, 0.035072408616542816, 0.01582895591855049, 0.011558118276298046, 0.0183300469070673, -0.02038724720478058, 0.00511168921366334, 0.058046381920576096, 0.017915811389684677, 0.015638703480362892, -0.011293161660432816, 0.005437707062810659, 0.02934815175831318, 0.017041783779859543, -0.0306970477104187, 0.008264443837106228, 0.02866690792143345, -0.05309195816516876, 0.009573839604854584, 0.008380354382097721, -0.05633215233683586, -0.0030922500882297754, 0.012995880097150803, 0.0007403652998618782, -0.03834786266088486, -0.014806410297751427, 0.009034472517669201, 0.014475231058895588, -0.015101567842066288, -0.01603100076317787, -0.009488056413829327, 0.027055323123931885, 0.008463488891720772, 0.015988018363714218, -0.0052797538228333, -0.0160171240568161, -0.016059134155511856, 0.0021068218629807234, -0.013825895264744759, -0.027334993705153465, -0.00974173191934824, 0.01170935295522213, 0.020535126328468323, -0.008905414491891861, 0.01906718499958515, 0.012951385229825974, 0.021246012300252914, 0.04331402853131294, -0.028443310409784317, 0.012579423375427723, -0.02198803424835205, -0.03725782409310341, -0.0327189639210701, -0.04220786318182945, -0.005686203949153423, -0.002461373107507825, 0.007133482489734888, 0.025721747428178787, 0.045879773795604706, -0.05921950563788414, -0.05355299636721611, 0.011584516614675522, -0.034040406346321106, 0.01511511392891407, 0.015583308413624763, 0.008451094850897789, -0.014981244690716267, 0.0022862162441015244, 0.00582441920414567, -0.04862559586763382, -0.030993670225143433, 0.0038227022159844637, 0.018766816705465317, -0.03419775888323784, -0.05498787388205528, -0.052591826766729355, 0.05113110691308975, 0.009923978708684444, -0.0016121300868690014, 0.0533360056579113, 0.017252610996365547, -0.00849047303199768, -0.031603939831256866, 0.008372703567147255, -0.015006487257778645, -0.001734299585223198, -0.03173273429274559, -0.058057814836502075, -0.014003723859786987, -0.02731539122760296, 0.006399295758455992, 0.021170586347579956, -0.032246366143226624, 0.027244819328188896, -0.02395256608724594, -0.019058765843510628, -0.042501095682382584, 0.03960277512669563, 0.05194052308797836, -0.01483747735619545, 0.022262167185544968, 0.0373222790658474, -0.016028832644224167, -0.023808691650629044, 0.0032238971907645464, 0.056318022310733795, 0.03170601278543472, 0.005413880106061697, -0.01257420890033245, 0.01034847367554903, 0.042243584990501404, -0.04358634725213051, -0.011290434747934341, 0.05815424025058746, 0.002208615420386195, -0.05438480153679848, -0.026824235916137695, 0.038889992982149124, 0.022329866886138916, -0.0027418872341513634, -0.0037946386728435755, 0.039094969630241394, -0.00917442049831152, 0.011281171813607216, 0.026573028415441513, -0.044337205588817596, -0.022580020129680634, -0.000171190346009098, 0.02873636968433857, -0.00537835294380784, 0.022046303376555443, -0.025068502873182297, -0.01846708543598652, -0.051726244390010834, 0.005022123456001282, -0.0021094484254717827, 0.02149445191025734, -0.007574334740638733, -0.01863100752234459, 0.013220168650150299, -0.030959337949752808, -0.03431641682982445, 0.08210761845111847, 0.008698834106326103, -0.03141436353325844, -0.012489336542785168, -0.008582944050431252, -0.0011209859512746334, -0.0007665119483135641, 0.005702350754290819, -0.016104193404316902, 0.03556447476148605, 0.017800265923142433, -0.007975331507623196, 0.0039004303980618715, 0.010926091112196445 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Porting other models I next proceeded to port theen-deandde-enmodels. I was surprised to discover that these weren't built in the same way. Each of these had a merged dictionary, so for a moment I felt frustration, since I thought I'd now have to do another huge change to support that. But, I didn't need to make any changes, as the merged dictionary fit in without needing any changes. I just used 2 identical dictionaries - one as a source and a copy of it as a target. I wrote another script to test all ported models' basic functionality: [fsmt-test-all.py](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/scripts/fsmt-test-all.py).
[ -0.01308146957308054, -0.01567629724740982, 0.022680630907416344, 0.016926726326346397, 0.0710868313908577, 0.051052384078502655, 0.00907941535115242, 0.05388930067420006, -0.0038914107717573643, -0.03883674368262291, -0.06156086176633835, 0.04286625608801842, 0.000476200832054019, 0.045125577598810196, 0.04692874848842621, -0.02952658198773861, -0.041025977581739426, -0.05399556830525398, 0.0005311899003572762, -0.0028693468775600195, 0.020542817190289497, -0.11332831531763077, 0.05154239013791084, 0.013381577096879482, -0.019267193973064423, -0.05531885847449303, 0.04641472175717354, 0.09683440625667572, -0.027265630662441254, 0.05084914341568947, -0.0287290308624506, 0.010502982884645462, -0.042046986520290375, -0.07201925665140152, -0.060225799679756165, 0.012842090800404549, -0.06627508252859116, 0.007198097184300423, -0.0028843607287853956, -0.07799302041530609, 0.025223763659596443, -0.012693130411207676, -0.023222463205456734, 0.031829725950956345, 0.0014861212112009525, 0.05341358110308647, -0.12773822247982025, 0.045601893216371536, 0.022829430177807808, 0.01746169477701187, -0.037407759577035904, -0.032640013843774796, -0.02510320022702217, 0.0060844700783491135, 0.007501270156353712, 0.02020987495779991, -0.010086214169859886, -0.030577264726161957, 0.0004975695046596229, 0.01447528600692749, -0.008580119349062443, 0.010671119205653667, 0.0017161009600386024, 0.051346469670534134, 0.008476008661091328, 0.012598525732755661, -0.02787753939628601, 0.004517786670476198, -0.04868316650390625, -0.007778969593346119, -0.011754306964576244, -0.00527926767244935, -0.04546816274523735, -0.04874284565448761, 0.02836548537015915, -0.10005674511194229, -0.010963534004986286, 0.004253029823303223, 0.0844973549246788, 0.06214699521660805, 0.07136351615190506, 0.017549637705087662, 0.07937812805175781, 0.0007279693381860852, 0.03828037902712822, -0.024908076971769333, -0.002622466068714857, -0.035775020718574524, -0.007730872370302677, 0.05347767472267151, 0.0006439207354560494, -0.09424394369125366, -0.0937594398856163, 0.024885624647140503, 0.07151730358600616, 0.036648135632276535, -0.009132199920713902, 0.07318275421857834, 0.0329148955643177, 0.02933678776025772, -0.018324898555874825, 0.0036287610419094563, 0.02193361334502697, -0.06969001144170761, 0.021073780953884125, 0.0026171908248215914, 0.0025502347853034735, -0.1119193285703659, -0.03524455800652504, -0.007614469155669212, -0.059325456619262695, -0.0078425956889987, 0.0009458328713662922, 0.04309631884098053, 0.011309676803648472, 0.05402051657438278, -0.010661093518137932, -0.04652386158704758, 0.005965833552181721, -0.014422211796045303, 0.06421121209859848, 0.06891768425703049, 0.03822946175932884, -0.040224313735961914, 0.10374943166971207, 0.09668689966201782, 0.06760530173778534, 0.029901528730988503, -0.045419517904520035, -0.08923494070768356, 0.04604087397456169, 0.026363089680671692, 0.0679187923669815, 0.013811259530484676, -0.07744363695383072, -0.11233563721179962, -0.0006089634844101965, 0.030571557581424713, 0.002975999377667904, -0.01966182142496109, -0.029426779597997665, 0.04780273884534836, -0.03237788751721382, 0.05330490693449974, -0.017535744234919548, 0.023394370451569557, -0.060639407485723495, 0.1164439395070076, -0.0015805858420208097, 0.02812712825834751, -0.022800182923674583, 0.017893875017762184, -0.025163453072309494, -0.07756053656339645, 0.0014383741654455662, 0.07587922364473343, -0.0031818528659641743, -0.005694652441889048, -0.060933634638786316, 0.020661501213908195, -0.0023668191861361265, -0.0006751413457095623, -0.04303128272294998, -0.04233644902706146, 0.03850207105278969, -0.03655698895454407, -0.05066043883562088, 0.03778080269694328, 0.0543147474527359, 0.018882136791944504, 0.03529562056064606, -0.025954166427254677, 0.08267299085855484, 0.008177907206118107, -0.03704048693180084, 0.06315384060144424, 0.07661868631839752, 0.058029983192682266, 0.05083910748362541, 0.011329707689583302, -0.06312078982591629, 0.03357253968715668, -0.05353322625160217, 0.0022569294087588787, 0.009207356721162796, -0.005601186770945787, 0.050790607929229736, -0.0342690572142601, -0.017339831218123436, 0.005742233246564865, -0.0883961096405983, -0.03894050046801567, 0.09461523592472076, -0.010338823311030865, 0.008257945068180561, 0.026721078902482986, -0.037137653678655624, 0.05913683772087097, 0.049719247967004776, 0.09694584459066391, 0.09204146265983582, -0.03207428753376007, 0.006578770931810141, 0.009528097696602345, 0.04156714305281639, 0.08027935028076172, -0.012447861954569817, -0.05871451646089554, 0.023343762382864952, 0.019833935424685478, 0.05888404697179794, -0.10372407734394073, 0.019847441464662552, -0.07373036444187164, 0.0022846402134746313, -0.07631740719079971, -0.06529801338911057, -0.03425934538245201, -0.022829867899417877, -0.045357730239629745, 0.09065032005310059, 0.040724627673625946, -0.03259032219648361, -0.04980773106217384, 0.003942020237445831, 0.08644894510507584, 0.07777182012796402, 0.025196917355060577, 0.09608452767133713, -0.05516210198402405, 0.003902019001543522, 0.022734545171260834, 0.0033102533780038357, 0.05861558020114899, -0.011286583729088306, -0.011632210575044155, 0.010766245424747467, 0.014645248651504517, 0.00242282054387033, -0.06207757443189621, 0.014763734303414822, 0.03467034921050072, 0.02773928828537464, 0.007697912864387035, -0.013810005970299244, 0.060041092336177826, 0.029376348480582237, -0.03254326805472374, -0.028768083080649376, -0.024404233321547508, -0.057651083916425705, 0.046055085957050323, 0.027272677049040794, -0.06669186800718307, 0.08092040568590164, 0.0039202431216835976, 0.010561266914010048, -0.0007020992343313992, 0.013283835723996162, 0.045529965311288834, -0.01662980206310749, 0.03032114915549755, -0.04576614126563072, -0.05493197962641716, 0.00821499153971672, -0.035765085369348526, -0.005731627810746431, -0.009970567189157009, -0.01109666470438242, 0.015258594416081905, -0.013124428689479828, -0.05674907565116882, -0.01808541640639305, -0.011242613196372986, -0.003264358500018716, -0.007584712002426386, 0.0073404270224273205, -0.005526749417185783, -0.04389392212033272, -0.01749354600906372, -0.024800995364785194, -0.02861676923930645, -0.005632697604596615, -0.0019079250050708652, -0.0012370129115879536, 0.011921006254851818, 0.003780244616791606, -0.014172462746500969, -0.02332433871924877, 0.018221458420157433, 0.06955070793628693, 0.006525207776576281, -0.010840825736522675, 0.019010553136467934, -0.05293180048465729, 0.007219098042696714, 0.025869209319353104, -0.014660993590950966, -0.015285758301615715, 0.018616650253534317, -0.007886613719165325, 0.034467436373233795, -0.0068495734594762325, -0.008846158161759377, -0.055258892476558685, 0.006582735106348991, 0.029475830495357513, -0.0027291413862258196, -0.11064057052135468, -0.0064865415915846825, -0.021766502410173416, 0.06315317749977112, -0.011139637790620327, -0.03476914018392563, 0.027571270242333412, -0.03864600509405136, 0.02282470092177391, 0.02566857635974884, 0.03631437569856644, 0.010128162801265717, 0.016882959753274918, 0.029282405972480774, -0.03262142464518547, -0.010033173486590385, -0.028200529515743256, 0.01649574749171734, 0.06664261966943741, 0.004006718285381794, -0.02412435971200466, 0.013364874757826328, 0.000433723529567942, -0.03596339002251625, -0.009957736358046532, -0.009955753572285175, 0.06627580523490906, 0.00928434543311596, -0.020105300471186638, -0.04151887446641922, -0.006620550062507391, 0.03307660296559334, -0.02853114902973175, -0.008170138113200665, -0.04174167290329933, -0.030398359522223473, -0.03227134793996811, 0.03772050887346268, -0.027227433398365974, 0.017725298181176186, 0.02690301090478897, 0.0148994829505682, 0.026499714702367783, 0.015909306704998016, 0.005566742271184921, 0.0006622174405492842, 0.017518771812319756, 0.021735968068242073, 0.014915947802364826, -0.020092718303203583, -0.015344040468335152, -0.03188583627343178, 0.022147728130221367, 0.07947631180286407, -0.023013031110167503, 0.0028963014483451843, 0.0009291435708291829, 0.031466931104660034, 0.02080462872982025, 0.004447742830961943, -0.04653441905975342, 0.03313563019037247, -0.029619691893458366, -0.02578533999621868, -0.03931634873151779, 0.09909024089574814, -0.01169402152299881, 0.028571726754307747, 0.018836896866559982, -0.000053345000196713954, -0.02050400711596012, 0.0006493083783425391, -0.022014562040567398, 0.008300530724227428, -0.0077485437504947186, 0.032032523304224014, -0.041596878319978714, -0.05696240812540054, 0.038501713424921036, -0.01137627474963665, 0.026264404878020287, -0.03974322974681854, -0.005283028818666935, 0.002854696474969387, -0.021675245836377144, 0.021995576098561287, -0.014593231491744518, -0.009485047310590744, -0.0010470666456967592, 0.024739155545830727, 0.0347738079726696, -0.019504960626363754, -0.013612923212349415, -0.011353745125234127, -0.002349073300138116, -0.030943788588047028, -0.009316669777035713, -0.020886985585093498, 0.02867583930492401, -0.02029276452958584, 0.022235717624425888, -0.0347035713493824, -0.029361601918935776, 0.005571090150624514, 0.005152930971235037, 0.03897687792778015, -0.02692648395895958, -0.022507382556796074, -0.0006204466335475445, -0.015543400309979916, -0.002875223523005843, 0.0009680299554020166, -0.032775502651929855, -0.0183463953435421, 0.015706513077020645, 0.01840120553970337, -0.013894904404878616, -0.01828024908900261, -0.018392516300082207, 0.04279738664627075, -0.022581784054636955, -0.03606024757027626, 0.021916307508945465, -0.02544322982430458, -0.036017123609781265, -0.0135368462651968, 0.05309942737221718, 0.003100804751738906, -0.030482273548841476, 0.025191035121679306, -0.03681804612278938, -0.006111423019319773, 0.04786286875605583, 0.024582158774137497, 0.0426446869969368, 0.0380452498793602, 0.022467222064733505, 0.03077121637761593, 0.011052408255636692, -0.04962055757641792, -0.009261753410100937, -0.021779721602797508, 0.007319790776818991, -0.046203337609767914, 0.00167451286688447, -0.002567014889791608, 0.00865241140127182, 0.027433959767222404, -0.037361517548561096, 0.057030320167541504, 0.029796665534377098, -0.027850667014718056, 0.003945820964872837, -0.02024167776107788, -0.014545486308634281, 0.017458820715546608, 0.008635345846414566, -0.0036267577670514584, 0.0007424975046887994, 0.058506738394498825, 0.002488530008122325, -0.03097882866859436, -0.033146101981401443, -0.008729877881705761, -0.01530805230140686, 0.008309969678521156, 0.02645738795399666, -0.06445734947919846, -0.009103725664317608, 0.004652414470911026, -0.0672890767455101, -0.01887979544699192, 0.02720252051949501, -0.0510379783809185, 0.028360087424516678, 0.04594927281141281, 0.0012774465139955282, -0.0038140411488711834, -0.021047845482826233, -0.04469314590096474, -0.004234659019857645, 0.024675313383340836, -0.012440995313227177, -0.01611831970512867, -0.02528831735253334, 0.04209143668413162, 0.01903797872364521, 0.04981311410665512, 0.006367473863065243, -0.0009825312299653888, -0.022889895364642143, 0.017018483951687813, -0.0096922367811203, -0.0026032435707747936, 0.010381721891462803, -0.05332941189408302, 0.0009291815222240984, -0.008795599453151226, 0.001918346737511456, -0.00837446004152298, 0.03686518222093582, 0.034237634390592575, 0.021518023684620857, -0.06960292905569077, 0.03254597261548042, -0.027823442593216896, 0.014799287542700768, -0.03108416311442852, 0.014481640420854092, -0.049483101814985275, 0.04152240231633186, 0.024561475962400436, -0.01928316429257393, -0.01445087417960167, 0.029248390346765518, -0.046478018164634705, -0.018506715074181557, 0.007666892372071743, -0.02818240597844124, -0.0006110785761848092, 0.022097939625382423, -0.016658252105116844, -0.00684128375723958, 0.05807321518659592, -0.0022059630136936903, -0.05109443515539169, 0.00806400552392006, 0.011898518539965153, 0.02193782851099968, 0.002955850912258029, 0.018589500337839127, 0.0043325829319655895, 0.01916593685746193, 0.030918333679437637, 0.04208743944764137, 0.01138866413384676, -0.04215116798877716, 0.04976935684680939, 0.016302896663546562, -0.0365862175822258, 0.014239472337067127, -0.023726774379611015, -0.020953593775629997, 0.022303592413663864, -0.03426789864897728, 0.003472997108474374, 0.07021511346101761, -0.033702149987220764, 0.01929701678454876, -0.0016480220947414637, 0.0014536665985360742, 0.04201222211122513, 0.01673012040555477, 0.026370486244559288, 0.0016163524705916643, -0.02783297188580036, 0.0438421405851841, 0.02897302433848381, 0.02867485024034977, -0.033520400524139404, 0.03906017541885376, -0.0076225027441978455, -0.006494435016065836, 0.002360281301662326, -0.015944933518767357, -0.006654135417193174, -0.016321348026394844, -0.019662363454699516, -0.01749693602323532, -0.022713232785463333, 0.012636630795896053, 0.045165207237005234, 0.03894888237118721, 0.022727657109498978, -0.008816891349852085, -0.046499550342559814, 0.07905691117048264, 0.021699193865060806, 0.03711545839905739, 0.017292583361268044, 0.016541840508580208, 0.03572353720664978, 0.03408142551779747, -0.003033093875274062, 0.021397016942501068, 0.047132041305303574, 0.061301346868276596, -0.004469623323529959, -0.006092119496315718, 0.031601134687662125, -0.015844156965613365, -0.002788745565339923, -0.0607687309384346, 0.004144622944295406, -0.02863367460668087, 0.03497236967086792, -0.026827648282051086, -0.010801048949360847, -0.006802818272262812, -0.0339772067964077, 0.08114076405763626, 0.05713130906224251, 0.01574035920202732, 0.022414563223719597, 0.05291471630334854, 0.04408382251858711, -0.009132776409387589, 0.023141656070947647, -0.017200490459799767, -0.001413256861269474, 0.017267964780330658, 0.033179402351379395, -0.050509996712207794, 0.004174697678536177, -0.03746655210852623, 0.017342202365398407, -0.021439699456095695, -0.03898089379072189, -0.01770966500043869, 0.031003758311271667, 0.010934222489595413, -0.027271384373307228, -0.009444422088563442, 0.022686634212732315, -0.020343339070677757, -0.012215757742524147, -0.03134956210851669, -0.034678827971220016, -0.03271213173866272, -0.007583953440189362, -0.02123040333390236, -0.00920080952346325, -0.00030530805815942585, -0.0009733064798638225, -0.014508836902678013, 0.03211104869842529, 0.044547464698553085, 0.040019579231739044, 0.03972364589571953, 0.016986988484859467, -0.04963446408510208, 0.02260652370750904, -0.0010141253005713224, -0.016455527395009995, 0.002962695201858878, 0.007160127628594637, 0.016629109159111977, 0.015459257178008556, 0.02347283810377121, 0.044765010476112366, -0.009142735973000526, 0.011297362856566906, -0.0149696609005332, -0.002757379552349448, -0.04412674158811569, -0.023816987872123718, 0.0071081966161727905, -0.016130657866597176, -0.044300682842731476, -0.013089912012219429, 0.026320813223719597, 0.0518089197576046, 0.019397461786866188, -0.02702469751238823, -0.04045398160815239, 0.011125498451292515, -0.031985338777303696, 0.0050630755722522736, 0.01214481983333826, 0.005811653565615416, 0.026017265394330025, 0.005650589242577553, -0.020589860156178474, 0.001058802823536098, -0.013838368467986584, -0.025578252971172333, 0.01808970607817173, -0.014546631835401058, -0.013651788234710693, -0.02669120579957962, 0.05647888779640198, 0.029794689267873764, 0.025716589763760567, 0.053165849298238754, 0.035752054303884506, 0.008106997236609459, 0.009520995430648327, -0.024993211030960083, 0.04620962217450142, 0.03002029098570347, -0.014215817674994469, -0.04559948667883873, -0.009352781809866428, -0.000186634119017981, -0.006484052166342735, -0.009295610710978508, -0.04444948211312294, -0.016281740739941597, -0.02519713155925274, -0.04827219620347023, 0.0015030058566480875, 0.04732488468289375, 0.05646887794137001, 0.06005609408020973, -0.010581622831523418, -0.003533056005835533, -0.012002626433968544, 0.011783963069319725, -0.006322095170617104, 0.04503507539629936, 0.02312364988029003, -0.015152054838836193, -0.005704811308532953, 0.003675999818369746, 0.03135770186781883, -0.03460178151726723, -0.06930429488420486, -0.03383449837565422, 0.017513923346996307, -0.03620973974466324, -0.043374642729759216, 0.01876063644886017, 0.01896664872765541, -0.018956506624817848, -0.009131792932748795, 0.007635443937033415, 0.0035114821512252092, -0.008450960740447044, -0.0002533606020733714, -0.05430196225643158, -0.019789043813943863, -0.013056835159659386, -0.011841748841106892, -0.02264556474983692, 0.002057398436591029, -0.05160599201917648, 0.003257536329329014, -0.01528965774923563, 0.04225825518369675, 0.004980894271284342, -0.022962238639593124, -0.0025700151454657316, -0.006049046758562326, 0.03186047449707985, -0.04435834661126137, -0.08944995701313019, 0.03653806075453758, 0.023723168298602104, -0.04765741527080536, 0.019686304032802582, 0.012443958781659603, -0.009676976129412651, -0.010912380181252956, 0.013072813861072063, 0.02117658033967018, -0.008680173195898533, 0.03253250569105148, -0.013352755457162857, 0.002846915042027831, 0.042031172662973404 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Model description This is a ported version of [...] ``` As you can see we define the languages, tags, license, datasets, and metrics. There is a full guide for writing these at [Model sharing and uploading](https://huggingface.co/transformers/model_sharing.html#add-a-model-card). The rest is the markdown document describing the model and its nuances. You can also try out the models directly from the model pages thanks to the Inference widgets. For example for English-to-russian translation: https://huggingface.co/facebook/wmt19-en-ru?text=My+name+is+Diego+and+I+live+in+Moscow. ![break point group](./assets/07_porting_fsmt/inference_api.png)
[ -0.00238992553204298, 0.011317829601466656, 0.022538000717759132, -0.002835380146279931, 0.11898055672645569, 0.050757646560668945, 0.0177350752055645, 0.06206170469522476, -0.03708120062947273, -0.006985456217080355, -0.08777860552072525, 0.02727409638464451, 0.008484364487230778, 0.06945418566465378, 0.012336835265159607, 0.018673604354262352, 0.023416703566908836, 0.008512990549206734, -0.02159050479531288, -0.007311441469937563, -0.004458956886082888, -0.05520506575703621, 0.04464361444115639, -0.0374927744269371, -0.02084234356880188, -0.034467533230781555, 0.03190908953547478, 0.02780875936150551, -0.08056532591581345, 0.05133209750056267, -0.10478398948907852, 0.023346981033682823, -0.0210945513099432, -0.03978065773844719, 0.00902530737221241, 0.03423095494508743, -0.128257617354393, 0.02893262356519699, 0.0014280544128268957, -0.05368943139910698, 0.032858073711395264, -0.03337867930531502, -0.037809837609529495, 0.04246018826961517, 0.05950910225510597, -0.016368338838219643, -0.17642413079738617, 0.04637983441352844, -0.02268647402524948, -0.01575145497918129, -0.07101043313741684, 0.013864049687981606, -0.04044780507683754, -0.0043539442121982574, 0.007636163383722305, -0.02189125120639801, -0.04627855122089386, -0.08590823411941528, 0.057744886726140976, 0.002444506622850895, 0.0598488412797451, 0.012579994276165962, 0.0469464547932148, 0.0021884129382669926, 0.06199013069272041, 0.0212569497525692, -0.02700411155819893, -0.01986399106681347, 0.013004353269934654, -0.013694877736270428, -0.008455907925963402, -0.015122765675187111, 0.004861153662204742, -0.07786064594984055, 0.004613460507243872, -0.07490378618240356, -0.03759726509451866, 0.030909014865756035, 0.09491536766290665, 0.03831501677632332, -0.005135789979249239, 0.028607914224267006, 0.06302570551633835, 0.07656820118427277, -0.032292865216732025, -0.023480810225009918, 0.02784009277820587, -0.007022522389888763, -0.05756859481334686, 0.03787675127387047, 0.024038607254624367, -0.11933305114507675, -0.0029950563330203295, 0.04092475771903992, 0.04941479489207268, -0.04833028465509415, 0.023994456976652145, 0.02213490754365921, -0.06147289648652077, -0.005463880021125078, -0.017241958528757095, 0.0045283762738108635, 0.03906835615634918, -0.052121344953775406, -0.052540842443704605, 0.0003878022253047675, -0.016378242522478104, -0.07251569628715515, -0.02751724235713482, -0.02012074552476406, 0.023223556578159332, -0.05578838661313057, 0.0172076765447855, 0.06046517193317413, -0.06814895570278168, 0.020866667851805687, -0.052069660276174545, -0.050201863050460815, -0.0018950223457068205, 0.007328072562813759, 0.0402609184384346, 0.039884839206933975, 0.027066048234701157, 0.01609146222472191, 0.038922589272260666, 0.09055688977241516, 0.03380966559052467, 0.022311454638838768, 0.013495155610144138, -0.04414843022823334, 0.008249095641076565, -0.06884872168302536, 0.05219893157482147, 0.023639336228370667, -0.01609843038022518, -0.08928985893726349, 0.008307194337248802, -0.06687773764133453, 0.05505257844924927, 0.03863123059272766, 0.01757602021098137, 0.03941616415977478, -0.028031792491674423, 0.03462991490960121, 0.046264804899692535, -0.00396118825301528, -0.06759192049503326, 0.01078933384269476, -0.0352022610604763, 0.007631844840943813, -0.09985315054655075, 0.05025750398635864, 0.037499066442251205, 0.000592140422668308, 0.038131121546030045, 0.05776847153902054, 0.001746128429658711, -0.007178900763392448, -0.05164332687854767, -0.02059090882539749, -0.015618719160556793, 0.01932905800640583, -0.08584000915288925, 0.022887207567691803, 0.0217769593000412, -0.021632470190525055, -0.02865941822528839, 0.048158809542655945, 0.022009998559951782, -0.056504618376493454, 0.018076803535223007, -0.06255606561899185, 0.09306518733501434, -0.029940873384475708, -0.002461954951286316, 0.09093287587165833, 0.001775630982592702, -0.005554927047342062, -0.024661151692271233, 0.020347271114587784, -0.034759022295475006, 0.04129602387547493, -0.00043614639434963465, 0.009916594251990318, 0.05788302421569824, -0.06111803650856018, 0.0005464845453388989, -0.02446509338915348, -0.003936610650271177, -0.022720942273736, -0.058630600571632385, -0.0451405793428421, 0.0700332373380661, -0.01191366370767355, 0.02096308209002018, -0.08565893769264221, -0.03557312488555908, 0.11051488667726517, 0.04543556645512581, 0.09823635220527649, 0.02971961535513401, 0.037698835134506226, -0.021725252270698547, -0.003944059368222952, -0.01597345434129238, 0.056141771376132965, 0.06414177268743515, -0.044439975172281265, 0.016035471111536026, 0.004765558056533337, 0.021354524418711662, -0.07978050410747528, 0.053876277059316635, -0.07955525815486908, 0.01569942943751812, -0.0504140704870224, -0.037402041256427765, 0.022140957415103912, -0.007246044464409351, 0.04403051733970642, 0.19909141957759857, 0.017310017719864845, -0.056211844086647034, -0.036369021981954575, -0.029542667791247368, 0.015606313943862915, 0.07690718024969101, 0.08661016821861267, 0.07876259833574295, -0.06825065612792969, -0.04233354702591896, -0.019000891596078873, 0.03921268507838249, 0.039315178990364075, -0.004540752619504929, -0.04543629288673401, 0.007440503686666489, 0.03991243615746498, 0.011045025661587715, -0.04627702757716179, 0.013013423420488834, -0.012597443535923958, 0.03088819608092308, -0.040025535970926285, -0.0296480730175972, -0.030187977477908134, 0.09518738090991974, 0.023529691621661186, -0.06888934224843979, 0.009053255431354046, -0.010155526921153069, 0.02415509521961212, 0.04484110325574875, -0.031447622925043106, 0.03107161447405815, 0.05084511637687683, 0.0032832862343639135, 0.012056337669491768, -0.025315038859844208, 0.06049853935837746, -0.005151013378053904, 0.008428076282143593, -0.05480707809329033, -0.041275519877672195, -0.0068655419163405895, -0.04003439471125603, -0.01441497728228569, 0.019600993022322655, -0.0035713501274585724, 0.029489492997527122, 0.007829030975699425, -0.013331342488527298, -0.0121556855738163, -0.023418543860316277, 0.022960105910897255, 0.02476743422448635, 0.038216639310121536, -0.011781008914113045, -0.027455074712634087, -0.023668620735406876, -0.017917336896061897, -0.010913141071796417, 0.03169206157326698, 0.047072649002075195, 0.011768125928938389, -0.037475988268852234, 0.010122455656528473, -0.034197963774204254, -0.04130022972822189, -0.005966818891465664, 0.025743134319782257, 0.05543264001607895, -0.01192009262740612, -0.03223578631877899, -0.01218053326010704, 0.01392125803977251, 0.011930780485272408, 0.03189938887953758, -0.0025314162485301495, 0.0437813326716423, -0.017078617587685585, 0.002353736199438572, -0.03157045319676399, 0.004721124190837145, -0.021381240338087082, 0.05305434763431549, -0.01618393324315548, 0.035333894193172455, -0.11930031329393387, -0.02861941233277321, 0.00867319107055664, 0.015564157627522945, 0.0014466432621702552, -0.02707209624350071, 0.03130989149212837, 0.01774466596543789, -0.013145647011697292, 0.011900540441274643, -0.0036847388837486506, 0.008626330643892288, 0.03621692955493927, -0.018446220085024834, -0.012287437915802002, 0.009314880706369877, -0.010744641534984112, 0.014220040291547775, 0.02005765587091446, 0.021565614268183708, -0.03938279673457146, 0.009717575274407864, 0.009409730322659016, 0.0001874511071946472, -0.026411788538098335, 0.000017171787476399913, 0.05135743319988251, 0.0028243863489478827, 0.013039888814091682, -0.021357180550694466, -0.017482802271842957, -0.0025509854312986135, -0.032448045909404755, -0.014278613030910492, -0.044546861201524734, 0.014725519344210625, -0.017834050580859184, -0.013008409179747105, 0.02717760019004345, 0.02949007973074913, -0.0072333612479269505, 0.001021279487758875, 0.04144439473748207, -0.014003606513142586, 0.02186380885541439, 0.023216979578137398, -0.020413223654031754, 0.007360380608588457, 0.009428166784346104, -0.0026090415194630623, 0.005201905034482479, -0.02738359570503235, 0.03677716478705406, 0.05016111955046654, 0.009826663881540298, 0.0031078376341611147, 0.013965476304292679, 0.015593069605529308, -0.004179590381681919, 0.002838371554389596, -0.07169537246227264, 0.008475393056869507, -0.03170645236968994, -0.021168215200304985, -0.03580116108059883, 0.03821151703596115, 0.005305733066052198, 0.03346000239253044, -0.015415792353451252, 0.03545767441391945, -0.006753917317837477, 0.025981120765209198, -0.005821125581860542, 0.0181173924356699, -0.027996204793453217, -0.019359104335308075, -0.035612378269433975, -0.05763661488890648, 0.061189986765384674, 0.014545610174536705, -0.006145852152258158, -0.016473256051540375, -0.026253018528223038, -0.007602219935506582, 0.019754691049456596, -0.010389752686023712, 0.044929638504981995, 0.0015145224751904607, 0.0335322804749012, 0.015151256695389748, 0.002291433047503233, -0.028285324573516846, 0.02604948729276657, -0.026163402944803238, -0.01337460521608591, -0.011386286467313766, -0.0018248418346047401, -0.015429742634296417, -0.0038570526521652937, 0.028341762721538544, 0.027134764939546585, -0.04401906579732895, 0.012753315269947052, 0.005414080806076527, 0.006206653546541929, 0.02353093959391117, -0.041574832051992416, -0.06634995341300964, -0.0035522037651389837, 0.005138783250004053, 0.00717916851863265, -0.019509632140398026, -0.002195905428379774, -0.0352918766438961, 0.010916521772742271, 0.02462856099009514, -0.0168527252972126, -0.041836339980363846, -0.04892773553729057, 0.02252918668091297, -0.021758494898676872, -0.03654627129435539, 0.00489517068490386, -0.001434276346117258, 0.028594214469194412, 0.013088662177324295, 0.030706221237778664, 0.026339681819081306, -0.01220795139670372, -0.005555344745516777, -0.052800826728343964, -0.0017469489248469472, 0.043971914798021317, 0.011895629577338696, 0.02858428657054901, 0.05380624905228615, -0.01129928044974804, -0.014618654735386372, 0.032371435314416885, -0.0388697013258934, -0.014967304654419422, -0.0036275663878768682, 0.025095989927649498, -0.007792057003825903, 0.048241183161735535, 0.01539728045463562, -0.04700116068124771, 0.0015028087655082345, -0.01302667148411274, 0.0018821372650563717, 0.04557335004210472, 0.011488729156553745, -0.05325775966048241, 0.030621174722909927, 0.012530023232102394, 0.009209051728248596, -0.006316613871604204, 0.03811529651284218, -0.007946922443807125, 0.05186259746551514, -0.024794282391667366, 0.015021122992038727, -0.026387125253677368, 0.04172739386558533, 0.019933318719267845, 0.020988330245018005, 0.02161046862602234, -0.07983995229005814, -0.026486694812774658, 0.030236031860113144, -0.009512168355286121, 0.0013077310286462307, 0.03169155865907669, -0.05849037691950798, -0.006863072514533997, 0.0424266941845417, 0.009587319567799568, 0.04703298211097717, -0.005036997143179178, 0.04024641960859299, -0.012447446584701538, 0.021152429282665253, 0.017961379140615463, -0.020330416038632393, 0.01089930534362793, 0.045230381190776825, 0.07503748685121536, 0.0749916210770607, 0.02510737255215645, 0.014468703418970108, -0.00018453608208801597, 0.015058341436088085, -0.009670606814324856, -0.03618400916457176, 0.007840238511562347, -0.012324132956564426, 0.03567050024867058, -0.0043827807530760765, -0.00508336303755641, -0.011037698946893215, 0.05226297304034233, 0.07786954194307327, -0.024572202935814857, 0.0008745268569327891, 0.026417959481477737, 0.00444251811131835, -0.01068680640310049, -0.03339233621954918, 0.022708991542458534, -0.0344962552189827, -0.015844622626900673, -0.030651729553937912, -0.006418590433895588, -0.02234075590968132, 0.013543400913476944, -0.010285005904734135, -0.034996308386325836, 0.0021027137991040945, 0.011451106518507004, 0.06469906121492386, -0.008470405824482441, -0.008690383285284042, -0.024473555386066437, 0.023499999195337296, 0.02673429064452648, -0.022695958614349365, -0.00791562907397747, 0.014362698420882225, 0.020684288814663887, -0.0027259583584964275, 0.02225741185247898, 0.0005122800939716399, 0.019330870360136032, 0.0028225830756127834, 0.0027040550485253334, 0.024615241214632988, -0.06436681002378464, -0.006165480241179466, 0.0533817820250988, 0.011441913433372974, -0.004119959194213152, -0.012333077378571033, -0.0678367167711258, -0.009485888294875622, -0.05889490246772766, -0.008557101711630821, 0.06451785564422607, -0.008265833370387554, 0.014855590648949146, 0.020015237852931023, -0.0014333822764456272, 0.012704381719231606, 0.0008228429360315204, 0.005800770130008459, -0.0036517709959298372, 0.02252364158630371, -0.00042568045319058, 0.047465432435274124, -0.013056809082627296, -0.01587536185979843, 0.03310970962047577, -0.031243838369846344, 0.021653559058904648, 0.021159328520298004, -0.04347149655222893, 0.051541272550821304, -0.016495754942297935, -0.05811365321278572, 0.01329962071031332, 0.033351607620716095, -0.005881243851035833, 0.05611678212881088, -0.005985437426716089, 0.00962456502020359, -0.010332806967198849, -0.001021573320031166, 0.02656683139503002, 0.06287334859371185, -0.019851889461278915, 0.04843376204371452, 0.0275429617613554, 0.01936372183263302, 0.061602987349033356, 0.007620371878147125, 0.003072373103350401, 0.02136325277388096, 0.09021563082933426, 0.03725084662437439, 0.014198709279298782, 0.009989234618842602, -0.0014154036762192845, -0.010523569770157337, -0.030395345762372017, 0.006480691488832235, -0.05691477283835411, 0.007789747789502144, 0.051592983305454254, 0.011783797293901443, 0.02641451358795166, -0.02060997672379017, 0.06121428683400154, 0.03190424293279648, 0.029650691896677017, -0.032207176089286804, 0.01724657602608204, 0.018942752853035927, -0.0131040308624506, -0.023457450792193413, 0.037888407707214355, 0.001696095336228609, -0.02157609537243843, 0.07384033501148224, 0.011030769906938076, -0.010047958232462406, -0.02261364459991455, 0.005872230511158705, -0.0055268025025725365, -0.037377141416072845, -0.009850380942225456, 0.000989411724731326, 0.05665355175733566, -0.014928833581507206, -0.04034605622291565, 0.008094655349850655, -0.035094425082206726, -0.004946127999573946, -0.04098377004265785, 0.002879970008507371, -0.00013074514572508633, -0.006687431130558252, 0.013270556926727295, 0.03462063893675804, -0.0017205375479534268, 0.007021651603281498, -0.057624801993370056, -0.020012274384498596, -0.0013187747681513429, 0.01099338848143816, 0.003315705107524991, -0.02023366652429104, -0.03161604702472687, -0.021235967054963112, -0.010551459155976772, 0.020870255306363106, -0.00044970569433644414, -0.025097066536545753, 0.013760908506810665, 0.03893487900495529, 0.0038621530402451754, 0.056248798966407776, 0.033624906092882156, 0.02445019967854023, 0.003648508107289672, 0.00757288234308362, -0.02146845869719982, -0.02216915413737297, -0.023133639246225357, -0.030402330681681633, -0.018049633130431175, -0.027266835793852806, -0.005872227251529694, 0.016379477456212044, 0.028757045045495033, -0.03572859615087509, -0.0446288026869297, -0.017463456839323044, -0.03618868440389633, -0.02126293070614338, 0.036729201674461365, -0.023808790370821953, -0.009382195770740509, 0.010336505249142647, 0.01134774275124073, 0.025342777371406555, -0.024037403985857964, 0.004917552694678307, 0.03583870828151703, -0.008658025413751602, -0.014972303062677383, -0.006672959309071302, 0.0250089094042778, 0.030473917722702026, 0.039407435804605484, 0.03525029495358467, 0.03074578009545803, 0.015961764380335808, 0.006032493431121111, 0.021059226244688034, -0.01502977404743433, 0.016495026648044586, -0.07085400074720383, -0.03431158885359764, -0.02428455650806427, 0.0054431697353720665, 0.019478214904665947, 0.019587839022278786, -0.04734132066369057, -0.018740445375442505, -0.013251600787043571, -0.030109848827123642, -0.026680154725909233, 0.021140608936548233, 0.07628762722015381, 0.01954740472137928, 0.011651824228465557, 0.004414594266563654, -0.02768898382782936, 0.011213061399757862, -0.0187847763299942, -0.0014008425641804934, 0.03571591526269913, -0.01181210856884718, 0.007231838069856167, 0.00969291478395462, 0.044952671974897385, -0.023437459021806717, -0.06079380214214325, -0.0002746536338236183, 0.04760657623410225, -0.006653198506683111, -0.013236142694950104, -0.02259122021496296, 0.026897937059402466, -0.0008291651029139757, 0.034352857619524, 0.0026008025743067265, -0.03352253511548042, -0.021993333473801613, 0.0032451271545141935, -0.07177861034870148, -0.016620056703686714, -0.03153381869196892, 0.02053869515657425, 0.030651476234197617, -0.0004268634947948158, 0.00007825497596058995, -0.007395613007247448, 0.009819590486586094, 0.021719463169574738, -0.02559557929635048, -0.017073510214686394, -0.032175347208976746, -0.014737097546458244, 0.00392714561894536, -0.017025237902998924, -0.009200346656143665, -0.006056090351194143, 0.01707499660551548, -0.0487101711332798, -0.014250561594963074, 0.03063815087080002, -0.02664288878440857, -0.04276736453175545, -0.0037874949630349874, -0.02585681527853012, 0.01616005040705204, 0.04492790251970291, -0.023036928847432137, -0.022938231006264687, 0.015820074826478958 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Preparations For the sake of this article let's assume that we work under ~/porting, and therefore let's create this directory: mkdir ~/porting cd ~/porting We need to install a few things for this work: # install fairseq git clone https://github.com/pytorch/fairseq cd fairseq pip install -e . # install mosesdecoder under fairseq git clone https://github.com/moses-smt/mosesdecoder # install fastBPE under fairseq git clone [email protected]:glample/fastBPE.git cd fastBPE; g++ -std=c++11 -pthread -O3 fastBPE/main.cc -IfastBPE -o fast; cd - cd - # install transformers git clone https://github.com/huggingface/transformers/ pip install -e .[dev]
[ 0.03298308327794075, 0.0302555114030838, 0.045143067836761475, 0.02626561000943184, 0.13218626379966736, 0.040817491710186005, 0.0393391028046608, 0.04455020651221275, -0.0010936420876532793, -0.06526138633489609, -0.06637531518936157, 0.03408850356936455, -0.011394121684134007, 0.01375528797507286, 0.03356292098760605, -0.02134639583528042, 0.013895917683839798, -0.0599278062582016, -0.03776920586824417, 0.00148618477396667, -0.01641317829489708, -0.0312688834965229, 0.025729941204190254, 0.06737831234931946, -0.004515241831541061, -0.0668831318616867, 0.031245868653059006, 0.0075146970339119434, -0.053528737276792526, 0.029218856245279312, -0.04049944505095482, -0.021580226719379425, 0.0009759352542459965, -0.0487753301858902, 0.0033619373571127653, 0.01750773936510086, -0.014586091041564941, -0.028325233608484268, 0.08201675117015839, -0.07563690096139908, 0.0025080288760364056, -0.02221253328025341, -0.008888816460967064, 0.054413843899965286, -0.00029816137976013124, 0.009419712238013744, -0.12239765375852585, 0.05069715529680252, -0.020737988874316216, 0.010810566134750843, -0.0853639543056488, -0.029118310660123825, -0.011998492293059826, 0.017875460907816887, 0.036929838359355927, 0.007752781733870506, 0.004904691595584154, 0.01584797166287899, 0.0029516967479139566, -0.020201897248625755, 0.0286819227039814, -0.0032535898499190807, -0.04431997239589691, 0.027848951518535614, -0.030998988077044487, -0.015820570290088654, -0.05502978339791298, -0.028201010078191757, -0.05842011049389839, -0.07074011862277985, 0.03168807551264763, -0.009939302690327168, -0.036140646785497665, -0.04935668408870697, -0.012008060701191425, -0.025871988385915756, -0.006082854233682156, 0.06405404210090637, 0.044932037591934204, 0.09663528203964233, 0.009339693002402782, 0.04403499513864517, 0.015419574454426765, 0.04949706792831421, 0.030506400391459465, -0.02355584129691124, 0.014114420861005783, 0.02537999115884304, -0.05648357421159744, 0.04745272919535637, -0.02687215805053711, -0.06285649538040161, -0.0733674168586731, 0.06337305903434753, 0.02757398597896099, -0.011351670138537884, -0.017775243148207664, 0.010463103652000427, 0.030079854652285576, 0.07261969894170761, 0.021231967955827713, -0.011897231452167034, 0.003842113772407174, -0.0834917202591896, 0.03164210170507431, 0.03651674464344978, 0.020373839884996414, -0.059022147208452225, -0.04897129908204079, -0.0051633394323289394, 0.03357122838497162, 0.04169117659330368, 0.03870300203561783, 0.02697245590388775, -0.04142238572239876, 0.05588461086153984, 0.006664642598479986, -0.034910090267658234, -0.006841577123850584, 0.011935887858271599, 0.017178703099489212, 0.12884971499443054, 0.0018655573949217796, 0.011862220242619514, 0.04913339018821716, 0.05604685842990875, 0.01990947499871254, 0.040186814963817596, -0.01943601295351982, -0.1284821778535843, 0.02236376330256462, -0.036026451736688614, 0.05884690582752228, 0.0016281056450679898, -0.037173960357904434, -0.07212014496326447, 0.014549100771546364, 0.020640188828110695, -0.009951174259185791, -0.040733836591243744, 0.00048704908112995327, 0.09112472087144852, 0.019154323264956474, 0.046573419123888016, -0.014823641628026962, -0.017304152250289917, -0.10623539984226227, 0.08665070682764053, -0.05178743228316307, 0.001556139555759728, 0.023075761273503304, 0.0371268130838871, -0.030878769233822823, -0.06113015487790108, -0.00006355733057716861, 0.04066982492804527, -0.021240461617708206, 0.04078245162963867, -0.06251299381256104, -0.015121929347515106, -0.031075796112418175, -0.03989426791667938, -0.055377405136823654, -0.06761090457439423, -0.055181872099637985, -0.1003025695681572, -0.005804083775728941, 0.0015234153252094984, 0.027291767299175262, -0.00009643797238823026, 0.007781095337122679, -0.07873955368995667, 0.031699370592832565, -0.008239886723458767, 0.03267882019281387, 0.04935380443930626, 0.06954582035541534, 0.052476271986961365, 0.03254135325551033, -0.04429693520069122, -0.049445345997810364, 0.077971912920475, -0.02756788581609726, 0.046518296003341675, 0.002548248739913106, -0.08029057085514069, 0.008138997480273247, -0.04433950036764145, 0.004032219294458628, 0.031549759209156036, -0.13405339419841766, -0.03852830454707146, 0.1024363562464714, -0.015127046965062618, 0.042632170021533966, 0.006281296722590923, -0.07210981100797653, 0.07372508943080902, 0.09304409474134445, 0.0272564385086298, -0.0106536615639925, 0.005934668239206076, 0.07768344134092331, 0.010149160400032997, -0.002587059745565057, 0.11933533102273941, 0.003974216058850288, -0.027435550466179848, 0.02397317998111248, 0.007701671216636896, 0.06825536489486694, -0.0685068666934967, 0.014588971622288227, -0.05095114931464195, -0.00905011035501957, -0.0583551786839962, -0.05845166742801666, 0.008219453506171703, 0.02146824076771736, 0.01285657286643982, 0.08085352927446365, -0.02055337093770504, -0.006440166383981705, 0.04968920350074768, 0.018643664196133614, 0.07761668413877487, 0.09559129178524017, 0.0223067719489336, 0.09105052798986435, -0.02875334955751896, 0.014290094375610352, -0.0259533878415823, -0.03865152969956398, 0.13549186289310455, -0.004794197157025337, -0.022609131410717964, -0.017338234931230545, -0.020265081897377968, -0.023396216332912445, -0.032183121889829636, 0.05284798517823219, 0.04915596917271614, -0.014183389022946358, -0.034122757613658905, 0.017290782183408737, 0.008998111821711063, 0.00814641173928976, -0.04409199580550194, 0.006283903494477272, -0.014003980904817581, -0.05192548409104347, 0.0404355451464653, 0.03584436699748039, 0.01050413679331541, 0.07565014064311981, 0.03454327955842018, 0.026642197743058205, 0.015689324587583542, 0.007416642736643553, 0.03355593979358673, -0.040644388645887375, 0.02454547770321369, -0.051529720425605774, -0.047219447791576385, -0.040865208953619, -0.00854476448148489, -0.011877709999680519, 0.032625712454319, -0.03293237090110779, -0.01259990967810154, -0.01785002462565899, -0.009302761405706406, 0.00508235115557909, -0.007403182331472635, -0.002084507839754224, -0.0022746215108782053, 0.027958886697888374, -0.0011625196784734726, -0.018100833520293236, -0.028245821595191956, 0.009121870622038841, -0.03150540962815285, -0.04095837101340294, 0.012235352769494057, 0.0009363172575831413, 0.054011858999729156, 0.02168520726263523, -0.03872804343700409, -0.022645121440291405, 0.0005080814007669687, -0.016929136589169502, 0.0322301983833313, 0.011810525320470333, -0.009178114123642445, -0.023322902619838715, -0.04663044959306717, 0.022984089329838753, -0.016627782955765724, -0.008089405484497547, 0.057955432683229446, -0.02935897372663021, 0.012129133567214012, 0.022533126175403595, -0.003469600575044751, -0.027238890528678894, 0.012433325871825218, 0.0043536084704101086, -0.0007116770721040666, -0.10152216255664825, -0.019247841089963913, -0.03184584155678749, 0.06928394734859467, 0.0015527536161243916, -0.04155542328953743, 0.03939587622880936, -0.0437372587621212, -0.009120823815464973, -0.00240648677572608, 0.03613460808992386, 0.012971015647053719, 0.04276351258158684, -0.004126274026930332, -0.0006622018408961594, -0.02442888356745243, 0.004611811134964228, 0.04153580963611603, 0.010752186179161072, -0.01780904270708561, -0.027087043970823288, 0.026045510545372963, -0.023298002779483795, -0.0013130338629707694, -0.0060030086897313595, 0.011034943163394928, 0.04540238901972771, 0.08386453241109848, -0.013876904733479023, -0.03350456431508064, -0.02290482260286808, 0.05151650682091713, 0.03302956372499466, -0.002271248260512948, -0.04030664265155792, -0.04298114776611328, -0.02592673897743225, -0.006085661239922047, -0.019435662776231766, 0.03156144917011261, 0.019876981154084206, 0.002843344584107399, 0.028680924326181412, -0.035342004150152206, -0.024054205045104027, -0.02089310623705387, -0.023325622081756592, 0.015192640945315361, -0.0404374897480011, 0.03024071827530861, -0.03662016615271568, -0.031104708090424538, -0.03557267785072327, 0.07972913980484009, -0.009421510621905327, -0.014216632582247257, -0.0015232631703838706, 0.06598340719938278, 0.025708360597491264, -0.006596095860004425, -0.043902624398469925, 0.012868321500718594, -0.057951852679252625, -0.09347803890705109, 0.017675789073109627, 0.05744209140539169, -0.032275717705488205, 0.004473238717764616, -0.007996472530066967, 0.014315242879092693, -0.05264929682016373, 0.010365857742726803, -0.004398908466100693, 0.0019083707593381405, -0.021169817075133324, -0.0013149053556844592, -0.06330402195453644, -0.051224108785390854, 0.04179966077208519, 0.011818711645901203, 0.009204878471791744, -0.04981499910354614, 0.0016031095292419195, -0.019912799820303917, -0.0005290537956170738, 0.021884258836507797, -0.04440535604953766, -0.032820649445056915, 0.013134671375155449, 0.013300533406436443, 0.03197694942355156, -0.007100982591509819, -0.0016889338148757815, -0.010412011295557022, -0.033404018729925156, -0.07176508754491806, 0.050821974873542786, -0.0051632774993777275, -0.015197467990219593, 0.025548364967107773, 0.01977105252444744, -0.03803772106766701, -0.030539734289050102, -0.024434741586446762, 0.002093582646921277, 0.00788500253111124, -0.049102019518613815, 0.002799140987917781, -0.043387699872255325, 0.03326528146862984, -0.00573289580643177, -0.028764452785253525, -0.030378777533769608, -0.04158301278948784, 0.009832514449954033, 0.0063751512207090855, -0.022081883624196053, -0.00869190227240324, -0.02638096734881401, 0.04630092531442642, -0.003696125466376543, -0.015142328105866909, 0.032696302980184555, -0.028650375083088875, 0.013764620758593082, -0.008885794319212437, 0.03573540970683098, 0.023945366963744164, 0.00019339643768034875, 0.017171699553728104, -0.03513753414154053, 0.04301471263170242, 0.0692676305770874, 0.006529876030981541, 0.03481146693229675, -0.006390497088432312, 0.04230077192187309, 0.05061982572078705, 0.027549108490347862, -0.035029031336307526, 0.017650628462433815, 0.035462427884340286, 0.011746865697205067, -0.015480153262615204, 0.01914048008620739, 0.027055105194449425, 0.024663666263222694, 0.028505587950348854, -0.06112484261393547, 0.013612451031804085, 0.013041399419307709, -0.04028336703777313, -0.009391944855451584, 0.02253323420882225, -0.001981973648071289, 0.02416885644197464, -0.028774796053767204, -0.007896878756582737, -0.005955888889729977, 0.04371972382068634, -0.01452594343572855, -0.03584029898047447, -0.02769388258457184, 0.04096129909157753, -0.03681519255042076, 0.020695975050330162, 0.05655679479241371, -0.06347476691007614, -0.0341917984187603, -0.015098024159669876, -0.05248880386352539, 0.010290360078215599, -0.028653455898165703, -0.05423217639327049, 0.018588868901133537, 0.012085789814591408, 0.02300979569554329, -0.012080123648047447, 0.025382040068507195, -0.046971261501312256, 0.04266175255179405, -0.019066333770751953, 0.01461884193122387, -0.03736908361315727, -0.048917096108198166, 0.026005329564213753, 0.04062628746032715, -0.011083662509918213, 0.011940646916627884, 0.005640902556478977, -0.004521296359598637, -0.005431487690657377, 0.019742969423532486, -0.03468526899814606, -0.007857229560613632, -0.008196212351322174, 0.01232386939227581, -0.013743262737989426, 0.019273417070508003, -0.012439186684787273, 0.024465713649988174, 0.043251946568489075, -0.004020829685032368, -0.04168190062046051, 0.03501215949654579, 0.006077960599213839, -0.015365762636065483, 0.0023219098802655935, 0.009315761737525463, -0.01752566732466221, 0.013824129477143288, 0.051290202885866165, -0.0070009478367865086, -0.042718444019556046, -0.029084527865052223, -0.036313824355602264, -0.00934943463653326, 0.06632489711046219, -0.004680037964135408, 0.00827956572175026, -0.009768957272171974, -0.013787186704576015, 0.03203582018613815, 0.044963445514440536, -0.00773601932451129, -0.031441446393728256, -0.01137547753751278, 0.003832821501418948, -0.017719455063343048, 0.0018864375306293368, 0.029218576848506927, 0.02596779726445675, 0.006734771654009819, 0.01302937138825655, 0.0250548105686903, -0.010689632035791874, -0.015560123138129711, 0.06022404506802559, 0.03088892437517643, 0.04141164943575859, 0.0018508161883801222, -0.056716252118349075, -0.017407692968845367, -0.032953716814517975, -0.004253878723829985, -0.0030628337990492582, 0.03870701789855957, 0.020302630960941315, -0.0013841713080182672, 0.005628423299640417, 0.018668506294488907, -0.008566667325794697, 0.00705098919570446, -0.020705904811620712, 0.01626664400100708, 0.021597016602754593, 0.01923259347677231, 0.019770551472902298, -0.01412266492843628, -0.018849506974220276, 0.05475115776062012, -0.0357702374458313, -0.008862843737006187, -0.005687772296369076, -0.022292783483862877, -0.017353489995002747, -0.007079205475747585, -0.00709783099591732, -0.005320870317518711, -0.022928083315491676, -0.01789758913218975, 0.018130404874682426, 0.056667640805244446, 0.03583875298500061, -0.014785814099013805, -0.027541955932974815, 0.043400995433330536, -0.0072858575731515884, 0.027456631883978844, -0.014187703840434551, -0.020736880600452423, 0.031070489436388016, 0.038890525698661804, -0.02491319179534912, 0.0026859520003199577, 0.014927788637578487, 0.08787040412425995, 0.005562103819102049, 0.035652756690979004, 0.013362929224967957, 0.00852636806666851, -0.03795510157942772, -0.01172607485204935, 0.015859682112932205, -0.03320765867829323, 0.058248039335012436, 0.03430953994393349, -0.011050070635974407, -0.0027578549925237894, -0.06310255825519562, 0.08316879719495773, 0.01895138807594776, 0.038039688020944595, 0.017676200717687607, 0.005351192317903042, 0.004908684641122818, 0.00573279382660985, 0.017287492752075195, -0.020656311884522438, 0.04116789996623993, 0.010791887529194355, 0.045487500727176666, -0.0173086766153574, 0.01060773991048336, -0.01995854079723358, -0.02684699185192585, 0.023165127262473106, 0.01611253060400486, -0.013559206388890743, 0.004418987315148115, 0.006372843869030476, -0.05130491778254509, -0.03544660285115242, 0.043729547411203384, -0.017899030819535255, 0.00012582639465108514, -0.0002908334427047521, 0.009466023184359074, 0.00005029121530242264, 0.005933962296694517, -0.023350927978754044, -0.002375849289819598, 0.013302253559231758, -0.003984708338975906, -0.04286843165755272, 0.042311038821935654, 0.02067013457417488, 0.03050299361348152, -0.004394554998725653, -0.004573512822389603, -0.036979082971811295, -0.007262339349836111, -0.012137016281485558, 0.0064874375239014626, -0.0015346717555075884, -0.00460681039839983, 0.002681888174265623, 0.020421205088496208, -0.006572157610207796, 0.010513207875192165, 0.018444186076521873, 0.03311799466609955, -0.04997408017516136, 0.03161953389644623, -0.02303534746170044, -0.03947681561112404, 0.018227074295282364, 0.04287472367286682, 0.0022964542731642723, -0.003688558004796505, 0.025257933884859085, 0.02708074264228344, 0.017037712037563324, -0.01884561963379383, -0.04536636546254158, 0.014774927869439125, -0.004036907572299242, -0.07139083743095398, 0.02635985054075718, 0.01345537044107914, 0.028977852314710617, 0.04332166165113449, -0.007946731522679329, -0.019361350685358047, 0.028712701052427292, 0.016325244680047035, -0.01133718341588974, 0.02735048346221447, 0.00270350044593215, -0.004885147325694561, 0.07698476314544678, 0.018813814967870712, 0.007710637990385294, 0.049537502229213715, 0.028597503900527954, 0.001368242665193975, -0.005319798830896616, -0.013593357987701893, -0.02234777994453907, 0.020906716585159302, -0.000429496169090271, -0.040996015071868896, -0.008844618685543537, 0.020701220259070396, 0.008900354616343975, 0.005913620349019766, -0.034522321075201035, -0.009224269539117813, -0.0172666497528553, -0.0205218568444252, -0.010219858027994633, 0.032774120569229126, 0.061473723500967026, 0.04728355258703232, -0.007634574081748724, -0.0132276127114892, -0.0336897186934948, -0.012401863932609558, 0.0039654686115682125, 0.033567119389772415, 0.04327419400215149, 0.005812044721096754, -0.011205874383449554, -0.038418859243392944, -0.006760012358427048, -0.00022711306519340724, -0.02471240796148777, -0.028242748230695724, -0.028131430968642235, -0.005857462994754314, -0.02866765856742859, 0.058078963309526443, 0.014753501862287521, -0.002807009033858776, -0.0025037964805960655, 0.0017432933673262596, -0.019316673278808594, 0.031129060313105583, -0.0365724116563797, -0.023867402225732803, 0.040182437747716904, 0.009481091983616352, 0.03078237920999527, 0.03404918313026428, 0.001917248941026628, -0.0331617072224617, 0.02032129094004631, -0.09554391354322433, -0.049273714423179626, 0.02298610657453537, -0.016725139692425728, 0.001542355166748166, -0.007664044853299856, 0.025435052812099457, -0.04431033879518509, -0.046185411512851715, 0.011995767243206501, 0.02992064319550991, -0.026156160980463028, 0.04093094542622566, -0.003687984775751829, -0.03667517378926277, -0.012674976140260696, 0.014308502897620201, 0.015669332817196846, 0.014248041436076164, 0.03041371889412403, -0.008084454573690891, -0.013756939209997654, -0.0006400014390237629 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Model cards One other important thing is that it's not enough to port a model and make it available to others. One needs to provide information on how to use it, nuances about hyper-parameters, sources of datasets, evaluation metrics, etc. This is all done by creating model cards, which is just aREADME.mdfile, that starts with some metadata that is used by [the models website](https://huggingface.co/models), followed by all the useful information that can be shared. For example, let's take [thefacebook/wmt19-en-rumodel card](https://github.com/huggingface/transformers/tree/129fdae04033fe4adfe013b734deaec6ec34ae2e/model_cards/facebook/wmt19-en-ru/README.md). Here is its top: ``` --- language: - en - ru thumbnail: tags: - translation - wmt19 - facebook license: apache-2.0 datasets: - wmt19 metrics: - bleu --- # FSMT
[ 0.05026121437549591, -0.03114273212850094, 0.004420642275363207, 0.0026722957845777273, 0.07669349014759064, 0.008495500311255455, -0.007968621328473091, 0.021909771487116814, -0.05594218149781227, -0.024723580107092857, -0.07504740357398987, 0.030366137623786926, 0.0035241572186350822, 0.07488340139389038, -0.02404888905584812, -0.04067935794591904, -0.030786970630288124, 0.008743220940232277, -0.036844972521066666, -0.01239015907049179, 0.021568285301327705, -0.10157620906829834, 0.06360173970460892, -0.014474524185061455, -0.0002546976029407233, -0.05380820482969284, 0.04438319057226181, 0.010063158348202705, 0.004093820694833994, 0.011005132459104061, -0.11314845830202103, 0.013176272623240948, -0.05023016780614853, -0.0035491373855620623, -0.00016382572357542813, 0.0223151296377182, -0.10981550067663193, 0.04479802027344704, 0.0219735000282526, -0.04303192347288132, 0.047316838055849075, -0.013106418773531914, -0.07284591346979141, 0.048619069159030914, 0.027794912457466125, 0.001150103285908699, -0.1668994128704071, 0.06856413930654526, -0.0005819969228468835, 0.032741330564022064, -0.03175940364599228, 0.05650218203663826, -0.021182989701628685, 0.0569654144346714, 0.05337486416101456, -0.028109995648264885, -0.010034853592514992, -0.03712872788310051, 0.002339733298867941, 0.018805956467986107, 0.047146089375019073, 0.0069838594645261765, 0.05474657192826271, 0.08167140185832977, 0.0012588537065312266, -0.0034210975281894207, 0.016560742631554604, -0.02609330043196678, -0.02716650627553463, -0.050678547471761703, 0.017249824479222298, -0.046307146549224854, 0.006095628719776869, -0.07797682285308838, -0.010011978447437286, -0.045394331216812134, 0.0021652972791343927, 0.022892601788043976, 0.08234263211488724, 0.03434659168124199, -0.0012094092089682817, -0.01201771292835474, 0.05751379206776619, 0.06478230655193329, 0.013199386186897755, -0.017321480438113213, 0.03173372894525528, -0.007053823210299015, -0.05978447571396828, 0.051008615642786026, -0.017961105331778526, -0.07405760139226913, -0.005102468654513359, -0.001098671113140881, 0.0707843154668808, -0.03772604838013649, -0.011464542709290981, 0.0387859009206295, -0.026023471727967262, 0.026618381962180138, -0.013189275749027729, -0.004518616478890181, 0.004281264264136553, -0.049393367022275925, -0.03173550218343735, 0.013201473280787468, 0.005897835362702608, -0.07648920267820358, -0.02057718299329281, 0.01268682535737753, -0.021730180829763412, -0.05843178927898407, 0.015158058144152164, 0.030365336686372757, -0.02507166564464569, 0.02874523028731346, 0.011409558355808258, -0.027150161564350128, 0.0055709281004965305, 0.04561303183436394, 0.023402705788612366, 0.09833937883377075, -0.0024932899978011847, 0.028545722365379333, 0.03794759139418602, 0.07195556163787842, 0.059448156505823135, 0.02302076667547226, -0.03887198492884636, -0.033929649740457535, 0.02971811778843403, -0.03497607633471489, 0.02737646922469139, 0.04453876242041588, -0.013686231337487698, -0.0972772166132927, -0.011703349649906158, -0.06312203407287598, 0.06563781201839447, 0.03649934381246567, -0.01855156198143959, 0.04142891243100166, -0.004997107665985823, -0.022260719910264015, 0.0158857274800539, -0.02133106254041195, -0.09020571410655975, 0.032100923359394073, -0.009910373017191887, 0.0073235840536653996, -0.034461475908756256, 0.060123052448034286, 0.042861901223659515, -0.034575365483760834, 0.024935487657785416, 0.09335727244615555, -0.01986285112798214, 0.00046656676568090916, -0.08438140898942947, 0.009804018773138523, -0.04705028235912323, -0.002968431683257222, -0.0728139728307724, 0.006838322151452303, 0.016631165519356728, 0.03232351690530777, -0.010049393400549889, 0.043781157582998276, 0.021562259644269943, -0.0069981231354177, 0.017269564792513847, -0.08761047571897507, 0.0707859992980957, -0.049721021205186844, 0.010115171782672405, 0.10895616561174393, 0.04651953652501106, 0.0026995164807885885, 0.022860966622829437, 0.028037179261446, -0.04542236030101776, 0.028372816741466522, -0.02426563948392868, 0.03897516429424286, 0.03570866212248802, -0.07816313952207565, -0.02101796865463257, -0.035990070551633835, -0.05666164308786392, -0.01548590138554573, -0.08288461714982986, -0.027047455310821533, 0.052998464554548264, -0.018331849947571754, 0.012064998038113117, -0.02290150709450245, -0.03215572610497475, 0.13195782899856567, 0.056507136672735214, 0.0856221541762352, 0.0539577417075634, 0.04185226559638977, -0.009294536896049976, 0.0012128687230870128, -0.02023615874350071, 0.014266746118664742, 0.036575742065906525, -0.044080398976802826, 0.0528985969722271, 0.015934035181999207, 0.005739096086472273, -0.1548151671886444, 0.043262362480163574, -0.07233565300703049, -0.006600028835237026, -0.055510398000478745, 0.0016327634220942855, 0.0023472921457141638, -0.013992071151733398, -0.02796884812414646, 0.18416646122932434, -0.015536821447312832, -0.034707631915807724, -0.017758585512638092, -0.016211193054914474, 0.08388274163007736, 0.0932251587510109, 0.10832808911800385, 0.1257680058479309, -0.07622691243886948, -0.020810116082429886, -0.0234534814953804, -0.010189495980739594, 0.02733512967824936, 0.04504217952489853, -0.03532838076353073, 0.06348919123411179, -0.04230945184826851, -0.0009545356151647866, -0.03668677434325218, -0.014884666539728642, -0.03023342229425907, 0.03294955939054489, -0.03612520545721054, 0.021093009039759636, -0.03144046664237976, 0.056184619665145874, 0.0017584944143891335, -0.06602664291858673, -0.0022721015848219395, -0.0903967022895813, 0.052121490240097046, 0.010058369487524033, -0.0379694327712059, 0.019673151895403862, 0.01567782089114189, 0.02371501736342907, -0.016615498811006546, -0.02158496528863907, 0.058610886335372925, 0.00003970210673287511, -0.0004078396304976195, -0.05325247719883919, -0.05629526451230049, -0.023257222026586533, -0.03726641833782196, 0.016800323501229286, 0.022356988862156868, 0.007618514820933342, 0.03188663348555565, 0.02074216865003109, -0.014545753598213196, 0.025530405342578888, 0.0020614638924598694, 0.0038540209643542767, 0.03590196371078491, 0.02192959561944008, -0.023287450894713402, -0.030895117670297623, -0.01147038210183382, -0.014252206310629845, -0.03083883784711361, 0.03190823644399643, 0.03432135283946991, 0.026137663051486015, 0.008708625100553036, -0.01803923025727272, -0.006719846278429031, -0.048803698271512985, 0.023073650896549225, 0.03966536745429039, 0.02941703423857689, -0.030848318710923195, -0.012267662212252617, 0.017544981092214584, -0.016494544222950935, 0.029076432809233665, -0.02247711457312107, -0.03662664070725441, 0.03050278127193451, -0.029429171234369278, 0.0033763174433261156, 0.02673068456351757, -0.01611155830323696, -0.01925826072692871, 0.03909336403012276, -0.009644336998462677, 0.01188158243894577, -0.11428356915712357, -0.02100549452006817, -0.02671404555439949, 0.027213839814066887, -0.029781237244606018, -0.010041624307632446, 0.043733514845371246, -0.010817856527864933, -0.016455160453915596, -0.004862683825194836, 0.014100191183388233, 0.02114928513765335, 0.029348652809858322, 0.0005309368716552854, -0.033654551953077316, 0.014350690878927708, -0.003959084860980511, -0.0057674734853208065, 0.04328938201069832, -0.012733276933431625, -0.02511279098689556, 0.018503664061427116, -0.01590312458574772, -0.004371441435068846, -0.023785997182130814, -0.00609935587272048, 0.04380274564027786, -0.0007388108060695231, -0.0005229194648563862, -0.02046939544379711, 0.026311147958040237, 0.0005674640997312963, -0.029390746727585793, -0.019662536680698395, -0.041195616126060486, -0.0037855550181120634, -0.0043120128102600574, 0.02070544846355915, -0.024130677804350853, 0.02736206352710724, 0.01750737987458706, -0.008759832940995693, 0.02058442495763302, 0.006128756329417229, 0.004645319189876318, 0.0018380223773419857, 0.00002475256951584015, 0.010768787004053593, 0.027110062539577484, -0.01834164746105671, 0.005458181723952293, -0.028451241552829742, 0.024485712870955467, 0.06083408743143082, -0.0072969370521605015, 0.020944997668266296, 0.014143831096589565, 0.041722334921360016, -0.042960356920957565, -0.035460785031318665, -0.0819876566529274, -0.014258104376494884, -0.03335888683795929, -0.017999179661273956, -0.030964158475399017, 0.06517557799816132, 0.010001257993280888, 0.03242390602827072, -0.012567102909088135, 0.05009618028998375, -0.001395534141920507, 0.035682667046785355, -0.0039538005366921425, 0.008184939622879028, 0.0029524497222155333, 0.005887780804187059, -0.03407112509012222, -0.045403771102428436, 0.06065826490521431, 0.03654308244585991, -0.027422834187746048, -0.030176328495144844, -0.017845245078206062, -0.015180457383394241, 0.004088184330612421, -0.013644888065755367, 0.02758779190480709, 0.029375730082392693, 0.008489251136779785, 0.04291494935750961, 0.00554674444720149, -0.0231174323707819, 0.0512179359793663, -0.015667641535401344, 0.013989631086587906, 0.00462923152372241, 0.010548789985477924, 0.01861008070409298, 0.019185971468687057, 0.024472396820783615, 0.013264225795865059, -0.041165418922901154, -0.0006625988753512502, 0.01476988010108471, -0.021199066191911697, 0.056256502866744995, -0.0469844788312912, -0.042506784200668335, 0.029012683779001236, -0.02917592041194439, -0.015138230286538601, -0.021672749891877174, -0.0359809435904026, -0.017517605796456337, 0.011662296019494534, 0.020993681624531746, -0.03221376612782478, -0.014842193573713303, -0.04584950953722, 0.029491743072867393, -0.014520439319312572, 0.010983489453792572, -0.010718369856476784, -0.009021060541272163, 0.012461109086871147, 0.015831852331757545, 0.019063472747802734, 0.028407013043761253, -0.0027842363342642784, 0.003921349998563528, -0.04021139442920685, 0.007509368937462568, 0.05048062279820442, 0.014317028224468231, 0.018562769517302513, 0.05664486438035965, -0.037026043981313705, 0.030367109924554825, 0.032152995467185974, -0.046710819005966187, 0.02605382725596428, -0.03329748287796974, 0.022004617378115654, -0.01818549633026123, 0.033525124192237854, -0.003480862360447645, -0.06212348863482475, -0.0049034045077860355, -0.048311542719602585, -0.002813054481521249, 0.0024560499005019665, -0.00003085822027060203, -0.04331182315945625, 0.026899803429841995, 0.018176594749093056, -0.005059001501649618, -0.015477819368243217, 0.010054350830614567, -0.013884072192013264, 0.03872690722346306, -0.043367888778448105, 0.01843489520251751, -0.050794199109077454, 0.008194401860237122, -0.01098204217851162, 0.029763324186205864, 0.029957883059978485, -0.07101798802614212, 0.015239077620208263, 0.020641988143324852, -0.04666176438331604, -0.001678389497101307, 0.009759750217199326, -0.03823301941156387, -0.030513228848576546, 0.03581136465072632, 0.04098429158329964, 0.032959550619125366, -0.009020395576953888, 0.02114018052816391, -0.054399315267801285, 0.017472149804234505, -0.0022804520558565855, -0.019813084974884987, 0.0013290341012179852, 0.029170354828238487, 0.050150129944086075, 0.10227744281291962, 0.0014478261582553387, 0.028562456369400024, 0.01195664145052433, 0.030123373493552208, 0.02170589193701744, -0.03465677797794342, -0.030056828632950783, -0.02702084183692932, 0.025859754532575607, 0.011901065707206726, 0.00945681519806385, 0.007055504713207483, 0.036825332790613174, 0.06648630648851395, -0.017246253788471222, -0.0362883061170578, 0.02016664482653141, -0.004703165031969547, -0.016991226002573967, 0.00654365960508585, 0.02578721009194851, -0.0165491234511137, -0.02166368067264557, 0.0008680851315148175, -0.01368789467960596, -0.02279731258749962, -0.01687108352780342, -0.02879304066300392, -0.04373054951429367, 0.009597064927220345, -0.014149367809295654, 0.05029469355940819, -0.01396981067955494, -0.001932491548359394, -0.028739990666508675, -0.003564448095858097, 0.03054450824856758, -0.030821045860648155, 0.0006309013115242124, -0.015844564884901047, -0.009604587219655514, 0.0027444155421108007, -0.0067466143518686295, -0.02020956575870514, 0.00838465616106987, 0.02144099399447441, 0.013748708181083202, 0.028639132156968117, -0.07578527927398682, 0.048180900514125824, 0.022875851020216942, -0.007971879094839096, -0.006659616716206074, -0.003358245361596346, -0.06068011000752449, 0.028999777510762215, -0.04218468442559242, 0.00587622681632638, 0.0758594498038292, -0.0017496548825874925, 0.010610965080559254, 0.019341200590133667, 0.010149135254323483, 0.006207918748259544, -0.008475701324641705, 0.0584464855492115, -0.03631747514009476, -0.001411000150255859, -0.003675794694572687, 0.034631192684173584, -0.004238666035234928, -0.000577643106225878, 0.010302986949682236, -0.06540784984827042, 0.03997232764959335, 0.0215177983045578, -0.024764319881796837, 0.010978861711919308, -0.008252453058958054, -0.03403465077280998, 0.03728063404560089, 0.020660949870944023, 0.013373575173318386, 0.0373334176838398, 0.029151057824492455, 0.0025649794843047857, -0.021050812676548958, -0.02191128209233284, 0.05142400413751602, 0.025810450315475464, 0.0041785878129303455, 0.03289400786161423, -0.00747307762503624, 0.036860350519418716, 0.08777657896280289, -0.015852926298975945, 0.004830142483115196, 0.029854666441679, 0.045302994549274445, -0.011267564259469509, 0.03531193733215332, 0.01741468906402588, 0.0007877975585870445, -0.0378909669816494, -0.012090492062270641, -0.003795910393819213, -0.021493924781680107, -0.0014059529639780521, 0.01268588937819004, -0.017759591341018677, 0.0020998679101467133, -0.011610611341893673, 0.08376433700323105, 0.05286269634962082, 0.0065664369612932205, 0.0036810520105063915, 0.025309119373559952, 0.029225673526525497, 0.005831041838973761, 0.0023816160392016172, 0.021540984511375427, 0.029336612671613693, -0.002446122467517853, 0.028360936790704727, 0.011677791364490986, -0.011265575885772705, 0.012051575817167759, 0.04672767594456673, 0.011288772337138653, -0.033051490783691406, 0.005846638232469559, -0.003288672072812915, 0.02958821877837181, -0.00503797410055995, -0.004156848415732384, 0.02276604250073433, -0.02655627764761448, -0.017373457551002502, -0.01417158916592598, -0.00651037972420454, -0.026224231347441673, -0.01581319235265255, 0.02006766013801098, 0.037098418921232224, 0.013316001743078232, -0.007364392746239901, 0.009037895128130913, -0.007862233556807041, -0.018325956538319588, 0.02024812437593937, 0.0035020189825445414, -0.015459276735782623, -0.04252186417579651, -0.01027718000113964, 0.02033410780131817, -0.004289517644792795, 0.0044795190915465355, -0.0036837963853031397, 0.004066858906298876, 0.01677796058356762, 0.0034416005946695805, 0.05918767303228378, 0.012770654633641243, 0.0069774361327290535, -0.020658742636442184, -0.001495735952630639, -0.004031595773994923, -0.026335079222917557, 0.0014218646101653576, -0.041130080819129944, 0.007748714182525873, -0.01689998246729374, 0.036378420889377594, 0.029283832758665085, 0.036799658089876175, -0.030988696962594986, -0.03292274475097656, -0.00073401746340096, -0.019352244213223457, -0.0031735822558403015, 0.02536998875439167, -0.0015882855514064431, 0.002559324260801077, 0.022080380469560623, -0.02492465078830719, 0.021150991320610046, -0.0156322680413723, -0.0040885875932872295, 0.041167229413986206, -0.01591474562883377, -0.004669212270528078, -0.014006134122610092, 0.06721170991659164, 0.04589901864528656, 0.05688117817044258, 0.023081688210368156, 0.03773481026291847, -0.01675778068602085, -0.009618067182600498, 0.03224216029047966, -0.01128184050321579, 0.031878091394901276, -0.023673102259635925, -0.05008925870060921, -0.014521753415465355, 0.0023861017543822527, 0.027532871812582016, 0.006281841080635786, -0.06697864830493927, -0.02515963464975357, -0.019536590203642845, -0.037750791758298874, -0.046232953667640686, 0.013973540626466274, 0.05052492022514343, 0.03253047168254852, -0.013374365866184235, 0.006653095595538616, -0.03023690916597843, 0.011512584052979946, -0.02483692578971386, 0.04234704002737999, 0.03625393286347389, -0.0016989767318591475, 0.0056574298068881035, -0.012047492899000645, 0.003531842492520809, 0.008888166397809982, -0.054058849811553955, -0.006165422964841127, 0.027583932504057884, -0.003414538223296404, -0.018300315365195274, -0.010862954892218113, 0.04108605906367302, -0.005649689584970474, 0.0339985117316246, -0.027486812323331833, 0.010349325835704803, -0.02440299652516842, 0.013806067407131195, -0.06261361390352249, 0.032077692449092865, -0.03936943784356117, 0.035804711282253265, 0.030337825417518616, 0.00006134006252977997, -0.020520541816949844, -0.025985591113567352, -0.0006600586930289865, 0.022257087752223015, -0.0032989338506013155, -0.04262811690568924, -0.048105549067258835, -0.0028805730398744345, 0.03489838168025017, -0.03185541555285454, -0.0637950748205185, 0.029825299978256226, -0.004820238798856735, -0.013249685056507587, 0.00033826357685029507, 0.004157835152000189, -0.011656641960144043, 0.004674483556300402, 0.014554096385836601, -0.034943051636219025, 0.018848352134227753, -0.0006700863596051931, -0.04294143244624138, -0.015856297686696053, -0.03879529610276222 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Conversion One of the most important parts of the porting process is to create a script that will take all the available source data provided by the original developer of the model, which includes a checkpoint with pre-trained weights, model and training configuration, dictionaries and tokenizer support files, and convert them into a new set of model files supported by transformers. You will find the final conversion script here: src/transformers/convert_fsmt_original_pytorch_checkpoint_to_pytorch.py I started this process by copying one of the existing conversion scripts src/transformers/convert_bart_original_pytorch_checkpoint_to_pytorch.py, gutted most of it out and then gradually added parts to it as I was progressing in the porting process. During the development I was testing all my code against a local copy of the converted model files, and only at the very end when everything was ready I uploaded the files to 🤗 s3 and then continued testing against the online version.
[ 0.01127307116985321, 0.010346338152885437, -0.022838151082396507, 0.01688784547150135, 0.04282447695732117, 0.042291708290576935, 0.009227219969034195, 0.018506670370697975, 0.004746277816593647, -0.016111787408590317, -0.05478646233677864, 0.03701982647180557, -0.011760021559894085, 0.02385595627129078, 0.04255680367350578, -0.03946959972381592, 0.025852885097265244, -0.05047920346260071, 0.01526535116136074, 0.019626691937446594, 0.01596362143754959, -0.0876346305012703, -0.020057355985045433, 0.04761820659041405, -0.026518959552049637, -0.03461924195289612, -0.01080895122140646, 0.06858677417039871, -0.021589096635580063, 0.06613816320896149, -0.10141363739967346, -0.006442450452595949, -0.014184501022100449, -0.06820967048406601, -0.02491595409810543, 0.05950852110981941, -0.07275734841823578, 0.04682987555861473, -0.02420923486351967, -0.05223533511161804, -0.010572499595582485, 0.0708337277173996, -0.0799548476934433, 0.05590077489614487, 0.03334097936749458, 0.005486881360411644, -0.1604083776473999, 0.05275106057524681, -0.010073626413941383, -0.03163450211286545, -0.03411461412906647, 0.038907039910554886, -0.05291710048913956, 0.013014419004321098, -0.017822930589318275, 0.03704620897769928, -0.026690876111388206, -0.0100377406924963, 0.005659185815602541, 0.005226662382483482, 0.04236433282494545, 0.039859771728515625, 0.03192617744207382, 0.04607590287923813, 0.04290395602583885, 0.0007350794621743262, 0.016548486426472664, 0.02597927115857601, -0.04746175929903984, -0.05940893664956093, 0.017846930772066116, -0.053788695484399796, -0.010485139675438404, -0.04670384153723717, -0.03224717453122139, -0.05579131469130516, 0.0575077086687088, 0.024657506495714188, 0.05042572319507599, 0.013932449743151665, 0.05672402307391167, 0.06382553279399872, -0.002645408734679222, 0.002637168625369668, 0.06530915200710297, 0.0036259370390325785, 0.07479961961507797, -0.04830551519989967, 0.030778007581830025, 0.07518385350704193, 0.0037677434738725424, -0.07832132279872894, -0.05453171208500862, 0.012449056841433048, 0.08496341854333878, 0.015326913446187973, 0.0007437084568664432, 0.028475776314735413, -0.004217494744807482, -0.007482352666556835, 0.028408071026206017, -0.02875654585659504, -0.020316187292337418, -0.04668279364705086, 0.0009375042864121497, -0.003135426202788949, 0.012382208369672298, -0.08277830481529236, 0.002466988516971469, -0.03150033578276634, -0.0069712488912045956, -0.01609140634536743, 0.007689761463552713, 0.04361944645643234, -0.036679573357105255, -0.02282342128455639, 0.033835843205451965, -0.07456844300031662, 0.0014204198960214853, 0.008367206901311874, 0.013377941213548183, 0.09160501509904861, -0.01114647090435028, -0.03611459583044052, 0.03407958149909973, 0.09877190738916397, 0.04359053075313568, 0.059856217354536057, 0.01537342369556427, -0.022840596735477448, 0.05543316528201103, -0.020982684567570686, 0.05190373584628105, 0.024458033964037895, -0.020761555060744286, -0.05581022426486015, -0.0043205083347857, -0.03260134533047676, -0.01883242279291153, -0.02821321040391922, -0.03797665610909462, 0.100588858127594, -0.05063788965344429, 0.0416419580578804, 0.009663654491305351, -0.028271622955799103, -0.0774625688791275, 0.1337219774723053, 0.021401505917310715, 0.04418119788169861, -0.10334067046642303, 0.06825435161590576, -0.038735996931791306, -0.06737853586673737, -0.03709368035197258, 0.05365024134516716, 0.035362500697374344, -0.042154666036367416, -0.09665830433368683, -0.04600080847740173, -0.02901902049779892, 0.02734817937016487, -0.03687262535095215, -0.02639530412852764, 0.026943452656269073, -0.06124014034867287, 0.027126429602503777, 0.0022933955769985914, 0.07789970189332962, 0.010374483652412891, 0.011855784803628922, -0.07765185832977295, 0.09950659424066544, -0.02599642053246498, 0.0012872484512627125, 0.0504184253513813, 0.0693664401769638, 0.06264722347259521, -0.02379424497485161, -0.031008712947368622, -0.03050854057073593, 0.05073845386505127, -0.05798462778329849, 0.021140463650226593, 0.02683398872613907, -0.061329420655965805, 0.013281241990625858, -0.03476964682340622, -0.03346054255962372, 0.04103989154100418, -0.07629375904798508, -0.009370539337396622, 0.03193403407931328, -0.012126226909458637, 0.05407349392771721, -0.039348870515823364, -0.034146782010793686, 0.12547411024570465, 0.00866730697453022, 0.09244535118341446, 0.03524855524301529, -0.043849606066942215, -0.004615336190909147, 0.0034730711486190557, 0.012992443516850471, 0.05939919874072075, 0.022753696888685226, -0.07488975673913956, 0.03775054216384888, 0.015492006205022335, 0.04371441900730133, -0.05803889036178589, 0.00006927690265001729, -0.08692656457424164, -0.022068805992603302, -0.04946175962686539, -0.1045697033405304, 0.014992077834904194, 0.006081277504563332, -0.06509888917207718, 0.16751691699028015, -0.049756117165088654, -0.004593010060489178, -0.055289074778556824, -0.022985020652413368, 0.060513705015182495, 0.018007036298513412, 0.06638551503419876, 0.0591622069478035, -0.08736903965473175, -0.048421092331409454, -0.06292081624269485, -0.003901503514498472, 0.051282208412885666, -0.004862428642809391, -0.016426552087068558, 0.005736164283007383, -0.015740642324090004, -0.0015767923323437572, -0.010536080226302147, 0.040690258145332336, 0.015373572707176208, 0.02982819452881813, -0.03856367617845535, 0.027023250237107277, 0.03295489400625229, 0.06411431729793549, -0.003830759087577462, 0.016742227599024773, -0.0026865305844694376, -0.04278791323304176, 0.04804302752017975, 0.04422377049922943, -0.018394632264971733, 0.08556752651929855, 0.02570762112736702, -0.012829327024519444, 0.0038649740163236856, 0.02355012856423855, 0.08305337280035019, 0.024386538192629814, 0.03154566138982773, -0.06689731031656265, -0.0446905754506588, -0.01816522143781185, -0.04743700847029686, 0.003756000427529216, 0.0058219339698553085, -0.02984064817428589, -0.010950249619781971, 0.009738671593368053, -0.05113488808274269, -0.0207046028226614, 0.0007970143924467266, 0.0309146735817194, 0.03173697367310524, 0.0432877391576767, -0.003542358288541436, -0.04123739153146744, -0.004047248978167772, 0.018865816295146942, -0.048185814172029495, 0.001334648230113089, 0.016572706401348114, -0.0032629177439957857, -0.00026367034297436476, 0.00876491330564022, 0.003299030242487788, -0.03506002575159073, 0.010006770491600037, 0.00744639802724123, 0.0038886237889528275, -0.020211603492498398, 0.0025860569439828396, -0.025093544274568558, -0.01239039096981287, -0.0035569840110838413, 0.0008660321473143995, 0.007042955607175827, 0.056991055607795715, -0.03783377632498741, 0.033254146575927734, 0.044146932661533356, -0.04216420277953148, -0.050119299441576004, 0.012695107609033585, 0.01798119954764843, -0.023326704278588295, -0.10158216953277588, 0.0031258133240044117, 0.005305862054228783, 0.03421351686120033, -0.03626291826367378, -0.03304925933480263, 0.0011414919281378388, -0.009157395921647549, -0.007841860875487328, 0.01774764060974121, 0.014232308603823185, 0.010206511244177818, 0.039564475417137146, 0.041321106255054474, -0.01448628306388855, 0.018303247168660164, -0.009473147802054882, 0.025555945932865143, 0.037448104470968246, 0.0005810942966490984, -0.041503727436065674, -0.001540905679576099, -0.016743121668696404, 0.012255875393748283, -0.0053914799354970455, 0.005919775925576687, 0.03492487594485283, 0.03438778966665268, -0.007453395053744316, -0.03143537417054176, -0.007981971837580204, -0.028469255194067955, 0.001614646753296256, -0.00804233644157648, -0.015403074212372303, -0.014205732382833958, 0.014288586564362049, 0.04175033047795296, 0.012462724931538105, 0.017528215423226357, -0.011129418388009071, -0.010995158925652504, 0.0031190221197903156, -0.028193209320306778, 0.053776275366544724, -0.004218521527945995, -0.012620067223906517, 0.012857876718044281, 0.006030205637216568, -0.012837833724915981, -0.029456138610839844, -0.04753239080309868, 0.01779727078974247, 0.07439994812011719, -0.015363708138465881, -0.0205020010471344, 0.015330744907259941, 0.040378469973802567, 0.04592525213956833, 0.012888182885944843, -0.05317644029855728, 0.04725329950451851, 0.011664999648928642, -0.04435575008392334, -0.028790581971406937, 0.07867014408111572, 0.00875723734498024, 0.003359624184668064, -0.018482672050595284, 0.03614487126469612, -0.026287756860256195, 0.022364381700754166, 0.00547005282714963, 0.00842716358602047, -0.06933774054050446, 0.05000872537493706, -0.04711063951253891, -0.02633911743760109, 0.027271240949630737, 0.049576956778764725, -0.012541639618575573, -0.005799241829663515, -0.023036783561110497, -0.039272382855415344, -0.003963594790548086, 0.03352537006139755, -0.010006221011281013, -0.020901532843708992, 0.02170081064105034, 0.0037797708064317703, 0.05308038741350174, -0.014353561215102673, -0.0009443872258998454, -0.019290415570139885, -0.029620952904224396, -0.007656124420464039, 0.021157845854759216, -0.017127595841884613, -0.0394170917570591, 0.023292427882552147, -0.011357646435499191, -0.04726611450314522, -0.025262096896767616, -0.003973858430981636, 0.005063275806605816, -0.0006673549069091678, -0.03270544111728668, -0.013958106748759747, 0.01992873288691044, 0.0004121851525269449, -0.008004631847143173, 0.02500884421169758, -0.019831810146570206, -0.0028033999260514975, 0.040081605315208435, 0.0345698706805706, -0.035931143909692764, -0.05159785971045494, -0.05238993465900421, 0.03455321863293648, -0.056949030607938766, 0.015732135623693466, 0.020757479593157768, -0.02261061780154705, 0.00865689106285572, -0.02507747896015644, 0.04951685667037964, 0.04885227978229523, 0.010690423659980297, 0.0010189195163547993, -0.04131725803017616, 0.03447955101728439, 0.04197118803858757, 0.044222619384527206, 0.006985650397837162, 0.006001617293804884, 0.015896741300821304, -0.02161663956940174, 0.03235207870602608, -0.007316634990274906, -0.026839949190616608, 0.0014001233503222466, 0.0026868402492254972, -0.01560548972338438, 0.02541406638920307, 0.009313486516475677, -0.03358084335923195, 0.018048200756311417, -0.037600018084049225, -0.0007020000484772027, 0.04102344438433647, -0.010309124365448952, -0.05241347849369049, -0.03414665907621384, -0.012084861285984516, -0.006455263588577509, 0.0401691198348999, -0.0000054067290875536855, 0.024703918024897575, 0.03337567672133446, -0.013333108276128769, -0.007096251472830772, -0.01080248598009348, -0.00494840182363987, 0.01742122694849968, 0.0017746371449902654, -0.00037871397216804326, -0.08626849949359894, -0.015681419521570206, 0.034335579723119736, -0.031084658578038216, -0.029752010479569435, 0.009915133938193321, -0.053101278841495514, 0.04063674062490463, 0.08257155865430832, 0.008253244683146477, 0.027492022141814232, -0.040846891701221466, 0.0108608677983284, 0.009893092326819897, -0.016154643148183823, 0.009649764746427536, -0.00014791375724598765, -0.015672538429498672, 0.0413532629609108, 0.026166006922721863, 0.05597330257296562, -0.03875201940536499, 0.02556869387626648, -0.014342679642140865, 0.005873944144695997, 0.01673557236790657, 0.001602735253982246, 0.008598925545811653, -0.023979349061846733, -0.008107512257993221, 0.013282380066812038, -0.004769225604832172, -0.006508821155875921, 0.024167008697986603, 0.062528595328331, 0.0019146319245919585, -0.013555559329688549, 0.031503915786743164, -0.006954537704586983, -0.01982133835554123, -0.015567551366984844, 0.025891438126564026, 0.007117490284144878, 0.015571902506053448, 0.029017990455031395, -0.0044529978185892105, -0.015279185026884079, -0.006464512553066015, -0.024213775992393494, -0.008898303844034672, 0.03100401535630226, 0.01090281456708908, 0.011322084814310074, 0.0298696868121624, -0.014318685047328472, -0.0038083551917225122, 0.05607850104570389, 0.013944735750555992, -0.039898619055747986, 0.0121132368221879, 0.010660449042916298, -0.013835449703037739, -0.0209401473402977, 0.026653479784727097, 0.0060125598683953285, -0.005374100990593433, 0.0335417315363884, 0.02854262851178646, -0.029350455850362778, -0.029331838712096214, 0.019330229610204697, 0.04198043420910835, -0.02383435145020485, -0.009425832889974117, -0.030770491808652878, -0.050834547728300095, 0.04280978441238403, -0.03461521863937378, 0.005213718395680189, 0.07811734080314636, 0.0022472962737083435, 0.052662283182144165, 0.025298766791820526, 0.01931072771549225, 0.03304329887032509, 0.03645933419466019, -0.005308111198246479, 0.009623945690691471, 0.0017067489679902792, 0.001795941381715238, -0.00456305081024766, 0.0038364860229194164, -0.04855935648083687, 0.04258379340171814, -0.04037987068295479, -0.03084420971572399, -0.013494524173438549, -0.01642550900578499, -0.011985734105110168, -0.008620338514447212, -0.041341133415699005, -0.014998099766671658, -0.0040286146104335785, 0.039497584104537964, 0.059266429394483566, 0.014194817282259464, 0.041617605835199356, -0.009377543814480305, -0.05143111199140549, 0.033515267074108124, 0.022295761853456497, -0.007906485348939896, 0.04653051123023033, 0.005107128992676735, 0.017222799360752106, 0.026617955416440964, 0.006304595153778791, 0.02436322532594204, -0.00661979615688324, 0.06900050491094589, -0.01077453326433897, 0.023785563185811043, 0.03199796378612518, 0.0152848269790411, -0.046130940318107605, -0.06347724050283432, -0.012131227180361748, -0.01092112809419632, 0.004342860076576471, 0.0012415499659255147, -0.020235667005181313, -0.010271798819303513, -0.0409720204770565, 0.0669572725892067, 0.04419206455349922, 0.048682618886232376, -0.04627728834748268, 0.047892145812511444, 0.022519750520586967, 0.0013319606659933925, 0.02066638320684433, 0.04010709375143051, 0.0346553772687912, 0.013443573378026485, 0.04524403437972069, -0.005282655358314514, 0.002981479512527585, -0.016704095527529716, 0.020168185234069824, 0.03044918179512024, 0.010803856886923313, -0.020233776420354843, 0.03703829646110535, -0.005766937974840403, -0.00842833798378706, -0.039459966123104095, 0.004489496350288391, -0.033697858452796936, 0.016139842569828033, -0.017026914283633232, -0.005393071100115776, -0.04279400408267975, -0.01927337236702442, -0.03832704946398735, 0.02266073226928711, 0.008139091543853283, -0.02662232331931591, -0.012977076694369316, -0.012983882799744606, 0.01116024050861597, 0.00045937884715385735, 0.027765637263655663, 0.020337168127298355, -0.035013508051633835, 0.021937761455774307, -0.01771635003387928, 0.001923528267070651, -0.028603428974747658, 0.019672123715281487, 0.02141542360186577, 0.03160936385393143, -0.001809199107810855, 0.024730399250984192, 0.021152058616280556, 0.0015468470519408584, -0.01349831372499466, -0.01964101754128933, -0.00040092229028232396, -0.038293253630399704, 0.021959897130727768, -0.01881694793701172, 0.009812257252633572, 0.004691986367106438, 0.043239567428827286, 0.01253498811274767, 0.038996849209070206, -0.023412203416228294, -0.0546429418027401, -0.00902794860303402, -0.008195990696549416, -0.02570587769150734, 0.02942436747252941, 0.02239757962524891, 0.002843977650627494, 0.04942285269498825, -0.020115451887249947, 0.013482319191098213, 0.01951543241739273, -0.03470127284526825, 0.019435973837971687, -0.002567741321399808, -0.020135102793574333, -0.007727022282779217, 0.09288658201694489, 0.009651576168835163, -0.0029765870422124863, 0.025180460885167122, 0.004646672867238522, -0.0015504639595746994, -0.012796444818377495, -0.02033773995935917, -0.01660374365746975, 0.008738270960748196, -0.01823299564421177, -0.06796782463788986, -0.017285184934735298, 0.024722596630454063, 0.000016480522390338592, -0.023693332448601723, -0.04351121187210083, -0.016853200271725655, -0.033846426755189896, -0.029570123180747032, -0.007538721431046724, 0.0023384946398437023, 0.02722543478012085, 0.052720531821250916, 0.004704702645540237, 0.009123791009187698, -0.0304774921387434, -0.0019565329421311617, -0.008597306907176971, 0.022731227800250053, 0.008989338763058186, 0.016379281878471375, -0.024173814803361893, -0.04252701625227928, 0.03232944756746292, -0.007257457356899977, -0.01897868700325489, -0.032261449843645096, 0.0014979027910158038, -0.01914740912616253, -0.07170671224594116, -0.007051785942167044, 0.014482184313237667, -0.0026606726460158825, 0.023705115541815758, -0.0018255828181281686, -0.001370909041725099, -0.0264324601739645, -0.013929583132266998, -0.07334738224744797, 0.0016121899243444204, -0.011983915232121944, -0.007963691838085651, 0.029960334300994873, 0.027272438630461693, -0.015857746824622154, 0.023992085829377174, -0.041235290467739105, 0.03339902311563492, -0.0035374939907342196, -0.007560913451015949, -0.036990001797676086, 0.019172029569745064, 0.05447392910718918, -0.01929921656847, -0.057920943945646286, 0.008105915039777756, -0.0028749823104590178, -0.02848745882511139, 0.01083102636039257, 0.011491130106151104, 0.024369552731513977, -0.0029137120582163334, -0.01974950172007084, -0.017719930037856102, -0.0033796015195548534, 0.010837815701961517, -0.034647513180971146, -0.0038769766688346863, 0.01724962145090103 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
How translation systems work Here is a very brief introduction to how computers translate text nowadays. Computers can't read text, but can only handle numbers. So when working with text we have to map one or more letters into numbers, and hand those to a computer program. When the program completes it too returns numbers, which we need to convert back into text. Let's start with two sentences in Russian and English and assign a unique number to each word: я люблю следовательно я существую 10 11 12 10 13 I love therefore I am 20 21 22 20 23 The numbers starting with 10 map Russian words to unique numbers. The numbers starting with 20 do the same for English words. If you don't speak Russian, you can still see that the word я (means 'I') repeats twice in the sentence and it gets the same number 10 associated with it. Same goes for I (20), which also repeats twice. A translation system works in the following stages: 1. [я люблю следовательно я существую] # tokenize sentence into words 2. [10 11 12 10 13] # look up words in the input dictionary and convert to ids 3. [black box] # machine learning system magic 4. [20 21 22 20 23] # look up numbers in the output dictionary and convert to text 5. [I love therefore I am] # detokenize the tokens back into a sentence If we combine the first two and the last two steps we get 3 stages: 1. Encode input: break input text into tokens, create a dictionary (vocab) of these tokens and remap each token into a unique id in that dictionary. 2. Generate translation: take input numbers, run them through a pre-trained machine learning model which predicts the best translation, and return output numbers. 3. Decode output: take output numbers, look them up in the target language dictionary, convert them back to text, and finally merge the converted tokens into the translated sentence. The second stage may return one or several possible translations. In the case of the latter the caller then can choose the most suitable outcome. In this article I will refer to the beam search algorithm, which is one of the ways multiple possible results are searched for. And the size of the beam refers to how many results are returned. If there is only one result that's requested, the model will choose the one with the highest likelihood probability. If multiple results are requested it will return those results sorted by their probabilities. Note that this same idea applies to the majority of NLP tasks, and not just translation.
[ 0.04203249514102936, 0.05499570816755295, 0.0244964100420475, -0.014022967778146267, 0.08324260264635086, 0.0920606330037117, 0.025353573262691498, 0.04159723222255707, -0.03684727102518082, 0.006753477733582258, -0.03963388875126839, 0.016765838488936424, -0.004288205876946449, 0.04146895185112953, -0.08453699946403503, -0.028438417240977287, 0.0741894468665123, -0.033434461802244186, 0.05821271240711212, 0.025115428492426872, -0.010257002897560596, -0.000007087430276442319, 0.10675002634525299, -0.024551061913371086, 0.017004169523715973, 0.057812221348285675, -0.024935804307460785, -0.04847875237464905, -0.07959433645009995, -0.008929233998060226, -0.09437115490436554, -0.00037107226671651006, -0.035377901047468185, -0.04316200315952301, -0.057671576738357544, 0.021760836243629456, -0.0871267020702362, 0.09043163061141968, 0.015413334593176842, -0.09717913717031479, -0.05791094899177551, 0.026242459192872047, -0.07156277447938919, 0.031906574964523315, -0.021172424778342247, -0.022361261770129204, -0.20024369657039642, 0.05323721468448639, -0.05398257076740265, -0.060181889683008194, -0.08053810894489288, -0.006056854501366615, -0.003075225045904517, -0.023983633145689964, -0.017439577728509903, 0.035636790096759796, -0.04685872420668602, -0.03259649872779846, -0.02067437581717968, 0.042286939918994904, 0.018994435667991638, 0.06687349826097488, 0.04809821769595146, 0.03347396105527878, 0.01412530429661274, 0.009249874390661716, 0.034101855009794235, 0.0022976542823016644, -0.0438905730843544, -0.03520659729838371, -0.041634634137153625, -0.030336102470755577, -0.008785048499703407, -0.049807384610176086, -0.03963904455304146, -0.05037830397486687, -0.014770658686757088, 0.07789018750190735, 0.020549336448311806, -0.029326312243938446, 0.012746602296829224, 0.04408171400427818, 0.031096236780285835, 0.003272105474025011, 0.09185946732759476, 0.01094463374465704, 0.04479297623038292, 0.018661893904209137, -0.04501686245203018, 0.04238736629486084, 0.0030125516932457685, -0.14074565470218658, -0.026379087939858437, 0.04492948204278946, 0.016258113086223602, -0.029976313933730125, 0.03200638294219971, 0.07584546506404877, -0.08065757900476456, -0.02556007169187069, 0.026019591838121414, -0.0365765281021595, 0.1273081749677658, -0.002546365838497877, -0.03373522683978081, 0.016189025714993477, 0.0037008067592978477, -0.013796338811516762, 0.007624808698892593, -0.0008684592321515083, -0.031743310391902924, -0.02581954374909401, 0.0235200896859169, 0.018288472667336464, -0.030711118131875992, -0.01298019103705883, 0.06764880567789078, 0.028542667627334595, -0.009652751497924328, 0.07042615860700607, 0.00021547767391894013, -0.01786150597035885, 0.032088752835989, -0.003920054063200951, 0.0018576065776869655, -0.05590761452913284, 0.016801226884126663, -0.03794603794813156, -0.0028226927388459444, 0.00932951457798481, 0.016544615849852562, 0.02529146708548069, 0.0804029256105423, 0.03478763625025749, 0.039712391793727875, -0.02676325850188732, 0.03935323655605316, -0.01192705612629652, -0.007964707911014557, -0.05111273378133774, -0.039842911064624786, 0.01866590417921543, -0.04091164469718933, 0.03714825212955475, 0.0503917895257473, 0.021631045266985893, -0.07493468374013901, -0.005921367555856705, -0.01634528487920761, 0.025712795555591583, -0.05387624353170395, 0.024386323988437653, -0.01127761323004961, -0.05318277329206467, 0.04835527762770653, 0.050561726093292236, 0.04020099341869354, -0.0544905960559845, -0.07434693723917007, -0.027995707467198372, -0.06869949400424957, 0.029658472165465355, 0.018364569172263145, -0.04078846424818039, -0.029788967221975327, -0.014616201631724834, 0.04985905438661575, 0.1519206017255783, 0.029774995520710945, 0.060255251824855804, 0.018753843382000923, 0.03853267431259155, 0.11067904531955719, -0.03354316204786301, 0.003389711957424879, 0.01020838227123022, -0.001843269681558013, 0.020512497052550316, 0.0038065158296376467, -0.09154561161994934, -0.024910446256399155, -0.025637086480855942, -0.014287461526691914, 0.03522316366434097, -0.015980763360857964, -0.033886171877384186, 0.004215131048113108, -0.05625859275460243, -0.0023654696997255087, 0.04320526868104935, -0.06804711371660233, -0.010728230699896812, 0.005688340403139591, -0.03470712527632713, 0.029663868248462677, -0.11576651781797409, -0.004860848654061556, 0.12578924000263214, -0.05125342309474945, 0.07755117118358612, 0.07203307002782822, -0.05689436197280884, 0.03094388358294964, -0.012705210596323013, 0.04085402563214302, 0.012096897698938847, 0.05645020678639412, -0.055731698870658875, -0.007944578304886818, 0.016928477212786674, -0.01687864027917385, -0.056777384132146835, 0.005045593716204166, -0.04974276199936867, -0.003028010716661811, -0.0014343785587698221, -0.024842415004968643, 0.0053068711422383785, 0.01192119624465704, -0.025226138532161713, 0.1071159616112709, -0.04729043319821358, -0.03684709221124649, 0.006168932653963566, -0.03379086032509804, 0.04232022166252136, 0.056524574756622314, 0.03312542289495468, -0.015911070629954338, -0.03394395112991333, -0.05245251953601837, -0.030769508332014084, 0.05915818735957146, 0.005430562887340784, -0.0531281940639019, -0.021298855543136597, -0.019079068675637245, 0.02480381354689598, 0.01429045107215643, 0.04180119186639786, 0.02000974863767624, -0.03515714779496193, -0.04419879615306854, 0.03523828461766243, -0.04280981793999672, 0.029760146513581276, 0.11900761723518372, 0.0011452684411779046, -0.015948979184031487, -0.0049166190437972546, -0.06004304438829422, 0.01560660544782877, -0.06006395071744919, -0.013810139149427414, 0.04407500848174095, 0.028016364201903343, 0.030874362215399742, -0.007603395730257034, 0.0063539063557982445, -0.003040597541257739, -0.017696700990200043, 0.007804141379892826, -0.007859103381633759, -0.05406954512000084, -0.012786278501152992, -0.034899670630693436, 0.011655597016215324, 0.015753911808133125, -0.0031440502498298883, 0.015504114329814911, -0.022345026955008507, -0.016973739489912987, 0.0396566279232502, -0.012465229257941246, 0.020452270284295082, 0.0012586567318066955, 0.020137203857302666, -0.024012543261051178, -0.045133594423532486, 0.01606382615864277, -0.021169861778616905, -0.010321710258722305, 0.06011144071817398, 0.03503197059035301, -0.020631445571780205, -0.034378815442323685, -0.021186338737607002, -0.028899071738123894, -0.00043047528015449643, 0.02486601285636425, -0.01985449343919754, -0.034190833568573, -0.0011634161928668618, -0.0015136082656681538, 0.01918547786772251, 0.02757885493338108, -0.01009896770119667, 0.029668139293789864, 0.007846602238714695, 0.026031164452433586, 0.010558617301285267, 0.014948327094316483, -0.0011374031892046332, 0.003159899730235338, -0.06319088488817215, 0.058183636516332626, -0.002569108037278056, 0.05769956856966019, -0.09583146125078201, -0.026212593540549278, 0.02757813036441803, -0.024472905322909355, 0.02335205115377903, 0.004295972641557455, 0.018561750650405884, 0.04988408833742142, 0.0031681067775934935, -0.002299326006323099, 0.0035183001309633255, 0.01575232297182083, -0.00019639520905911922, 0.0010148804867640138, 0.0041482760570943356, 0.01695462130010128, 0.02625230886042118, 0.01971633918583393, 0.006420082412660122, 0.036142706871032715, -0.014306914061307907, 0.014870834536850452, 0.01949065551161766, 0.044960834085941315, -0.03961336985230446, -0.00535560492426157, 0.05240539088845253, -0.005056592170149088, -0.0007562406826764345, -0.0164639949798584, -0.018778620287775993, 0.018961189314723015, 0.006682601757347584, -0.031064586713910103, -0.022299272939562798, -0.00040168233681470156, 0.06935249269008636, 0.0009312850306741893, 0.03496560454368591, 0.018282590433955193, -0.0047627161256968975, 0.0011737135937437415, 0.017225084826350212, -0.0367395393550396, -0.015257686376571655, -0.010270858183503151, -0.016737908124923706, -0.025388967245817184, -0.032531388103961945, -0.06255883723497391, 0.018727010115981102, -0.030171383172273636, -0.00496993213891983, 0.009015698917210102, 0.01889546401798725, -0.016276437789201736, -0.00329541671089828, 0.0008353955927304924, 0.04383929446339607, 0.01574729196727276, -0.01419353112578392, 0.0234625656157732, -0.007166327442973852, -0.040230341255664825, -0.020965514704585075, 0.05686384066939354, 0.015028128400444984, 0.0294276662170887, 0.018597759306430817, 0.04836282879114151, -0.0077709113247692585, 0.0004530437581706792, 0.044711291790008545, 0.0035165701992809772, -0.013983937911689281, 0.020466649904847145, -0.06623872369527817, -0.0016093244776129723, 0.04124573990702629, 0.06568363308906555, -0.03143708407878876, -0.018698064610362053, -0.040418822318315506, -0.020030442625284195, 0.04082022234797478, -0.03464657813310623, 0.03531946986913681, -0.015264331363141537, -0.005683254450559616, 0.007876272313296795, 0.023236149922013283, -0.05176286771893501, 0.0017554046353325248, 0.007599282544106245, 0.02420991286635399, -0.0014747758395969868, 0.06367511302232742, -0.020034058019518852, 0.011608767323195934, -0.034643396735191345, 0.020914921537041664, -0.07259867340326309, -0.024446316063404083, -0.04686429351568222, 0.00037115506711415946, 0.031074265018105507, -0.07486003637313843, -0.01636962778866291, 0.0269517432898283, 0.01750062219798565, -0.04158613085746765, 0.013482476584613323, -0.030432740226387978, 0.023154400289058685, 0.0027328496798872948, 0.021954920142889023, -0.01211160235106945, -0.06675969809293747, -0.025148233398795128, -0.03695445880293846, -0.04052954539656639, -0.00786979403346777, -0.008011535741388798, 0.030239397659897804, -0.02193775586783886, 0.005736168939620256, 0.04310616850852966, -0.0030490534845739603, -0.013307944871485233, -0.06260068714618683, -0.010099801234900951, 0.049350108951330185, 0.026729397475719452, 0.02470739558339119, -0.014914787374436855, 0.011894536204636097, 0.021267712116241455, 0.015929516404867172, -0.03288816288113594, -0.04791540652513504, -0.009856857359409332, -0.021385114639997482, 0.03639959916472435, -0.03649979457259178, 0.05425582826137543, 0.009716031141579151, -0.013656754978001118, -0.027987204492092133, 0.03457421064376831, -0.01587650366127491, 0.0507630780339241, -0.0289317574352026, -0.04071139171719551, 0.020329071208834648, -0.0032608734909445047, -0.040689267218112946, -0.005978666711598635, 0.047494374215602875, -0.00729334307834506, 0.034997012466192245, 0.028392111882567406, -0.015866214409470558, -0.008088435046374798, 0.025270400568842888, 0.0069812904112041, -0.04368157684803009, 0.008650020696222782, -0.0341065488755703, -0.025440813973546028, 0.003749025519937277, 0.04088788852095604, -0.000868114351760596, -0.03818463161587715, -0.004334008786827326, 0.010423015803098679, 0.014201718382537365, -0.047559283673763275, 0.016815757378935814, -0.017464788630604744, -0.022239573299884796, 0.04913310334086418, -0.01621886156499386, 0.023202840238809586, 0.03744009509682655, -0.038929808884859085, 0.01217441726475954, 0.04447505250573158, 0.02199479565024376, -0.008563170209527016, -0.017559343948960304, 0.019486624747514725, 0.037635672837495804, 0.03006770648062229, -0.02972862869501114, 0.015168337151408195, -0.009728389792144299, 0.0038959055673331022, 0.028470324352383614, -0.016043441370129585, 0.06370710581541061, 0.03261760622262955, 0.02631778083741665, -0.0030846712179481983, -0.017866455018520355, -0.004502969328314066, -0.006674071773886681, -0.04345129057765007, -0.01986953616142273, 0.018041012808680534, -0.017620055004954338, -0.034361932426691055, -0.020860983058810234, -0.05472608655691147, 0.03339351341128349, -0.01855345256626606, -0.06296884268522263, -0.019688988104462624, -0.006379030179232359, 0.0012095629936084151, 0.04268057644367218, 0.043084390461444855, -0.006058094557374716, -0.025091862305998802, 0.04433629289269447, 0.022341078147292137, -0.03125354275107384, 0.025613127276301384, -0.0004916528705507517, 0.03231005743145943, -0.006743629928678274, 0.03931068256497383, -0.005872150417417288, -0.0074245510622859, 0.023127185180783272, 0.008329346776008606, -0.034060701727867126, -0.018444741144776344, 0.014754435047507286, 0.010928457602858543, -0.0020249257795512676, 0.0014469034504145384, 0.006343691144138575, -0.037974465638399124, 0.053651656955480576, 0.012736115604639053, 0.028485989198088646, 0.03059959225356579, 0.0032983790151774883, 0.02225220762193203, 0.011788617819547653, 0.00947432592511177, 0.007604957092553377, -0.0010101388907060027, 0.036479245871305466, -0.011758822947740555, 0.0548848994076252, 0.015690073370933533, 0.007809347473084927, -0.008695085532963276, 0.013896363787353039, 0.03361538425087929, -0.037997230887413025, 0.0003947735240217298, 0.04351016506552696, 0.0031444670166820288, 0.02839699760079384, 0.01390126720070839, -0.045472122728824615, 0.01430280040949583, 0.04711688309907913, 0.04866551235318184, 0.010612123645842075, -0.005956169217824936, 0.053132470697164536, -0.00026976846856996417, -0.01959933713078499, 0.003310440108180046, 0.09188712388277054, -0.022141145542263985, 0.04118751361966133, 0.024960603564977646, 0.0354645662009716, -0.0005787404370494187, -0.00463234493508935, 0.024781329557299614, 0.015201490372419357, 0.037503644824028015, 0.00606886763125658, 0.036226920783519745, -0.008560385555028915, -0.01397726871073246, -0.02674381248652935, -0.019386643543839455, 0.00694526731967926, -0.014568834565579891, 0.0005948360194452107, 0.011009088717401028, 0.016301341354846954, -0.002643065992742777, 0.003838715609163046, 0.04469636082649231, 0.021262114867568016, 0.04512995108962059, 0.004005206748843193, 0.015544120222330093, 0.02184649556875229, 0.02915899083018303, 0.03878801688551903, 0.05706855654716492, -0.017575964331626892, 0.02873591147363186, 0.03362657129764557, 0.01305847242474556, 0.03661393001675606, 0.01934281550347805, -0.0015342985279858112, 0.008719690144062042, 0.0008703037747181952, -0.042880117893218994, 0.04003835469484329, -0.00493248738348484, 0.0011460446985438466, -0.02278834395110607, 0.0339939147233963, -0.03473486378788948, -0.024063028395175934, -0.002942795865237713, -0.04232318699359894, -0.030553050339221954, -0.058510664850473404, -0.04341965168714523, 0.07425983250141144, -0.009001495316624641, -0.06381083279848099, -0.01632360927760601, -0.059304479509592056, 0.004641146399080753, -0.004680105485022068, 0.018243171274662018, 0.0038856903556734324, -0.03526934236288071, -0.011477632448077202, -0.022517092525959015, -0.02001001127064228, -0.008844521827995777, 0.007160641718655825, 0.01777655817568302, 0.03328123688697815, -0.03690009191632271, 0.008220979943871498, 0.009786820039153099, 0.0000867621783982031, -0.008870022371411324, 0.02473415993154049, -0.019038939848542213, -0.00028673181077465415, 0.010377123020589352, -0.035025786608457565, -0.006768106482923031, -0.0269419364631176, -0.002538849599659443, -0.004987493623048067, 0.04124118387699127, 0.01120778638869524, -0.031125003471970558, 0.02634419873356819, -0.0146112572401762, -0.05406226962804794, 0.0017295220168307424, -0.005383252631872892, -0.02053680270910263, 0.010222692042589188, -0.015234152786433697, 0.020882532000541687, -0.013684220612049103, 0.009257800877094269, 0.012566826306283474, -0.011781923472881317, -0.025449998676776886, -0.056119155138731, 0.036999765783548355, 0.026855237782001495, 0.0018556835129857063, 0.04545648768544197, -0.01756404899060726, 0.022727595642209053, -0.023608630523085594, 0.06569748371839523, -0.03433217853307724, 0.05821382999420166, -0.0017566508613526821, -0.07405004650354385, -0.0031803047750145197, -0.01078109908849001, -0.00518415542319417, 0.02076224610209465, -0.010670662857592106, 0.024351660162210464, -0.01863805763423443, 0.01546801533550024, -0.015712006017565727, -0.04096967354416847, 0.014543182216584682, 0.0052604819647967815, 0.009484670124948025, 0.028346074745059013, 0.019220540300011635, -0.014087523333728313, -0.022104015573859215, 0.009169484488666058, 0.016633473336696625, -0.02008933015167713, 0.009563512168824673, 0.014527919702231884, 0.01518089510500431, -0.03596382588148117, -0.006543568801134825, 0.03864811733365059, 0.031549204140901566, -0.019489023834466934, -0.021184414625167847, 0.02206731028854847, 0.009748565964400768, 0.0019063178915530443, -0.00033468974288553, -0.007913444191217422, -0.029992079362273216, 0.00836862064898014, -0.012832669541239738, -0.051423244178295135, -0.037620965391397476, 0.018415654078125954, 0.01668703183531761, 0.026102911680936813, 0.04829778894782066, 0.03711396083235741, -0.015623804181814194, 0.008509140461683273, 0.0498291477560997, -0.0354410745203495, 0.023029033094644547, -0.06395857036113739, -0.014318622648715973, 0.011786526069045067, -0.005697852000594139, -0.028814321383833885, 0.05245179682970047, -0.0049260687083005905, -0.018150491639971733, -0.0079580657184124, 0.038670722395181656, -0.041417501866817474, -0.02626834623515606, -0.0031964825466275215, 0.008376361802220345, 0.06164279952645302, -0.012948601506650448, 0.03165899217128754, 0.004855325445532799, 0.019936703145503998 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Tokenization Early systems tokenized sentences into words and punctuation marks. But since many languages have hundreds of thousands of words, it is very taxing to work with huge vocabularies, as it dramatically increases the compute resource requirements and the length of time to complete the task. As of 2020 there are quite a few different tokenizing methods, but most of the recent ones are based on sub-word tokenization - that is instead of breaking input text down into words, these modern tokenizers break the input text down into word segments and letters, using some kind of training to obtain the most optimal tokenization. Let's see how this approach helps to reduce memory and computation requirements. If we have an input vocabulary of 6 common words: go, going, speak, speaking, sleep, sleeping - with word-level tokenization we end up with 6 tokens. However, if we break these down into: go, go-ing, speak, speak-ing, etc., then we have only 4 tokens in our vocabulary: go, speak, sleep, ing. This simple change made a 33% improvement! Except, the sub-word tokenizers don't use grammar rules, but they are trained on massive text inputs to find such splits. In this example I used a simple grammar rule as it's easy to understand. Another important advantage of this approach is when dealing with input text words, that aren't in our vocabulary. For example, let's say our system encounters the word grokking (), which can't be found in its vocabulary. If we split it into grokk'-'ing', then the machine learning model might not know what to do with the first part of the word, but it gets a useful insight that 'ing' indicates a continuous tense, so it'll be able to produce a better translation. In such situation the tokenizer will split the unknown segments into segments it knows, in the worst case reducing them to individual letters. * footnote: to grok was coined in 1961 by Robert A. Heinlein in "Stranger in a Strange Land": to understand (something) intuitively or by empathy. There are many other nuances to why the modern tokenization approach is much more superior than simple word tokenization, which won't be covered in the scope of this article. Most of these systems are very complex to how they do the tokenization, as compared to the simple example of splittingingendings that was just demonstrated, but the principle is similar.
[ 0.052392374724149704, 0.018137792125344276, 0.011964223347604275, -0.04131228104233742, 0.0790984109044075, 0.07861681282520294, -0.01042963843792677, 0.059473633766174316, -0.043484512716531754, 0.007445656694471836, -0.04386826232075691, 0.012239350005984306, -0.01253070030361414, 0.037483420222997665, -0.034030210226774216, 0.021934404969215393, 0.04557683318853378, -0.04196423292160034, 0.020566517487168312, -0.060880448669195175, -0.034849535673856735, -0.011884765699505806, 0.10791610926389694, 0.03467683121562004, 0.0572437047958374, 0.03629526123404503, -0.022271549329161644, -0.0377754308283329, -0.046665869653224945, 0.013441273011267185, -0.09479912370443344, -0.011590094305574894, -0.037756629288196564, 0.016263050958514214, -0.04058195650577545, -0.04644964262843132, -0.09987369179725647, 0.08895821124315262, 0.006517916917800903, -0.049247659742832184, -0.03600237891077995, -0.03767099604010582, -0.03522311896085739, 0.020251238718628883, -0.04977456480264664, 0.010820089839398861, -0.22636711597442627, 0.06907424330711365, -0.05188916623592377, -0.038213036954402924, -0.08912979066371918, 0.014884129166603088, -0.03370892256498337, -0.02623014897108078, -0.04827392101287842, -0.005584497004747391, -0.00984138436615467, -0.09448990970849991, 0.01231475081294775, 0.001812449423596263, 0.03993554785847664, -0.007632829714566469, 0.008884155191481113, -0.01777975633740425, 0.044141486287117004, 0.028389165177941322, -0.04540140554308891, 0.024371834471821785, -0.07390107214450836, -0.004072836134582758, -0.019142642617225647, -0.042275674641132355, -0.05003952980041504, -0.014413109980523586, -0.037563908845186234, -0.04105902835726738, 0.011580674909055233, -0.008190684951841831, -0.01712232269346714, -0.004136437084525824, 0.002078267280012369, 0.04563550651073456, 0.040571171790361404, 0.02540559135377407, 0.03411644324660301, -0.017248744145035744, 0.0038124495185911655, -0.0019021709449589252, -0.033341094851493835, 0.0368034765124321, -0.0201912559568882, -0.14125768840312958, -0.018664764240384102, 0.04462261125445366, 0.041044123470783234, -0.01447079237550497, 0.03222782164812088, 0.08460782468318939, 0.0034123773220926523, 0.0011455031344667077, -0.010169009678065777, -0.11082882434129715, 0.0805160403251648, 0.03201080486178398, -0.01783178187906742, 0.020993096753954887, -0.016324693337082863, -0.013590243645012379, 0.05189814418554306, 0.010767629370093346, 0.01716870255768299, 0.033417798578739166, 0.0813431590795517, 0.046969249844551086, -0.08224355429410934, 0.02706151455640793, 0.012198960408568382, 0.04614488035440445, 0.005589103791862726, 0.027764765545725822, 0.008003400638699532, 0.03284444659948349, 0.1312713325023651, 0.006669308058917522, -0.05100935325026512, -0.04404642805457115, 0.08352777361869812, 0.012495082803070545, 0.0037471503019332886, -0.01937340572476387, -0.007854421623051167, 0.05488568916916847, 0.019508952274918556, 0.051160793751478195, 0.006502904463559389, -0.020166141912341118, 0.03518621250987053, -0.038993049412965775, -0.003632291918620467, -0.0371914803981781, -0.06012310832738876, 0.05426179990172386, -0.026024408638477325, 0.013824746944010258, 0.044677313417196274, -0.001326243975199759, -0.09457820653915405, 0.010409574024379253, -0.04876274988055229, -0.03392975777387619, -0.05973263084888458, -0.004979592747986317, -0.024758296087384224, -0.006955823861062527, 0.029815180227160454, 0.031849462538957596, -0.012387337163090706, -0.020594408735632896, -0.04666221886873245, -0.04872690886259079, -0.017766132950782776, 0.03300771862268448, 0.008550317026674747, 0.0066212816163897514, 0.024706002324819565, -0.05504501610994339, 0.04908011853694916, 0.08390103280544281, -0.02278856746852398, 0.008727967739105225, 0.0405987985432148, 0.010071349330246449, 0.10227459669113159, -0.09174087643623352, -0.04433275759220123, 0.05512157455086708, -0.028645727783441544, 0.05385134369134903, -0.0029124387074261904, 0.01713687740266323, -0.037320904433727264, -0.011481785215437412, 0.007573157083243132, 0.040205106139183044, 0.023473914712667465, -0.0982525423169136, -0.015564688481390476, -0.02411581203341484, -0.0003562254423741251, 0.0420551523566246, -0.05324883759021759, -0.045927487313747406, 0.013235527090728283, 0.0130535326898098, 0.024017861112952232, -0.07133244723081589, -0.023595908656716347, 0.10726828873157501, 0.03337620943784714, 0.0891287624835968, 0.056650590151548386, -0.006452473346143961, -0.02808273769915104, -0.03342145308852196, -0.05128268525004387, 0.030325502157211304, 0.019351277500391006, -0.0500473789870739, 0.02804117649793625, 0.0066650561057031155, 0.02853711135685444, -0.05270450562238693, 0.0208879504352808, -0.06922122091054916, -0.03625364229083061, 0.00016079792112577707, 0.013297499157488346, 0.10585226863622665, 0.021258018910884857, -0.08659537881612778, 0.1518574357032776, -0.11960208415985107, -0.02313952147960663, 0.018033994361758232, -0.04177144542336464, 0.03667869418859482, 0.06873463839292526, 0.00438126502558589, 0.0521717444062233, -0.08040664345026016, -0.07834092527627945, -0.08741540461778641, 0.01769201271235943, 0.006529731675982475, -0.012454751878976822, 0.014485763385891914, 0.0032306534703820944, 0.004674807656556368, 0.006312973331660032, -0.030735522508621216, -0.0319644995033741, -0.07563265413045883, 0.027017278596758842, 0.03717893734574318, 0.026849238201975822, 0.024396218359470367, 0.07990515977144241, 0.006686808541417122, -0.034892402589321136, -0.026467610150575638, -0.06793425232172012, 0.06613260507583618, -0.022018354386091232, -0.00937036331743002, 0.015694908797740936, -0.0022882462944835424, 0.03882438316941261, 0.005987642798572779, 0.004969899542629719, -0.01785072684288025, -0.01734357513487339, -0.012959331274032593, 0.01662454940378666, -0.06439826637506485, 0.012002835050225258, -0.04035896807909012, -0.006039835046976805, 0.015409731306135654, 0.007216400932520628, 0.020936984568834305, 0.0044550057500600815, 0.0038917595520615578, 0.008748737163841724, 0.012492222711443901, 0.013885457068681717, 0.014160864055156708, 0.020320653915405273, -0.03824819251894951, -0.019812917336821556, -0.014155484735965729, -0.0012828554026782513, -0.02104569412767887, 0.011916087009012699, 0.044577766209840775, 0.01801486313343048, -0.02827504090964794, 0.01876753568649292, -0.02031932771205902, -0.01874411664903164, 0.03497583419084549, 0.02476458065211773, 0.016480760648846626, -0.018458548933267593, -0.013409726321697235, 0.03528508171439171, 0.013440927490592003, -0.01326549518853426, 0.013464991003274918, 0.015833979472517967, 0.00617322139441967, 0.013460644520819187, 0.01892874762415886, -0.014555857516825199, -0.01317018736153841, -0.041838258504867554, 0.01415975484997034, 0.005848284810781479, 0.03148256987333298, -0.10803309082984924, -0.009628734551370144, 0.018901504576206207, 0.0008392476011067629, -0.02941894717514515, -0.005811402574181557, 0.050249915570020676, 0.016907967627048492, -0.029848692938685417, -0.011980882845818996, 0.003914721310138702, 0.005206919275224209, 0.004590386990457773, 0.0013987688580527902, -0.023516884073615074, 0.028351416811347008, -0.004293676000088453, 0.02024148218333721, -0.02017657645046711, 0.041490260511636734, 0.010069763287901878, 0.04868810996413231, -0.0007737957639619708, 0.003910780418664217, -0.00652681989595294, -0.003463601227849722, 0.03193461149930954, 0.0307523962110281, 0.06427613645792007, -0.00783616118133068, -0.020651815459132195, -0.023755256086587906, 0.0036732887383550406, 0.013911038637161255, -0.045880455523729324, -0.0018767468864098191, 0.014764728955924511, 0.013353853486478329, -0.014542204327881336, 0.04475902020931244, 0.016353122889995575, -0.00577158248052001, 0.05750292167067528, -0.04427804797887802, -0.029819922521710396, -0.005554378964006901, -0.025254469364881516, -0.04002460837364197, 0.02938842959702015, -0.06022825837135315, 0.010571174323558807, -0.03184887394309044, 0.02918277680873871, 0.04583357647061348, 0.011744670569896698, -0.03116370551288128, -0.010462396778166294, -0.009320853278040886, 0.036729227751493454, -0.001520541263744235, -0.016667773947119713, 0.038271043449640274, -0.02247503772377968, -0.0031607935670763254, -0.06023648753762245, 0.06289619207382202, 0.01126797217875719, 0.02307816408574581, 0.016908491030335426, 0.042239196598529816, -0.012663188390433788, 0.027109023183584213, 0.01393864955753088, 0.0019930016715079546, -0.024996405467391014, 0.017160123214125633, -0.050664566457271576, -0.022822052240371704, 0.05691588297486305, 0.07219100743532181, -0.028469685465097427, -0.029127873480319977, -0.019459959119558334, -0.02716577611863613, 0.0032915938645601273, 0.0028940143529325724, 0.005857258103787899, 0.016627276316285133, -0.005551534704864025, 0.035626139491796494, 0.03498048335313797, -0.014587613753974438, 0.03824020177125931, 0.021102629601955414, 0.0033264877274632454, -0.001187724294140935, 0.042750388383865356, -0.03959280997514725, 0.012924090959131718, -0.0023573937360197306, 0.020383378490805626, -0.05894330143928528, -0.0014743255451321602, -0.006359975319355726, 0.028704972937703133, 0.06229708343744278, -0.060460321605205536, -0.018033670261502266, 0.026818914338946342, 0.046368759125471115, -0.013851208612322807, 0.027056531980633736, 0.004917423706501722, -0.02710805833339691, 0.010132068768143654, -0.004026522394269705, -0.014958787709474564, -0.01571814715862274, -0.0375625379383564, -0.013960551470518112, -0.02639061026275158, 0.03033631294965744, 0.021102113649249077, 0.0037476965226233006, 0.034368980675935745, -0.011040077544748783, 0.04102563112974167, -0.01788882538676262, -0.002590898424386978, -0.003546634688973427, -0.014957048930227757, 0.025789158418774605, 0.011478140950202942, 0.009459392167627811, 0.029192550107836723, -0.003008302766829729, 0.0034196292981505394, 0.014307926408946514, -0.004968285094946623, -0.03771108016371727, -0.020972665399312973, -0.03795613721013069, 0.013021064922213554, -0.027311481535434723, 0.047529350966215134, 0.00727958045899868, -0.04170450568199158, -0.03127222880721092, 0.04523226246237755, 0.019678333774209023, 0.03523683920502663, -0.00628700153902173, -0.04337740316987038, 0.0023486025165766478, -0.002308979630470276, -0.04484856501221657, -0.00033415635698474944, 0.028110798448324203, 0.0025322288274765015, 0.030481349676847458, 0.017089348286390305, -0.014445502310991287, -0.0315377451479435, 0.02663854882121086, 0.017555249854922295, -0.06782747060060501, -0.009432757273316383, -0.013334707356989384, 0.0029836460016667843, -0.0046227360144257545, 0.04040404036641121, -0.011107631959021091, -0.024980496615171432, -0.015754081308841705, 0.0231508556753397, -0.037834662944078445, -0.0012480545556172729, 0.03921610116958618, -0.026967845857143402, 0.02992985025048256, -0.012135655619204044, -0.0067579252645373344, 0.006125140003859997, -0.0009103571646846831, 0.012839524075388908, -0.011942727491259575, 0.0471760518848896, 0.06230900436639786, -0.05194453150033951, 0.030126620084047318, 0.01052060816437006, 0.016579139977693558, -0.0031056704465299845, -0.02140570618212223, 0.03236338496208191, -0.014408702030777931, -0.020496847108006477, 0.021621203050017357, -0.03722376748919487, 0.04999411851167679, 0.023735063150525093, 0.032593388110399246, 0.00671562273055315, -0.004922898486256599, -0.030274776741862297, 0.034523751586675644, -0.018785903230309486, -0.04877125844359398, 0.009401125833392143, -0.05482413247227669, -0.02856823243200779, -0.052366383373737335, -0.020399414002895355, 0.004342986270785332, -0.02507089450955391, 0.006284349597990513, 0.00044804177014157176, -0.007353940978646278, -0.004745057784020901, 0.06482154875993729, 0.011990618892014027, -0.01005147397518158, -0.06254324316978455, 0.018994165584445, 0.03667948767542839, 0.0068349093198776245, 0.015963111072778702, 0.017279013991355896, 0.016976207494735718, 0.0372496023774147, 0.05275614187121391, 0.009592132642865181, 0.021717164665460587, 0.04965437203645706, -0.03847651928663254, -0.029671799391508102, -0.00962176825851202, -0.003664429532364011, 0.008346842601895332, 0.002364689251407981, 0.035723209381103516, 0.017415212467312813, -0.02981630526483059, 0.02294037491083145, -0.0464579313993454, -0.0027470604982227087, 0.04001682624220848, -0.0008684481144882739, -0.01981361210346222, 0.05067838355898857, 0.02825765684247017, -0.011952213011682034, -0.021718183532357216, -0.007304700091481209, 0.04935882240533829, 0.00025611164164729416, 0.05950097739696503, 0.036383505910634995, -0.010968669317662716, -0.011996555142104626, 0.032757923007011414, -0.047019969671964645, -0.006677752360701561, 0.02394278533756733, -0.005603670608252287, 0.030888011679053307, -0.003913680091500282, -0.02563077211380005, 0.011286619119346142, 0.03389584645628929, 0.01415954064577818, -0.004872344434261322, -0.029229290783405304, 0.03142985329031944, 0.002942326245829463, 0.011240082792937756, 0.004550086334347725, 0.05788835510611534, -0.01951936073601246, 0.05810057371854782, 0.03391934186220169, 0.04160529002547264, 0.05829673632979393, -0.026744544506072998, -0.04244454205036163, 0.03781548887491226, 0.03623925894498825, -0.015668043866753578, 0.03519922494888306, 0.00005457844235934317, -0.002670763758942485, -0.030726486817002296, -0.016218973323702812, 0.032124634832143784, -0.038412824273109436, 0.02114677056670189, 0.03845648095011711, -0.016086045652627945, 0.027620406821370125, -0.014904131181538105, 0.04087004438042641, 0.016553519293665886, 0.007926281541585922, -0.017902592197060585, 0.008138787932693958, 0.024654461070895195, 0.048102665692567825, 0.023843582719564438, 0.049474459141492844, -0.04614773765206337, 0.03680387884378433, 0.05896136909723282, 0.0212649405002594, 0.044034410268068314, -0.019288862124085426, -0.004524321295320988, 0.01239634957164526, -0.03162437677383423, 0.008714704774320126, 0.005504434462636709, -0.005712499376386404, -0.005585259757936001, 0.011871756985783577, -0.04454899579286575, -0.03184128552675247, 0.0011739896144717932, -0.003771225456148386, 0.008880377747118473, 0.005015220958739519, -0.03838834539055824, 0.0012900173896923661, 0.03296162933111191, -0.016223503276705742, -0.08815951645374298, -0.0019266182789579034, -0.012317550368607044, 0.015334848314523697, -0.01944873295724392, -0.005668224301189184, -0.0020929058082401752, 0.021016687154769897, -0.001886269892565906, -0.005046000704169273, -0.009123031981289387, 0.026253584772348404, 0.0007335336995311081, 0.01517287828028202, 0.025371208786964417, -0.054864782840013504, 0.010297025553882122, 0.007532313000410795, 0.012203147634863853, 0.004606609232723713, 0.05220756307244301, -0.018513906747102737, -0.007601525168865919, -0.0025964295491576195, -0.047517500817775726, -0.00930751021951437, -0.030738292261958122, 0.025235531851649284, 0.02133711241185665, 0.04592481628060341, -0.032225366681814194, 0.002833106555044651, -0.01843336783349514, -0.026196718215942383, -0.015141448937356472, -0.009999704547226429, 0.02794681116938591, -0.0300050750374794, 0.0141080841422081, -0.006907030940055847, -0.03834697976708412, -0.022944213822484016, 0.02219627983868122, 0.02675298973917961, 0.02067202888429165, -0.02112416736781597, -0.05594322085380554, 0.03449351713061333, 0.013237293809652328, 0.0071814656257629395, 0.026800325140357018, -0.010973026975989342, -0.007433227263391018, -0.02959844097495079, 0.043597400188446045, -0.03648265451192856, 0.012575866654515266, 0.015926726162433624, -0.024611342698335648, -0.01999516785144806, -0.016034085303544998, -0.006152310874313116, 0.013289821334183216, -0.03693418949842453, 0.03129180893301964, -0.016012191772460938, -0.002139223972335458, -0.002233880339190364, -0.039330340921878815, 0.02099592611193657, -0.027453826740384102, 0.020639153197407722, 0.03756864741444588, -0.010652909055352211, -0.001280963304452598, 0.03214752674102783, 0.009146830067038536, 0.031174777075648308, -0.006938290316611528, -0.007799201179295778, -0.03369002416729927, 0.001274195034056902, -0.022438785061240196, -0.010344062000513077, 0.021076608449220657, 0.04548005759716034, -0.02350897341966629, -0.008957406505942345, 0.051435649394989014, 0.003061150899156928, -0.009378130547702312, 0.019488247111439705, 0.016849415376782417, -0.02544841170310974, 0.0443287156522274, 0.030629906803369522, -0.023836631327867508, -0.04276596009731293, 0.010058656334877014, 0.03373124450445175, 0.052796054631471634, 0.06671442091464996, 0.020610956475138664, 0.00746244378387928, -0.05230654776096344, 0.005169577430933714, -0.004450671840459108, -0.0069064004346728325, -0.02765001356601715, 0.011184398084878922, 0.042191728949546814, -0.016441961750388145, 0.007057587616145611, 0.044677428901195526, 0.024816958233714104, -0.02327098324894905, -0.0012885808246210217, -0.009961098432540894, -0.013608533889055252, -0.035320814698934555, 0.001837915857322514, -0.001116198836825788, 0.03196539729833603, 0.011591406539082527, 0.03580983355641365, -0.0040938095189630985, 0.01730242557823658 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
More scripts As each ported group of models has its own nuances, I made dedicated scripts to each one of them, so that it will be easy to re-build things in the future or to create new scripts to convert new models. You will find all the conversion, evaluation, and other scripts [here](https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/scripts/fsmt/).
[ 0.027263524010777473, 0.012547065503895283, 0.026422401890158653, -0.036899738013744354, 0.06506422907114029, 0.04626806825399399, 0.032971467822790146, 0.01857803575694561, -0.0184592567384243, -0.06724626570940018, -0.09371021389961243, 0.07647495716810226, -0.02626030147075653, 0.012889165431261063, 0.012278597801923752, -0.023878097534179688, 0.0027771079912781715, -0.011789019219577312, -0.02936183102428913, 0.026154113933444023, 0.03791307657957077, -0.09342959523200989, 0.03151490539312363, 0.007963732816278934, -0.03338528797030449, -0.051010943949222565, 0.02065468579530716, 0.012343763373792171, -0.04410182684659958, 0.06097932159900665, -0.11954882740974426, -0.018599828705191612, -0.07065703719854355, -0.004732639528810978, -0.029228130355477333, 0.0007003435166552663, -0.10999056696891785, 0.028298648074269295, -0.003690023673698306, -0.02184046246111393, 0.0027620624750852585, -0.017605960369110107, -0.04237199202179909, 0.010523688979446888, 0.027423707768321037, 0.014114071615040302, -0.21124668419361115, 0.04508974775671959, -0.023152360692620277, -0.055056434124708176, -0.03342235088348389, 0.05226695537567139, -0.029055902734398842, 0.0005981803988106549, 0.031199248507618904, -0.012637774460017681, 0.0158854927867651, -0.03132058307528496, 0.00801385473459959, 0.013376522809267044, 0.03450221195816994, 0.003220159327611327, 0.047076769173145294, 0.10257194936275482, 0.07472100853919983, 0.010176685638725758, -0.0416569784283638, 0.016489025205373764, -0.04320943355560303, -0.043128326535224915, 0.020628612488508224, -0.01307081338018179, 0.0025991343427449465, -0.024102425202727318, 0.04041743278503418, -0.021962083876132965, -0.015585275366902351, 0.00851158145815134, 0.05842476710677147, 0.034930720925331116, 0.023870714008808136, -0.023526400327682495, 0.03812836483120918, 0.06573290377855301, -0.0014768546679988503, -0.007457208354026079, 0.07752550393342972, -0.032307542860507965, -0.049650032073259354, 0.07255513221025467, 0.013797840103507042, -0.11544689536094666, -0.039463646709918976, 0.0333118699491024, 0.08373858779668808, -0.023089362308382988, 0.01011442206799984, 0.022109035402536392, 0.031030911952257156, 0.015577595680952072, 0.0010723592713475227, -0.012224539183080196, -0.005134588573127985, -0.05038062483072281, -0.009415093809366226, -0.04747706279158592, -0.008856236934661865, -0.09617948532104492, -0.015914395451545715, 0.009057607501745224, 0.007197740022093058, -0.05740838125348091, 0.03960423916578293, 0.05930112302303314, -0.013933099806308746, 0.018779251724481583, -0.0026456061750650406, -0.051370684057474136, -0.026176458224654198, 0.026067649945616722, 0.04972304776310921, 0.059030476957559586, 0.024703994393348694, 0.00433318829163909, 0.04415157437324524, 0.08160114288330078, 0.04439277946949005, 0.02387995645403862, -0.025057177990674973, -0.05493808165192604, 0.029857415705919266, -0.01715313084423542, 0.06192967668175697, 0.020660188049077988, 0.015486203134059906, -0.12521716952323914, -0.025613835081458092, -0.047445300966501236, 0.017345763742923737, 0.010711785405874252, -0.010842896066606045, 0.0784464031457901, -0.020257050171494484, 0.03730788081884384, 0.02158566378057003, -0.0370531789958477, -0.10186413675546646, 0.0694848895072937, -0.05117318034172058, 0.07472624629735947, -0.07125462591648102, 0.036343201994895935, -0.024320388212800026, -0.02378891222178936, -0.0027399538084864616, 0.0837058275938034, -0.02728068083524704, -0.04499111697077751, -0.05550428852438927, -0.02543683536350727, -0.012834656052291393, -0.010283921845257282, -0.035762686282396317, -0.0005138518172316253, 0.014236127026379108, -0.043734919279813766, -0.024073485285043716, 0.03194502741098404, 0.010360711254179478, -0.020138274878263474, 0.03959345072507858, -0.058885060250759125, 0.0527973398566246, -0.029948744922876358, -0.004815876483917236, 0.04063066840171814, 0.08329792320728302, 0.0665016770362854, 0.03503205627202988, -0.004625590052455664, -0.041217803955078125, 0.036739543080329895, -0.01240525022149086, 0.04718298837542534, 0.03837432339787483, -0.06809493899345398, 0.00039201165782287717, -0.011111797764897346, -0.03302431479096413, 0.04510458931326866, -0.05680068954825401, -0.013628487475216389, 0.0894501656293869, 0.014455068856477737, 0.0299490038305521, -0.05066327378153801, -0.03962460160255432, 0.1513603925704956, 0.06590632349252701, 0.06312360614538193, 0.020188627764582634, 0.027681661769747734, -0.001608624355867505, -0.01982082612812519, -0.004007513169199228, 0.05064207687973976, 0.042908620089292526, -0.03488650172948837, 0.017437294125556946, 0.0007226938614621758, 0.02751428633928299, -0.08880326896905899, 0.023562248796224594, -0.06557048112154007, 0.04189247637987137, -0.08721083402633667, -0.08347809314727783, -0.020262347534298897, -0.01087032537907362, -0.05836322903633118, 0.14157478511333466, -0.024618273600935936, -0.03109983168542385, -0.0370950773358345, -0.03576699271798134, 0.05749409645795822, 0.053449343889951706, 0.07089761644601822, 0.0721498653292656, -0.06683070957660675, 0.02087351866066456, -0.04321576654911041, -0.024603160098195076, 0.03803287073969841, 0.009956644847989082, -0.034495286643505096, 0.0389120951294899, -0.013988737016916275, -0.03935614228248596, -0.04467565938830376, -0.00781335774809122, 0.010170679539442062, 0.058143701404333115, 0.024191666394472122, 0.013790764845907688, 0.0007392942206934094, 0.03660073131322861, 0.04558957740664482, -0.011143605224788189, -0.01542404294013977, -0.06401662528514862, 0.07600023597478867, 0.009745972231030464, -0.05044640973210335, 0.032148364931344986, 0.009889276698231697, 0.008933774195611477, 0.000929186528082937, -0.05904420465230942, 0.06828022748231888, 0.009376118890941143, 0.0011522697750478983, -0.06295443326234818, -0.03537670150399208, -0.019031841307878494, -0.06960473209619522, -0.00873467419296503, 0.009608612395823002, -0.01267235353589058, 0.03036937303841114, 0.0030752012971788645, -0.008321277797222137, -0.006914882455021143, 0.00293828547000885, 0.019306393340229988, 0.020983189344406128, 0.065064936876297, -0.012599242851138115, -0.033455993980169296, -0.007162392605096102, 0.007571169640868902, -0.04549916833639145, 0.01666850596666336, 0.04804566875100136, 0.001818559831008315, -0.00852157548069954, -0.006991236936300993, -0.0056910282000899315, -0.03763454034924507, 0.027365395799279213, 0.009889976121485233, 0.03260548785328865, -0.01958906464278698, -0.042518120259046555, -0.03448264300823212, -0.0023604808375239372, 0.0027474495582282543, -0.011935826390981674, -0.02189568243920803, 0.052548810839653015, -0.0031360627617686987, 0.03271561861038208, -0.018147798255085945, -0.0025880017783492804, -0.015920933336019516, 0.053801313042640686, 0.0015627422835677862, 0.011816466227173805, -0.11151199787855148, -0.00680560152977705, -0.02986964024603367, 0.05907071754336357, -0.0014245151542127132, -0.022704031318426132, 0.01479498203843832, -0.037699535489082336, 0.016972418874502182, 0.03481744974851608, 0.020556556060910225, -0.010248113423585892, 0.059931326657533646, -0.0029046263080090284, -0.027318086475133896, 0.00390334939584136, -0.028940148651599884, 0.023784440010786057, 0.026030173525214195, 0.013158399611711502, -0.009101010859012604, 0.0022733465302735567, -0.0069740209728479385, -0.021975025534629822, 0.0032616942189633846, -0.00033061247086152434, 0.06948904693126678, 0.028016693890094757, 0.023224463686347008, -0.05731188505887985, -0.007729513105005026, 0.025271225720643997, -0.02683515101671219, 0.00043679948430508375, -0.016815518960356712, -0.02225424535572529, -0.020510884001851082, 0.03099019266664982, 0.010943416506052017, 0.02069525234401226, 0.044984206557273865, 0.0133048165589571, 0.0069552273489534855, 0.018992535769939423, 0.0054410360753536224, -0.009554729796946049, 0.008453570306301117, 0.04134277626872063, -0.0032811197452247143, 0.009412174113094807, -0.0009565747459419072, -0.020118221640586853, 0.00043965427903458476, 0.036359772086143494, 0.01500201877206564, 0.02066429890692234, 0.011964647099375725, 0.02982018142938614, 0.0319487638771534, -0.029835795983672142, -0.042990706861019135, 0.015032581053674221, -0.025721000507473946, -0.03118373267352581, -0.04523659870028496, 0.06883316487073898, -0.010745351202785969, 0.03204086795449257, -0.007661776151508093, 0.04059186577796936, -0.02391446754336357, 0.02634032815694809, 0.017694268375635147, 0.008382463827729225, -0.05692588537931442, 0.010347445495426655, -0.053646039217710495, -0.03848882392048836, 0.05301648750901222, 0.01121536549180746, -0.008430061861872673, -0.014999233186244965, -0.02209707535803318, 0.010214092209935188, 0.0030747889541089535, 0.02316904067993164, 0.03537408635020256, 0.0036505935713648796, 0.01845634914934635, 0.03473936766386032, 0.03197639063000679, -0.013689477927982807, 0.045656196773052216, -0.018381915986537933, -0.005174425896257162, 0.016849452629685402, 0.015750505030155182, 0.002271810779348016, -0.0027628818061202765, 0.028216643258929253, 0.03406008332967758, -0.06620150059461594, 0.005803081672638655, 0.018392758443951607, -0.006711594294756651, 0.013933406211435795, -0.022754713892936707, -0.031196292489767075, 0.016346914693713188, 0.006030984688550234, -0.0035481026861816645, 0.003218109719455242, -0.00048490209155716, -0.025267567485570908, 0.028908642008900642, 0.036853838711977005, -0.012435018084943295, -0.004919502884149551, -0.045343853533267975, 0.0020108427852392197, -0.01309502124786377, 0.03311479836702347, -0.014279753901064396, 0.006157794035971165, 0.02577827498316765, 0.0094711072742939, 0.020337585359811783, 0.04132748022675514, 0.008318180218338966, 0.03469181805849075, 0.003089348552748561, -0.0015464139869436622, 0.02698567695915699, 0.040958307683467865, 0.005968824494630098, 0.04225888103246689, -0.02558344602584839, -0.0042448146268725395, 0.004902204964309931, -0.05800324305891991, -0.01154204923659563, 0.0021019906271249056, 0.0061669908463954926, -0.009178856387734413, 0.012925537303090096, 0.014443048276007175, -0.02942573092877865, 0.0037247107829898596, -0.042088598012924194, 0.05645473301410675, 0.023527754470705986, -0.014942040666937828, -0.07032368332147598, -0.00004592208279063925, 0.01144100446254015, -0.0015699121868237853, -0.02682597190141678, -0.008417597971856594, -0.006474383641034365, 0.04966917634010315, -0.025512149557471275, 0.036555252969264984, -0.043638672679662704, 0.02554894983768463, -0.002660489408299327, 0.024170085787773132, -0.018343769013881683, -0.08558710664510727, -0.011707422323524952, 0.020530832931399345, -0.028350163251161575, -0.026510266587138176, 0.007984130643308163, -0.023422634229063988, 0.009064250625669956, 0.08304701745510101, 0.033759601414203644, 0.02501361258327961, 0.013642175123095512, -0.012720804661512375, -0.03090866468846798, 0.01143734809011221, 0.019817963242530823, -0.020532719790935516, 0.003360695205628872, 0.04039021208882332, 0.024693116545677185, 0.05536084622144699, -0.0012312080943956971, 0.0395495630800724, 0.0050094351172447205, 0.007931295782327652, 0.022506188601255417, -0.006461357697844505, -0.008881895802915096, -0.012340215034782887, 0.044783201068639755, -0.001116595696657896, -0.02575935609638691, -0.00027330988086760044, 0.03992057591676712, 0.04348389431834221, -0.034549009054899216, -0.049604400992393494, 0.03984227031469345, 0.007688453420996666, -0.03249906748533249, -0.03401656076312065, 0.0421573631465435, -0.03283720836043358, 0.006769314408302307, 0.019712677225470543, -0.03484737128019333, -0.022971978411078453, 0.019276995211839676, -0.0478026419878006, -0.026766857132315636, -0.006016280967742205, 0.022964300587773323, 0.024705123156309128, -0.03617069497704506, -0.006690898910164833, -0.046792805194854736, 0.021411970257759094, 0.02169160544872284, -0.03427371010184288, -0.011569430120289326, -0.024021096527576447, 0.007547192275524139, -0.012237489223480225, 0.03314313665032387, 0.010891564190387726, -0.03046228177845478, 0.009949387051165104, 0.019905297085642815, 0.01847461424767971, -0.08135652542114258, 0.012529924511909485, 0.03267522528767586, -0.029169665649533272, 0.014603693969547749, -0.010020476765930653, -0.047772884368896484, -0.004140076693147421, -0.05275135487318039, 0.018060114234685898, 0.06377416104078293, 0.011396532878279686, 0.004106556531041861, 0.041216567158699036, 0.03261607140302658, 0.016479473561048508, -0.0030443486757576466, 0.010739785619080067, -0.006121938116848469, 0.003825819119811058, 0.012165003456175327, 0.05833474546670914, 0.0006188057595863938, -0.024065539240837097, 0.0314921997487545, -0.014004799537360668, -0.024086114019155502, -0.003007458755746484, -0.03693821653723717, 0.0406789630651474, -0.015088471584022045, -0.04119203984737396, 0.01460268720984459, 0.02667298913002014, 0.012758396565914154, 0.06989534944295883, 0.024374889209866524, 0.02279934287071228, -0.0005987164913676679, -0.04914465546607971, 0.01732412725687027, 0.035060010850429535, 0.03663317486643791, 0.006293367128819227, 0.021052327007055283, 0.030042152851819992, 0.04338176175951958, 0.015444513410329819, 0.05978584662079811, -0.012946139089763165, 0.08893319964408875, -0.01930149272084236, 0.02696760930120945, 0.047078341245651245, -0.01441980805248022, -0.02612927183508873, -0.04793741926550865, -0.03700363636016846, -0.03615644946694374, -0.0015644815284758806, 0.021810144186019897, -0.0019695907831192017, 0.0023566505406051874, -0.03820600360631943, 0.0408746562898159, 0.013860720209777355, 0.03362776339054108, -0.0015725159319117665, 0.0239027738571167, 0.008655592799186707, -0.005824017338454723, -0.015873605385422707, 0.025313161313533783, 0.026808423921465874, -0.021622352302074432, 0.0504421703517437, -0.013405045494437218, 0.005725611001253128, 0.010245156474411488, 0.014015588909387589, 0.034247808158397675, -0.02659684419631958, 0.0061383056454360485, -0.018076138570904732, -0.010236375033855438, -0.028128646314144135, -0.019229060038924217, -0.022502347826957703, -0.03810694441199303, -0.002689794171601534, 0.002392415888607502, 0.00004522411109064706, -0.04860860854387283, -0.014934479258954525, -0.023743823170661926, 0.03618376702070236, -0.009971223771572113, -0.01905055344104767, -0.008180875331163406, 0.006097074132412672, 0.024357810616493225, 0.016848014667630196, -0.014221856370568275, 0.005393526051193476, -0.03596236929297447, -0.004147427622228861, 0.02966291457414627, 0.044266097247600555, -0.01349271647632122, -0.018542150035500526, -0.0006274090264923871, 0.025984426960349083, 0.0130399065092206, 0.037483952939510345, 0.006856297608464956, 0.012853637337684631, -0.05564316362142563, 0.009470419958233833, -0.001121800160035491, -0.025098342448472977, -0.01228685025125742, -0.06042672321200371, -0.005857554264366627, -0.01114219892770052, 0.01475454494357109, 0.011038071475923061, 0.019153574481606483, -0.04198528826236725, -0.019464513286948204, -0.0072321100160479546, -0.03761054947972298, -0.013818148523569107, 0.04854898154735565, -0.002508541801944375, -0.008153751492500305, 0.024866359308362007, -0.013954125344753265, 0.0022021520417183638, -0.029844855889678, -0.008746680803596973, 0.011372257955372334, 0.014210335910320282, -0.04422501102089882, 0.016471320763230324, 0.08303363621234894, 0.03340505436062813, 0.030165042728185654, 0.013851569965481758, 0.03183193877339363, 0.00560795096680522, -0.052057377994060516, 0.005153450649231672, 0.01503329910337925, 0.010490555316209793, -0.03841564059257507, -0.03932856395840645, -0.020429207012057304, -0.008967237547039986, -0.0036575603298842907, -0.010194637812674046, -0.05481654405593872, -0.01677083596587181, -0.012421908788383007, -0.03336777538061142, -0.019353777170181274, 0.04059327021241188, 0.058006349951028824, 0.03535185381770134, -0.015644779428839684, -0.0059534101746976376, -0.029229752719402313, 0.027968937531113625, -0.02121523767709732, 0.029797475785017014, 0.044248923659324646, 0.03587344288825989, -0.012008429504930973, -0.007264875341206789, 0.021142233163118362, -0.006043991539627314, -0.05376525968313217, -0.012003195472061634, 0.029150579124689102, -0.01969415321946144, -0.011801580898463726, 0.004646276589483023, -0.00002027666960202623, 0.011323191225528717, 0.043105632066726685, 0.008887811563909054, 0.007895064540207386, -0.028098082169890404, 0.0204448401927948, -0.05318490415811539, 0.012746398337185383, -0.010185778141021729, 0.013904397375881672, 0.004642770159989595, 0.02659093402326107, 0.020566757768392563, -0.00931813009083271, -0.053865980356931686, 0.045481760054826736, -0.021284781396389008, -0.005733355414122343, -0.005851703695952892, -0.023531604558229446, 0.03685856983065605, -0.008441568352282047, -0.08224043250083923, 0.0329083688557148, 0.0007149023585952818, -0.034686289727687836, 0.00906459242105484, 0.01947934366762638, 0.010126776061952114, -0.04707539081573486, 0.016660865396261215, -0.045675769448280334, 0.003963473718613386, 0.02328287810087204, -0.012464276514947414, -0.027118677273392677, -0.002487229648977518 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Autoprint all in Jupyter Notebook My jupyter notebook is configured to automatically print all expressions, so I don't have to explicitlyprint()them. The default behavior is to print only the last expression of each cell. So if you read the outputs in my notebooks they may not the be same as if you were to run them yourself, unless you have the same setup. You can enable the print-all feature in your jupyter notebook setup by adding the following to~/.ipython/profile_default/ipython_config.py(create it if you don't have one): ``` c = get_config() # Run all nodes interactively c.InteractiveShell.ast_node_interactivity = "all" # restore to the original behavior # c.InteractiveShell.ast_node_interactivity = "last_expr" ``` and restarting your jupyter notebook server.
[ 0.002513064304366708, 0.08254494518041611, 0.04995647445321083, -0.01911693438887596, 0.06270842254161835, -0.024814344942569733, -0.009262721985578537, -0.012753954157233238, -0.03273796662688255, -0.008434155955910683, -0.09871380031108856, -0.0029180755373090506, 0.0008823216776363552, 0.055832330137491226, 0.012309725396335125, 0.0326601080596447, -0.006560516078025103, 0.010850482620298862, 0.06557771563529968, 0.05498286709189415, 0.056820098310709, -0.0032308471854776144, 0.04249102249741554, 0.03351661562919617, 0.00992798712104559, -0.07327557355165482, 0.0018994372803717852, 0.027302125468850136, -0.09713684767484665, -0.03157602995634079, -0.1140209287405014, 0.02128242887556553, 0.0478309728205204, 0.061389680951833725, -0.008242141455411911, -0.043222688138484955, -0.08152534067630768, 0.060505159199237823, 0.05024169757962227, -0.028698960319161415, 0.023992391303181648, -0.08488331735134125, -0.01217642892152071, -0.003089773701503873, -0.02389271929860115, -0.005812481511384249, -0.1866178810596466, 0.08979592472314835, 0.0038357486482709646, 0.04172991216182709, -0.04971593990921974, 0.058907780796289444, -0.021761411800980568, -0.007154420483857393, -0.07025033980607986, -0.026619505137205124, 0.0491582415997982, 0.004571541212499142, 0.024745788425207138, 0.002047081245109439, 0.025751959532499313, -0.032983776181936264, 0.007277118973433971, 0.10112838447093964, 0.02872384898364544, -0.009529751725494862, 0.005767911206930876, 0.02501942403614521, -0.06596869975328445, -0.019053054973483086, -0.08565650880336761, -0.0516979917883873, 0.004653959535062313, -0.019432689994573593, 0.08185893297195435, -0.05575062707066536, -0.026831990107893944, -0.02074398472905159, -0.02946893870830536, 0.0457669198513031, 0.03068174049258232, 0.02159309946000576, 0.009321663528680801, 0.053407661616802216, 0.06677762418985367, -0.028931815177202225, -0.04104498773813248, -0.0016619834350422025, -0.0005440296372398734, 0.023656336590647697, 0.027005651965737343, -0.14069834351539612, -0.02992766723036766, 0.0195197444409132, -0.030772916972637177, -0.03938601538538933, 0.01471778191626072, 0.009432719089090824, -0.025783566758036613, -0.005122673697769642, 0.0013459788169711828, -0.07062014192342758, 0.04005245864391327, -0.05780208110809326, -0.1298183649778366, 0.03407638892531395, -0.06858715415000916, -0.025975249707698822, -0.012901607900857925, 0.01254788413643837, -0.04948471486568451, 0.013009644113481045, -0.018804868683218956, 0.04441000148653984, -0.09490615874528885, 0.09874383360147476, 0.022986670956015587, 0.029321197420358658, -0.03891599550843239, -0.08516691625118256, 0.0030977807473391294, 0.05047360435128212, 0.12804481387138367, 0.019183604046702385, 0.028265278786420822, 0.017003139480948448, -0.0255736093968153, -0.00017020470113493502, 0.04632501304149628, -0.04114442691206932, 0.0501670204102993, 0.0582767054438591, 0.06955581158399582, -0.005088111851364374, -0.014793261885643005, -0.07257554680109024, 0.020823094993829727, -0.03352605924010277, 0.07557385414838791, 0.02607841230928898, -0.061037577688694, 0.06411300599575043, 0.02065255679190159, 0.06379315257072449, -0.016711808741092682, -0.0009907784406095743, -0.03604721650481224, 0.020402828231453896, -0.041741739958524704, 0.025355728343129158, -0.05985105782747269, -0.015172322280704975, 0.004619263578206301, -0.08182055503129959, 0.015390891581773758, -0.006047483999282122, 0.009381163865327835, 0.020867783576250076, -0.09942883253097534, -0.006656324025243521, 0.058792274445295334, 0.021193187683820724, 0.04636279493570328, 0.0041772183030843735, -0.002553235739469528, 0.0077180624939501286, 0.05602633208036423, 0.004363246262073517, 0.10539622604846954, -0.02351907640695572, -0.0035475711338222027, -0.07014968246221542, 0.053833138197660446, -0.056931305676698685, 0.04169212281703949, -0.0032071599271148443, 0.018122512847185135, -0.007301404140889645, 0.03788955882191658, 0.009305230341851711, -0.019348789006471634, 0.03186239302158356, -0.10069756209850311, 0.038535017520189285, 0.018738722428679466, -0.03659139946103096, -0.011671700514853, -0.01828947104513645, 0.08327337354421616, 0.008687697350978851, -0.039912935346364975, -0.00932252872735262, 0.0815073549747467, -0.007970292121171951, 0.03898324817419052, -0.042984072118997574, -0.04836582392454147, 0.08792231231927872, 0.039180271327495575, 0.009685702621936798, -0.012584737502038479, 0.0219133123755455, 0.027278080582618713, 0.010636700317263603, 0.0366801917552948, 0.038078200072050095, 0.005507170222699642, -0.06005193665623665, 0.06738822162151337, -0.00823739543557167, -0.05665106326341629, -0.02852235734462738, 0.01576554961502552, -0.03783867135643959, -0.03954365476965904, -0.04199543967843056, 0.012007149867713451, 0.02114800736308098, 0.017372330650687218, 0.016526345163583755, 0.1346009224653244, -0.01598469726741314, 0.06272919476032257, 0.013907569460570812, -0.07798769325017929, 0.029809249565005302, 0.04373222962021828, 0.06047441437840462, -0.012778274714946747, 0.0012494957773014903, -0.08108679205179214, -0.0821160301566124, 0.0068656266666948795, 0.052582915872335434, -0.019662445411086082, -0.04102255776524544, -0.016451522707939148, -0.0018192223506048322, 0.017676113173365593, -0.06039317324757576, 0.06411807239055634, 0.017126141116023064, 0.017734389752149582, 0.030469175428152084, -0.010622174479067326, 0.022016195580363274, 0.06275829672813416, 0.048464372754096985, -0.08906853199005127, -0.0037788550835102797, 0.007366088218986988, -0.005575728602707386, -0.029302529990673065, -0.03667258471250534, 0.03272795304656029, 0.06931749731302261, -0.00026648127823136747, 0.006285016890615225, 0.003742275992408395, 0.03814316540956497, -0.04797317832708359, -0.022361449897289276, 0.0038938780780881643, -0.050474923104047775, -0.04079534113407135, 0.0008102805586531758, 0.022098209708929062, -0.01757964678108692, -0.003982055466622114, 0.03892825171351433, 0.02873401902616024, -0.03003806434571743, 0.009981540963053703, 0.007744982838630676, 0.014626678079366684, -0.007122147362679243, 0.014535639435052872, -0.034268639981746674, -0.004079824313521385, 0.017070956528186798, 0.033553529530763626, -0.031169891357421875, -0.01453941036015749, 0.03442801535129547, 0.005797583609819412, 0.013458251021802425, 0.028665926307439804, -0.0031277078669518232, -0.0021520189475268126, 0.02052478678524494, 0.002538136439397931, 0.05810196325182915, 0.028532667085528374, 0.0016884790966287255, 0.00876674149185419, 0.021534575149416924, -0.02720577083528042, -0.012608672492206097, 0.013967819511890411, 0.018788939341902733, -0.004115242976695299, -0.0022900993935763836, 0.012029193341732025, -0.008368191309273243, -0.042265575379133224, 0.035581111907958984, 0.0072779874317348, 0.006572728976607323, -0.11111411452293396, -0.03244183585047722, 0.03638818487524986, 0.015195460990071297, 0.0065020602196455, -0.014770399779081345, 0.022214679047465324, -0.015451795421540737, 0.0030450548510998487, -0.03045646846294403, -0.00004172565968474373, 0.005405918229371309, -0.012800796888768673, 0.025035522878170013, -0.009963504038751125, -0.0013175824424251914, -0.0013230940094217658, -0.004131993744522333, 0.03280796855688095, 0.05172627046704292, 0.027385437861084938, 0.0630570650100708, -0.021848272532224655, -0.025806834921240807, -0.004054726101458073, 0.017439864575862885, 0.011074716225266457, 0.0118587426841259, 0.03903146833181381, -0.005578872747719288, 0.015145686455070972, -0.038668159395456314, -0.023183029145002365, -0.019071927294135094, -0.0638408362865448, -0.03535839915275574, 0.0015966743230819702, 0.009420434944331646, -0.008782299235463142, 0.01970812678337097, -0.006900607608258724, 0.030935192480683327, 0.003790292190387845, -0.014055686071515083, -0.007815560325980186, 0.014439295046031475, -0.019591640681028366, 0.026532376185059547, 0.028744308277964592, -0.02972571738064289, -0.005804002750664949, -0.012398486025631428, 0.02316291816532612, 0.004080161452293396, 0.0021829630713909864, -0.0063537838868796825, 0.015391693450510502, 0.004014792386442423, -0.004584077745676041, -0.03006495162844658, -0.027300776913762093, -0.00023036438506096601, -0.024211734533309937, -0.014493012800812721, -0.025008929893374443, 0.0605224184691906, -0.020487895235419273, 0.03487071394920349, 0.033387113362550735, 0.03724928945302963, -0.04141322150826454, 0.0058287763968110085, 0.012354985810816288, 0.009001927450299263, 0.003867910010740161, 0.004531932063400745, -0.026210308074951172, -0.02369428612291813, 0.0456138513982296, 0.02344878576695919, -0.041109368205070496, -0.03469949588179588, 0.00019941746722906828, -0.021145133301615715, -0.021108895540237427, -0.0053190067410469055, -0.020072991028428078, -0.013590228743851185, 0.007246821653097868, 0.0316360704600811, -0.02316737174987793, -0.045136112719774246, 0.03944284841418266, -0.015802999958395958, 0.0026797372847795486, 0.027841834351420403, 0.0026663450989872217, -0.012387269176542759, 0.03006535768508911, -0.0023608210030943155, 0.006909943651407957, -0.04060043767094612, -0.014638266526162624, 0.012410151772201061, -0.0008592169033363461, 0.04789111390709877, -0.0654984563589096, -0.014809678308665752, -0.04026224464178085, -0.0008940771222114563, 0.026869259774684906, 0.007405195385217667, 0.043792471289634705, -0.03182312846183777, 0.04292621463537216, 0.05066154897212982, 0.03217386454343796, -0.03045642375946045, -0.06038297340273857, 0.042760733515024185, -0.046621233224868774, 0.019622504711151123, -0.016828486695885658, -0.014372635632753372, -0.012734312564134598, -0.016460679471492767, 0.008404591120779514, 0.002477179514244199, -0.031847547739744186, -0.034150347113609314, -0.026489846408367157, -0.030162611976265907, 0.002314275596290827, -0.03125201165676117, -0.005982613656669855, 0.025611381977796555, -0.004205947741866112, 0.026410816237330437, 0.02711196057498455, -0.04711860045790672, -0.03110223449766636, 0.01867753639817238, 0.023931819945573807, -0.01112477108836174, 0.029946820810437202, -0.008480255492031574, -0.05762716382741928, 0.01288175955414772, -0.05282388627529144, 0.009724599309265614, 0.07336948066949844, 0.038039639592170715, -0.022600406780838966, 0.005397319793701172, -0.01825224980711937, -0.010522634722292423, -0.006005947478115559, 0.012530729174613953, 0.034638404846191406, 0.06923630088567734, -0.01890813186764717, -0.0003981830959673971, 0.022444622591137886, 0.014026721008121967, -0.007300631143152714, -0.030842646956443787, -0.009922699071466923, -0.011599507182836533, 0.006472559180110693, 0.018953775987029076, -0.004810776095837355, 0.004056407604366541, 0.023684315383434296, -0.020476052537560463, 0.050002507865428925, 0.00197786558419466, 0.045623213052749634, 0.03198016807436943, 0.03736055642366409, -0.008783558383584023, -0.01044508721679449, 0.010880593210458755, 0.006864169146865606, 0.003682608250528574, -0.03509042412042618, 0.013468009419739246, -0.00526209082454443, 0.013510138727724552, -0.007397656328976154, 0.0195247121155262, 0.039401549845933914, -0.09564913809299469, 0.005652501247823238, -0.035833485424518585, 0.004842233844101429, 0.01431931834667921, 0.05057176575064659, 0.011873897165060043, -0.027371345087885857, -0.025152746587991714, 0.06078437343239784, 0.0063043395057320595, -0.013020142912864685, -0.03354419767856598, 0.051080480217933655, 0.05548911541700363, 0.03221756964921951, -0.04544183239340782, 0.04091702774167061, -0.003512625116854906, 0.03116210177540779, -0.03416921943426132, -0.025929488241672516, 0.01846952550113201, 0.041862983256578445, 0.007863465696573257, -0.03387542441487312, -0.022113725543022156, -0.03342081606388092, 0.027130842208862305, -0.0002314554003532976, 0.04284181445837021, -0.03684910759329796, 0.01927122287452221, 0.028440702706575394, -0.03792506828904152, 0.008169841021299362, -0.01281440258026123, 0.029369717463850975, 0.008566371165215969, 0.05405263975262642, 0.031211329624056816, -0.024733932688832283, -0.011085105128586292, 0.005760560743510723, 0.009594338946044445, -0.07726829499006271, 0.04865438863635063, -0.031603068113327026, 0.0005428248550742865, -0.023739473894238472, -0.0209522545337677, -0.0481538288295269, 0.03221649304032326, 0.008550453931093216, 0.004953457973897457, 0.06560157239437103, -0.018357913941144943, 0.019424917176365852, 0.033186279237270355, 0.006374351214617491, 0.02067646011710167, 0.005517949350178242, 0.002978798234835267, 0.0479816198348999, -0.033469200134277344, -0.008972563780844212, 0.0033134298864752054, 0.030196072533726692, 0.0013233119389042258, 0.01729930005967617, -0.03892478346824646, 0.0320248045027256, 0.01636524684727192, -0.0006537580047734082, 0.03724734112620354, 0.02497907355427742, -0.003770844778046012, -0.02865765057504177, 0.017017444595694542, 0.04704165831208229, 0.01876048743724823, -0.04404156282544136, 0.007488038390874863, 0.008645317517220974, -0.006567749194800854, 0.005205634515732527, 0.09075644612312317, -0.04589945077896118, 0.05571332573890686, -0.0017248442163690925, 0.07087956368923187, 0.012267320416867733, -0.012208595871925354, -0.017806680873036385, -0.03523669019341469, 0.03744139522314072, 0.014075128361582756, 0.04344990476965904, -0.00023814858286641538, 0.013048204593360424, -0.0217730849981308, -0.018540794029831886, -0.019042503088712692, 0.0016890723491087556, 0.027798794209957123, 0.05392276868224144, 0.017776280641555786, 0.009192964062094688, -0.03160887956619263, 0.04568355903029442, 0.07411174476146698, 0.013648387975990772, 0.005981707014143467, -0.007413582876324654, 0.05963802710175514, -0.014330110512673855, 0.008335404098033905, 0.008183084428310394, -0.03988565132021904, -0.005576100666075945, 0.07633047550916672, -0.008595094084739685, 0.025601625442504883, 0.01713087037205696, 0.00751925352960825, -0.00024328938161488622, -0.04869937151670456, -0.01773248426616192, 0.009637447074055672, 0.04628559947013855, -0.018770890310406685, -0.024298660457134247, 0.004900778643786907, -0.024461716413497925, 0.019359199330210686, 0.007074149791151285, -0.022170521318912506, 0.017170965671539307, -0.015677498653531075, -0.011747268959879875, 0.027290955185890198, 0.027295436710119247, -0.03733434900641441, -0.010808832943439484, 0.02194521389901638, -0.011077797040343285, -0.03847122564911842, 0.02921460196375847, -0.029395652934908867, -0.03655664622783661, 0.03520771861076355, -0.028383349999785423, 0.01741466298699379, -0.020073093473911285, -0.02836725115776062, -0.014264777302742004, 0.0077604190446436405, 0.000486707896925509, -0.001703782007098198, 0.026034479960799217, 0.03037736564874649, 0.009761733002960682, -0.006060896907001734, -0.025042960420250893, 0.00046774529619142413, 0.004290688317269087, -0.044646307826042175, 0.011161736212670803, -0.013914794661104679, -0.005781505256891251, 0.02452937327325344, -0.0404558964073658, 0.03215448185801506, -0.04178910329937935, 0.028439149260520935, -0.020777080208063126, -0.05104629322886467, -0.016523322090506554, 0.005381524562835693, -0.0013954750029370189, 0.00041354031418450177, -0.023027805611491203, -0.015936730429530144, -0.01311805471777916, -0.031670987606048584, 0.013524050824344158, -0.02184383012354374, -0.03253358602523804, 0.035405728965997696, 0.013513091951608658, -0.002607150236144662, 0.02184591442346573, 0.005966737866401672, -0.003559563774615526, 0.005399258807301521, -0.05376790836453438, -0.017802191898226738, -0.027961669489741325, 0.00904077384620905, -0.05271083861589432, -0.016517793759703636, -0.01949397288262844, -0.02684793248772621, -0.04083200916647911, 0.006058668717741966, -0.017282504588365555, 0.053848642855882645, 0.0253753624856472, -0.01813783124089241, -0.027048397809267044, -0.008370107039809227, 0.02036973088979721, 0.01896454021334648, -0.010287371464073658, 0.004551067482680082, -0.042340729385614395, 0.003984850365668535, -0.020690498873591423, -0.012397089041769505, -0.014700443483889103, 0.020989228039979935, -0.0061646574176847935, -0.0015334804775193334, -0.005212488118559122, -0.03433681279420853, -0.010215147398412228, 0.017758414149284363, -0.02530411258339882, -0.009838175028562546, -0.02318575419485569, -0.012612390331923962, 0.058216676115989685, 0.0009504508343525231, 0.0209350623190403, 0.041287172585725784, 0.0064879911951720715, -0.007323590572923422, 0.023881196975708008, -0.042000338435173035, -0.024053532630205154, 0.024695781990885735, -0.0278007835149765, 0.01572454161942005, 0.014268996194005013, 0.04092847928404808, -0.046073030680418015, -0.01854659616947174, -0.021573267877101898, 0.004267742391675711, -0.05564633756875992, -0.0455733947455883, 0.006565305404365063, 0.03370943292975426, -0.04711814969778061, -0.007474642712622881, 0.00577577156946063, -0.00244239647872746, 0.0032250615768134594, 0.0026571685448288918, 0.02429185062646866, 0.05631940811872482, 0.004960073158144951, 0.05790159851312637, 0.03794901818037033, 0.03170417249202728, 0.021419188007712364, 0.040069274604320526, 0.011391722597181797, 0.0009314386988990009 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
It's PR time Once I felt my work was quite complete, I was ready to submit my PR. Since this work involved many git commits, I wanted to make a clean PR, so I used the following technique to squash all the commits into one in a new branch. This kept all the initial commits in place if I wanted to access any of them later. The branch I was developing on was calledfair-wmt, and the new branch that I was going to submit the PR from I namedfair-wmt-clean, so here is what I did: ``` git checkout master git checkout -b fair-wmt-clean git merge --squash fair-wmt git commit -m "Ready for PR" git push origin fair-wmt-clean ``` Then I went to github and submitted this [PR](https://github.com/huggingface/transformers/pull/6940) based on thefair-wmt-cleanbranch. It took two weeks of several cycles of feedback, followed by modifications, and more such cycles. Eventually it was all satisfactory and the PR got merged. While this process was going on, I was finding issues here and there, adding new tests, improving the documentation, etc., so it was time well spent. I subsequently filed a few more PRs with changes after I improved and reworked a few features, adding various build scripts, models cards, etc. Since the models I ported were belonging tofacebookandallenaiorganizations, I had to ask Sam to move those model files from my account ons3to the corresponding organizations.
[ -0.01193308737128973, 0.0014153532683849335, 0.05351731553673744, 0.013233760371804237, 0.050536274909973145, 0.06055181846022606, 0.020359862595796585, 0.0175271388143301, 0.019348207861185074, -0.05151194706559181, -0.0394071489572525, 0.06113575026392937, -0.02063027024269104, 0.07645528018474579, -0.00863032415509224, -0.04404318705201149, 0.011030435562133789, -0.027296219021081924, -0.032104164361953735, -0.0366390086710453, 0.012175023555755615, -0.04652908444404602, -0.014941825531423092, 0.014464053325355053, 0.017796847969293594, -0.0021637591999024153, 0.046673208475112915, -0.004251751583069563, 0.061603255569934845, 0.003744300454854965, -0.06697648018598557, -0.03594468906521797, -0.005740760359913111, -0.07440498471260071, -0.039591412991285324, -0.005807304289191961, -0.08224651962518692, 0.049317456781864166, 0.0477975532412529, -0.07688293606042862, 0.05774614214897156, -0.002408160362392664, -0.0788850411772728, -0.0060463170520961285, -0.028943868353962898, 0.0005609547952190042, -0.12297702580690384, 0.09462245553731918, -0.026346717029809952, -0.06174487993121147, -0.010183361358940601, -0.012184166349470615, -0.08172792941331863, -0.035054903477430344, -0.04070675000548363, 0.039525263011455536, 0.04238414764404297, -0.04332742840051651, -0.005146029870957136, 0.004623692948371172, 0.03170923888683319, -0.030677292495965958, 0.04071302339434624, 0.07745229452848434, 0.015597623772919178, 0.02114233933389187, 0.0035781185142695904, -0.020315280184149742, -0.01986714079976082, 0.0017998862313106656, 0.038178060203790665, -0.017720334231853485, 0.0044329529628157616, -0.0124494144693017, 0.05515112727880478, -0.03269868344068527, -0.011099342256784439, 0.09164828062057495, -0.002325743669643998, 0.07215075194835663, 0.016600394621491432, 0.003547712229192257, -0.005366192664951086, 0.09816121309995651, 0.05778214707970619, 0.01663777232170105, 0.04954049363732338, -0.07704410701990128, -0.052312154322862625, 0.026302983984351158, 0.01727329008281231, -0.07691516727209091, -0.00629018247127533, 0.029798606410622597, 0.007290016394108534, -0.05936000496149063, -0.0005758930929005146, -0.009760251268744469, 0.004972731228917837, -0.03794891759753227, -0.03397751972079277, -0.0231452789157629, -0.028961220756173134, -0.028595149517059326, 0.004988513886928558, 0.029502520337700844, -0.03915947303175926, -0.0852443054318428, -0.031915079802274704, 0.01987546868622303, 0.04970439523458481, 0.03187723830342293, -0.02680576965212822, 0.04404328763484955, -0.004668546840548515, 0.06790786236524582, 0.01595376990735531, -0.06766600906848907, -0.0006926791393198073, -0.0032405380625277758, 0.039920177310705185, 0.08260729163885117, 0.041344013065099716, -0.006107048597186804, 0.054149605333805084, -0.010951957665383816, 0.04717276990413666, 0.008554834872484207, -0.040050044655799866, -0.07721531391143799, -0.042048729956150055, 0.00465784315019846, 0.030420459806919098, -0.037514131516218185, -0.04501869156956673, -0.05044179409742355, 0.08755764365196228, -0.059472691267728806, 0.05186646059155464, -0.04321378841996193, 0.028355758637189865, 0.07857147604227066, -0.04253101721405983, 0.05593990907073021, 0.00172839080914855, 0.0007616769871674478, -0.08123720437288284, -0.026848455891013145, 0.025419931858778, 0.02671149931848049, -0.006083388347178698, 0.024918122217059135, -0.0615851953625679, -0.06934662908315659, 0.00864838995039463, 0.11076170206069946, 0.030668877065181732, -0.05938953161239624, -0.03336556255817413, 0.03921355679631233, -0.007843030616641045, 0.052956171333789825, 0.06302499771118164, -0.024231454357504845, 0.08115048706531525, -0.07700738310813904, 0.0018994975835084915, -0.029981547966599464, -0.028227081522345543, 0.01676909811794758, 0.03414636105298996, -0.0202548298984766, 0.03345021978020668, -0.02062900736927986, 0.06677497923374176, 0.09162294864654541, 0.05272562801837921, 0.06271319091320038, -0.01838912069797516, -0.006690255831927061, -0.010600133799016476, 0.034098390489816666, 0.022029833868145943, 0.04090488329529762, -0.023475786671042442, -0.04536633566021919, 0.004807567223906517, 0.007809686008840799, -0.025136016309261322, -0.004996896255761385, -0.036332473158836365, -0.0720611959695816, 0.11469221860170364, -0.08941958844661713, 0.023249050602316856, -0.0019976638723164797, -0.04207613691687584, 0.12343039363622665, -0.00016894687723834068, 0.06993848085403442, 0.019300077110528946, -0.009943626821041107, 0.08189082890748978, -0.07155166566371918, -0.03738454729318619, 0.03494478762149811, 0.03735203668475151, -0.018850021064281464, 0.018282482400536537, 0.0779605284333229, 0.023248758167028427, -0.02695775218307972, 0.05640853941440582, -0.07466549426317215, 0.0007664431468583643, -0.024593694135546684, 0.005777102895081043, 0.015588401816785336, -0.04118277505040169, -0.044906776398420334, 0.14632444083690643, 0.022130973637104034, 0.0020049584563821554, 0.0721001848578453, 0.06052564084529877, 0.03180432692170143, 0.03870079666376114, 0.09435246884822845, 0.06924854964017868, -0.06211131811141968, -0.0565606988966465, 0.022441064938902855, -0.061603471636772156, 0.004624735098332167, -0.007163350936025381, -0.061935003846883774, -0.04276512190699577, -0.05646438151597977, -0.02113259769976139, -0.06116681918501854, 0.010670190677046776, 0.007413250394165516, 0.07007403671741486, 0.03535141423344612, 0.010274880565702915, -0.03349967300891876, 0.04957194626331329, -0.03458395600318909, -0.02553032524883747, -0.010209891013801098, -0.12152723222970963, 0.03316999971866608, 0.02310696430504322, -0.017610304057598114, 0.04470380023121834, -0.004310904070734978, -0.022023115307092667, 0.0067122927866876125, -0.029901815578341484, 0.02506670169532299, -0.03980334848165512, 0.0017531899502500892, -0.006712034810334444, -0.017537763342261314, 0.01317940466105938, 0.02078275755047798, -0.01843380555510521, 0.0019049434922635555, -0.003801607294008136, 0.0009744376293383539, -0.0001479595375712961, -0.030754759907722473, 0.027599716559052467, 0.003496857825666666, 0.00941127073019743, -0.03120487742125988, 0.015410535968840122, 0.019419634714722633, 0.029348505660891533, -0.010057314299046993, -0.02431745082139969, -0.018346112221479416, 0.0004901446518488228, 0.005855092313140631, 0.03906654939055443, 0.0004671442147810012, 0.024758659303188324, -0.007512268144637346, -0.01814558357000351, 0.004915176425129175, 0.053961120545864105, -0.002775750122964382, -0.02128574438393116, 0.002062681131064892, 0.030855817720294, -0.030858950689435005, 0.02557760290801525, -0.0790872722864151, -0.03174560144543648, -0.012449727393686771, -0.026154467836022377, -0.01915641687810421, 0.01868286356329918, -0.05082738772034645, -0.034648265689611435, 0.010469390079379082, 0.03220503032207489, -0.011427467688918114, -0.11044050008058548, -0.04058777168393135, 0.009297761134803295, -0.006122661288827658, -0.016082189977169037, -0.017219411209225655, 0.028007712215185165, -0.015010305680334568, -0.01764512248337269, 0.010232298634946346, 0.026499472558498383, -0.01641143672168255, 0.011207777075469494, -0.01502947136759758, -0.013423155061900616, -0.04834359139204025, -0.004884873516857624, -0.016360817477107048, 0.004822700284421444, 0.015171431936323643, -0.03240618854761124, 0.027380600571632385, 0.002062215469777584, -0.03273466229438782, -0.023916028439998627, 0.008446743711829185, 0.028864791616797447, 0.04068751260638237, 0.03591588884592056, -0.022359628230333328, -0.013477297499775887, -0.028014959767460823, -0.02082761749625206, 0.001848299871198833, -0.057675499469041824, -0.0530509315431118, 0.00607756432145834, 0.028323184698820114, -0.012722959741950035, 0.054344356060028076, 0.03041837178170681, 0.029211577028036118, -0.023609351366758347, -0.014800483360886574, 0.009029174223542213, -0.013344652019441128, -0.018763389438390732, 0.014886070974171162, 0.04832151159644127, -0.012434110045433044, 0.0035590266343206167, 0.033941708505153656, 0.019536573439836502, 0.06476137042045593, -0.01580645702779293, 0.03219069540500641, 0.006860984489321709, 0.006260802503675222, 0.0011802510125562549, -0.006173714064061642, -0.02406347543001175, 0.032697178423404694, -0.0071755447424948215, -0.04225946217775345, -0.009861770085990429, 0.05144108831882477, -0.01617964170873165, -0.0054809642024338245, -0.04013124853372574, 0.02670981176197529, 0.06769700348377228, -0.01828981749713421, -0.059369537979364395, -0.0019210505997762084, 0.017534460872411728, 0.001949029741808772, -0.04984613507986069, -0.035908252000808716, 0.01718476228415966, 0.023046506568789482, -0.03156648948788643, -0.004072500858455896, -0.008663946762681007, 0.019167663529515266, -0.04084398224949837, 0.03823459893465042, 0.016826538369059563, 0.01624869555234909, -0.005087451543658972, 0.020239070057868958, 0.011920487508177757, -0.02229381538927555, -0.04187280312180519, -0.004775722976773977, -0.002903925720602274, -0.01242552138864994, 0.059735432267189026, 0.01661064848303795, 0.03213398531079292, 0.013406222686171532, 0.010486777871847153, -0.019681761041283607, -0.01578078418970108, -0.01594751514494419, 0.028052762150764465, 0.041710421442985535, -0.059527743607759476, -0.02484946697950363, 0.0025739544071257114, 0.025594253093004227, 0.006150829140096903, -0.032335441559553146, -0.01593366079032421, -0.04832177981734276, 0.0234543289989233, -0.001004719641059637, -0.04342091828584671, -0.05252625793218613, -0.06868872046470642, 0.04895428195595741, -0.0315055176615715, 0.011714579537510872, 0.03067445196211338, -0.021782763302326202, 0.018114948645234108, -0.011516430415213108, -0.0005273319547995925, -0.021899180486798286, -0.007484886329621077, -0.03567773476243019, -0.001857016235589981, -0.03031887672841549, 0.05380989611148834, -0.007407967932522297, 0.017216678708791733, 0.051022887229919434, 0.03973470255732536, 0.009005500003695488, -0.03926241770386696, -0.027162600308656693, -0.023892728611826897, 0.0597037598490715, 0.04770945385098457, -0.03930043429136276, 0.03283444046974182, 0.03295557200908661, -0.025409601628780365, 0.03311600163578987, -0.03042294830083847, 0.060898181051015854, -0.04098488762974739, 0.032458238303661346, -0.0271963719278574, 0.03233538568019867, 0.022541461512446404, 0.021438492462038994, -0.003045820165425539, -0.038612689822912216, -0.016574081033468246, 0.02936004102230072, -0.020045334473252296, -0.025646910071372986, 0.0000982724959612824, 0.01926514320075512, 0.079926036298275, -0.016829131171107292, -0.025423908606171608, -0.03132972866296768, -0.02391337789595127, -0.007866499945521355, -0.022419385612010956, 0.0009072665707208216, 0.03973544016480446, -0.034595612436532974, 0.02750147134065628, 0.08142322301864624, 0.039999548345804214, -0.02038107067346573, 0.020420050248503685, 0.013091827742755413, -0.04051339998841286, 0.02771368995308876, 0.0047660935670137405, -0.0014595421962440014, -0.019423315301537514, -0.016314338892698288, 0.0722157284617424, 0.035148680210113525, -0.01806306093931198, 0.013141946867108345, -0.03457354009151459, -0.023562384769320488, 0.002418484538793564, -0.006112583912909031, 0.015203017741441727, -0.005450491793453693, -0.02220442146062851, -0.007523082662373781, -0.027045538648962975, -0.011273126117885113, 0.04625822603702545, 0.0385318286716938, 0.004310848191380501, 0.004744442645460367, 0.042284391820430756, -0.02443208172917366, -0.0149688133969903, -0.03136443346738815, 0.005559657700359821, -0.021962439641356468, 0.0006824310403317213, -0.006947826128453016, -0.002932327799499035, -0.02308475412428379, -0.002376007381826639, -0.02908242680132389, -0.015409945510327816, 0.0005208446527831256, -0.020253963768482208, 0.036011453717947006, 0.013212934136390686, 0.008909015916287899, -0.027290595695376396, 0.008252092637121677, 0.0037388731725513935, -0.05005708709359169, -0.03426001965999603, 0.021496795117855072, -0.026467980816960335, -0.010863292962312698, 0.054132044315338135, -0.03702174872159958, -0.0034185138065367937, 0.03426133096218109, -0.0021242164075374603, 0.047460854053497314, 0.0026551184710115194, 0.03398522734642029, 0.033313900232315063, -0.013609864749014378, -0.008402567356824875, -0.027257367968559265, -0.008475896902382374, -0.03265013173222542, -0.0016048663528636098, 0.04160243272781372, 0.019489835947752, 0.023330075666308403, 0.02260962873697281, 0.046529371291399, 0.02594519406557083, 0.035437870770692825, -0.0025726219173520803, 0.0010228919563814998, -0.026930147781968117, -0.014944215305149555, 0.02665487863123417, 0.025493474677205086, 0.04030308499932289, -0.005359094589948654, 0.034804247319698334, -0.03744424507021904, -0.0483362190425396, 0.04020756483078003, -0.04032950475811958, 0.03657747805118561, -0.006984312552958727, -0.0871603712439537, -0.007266486994922161, 0.0036597494035959244, 0.003824362065643072, -0.002917323727160692, 0.04390193521976471, 0.020000342279672623, -0.026694264262914658, -0.0004977453500032425, 0.027855630964040756, -0.004109054803848267, -0.046169739216566086, 0.027605291455984116, 0.014755159616470337, 0.024288330227136612, 0.04588586091995239, -0.028960803523659706, 0.01285721454769373, 0.014142027124762535, 0.04524610936641693, -0.0062101795338094234, 0.0378669872879982, 0.014053411781787872, 0.015029807575047016, 0.007096685469150543, -0.04089606553316116, -0.014695501886308193, -0.014623366296291351, 0.029701178893446922, -0.023436738178133965, -0.012432847172021866, -0.011831805109977722, -0.022379186004400253, 0.04344930499792099, -0.004878994543105364, 0.034280925989151, 0.059404753148555756, 0.03384718671441078, 0.03943479061126709, 0.027305958792567253, 0.05053156614303589, 0.007856304757297039, -0.03318061679601669, -0.012189878150820732, 0.014802075922489166, 0.019807355478405952, 0.03905929625034332, 0.007329393643885851, 0.004681656137108803, 0.01330993976444006, -0.018856143578886986, -0.018291829153895378, -0.029423942789435387, 0.009456533007323742, 0.021787822246551514, -0.025359876453876495, 0.0071341004222631454, 0.00026643520686775446, -0.0016617221990600228, -0.003494980512186885, 0.006797490641474724, -0.018228376284241676, -0.016639377921819687, 0.028164975345134735, 0.02710699290037155, -0.04548756405711174, -0.07044937461614609, 0.01404851209372282, 0.014927953481674194, 0.03716457635164261, 0.008505313657224178, -0.04660334438085556, 0.009639878757297993, -0.04400467872619629, 0.019376054406166077, 0.007455078419297934, 0.03306407481431961, -0.024913903325796127, -0.020606650039553642, 0.030009828507900238, 0.015362867154181004, 0.027417577803134918, 0.06322452425956726, 0.004194998648017645, 0.027007538825273514, -0.010601969435811043, 0.004751251079142094, -0.03270943835377693, -0.030919397249817848, -0.023850426077842712, -0.011009478010237217, 0.009938926436007023, 0.0013775428524240851, 0.016681360080838203, -0.01084866002202034, 0.030116921290755272, -0.018299473449587822, -0.020185010507702827, 0.03350715711712837, 0.007844861596822739, -0.02002495899796486, 0.01969795860350132, 0.01780182309448719, -0.05535649135708809, 0.020280679687857628, -0.04600462317466736, 0.005226879846304655, 0.008695528842508793, -0.013308469206094742, 0.07600647956132889, -0.0029030609875917435, 0.003467562375590205, 0.05582968145608902, 0.03744329884648323, 0.04055788367986679, -0.009650204330682755, 0.02173394337296486, -0.007323896512389183, 0.0057101561687886715, -0.049403294920921326, 0.01650177873671055, 0.03485393524169922, 0.0049348552711308, -0.019432606175541878, -0.04877509921789169, -0.030545208603143692, 0.006575304549187422, 0.01593831554055214, 0.052155643701553345, -0.03336797654628754, -0.002766556339338422, 0.031173519790172577, 0.01733531802892685, -0.012352820485830307, 0.021022800356149673, 0.04257567599415779, 0.0404265820980072, 0.0415709987282753, -0.01995960809290409, 0.020945992320775986, -0.025209881365299225, -0.007939173839986324, 0.04474272206425667, 0.012412636540830135, -0.0012610225239768624, 0.010807003825902939, 0.0448911115527153, -0.01629839465022087, -0.025555456057190895, -0.024965928867459297, 0.00047523932880721986, 0.05093769729137421, -0.0024525176268070936, -0.024616993963718414, -0.0017926909495145082, 0.010053395293653011, 0.0068636685609817505, -0.011387468315660954, -0.023367159068584442, -0.02574092522263527, -0.005278169177472591, -0.006330033764243126, -0.00502398144453764, 0.021013617515563965, 0.025759311392903328, 0.03561292216181755, 0.02861398085951805, 0.0093638114631176, 0.022192062810063362, 0.00968159269541502, 0.004030137322843075, 0.022352753207087517, 0.03023366630077362, -0.06909607350826263, -0.03204086050391197, -0.0038518202491104603, 0.04929867759346962, -0.053204577416181564, -0.08151422441005707, 0.0483304001390934, -0.02483067475259304, -0.0923866406083107, 0.019731417298316956, -0.010950599797070026, -0.001387953176163137, -0.003269138280302286, -0.002713839989155531, -0.009652175940573215, 0.003962103743106127, -0.03278813883662224, -0.0030815317295491695, -0.0553225502371788, 0.01635090634226799 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Evaluation I knew that the ported model was doing quite well based on my manual testing with a large body of text, but I didn't know how well the ported model performed comparatively to the original. So it was time to evaluate. For the task of translation [BLEU score](https://en.wikipedia.org/wiki/BLEU) is used as an evaluation metric.transformershas a script [run_eval.py](https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/examples/seq2seq/run_eval.py) to perform the evaluation. Here is an evaluation for the ru-en pair export PAIR=ru-en export MODEL=facebook/wmt19-$PAIR export DATA_DIR=data/$PAIR export SAVE_DIR=data/$PAIR export BS=64 export NUM_BEAMS=5 export LENGTH_PENALTY=1.1 mkdir -p $DATA_DIR sacrebleu -t wmt19 -l $PAIR --echo src > $DATA_DIR/val.source sacrebleu -t wmt19 -l $PAIR --echo ref > $DATA_DIR/val.target PYTHONPATH="src:examples/seq2seq" python examples/seq2seq/run_eval.py $MODEL \ $DATA_DIR/val.source $SAVE_DIR/test_translations.txt --reference_path $DATA_DIR/val.target \ --score_path $SAVE_DIR/test_bleu.json --bs $BS --task translation --num_beams $NUM_BEAMS \ --length_penalty $LENGTH_PENALTY --info $MODEL --dump-args which took a few minutes to run and returned: {'bleu': 39.0498, 'n_obs': 2000, 'runtime': 184, 'seconds_per_sample': 0.092, 'num_beams': 5, 'length_penalty': 1.1, 'info': 'ru-en'} You can see that the BLEU score was 39.0498 and that it evaluated using 2000 test inputs, provided by sacrebleu using the wmt19 dataset. Remember, I couldn't use the model ensemble, so I next needed to find the best performing checkpoint. For that purpose I wrote a script fsmt-bleu-eval-each-chkpt.py which converted each checkpoint, run the eval script and reported the best one. As a result I knew that model4.pt was delivering the best performance, out of the 4 available checkpoints. I wasn't getting the same BLEU scores as the ones reported in the original paper, so I next needed to make sure that we were comparing the same data using the same tools. Through asking at the fairseq issue I was given the code that was used by fairseq developers to get their BLEU scores - you will find it here. But, alas, their method was using a re-ranking approach which wasn't disclosed. Moreover, they evaled on outputs before detokenization and not the real output, which apparently scores better. Bottom line - we weren't scoring in the same way (). * footnote: the paper A Call for Clarity in Reporting BLEU Scores invites developers to start using the same method for calculating the metrics (tldr: use sacrebleu). Currently, this ported model is slightly behind the original on the BLEU scores, because model ensemble is not used, but it's impossible to tell the exact difference until the same measuring method is used.
[ 0.03700466826558113, -0.03441048413515091, -0.014209396205842495, -0.04360494017601013, 0.02451205998659134, 0.037591297179460526, 0.0839206874370575, 0.04419495537877083, -0.051910076290369034, -0.015540337190032005, -0.04127856343984604, 0.05248556658625603, -0.011750899255275726, 0.02919851243495941, -0.007716160733252764, -0.05401739105582237, 0.03983081877231598, -0.036650218069553375, 0.021506192162632942, 0.02357141487300396, -0.013201987370848656, -0.08535687625408173, 0.047155868262052536, 0.0446305088698864, 0.0025555964093655348, -0.058543115854263306, 0.04617954045534134, -0.003921548370271921, -0.08285399526357651, 0.010683075524866581, -0.10723036527633667, -0.032650068402290344, -0.06363721936941147, -0.021987799555063248, -0.03308810293674469, 0.0034492085687816143, -0.09262721240520477, 0.07011106610298157, 0.02456354722380638, -0.032780665904283524, 0.023708999156951904, -0.03680255636572838, -0.012396574951708317, -0.003058539004996419, 0.019768843427300453, -0.004278404638171196, -0.1500432789325714, 0.015366625972092152, 0.016081981360912323, 0.011929468251764774, -0.03274475038051605, 0.0605940967798233, -0.051698535680770874, 0.0020154621452093124, 0.020238559693098068, 0.014872371219098568, 0.014639896340668201, -0.0003002672456204891, 0.04065866023302078, 0.007162590976804495, -0.008421100676059723, -0.04530446603894234, 0.04073471575975418, 0.0649840459227562, -0.004671377129852772, -0.001056065782904625, 0.019264735281467438, 0.06884373724460602, -0.05017910897731781, -0.010571012273430824, -0.02853027731180191, -0.009277977980673313, -0.00744383130222559, -0.025419292971491814, -0.05819481611251831, -0.037688449025154114, -0.030263809487223625, 0.032529450953006744, 0.0978582352399826, 0.08184195309877396, -0.0006591897108592093, 0.005975696258246899, 0.0035118423402309418, 0.047812625765800476, 0.035274799913167953, 0.05316143110394478, 0.05855517089366913, -0.05262596160173416, -0.10963018983602524, 0.04404756799340248, -0.030882716178894043, -0.10313894599676132, -0.011984201148152351, 0.05599815025925636, 0.06357307732105255, -0.048158206045627594, 0.043952491134405136, 0.035535842180252075, -0.01531878300011158, 0.005026186816394329, 0.03969983384013176, -0.01106614526361227, 0.0332249291241169, -0.017207222059369087, -0.025539971888065338, -0.01241651363670826, -0.021960049867630005, -0.07943440973758698, -0.011316649615764618, 0.014563123695552349, 0.04750698804855347, -0.015869179740548134, -0.008058122359216213, 0.04522910714149475, -0.06941854953765869, -0.013928023166954517, -0.03759656101465225, 0.0057280464097857475, 0.011698223650455475, 0.04857553541660309, 0.0539877712726593, 0.0701586902141571, 0.028848769143223763, 0.005202449392527342, 0.0794038474559784, 0.01630558632314205, 0.07594376802444458, 0.024669812992215157, 0.011972594074904919, -0.016016431152820587, 0.050951577723026276, -0.02615515887737274, 0.08122037351131439, 0.06067177653312683, -0.030350180342793465, -0.054321277886629105, 0.018046433106064796, -0.028958545997738838, -0.008022241294384003, -0.02797411009669304, -0.07541963458061218, 0.07228360325098038, -0.029602589085698128, 0.01868513971567154, 0.03783116117119789, 0.02012067288160324, -0.06803379952907562, 0.06709890067577362, 0.016756700351834297, 0.03368839994072914, -0.08357656002044678, 0.054326847195625305, -0.02262054570019245, -0.04769015684723854, 0.013063261285424232, 0.08147305995225906, -0.032953277230262756, -0.04510879144072533, -0.09812674671411514, 0.03466109558939934, -0.039886925369501114, 0.03531249985098839, -0.03941488638520241, -0.06220262870192528, 0.023248402401804924, 0.03253689780831337, -0.009291752241551876, 0.026882916688919067, -0.01450919359922409, -0.00704182730987668, 0.11409086734056473, -0.03922440856695175, 0.1166701540350914, 0.007178209256380796, -0.027228685095906258, 0.043081194162368774, 0.06370799988508224, 0.024309450760483742, 0.01203659363090992, -0.04771625995635986, -0.042501457035541534, 0.0586172491312027, -0.008945261128246784, 0.08584772795438766, 0.06949084252119064, -0.09926986694335938, 0.01743190921843052, -0.0289987213909626, 0.011989839375019073, 0.01984182558953762, -0.10206647962331772, -0.04689333960413933, 0.09387962520122528, -0.03891175612807274, 0.024668928235769272, -0.042777203023433685, 0.014065038412809372, 0.10979096591472626, 0.04446014016866684, 0.024219710379838943, 0.004566919058561325, 0.03805125877261162, 0.034889865666627884, -0.03862946853041649, -0.020049957558512688, 0.04249414801597595, 0.07354779541492462, -0.07175839692354202, -0.010293038561940193, 0.055352941155433655, 0.03540349379181862, -0.0846157893538475, 0.04546605795621872, -0.05487135425209999, 0.0081330556422472, -0.0807759016752243, -0.02443511411547661, 0.009628727100789547, -0.02515147067606449, -0.012280796654522419, 0.12083178013563156, -0.006713054608553648, -0.009210544638335705, -0.06079787388443947, -0.028628692030906677, 0.017768045887351036, 0.0626738965511322, 0.09351538866758347, 0.029386084526777267, -0.012705891393125057, -0.04665210470557213, -0.0494428351521492, -0.05091799423098564, 0.07610372453927994, -0.04487474635243416, -0.06274734437465668, 0.03299597278237343, 0.0011071041226387024, 0.0067549594677984715, -0.05047948285937309, -0.041678041219711304, 0.025019317865371704, 0.059545282274484634, 0.07928389310836792, -0.04998376965522766, -0.014302334748208523, 0.046375617384910583, -0.01793988235294819, -0.04101499915122986, -0.04268789291381836, -0.0470692478120327, 0.06029832735657692, 0.005136700347065926, -0.030497729778289795, 0.04629642888903618, 0.01857736147940159, -0.011528823524713516, 0.013340206816792488, -0.052791204303503036, 0.023968055844306946, -0.004225572105497122, -0.003680021967738867, -0.05098473280668259, -0.029316307976841927, 0.02020351216197014, -0.05634982883930206, -0.0044573089107871056, 0.010310722514986992, -0.01125407312065363, 0.007656390778720379, -0.03154917433857918, -0.006968474481254816, 0.029715029522776604, -0.008663823828101158, 0.00930445920675993, 0.00288432277739048, 0.037103377282619476, -0.0003671392914839089, -0.030576348304748535, -0.026716560125350952, -0.02091618813574314, -0.034118156880140305, 0.013196705840528011, -0.00918976217508316, 0.03410429507493973, 0.02382878214120865, 0.0040054009296, -0.012516106478869915, -0.027827907353639603, 0.01918242871761322, 0.032711856067180634, 0.009367120452225208, -0.006809106096625328, -0.043429892510175705, 0.024960383772850037, 0.006127986591309309, 0.0021951417438685894, -0.02983023226261139, 0.021226441487669945, 0.05245332792401314, -0.047260552644729614, 0.029392799362540245, -0.04430587589740753, 0.00641765259206295, -0.01588667556643486, 0.013874830678105354, -0.023115677759051323, 0.02716592699289322, -0.10538704693317413, 0.003977569751441479, 0.03624550253152847, 0.029547564685344696, -0.007370281033217907, -0.005096892826259136, 0.03313275799155235, 0.016623523086309433, 0.018935266882181168, 0.022653019055724144, 0.02529369667172432, -0.018934078514575958, 0.035960935056209564, 0.017824992537498474, -0.012813947163522243, 0.012123427353799343, -0.004382777493447065, 0.03551444783806801, 0.01669316366314888, -0.013738793320953846, -0.02380814217031002, 0.021100830286741257, -0.016245540231466293, -0.010014633648097515, -0.022536056116223335, 0.011602739803493023, 0.023324966430664062, 0.002981716301292181, 0.024184448644518852, -0.03395650535821915, -0.0015845519956201315, -0.0249817855656147, 0.016225971281528473, -0.010432098060846329, -0.014058887027204037, -0.0441901795566082, -0.01781632751226425, -0.001984870061278343, -0.009341718629002571, 0.04303024336695671, 0.04574287682771683, -0.007497110404074192, 0.015496046282351017, -0.009516159072518349, 0.00851688627153635, -0.005661925300955772, 0.009726430289447308, -0.018868127837777138, 0.02378164604306221, 0.003420285414904356, -0.03583625704050064, -0.006737868767231703, -0.026967130601406097, 0.06958881765604019, 0.002051593968644738, -0.010688193142414093, -0.014046131633222103, 0.005601188167929649, 0.012327366508543491, -0.022901024669408798, -0.05796061083674431, 0.004082622472196817, -0.036608099937438965, 0.019176241010427475, -0.015817850828170776, 0.040814872831106186, -0.024097494781017303, 0.03600206598639488, -0.03517470136284828, 0.03486539423465729, -0.010200638324022293, 0.02248825505375862, -0.012494652532041073, 0.014013046398758888, -0.03459969162940979, -0.01028434932231903, -0.05880815163254738, -0.036990951746702194, 0.04855167493224144, 0.027700545266270638, -0.0346207432448864, -0.03081037849187851, -0.018441397696733475, 0.006293902639299631, -0.009722204878926277, -0.004829137120395899, 0.018052229657769203, -0.006666467059403658, 0.02216884307563305, 0.03040308505296707, 0.006654529366642237, -0.04751717299222946, -0.007133867125958204, 0.024102890864014626, -0.03173685818910599, -0.059490419924259186, 0.015397637151181698, 0.007390356156975031, -0.01160597987473011, 0.04942266270518303, 0.0036731278523802757, -0.05106356367468834, 0.010290678590536118, -0.010434357449412346, 0.02715531550347805, 0.03157305717468262, -0.06025687977671623, -0.04130048304796219, 0.027982626110315323, -0.029628967866301537, -0.01177024282515049, -0.00240993220359087, -0.04197156801819801, 0.0034301849082112312, 0.07118508964776993, 0.03680560737848282, -0.020213181152939796, -0.01689351350069046, -0.028859145939350128, 0.027197934687137604, -0.008084055036306381, 0.0022493014112114906, -0.033590514212846756, -0.0205448716878891, 0.0075114015489816666, 0.02849460020661354, -0.0064529795199632645, 0.06472915410995483, -0.012164386920630932, 0.008656183257699013, -0.010065477341413498, 0.04796848073601723, 0.060809895396232605, -0.01348805520683527, 0.009360904805362225, 0.007739681750535965, -0.00034681332181207836, -0.03656148165464401, -0.0078001911751925945, -0.027342887595295906, -0.026541655883193016, 0.00786395650357008, -0.006873812060803175, -0.014619306661188602, 0.005998949985951185, 0.021818378940224648, -0.03193977475166321, 0.01932944729924202, -0.038211893290281296, 0.015029523521661758, 0.03893011063337326, -0.0270028505474329, -0.044964443892240524, 0.02788376249372959, 0.020496446639299393, -0.008419017307460308, -0.02536213956773281, 0.0013726350152865052, -0.013329621404409409, 0.05975343659520149, -0.04585104063153267, 0.008949756622314453, -0.04447716102004051, 0.030056631192564964, -0.005414104554802179, -0.015380263328552246, 0.02817552722990513, -0.05931410193443298, 0.005766324233263731, 0.008624177426099777, -0.02431066893041134, -0.007998773828148842, -0.014759828336536884, -0.04358130693435669, -0.012956153601408005, 0.06616581231355667, -0.0018598866881802678, -0.013577604666352272, 0.029668673872947693, 0.012963722459971905, -0.00742898415774107, -0.017862845212221146, 0.016686037182807922, -0.010822471231222153, 0.01823236048221588, 0.020788252353668213, 0.03090236522257328, 0.07049450278282166, -0.003653815947473049, 0.013321392238140106, -0.006976007483899593, -0.005582283716648817, 0.005217306315898895, -0.05685138329863548, -0.010240720584988594, -0.00477616535499692, 0.019978629425168037, -0.0020953030325472355, -0.022243572399020195, -0.003552636131644249, 0.037409842014312744, 0.04017329216003418, -0.029516685754060745, -0.027084598317742348, 0.03401976078748703, -0.0027072401717305183, -0.023317895829677582, 0.0016171709867194295, 0.044079944491386414, -0.03194257989525795, 0.008208182640373707, -0.019461097195744514, -0.03055053949356079, 0.005970844067633152, 0.055039722472429276, -0.06871459633111954, 0.016044899821281433, 0.02703727036714554, 0.012387334369122982, 0.0011700146133080125, -0.01157866045832634, -0.02255960740149021, -0.04267777130007744, -0.028094368055462837, 0.011791542172431946, -0.033117182552814484, 0.029709581285715103, -0.012524386867880821, 0.004182468634098768, -0.002354963216930628, 0.0022751870565116405, 0.005908877123147249, -0.013004045002162457, 0.006165062543004751, 0.0378878228366375, 0.005788448266685009, -0.04540662094950676, 0.04525787755846977, 0.031833939254283905, -0.016889765858650208, 0.007485054899007082, 0.011866544373333454, -0.008726503700017929, -0.002034545876085758, -0.05731545761227608, 0.03348982334136963, 0.06313322484493256, 0.017311550676822662, 0.042732980102300644, -0.0049091512337327, 0.036967601627111435, 0.027256065979599953, -0.012968350201845169, 0.02861947938799858, -0.01008825283497572, -0.0054191118106245995, -0.01966823823750019, 0.0277623999863863, 0.004619317129254341, 0.014377561397850513, 0.03771042823791504, -0.028071558102965355, -0.0015978945884853601, 0.057157743722200394, -0.04506919905543327, 0.03467262536287308, 0.003920800052583218, -0.06389583647251129, 0.03114006482064724, 0.04254826903343201, -0.01205761544406414, 0.03279734030365944, 0.03336659073829651, 0.02273784577846527, 0.0028136721812188625, -0.028949925675988197, 0.023998383432626724, 0.06299988180398941, 0.025916147977113724, 0.0071615963242948055, 0.043768260627985, 0.03352845832705498, 0.037093210965394974, -0.004142405465245247, 0.02268517203629017, 0.01026264950633049, 0.10964681953191757, -0.0034515485167503357, 0.03237895295023918, 0.03061470203101635, -0.008705981075763702, -0.025027688592672348, -0.008126736618578434, -0.047425370663404465, -0.023653265088796616, -0.00709396880120039, -0.007439385633915663, -0.001370123471133411, 0.038131631910800934, -0.009114859625697136, 0.04251212999224663, 0.03980661556124687, 0.022379042580723763, 0.0030673404689878225, 0.024494832381606102, 0.016742991283535957, -0.011244343593716621, -0.0035494102630764246, 0.026279013603925705, -0.018683653324842453, -0.0037247303407639265, 0.08186253160238266, -0.007936890237033367, -0.004650995600968599, -0.040413446724414825, 0.03157450631260872, -0.002438024850562215, -0.0006523564807139337, -0.004794727545231581, 0.03008938394486904, -0.0027643011417239904, 0.010686191730201244, -0.010154183022677898, 0.05815528705716133, -0.021428564563393593, -0.02582799270749092, -0.017202917486429214, -0.015208355151116848, -0.017823878675699234, -0.016476579010486603, -0.013396793976426125, 0.0753786489367485, -0.004524752963334322, -0.054274048656225204, -0.029453983530402184, 0.012190219014883041, 0.03555051609873772, 0.02429494634270668, -0.022480448707938194, 0.016112957149744034, -0.019886530935764313, -0.007225325796753168, -0.004438846372067928, 0.030895007774233818, -0.009000550955533981, 0.006651424802839756, -0.0017853367608040571, 0.02079172432422638, 0.0027961654122918844, 0.008369194343686104, 0.006852833088487387, 0.02433411218225956, -0.05061453953385353, -0.004829013720154762, 0.00405886210501194, -0.038123875856399536, -0.000017905129425344057, -0.04291246831417084, -0.04243292659521103, 0.005384284071624279, 0.054940834641456604, 0.016694677993655205, 0.030594462528824806, 0.005574304144829512, -0.004279307089745998, -0.021406564861536026, -0.0164782777428627, -0.021695714443922043, 0.030170809477567673, -0.02294493466615677, 0.03435884788632393, 0.01187857985496521, -0.025957439094781876, -0.02134694904088974, -0.004184948746114969, 0.013125027529895306, 0.039307136088609695, -0.02331094816327095, -0.006581923924386501, -0.015027329325675964, 0.031181246042251587, 0.04016115888953209, 0.045615676790475845, 0.019231831654906273, 0.001430277363397181, 0.008663412183523178, -0.03876902163028717, 0.038835860788822174, -0.03163057565689087, 0.0020700516179203987, -0.018157031387090683, -0.035866230726242065, -0.008620889857411385, 0.009760446846485138, -0.04722461849451065, 0.009502064436674118, -0.04392780363559723, -0.001500160782597959, -0.014081008732318878, -0.009049571119248867, -0.02464410848915577, 0.01643432304263115, 0.05693827196955681, 0.02771696262061596, 0.009244071319699287, -0.00427138851955533, -0.03145378828048706, 0.0173221156001091, -0.024496236816048622, 0.038683585822582245, 0.06269685924053192, 0.01932235062122345, -0.015484338626265526, -0.01374009344726801, 0.017089346423745155, 0.02127392590045929, -0.024762485176324844, -0.0006383886211551726, 0.01988130435347557, -0.04103516787290573, -0.011269252747297287, 0.00869668647646904, 0.027659911662340164, -0.008035607635974884, 0.04196371138095856, -0.019571801647543907, -0.013497748412191868, -0.011593206785619259, 0.011747405864298344, -0.07894100248813629, -0.007420442067086697, -0.00534193217754364, 0.01654895395040512, 0.006462289951741695, 0.02323462814092636, 0.02972511202096939, 0.01429840549826622, -0.01572323776781559, -0.0020020951051265, 0.003284212201833725, -0.05260081589221954, -0.060832489281892776, 0.0025991033762693405, 0.02742980606853962, -0.03929838910698891, -0.07858460396528244, 0.03839734569191933, -0.010150774382054806, -0.0036456016823649406, -0.02815084159374237, -0.014471188187599182, 0.018260914832353592, -0.018629644066095352, 0.004680972080677748, -0.03046281822025776, 0.0033475151285529137, 0.020636821165680885, -0.021346811205148697, -0.01111646182835102, 0.011350061744451523 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Files As a quick overview, the following files needed to be created and written: * src/transformers/configuration_fsmt.py - a short configuration class. * src/transformers/convert_fsmt_original_pytorch_checkpoint_to_pytorch.py - a complex conversion script. * src/transformers/modeling_fsmt.py - this is where the model architecture is implemented. * src/transformers/tokenization_fsmt.py - a tokenizer code. * tests/test_modeling_fsmt.py - model tests. * tests/test_tokenization_fsmt.py - tokenizer tests. * docs/source/model_doc/fsmt.rst - a doc file. There are other files that needed to be modified as well, we will talk about those towards the end.
[ 0.05220572277903557, -0.02067258395254612, -0.022515585646033287, -0.004546454641968012, 0.09293420612812042, 0.025549575686454773, 0.00996177364140749, 0.0073147849179804325, 0.0262528695166111, -0.006025827955454588, -0.0904739648103714, 0.0593450590968132, 0.0055073825642466545, 0.044520169496536255, 0.030414177104830742, 0.03175366669893265, 0.014256078749895096, -0.022221021354198456, -0.044592879712581635, 0.03142980858683586, 0.004970948211848736, -0.05444760620594025, -0.002853035693988204, 0.025495700538158417, 0.021938135847449303, -0.045001909136772156, -0.011692778207361698, 0.03206763043999672, -0.004571340978145599, 0.06980327516794205, -0.07255394756793976, -0.02859855815768242, -0.03275631368160248, -0.03924819454550743, -0.051675859838724136, 0.044112883508205414, -0.10522543638944626, 0.043208081275224686, 0.03396660089492798, -0.05984526500105858, 0.0056025744415819645, 0.016930563375353813, -0.1111074909567833, 0.047987956553697586, 0.02594449557363987, 0.052635639905929565, -0.15336698293685913, 0.07819084823131561, -0.016907982528209686, -0.04639352858066559, -0.048778507858514786, -0.024695737287402153, -0.05955862998962402, -0.021611711010336876, -0.006172609981149435, 0.033015813678503036, -0.014281815849244595, 0.01993487775325775, 0.015052564442157745, 0.001939031877554953, 0.0636177808046341, 0.02123231440782547, 0.03695263713598251, 0.046451322734355927, 0.06430916488170624, -0.019198013469576836, -0.021516496315598488, -0.027035929262638092, -0.04655137285590172, -0.03607684001326561, -0.03541255742311478, 0.009183957241475582, -0.023344166576862335, -0.035579707473516464, -0.03327491506934166, -0.04479795694351196, 0.05670507252216339, 0.011538224294781685, 0.06008708104491234, 0.08703453838825226, 0.041742954403162, 0.06473419070243835, 0.008371385745704174, 0.04812537506222725, 0.0064756423234939575, -0.028543315827846527, 0.028140490874648094, -0.014331028796732426, 0.041646625846624374, 0.053899697959423065, 0.0074628074653446674, -0.10102426260709763, -0.07187718152999878, 0.02605520933866501, 0.04037284851074219, 0.009924153797328472, 0.026200642809271812, 0.05051816999912262, 0.00795007310807705, 0.012870866805315018, 0.006094041280448437, -0.012951100245118141, -0.04655780270695686, -0.010271800681948662, -0.021013284102082253, 0.016791194677352905, 0.004104853142052889, -0.03410901501774788, -0.04618487134575844, -0.002693197224289179, -0.03614639863371849, -0.02428540401160717, -0.033207979053258896, 0.04258228838443756, -0.04868341237306595, -0.0005974072846584022, -0.017903966829180717, -0.08042776584625244, -0.023855043575167656, 0.027721650898456573, -0.017320098355412483, 0.08163277804851532, 0.05545536428689957, -0.015348521992564201, 0.03730272129178047, 0.10551709681749344, 0.05455756559967995, 0.04676203057169914, -0.03478597477078438, -0.11874274909496307, 0.027497995644807816, -0.017614977434277534, 0.05711442232131958, 0.007422159891575575, -0.012917677871882915, -0.05502106994390488, -0.012265012599527836, -0.017056595534086227, -0.0009476792765781283, 0.024968253448605537, -0.01383416261523962, 0.06913018226623535, -0.025705961510539055, 0.0496206134557724, -0.011670860461890697, -0.05524521693587303, -0.08794666081666946, 0.08731728792190552, -0.010133207775652409, 0.015477183274924755, -0.07828327268362045, 0.043795183300971985, -0.010258803144097328, -0.01837528683245182, -0.028962714597582817, 0.07416634261608124, 0.021171607077121735, -0.010100768879055977, -0.06619073450565338, -0.05170825123786926, -0.009383712895214558, 0.03647042438387871, -0.06380407512187958, 0.0075921667739748955, 0.012286369688808918, -0.07172951847314835, 0.02915731817483902, 0.029095778241753578, 0.07404546439647675, 0.00243174284696579, 0.013007914647459984, -0.051456745713949203, 0.05744393169879913, -0.009330682456493378, -0.015761973336338997, 0.05097227171063423, 0.032725147902965546, 0.061950262635946274, 0.011304900981485844, -0.0346338115632534, -0.005187797360122204, 0.04395359754562378, -0.06287951022386551, -0.004365718923509121, 0.023380395025014877, -0.05542384460568428, 0.030557679012417793, -0.042988210916519165, -0.05080827325582504, 0.022734669968485832, -0.10799132287502289, -0.04651359096169472, 0.05268493667244911, -0.024801859632134438, 0.04532147943973541, -0.009172982536256313, 0.014658695086836815, 0.10655254870653152, 0.045850224792957306, 0.039295829832553864, 0.016336413100361824, -0.014684769324958324, -0.0314929261803627, -0.00144072319380939, 0.019034063443541527, 0.0508437380194664, 0.00003888397986884229, -0.06403031945228577, 0.07412304729223251, -0.019696999341249466, 0.05703775957226753, -0.03299989923834801, 0.039163731038570404, -0.08232372254133224, 0.030399292707443237, -0.0953083261847496, -0.05761963501572609, -0.003405702067539096, 0.02005331590771675, -0.040601085871458054, 0.15862536430358887, -0.05487780645489693, -0.003343068528920412, -0.04225093498826027, -0.058725740760564804, 0.060884445905685425, 0.047277867794036865, 0.04823703691363335, 0.06346194446086884, -0.11301704496145248, -0.03997023403644562, -0.075189970433712, -0.031244046986103058, 0.09446287900209427, 0.014114851132035255, -0.02462027035653591, 0.01197921484708786, 0.07690935581922531, -0.009395081549882889, -0.022295653820037842, 0.07032245397567749, 0.009512617252767086, -0.006201895419508219, -0.02397485077381134, 0.01862521283328533, -0.05145125091075897, 0.0748169869184494, -0.007286399602890015, -0.001657346379943192, 0.0008496635709889233, -0.04739179462194443, 0.0415690578520298, 0.010975142009556293, -0.004874673206359148, 0.08388709276914597, 0.04826469346880913, -0.013826004229485989, -0.024267401546239853, 0.01994180865585804, 0.04486678168177605, 0.0047383736819028854, 0.029119985178112984, -0.056097954511642456, -0.041765447705984116, -0.06086425110697746, -0.022880693897604942, -0.013884815387427807, 0.005851654801517725, -0.000979984411969781, 0.04180198535323143, -0.015195904299616814, -0.02974751591682434, -0.012072212062776089, -0.013258633203804493, 0.014013541862368584, 0.02086116001009941, 0.033691633492708206, -0.012481408193707466, -0.020730745047330856, 0.006765773519873619, -0.002956240903586149, -0.02227952517569065, 0.02439090423285961, 0.04240701347589493, -0.00044601221452467144, 0.02454802580177784, -0.0118405781686306, -0.016650596633553505, -0.03057899698615074, 0.024086039513349533, -0.023387011140584946, 0.03019792027771473, 0.008455305360257626, -0.013985694386065006, -0.017944740131497383, 0.0307988952845335, -0.03490568697452545, -0.00532349431887269, -0.007232125382870436, 0.037151992321014404, -0.02632533572614193, 0.04350191354751587, 0.01544040534645319, -0.02622794918715954, -0.04585365578532219, 0.039034198969602585, 0.020404106006026268, 0.022723833099007607, -0.10253295302391052, -0.000042439522076165304, 0.001291420659981668, 0.035259198397397995, 0.013856240548193455, -0.03140756115317345, 0.008994021452963352, 0.015624146908521652, -0.016368098556995392, -0.018228909000754356, -0.003266615094617009, 0.017026446759700775, 0.014413258992135525, 0.02452302724123001, -0.01162415836006403, 0.008539596572518349, -0.0196328554302454, 0.041543226689100266, 0.01552275475114584, -0.021526914089918137, -0.01960906945168972, 0.010678253136575222, -0.0026275338605046272, -0.017382169142365456, -0.004213291686028242, 0.026297099888324738, 0.03316247835755348, 0.08216265588998795, 0.006499807350337505, -0.029172474518418312, -0.040504809468984604, 0.005734867416322231, -0.025309083983302116, -0.0140923410654068, -0.020257728174328804, -0.015809131786227226, -0.013871400617063046, 0.031328774988651276, 0.011140192858874798, 0.03601876273751259, -0.000054271367844194174, 0.01409971620887518, 0.00623690988868475, -0.008221292868256569, 0.037480685859918594, -0.01169124897569418, -0.019777441397309303, 0.0002808906720019877, -0.0007794873672537506, 0.021338509395718575, -0.017984827980399132, -0.03535928577184677, 0.02286021038889885, 0.07092906534671783, -0.030305983498692513, -0.02131485566496849, 0.024848779663443565, 0.021745197474956512, 0.04499715194106102, 0.005423161666840315, -0.07037066668272018, 0.012190991081297398, -0.009829728864133358, -0.039647817611694336, -0.02982756868004799, 0.08754358440637589, 0.025050874799489975, 0.005946439690887928, -0.043192677199840546, 0.023298582062125206, -0.05879779905080795, 0.02933584339916706, -0.004568133968859911, 0.006754882633686066, -0.059735529124736786, 0.027030790224671364, -0.06828340142965317, -0.04414113983511925, 0.0546422079205513, 0.04077156260609627, -0.010876390151679516, -0.026797955855727196, -0.023489056155085564, -0.02464411035180092, -0.008385811001062393, 0.026911292225122452, -0.011633031070232391, -0.03133603185415268, 0.022669648751616478, 0.012120665051043034, 0.003879853058606386, -0.006343713030219078, 0.0119999460875988, -0.00997039582580328, -0.02432161569595337, -0.01687711477279663, 0.03824774548411369, -0.0015350149478763342, 0.0075082117691636086, 0.01645115204155445, -0.002974942559376359, -0.0336444154381752, -0.011470705270767212, -0.010691878385841846, 0.0023771601263433695, -0.0055630942806601524, -0.05486056208610535, 0.0012262259842827916, 0.014420577324926853, 0.023532548919320107, 0.005652348976582289, 0.002235488733276725, 0.036542586982250214, -0.005302014760673046, 0.0311269611120224, 0.05503483861684799, 0.00975731573998928, -0.04879351332783699, -0.03440937027335167, 0.04144253209233284, -0.04211937263607979, 0.013787396252155304, 0.0013609620509669185, -0.014804056845605373, 0.0035153336357325315, -0.03145940974354744, 0.05590466782450676, 0.017204932868480682, 0.029368039220571518, 0.02018583193421364, -0.03864119201898575, 0.024304771795868874, 0.014425556175410748, 0.058059487491846085, -0.005899521987885237, 0.02537175826728344, 0.02689434215426445, -0.0035186056047677994, 0.024265818297863007, -0.04374341666698456, -0.011382454074919224, 0.018008248880505562, 0.02805297262966633, -0.02195444330573082, 0.026409951969981194, -0.00805196724832058, -0.029588816687464714, 0.02792663872241974, -0.017125871032476425, 0.006046042777597904, 0.033863816410303116, 0.008612580597400665, -0.0188736654818058, -0.0087997792288661, -0.013561873696744442, 0.018384195864200592, 0.04127466678619385, 0.028794918209314346, -0.006215969100594521, 0.059441111981868744, -0.017748238518834114, -0.020349889993667603, -0.023639682680368423, -0.010579554364085197, 0.03424140438437462, 0.026817141100764275, 0.0076599447056651115, -0.12826617062091827, -0.023522816598415375, 0.021220169961452484, -0.023539278656244278, -0.016606995835900307, -0.008546416647732258, -0.04616284370422363, 0.042811062186956406, 0.03310474380850792, 0.03549754247069359, 0.04223056137561798, -0.026652391999959946, -0.025336340069770813, 0.006387355737388134, 0.01427543442696333, 0.046750474721193314, -0.008147001266479492, 0.0006261937669478357, 0.04892527684569359, 0.025664202868938446, 0.03590654209256172, -0.01332799531519413, 0.02325320988893509, -0.024007178843021393, -0.017298659309744835, 0.023452073335647583, 0.019296951591968536, -0.004144249018281698, 0.007671321742236614, -0.02533498778939247, -0.004626671317964792, 0.01988344080746174, -0.0367635115981102, 0.03600671887397766, 0.06430995464324951, -0.002281115623190999, -0.007809903472661972, 0.02848992682993412, -0.006681967061012983, 0.0017364813247695565, -0.02233675681054592, 0.07303155958652496, -0.01805446669459343, -0.005253885872662067, 0.006377409212291241, -0.0152233662083745, -0.02125229500234127, 0.003250069683417678, -0.05195293575525284, -0.04118708521127701, 0.007960028015077114, 0.002025729278102517, 0.016083231195807457, -0.019076000899076462, -0.009052403271198273, 0.018087336793541908, 0.05434444546699524, 0.0285646915435791, -0.02147485315799713, 0.004273728001862764, 0.025319913402199745, 0.0015575774013996124, -0.015032606199383736, 0.03353618085384369, -0.037499431520700455, 0.00877357367426157, 0.03265247866511345, 0.012705611065030098, -0.001485270680859685, -0.03093324974179268, 0.016508208587765694, 0.03541982173919678, -0.0171416774392128, -0.0008765165694057941, -0.011042681522667408, -0.05726199224591255, 0.04033413156867027, -0.02759656310081482, -0.0019069501431658864, 0.09925879538059235, -0.005438564345240593, 0.02818680927157402, 0.0348130501806736, 0.042619895190000534, 0.014499267563223839, -0.017330070957541466, -0.030464716255664825, -0.014687148854136467, -0.020150993019342422, 0.010883161798119545, 0.025410989299416542, 0.020768946036696434, -0.05055036395788193, 0.03634781762957573, -0.02752755954861641, -0.042660921812057495, -0.03327958658337593, -0.003256740514189005, -0.02267986536026001, -0.002601894550025463, -0.045108381658792496, 0.012233852408826351, -0.0058285570703446865, 0.008400674909353256, 0.02216014824807644, 0.0253415796905756, 0.033870697021484375, 0.016301734372973442, -0.023981712758541107, 0.016270030289888382, 0.016836103051900864, -0.00299658440053463, 0.039576414972543716, -0.01989833451807499, 0.017042813822627068, 0.0527772381901741, -0.003294389694929123, -0.017996475100517273, 0.03324628993868828, 0.06257264316082001, 0.006101947743445635, -0.013983745127916336, 0.00962129607796669, 0.006157775409519672, -0.026359863579273224, -0.04338299483060837, 0.00976190622895956, -0.040230244398117065, -0.013792027719318867, -0.011130173690617085, 0.010733459144830704, -0.008854486979544163, -0.04490787908434868, 0.05787322297692299, 0.014372378587722778, 0.0058935643173754215, 0.0036859672982245684, 0.056178461760282516, -0.003910583443939686, -0.011523027904331684, 0.0007438914035446942, 0.059111785143613815, 0.003957290202379227, 0.017594249919056892, 0.07167079299688339, -0.026058297604322433, -0.006038985680788755, 0.005015077069401741, 0.011058195494115353, 0.019993923604488373, -0.02218940481543541, -0.002508050063624978, -0.01932937651872635, 0.01727476716041565, -0.012976237572729588, -0.05259145423769951, 0.004340050276368856, -0.061754051595926285, 0.002920210827142, -0.032565031200647354, -0.0179948341101408, -0.041739095002412796, -0.03798925504088402, -0.006939703598618507, 0.002263080794364214, -0.004611315205693245, -0.000269767246209085, -0.002070910297334194, 0.0008935160585679114, 0.022657083347439766, 0.011847293935716152, 0.005328823812305927, 0.02406274527311325, -0.006691372487694025, 0.028680473566055298, -0.008801518939435482, 0.008998951874673367, 0.006024974398314953, -0.009893229231238365, 0.038325387984514236, 0.054125070571899414, -0.042609140276908875, 0.03367467597126961, 0.0036267770919948816, 0.014869449660182, -0.022690877318382263, -0.002254849299788475, -0.011947705410420895, 0.0020764577202498913, 0.03366750106215477, 0.015139325521886349, -0.011299915611743927, 0.018477965146303177, 0.04635995626449585, 0.035272017121315, 0.035119276493787766, -0.013139838352799416, -0.06136515736579895, -0.005678053945302963, -0.03422947973012924, -0.007802973035722971, 0.030089272186160088, 0.005562233738601208, 0.00738099031150341, 0.042380236089229584, -0.042422086000442505, -0.0171810295432806, -0.016687829047441483, -0.03134456276893616, 0.01135904062539339, -0.010372756980359554, 0.0016480586491525173, -0.004903843626379967, 0.09054642170667648, 0.04598945006728172, -0.003496935125440359, 0.023552462458610535, 0.014615525491535664, -0.013954433612525463, -0.006633801851421595, -0.00560810836032033, 0.007775140926241875, 0.01723669283092022, -0.02522464655339718, -0.07342356443405151, -0.016743581742048264, 0.004365431144833565, 0.024384168907999992, 0.0008345253299921751, -0.06467940658330917, 0.004996520932763815, -0.013854125514626503, -0.008488895371556282, 0.025158729404211044, -0.008425592444837093, 0.02099931240081787, 0.04238478094339371, -0.008754074573516846, 0.004714399576187134, -0.05761544033885002, 0.01915036328136921, -0.026358673349022865, 0.026482580229640007, 0.03802092745900154, 0.03980571776628494, -0.0070619829930365086, -0.029764441773295403, 0.036618564277887344, -0.022011976689100266, -0.027207858860492706, 0.0003283283149357885, 0.00014319285401143134, -0.023585285991430283, -0.06517321616411209, 0.004290963523089886, 0.02725379355251789, -0.005966823548078537, 0.002535464009270072, -0.009292639791965485, -0.012224890291690826, -0.022710543125867844, -0.027365904301404953, -0.06045052409172058, -0.00937127135694027, -0.015318461693823338, -0.02489634044468403, 0.024449793621897697, 0.015293952077627182, 0.013785254210233688, 0.003644661046564579, -0.02797417901456356, 0.03098292089998722, -0.0030310486909002066, -0.031862303614616394, -0.02003614790737629, 0.005059526767581701, 0.0328829400241375, -0.011723383329808712, -0.03775271400809288, 0.034929629415273666, -0.011279109865427017, -0.021067162975668907, 0.00972314365208149, 0.013522526249289513, 0.017693806439638138, -0.036465395241975784, 0.02005895972251892, -0.04167656600475311, 0.01686563529074192, 0.007411619648337364, -0.040301449596881866, -0.03363539278507233, -0.006387018598616123 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
fairseq's tokenizer workings Let's understand howfairseq's tokenizer works.fairseq(*) uses the [Byte Pair Encoding](https://en.wikipedia.org/wiki/Byte_pair_encoding) (BPE) algorithm for tokenization. * footnote: from here on when I refer tofairseq, I refer [to this specific model implementation](https://github.com/pytorch/fairseq/tree/master/examples/wmt19) - thefairseqproject itself has dozens of different implementations of different models. Let's see what BPE does: ``` import torch sentence = "Machine Learning is great" checkpoint_file='model4.pt' model = torch.hub.load('pytorch/fairseq', 'transformer.wmt19.en-ru', checkpoint_file=checkpoint_file, tokenizer='moses', bpe='fastbpe') # encode step by step tokens = model.tokenize(sentence) print("tokenize ", tokens) bpe = model.apply_bpe(tokens) print("apply_bpe: ", bpe) bin = model.binarize(bpe) print("binarize: ", len(bin), bin) # compare to model.encode - should give us the same output expected = model.encode(sentence) print("encode: ", len(expected), expected) ``` gives us: ``` ('tokenize ', 'Machine Learning is great') ('apply_bpe: ', 'Mach@@ ine Lear@@ ning is great') ('binarize: ', 7, tensor([10217, 1419, 3, 2515, 21, 1054, 2])) ('encode: ', 7, tensor([10217, 1419, 3, 2515, 21, 1054, 2])) ``` You can see thatmodel.encodedoestokenize+apply_bpe+binarize- as we get the same output. The steps were: 1.tokenize: normally it'd escape apostrophes and do other pre-processing, in this example it just returned the input sentence without any changes 2.apply_bpe: BPE splits the input into words and sub-words according to itsbpecodesfile supplied by the tokenizer - we get 6 BPE chunks 3.binarize: this simply remaps the BPE chunks from the previous step into their corresponding ids in the vocabulary (which is also downloaded with the model) You can refer to [this notebook](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/nbs/tokenizer.ipynb) to see more details. This is a good time to look inside thebpecodesfile. Here is the top of the file: ``` $ head -15 ~/porting/pytorch_fairseq_model/bpecodes e n</w> 1423551864 e r 1300703664 e r</w> 1142368899 i n 1130674201 c h 933581741 a n 845658658 t h 811639783 e n 780050874 u n 661783167 s t 592856434 e i 579569900 a r 494774817 a l 444331573 o r 439176406 th e</w> 432025210 [...] ``` The top entries of this file include very frequent short 1-letter sequences. As we will see in a moment the bottom includes the most common multi-letter sub-words and even full long words. A special tokenindicates the end of the word. So in several lines quoted above we find: ``` e n</w> 1423551864 e r</w> 1142368899 th e</w> 432025210 ``` If the second column doesn't include, it means that this segment is found in the middle of the word and not at the end of it. The last column declares the number of times this BPE code has been encountered while being trained. Thebpecodesfile is sorted by this column - so the most common BPE codes are on top. By looking at the counts we now know that when this tokenizer was trained it encountered 1,423,551,864 words ending inen, 1,142,368,899 words ending inerand 432,025,210 words ending inthe. For the latter it most likely means the actual wordthe, but it would also include words likelathe,loathe,tithe, etc. These huge numbers also indicate to us that this tokenizer was trained on an enormous amount of text! If we look at the bottom of the same file: ``` $ tail -10 ~/porting/pytorch_fairseq_model/bpecodes 4 x 109019 F ische</w> 109018 sal aries</w> 109012 e kt 108978 ver gewal 108978 Sten cils</w> 108977 Freiwilli ge</w> 108969 doub les</w> 108965 po ckets</w> 108953 Gö tz</w> 108943 ``` we see complex combinations of sub-words which are still pretty frequent, e.g.sal ariesfor 109,012 times! So it got its own dedicated entry in thebpecodesmap file. Howapply_bpedoes its work? By looking up the various combinations of letters in thebpecodesmap file and when finding the longest fitting entry it uses that. Going back to our example, we saw that it splitMachineinto:Mach@@+ine- let's check: ``` $ grep -i ^mach ~/porting/pytorch_fairseq_model/bpecodes mach ine</w> 463985 Mach t 376252 Mach ines</w> 374223 mach ines</w> 214050 Mach th 119438 ``` You can see that it hasmach ine. We don't seeMach inein there - so it must be handling lower cased look ups when normal case is not matching. Now let's check:Lear@@+ning``` $ grep -i ^lear ~/porting/pytorch_fairseq_model/bpecodes lear n</w> 675290 lear ned</w> 505087 lear ning</w> 417623 ``` We findlear ningis there (again the case is not the same). Thinking more about it, the case probably doesn't matter for tokenization, as long as there is a unique entry forMach/Learandmach/learin the dictionary where it's very critical to have each case covered. Hopefully, you can now see how this works. One confusing thing is that if you remember theapply_bpeoutput was: ``` ('apply_bpe: ', 6, ['Mach@@', 'ine', 'Lear@@', 'ning', 'is', 'great']) ``` Instead of marking endings of the words with, it leaves those as is, but, instead, marks words that were not the endings with@@. This is probably so, becausefastBPEimplementation is used byfairseqand that's how it does things. I had to change this to fit thetransformersimplementation, which doesn't usefastBPE. One last thing to check is the remapping of the BPE codes to vocabulary ids. To repeat, we had: ``` ('apply_bpe: ', 'Mach@@ ine Lear@@ ning is great') ('binarize: ', 7, tensor([10217, 1419, 3, 2515, 21, 1054, 2])) ```2- the last token id is aeos(end of stream) token. It's used to indicate to the model the end of input. And thenMach@@gets remapped to10217, andineto1419. Let's check that the dictionary file is in agreement: ``` $ grep ^Mach@@ ~/porting/pytorch_fairseq_model/dict.en.txt Mach@@ 6410 $ grep "^ine " ~/porting/pytorch_fairseq_model/dict.en.txt ine 88376 ``` Wait a second - those aren't the ids that we got afterbinarize, which should be10217and1419correspondingly. It took some investigating to find out that the vocab file ids aren't the ids used by the model and that internally it remaps them to new ids once the vocab file is loaded. Luckily, I didn't need to figure out how exactly it was done. Instead, I just usedfairseq.data.dictionary.Dictionary.loadto load the dictionary (*), which performed all the re-mappings, - and I then saved the final dictionary. I found out about thatDictionaryclass by stepping throughfairseqcode with debugger. * footnote: the more I work on porting models and datasets, the more I realize that putting the original code to work for me, rather than trying to replicate it, is a huge time saver and most importantly that code has already been tested - it's too easy to miss something and down the road discover big problems! After all, at the end, none of this conversion code will matter, since only the data it generated will be used bytransformersand its end users. Here is the relevant part of the conversion script: ``` from fairseq.data.dictionary import Dictionary def rewrite_dict_keys(d): # (1) remove word breaking symbol # (2) add word ending symbol where the word is not broken up, # e.g.: d = {'le@@': 5, 'tt@@': 6, 'er': 7} => {'le': 5, 'tt': 6, 'er</w>': 7} d2 = dict((re.sub(r"@@$", "", k), v) if k.endswith("@@") else (re.sub(r"$", "</w>", k), v) for k, v in d.items()) keep_keys = "<s> <pad> </s> <unk>".split() # restore the special tokens for k in keep_keys: del d2[f"{k}</w>"] d2[k] = d[k] # restore return d2 src_dict_file = os.path.join(fsmt_folder_path, f"dict.{src_lang}.txt") src_dict = Dictionary.load(src_dict_file) src_vocab = rewrite_dict_keys(src_dict.indices) src_vocab_size = len(src_vocab) src_vocab_file = os.path.join(pytorch_dump_folder_path, "vocab-src.json") print(f"Generating {src_vocab_file}") with open(src_vocab_file, "w", encoding="utf-8") as f: f.write(json.dumps(src_vocab, ensure_ascii=False, indent=json_indent)) # we did the same for the target dict - omitted quoting it here # and we also had to savebpecodes, it's calledmerges.txtin the transformers land ``` After running the conversion script, let's check the converted dictionary: ``` $ grep '"Mach"' /code/huggingface/transformers-fair-wmt/data/wmt19-en-ru/vocab-src.json "Mach": 10217, $ grep '"ine</w>":' /code/huggingface/transformers-fair-wmt/data/wmt19-en-ru/vocab-src.json "ine</w>": 1419, ``` We have the correct ids in thetransformersversion of the vocab file. As you can see I also had to re-write the vocabularies to match thetransformersBPE implementation. We have to change: ``` ['Mach@@', 'ine', 'Lear@@', 'ning', 'is', 'great'] ``` to: ``` ['Mach', 'ine</w>', 'Lear', 'ning</w>', 'is</w>', 'great</w>'] ``` Instead of marking chunks that are segments of a word, with the exception of the last segment, we mark segments or words that are the final segment. One can easily go from one style of encoding to another and back. This successfully completed the porting of the first part of the model files. You can see the final version of the code [here](https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/src/transformers/convert_fsmt_original_pytorch_checkpoint_to_pytorch.py#L128). If you're curious to look deeper there are more tinkering bits in [this notebook](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/nbs/tokenizer-dev.ipynb).
[ 0.012999888509511948, 0.00003182008003932424, 0.030631665140390396, -0.03920295462012291, 0.03577396646142006, 0.05611729249358177, 0.025367390364408493, 0.032623060047626495, -0.04281621426343918, 0.039725739508867264, -0.08109395205974579, -0.006684427615255117, 0.02420806512236595, 0.05291314423084259, -0.03340042382478714, 0.04203421249985695, 0.040650516748428345, -0.02892518974840641, -0.023853907361626625, -0.0378132089972496, 0.001245106104761362, -0.002997152740135789, 0.09032613039016724, 0.006670819595456123, -0.009055586531758308, -0.03610352799296379, -0.04697598144412041, -0.018220728263258934, -0.025026623159646988, 0.027210496366024017, -0.08355071395635605, -0.06375445425510406, -0.016423849388957024, -0.07057985663414001, -0.005669882055372, 0.0036183588672429323, -0.10942152142524719, 0.032564353197813034, 0.06650150567293167, -0.021424127742648125, -0.04633916914463043, -0.01493646577000618, -0.04608459398150444, 0.07820326834917068, -0.018722325563430786, 0.011343740858137608, -0.09699229896068573, 0.02639632672071457, -0.03142118081450462, -0.014137073419988155, -0.061315346509218216, -0.0023995821829885244, -0.07948314398527145, 0.057542622089385986, 0.011687478050589561, 0.005368315614759922, -0.05569090321660042, -0.03683855012059212, 0.08120956271886826, 0.03939196094870567, 0.03591751679778099, 0.011122399941086769, 0.020237719640135765, -0.001647177035920322, 0.03974492475390434, 0.02405601367354393, -0.05168985575437546, 0.054528526961803436, 0.008003249764442444, -0.0058874827809631824, -0.002409079112112522, 0.016203638166189194, -0.007743933238089085, -0.04323737323284149, -0.023893535137176514, -0.0514734722673893, -0.026742085814476013, -0.035473693162202835, 0.04583754017949104, 0.08112380653619766, -0.03137525916099548, 0.06479994207620621, 0.05219721421599388, -0.0038988804444670677, 0.022334404289722443, 0.0016812303801998496, -0.017506491392850876, -0.04139763489365578, -0.02709849365055561, 0.0004469245614018291, -0.04022294282913208, -0.13823963701725006, -0.05045801028609276, 0.06871874630451202, -0.026101049035787582, 0.017699163407087326, 0.03929278999567032, 0.07874275743961334, -0.001738145132549107, 0.019457682967185974, -0.046081144362688065, -0.09103299677371979, 0.05539414659142494, -0.0011923240963369608, -0.01607614941895008, 0.057689178735017776, -0.028547991067171097, -0.07544266432523727, -0.0033343646209686995, -0.0037818036507815123, 0.03271862864494324, -0.027652181684970856, -0.03656734898686409, 0.07902239263057709, -0.048020221292972565, 0.009515166282653809, -0.02575293742120266, 0.015133706852793694, 0.010492458939552307, 0.07764583081007004, -0.023069582879543304, 0.10143062472343445, 0.09398018568754196, -0.02521192468702793, 0.014774161390960217, 0.01320808194577694, 0.02936762012541294, 0.029460236430168152, -0.05902514606714249, -0.04455443099141121, -0.003824805375188589, -0.0048099844716489315, 0.04941002279520035, -0.013626495376229286, 0.011450720950961113, -0.00016468226385768503, 0.008766114711761475, -0.04396269842982292, -0.041415873914957047, -0.029048345983028412, -0.08353554457426071, 0.07283052057027817, 0.023952752351760864, 0.030000654980540276, 0.012050599791109562, 0.05017320439219475, -0.06332921981811523, 0.11578338593244553, -0.010488027706742287, 0.015292303636670113, -0.008879542350769043, 0.024920912459492683, 0.054314304143190384, -0.05090592801570892, 0.008423340506851673, 0.008503952994942665, -0.026727041229605675, -0.01490851305425167, -0.011001337319612503, -0.039322808384895325, -0.05448498576879501, -0.06023182347416878, -0.04850887879729271, -0.047309327870607376, -0.05030131712555885, 0.02847359888255596, 0.02495112456381321, 0.02006201446056366, -0.0005724246148020029, 0.03281218931078911, 0.08440915495157242, -0.03997617959976196, 0.0511164665222168, -0.0501297265291214, -0.024183500558137894, 0.05309004336595535, -0.017904845997691154, 0.06494379043579102, 0.02902127243578434, -0.03014220856130123, -0.04565451294183731, 0.023952361196279526, -0.04588286206126213, 0.020344799384474754, 0.023853057995438576, -0.06794436275959015, -0.007108885794878006, -0.033274367451667786, 0.05025971680879593, 0.09023995697498322, -0.07495284080505371, 0.011216901242733002, 0.05876939371228218, -0.08284100145101547, -0.042817480862140656, -0.04444234445691109, -0.003829427994787693, 0.07802043110132217, -0.01305001974105835, -0.003916311543434858, 0.03498739376664162, -0.022818710654973984, 0.019646083936095238, -0.05160451680421829, -0.04783812537789345, 0.02611808478832245, 0.001507243956439197, -0.06891388446092606, 0.047937534749507904, 0.023535732179880142, 0.018985731527209282, -0.06198316067457199, 0.008229350671172142, -0.07566379010677338, -0.0004685657622758299, -0.005485652945935726, 0.001470580231398344, 0.02321382611989975, 0.025524787604808807, -0.022162949666380882, 0.18574552237987518, -0.11116006970405579, 0.03820378705859184, -0.04947289451956749, 0.02784300036728382, 0.04989936947822571, 0.07072204351425171, 0.01100545097142458, 0.05075172334909439, -0.05567473545670509, 0.0029429132118821144, -0.0330425500869751, 0.009577116928994656, 0.022483818233013153, -0.10088756680488586, -0.03516662120819092, 0.029168643057346344, 0.04359038546681404, 0.04085328429937363, -0.03908373415470123, 0.01794249750673771, 0.04934683069586754, -0.04520212486386299, -0.028756944462656975, -0.004226848483085632, 0.057077568024396896, 0.11840188503265381, -0.03269140422344208, -0.030278626829385757, -0.02576717920601368, -0.011057600378990173, 0.04144029691815376, -0.036301013082265854, -0.03184577822685242, 0.037965089082717896, 0.05037326738238335, 0.05926201492547989, -0.038242511451244354, 0.021639419719576836, 0.01878505013883114, -0.00003481188468867913, -0.012057612650096416, -0.0337938591837883, -0.04063340649008751, -0.018412819132208824, -0.015496929176151752, 0.008168589323759079, 0.018884729593992233, 0.004593053832650185, 0.02042379602789879, 0.003107370575889945, 0.01728356070816517, 0.02553846314549446, -0.007470757234841585, 0.0437612421810627, 0.048184048384428024, 0.0003540863108355552, -0.07415051013231277, -0.011894850991666317, -0.022706545889377594, -0.00905119813978672, -0.008891040459275246, 0.03420139476656914, 0.04626332223415375, -0.00861490610986948, 0.022972917184233665, 0.007818995043635368, -0.04692729189991951, -0.05982643738389015, 0.045051515102386475, 0.025285877287387848, 0.011995730921626091, 0.044644374400377274, -0.014883259311318398, -0.008715174160897732, 0.0033959064166992903, -0.040005162358284, 0.003419413696974516, 0.007184617221355438, 0.039716869592666626, -0.03196768835186958, -0.01237878855317831, -0.02209881693124771, -0.016216320917010307, -0.047712527215480804, 0.005494791083037853, -0.026380054652690887, 0.010144537314772606, -0.07788200676441193, 0.017647748813033104, -0.01185101643204689, 0.010280495509505272, -0.011571592651307583, -0.013369795866310596, 0.05435088649392128, 0.028539150953292847, -0.010436990298330784, 0.021792538464069366, 0.026667186990380287, -0.019674895331263542, -0.005663963500410318, 0.02205510437488556, -0.021117208525538445, 0.02911483868956566, -0.032377827912569046, 0.017588600516319275, -0.041890501976013184, -0.01908600889146328, -0.006014599464833736, 0.027784358710050583, -0.05048920586705208, -0.040460653603076935, 0.00743165984749794, -0.01350086648017168, 0.028402578085660934, 0.005460573825985193, 0.0015777841908857226, -0.028422310948371887, -0.04909564554691315, 0.011814214289188385, 0.04480091482400894, -0.02640802413225174, -0.04986520856618881, -0.03144203498959541, 0.007568253204226494, -0.043893277645111084, -0.03038553148508072, 0.022508496418595314, -0.012957999482750893, 0.04935227334499359, 0.034537311643362045, -0.054625026881694794, 0.014379684813320637, -0.031568411737680435, -0.02709975838661194, -0.024138059467077255, 0.040263861417770386, -0.058831583708524704, -0.01330993976444006, -0.028620200231671333, 0.016499027609825134, 0.05574367195367813, 0.010018127970397472, -0.016666710376739502, -0.024997875094413757, 0.005076911300420761, 0.06241586431860924, 0.011081420816481113, -0.08041878044605255, 0.021827220916748047, -0.026793770492076874, -0.05071891471743584, -0.03212569281458855, 0.05124760791659355, 0.012871664948761463, -0.0018306220881640911, -0.0018806683365255594, 0.01204754039645195, -0.03954927623271942, 0.033077869564294815, -0.0005038288654759526, 0.00758419930934906, 0.028583208099007607, 0.021738171577453613, -0.017229551449418068, -0.04436417296528816, 0.009808661416172981, 0.03946000337600708, 0.001425774535164237, -0.014532387256622314, -0.005753862671554089, -0.01413392648100853, 0.0037028412334620953, -0.014353569597005844, -0.012304051779210567, -0.03667619824409485, 0.002526721218600869, 0.006729558575898409, 0.014739548787474632, -0.012568882666528225, 0.016379039734601974, 0.054701101034879684, -0.026399405673146248, -0.02614608034491539, 0.001890325453132391, 0.021953077986836433, 0.0021226415410637856, 0.007910764776170254, -0.0067605432122945786, -0.08474569022655487, -0.027893569320440292, -0.006098393350839615, 0.002165356185287237, 0.007307313848286867, -0.05307542532682419, -0.009599665179848671, 0.017391741275787354, 0.04259577766060829, -0.012511145323514938, 0.010915410704910755, -0.01813056506216526, -0.017897265031933784, 0.04518115147948265, -0.016742248088121414, 0.02733447402715683, -0.035095930099487305, 0.023411890491843224, -0.020374363288283348, -0.026734748855233192, -0.0033360670786350965, 0.024100495502352715, 0.0051406132988631725, -0.0029494925402104855, -0.013690262101590633, 0.027203690260648727, -0.0151036586612463, 0.04053514823317528, -0.01670660637319088, -0.08555421978235245, 0.030713828280568123, 0.026799257844686508, -0.014260439202189445, 0.013809800148010254, 0.03731366619467735, 0.016496198251843452, -0.008628176525235176, 0.01988433115184307, -0.05150213465094566, -0.012337462045252323, -0.012845389544963837, 0.018162289634346962, -0.034165650606155396, 0.018449826166033745, 0.03566107898950577, -0.01467007678002119, -0.012872307561337948, -0.04630514979362488, 0.010407141409814358, 0.05926508083939552, -0.01259816437959671, -0.008857274428009987, -0.018960436806082726, 0.0392884835600853, -0.02934773452579975, 0.009007954970002174, 0.0018255331087857485, 0.016160041093826294, 0.0006860009161755443, -0.008199180476367474, -0.021602539345622063, -0.03158941492438316, 0.031403880566358566, 0.017570791766047478, -0.03284712880849838, -0.012855913490056992, -0.05018341913819313, -0.027261503040790558, 0.0030718587804585695, -0.020461110398173332, 0.0031690034084022045, -0.008407467044889927, -0.024685382843017578, 0.025989769026637077, 0.031637996435165405, 0.011846777983009815, 0.021831780672073364, -0.03557416424155235, -0.01452886313199997, -0.0027227234095335007, 0.027525030076503754, 0.040910348296165466, -0.02946668118238449, -0.01962248608469963, 0.05213820934295654, 0.057201649993658066, 0.03447513282299042, -0.009815244004130363, 0.021365022286772728, 0.03172050043940544, -0.011460385285317898, -0.00024601921904832125, -0.00497376499697566, -0.045117273926734924, -0.03545089438557625, -0.017579540610313416, 0.009287950582802296, -0.03979033604264259, -0.015078451484441757, 0.023258570581674576, 0.03833729773759842, 0.03126603737473488, -0.030657455325126648, 0.0069945440627634525, -0.052436165511608124, -0.014629969373345375, -0.03406737744808197, 0.012168134562671185, -0.05550026521086693, 0.01858474500477314, 0.0016258707037195563, -0.02575787715613842, -0.01718534156680107, 0.0010020831832662225, -0.0021497104316949844, -0.009007930755615234, 0.03580110892653465, -0.004797258879989386, 0.06216665729880333, -0.016771700233221054, -0.009859558194875717, -0.016056591644883156, 0.013321572914719582, 0.032590676099061966, -0.01331614051014185, 0.014433079399168491, 0.010775264352560043, 0.03461325541138649, 0.031421929597854614, 0.02775038778781891, -0.013467605225741863, -0.003038114635273814, 0.011890890076756477, -0.01571779139339924, -0.015791188925504684, 0.0017502176342532039, -0.005542488303035498, 0.023713549599051476, 0.006871163845062256, 0.04666471853852272, -0.032209958881139755, -0.010087448172271252, 0.01752026192843914, -0.0346660315990448, 0.022374950349330902, 0.02940879575908184, -0.022904178127646446, 0.031201574951410294, 0.014710905961692333, 0.03160976618528366, -0.015962833538651466, -0.007975797168910503, 0.009326678700745106, 0.04292338714003563, 0.03073657490313053, 0.08693138509988785, -0.0014303846983239055, 0.007709234952926636, 0.009415733627974987, 0.05994595214724541, -0.05919612571597099, -0.0021550978999584913, 0.021482525393366814, -0.028391387313604355, 0.04294693470001221, -0.010819128714501858, -0.03135642036795616, 0.0023810616694390774, -0.002177851740270853, 0.020195642486214638, -0.007439394015818834, 0.0021794727072119713, 0.057858847081661224, -0.03233691304922104, 0.015488560311496258, 0.004236641805619001, 0.08976216614246368, -0.03640782833099365, 0.04194890335202217, 0.0023320068139582872, 0.005536402575671673, 0.0025889903772622347, 0.008053668774664402, -0.0028336658142507076, -0.001077562104910612, 0.07047014683485031, 0.012553946115076542, 0.029662001878023148, 0.044887445867061615, 0.039309728890657425, 0.0014480534009635448, -0.033782895654439926, -0.02129262313246727, 0.00260772998444736, 0.022853733971714973, 0.040842581540346146, -0.003941952250897884, 0.041166290640830994, -0.008880874142050743, 0.031301602721214294, 0.015360224060714245, 0.05255916342139244, -0.03114614263176918, 0.02246355637907982, 0.0224996879696846, 0.01583668403327465, 0.05585342273116112, -0.007448019925504923, -0.008884343318641186, 0.037257250398397446, 0.08653276413679123, 0.05176592245697975, 0.007402883376926184, 0.0064642163924872875, -0.044465504586696625, 0.02211678959429264, 0.004796092864125967, -0.034883856773376465, 0.015802327543497086, 0.0407397598028183, -0.02324485220015049, 0.013558292761445045, 0.026286721229553223, 0.013651544228196144, 0.020238764584064484, -0.013887627981603146, -0.02463984489440918, -0.006361707113683224, 0.0016696483362466097, -0.009271879680454731, 0.04330552741885185, 0.00017772453429643065, -0.07911139726638794, -0.024723950773477554, 0.006965907756239176, -0.0009270181762985885, 0.03860422596335411, -0.035571739077568054, -0.008318689651787281, -0.012615814805030823, -0.016830993816256523, -0.02926100231707096, -0.004476380068808794, -0.018993165343999863, 0.025955315679311752, 0.01883259415626526, 0.031193289905786514, 0.017859693616628647, 0.00689266761764884, 0.005048171617090702, 0.030620379373431206, -0.015303230844438076, 0.005843724589794874, -0.02187645249068737, -0.014058982022106647, 0.04372865706682205, -0.0011386744445189834, 0.014678058214485645, 0.011586744338274002, 0.011766928248107433, 0.04257091507315636, 0.03671566769480705, -0.024146489799022675, -0.06600145995616913, -0.026532629504799843, -0.021643176674842834, -0.032443203032016754, -0.01863854192197323, 0.03385510295629501, 0.03891878202557564, -0.014138898812234402, -0.0013449748512357473, -0.019328143447637558, 0.018159501254558563, -0.003125166753306985, 0.03164025396108627, -0.015602443367242813, -0.03447205573320389, -0.03826019912958145, 0.0699688121676445, 0.019423391669988632, 0.02682298794388771, 0.06978238373994827, 0.0024218549951910973, 0.011546035297214985, 0.025456627830863, 0.022449389100074768, -0.07445990294218063, -0.0066949957981705666, 0.015163475647568703, -0.017976107075810432, 0.010326571762561798, 0.03290804475545883, -0.020021922886371613, 0.04101186245679855, -0.021842967718839645, 0.03812475502490997, -0.010140583850443363, -0.012736255303025246, 0.009015464223921299, -0.022319331765174866, 0.06811936944723129, 0.023874739184975624, -0.008799855597317219, 0.011577164754271507, -0.04529157280921936, -0.006154712755233049, -0.006014305166900158, 0.002302295295521617, 0.0946393758058548, -0.010699321515858173, 0.0015563450288027525, 0.014592421241104603, 0.013063641265034676, -0.021944085136055946, -0.02713966928422451, 0.0014838080387562513, -0.011748824268579483, 0.010996183380484581, -0.021854940801858902, 0.05495890602469444, 0.006802846677601337, -0.008486787788569927, 0.01302457507699728, -0.013677025213837624, 0.03490221127867699, 0.004408420063555241, -0.00684813316911459, -0.08084419369697571, -0.012343153357505798, -0.02747245691716671, -0.02157185599207878, 0.0030720429494976997, 0.018852150067687035, 0.03395272418856621, 0.031470175832509995, -0.026394261047244072, -0.044960811734199524, -0.00581604428589344, -0.005409395322203636, -0.011099005118012428, -0.018020877614617348, 0.03585308790206909, -0.01377890445291996, -0.03978973254561424, 0.06429726630449295, -0.017961876466870308, -0.037071343511343, 0.010463823564350605, 0.004593485035002232, -0.005636336747556925, -0.006970626302063465, -0.0005532934446819127, 0.006449602544307709, 0.053130317479372025, 0.024287572130560875, 0.004936284851282835, -0.0035740849561989307, -0.007910584099590778 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Porting tokenizer's encoder to transformerstransformerscan't rely on [fastBPE](https://github.com/glample/fastBPE) since the latter requires a C-compiler, but luckily someone already implemented a python version of the same in [tokenization_xlm.py](https://github.com/huggingface/transformers/blob/master/src/transformers/tokenization_xlm.py). So I just copied it tosrc/transformers/tokenization_fsmt.pyand renamed the class names: ``` cp tokenization_xlm.py tokenization_fsmt.py perl -pi -e 's|XLM|FSMT|ig; s|xlm|fsmt|g;' tokenization_fsmt.py ``` and with very few changes I had a working encoder part of the tokenizer. There was a lot of code that didn't apply to the languages I needed to support, so I removed that code. Since I needed 2 different vocabularies, instead of one here in tokenizer and everywhere else I had to change the code to support both. So for example I had to override the super-class' methods: ``` def get_vocab(self) -> Dict[str, int]: return self.get_src_vocab() @property def vocab_size(self) -> int: return self.src_vocab_size ``` Sincefairseqdidn't usebos(beginning of stream) tokens, I also had to change the code to not include those (*): ``` - return bos + token_ids_0 + sep - return bos + token_ids_0 + sep + token_ids_1 + sep + return token_ids_0 + sep + return token_ids_0 + sep + token_ids_1 + sep ``` * footnote: this is the output ofdiff(1)which shows the difference between two chunks of code - lines starting with-show what was removed, and with+what was added.fairseqwas also escaping characters and performing an aggressive dash splitting, so I had to also change: ``` - [...].tokenize(text, return_str=False, escape=False) + [...].tokenize(text, return_str=False, escape=True, aggressive_dash_splits=True) ``` If you're following along, and would like to see all the changes I did to the originaltokenization_xlm.py, you can do: ``` cp tokenization_xlm.py tokenization_orig.py perl -pi -e 's|XLM|FSMT|g; s|xlm|fsmt|g;' tokenization_orig.py diff -u tokenization_orig.py tokenization_fsmt.py | less ``` Just make sure you're checking out the repository [around the time fsmt was released](https://github.com/huggingface/transformers/tree/129fdae04033fe4adfe013b734deaec6ec34ae2e), since the 2 files could have diverged since then. The final stage was to run through a bunch of inputs and to ensure that the ported tokenizer produced the same ids as the original. You can see this is done in [this notebook](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/nbs/tokenizer.ipynb), which I was running repeatedly while trying to figure out how to make the outputs match. This is how most of the porting process went, I'd take a small feature, run it thefairseq-way, get the outputs, do the same with thetransformerscode, try to make the outputs match - fiddle with the code until it did, then try a different kind of input make sure it produced the same outputs, and so on, until all inputs produced outputs that matched.
[ -0.020947039127349854, 0.010850591585040092, -0.0009285052074119449, -0.021306099370121956, 0.01673845201730728, 0.03399822860956192, 0.021946053951978683, 0.012619519606232643, -0.0019273069920018315, 0.059480804949998856, -0.09401310980319977, 0.04887640103697777, -0.019073136150836945, 0.05917089432477951, 0.040025513619184494, 0.028307054191827774, 0.03067711926996708, 0.0025419776793569326, 0.04208644479513168, 0.009790127165615559, -0.008101997897028923, -0.036977507174015045, 0.05572398751974106, 0.0025823120959103107, -0.028815506026148796, -0.033718377351760864, -0.04635366052389145, 0.04351727291941643, -0.044632792472839355, 0.020495444536209106, -0.08638586848974228, -0.01342440489679575, 0.019787082448601723, -0.011241262778639793, -0.009083857759833336, -0.00450539868324995, -0.15815246105194092, -0.008530333638191223, 0.01838335022330284, 0.03759784251451492, -0.013066377490758896, 0.004749728366732597, -0.023921631276607513, 0.06517452746629715, 0.015144086442887783, 0.016548199579119682, -0.161280557513237, 0.06495273858308792, -0.040015026926994324, -0.02382340095937252, -0.0337231419980526, 0.025936003774404526, -0.016003375872969627, 0.03917407616972923, 0.03490254282951355, -0.0022289289627224207, -0.05325242877006531, -0.07110469788312912, 0.009680322371423244, -0.013006146065890789, 0.009742251597344875, -0.00033876587986014783, 0.0030796248465776443, 0.002847149968147278, 0.06180576980113983, 0.06442859023809433, -0.08120536059141159, 0.007039710413664579, -0.04027024284005165, -0.05200674384832382, 0.004244898911565542, -0.026750201359391212, -0.010599725879728794, -0.014647596515715122, -0.01675770804286003, -0.08099900186061859, 0.00036463444121181965, 0.01532729808241129, 0.06756916642189026, 0.08965221047401428, 0.020955871790647507, 0.04438058286905289, 0.042326707392930984, 0.03314869850873947, 0.05181248113512993, 0.004758269060403109, 0.02538440003991127, -0.07743033021688461, -0.03016987442970276, 0.04250533506274223, -0.05030437558889389, -0.13462360203266144, -0.10184197872877121, 0.029991216957569122, 0.017751434817910194, 0.029399743303656578, -0.0029415523167699575, 0.05962001532316208, -0.0183595921844244, -0.0152763482183218, 0.006307096220552921, -0.05237564072012901, 0.012393024750053883, -0.037363436073064804, 0.02090732753276825, -0.01716729626059532, -0.03130914270877838, -0.07378249615430832, 0.006721563171595335, -0.04918709769845009, 0.09368540346622467, -0.025416051968932152, -0.007654900196939707, 0.06353612244129181, -0.04843948408961296, 0.01735031045973301, 0.009521400555968285, -0.02472759038209915, -0.008897111751139164, 0.027558250352740288, -0.01507239043712616, 0.1302400529384613, 0.01701122522354126, -0.04344873130321503, 0.018975360319018364, 0.10283078253269196, 0.02103135734796524, 0.05910172313451767, 0.022272225469350815, -0.04697353020310402, 0.006002152804285288, 0.02747352421283722, 0.07101473957300186, -0.0008339277119375765, 0.003093175822868943, -0.07558902353048325, 0.0009459687280468643, -0.06755100935697556, -0.0765770822763443, -0.023728888481855392, -0.05230950191617012, 0.0802660882472992, -0.032604049891233444, 0.012009276077151299, -0.0219851266592741, 0.0746367797255516, -0.11165237426757812, 0.11479783803224564, 0.0016167695866897702, -0.02015867456793785, -0.05526351556181908, -0.008752761408686638, 0.01351169403642416, -0.0028288671746850014, 0.015274829231202602, 0.08113091439008713, -0.011321607045829296, -0.015348901972174644, -0.09499730914831161, 0.023731352761387825, -0.08183372020721436, 0.03938420116901398, -0.05149776488542557, -0.001748027396388352, -0.03007449395954609, -0.04890016093850136, -0.009291168302297592, 0.014504581689834595, 0.012675628066062927, 0.003545391606166959, 0.0752476155757904, -0.017664160579442978, 0.010588129982352257, -0.024638058617711067, 0.005158731248229742, 0.026737531647086143, 0.019113842397928238, 0.0527203269302845, -0.011304061859846115, -0.029685314744710922, -0.06356494128704071, 0.0422956608235836, -0.021654702723026276, 0.05050193518400192, -0.0003676078631542623, -0.05154770240187645, 0.004267894197255373, -0.017213281244039536, -0.0006382836145348847, 0.057229846715927124, -0.055331457406282425, -0.06572268158197403, 0.05144768953323364, 0.003131115809082985, 0.006275393068790436, -0.005886753089725971, -0.013577437959611416, 0.06703038513660431, 0.015460047870874405, 0.039000920951366425, 0.007271154318004847, -0.018953850492835045, -0.04543524608016014, -0.015105120837688446, -0.01646270602941513, 0.017510728910565376, -0.017970234155654907, -0.0636538565158844, 0.0334806926548481, 0.028890429064631462, 0.048811208456754684, -0.05584472417831421, 0.04980502650141716, -0.09241326153278351, 0.013628821820020676, -0.03304214030504227, -0.042485155165195465, -0.0021673012524843216, 0.031550388783216476, -0.018834110349416733, 0.135141983628273, -0.11619042605161667, -0.0033226723317056894, -0.04852858930826187, -0.01678263209760189, 0.013846248388290405, 0.06312208622694016, 0.008539245463907719, 0.08060166984796524, -0.06953717023134232, -0.04028967767953873, -0.038611799478530884, -0.033905353397130966, -0.008169465698301792, -0.03384707495570183, -0.029204189777374268, -0.007800272665917873, -0.020200401544570923, -0.005261461716145277, 0.0007106076809577644, -0.01437010895460844, -0.02184939756989479, -0.02415315806865692, -0.058569278568029404, -0.006188570987433195, 0.05149675905704498, 0.065972700715065, -0.0005149906501173973, 0.01718025468289852, 0.0078024123795330524, -0.08474759012460709, 0.04895320162177086, 0.020897168666124344, -0.09940110892057419, 0.018630681559443474, 0.08469060063362122, -0.019841711968183517, -0.019438566640019417, -0.01789218746125698, 0.021167520433664322, -0.018066052347421646, 0.0001540735102025792, -0.07504352927207947, -0.06177974492311478, -0.05157287046313286, -0.020491475239396095, -0.03400345891714096, 0.07809337973594666, -0.028691010549664497, 0.007117000408470631, 0.00898082833737135, -0.0014387546107172966, 0.031045090407133102, 0.005837987642735243, 0.03715495765209198, 0.030578067526221275, 0.03843214362859726, -0.028491323813796043, -0.05149288475513458, -0.010122413747012615, 0.03485526144504547, -0.04380373656749725, 0.02757059410214424, 0.042812515050172806, -0.022766657173633575, 0.04045679420232773, 0.01765335351228714, -0.02362089604139328, -0.018127311021089554, -0.0037814790848642588, 0.0045898472890257835, 0.04440823942422867, 0.02821424975991249, -0.02832741104066372, -0.03829703852534294, 0.035549603402614594, 0.006929147522896528, 0.0225173719227314, 0.004391693975776434, 0.04931582510471344, -0.03485459089279175, 0.018058646470308304, 0.013903019018471241, 0.00932706706225872, -0.03547724336385727, 0.01837361417710781, -0.020812392234802246, -0.001942124217748642, -0.08705639094114304, -0.002153168898075819, -0.01911488175392151, 0.04328847676515579, -0.015244635753333569, -0.005749596282839775, 0.0313933901488781, 0.005025065504014492, -0.011089326813817024, 0.007911263965070248, 0.04244670644402504, 0.013275666162371635, 0.001181746949441731, 0.006439481861889362, 0.006507813464850187, -0.02660222165286541, -0.017434606328606606, 0.017571570351719856, 0.031148478388786316, -0.0035486926790326834, -0.023949092254042625, 0.001529993605799973, -0.0029740394093096256, -0.020860206335783005, 0.01097191870212555, -0.009357583709061146, 0.049358002841472626, -0.01178660523146391, 0.039786554872989655, -0.04676826298236847, -0.010092836804687977, -0.006206421181559563, 0.045540571212768555, -0.020883554592728615, -0.03810179606080055, -0.009869124740362167, -0.002072924980893731, -0.028459949418902397, -0.013526380993425846, 0.022876253351569176, 0.004054781049489975, -0.016798149794340134, 0.039573125541210175, -0.046551622450351715, 0.06732858717441559, -0.023860342800617218, 0.0007653160719200969, -0.05211840569972992, -0.0014342722715809941, -0.010847977362573147, -0.012494704686105251, -0.030953874811530113, 0.030463648959994316, 0.03592389449477196, 0.030696675181388855, 0.013598167337477207, -0.026670081540942192, 0.018575390800833702, 0.010268077254295349, 0.032298777252435684, -0.0368640199303627, 0.02804139256477356, -0.04404386505484581, -0.031578920781612396, -0.03261598199605942, 0.08136400580406189, 0.0327594093978405, 0.009506220929324627, -0.022401239722967148, 0.03661707043647766, -0.060950689017772675, 0.016302337870001793, 0.013416537083685398, 0.013545941561460495, -0.01231361087411642, 0.015111600048840046, -0.06641838699579239, -0.03880010545253754, 0.03099672682583332, 0.006539335008710623, -0.031440842896699905, 0.0031109654810279608, -0.0038855334278196096, 0.024378862231969833, -0.02510085515677929, -0.0011849722359329462, 0.02259516529738903, -0.006075057201087475, 0.04083332046866417, 0.011651135981082916, 0.01191710215061903, -0.0010134385665878654, -0.018251465633511543, -0.028989184647798538, -0.014364120550453663, -0.006955316290259361, 0.019839176908135414, -0.010068031027913094, -0.007884755730628967, 0.028580719605088234, 0.027443770319223404, -0.08318191766738892, 0.008928872644901276, -0.025392329320311546, 0.004032779484987259, -0.0290977843105793, -0.043756235390901566, -0.031214796006679535, 0.03597041592001915, 0.004003041423857212, 0.02143918164074421, -0.026738546788692474, -0.04628315195441246, -0.0015018874546512961, 0.040529124438762665, 0.03294195979833603, -0.002270919270813465, -0.03527937829494476, -0.022681880742311478, 0.0024814254138618708, -0.02373604103922844, 0.0046235970221459866, 0.020330458879470825, 0.009668022394180298, 0.03683551400899887, -0.005395710002630949, 0.06424246728420258, 0.035849250853061676, -0.000561447930522263, 0.0049489689990878105, -0.03181799128651619, 0.0014073365600779653, 0.026936262845993042, 0.013020014390349388, 0.05518616735935211, 0.02480875700712204, 0.007149550132453442, -0.023186778649687767, 0.03528459370136261, -0.01317964494228363, -0.06044699624180794, -0.010249823331832886, 0.03872670233249664, -0.022784456610679626, 0.023267067968845367, 0.012790141627192497, 0.001872153952717781, -0.002052685711532831, 0.009418954141438007, -0.008347311057150364, 0.03594514727592468, -0.031358860433101654, 0.0027017896063625813, 0.0033883745782077312, 0.016826676204800606, -0.029663102701306343, 0.036055613309144974, 0.03389773890376091, 0.02192811295390129, 0.03179336339235306, -0.01832965575158596, 0.0061737229116261005, -0.0024105890188366175, -0.009582486003637314, 0.020808061584830284, -0.006467961706221104, -0.006684608291834593, -0.09076163172721863, -0.023816928267478943, 0.007354448549449444, -0.016021426767110825, 0.030191145837306976, 0.036146242171525955, -0.03035888820886612, 0.007888510823249817, 0.06063259765505791, 0.0244352538138628, 0.008442199788987637, -0.02211202122271061, 0.017088374122977257, 0.003517771139740944, 0.01611056551337242, 0.041014663875103, -0.02678423374891281, -0.039282191544771194, 0.03640371188521385, 0.06929098814725876, 0.0629950538277626, 0.012819008901715279, 0.027799779549241066, -0.029499726369976997, -0.009707313030958176, -0.0038911225274205208, 0.004125824198126793, -0.022962147369980812, -0.06476900726556778, -0.030762791633605957, -0.010449867695569992, -0.035036999732255936, 0.0034471568651497364, 0.03130064904689789, 0.007701594848185778, 0.008596077561378479, -0.0219682939350605, 0.010243961587548256, -0.00895470567047596, 0.0025508515536785126, -0.04116469621658325, 0.0039059233386069536, -0.05432815104722977, 0.01980419084429741, 0.023897813633084297, -0.008920826017856598, 0.005069579929113388, 0.04208666831254959, -0.013684521429240704, 0.011390195228159428, 0.018037835136055946, -0.015075433067977428, 0.03898732736706734, -0.013338019140064716, 0.005063020158559084, -0.011417126283049583, -0.006844153627753258, 0.01839049905538559, -0.005484049674123526, 0.016606606543064117, 0.03173067793250084, 0.012946218252182007, 0.014846770092844963, 0.02882416546344757, -0.02536904811859131, -0.015238373540341854, 0.054127179086208344, -0.007913682609796524, -0.042564231902360916, 0.006975175812840462, 0.021808331832289696, 0.046590451151132584, -0.017419233918190002, 0.048707474023103714, -0.0039032804779708385, -0.04995075985789299, 0.0326758474111557, -0.010203002952039242, 0.023183804005384445, 0.04675929620862007, 0.008184232749044895, 0.02225237712264061, 0.026630157604813576, 0.03091144748032093, 0.005054930690675974, -0.007776690647006035, -0.0124290082603693, 0.0401148647069931, 0.011502387002110481, 0.041589315980672836, 0.01918407715857029, -0.014335733838379383, -0.01782207563519478, 0.024628369137644768, -0.056220151484012604, -0.021259434521198273, 0.006211242638528347, -0.02915160357952118, 0.04583846032619476, -0.027990400791168213, -0.062209367752075195, -0.0363997220993042, 0.002822905546054244, -0.0007399983005598187, 0.03285222128033638, -0.03605133667588234, 0.04889252409338951, 0.006177797913551331, -0.017475523054599762, 0.00910078827291727, 0.06577471643686295, -0.014789044857025146, 0.05165136232972145, 0.01822005584836006, 0.008459393866360188, 0.03485310450196266, 0.0478149950504303, 0.042289722710847855, 0.028415212407708168, 0.046182580292224884, -0.009599877521395683, 0.01526598073542118, 0.04085046425461769, 0.03520328179001808, -0.017818057909607887, -0.07323053479194641, 0.015421244315803051, -0.025063231587409973, -0.0038006349932402372, 0.026231149211525917, 0.02705116756260395, 0.024445800110697746, -0.014893813990056515, 0.06376316398382187, 0.028309624642133713, 0.03737153112888336, -0.02870662324130535, 0.02931266836822033, 0.009498435072600842, -0.002752672415226698, 0.021210510283708572, 0.03166012093424797, 0.017903095111250877, 0.025046123191714287, 0.07345625013113022, 0.03042703866958618, 0.04603977128863335, -0.020972317084670067, 0.01968158781528473, 0.03119875118136406, -0.007618660572916269, -0.03251326084136963, -0.0004452000721357763, 0.025150910019874573, -0.04088754579424858, -0.01901031658053398, 0.010363073088228703, -0.039081744849681854, 0.015989596024155617, 0.012333542108535767, -0.033682338893413544, -0.028320057317614555, 0.00010123049287358299, 0.004366755485534668, 0.014807933941483498, -0.017719684168696404, -0.03608574718236923, -0.010624784976243973, 0.035554997622966766, 0.014271540567278862, 0.005285666324198246, -0.00988980196416378, 0.01793144829571247, -0.014587773010134697, -0.003209145972505212, -0.035954561084508896, -0.014044340699911118, 0.000004787405941897305, 0.008159535005688667, 0.011292068287730217, 0.021496830508112907, 0.02135566808283329, 0.030645456165075302, 0.0098853949457407, 0.03142284229397774, -0.07034449279308319, -0.013084697537124157, 0.01039979886263609, -0.0017167109763249755, -0.011805579997599125, -0.015603375621140003, 0.04607642814517021, 0.020866811275482178, 0.028593581169843674, 0.05167507752776146, 0.04430669546127319, -0.02010580338537693, -0.03678803890943527, -0.03484608605504036, -0.02992977760732174, -0.0012792980996891856, 0.01282971166074276, 0.0404927097260952, 0.004154787864536047, 0.003951448015868664, -0.030697783455252647, -0.005554764065891504, 0.010037258267402649, 0.010933345183730125, 0.057977065443992615, -0.009128007106482983, -0.024742979556322098, -0.05026624724268913, 0.05229954421520233, 0.048055097460746765, -0.019135966897010803, 0.03734556958079338, -0.008455147966742516, 0.011705968528985977, -0.005835332907736301, -0.014192301779985428, -0.051746055483818054, -0.03830845281481743, -0.04458018019795418, -0.08510507643222809, 0.010945490561425686, 0.014035988599061966, -0.009221349842846394, 0.014580168761312962, -0.03159325197339058, 0.011631973087787628, 0.007534518837928772, -0.03986550122499466, 0.007259751670062542, -0.009450233541429043, 0.030576804652810097, 0.009386015124619007, -0.0019539855420589447, -0.02305932156741619, -0.046182647347450256, 0.012223546393215656, -0.019310491159558296, 0.021085374057292938, 0.061755456030368805, 0.015553959645330906, -0.004420342389494181, -0.010906330309808254, 0.018922416493296623, 0.025848885998129845, -0.012113676406443119, 0.02978917583823204, -0.03522283956408501, -0.0364622101187706, 0.005650530103594065, 0.009822354651987553, 0.04554734006524086, 0.007066555321216583, 0.035116326063871384, 0.03455214947462082, 0.004148133099079132, 0.02719969116151333, 0.004849530290812254, -0.04550107568502426, -0.0193552877753973, -0.01002101507037878, 0.015330523252487183, 0.030905161052942276, 0.008746911771595478, 0.026707135140895844, 0.026628708466887474, -0.03457576408982277, 0.013483746908605099, 0.004283256363123655, 0.013321059755980968, 0.003963898867368698, -0.01064489595592022, 0.008787012659013271, -0.01946968026459217, -0.015030342154204845, 0.09054526686668396, 0.03924599289894104, -0.02770133689045906, 0.005130195524543524, -0.01117886882275343, -0.020525960251688957, -0.01784752681851387, -0.008608282543718815, -0.02159261144697666, 0.01702125184237957, -0.001717363833449781, 0.010575447231531143, 0.0017245933413505554, -0.0069598788395524025 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Test Coverage This next step was very important - I needed to prepare an extensive testing for the ported model. In thetransformerstest suite most tests that deal with large models are marked as@slowand those don't get to run normally on CI (Continual Integration), as they are, well, slow. So I needed to also create a tiny model, that has the same structure as a normal pre-trained model, but it had to be very small and it could have random weights. This tiny model is then can be used to test the ported functionality. It just can't be used for quality testing, since it has just a few weights and thus can't really be trained to do anything practical. [fsmt-make-tiny-model.py](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/scripts/fsmt-make-tiny-model.py) creates such a tiny model. The generated model with all of its dictionary and config files was just 3MB in size. I uploaded it tos3usingtransformers-cli uploadand now I was able to use it in the test suite. Just like with the code, I started by copyingtests/test_modeling_bart.pyand converting it to useFSMT, and then tweaking it to work with the new model. I then converted a few of my scripts I used for manual testing into unit tests - that was easy.transformershas a huge set of common tests that each model runs through - I had to do some more tweaks to make these tests work forFSMT(primarily to adjust for the 2 dictionary setup) and I had to override a few tests, that weren't possible to run due to the uniqueness of this model, in order to skip them. You can see the results [here](https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/tests/test_tokenization_fsmt.py). I added one more test that performs a light BLEU evaluation - I used just 8 text inputs for each of the 4 models and measured BLEU scores on those. Here is the [test](https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/examples/seq2seq/test_fsmt_bleu_score.py) and the [script that generated data](https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/examples/seq2seq/test_data/fsmt/build-eval-data.py).
[ 0.014858288690447807, -0.05113699659705162, 0.010809321887791157, 0.01563982293009758, 0.06520397961139679, 0.05719708278775215, 0.07866664230823517, 0.02529977820813656, -0.017329469323158264, -0.03726392239332199, -0.04974287003278732, 0.08486159145832062, 0.02061905339360237, 0.0272753294557333, 0.06072179600596428, -0.02136741206049919, 0.0649736151099205, -0.03712254390120506, 0.030598491430282593, 0.05377946421504021, -0.004131600260734558, -0.06722075492143631, 0.02086646854877472, 0.01919122040271759, -0.030076811090111732, -0.0628952905535698, 0.08628761768341064, 0.0592600479722023, -0.0173503290861845, -0.007944774813950062, -0.09736385196447372, -0.034206125885248184, -0.04865004122257233, -0.06799758225679398, -0.040592826902866364, 0.031185990199446678, -0.0890895277261734, 0.05025244131684303, -0.00016921767382882535, -0.04053421691060066, 0.0648353323340416, 0.013240691274404526, -0.05959222838282585, 0.026311378926038742, -0.010443718172609806, 0.040316011756658554, -0.12019620090723038, 0.0932120755314827, 0.00737322261556983, -0.058364782482385635, -0.0018941907910630107, 0.04025358334183693, -0.0318850539624691, -0.0092519735917449, 0.0685543641448021, 0.04746299237012863, -0.004153707530349493, -0.02296251803636551, -0.0005332708824425936, 0.0019877657759934664, -0.01750868186354637, -0.0003632256994023919, 0.032668329775333405, 0.08277742564678192, 0.001680730376392603, 0.0030024501029402018, 0.007879059761762619, 0.004377683158963919, -0.0395011268556118, -0.03612971678376198, -0.011764892376959324, -0.041091036051511765, -0.007347885984927416, -0.03100513108074665, -0.02236047014594078, -0.006555207073688507, -0.017326408997178078, 0.032157205045223236, 0.07358959317207336, 0.10782782733440399, -0.003608688013628125, 0.005100776441395283, 0.056955739855766296, 0.04236556217074394, 0.01191800832748413, -0.020867114886641502, 0.06843031197786331, -0.005381395108997822, -0.05742865800857544, 0.09584708511829376, -0.015375516377389431, -0.08422411233186722, -0.061046916991472244, 0.05924760177731514, 0.04476277157664299, 0.01196890790015459, -0.025055931881070137, 0.02201833389699459, 0.01810898818075657, -0.018561966717243195, 0.007162837777286768, -0.036314498633146286, -0.021001512184739113, -0.04017886891961098, -0.07934809476137161, 0.02297080308198929, 0.008666841313242912, -0.06781291961669922, -0.03531070798635483, 0.02972087636590004, 0.03889238461852074, -0.07881882041692734, -0.051969144493341446, 0.10565318912267685, -0.08904074132442474, 0.021968936547636986, -0.030999263748526573, -0.024469764903187752, 0.01972135715186596, 0.04439800977706909, 0.02778039313852787, 0.11396907269954681, 0.02153988555073738, -0.018049711361527443, 0.05878663808107376, 0.037090349942445755, 0.0388653464615345, 0.012762789614498615, -0.011310991831123829, -0.02367061749100685, -0.030227379873394966, -0.01986248791217804, 0.05881606414914131, 0.07572174817323685, -0.006174623034894466, -0.011317843571305275, 0.062210533767938614, -0.01672525517642498, 0.016745736822485924, 0.003015343099832535, 0.0145045081153512, 0.049489427357912064, -0.014335168525576591, 0.006259954534471035, 0.007731342222541571, -0.009148097597062588, -0.08634182810783386, 0.09006741642951965, -0.02129235677421093, 0.027043519541621208, -0.10227258503437042, 0.019304389134049416, -0.04230901598930359, 0.0009326036088168621, -0.0034645383711904287, 0.06228741630911827, -0.023164482787251472, -0.06713699549436569, -0.11019965261220932, -0.015408354811370373, -0.004637850448489189, 0.0038138378877192736, -0.026359781622886658, -0.06504786014556885, 0.0660216435790062, -0.022720756009221077, -0.033433832228183746, 0.0010538232745602727, 0.05133385583758354, 0.02178000658750534, 0.03479555994272232, -0.028438204899430275, 0.05251198634505272, -0.0005799948703497648, 0.0120382746681571, 0.042157359421253204, 0.05457111448049545, 0.039010848850011826, -0.0187271349132061, -0.00024195300647988915, -0.0627489760518074, 0.09579434245824814, -0.002328419592231512, 0.03253750503063202, -0.008607768453657627, -0.07989354431629181, 0.044170841574668884, 0.036302600055933, -0.05201621726155281, 0.008458016440272331, -0.015119015239179134, -0.009287003427743912, 0.08653032779693604, -0.029348522424697876, 0.03483954817056656, -0.0018825809238478541, 0.04721863567829132, 0.11173947155475616, 0.038163598626852036, 0.05441635847091675, -0.01690053381025791, 0.055762361735105515, 0.02538657747209072, -0.017959464341402054, 0.030150771141052246, 0.0851738229393959, 0.005673784296959639, -0.07640425115823746, -0.019650278612971306, -0.010091130621731281, 0.043522611260414124, -0.07989858090877533, 0.06500159949064255, -0.0578237883746624, -0.025672757998108864, -0.08125246316194534, -0.03161148354411125, -0.028652161359786987, -0.012653724290430546, -0.026066118851304054, 0.11175626516342163, -0.0045667546801269054, -0.045232437551021576, -0.0803571566939354, -0.038728296756744385, 0.002581535605713725, 0.05074988678097725, 0.03728513419628143, 0.06427115201950073, -0.08859481662511826, 0.008249369449913502, -0.06718453764915466, 0.006555892992764711, 0.0074562677182257175, -0.03423725813627243, -0.11382011324167252, 0.010899756103754044, -0.027021540328860283, 0.0020479196682572365, -0.010958672501146793, 0.011226012371480465, 0.013090641237795353, 0.04538198933005333, 0.05922534316778183, -0.04421425610780716, 0.019309058785438538, 0.044544246047735214, 0.0020276405848562717, -0.009710000827908516, -0.04520627483725548, -0.054580505937337875, 0.041779909282922745, -0.03903980180621147, -0.07617343217134476, 0.044103268533945084, -0.009073168970644474, 0.010670422576367855, 0.031802982091903687, -0.05454214662313461, 0.004473952576518059, 0.007458538748323917, 0.0013648325111716986, -0.03552157059311867, -0.014460070058703423, 0.00896512158215046, -0.03155435994267464, -0.01708841510117054, 0.020537961274385452, -0.013667210005223751, 0.01734871231019497, 0.005843936000019312, -0.014913404360413551, 0.01192152313888073, 0.001938626286573708, 0.03381674364209175, 0.022704608738422394, 0.020465536043047905, -0.004067032132297754, -0.055871590971946716, -0.012996778823435307, -0.04593988507986069, -0.004886640701442957, 0.031031012535095215, 0.021862952038645744, 0.024521315470337868, 0.019862975925207138, -0.028177432715892792, -0.02246573381125927, -0.030069703236222267, 0.011714156717061996, 0.013708704151213169, 0.029986515641212463, 0.029724104329943657, -0.024171756580471992, 0.01106252521276474, -0.016175417229533195, -0.02398759312927723, -0.04446980729699135, 0.013285433873534203, 0.0496721975505352, -0.003580257063731551, 0.011687434278428555, 0.00038509885780513287, 0.017951494082808495, -0.026213185861706734, 0.010970251634716988, 0.01420807559043169, 0.02944655530154705, -0.0970868468284607, 0.013735363259911537, -0.005614429246634245, 0.04186101257801056, -0.013559005223214626, -0.06184797361493111, 0.03632839396595955, -0.014647331088781357, 0.009772222489118576, 0.025778023526072502, 0.027905697003006935, 0.007228981703519821, 0.024908624589443207, 0.007659647613763809, -0.026932723820209503, -0.0024597779847681522, -0.01003149151802063, -0.014072421006858349, 0.058350831270217896, 0.019442996010184288, -0.01119361910969019, 0.0185190849006176, 0.04121817648410797, 0.02448638342320919, -0.010732325725257397, -0.013744788244366646, 0.0181952603161335, 0.05064483359456062, 0.055417221039533615, -0.012255273759365082, -0.006598735228180885, -0.01851164549589157, -0.006113509647548199, 0.008995095267891884, -0.037797827273607254, -0.023734677582979202, -0.013676135800778866, 0.02799198031425476, -0.023943781852722168, 0.003449254436418414, 0.016225887462496758, 0.0045393770560622215, 0.04077421501278877, 0.015818145126104355, 0.021473681554198265, -0.041997261345386505, 0.0011985099408775568, 0.0038558675441890955, 0.03727807477116585, -0.012513759545981884, -0.02849002368748188, -0.003920488990843296, -0.018914151936769485, 0.07474735379219055, -0.020943613722920418, 0.0455961599946022, 0.049286603927612305, 0.017349088564515114, -0.00691201351583004, 0.003006093669682741, -0.04935755208134651, -0.0037068563979119062, -0.03012443333864212, -0.021978653967380524, -0.03347355127334595, 0.07321909070014954, 0.01842973381280899, 0.0036216017324477434, -0.013876794837415218, 0.01993476413190365, -0.018751146271824837, 0.019458632916212082, 0.0028930215630680323, 0.006161974277347326, -0.012712720781564713, 0.015895767137408257, -0.03572847321629524, -0.04825795069336891, 0.03217719867825508, 0.0061288815923035145, 0.025432433933019638, 0.007095027714967728, -0.021172720938920975, 0.014404978603124619, -0.00009834734373725951, 0.013315306976437569, -0.0050228009931743145, -0.015494480729103088, 0.016569456085562706, 0.05181752145290375, 0.0380912609398365, -0.047347716987133026, -0.013274089433252811, -0.026234129443764687, -0.012526538223028183, -0.032424330711364746, 0.012746881693601608, -0.029052220284938812, -0.0032462419476360083, 0.021341852843761444, 0.027090657502412796, -0.016334738582372665, 0.020444706082344055, -0.019160069525241852, -0.00018711462325882167, -0.008657005615532398, -0.07190839946269989, -0.021545961499214172, 0.03776124492287636, -0.003996737767010927, -0.011932537890970707, -0.0172246266156435, -0.033635105937719345, 0.008540469221770763, 0.04893369600176811, 0.05920635536313057, -0.0005494471406564116, 0.008036692626774311, -0.011367722414433956, 0.037579454481601715, -0.026821894571185112, -0.000458497874205932, -0.014188052155077457, -0.016818858683109283, 0.0315740704536438, -0.008889956399798393, 0.030702607706189156, 0.029764723032712936, -0.014829677529633045, -0.0013096689945086837, -0.0052843596786260605, -0.00468192994594574, 0.03639831393957138, 0.0016133220633491874, 0.020718466490507126, 0.006272892002016306, 0.0032745422795414925, -0.008454387076199055, 0.010402156971395016, -0.024021105840802193, -0.02985512837767601, -0.002895883983001113, 0.0027768441941589117, -0.02962515689432621, 0.018075350672006607, 0.012472783215343952, 0.0011498240055516362, 0.003581617958843708, -0.057410042732954025, -0.005571639630943537, 0.04145220294594765, -0.013160943053662777, -0.04832028970122337, -0.0018532926915213466, 0.007431621663272381, -0.003180672414600849, 0.019477497786283493, 0.0028071263805031776, 0.02790801040828228, 0.018423674628138542, -0.033180832862854004, 0.00645871739834547, -0.00858461856842041, 0.03245152160525322, 0.03321667015552521, 0.009572722017765045, -0.019779348745942116, -0.10537943243980408, -0.04806802049279213, -0.0014922816772013903, -0.04890155792236328, -0.0055580358020961285, -0.013169138692319393, -0.01399901881814003, 0.007454504258930683, 0.10116224735975266, 0.02324516326189041, -0.015584427863359451, 0.01318051852285862, 0.013902333565056324, 0.018965836614370346, -0.005581621080636978, -0.0011926578590646386, -0.006008850410580635, -0.005195517558604479, 0.059879809617996216, 0.05471431091427803, 0.05563260242342949, -0.03376000002026558, 0.031616851687431335, -0.025476068258285522, -0.01671498455107212, 0.002246468560770154, -0.03334379941225052, -0.006640343461185694, -0.0006403447478078306, -0.012485158629715443, -0.012496628798544407, 0.0034758879337459803, -0.02935086190700531, 0.014134581200778484, 0.042235467582941055, -0.014955946244299412, -0.022384069859981537, 0.06611085683107376, 0.007649368606507778, -0.012651542201638222, 0.0010595968924462795, 0.045754943042993546, -0.0370454415678978, -0.008646919392049313, -0.008104544132947922, 0.005764304660260677, 0.00933405477553606, 0.01057056151330471, -0.09028467535972595, -0.006514362525194883, 0.030825844034552574, 0.03163612261414528, -0.011196027509868145, -0.015118435956537724, 0.009893357753753662, 0.00033764183172024786, -0.01517059188336134, 0.0277501679956913, -0.028054574504494667, -0.01931423507630825, -0.014907820150256157, -0.021467329934239388, 0.025560954585671425, 0.010506297461688519, 0.02057877741754055, -0.0012281239032745361, 0.0062302276492118835, 0.03993700444698334, 0.013777588494122028, -0.019881701096892357, 0.01597336120903492, 0.0043797059915959835, -0.039484184235334396, 0.0035117880906909704, -0.031045569106936455, -0.032752055674791336, 0.027583425864577293, -0.025332732126116753, 0.03649536520242691, 0.08081120997667313, 0.007598338648676872, 0.026542112231254578, 0.010079409927129745, -0.0039186300709843636, 0.04527996852993965, -0.010345005430281162, -0.010762643069028854, -0.01795550435781479, -0.005194144789129496, 0.0119836600497365, 0.05926983803510666, 0.006658291444182396, 0.0033053760416805744, 0.01826556958258152, -0.04869593307375908, -0.003063115756958723, -0.0008183828904293478, -0.045762497931718826, -0.008692210540175438, 0.007747713942080736, -0.07353916019201279, 0.004089812748134136, 0.0074213421903550625, 0.012000391259789467, 0.041628848761320114, 0.02201075665652752, -0.016043487936258316, -0.04269041493535042, -0.011542582884430885, 0.03292709216475487, 0.025125762447714806, 0.04460613802075386, 0.030908817425370216, 0.012523331679403782, 0.026880357414484024, 0.03560657799243927, -0.0012278611538931727, 0.028123874217271805, 0.0233803428709507, 0.09190855920314789, 0.01882709190249443, -0.00007887045649113134, 0.019817031919956207, -0.022292360663414, -0.004020065534859896, -0.043712541460990906, -0.00993000715970993, -0.020059142261743546, 0.010346113704144955, -0.00891219824552536, 0.008244604803621769, -0.00007845439540687948, 0.009458882734179497, 0.06815485656261444, 0.03446242958307266, 0.0228462852537632, -0.017996493726968765, 0.03429451957345009, 0.018900752067565918, 0.010570444166660309, -0.02910628914833069, 0.03862627595663071, 0.01887073554098606, -0.01570635847747326, 0.04976324737071991, -0.02077573724091053, 0.0344746969640255, -0.012951293960213661, 0.03002847544848919, -0.014642033725976944, -0.031176937744021416, -0.004832413513213396, 0.006109193898737431, -0.015413871966302395, 0.0107325604185462, -0.010066380724310875, 0.032634418457746506, -0.040394142270088196, 0.016765540465712547, -0.046817466616630554, -0.04839097708463669, -0.041895944625139236, -0.0313640832901001, -0.02536442130804062, 0.012824120000004768, 0.0012954408302903175, -0.0525590144097805, 0.015476243570446968, 0.011726560071110725, 0.03434079512953758, -0.006947465240955353, 0.015551417134702206, 0.03517904132604599, 0.005245737265795469, -0.008665554225444794, 0.008818299509584904, 0.008501678705215454, -0.044732656329870224, -0.02216026559472084, 0.006325573194772005, 0.03724073991179466, -0.0036094964016228914, 0.07914326339960098, 0.023685812950134277, 0.026424221694469452, -0.038170117884874344, 0.008679978549480438, -0.01771487481892109, -0.04096352681517601, 0.002607391681522131, -0.06020265817642212, -0.0895024910569191, 0.0119151147082448, 0.04253357648849487, 0.02743649296462536, 0.03760156407952309, 0.0052618528716266155, -0.03774247691035271, -0.026260940358042717, -0.04066789895296097, -0.015868645161390305, 0.026613697409629822, -0.024216266348958015, 0.02512623555958271, 0.028902234509587288, -0.005430438090115786, -0.003490377450361848, 0.01447661779820919, -0.01147618517279625, 0.018650883808732033, -0.013164296746253967, -0.0523955300450325, 0.006758659612387419, 0.023940855637192726, 0.04189571738243103, 0.00830022618174553, 0.032521430402994156, 0.029276462271809578, 0.010103205218911171, -0.023069730028510094, 0.001156829297542572, -0.022516541182994843, 0.009994417428970337, -0.0490030013024807, -0.04541191831231117, -0.010954296216368675, -0.016814585775136948, -0.03503544256091118, -0.0012480515288189054, -0.027989286929368973, -0.011886075139045715, -0.018481414765119553, 0.013472574763000011, 0.004789732396602631, 0.003487425623461604, 0.04455041140317917, 0.045976441353559494, -0.027092333883047104, -0.016707852482795715, -0.06808669120073318, -0.004330037161707878, -0.019005456939339638, 0.03758678957819939, 0.05642693117260933, 0.02876940928399563, 0.006768358871340752, -0.011616501025855541, -0.00790619757026434, 0.011309209279716015, -0.05022461339831352, 0.005271504167467356, 0.03385021165013313, -0.04859580099582672, -0.021635517477989197, -0.009077910333871841, 0.03911181166768074, -0.016225477680563927, 0.03846834599971771, -0.017624270170927048, -0.035509273409843445, 0.004010370001196861, 0.009188839234411716, -0.06103181466460228, -0.0314020961523056, -0.005079967435449362, 0.01192600280046463, -0.00035293801920488477, 0.0048626563511788845, -0.004359867889434099, 0.01741604134440422, -0.0059481216594576836, 0.04577159881591797, 0.02403850480914116, -0.033497754484415054, -0.04978060722351074, 0.01016322523355484, 0.026177093386650085, -0.026542464271187782, -0.0653797909617424, 0.020806871354579926, -0.018666593357920647, -0.043100304901599884, -0.03582395985722542, 0.0016167530557140708, 0.009171521291136742, -0.05066610872745514, 0.001823779079131782, -0.04900699853897095, -0.011683668941259384, 0.02959718368947506, -0.03010907955467701, -0.021416453644633293, 0.001971888355910778 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Documentation Finally, the documentation needed to be added. Luckily, most of the documentation is autogenerated from the docstrings in the module files. As before, I copieddocs/source/model_doc/bart.rstand adapted it toFSMT. When it was ready I linked to it by addingfsmtentry insidedocs/source/index.rstI used: ``` make docs ``` to test that the newly added document was building correctly. The file I needed to check after running that target wasdocs/_build/html/model_doc/fsmt.html- I just loaded in my browser and verified that it rendered correctly. Here is the final source document [docs/source/model_doc/fsmt.rst](https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/docs/source/model_doc/fsmt.rst) and its [rendered version](https://huggingface.co/transformers/model_doc/fsmt.html).
[ 0.050767406821250916, -0.017333900555968285, 0.03644019737839699, 0.048183877021074295, 0.05848197266459465, 0.006500420160591602, 0.00004709677159553394, -0.03512893244624138, 0.012766196392476559, 0.004455000627785921, -0.07925018668174744, 0.04208218306303024, 0.06326691806316376, 0.04899076744914055, 0.024950603023171425, 0.03808523714542389, 0.019842471927404404, -0.05868464708328247, -0.08080139756202698, -0.052571818232536316, 0.02262297458946705, -0.01435808651149273, -0.008677415549755096, 0.02377861738204956, 0.08063541352748871, -0.08801612257957458, 0.03339509293437004, 0.06139639765024185, -0.0020947447046637535, 0.06338726729154587, -0.06562047451734543, -0.04763657972216606, -0.03232701122760773, -0.08657760173082352, -0.03367291018366814, 0.05507330968976021, -0.10888388752937317, 0.05720137804746628, -0.02952643111348152, -0.02080114372074604, -0.02131783217191696, -0.021361932158470154, -0.03770118206739426, 0.05849863216280937, 0.05382966250181198, -0.0074930936098098755, -0.1762133091688156, 0.009974416345357895, 0.03422235697507858, 0.025650091469287872, -0.028772806748747826, 0.013907401822507381, -0.03592417761683464, -0.006668004672974348, -0.024267811328172684, 0.010250117629766464, -0.07635189592838287, 0.016265014186501503, 0.016168847680091858, -0.002912313211709261, 0.01006992720067501, -0.019181126728653908, 0.015573590062558651, 0.07719384133815765, 0.027733301743865013, 0.030489126220345497, -0.040696702897548676, 0.006564713083207607, -0.02851063199341297, 0.019191617146134377, 0.0245414637029171, 0.02248595468699932, 0.037472352385520935, 0.014898939989507198, 0.03834240883588791, -0.008844044990837574, 0.013441916555166245, 0.016354788094758987, 0.0485302172601223, 0.0395086444914341, 0.01782085746526718, 0.04329998418688774, 0.021341636776924133, 0.09864083677530289, -0.01853366568684578, -0.015015949495136738, 0.058408286422491074, -0.04426729679107666, -0.037714485079050064, 0.01506865955889225, 0.022936223074793816, -0.10670886933803558, -0.053094811737537384, 0.014609569683670998, 0.06688010692596436, -0.03851163387298584, -0.007928312756121159, 0.042685072869062424, 0.009946764446794987, 0.006128854118287563, -0.03495405986905098, 0.005458846688270569, 0.01014740765094757, -0.03811085224151611, -0.048624031245708466, 0.030085554346442223, -0.06459430605173111, -0.023966394364833832, -0.023917624726891518, 0.01240590400993824, -0.013726061210036278, -0.06303594261407852, 0.017171423882246017, 0.0015484440373256803, -0.05312541127204895, 0.08814029395580292, 0.0057379743084311485, -0.07974773645401001, -0.045059934258461, -0.0231021661311388, -0.05919349193572998, 0.09742088615894318, 0.011770498938858509, 0.00671046320348978, 0.02507888153195381, 0.11030460149049759, 0.01066002156585455, 0.05601431056857109, -0.031216362491250038, -0.0159880630671978, 0.0168036799877882, 0.03725676238536835, 0.08278611302375793, 0.007972710765898228, -0.018216168507933617, -0.0551416240632534, 0.017441878095269203, -0.07015933841466904, 0.021953614428639412, 0.04371245950460434, 0.0156776811927557, 0.0465426929295063, -0.07504718005657196, 0.0362849235534668, -0.009065462276339531, -0.02470416948199272, -0.09418923407793045, 0.0034257604274898767, -0.07091645151376724, 0.021478209644556046, -0.04376053810119629, -0.017311183735728264, 0.029944755136966705, -0.012841103598475456, 0.009975161403417587, 0.037982046604156494, 0.021603841334581375, 0.013934795744717121, -0.05404624342918396, -0.019340889528393745, -0.018117988482117653, 0.058280497789382935, -0.03279637172818184, -0.01404358446598053, 0.014217748306691647, -0.06039678677916527, -0.013387159444391727, 0.03343641757965088, 0.08918379247188568, -0.012434937059879303, 0.04161578044295311, -0.09048651903867722, 0.055791500955820084, -0.00824473612010479, 0.018096057698130608, 0.04969801753759384, 0.02219870686531067, -0.03606273606419563, -0.011452999897301197, -0.003201743122190237, -0.03770510107278824, 0.06374339014291763, 0.0047328416258096695, 0.004640783648937941, 0.05714397877454758, -0.022479016333818436, 0.03863486647605896, -0.05032088980078697, -0.01990598440170288, -0.03589524328708649, -0.07014614343643188, -0.02227950654923916, 0.06052011251449585, 0.0033943147864192724, 0.021903444081544876, 0.01179448515176773, -0.013707316480576992, 0.11836809664964676, -0.005564993713051081, 0.06874758750200272, 0.029727112501859665, -0.022471783682703972, -0.005040478426963091, 0.01331425178796053, 0.01621955633163452, 0.034533675760030746, 0.02683451771736145, -0.07238420844078064, 0.0266239196062088, 0.0170812476426363, 0.06611098349094391, -0.00790454726666212, 0.06083844602108002, -0.07178854197263718, 0.02357455901801586, -0.12211010605096817, 0.0162882711738348, -0.008502733893692493, -0.01705026626586914, -0.00304345041513443, 0.1719987988471985, 0.01690005511045456, 0.02214878238737583, -0.06276686489582062, -0.05670665577054024, 0.03315839171409607, 0.06847763061523438, 0.10259165614843369, 0.050062455236911774, -0.05485209450125694, -0.051370006054639816, -0.04938950389623642, 0.010490817949175835, 0.05341433361172676, -0.01954643987119198, -0.004717427771538496, 0.015887927263975143, 0.013731068931519985, -0.01583336479961872, -0.05389436334371567, 0.042477067559957504, -0.029866352677345276, 0.06738253682851791, -0.0052220169454813, 0.04566862806677818, -0.03390537574887276, 0.049953922629356384, 0.05742941424250603, -0.07945607602596283, -0.02813137322664261, -0.05844024196267128, 0.026502663269639015, 0.006330409552901983, -0.01823611557483673, 0.0594191774725914, 0.06311416625976562, 0.0022190487943589687, -0.03263198956847191, -0.0120754549279809, 0.07812417298555374, -0.002845635637640953, 0.013546554371714592, -0.057678673416376114, -0.033650193363428116, -0.010312209837138653, -0.0026170930359512568, -0.013072122819721699, -0.0253515113145113, 0.021203089505434036, 0.03657335042953491, 0.02432410791516304, -0.026067400351166725, -0.043155260384082794, -0.007126855663955212, -0.0007381753530353308, 0.035713255405426025, -0.008569170720875263, -0.017761994153261185, -0.026803435757756233, -0.0046121226623654366, -0.0007866423111408949, -0.007204425986856222, 0.03577519953250885, 0.02797851711511612, 0.03152891993522644, 0.006233118940144777, -0.0106338607147336, -0.003304098965600133, -0.058279599994421005, -0.04438294842839241, 0.029042821377515793, 0.006077696103602648, 0.015836302191019058, -0.023238589987158775, 0.0028454598505049944, 0.05204533413052559, 0.03385290876030922, 0.023296000435948372, -0.016814008355140686, 0.035007454454898834, -0.03633899614214897, 0.028531156480312347, -0.006221635267138481, -0.025978242978453636, -0.05000893771648407, 0.021657412871718407, 0.034933093935251236, -0.005925110075622797, -0.09798292815685272, -0.041406914591789246, 0.014838327653706074, 0.054833848029375076, -0.0028561914805322886, -0.021480582654476166, 0.04358759894967079, -0.03874828666448593, 0.01399852242320776, -0.051340680569410324, -0.018183279782533646, 0.015536945313215256, 0.02841147966682911, 0.01658969558775425, -0.014418396167457104, -0.009206398390233517, -0.03549133613705635, 0.028250569477677345, -0.004014676436781883, -0.0030460518319159746, -0.014809989370405674, -0.018589572980999947, 0.0032675417605787516, -0.019359329715371132, -0.026900559663772583, 0.010592435486614704, 0.004143170081079006, 0.02635146677494049, 0.011035999283194542, -0.07251758873462677, -0.006941772066056728, -0.005584566853940487, 0.017824383452534676, -0.00773213105276227, -0.0463857538998127, -0.02390228770673275, -0.010400592349469662, 0.029927069321274757, -0.023425783962011337, 0.03499492630362511, 0.01393836922943592, 0.00020909536397084594, -0.014269223436713219, 0.030040575191378593, -0.005644563585519791, -0.00486366543918848, -0.0390629917383194, 0.043569471687078476, 0.023202380165457726, 0.008221837691962719, -0.019533270969986916, -0.017962154000997543, 0.03800516948103905, 0.054268840700387955, -0.04112110286951065, 0.020111875608563423, -0.0030265599489212036, -0.008564364165067673, 0.011005581356585026, 0.02559509128332138, -0.07885538786649704, -0.02414344996213913, -0.053821366280317307, -0.02204509824514389, -0.007569607347249985, 0.09355480968952179, 0.0032086356077343225, 0.0342341884970665, -0.035818763077259064, 0.048433467745780945, -0.01720196194946766, 0.001733295968733728, 0.013091132044792175, 0.011450674384832382, -0.02628796547651291, -0.02738037146627903, -0.06929313391447067, -0.0775826945900917, 0.061194323003292084, -0.018256481736898422, 0.019008567556738853, -0.0329289436340332, -0.02882283180952072, 0.010106348432600498, -0.028527384623885155, 0.004499354399740696, 0.04838058724999428, -0.014931917190551758, 0.020126326009631157, 0.02719367854297161, 0.004727546125650406, 0.0054640197195112705, -0.01633860170841217, -0.005340104456990957, -0.0314052477478981, -0.02208450809121132, -0.015923885628581047, -0.02942783012986183, 0.02795315720140934, 0.051296696066856384, -0.007871830835938454, -0.02035202644765377, 0.00495512830093503, 0.012128351256251335, 0.01900635100901127, 0.034839194267988205, -0.0412355437874794, -0.04772413149476051, 0.03669155761599541, 0.02324720285832882, -0.01482840534299612, -0.031771380454301834, 0.00969784241169691, -0.01954893209040165, -0.0032801292836666107, 0.03514730557799339, 0.0043657091446220875, -0.03267738223075867, -0.058223824948072433, 0.027300020679831505, 0.004998175427317619, 0.02886713109910488, 0.007934526540338993, 0.02963108941912651, -0.03732558712363243, -0.0009043502504937351, 0.02522324211895466, 0.02537585236132145, 0.02124009095132351, 0.04482930526137352, -0.03774241358041763, -0.029057608917355537, 0.05119924247264862, -0.018149985000491142, -0.039916396141052246, 0.041526373475790024, -0.0384967178106308, 0.020077647641301155, 0.0415506474673748, -0.054982103407382965, -0.052581530064344406, -0.02050667442381382, 0.035443685948848724, -0.034266397356987, 0.014710983261466026, 0.01336297020316124, -0.02307869680225849, 0.023880068212747574, -0.04105208069086075, -0.0026582845021039248, 0.034408144652843475, 0.017134081572294235, -0.03282085806131363, 0.0071357423439621925, -0.013654693029820919, -0.0030639292672276497, 0.028422735631465912, 0.033902257680892944, 0.012263539247214794, 0.012557648122310638, -0.04447798430919647, 0.02696988359093666, -0.02281295321881771, -0.019225258380174637, -0.0032191784121096134, 0.007623984944075346, -0.00457165390253067, -0.08056122809648514, 0.02113713137805462, 0.004373141564428806, -0.01962929777801037, -0.02568148821592331, 0.03680717572569847, -0.033531419932842255, -0.0026711104437708855, 0.02289014495909214, 0.06391800940036774, 0.04053432494401932, -0.0026799559127539396, -0.0037662230897694826, 0.006370209623128176, 0.011549139395356178, -0.003858288051560521, 0.005962446331977844, -0.01544464472681284, 0.03722630441188812, 0.06178032234311104, 0.04239840805530548, -0.004490460269153118, 0.042531151324510574, 0.020012106746435165, -0.006761506665498018, 0.02247718535363674, -0.024345511570572853, -0.016917342320084572, -0.02834753692150116, 0.015538733452558517, -0.0016402126057073474, -0.00009046026389114559, -0.02699257992208004, 0.04484294727444649, 0.06994285434484482, -0.003939476329833269, 0.015916893258690834, 0.012044313363730907, 0.0025292402133345604, 0.013822367414832115, -0.022667119279503822, 0.06364907324314117, -0.011661406606435776, -0.0008324497030116618, -0.041649945080280304, 0.013364124111831188, -0.0007082062656991184, 0.004585045389831066, -0.018164372071623802, -0.018484653905034065, -0.01392090693116188, -0.00760338781401515, 0.00965709425508976, -0.002294398844242096, 0.04129234701395035, -0.04146505147218704, 0.04785788059234619, -0.022498195990920067, -0.03203804790973663, 0.007002322934567928, 0.008680342696607113, 0.013760100118815899, -0.04313689097762108, 0.0024809774477034807, -0.022876441478729248, 0.0283349622040987, 0.018914662301540375, 0.01803738996386528, 0.002361894818022847, -0.05003810673952103, 0.033553242683410645, 0.017477821558713913, -0.015753362327814102, 0.016738999634981155, 0.00952395424246788, -0.029636280611157417, 0.024253739044070244, -0.023559438064694405, 0.03078310191631317, 0.06319298595190048, -0.01233868207782507, 0.047627195715904236, 0.04496600106358528, 0.013186483643949032, 0.005618744529783726, -0.01595153845846653, -0.005209015216678381, -0.03024275228381157, 0.04542231932282448, 0.017052505165338516, 0.011304011568427086, -0.05230420082807541, -0.03227614983916283, 0.018757693469524384, -0.04829759523272514, -0.02395695075392723, -0.014259271323680878, -0.025029540061950684, 0.027415292337536812, -0.02717420645058155, -0.0449361614882946, -0.00956581998616457, 0.04105906933546066, -0.025474710389971733, 0.04145493730902672, 0.009034717455506325, -0.00952086690813303, -0.008871732279658318, -0.04782063141465187, 0.03314398601651192, 0.05250116065144539, -0.01948637329041958, 0.049065470695495605, 0.0017440029187127948, 0.04023372381925583, 0.04341179504990578, -0.012231479398906231, 0.001931393169797957, 0.041272442787885666, 0.07742884755134583, 0.0031714222859591246, 0.003769917180761695, 0.02369712106883526, -0.021911608055233955, -0.004613135475665331, -0.02732613869011402, -0.021241171285510063, -0.04016076400876045, -0.002349287271499634, -0.012987635098397732, 0.013339516706764698, -0.020877957344055176, -0.03219121694564819, 0.06554314494132996, 0.019665202125906944, 0.04706548526883125, -0.014989874325692654, 0.03260945901274681, 0.023237131536006927, -0.024732312187552452, -0.0010756432311609387, 0.03759624809026718, -0.001350022736005485, -0.03547115623950958, 0.07890569418668747, 0.0008200021693482995, 0.028151648119091988, 0.006235666573047638, -0.0025828464422374964, -0.0076242899522185326, -0.016297312453389168, 0.0008270272519439459, -0.002649867907166481, 0.04717399552464485, 0.017863161861896515, -0.04379277676343918, 0.009014495648443699, -0.03318331018090248, 0.016939034685492516, -0.032121896743774414, -0.03215695172548294, -0.001255082432180643, -0.0011933459900319576, 0.03176344931125641, 0.02508704550564289, 0.01673315092921257, -0.008054489269852638, 0.008562758564949036, 0.0023187194019556046, 0.003199863014742732, -0.001931871403940022, 0.01670866645872593, 0.02817673794925213, -0.02779153734445572, -0.0009828717447817326, -0.013893253169953823, 0.011868770234286785, -0.011482272297143936, 0.00947646051645279, 0.002160051604732871, 0.05556011199951172, 0.021866844967007637, 0.023247942328453064, -0.01221622247248888, 0.007749899756163359, -0.060369573533535004, 0.016056586056947708, -0.018437305465340614, -0.03883333131670952, -0.004368101246654987, -0.009101799689233303, 0.016876721754670143, -0.014677247032523155, 0.015826817601919174, 0.027805175632238388, 0.0349455252289772, -0.023948146030306816, -0.03298919275403023, 0.026177451014518738, -0.002618856495246291, -0.022998347878456116, 0.044406794011592865, -0.01469490583986044, 0.008437873795628548, 0.016703680157661438, -0.04689767211675644, -0.013154366053640842, -0.005924852564930916, 0.002674231305718422, 0.04711971431970596, -0.030718017369508743, -0.02245274744927883, -0.0035969039890915155, 0.023384086787700653, 0.01642865315079689, 0.007329348474740982, 0.021377695724368095, 0.030080486088991165, 0.02646162174642086, -0.0014829881256446242, -0.024458110332489014, 0.011074436828494072, -0.03010629117488861, -0.07421713322401047, -0.06394938379526138, -0.015458257868885994, -0.02617555484175682, 0.040076471865177155, 0.0378883071243763, -0.030022423714399338, 0.006878072861582041, 0.001694047125056386, -0.03775700554251671, -0.005163787864148617, 0.013160514645278454, 0.03507719933986664, -0.022794580087065697, 0.008430153131484985, 0.008716147392988205, 0.0028868052177131176, 0.04820568114519119, -0.007606262806802988, 0.018723702058196068, 0.002869104966521263, 0.053741153329610825, 0.005610714666545391, -0.0022998210042715073, 0.008139779791235924, -0.02715330570936203, -0.05534447357058525, 0.024417296051979065, 0.016213376075029373, 0.020927023142576218, -0.030996225774288177, 0.014026958495378494, 0.03450080752372742, 0.01929076761007309, 0.028959568589925766, -0.016089752316474915, -0.006996726151555777, 0.008487734943628311, 0.013150307349860668, -0.028033878654241562, 0.04133671894669533, -0.015851108357310295, -0.009815636090934277, 0.014750877395272255, -0.012071975506842136, 0.018973996862769127, -0.010559230111539364, 0.006470697000622749, -0.004651054739952087, 0.010126489214599133, -0.05629437789320946, -0.06191381439566612, -0.012766800820827484, 0.01798725686967373, -0.017191166058182716, -0.014079133979976177, 0.0014075124636292458, -0.015628810971975327, -0.07344923168420792, -0.012322047725319862, 0.026717735454440117, -0.010077150538563728, -0.044474534690380096, -0.012198319658637047, -0.027274489402770996, -0.01564987190067768, -0.002567501738667488, -0.015829795971512794, -0.009530095383524895, -0.01878957636654377 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Closing thoughts - While I couldn't port the model ensemble astransformersdoesn't support it, on the plus side the download size of the finalfacebook/wmt19-*models is 1.1GB and not 13GB as in the original. For some reason the original includes the optimizer state saved in the model - so it adds almost 9GB (4x2.2GB) of dead weight for those who just want to download the model to use it as is to translate text. - While the job of porting looked very challenging at the beginning as I didn't know the internals of neithertransformersnorfairseq, looking back it wasn't that difficult after all. This was primarily due to having most of the components already available to me in the various parts oftransformers- I *just* needed to find parts that I needed, mostly borrowing heavily from other models, and then tweak them to do what I needed. This was true for both the code and the tests. Let's rephrase that - porting was difficult - but it'd have been much more difficult if I had to write it all from scratch. And finding the right parts wasn't easy.
[ -0.06374290585517883, 0.029976528137922287, 0.015033316798508167, 0.013556282967329025, 0.06768865883350372, -0.0079945744946599, 0.037221916019916534, 0.035466525703668594, 0.0027193487621843815, -0.14040498435497284, -0.022945718839764595, 0.030138494446873665, 0.04544191434979439, -0.056168291717767715, 0.03947479650378227, -0.007345625199377537, 0.004897549282759428, -0.049871742725372314, 0.036062873899936676, 0.02597086876630783, 0.01612432673573494, -0.015393538400530815, 0.025582609698176384, -0.024202687665820122, -0.021098436787724495, -0.06451189517974854, -0.011824113316833973, 0.07555840909481049, -0.016750916838645935, 0.004320542328059673, -0.011872338131070137, -0.006217433605343103, -0.049039676785469055, -0.06346920132637024, -0.0549931600689888, -0.0006809534970670938, -0.055527471005916595, 0.027463393285870552, 0.007880262099206448, -0.017673376947641373, 0.02870301716029644, 0.06106916069984436, -0.10095687955617905, 0.08663247525691986, 0.07626310735940933, -0.02562357857823372, -0.05419955775141716, 0.021069573238492012, -0.038232047110795975, 0.01066411193460226, -0.05966751649975777, 0.013532397337257862, 0.039914555847644806, 0.08111639320850372, 0.07495847344398499, -0.03817444667220116, -0.021756179630756378, -0.0034350331407040358, -0.018637780100107193, -0.016814682632684708, 0.0464104488492012, 0.025330206379294395, 0.03580223768949509, 0.01051604375243187, -0.07900652289390564, 0.03399660065770149, -0.01706894114613533, -0.011513515375554562, -0.0678633525967598, -0.09803739190101624, -0.020894721150398254, -0.006553213577717543, 0.03494459390640259, -0.02293788455426693, -0.025656217709183693, -0.037847477942705154, 0.052935272455215454, 0.045249421149492264, 0.05662573128938675, 0.04031110182404518, -0.00999913364648819, 0.061023373156785965, 0.058983709663152695, -0.011501424014568329, -0.0014316135784611106, -0.05219849571585655, 0.03631863370537758, -0.0397605299949646, -0.028087176382541656, -0.010989965870976448, -0.056787725538015366, -0.06974488496780396, -0.06272698193788528, 0.013414613902568817, 0.0598239041864872, 0.007832452654838562, -0.033305343240499496, 0.06559331715106964, 0.05442062020301819, 0.023514432832598686, 0.06376801431179047, 0.024554235860705376, 0.022446831688284874, -0.07884715497493744, 0.01650620996952057, 0.022211529314517975, -0.06295155733823776, -0.1294807344675064, 0.04235801473259926, 0.03106197528541088, 0.04772370308637619, -0.023660607635974884, -0.0005201998865231872, -0.00012089250958524644, -0.04917535558342934, 0.07326675951480865, 0.009458052925765514, 0.020854663103818893, 0.018235860392451286, 0.06218364089727402, 0.07688210904598236, 0.08892003446817398, 0.02989501692354679, -0.05938524007797241, 0.10331307351589203, 0.031408581882715225, 0.018912790343165398, -0.03788617253303528, 0.0034328741021454334, -0.017699535936117172, 0.04333000257611275, -0.0633089616894722, 0.005925192963331938, 0.00114283652510494, -0.02505662478506565, -0.09685687720775604, 0.00936489924788475, 0.00721035385504365, -0.005519338883459568, -0.0060129789635539055, -0.01863247901201248, 0.015878092497587204, -0.021649939939379692, 0.010601448826491833, 0.011173072271049023, 0.008232330903410912, -0.07137954235076904, 0.07560660690069199, -0.015412315726280212, -0.010094581171870232, -0.055427443236112595, 0.018819065764546394, -0.0013896963791921735, -0.09297165274620056, 0.012173731811344624, -0.008558038622140884, 0.000475342501886189, -0.05687427893280983, -0.08124686032533646, -0.024634920060634613, -0.03528469428420067, 0.03554056957364082, -0.059345491230487823, -0.03850720822811127, -0.016650373116135597, -0.008135462179780006, -0.0039299908094108105, 0.05541713163256645, 0.02640179917216301, -0.06122611090540886, 0.038927964866161346, -0.04834136739373207, 0.052660297602415085, -0.02138558402657509, -0.023948967456817627, 0.02269105240702629, 0.06747362017631531, 0.03530827537178993, 0.06404513120651245, -0.030569134280085564, -0.03232593834400177, 0.03726903349161148, 0.02769336849451065, -0.04082190990447998, 0.007623073644936085, -0.037828147411346436, 0.04481036216020584, 0.012303417548537254, -0.09666121751070023, -0.024099158123135567, -0.07495110481977463, 0.011755322106182575, 0.06969355791807175, -0.007966161705553532, -0.0032233295496553183, 0.002746341982856393, -0.014587931334972382, 0.07664080709218979, 0.07245786488056183, 0.06019575148820877, 0.09963566064834595, 0.06334210187196732, 0.015732554718852043, 0.026360008865594864, -0.016629202291369438, 0.04056185483932495, -0.045714668929576874, -0.0024132071994245052, -0.030282258987426758, 0.01113183330744505, 0.01048255991190672, -0.09045899659395218, 0.009322906844317913, -0.017027046531438828, 0.0019844018388539553, -0.03056105226278305, -0.07937993109226227, 0.010766654275357723, -0.025435777381062508, -0.11489982903003693, 0.0961826741695404, 0.04640481248497963, -0.07381395995616913, -0.08537811040878296, -0.027886969968676567, 0.06926023215055466, -0.01363602839410305, 0.007991475984454155, 0.040982697159051895, -0.09284250438213348, 0.07426564395427704, 0.026176204904913902, -0.06724562495946884, 0.05211788788437843, 0.009725069627165794, -0.027786632999777794, -0.06054671108722687, -0.02547375112771988, 0.006716741248965263, -0.05082673579454422, -0.0009761286783032119, 0.06344877928495407, -0.022123437374830246, -0.002583320252597332, 0.0008741513011045754, 0.04114976152777672, 0.007355904206633568, 0.028826097026467323, -0.0009838099358603358, 0.009982644580304623, -0.024949856102466583, 0.021289952099323273, 0.039776984602212906, -0.033794254064559937, 0.022278394550085068, 0.027958450838923454, 0.0016031796112656593, 0.009632844477891922, 0.01816713623702526, 0.02189183235168457, -0.005203514825552702, 0.03116735816001892, -0.003338839393109083, 0.0036598672159016132, -0.01949620246887207, -0.029487304389476776, 0.007942449301481247, -0.00758111197501421, -0.0068712495267391205, -0.002251903060823679, 0.004278211854398251, -0.010841894894838333, -0.001875338377431035, 0.012256531976163387, 0.00902873370796442, -0.004612343851476908, 0.008219904266297817, -0.023560846224427223, -0.058368850499391556, -0.004842156078666449, 0.016214055940508842, -0.036193449050188065, 0.04136092960834503, -0.008740076795220375, 0.0026930710300803185, -0.0033409043680876493, 0.010818195529282093, -0.014390457421541214, -0.04220890998840332, 0.018446311354637146, 0.02447502128779888, -0.020983755588531494, 0.048804908990859985, -0.011799126863479614, -0.03974676504731178, -0.013516892679035664, 0.044721487909555435, -0.04321988299489021, -0.00899053830653429, 0.011337334290146828, 0.000493814586661756, -0.0074539585039019585, 0.032355375587940216, 0.008235005661845207, -0.012597541324794292, -0.03232548013329506, -0.021961558610200882, 0.024732187390327454, -0.09150607138872147, 0.034426238387823105, -0.015543395653367043, 0.03751836344599724, -0.023214196786284447, -0.03964315727353096, -0.00828003790229559, -0.039303358644247055, 0.016178598627448082, 0.07069101184606552, 0.027481939643621445, 0.03763638809323311, 0.012129400856792927, 0.046513576060533524, -0.018072504550218582, 0.05254783853888512, 0.004558083601295948, -0.015565309673547745, 0.04086063802242279, 0.03623871132731438, -0.043149519711732864, -0.0598970428109169, 0.03252333030104637, -0.028237005695700645, -0.004350557923316956, 0.03275899961590767, 0.038984231650829315, -0.04222099855542183, -0.007899864576756954, -0.054738979786634445, 0.03961724042892456, -0.02080960012972355, -0.005975330714136362, -0.02265366166830063, -0.0061940355226397514, -0.019721271470189095, -0.017153026536107063, 0.029628466814756393, -0.012054369784891605, 0.05537300184369087, -0.02344593033194542, -0.015953009948134422, 0.05810382217168808, -0.011446119286119938, 0.04387028515338898, 0.008550701662898064, -0.018930956721305847, 0.05306101217865944, 0.06277792900800705, 0.002720848424360156, -0.017005514353513718, -0.08307833969593048, 0.011430187150835991, 0.06442849338054657, -0.0298320222645998, 0.009223636239767075, 0.02580135315656662, 0.019794557243585587, 0.0065138498321175575, -0.0525178425014019, -0.05384423956274986, -0.006421791389584541, -0.07735326141119003, -0.007107681129127741, 0.02555670775473118, 0.08519669622182846, 0.03725522756576538, 0.015638286247849464, 0.009133742190897465, 0.016642622649669647, -0.039573751389980316, 0.026465073227882385, 0.025748617947101593, -0.000736140355002135, 0.013279846869409084, 0.03593821823596954, 0.019998906180262566, -0.05347644165158272, 0.011463996022939682, 0.0030003602150827646, -0.012486474588513374, 0.02925984561443329, -0.03998880460858345, 0.010891505517065525, 0.0029500536620616913, 0.06102608144283295, 0.003434387966990471, 0.021153319627046585, 0.012076826766133308, 0.046770259737968445, 0.0392635241150856, -0.058032549917697906, 0.01867232657968998, -0.03270323947072029, -0.008783756755292416, -0.015675416216254234, 0.015472433529794216, 0.011570548638701439, -0.015210682526230812, 0.020329860970377922, 0.026253940537571907, -0.01962791010737419, -0.021171456202864647, 0.03200928494334221, 0.03101973608136177, 0.050220705568790436, -0.04377206414937973, -0.008970635011792183, 0.02800065465271473, -0.00752254156395793, -0.0189825389534235, -0.036417633295059204, -0.03775019571185112, 0.0036260129418224096, 0.018673017621040344, -0.004520655144006014, -0.002899396698921919, 0.005208404269069433, -0.0502919927239418, -0.006229465361684561, 0.019086457788944244, -0.041985418647527695, 0.03271637111902237, -0.015292355790734291, -0.011392694897949696, 0.04677197337150574, -0.011304167099297047, 0.01907815784215927, -0.00042209422099404037, -0.03173643723130226, -0.06698276847600937, -0.008763113990426064, 0.036580927670001984, 0.04844282567501068, 0.03786711022257805, -0.014737908728420734, 0.0032852767035365105, 0.031052445992827415, 0.009142367169260979, -0.05232832208275795, 0.07429304718971252, -0.03963521495461464, 0.018196577206254005, -0.05318855866789818, 0.017345476895570755, -0.0011286130174994469, 0.03342871367931366, 0.024493375793099403, -0.01966031827032566, 0.019626451656222343, 0.008235371671617031, -0.0463261716067791, -0.04309341311454773, 0.011763989925384521, -0.004050746560096741, 0.032693006098270416, -0.034558672457933426, -0.03547031432390213, 0.025862330570816994, 0.02898876555263996, -0.010081053711473942, 0.0032556892838329077, -0.01709803380072117, 0.04272504895925522, -0.032172124832868576, 0.0032445297110825777, 0.05844215303659439, -0.03879562392830849, -0.00006791817577322945, -0.01972324401140213, -0.020525535568594933, -0.026902077719569206, 0.0006803430151194334, -0.008645763620734215, 0.029537074267864227, 0.07309074699878693, 0.012294305488467216, -0.01571367122232914, -0.009203540161252022, 0.021235713735222816, 0.009322967380285263, -0.00821087695658207, 0.023364199325442314, -0.0356413871049881, -0.02090255171060562, 0.035314030945301056, 0.03557207062840462, 0.06408950686454773, -0.00011195564729860052, -0.0053383405320346355, -0.005290523637086153, 0.006788427475839853, -0.02312324568629265, -0.03294127807021141, -0.048022083938121796, -0.026473145931959152, 0.02639799937605858, 0.031387243419885635, 0.03074449673295021, 0.008469448424875736, 0.041479866951704025, 0.05114331468939781, 0.024948162958025932, -0.031197141855955124, -0.00760411424562335, -0.03596627712249756, 0.01396563183516264, -0.048096440732479095, 0.014966493472456932, -0.007348853629082441, 0.00708980904892087, 0.014148715883493423, -0.02352648414671421, -0.02346033602952957, 0.025386054068803787, -0.05496200546622276, -0.0019000000320374966, 0.047128669917583466, 0.017406083643436432, 0.015595346689224243, 0.01368629653006792, 0.01342848315834999, -0.0022366091143339872, 0.07719481736421585, -0.021036650985479355, -0.04076843336224556, 0.022321544587612152, 0.015223382972180843, -0.014519529417157173, 0.04731935262680054, 0.04340051859617233, -0.007136184722185135, -0.011587127111852169, 0.007145529612898827, 0.05975138768553734, -0.006515809800475836, 0.004551023710519075, 0.019547363743185997, 0.031829796731472015, 0.00014282642223406583, 0.004995465744286776, -0.04169046878814697, -0.030530434101819992, 0.01051240786910057, -0.020103346556425095, 0.04779154434800148, 0.0028150712605565786, -0.03096943348646164, 0.034382909536361694, -0.03532468155026436, 0.024887431412935257, 0.003939626272767782, -0.011068815365433693, 0.016682947054505348, -0.03285444527864456, 0.005366214085370302, -0.0025371701922267675, 0.02162034623324871, 0.028452962636947632, -0.013613387010991573, -0.006635445635765791, 0.014144336804747581, -0.014298317953944206, 0.016711199656128883, 0.009372983127832413, 0.02863212674856186, -0.0298233050853014, -0.018210485577583313, 0.030691087245941162, 0.028168288990855217, 0.016976071521639824, 0.03695986792445183, -0.0007017083116807044, 0.004773243330419064, -0.021100739017128944, -0.035176873207092285, 0.060611359775066376, 0.015548734925687313, 0.0414000004529953, 0.0009437613771297038, -0.007014291360974312, 0.0656685009598732, 0.019734321162104607, 0.022289037704467773, 0.019202349707484245, 0.04552268609404564, 0.029828347265720367, -0.01933681219816208, -0.02132641151547432, -0.016478216275572777, -0.016382277011871338, 0.0007292749942280352, 0.016404911875724792, 0.008084244094789028, -0.033382683992385864, 0.017801592126488686, 0.03666672483086586, 0.012507975101470947, 0.025414185598492622, -0.013430782593786716, 0.03730334714055061, -0.001338872592896223, 0.00006565064541064203, -0.019630488008260727, 0.00278207054361701, -0.009424559772014618, 0.009299715049564838, -0.007433146238327026, -0.0487569198012352, 0.020656947046518326, -0.015517940744757652, 0.04638029262423515, -0.024355409666895866, -0.008481185883283615, -0.0064986636862158775, 0.010069216601550579, 0.0120242303237319, -0.01964525505900383, 0.010388324037194252, -0.0018614039290696383, -0.06734159588813782, -0.012760041281580925, 0.010608703829348087, 0.04231395944952965, -0.0028626592829823494, -0.014687122777104378, -0.0104962894693017, -0.045499589294195175, -0.044760216027498245, 0.012230138294398785, -0.008165747858583927, 0.03800134360790253, -0.012601290829479694, -0.0024741527158766985, 0.020760493353009224, -0.00975788477808237, 0.014245628379285336, 0.0019606479909271, 0.02271343022584915, 0.032603807747364044, -0.03841102123260498, 0.028427155688405037, -0.02047180011868477, 0.004897681530565023, 0.03394364193081856, 0.00618033716455102, 0.0555390790104866, 0.020131070166826248, 0.027035722509026527, 0.06348102539777756, 0.014696570113301277, 0.029277022927999496, -0.024051956832408905, 0.0013065404491499066, 0.03140166774392128, 0.003203673753887415, 0.01822041906416416, -0.04317222908139229, -0.01162718515843153, -0.017434680834412575, 0.0021049855276942253, 0.002062480431050062, 0.07245061546564102, -0.037544626742601395, -0.03863906115293503, -0.021514737978577614, -0.020794536918401718, 0.0591861754655838, 0.028596295043826103, -0.016424478963017464, -0.0027567155193537474, -0.010126419365406036, -0.0331738144159317, 0.030056487768888474, -0.001866124221123755, -0.047630637884140015, -0.011118902824819088, 0.022338110953569412, 0.013338521122932434, -0.04714702069759369, 0.04339202493429184, -0.0280012134462595, 0.004406417720019817, 0.040740836411714554, 0.06393113732337952, -0.0007131311576813459, -0.015978500247001648, -0.00917649082839489, 0.02615305408835411, 0.002338600577786565, -0.03687720745801926, -0.03137917444109917, -0.01032538153231144, 0.03579200804233551, -0.004402132239192724, -0.01150035485625267, 0.008744947612285614, -0.023690542206168175, -0.021754208952188492, -0.043798040598630905, -0.006561563350260258, -0.0028651878237724304, 0.023785945028066635, 0.04825747758150101, 0.0034749575424939394, 0.02257331646978855, 0.011021031998097897, -0.006516915280371904, -0.05445962771773338, 0.046220529824495316, 0.06128076836466789, 0.01561083272099495, 0.002441184362396598, -0.018628668040037155, 0.0045797755010426044, 0.021692760288715363, -0.08458546549081802, -0.017465615645051003, 0.00920862052589655, -0.02492402493953705, -0.03021266870200634, -0.016617896035313606, 0.003395524574443698, 0.03885994851589203, 0.01516436692327261, 0.019009659066796303, -0.006564164534211159, 0.002214787295088172, 0.014560057781636715, -0.045857418328523636, -0.02651277929544449, -0.022982580587267876, 0.0407126359641552, 0.0006593290599994361, -0.01726844534277916, -0.07662977278232574, 0.017970159649848938, -0.009506247006356716, 0.0023502171970903873, -0.001432038494385779, 0.0031047773081809282, 0.006030648481100798, 0.008152891881763935, 0.03858225792646408, -0.04238078370690346, -0.10068261623382568, -0.00036007611197419465, 0.009535911493003368, -0.006592182442545891, -0.021814657375216484, -0.024427495896816254, -0.02922702394425869, -0.024048304185271263, -0.04165979102253914, -0.022404275834560394, -0.014758054167032242, 0.048719123005867004, -0.026094261556863785, -0.024352511391043663, -0.009202118963003159 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Porting weights and configuration The first thing I did is to look at what was inside the publicly shared checkpoint. [This notebook](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/nbs/config.ipynb) shows what I did there. I discovered that there were 4 checkpoints in there. I had no idea what to do about it, so I started with a simpler job of using just the first checkpoint. Later I discovered thatfairseqused all 4 checkpoints in an ensemble to get the best predictions, and thattransformerscurrently doesn't support that feature. When the porting was completed and I was able to measure the performance scores, I found out that themodel4.ptcheckpoint provided the best score. But during the porting performance didn't matter much. Since I was using only one checkpoint it was crucial that when I was comparing outputs, I hadfairseqalso use just one and the same checkpoint. To accomplish that I used a slightly differentfairseqAPI: ``` from fairseq import hub_utils #checkpoint_file = 'model1.pt:model2.pt:model3.pt:model4.pt' checkpoint_file = 'model1.pt' model_name_or_path = 'transformer.wmt19.ru-en' data_name_or_path = '.' cls = fairseq.model_parallel.models.transformer.ModelParallelTransformerModel models = cls.hub_models() kwargs = {'bpe': 'fastbpe', 'tokenizer': 'moses'} ru2en = hub_utils.from_pretrained( model_name_or_path, checkpoint_file, data_name_or_path, archive_map=models, **kwargs ) ``` First I looked at the model: ``` print(ru2en["models"][0]) ``` ``` TransformerModel( (encoder): TransformerEncoder( (dropout_module): FairseqDropout() (embed_tokens): Embedding(31232, 1024, padding_idx=1) (embed_positions): SinusoidalPositionalEmbedding() (layers): ModuleList( (0): TransformerEncoderLayer( (self_attn): MultiheadAttention( (dropout_module): FairseqDropout() (k_proj): Linear(in_features=1024, out_features=1024, bias=True) (v_proj): Linear(in_features=1024, out_features=1024, bias=True) (q_proj): Linear(in_features=1024, out_features=1024, bias=True) (out_proj): Linear(in_features=1024, out_features=1024, bias=True) ) [...] # the full output is in the notebook ``` which looked very similar to BART's architecture, with some slight differences in a few layers - some were added, others removed. So this was great news as I didn't have to re-invent the wheel, but to only tweak a well-working design. Note that in the code sample above I'm not usingtorch.load()to loadstate_dict. This is what I initially did and the result was most puzzling - I was missingself_attn.(k|q|v)_projweights and instead had a singleself_attn.in_proj. When I tried loading the model usingfairseqAPI, it fixed things up - apparently that model was old and was using an old architecture that had one set of weights fork/q/vand the newer architecture has them separate. Whenfairseqloads this old model, it rewrites the weights to match the modern architecture. I also used [this notebook](https://github.com/stas00/porting/tree/master/transformers/fairseq-wmt19/nbs/visualize-models.ipynb) to compare thestate_dicts visually. In that notebook you will also see thatfairseqfetches a 2.2GB-worth of data inlast_optimizer_state, which we can safely ignore, and have a 3 times leaner final model size. In the conversion script I also had to remove somestate_dictkeys, which I wasn't going to use, e.g.model.encoder.version,model.modeland a few others. Next we look at the configuration args: ``` args = dict(vars(ru2en["args"])) pprint(args) ``` ``` 'activation_dropout': 0.0, 'activation_fn': 'relu', 'adam_betas': '(0.9, 0.98)', 'adam_eps': 1e-08, 'adaptive_input': False, 'adaptive_softmax_cutoff': None, 'adaptive_softmax_dropout': 0, 'arch': 'transformer_wmt_en_de_big', 'attention_dropout': 0.1, 'bpe': 'fastbpe', [... full output is in the notebook ...] ``` ok, we will copy those to configure the model. I had to rename some of the argument names, wherevertransformersused different names for the corresponding configuration setting. So the re-mapping of configuration looks as following: ``` model_conf = { "architectures": ["FSMTForConditionalGeneration"], "model_type": "fsmt", "activation_dropout": args["activation_dropout"], "activation_function": "relu", "attention_dropout": args["attention_dropout"], "d_model": args["decoder_embed_dim"], "dropout": args["dropout"], "init_std": 0.02, "max_position_embeddings": args["max_source_positions"], "num_hidden_layers": args["encoder_layers"], "src_vocab_size": src_vocab_size, "tgt_vocab_size": tgt_vocab_size, "langs": [src_lang, tgt_lang], [...] "bos_token_id": 0, "pad_token_id": 1, "eos_token_id": 2, "is_encoder_decoder": True, "scale_embedding": not args["no_scale_embedding"], "tie_word_embeddings": args["share_all_embeddings"], } ``` All that remains is to save the configuration intoconfig.jsonand create a newstate_dictdump intopytorch.dump: ``` print(f"Generating {fsmt_tokenizer_config_file}") with open(fsmt_tokenizer_config_file, "w", encoding="utf-8") as f: f.write(json.dumps(tokenizer_conf, ensure_ascii=False, indent=json_indent)) [...] print(f"Generating {pytorch_weights_dump_path}") torch.save(model_state_dict, pytorch_weights_dump_path) ``` We have the configuration and the model'sstate_dictported - yay! You will find the final conversion code [here](https://github.com/huggingface/transformers/blob/129fdae04033fe4adfe013b734deaec6ec34ae2e/src/transformers/convert_fsmt_original_pytorch_checkpoint_to_pytorch.py#L162).
[ -0.036576561629772186, 0.010734756477177143, -0.029329918324947357, 0.004268776159733534, 0.08195953816175461, 0.026964306831359863, -0.00014431435556616634, 0.035770807415246964, -0.029188942164182663, -0.07416976988315582, 0.02131129428744316, -0.018472937867045403, -0.0021271617151796818, 0.009953214786946774, 0.025687741115689278, -0.048515934497117996, 0.03384716063737869, -0.08935564011335373, 0.02543708123266697, 0.01381879486143589, 0.04082399606704712, -0.04968753829598427, 0.06787233054637909, 0.05424783378839493, -0.02977045066654682, -0.06823378056287766, 0.0009891914669424295, 0.06709149479866028, -0.049980033189058304, 0.044848281890153885, -0.06314165145158768, 0.03641330450773239, -0.03125376254320145, -0.05375906825065613, 0.061284322291612625, 0.022118370980024338, -0.04023795574903488, 0.04117758944630623, 0.029975347220897675, -0.052584659308195114, -0.016166219487786293, 0.02267756499350071, -0.02940334938466549, 0.0449194498360157, 0.040484149008989334, 0.023963309824466705, -0.05459902808070183, 0.048513490706682205, -0.02322329767048359, 0.018056169152259827, -0.01667596586048603, 0.024898095056414604, 0.02527492120862007, 0.027390213683247566, 0.03439731150865555, -0.03940124809741974, -0.006942761596292257, -0.03359023854136467, 0.04560582712292671, 0.020232895389199257, -0.03194554150104523, 0.028165096417069435, 0.021230854094028473, 0.07780823856592178, -0.0066542658023536205, 0.01182476431131363, -0.01923830807209015, 0.01659662090241909, -0.03271183371543884, -0.026334580034017563, -0.001933945924974978, -0.007857289165258408, -0.00231813988648355, -0.06414026767015457, 0.01570216193795204, -0.0528857484459877, -0.02919243648648262, -0.029877066612243652, 0.06729652732610703, 0.04644244164228439, -0.0013372625689953566, 0.03771916776895523, -0.03617948666214943, 0.018707353621721268, 0.03449634462594986, -0.00522984191775322, 0.058622803539037704, -0.043862853199243546, -0.008846044540405273, 0.02656690962612629, -0.023824933916330338, -0.06856004893779755, -0.07246553897857666, 0.027447428554296494, 0.03478950634598732, -0.026180526241660118, -0.002215309999883175, 0.05588512495160103, 0.01619989238679409, -0.06082240119576454, 0.0031018448062241077, -0.05930696055293083, 0.0555737130343914, -0.05556340888142586, -0.01330726407468319, 0.04652903228998184, 0.018038855865597725, -0.10273580998182297, -0.018803421407938004, 0.022952938452363014, 0.015543759800493717, 0.02261914126574993, -0.04592210799455643, 0.08740174770355225, -0.021378308534622192, 0.03913198038935661, -0.004817104898393154, -0.056912992149591446, 0.03817151486873627, 0.04091711714863777, -0.005578225012868643, 0.15383374691009521, 0.042975932359695435, -0.029122717678546906, 0.04418794810771942, 0.05897417664527893, 0.054112520068883896, 0.028792183846235275, -0.023540938273072243, -0.017361987382173538, 0.0625123605132103, -0.04702169448137283, 0.047363653779029846, -0.046871624886989594, -0.04725244268774986, -0.10389846563339233, -0.0019042345229536295, 0.0037359020207077265, -0.00033462821738794446, 0.019159656018018723, -0.09895341098308563, 0.07908214628696442, -0.0034969195257872343, 0.00681079737842083, -0.012228012084960938, 0.025607433170080185, -0.0887121930718422, 0.08593190461397171, 0.05480849742889404, -0.03240402042865753, -0.0609862394630909, 0.01549481600522995, -0.007097943220287561, -0.06330021470785141, 0.009485567919909954, 0.06518557667732239, 0.015556254424154758, -0.07386563718318939, -0.0564420185983181, -0.004153876565396786, -0.010637381114065647, 0.004389050882309675, -0.05226266384124756, -0.07926399260759354, -0.02274326980113983, 0.0027756893541663885, 0.022014068439602852, -0.013806753791868687, 0.0634026750922203, 0.036185380071401596, 0.05117206647992134, -0.01885492540895939, 0.10914468765258789, -0.020332451909780502, -0.03471461683511734, 0.07825520634651184, 0.052782267332077026, 0.06034374609589577, 0.007169835269451141, -0.020336134359240532, -0.07387134432792664, 0.0519796721637249, -0.08984316885471344, 0.045494504272937775, 0.057340964674949646, -0.043771713972091675, 0.01122791226953268, -0.01413777470588684, -0.04799467325210571, 0.0026834718883037567, -0.11707845330238342, -0.01091633178293705, 0.07640767097473145, -0.004804389551281929, 0.023817608132958412, -0.04342683404684067, -0.02198837138712406, 0.07007867097854614, 0.037540070712566376, 0.010405011475086212, 0.06225688382983208, -0.0114292586222291, 0.022713197395205498, -0.009755492210388184, -0.023532187566161156, 0.06509978324174881, -0.0714787170290947, -0.1609756052494049, 0.03257829323410988, 0.004011176992207766, 0.028051555156707764, -0.06765997409820557, -0.016945447772741318, -0.05526594817638397, -0.00548968743532896, -0.0411067008972168, -0.06684131920337677, 0.0053289965726435184, -0.005877864547073841, -0.011691263876855373, 0.14719079434871674, 0.007328134961426258, -0.012644861824810505, 0.006658567581325769, 0.02489176206290722, 0.00391177786514163, 0.008981002494692802, 0.0019389718072488904, 0.0600627064704895, -0.03248942643404007, -0.05620470643043518, -0.01124617550522089, -0.016444558277726173, 0.12153036147356033, 0.0030828381422907114, -0.019933363422751427, -0.013829943723976612, -0.04770469665527344, 0.03760603442788124, -0.07783838361501694, 0.005493081174790859, 0.0683797225356102, -0.014208530075848103, 0.0016188945155590773, 0.019633429124951363, 0.03593262657523155, 0.05726409703493118, 0.0006579120527021587, -0.05345313623547554, -0.038678128272295, -0.05796978250145912, 0.025698984041810036, 0.0376463457942009, -0.03297845274209976, 0.06910025328397751, 0.040209926664829254, 0.024239523336291313, 0.015448235906660557, -0.015054263174533844, 0.053868748247623444, -0.02005062811076641, 0.029013436287641525, -0.046697840094566345, -0.04629542678594589, -0.0007992526516318321, -0.026827827095985413, -0.0243845097720623, -0.023438138887286186, -0.005594565067440271, -0.002052544616162777, 0.027436913922429085, -0.04155930131673813, -0.0006950287497602403, 0.0019444511272013187, 0.022489039227366447, 0.012591452337801456, -0.037761393934488297, -0.015827100723981857, -0.05719701200723648, -0.005905043799430132, 0.03464921936392784, -0.04901953786611557, 0.008703946135938168, 0.006499145645648241, 0.0109578687697649, 0.009707453660666943, 0.017944008111953735, -0.006413613446056843, -0.031957946717739105, 0.03074059449136257, 0.029616549611091614, 0.01160221453756094, 0.005387605167925358, 0.013598833233118057, -0.027049299329519272, 0.00794938113540411, 0.011956213973462582, -0.02063371241092682, -0.00004112535680178553, 0.04316728189587593, -0.046548280864953995, 0.011988897807896137, 0.021334871649742126, -0.0073983194306492805, -0.035865724086761475, 0.021572722122073174, 0.004892867058515549, 0.020534822717308998, -0.09094042330980301, 0.01587764360010624, -0.009787311777472496, 0.04236753284931183, -0.06159336119890213, -0.038900114595890045, 0.024330083280801773, -0.06407421827316284, 0.01189644169062376, 0.010058771818876266, 0.04724125936627388, 0.00481198076158762, 0.019525716081261635, 0.016969552263617516, -0.016267161816358566, 0.03847825154662132, 0.0010352253448218107, 0.01364060677587986, 0.049660574644804, -0.014505364000797272, -0.02664789743721485, -0.01818167418241501, -0.021625561639666557, -0.039121419191360474, 0.026805929839611053, 0.009887036867439747, 0.044738154858350754, 0.008003554306924343, -0.017846863716840744, -0.037474751472473145, -0.004136322066187859, -0.03372444957494736, 0.02360803633928299, -0.032871536910533905, -0.01402871310710907, -0.0443999208509922, -0.03395881876349449, 0.020097265020012856, -0.010220009833574295, 0.03147447854280472, 0.0012371984776109457, 0.009272790513932705, 0.03995261713862419, -0.008817889727652073, 0.017755592241883278, 0.027468262240290642, 0.05089447274804115, 0.026573609560728073, 0.004693734925240278, -0.014226360246539116, 0.0075066606514155865, -0.021403376013040543, 0.030555883422493935, 0.041552044451236725, -0.02075556106865406, -0.02188527025282383, -0.003996011335402727, 0.035083603113889694, 0.01955423690378666, 0.011850501410663128, -0.08234219253063202, 0.020876126363873482, -0.0578584223985672, -0.03208061680197716, 0.012356403283774853, 0.06567833572626114, -0.027124498039484024, 0.040002867579460144, -0.04448170214891434, -0.00789555348455906, -0.04807620123028755, 0.0359639972448349, 0.03315436840057373, 0.0005539213889278471, -0.006417802069336176, 0.020597312599420547, -0.030708130449056625, -0.042837876826524734, 0.016827842220664024, 0.009833850897848606, 0.005848797503858805, -0.011559459380805492, -0.03933475539088249, -0.003438153536990285, 0.015923354774713516, 0.041460368782281876, -0.010435905307531357, -0.04438059777021408, 0.025716550648212433, 0.032135773450136185, 0.004792005755007267, 0.004074717406183481, -0.03166991472244263, -0.009609679691493511, -0.011006954126060009, -0.053383827209472656, -0.005124564282596111, 0.001401448855176568, -0.030769722536206245, 0.018581874668598175, -0.00781130651012063, -0.021623872220516205, -0.015638908371329308, -0.027814285829663277, 0.009662536904215813, 0.014909487217664719, -0.03906857594847679, 0.002402213169261813, -0.035569898784160614, -0.0182432159781456, -0.022349225357174873, 0.022233959287405014, -0.019425494596362114, -0.03719230368733406, 0.05952848494052887, 0.022458689287304878, -0.02157568745315075, -0.00830796454101801, -0.022042900323867798, 0.027992110699415207, -0.02786973863840103, -0.00982637982815504, 0.052841491997241974, -0.045574747025966644, 0.018941884860396385, -0.0001759386359481141, 0.034699052572250366, -0.0029916854109615088, -0.018141571432352066, -0.024778665974736214, -0.062248531728982925, -0.016093848273158073, 0.06697864830493927, 0.027438202872872353, 0.03149871900677681, 0.02902793698012829, -0.01875476725399494, 0.0004360415623523295, 0.010973830707371235, -0.025354651734232903, 0.003364580450579524, 0.005716103594750166, 0.017022592946887016, -0.044293493032455444, 0.029490835964679718, 0.02965284138917923, -0.026006637141108513, 0.023232510313391685, -0.06728190928697586, 0.017692947760224342, 0.05831816419959068, 0.004469302017241716, -0.03345054015517235, -0.0061389850452542305, 0.0477227047085762, -0.006520014256238937, 0.03677656129002571, -0.02585459314286709, 0.035147618502378464, 0.05116980895400047, -0.03212527930736542, -0.05236945301294327, -0.016118308529257774, 0.014309052377939224, -0.013162091374397278, 0.009190181270241737, 0.03615386411547661, -0.08025933057069778, -0.04072973132133484, -0.0023538118693977594, -0.008487052284181118, -0.01655956357717514, 0.011480704881250858, -0.05131681263446808, 0.015661923214793205, 0.04706951230764389, -0.03546726331114769, 0.01616969145834446, 0.009035062044858932, -0.017258981242775917, -0.019729139283299446, 0.013777466490864754, 0.029138706624507904, -0.031093083322048187, -0.031752780079841614, 0.03559017553925514, 0.03344250097870827, 0.03572860732674599, -0.001830333610996604, 0.005528447683900595, 0.015815263614058495, -0.004075469449162483, 0.02220609225332737, -0.04241587221622467, -0.02113010361790657, -0.013659392483532429, -0.016503816470503807, 0.0008355671307072043, -0.013606646098196507, 0.0017484213458374143, 0.015559596940875053, 0.030700378119945526, 0.02380591630935669, -0.02547411248087883, 0.01161650288850069, 0.0034935749135911465, -0.045656438916921616, -0.044985536485910416, 0.01762298308312893, -0.03126910701394081, 0.059738483279943466, 0.009370372630655766, -0.02506089396774769, -0.02246187813580036, 0.05189965292811394, -0.032114673405885696, -0.004683828912675381, 0.05753239616751671, 0.03469253331422806, -0.004616246558725834, 0.0055089304223656654, -0.033254217356443405, -0.017036540433764458, 0.019036034122109413, -0.0025583526585251093, -0.05808489769697189, 0.03531261160969734, -0.0034798039123415947, -0.005186047405004501, 0.04085785150527954, -0.012974732555449009, 0.014261368662118912, 0.010168947279453278, 0.037700653076171875, 0.02585430257022381, -0.01828690618276596, -0.03246640786528587, 0.028061047196388245, 0.04854283854365349, -0.011447212658822536, 0.012283367104828358, -0.01033072266727686, -0.0048543051816523075, 0.019435545429587364, -0.04262728989124298, 0.068348728120327, 0.03211455047130585, -0.019141843542456627, 0.037280019372701645, -0.02626730129122734, 0.02679300680756569, 0.051262322813272476, 0.022979246452450752, 0.0016325564356520772, 0.005594688933342695, -0.004790238104760647, 0.030359342694282532, -0.0032820014748722315, 0.006006403360515833, 0.011444629170000553, 0.030608318746089935, -0.026512952521443367, 0.034044574946165085, 0.002185286721214652, -0.04803064465522766, 0.012256082147359848, -0.009162915870547295, -0.049456316977739334, 0.02603861875832081, -0.027815373614430428, 0.01905166171491146, 0.0012405728921294212, -0.006289280019700527, 0.02746322751045227, -0.011738787405192852, 0.003365312470123172, 0.03458221256732941, 0.041135139763355255, -0.009968183003365993, -0.008614437654614449, 0.01836566999554634, 0.03473503887653351, 0.002008423674851656, 0.044227320700883865, 0.04505915939807892, 0.03499160334467888, 0.06088320538401604, 0.029769551008939743, 0.024808449670672417, 0.0149460444226861, 0.017583061009645462, -0.002205267082899809, -0.050533100962638855, -0.03573337569832802, -0.00468122074380517, 0.030563930049538612, 0.007018235977739096, -0.019174419343471527, 0.02192838117480278, -0.019550224766135216, 0.03117123804986477, 0.021821577101945877, 0.013543225824832916, -0.03285904973745346, 0.024381550028920174, 0.04580943286418915, -0.0051757642067968845, 0.01800190657377243, -0.011421775445342064, 0.013297014869749546, -0.0023592349607497454, 0.05483600124716759, 0.004032887518405914, 0.012504440732300282, -0.03198846057057381, 0.0125581631436944, -0.016284573823213577, -0.024698877707123756, 0.0011123883305117488, 0.039031971246004105, -0.0069436198100447655, 0.005323352757841349, 0.013829389587044716, 0.03484345227479935, -0.01921439915895462, -0.0016254258807748556, 0.0033899149857461452, -0.006247083190828562, -0.04382969066500664, 0.01786213368177414, -0.04483557865023613, 0.05158086493611336, 0.0014893623301759362, -0.05096976459026337, -0.02448269911110401, 0.02731241099536419, 0.024809228256344795, 0.023222720250487328, 0.01698221080005169, 0.0171457901597023, -0.019444534555077553, 0.020770998671650887, 0.006935633718967438, 0.04261688515543938, -0.01206107810139656, 0.011658981442451477, 0.03291398286819458, 0.026994621381163597, 0.017297232523560524, 0.02321615256369114, 0.0055872914381325245, 0.008484802208840847, -0.019389845430850983, -0.007187793962657452, 0.018125571310520172, -0.039321500808000565, 0.04673776403069496, -0.019841361790895462, -0.009238950908184052, 0.01594444550573826, -0.0029305717907845974, 0.04578594118356705, 0.005048771388828754, 0.011690521612763405, -0.06919106841087341, 0.011888825334608555, -0.01748773455619812, -0.035613253712654114, 0.004797524772584438, 0.004034650512039661, 0.0001684833550825715, 0.02105576917529106, -0.008331649005413055, 0.031806036829948425, 0.008374884724617004, -0.00832670833915472, 0.004520700313150883, 0.01178752165287733, 0.013001950457692146, 0.0011561892461031675, 0.07480388879776001, 0.009662716649472713, 0.034307628870010376, 0.07229521870613098, -0.012300089932978153, 0.011226482689380646, 0.006066976580768824, -0.05130415037274361, -0.004627658054232597, 0.021438749507069588, -0.02335953712463379, -0.0489177331328392, -0.02894825115799904, 0.046958040446043015, -0.027385689318180084, 0.029811900109052658, -0.032152965664863586, -0.03802573308348656, -0.03650524467229843, -0.020208822563290596, -0.038910239934921265, 0.0019007570808753371, 0.028650330379605293, 0.08042606711387634, -0.008906694129109383, 0.04848681762814522, -0.05727038532495499, -0.026980813592672348, -0.039656758308410645, 0.024857353419065475, 0.055594552308321, 0.009731805883347988, 0.01643189787864685, -0.02832016907632351, 0.01002697553485632, -0.006875067483633757, -0.028142325580120087, -0.043883536010980606, 0.00486125098541379, 0.0029259228613227606, -0.06809963285923004, -0.01021755300462246, 0.05378900468349457, -0.002248124685138464, 0.022971058264374733, 0.013444731011986732, 0.02769327349960804, 0.00034393786336295307, -0.009059802629053593, -0.05590008571743965, -0.04620465636253357, -0.03310887888073921, 0.03115033730864525, -0.012072340585291386, -0.008617986924946308, -0.022834908217191696, 0.029260179027915, -0.03401235491037369, -0.0056677828542888165, -0.012631111778318882, 0.0000965017534326762, -0.04529464617371559, -0.002257641637697816, 0.03456893563270569, -0.06424490362405777, -0.06590323150157928, 0.042555514723062515, 0.02759886346757412, -0.023446733132004738, -0.009425710886716843, 0.005172974895685911, -0.02133176103234291, -0.00939426850527525, 0.01453578844666481, 0.010494424030184746, -0.0016441261395812035, 0.021637750789523125, -0.002333217067644, -0.004308614879846573, 0.023663105443120003 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Uploading models to s3 Once the conversion script did a complete job of porting all the required files totransformers, I uploaded the models to my 🤗 s3 account: ``` cd data transformers-cli upload -y wmt19-ru-en transformers-cli upload -y wmt19-en-ru transformers-cli upload -y wmt19-de-en transformers-cli upload -y wmt19-en-de cd - ``` For the duration of testing I was using my 🤗 s3 account and once my PR with the complete changes was ready to be merged I asked in the PR to move the models to thefacebookorganization account, since these models belong there. Several times I had to update just the config files, and I didn't want to re-upload the large models, so I wrote this little script that produces the right upload commands, which otherwise were too long to type and as a result were error-prone: ``` perl -le 'for $f (@ARGV) { print qq[transformers-cli upload -y $_/$f --filename $_/$f] \ for map { "wmt19-$_" } ("en-ru", "ru-en", "de-en", "en-de")}' \ vocab-src.json vocab-tgt.json tokenizer_config.json config.json # add/remove files as needed ``` So if, for example, I only needed to update all theconfig.jsonfiles, the script above gave me a convenient copy-n-paste: ``` transformers-cli upload -y wmt19-en-ru/config.json --filename wmt19-en-ru/config.json transformers-cli upload -y wmt19-ru-en/config.json --filename wmt19-ru-en/config.json transformers-cli upload -y wmt19-de-en/config.json --filename wmt19-de-en/config.json transformers-cli upload -y wmt19-en-de/config.json --filename wmt19-en-de/config.json ``` Once the upload was completed, these models could be accessed as (*): ``` tokenizer = FSMTTokenizer.from_pretrained("stas/wmt19-en-ru") ``` * footnote:stasis my username at https://huggingface.co. Before I made this upload I had to use the local path to the folder with the model files, e.g.: ``` tokenizer = FSMTTokenizer.from_pretrained("/code/huggingface/transformers-fair-wmt/data/wmt19-en-ru") ``` Important: If you update the model files, and re-upload them, you must be aware that due to CDN caching the uploaded model may be unavailable for up to 24 hours after the upload - i.e. the old cached model will be delivered. So the only way to start using the new model sooner is by either: 1. downloading it to a local path and using that path as an argument that gets passed tofrom_pretrained(). 2. or using:from_pretrained(..., use_cdn=False)everywhere for the next 24h - it's not enough to do it once.
[ -0.01624060422182083, 0.0641784742474556, -0.008519237861037254, 0.048967745155096054, 0.06381776928901672, 0.060487050563097, 0.00855147186666727, 0.040005967020988464, -0.004347591660916805, 0.046789903193712234, -0.01974487490952015, 0.036845795810222626, -0.024265708401799202, 0.03968577831983566, -0.033044829964637756, -0.003116140142083168, -0.03266863524913788, 0.03567564859986305, -0.032486606389284134, -0.019231200218200684, 0.005233383737504482, -0.09325766563415527, 0.05638061463832855, -0.022392872720956802, 0.020778171718120575, -0.051261816173791885, -0.02372092194855213, 0.052711013704538345, -0.006416983436793089, 0.049028750509023666, -0.06981457769870758, -0.034397292882204056, -0.040477454662323, -0.03223448619246483, -0.004110012669116259, 0.048349395394325256, -0.0671161338686943, 0.0293514896184206, 0.019329674541950226, -0.10563573241233826, 0.0035113978665322065, 0.0273900143802166, -0.058651868253946304, 0.027331572026014328, 0.06202155724167824, 0.017483944073319435, -0.13148514926433563, 0.06758362054824829, -0.021827245131134987, 0.022132188081741333, -0.021902957931160927, 0.07249212265014648, -0.007545995991677046, 0.005912245716899633, -0.014659714885056019, 0.04890307039022446, -0.0021381874103099108, -0.038357656449079514, 0.0054369582794606686, -0.01918294094502926, 0.03144340217113495, 0.02238275296986103, 0.057913731783628464, 0.013759229332208633, 0.004649936221539974, 0.013480941765010357, -0.03790438920259476, -0.009780903346836567, -0.046416670083999634, -0.07739144563674927, 0.03610885888338089, -0.027602093294262886, 0.051334578543901443, -0.08125970512628555, -0.01683332584798336, -0.050826188176870346, 0.049186211079359055, 0.037639070302248, 0.06338203698396683, 0.05756266415119171, 0.03880633786320686, 0.01627190038561821, -0.01365933008491993, 0.03546208143234253, 0.01635497808456421, -0.0008846168057061732, 0.06278640776872635, -0.08725535124540329, -0.045847952365875244, 0.04957135394215584, 0.03929905593395233, -0.11356408894062042, -0.08600987493991852, 0.07462595403194427, 0.129588782787323, 0.05165008828043938, -0.023832429200410843, -0.0011561585124582052, 0.011701679788529873, 0.011643425561487675, 0.03152848035097122, 0.02180706523358822, 0.04807063192129135, -0.07188257575035095, -0.019496027380228043, 0.02411038428544998, -0.011254760436713696, -0.10798405110836029, 0.03758518770337105, -0.005077376030385494, 0.04742945730686188, 0.00818713940680027, 0.024427082389593124, -0.023465098813176155, -0.0016935018356889486, -0.019943740218877792, 0.015424507670104504, -0.0672650933265686, 0.0028311777859926224, 0.09499402344226837, 0.03272409737110138, 0.08476641774177551, 0.05954838544130325, -0.03870715573430061, 0.02422773838043213, 0.042185403406620026, 0.08988537639379501, -0.022779205814003944, -0.02417302131652832, -0.06595928966999054, 0.05163184180855751, 0.023652585223317146, 0.07693973183631897, 0.036360807716846466, 0.024622701108455658, -0.08121293038129807, -0.01971890591084957, 0.011102534830570221, 0.03096887655556202, 0.01244910154491663, 0.036581289023160934, 0.07539517432451248, -0.0457279309630394, 0.02226157858967781, 0.013831378892064095, 0.03574914485216141, -0.06142643466591835, 0.05330391600728035, 0.017229583114385605, 0.05529165267944336, -0.054214827716350555, 0.05564790219068527, -0.02373722568154335, -0.04706345498561859, 0.05045728385448456, 0.08402512967586517, 0.010768572799861431, 0.0072924429550766945, -0.08850061893463135, -0.02337229810655117, -0.03149985149502754, 0.03541315719485283, -0.013407410122454166, -0.005650736857205629, 0.01696852035820484, -0.09762166440486908, 0.024441365152597427, 0.007454740349203348, 0.08063456416130066, -0.04312623292207718, 0.0034533021971583366, -0.050211187452077866, 0.07390172779560089, 0.04846470430493355, 0.012680907733738422, 0.02861133962869644, 0.027465417981147766, 0.06524025648832321, -0.01843472197651863, -0.052889302372932434, -0.024685345590114594, 0.06672624498605728, -0.024354523047804832, 0.02482873946428299, 0.0157487615942955, -0.026846574619412422, 0.004903588909655809, 0.0011968022445216775, -0.03233936429023743, 0.017307506874203682, 0.00005948493708274327, -0.06901485472917557, 0.10830811411142349, 0.006396244280040264, 0.03696621581912041, 0.05961659178137779, -0.04033505916595459, 0.10199202597141266, 0.010945317335426807, 0.0596637949347496, -0.08135175704956055, 0.004461652133613825, 0.03127293661236763, -0.05289282649755478, 0.014057924970984459, 0.08111482113599777, 0.008410794660449028, -0.009349704720079899, 0.015173288993537426, 0.024127056822180748, 0.04757492244243622, -0.021463142707943916, 0.01929062232375145, -0.061292968690395355, -0.050544336438179016, -0.07845884561538696, -0.0432782918214798, -0.03410041704773903, -0.045592885464429855, -0.009952573105692863, 0.15801656246185303, 0.036696892231702805, 0.008797950111329556, -0.06419285386800766, -0.0132588567212224, 0.0007233665091916919, 0.012957373633980751, 0.0368444100022316, 0.08308804035186768, -0.05772430822253227, -0.006970142014324665, -0.014387578703463078, -0.058346375823020935, -0.020767249166965485, -0.014319192618131638, 0.016013676300644875, -0.031044527888298035, -0.043477755039930344, -0.027676288038492203, 0.024280935525894165, 0.03878847137093544, -0.01607593521475792, 0.03908771649003029, 0.012104891240596771, 0.019863799214363098, 0.015417681075632572, 0.059564970433712006, -0.03412122279405594, -0.0052206446416676044, 0.03825942054390907, -0.08414590358734131, 0.038858965039253235, -0.0005894876667298377, -0.05295649915933609, 0.11316709965467453, 0.018828559666872025, -0.023131776601076126, -0.0009198181796818972, 0.0017282047774642706, 0.05791556462645531, -0.041055828332901, 0.04075278341770172, -0.032459959387779236, -0.028641903772950172, -0.004615254700183868, -0.015331704169511795, -0.008040948770940304, -0.008567946963012218, -0.0064649130217731, -0.02321460098028183, 0.004330714698880911, -0.0019564321264624596, 0.01449209451675415, 0.011653685010969639, 0.009600946679711342, 0.01903577148914337, 0.03838609904050827, -0.01970234513282776, -0.02014811523258686, 0.009813357144594193, 0.013598943129181862, -0.012913295067846775, 0.0018455478129908442, 0.0071259960532188416, 0.012410151772201061, 0.018949046730995178, 0.021004628390073776, -0.058835387229919434, -0.01624133437871933, -0.002749768551439047, 0.0336967334151268, -0.022815702483057976, 0.01294462289661169, 0.0044733271934092045, -0.023427868261933327, -0.00818692333996296, -0.012921808287501335, -0.035784609615802765, -0.004623796790838242, 0.07038699090480804, -0.007646592333912849, 0.001764889108017087, 0.01169573049992323, -0.025166576728224754, -0.050002072006464005, 0.017950793728232384, 0.016744663938879967, 0.005111074075102806, -0.09499682486057281, -0.02750125527381897, -0.005969097372144461, 0.012449237518012524, 0.008688736706972122, 0.006368953734636307, 0.028542380779981613, -0.018676623702049255, 0.003078050445765257, 0.06694631278514862, 0.044293805956840515, 0.018332188948988914, 0.019608590751886368, 0.03852834925055504, -0.00920731108635664, -0.014803447760641575, -0.014187609776854515, 0.03345543146133423, 0.017824027687311172, 0.0038918224163353443, -0.04481898248195648, -0.03745894134044647, -0.0060044885613024235, -0.0051456019282341, 0.009721720591187477, 0.0029219859279692173, 0.04892369732260704, -0.013648551888763905, -0.009313567541539669, -0.05347084999084473, 0.002406685845926404, -0.00946615170687437, 0.005513178184628487, -0.022483529523015022, -0.06187216192483902, -0.023900017142295837, 0.02895589917898178, 0.02731150947511196, 0.013615826144814491, -0.00567995011806488, 0.0036459174007177353, -0.01353661622852087, 0.01131737045943737, -0.002575821476057172, 0.029061993584036827, -0.01986822485923767, 0.015103149227797985, 0.01141050923615694, 0.013518008403480053, 0.020999813452363014, -0.010303262621164322, -0.02881663292646408, 0.01827607862651348, 0.0056079174391925335, 0.004426409024745226, -0.003633851883932948, -0.01878524199128151, 0.03215716406702995, 0.010219126008450985, -0.025246603414416313, -0.010916478000581264, 0.0014525457518175244, -0.0194089338183403, -0.03709385544061661, -0.030726101249456406, 0.04795979708433151, -0.000622135354205966, 0.0195503830909729, 0.026115085929632187, 0.03076295740902424, 0.022402098402380943, -0.0007380328024737537, -0.025609580799937248, -0.004146273247897625, -0.03669852390885353, -0.020540989935398102, -0.06069725379347801, -0.017738912254571915, -0.010071813128888607, 0.007368805352598429, -0.041454821825027466, 0.004347522743046284, -0.047526754438877106, -0.0073662977665662766, 0.008169814944267273, 0.01735628768801689, 0.020702466368675232, -0.029293930158019066, -0.0002079713885905221, 0.022381683811545372, -0.0031456020660698414, -0.03372631222009659, -0.030854588374495506, -0.029169389978051186, -0.014915857464075089, -0.06528415530920029, 0.03538201004266739, -0.021831417456269264, -0.022359002381563187, -0.016400594264268875, 0.015566867776215076, -0.07045083492994308, -0.010571438819169998, -0.028126310557127, -0.030458539724349976, -0.022176358848810196, -0.01690916158258915, -0.006749039515852928, 0.01116209290921688, 0.04570014029741287, 0.059595245867967606, -0.01921211928129196, -0.015400689095258713, -0.01893308386206627, -0.00489884102717042, 0.03520236909389496, -0.014898736029863358, -0.05560534447431564, -0.02343478612601757, 0.041036926209926605, -0.029867535457015038, 0.003995339386165142, 0.011843479238450527, -0.006827584933489561, -0.004198720678687096, 0.002813227940350771, 0.04850590229034424, 0.061189308762550354, -0.0396946482360363, -0.030849982053041458, -0.04988439753651619, -0.009361010044813156, 0.050230227410793304, 0.01167237851768732, 0.014353714883327484, 0.03920116648077965, -0.01432772632688284, 0.02478092536330223, 0.04634273424744606, 0.02965943142771721, -0.04706130921840668, 0.007957818917930126, 0.008845029398798943, -0.03982864320278168, 0.0091844592243433, -0.008599466644227505, -0.03198765590786934, 0.014896140433847904, -0.00699654733762145, 0.013817104510962963, 0.028434379026293755, -0.011769179254770279, -0.04043343663215637, -0.02508276328444481, 0.02908489853143692, 0.0020731904078274965, 0.02585378848016262, -0.03313787654042244, 0.015579840168356895, 0.05418388545513153, 0.016446854919195175, 0.0094160670414567, -0.037767767906188965, -0.003048318438231945, 0.032502684742212296, 0.025453966110944748, 0.00862982776015997, -0.09200381487607956, -0.003027460305020213, 0.022637328132987022, -0.0297345370054245, 0.003999745007604361, 0.02376660704612732, -0.03392431512475014, 0.015058685094118118, 0.0360724963247776, -0.023945333436131477, 0.03021274320781231, 0.002386766253039241, 0.013107137754559517, -0.0326257199048996, -0.010680677369236946, 0.007512603420764208, -0.034277115017175674, -0.021413875743746758, 0.022090299054980278, 0.07586226612329483, 0.08519193530082703, -0.04351308196783066, 0.00248516327701509, 0.004793667234480381, -0.004558904096484184, 0.003919963724911213, -0.049589842557907104, -0.005127777345478535, -0.014327981509268284, 0.023247217759490013, 0.018056711181998253, 0.025727003812789917, 0.022781990468502045, 0.04189009219408035, 0.06798607856035233, -0.00125316740013659, -0.015235778875648975, -0.016369299963116646, -0.015562900342047215, 0.0015581075567752123, 0.0005761382635682821, 0.0006569268880411983, -0.004019526299089193, 0.0028676867950707674, 0.007241433952003717, 0.022708453238010406, -0.0012453468516469002, -0.00043377751717343926, -0.04688289761543274, 0.020392797887325287, 0.004659281112253666, 0.027553100138902664, 0.038984667509794235, 0.02074534259736538, -0.0011064644204452634, -0.0019599017687141895, 0.03927609324455261, 0.03872913122177124, -0.015189110301434994, 0.01090689655393362, 0.010336754843592644, -0.004501288291066885, -0.01212702039629221, 0.018122419714927673, -0.01664939895272255, -0.0037559124175459146, 0.010975898243486881, 0.04257119819521904, -0.032068900763988495, -0.0037146948743611574, 0.060637470334768295, 0.018908461555838585, -0.040983885526657104, 0.022572550922632217, -0.028260262683033943, -0.058346379548311234, 0.028477638959884644, -0.009205551818013191, -0.012962657026946545, 0.03539145737886429, -0.0018105875933542848, -0.014623823575675488, 0.008219361305236816, -0.01064555998891592, 0.014646600931882858, 0.019051123410463333, 0.000596894882619381, 0.004714882466942072, 0.026430606842041016, -0.006607390474528074, 0.03869420289993286, -0.020431257784366608, -0.049084000289440155, 0.06085656210780144, -0.029127199202775955, -0.034681178629398346, 0.016390183940529823, 0.01578696072101593, -0.018576301634311676, 0.008712849579751492, -0.046080637723207474, -0.012739190831780434, 0.014391441829502583, 0.013353214599192142, 0.04176519438624382, -0.022416340187191963, 0.0074277292005717754, -0.036250531673431396, -0.0036560732405632734, 0.0635916218161583, 0.013855049386620522, -0.013453733175992966, 0.031754475086927414, -0.015860367566347122, 0.049065954983234406, 0.024361511692404747, -0.0032169497571885586, 0.015223316848278046, 0.021486345678567886, 0.03145919740200043, -0.017962029203772545, 0.010740891098976135, 0.02541526034474373, 0.015915127471089363, -0.03119131177663803, -0.0739799216389656, -0.005826851353049278, -0.034308962523937225, 0.03411644324660301, -0.023336945101618767, -0.018103839829564095, -0.01473256852477789, -0.02958577498793602, 0.04597891867160797, -0.02411462739109993, 0.031160760670900345, -0.03784727305173874, 0.0468607097864151, 0.027255786582827568, 0.002150164917111397, 0.05978507921099663, 0.03490893542766571, 0.023475462570786476, -0.030938519164919853, 0.04719493165612221, -0.013383405283093452, 0.03368017449975014, 0.010318133980035782, -0.018008485436439514, 0.03691821172833443, -0.04889657720923424, -0.04215443506836891, 0.049560122191905975, 0.012554998509585857, -0.010328208096325397, -0.04904942587018013, 0.04772955924272537, 0.0004549459263216704, 0.010709608905017376, 0.01126184593886137, -0.00634697824716568, -0.052330248057842255, -0.06401656568050385, 0.009968536905944347, -0.005333662498742342, -0.05502121523022652, -0.03820916637778282, -0.026744572445750237, 0.004624766297638416, 0.04076186940073967, 0.0027102509047836065, 0.018993893638253212, -0.011647311970591545, -0.05265287309885025, 0.032120924443006516, -0.04087236523628235, 0.005899718962609768, 0.01076623983681202, -0.01000751182436943, 0.0012073272373527288, -0.0022988468408584595, -0.004843440838158131, 0.03433998301625252, 0.0030811866745352745, 0.0261714868247509, -0.01554088480770588, -0.007219432387501001, -0.003841985482722521, -0.020288320258259773, 0.008283770643174648, -0.029631931334733963, -0.019300997257232666, -0.004655304830521345, 0.048746731132268906, 0.03434496000409126, 0.0012352828634902835, -0.03196154534816742, 0.018283260986208916, -0.008970120921730995, -0.007035059854388237, 0.010410419665277004, 0.023761538788676262, -0.032387662678956985, -0.01398364920169115, 0.008142433129251003, -0.04605080187320709, 0.011824066750705242, 0.002259771339595318, -0.04779133200645447, 0.03596612066030502, -0.013136105611920357, 0.017348354682326317, -0.008550386875867844, 0.05137651041150093, 0.027589023113250732, 0.014837093651294708, -0.04186085984110832, 0.03836796060204506, 0.022181013599038124, 0.002319169230759144, 0.0021895121317356825, 0.03406656160950661, -0.0002103264123434201, -0.029223022982478142, -0.060983769595623016, -0.025703778490424156, -0.013444754295051098, -0.039309311658144, 0.02357981540262699, -0.07138925045728683, 0.019006995484232903, -0.028658080846071243, -0.049892716109752655, -0.0017532550264149904, 0.02513359859585762, 0.030870843678712845, 0.012082955799996853, 0.00916382484138012, -0.01866021752357483, -0.035278212279081345, 0.0050193509086966515, -0.02606693096458912, 0.04436641186475754, 0.015853293240070343, 0.03334791585803032, 0.011492205783724785, -0.030684852972626686, 0.05501822382211685, -0.036392197012901306, -0.052947577089071274, 0.004912109114229679, 0.026189018040895462, 0.014594334177672863, -0.05009729787707329, -0.0061990730464458466, 0.03643424063920975, 0.010911677032709122, 0.013054372742772102, 0.008349996991455555, -0.03706245496869087, -0.018827665597200394, -0.01874558813869953, -0.07025714963674545, 0.016050808131694794, 0.01146810781210661, -0.008959094062447548, 0.0344616137444973, 0.01749308779835701, -0.0115582924336195, -0.006758035160601139, -0.042594023048877716, 0.05586520954966545, -0.014114119112491608, -0.03981753811240196, -0.034466881304979324, 0.0025120736099779606, 0.020229220390319824, -0.027373485267162323, -0.03513595834374428, 0.02330845221877098, -0.02525186352431774, -0.010559952817857265, -0.021147582679986954, -0.010209742933511734, -0.05690809711813927, -0.029713207855820656, -0.054909493774175644, -0.05098852887749672, -0.02966168336570263, 0.0016005616635084152, -0.016815809532999992, 0.005946958437561989, 0.005033429712057114 ]
Porting fairseq wmt19 translation system to transformers
stas
November 3, 2020
porting-fsmt
open-source-collab, nlp
https://huggingface.co/blog/porting-fsmt
Appreciations - Having [Sam Shleifer](https://github.com/sshleifer) mentor me through this process was of an extreme help to me, both thanks to his technical support and just as importantly for inspiring and encouraging me when I was getting stuck. - The PR merging process took a good couple of weeks before it was accepted. During this stage, besides Sam, [Lysandre Debut](https://github.com/LysandreJik) and [Sylvain Gugger](https://github.com/sgugger) contributed a lot through their insights and suggestions, which I integrating into the codebase. - I'm grateful to everybody who has contributed to thetransformerscodebase, which paved the way for my work.
[ 0.07482969760894775, 0.03913552686572075, 0.013732768595218658, 0.03720434010028839, 0.04602671042084694, 0.11660321801900864, 0.006545632611960173, 0.08163726329803467, -0.0033212185371667147, -0.057051267474889755, -0.0035161126870661974, 0.012892619706690311, 0.029586855322122574, 0.011918536387383938, -0.016408737748861313, -0.017263848334550858, 0.034332793205976486, -0.05417852848768234, -0.0075403843075037, 0.017806606367230415, -0.035191379487514496, -0.03918423876166344, -0.02896747924387455, -0.0035267090424895287, -0.0015730597078800201, -0.025383301079273224, -0.024446673691272736, 0.026266762986779213, 0.009319893084466457, 0.022959282621741295, -0.005819509271532297, -0.04989614337682724, -0.02110362984240055, -0.06833988428115845, -0.05983655899763107, -0.0010132157476618886, -0.06539107859134674, 0.03884946182370186, 0.07500657439231873, -0.08470658957958221, 0.01123348344117403, -0.03882643207907677, -0.08458098769187927, 0.047869205474853516, -0.017427871003746986, -0.012032703496515751, -0.11716767400503159, 0.09625652432441711, -0.030496401712298393, -0.024327432736754417, -0.053612276911735535, 0.05851146951317787, 0.004288192372769117, 0.042739640921354294, -0.0007435668376274407, 0.013488837517797947, 0.037321895360946655, -0.03505750745534897, 0.001839867327362299, 0.005766802001744509, 0.027867186814546585, -0.024365821853280067, 0.05528062582015991, 0.06225401163101196, 0.043833181262016296, 0.01282657589763403, -0.008364688605070114, 0.01899351365864277, -0.03010665252804756, -0.011175931431353092, 0.05744427815079689, -0.05718280002474785, -0.005845797713845968, -0.011642307974398136, 0.016177309677004814, -0.035061441361904144, 0.045959923416376114, 0.09845812618732452, 0.030525967478752136, 0.021647784858942032, -0.012274067848920822, 0.020328395068645477, -0.021658938378095627, 0.09359868615865707, 0.0694505125284195, 0.05795612931251526, 0.09400521963834763, -0.09620018303394318, -0.07265231013298035, -0.025607813149690628, -0.015909012407064438, -0.1189345046877861, -0.004854592494666576, 0.03921123221516609, 0.04824843257665634, -0.060484789311885834, 0.04517856612801552, 0.020661810413002968, 0.0056129684671759605, -0.06447086483240128, -0.04135379195213318, 0.06270559877157211, -0.02939349226653576, -0.05914635583758354, 0.007860513404011726, 0.03683020919561386, -0.05776738375425339, -0.05738997086882591, -0.013025670312345028, 0.021553710103034973, -0.008571618236601353, 0.09706654399633408, 0.007051170337945223, 0.07531889528036118, -0.04873761907219887, 0.08526762574911118, 0.004979748744517565, -0.08227856457233429, 0.0038534305058419704, 0.000057584704336477444, 0.042359307408332825, 0.040040574967861176, 0.015431891195476055, 0.0612625814974308, 0.029915090650320053, 0.01416022703051567, 0.02304994687438011, 0.037049829959869385, -0.04761600121855736, -0.03285570070147514, -0.053656648844480515, -0.022912096232175827, 0.027252711355686188, 0.010661029256880283, -0.05818774923682213, -0.00985119491815567, 0.005398155190050602, -0.026842335239052773, -0.03281182795763016, -0.005338376387953758, -0.019320456311106682, 0.0811639279127121, -0.08439091593027115, 0.04338822886347771, -0.00836058147251606, -0.01759287901222706, -0.11806047707796097, 0.009802348911762238, 0.014991233125329018, 0.019511548802256584, -0.016549216583371162, 0.02150832489132881, -0.11191952973604202, -0.020843060687184334, -0.004257826134562492, 0.0948166772723198, 0.03549192473292351, -0.021082798019051552, -0.019451091066002846, 0.06291112303733826, 0.04135169833898544, 0.040579747408628464, -0.02564404159784317, 0.001632762374356389, 0.036548975855112076, -0.04063696041703224, -0.053452543914318085, -0.024105336517095566, -0.03705032169818878, -0.04690869152545929, 0.030386997386813164, -0.001402994617819786, 0.023700213059782982, 0.01201502326875925, -0.012802052311599255, 0.09094467014074326, 0.09084467589855194, 0.046219948679208755, 0.04942996799945831, -0.07391183823347092, -0.009007430635392666, 0.020084494724869728, 0.00879677850753069, 0.021244511008262634, -0.040443435311317444, -0.04698638617992401, 0.044861599802970886, 0.017583969980478287, 0.016779065132141113, 0.036888450384140015, -0.08061910420656204, 0.007705175783485174, 0.10214502364397049, -0.040700361132621765, -0.013750607147812843, -0.012034597806632519, -0.008527104742825031, 0.11419732123613358, 0.03271589055657387, 0.07587267458438873, 0.04639219492673874, -0.00499962130561471, 0.06529957801103592, -0.018938591703772545, 0.03643297776579857, 0.06113399192690849, 0.07881101220846176, -0.02545178309082985, 0.003839361248537898, 0.05690468102693558, 0.012229192070662975, -0.01769839972257614, 0.0934036448597908, -0.0764041319489479, 0.035080716013908386, -0.043446093797683716, 0.018358569592237473, -0.08788801729679108, 0.0007846799562685192, 0.01211638655513525, 0.13134777545928955, -0.026772135868668556, -0.024508504197001457, 0.039367396384477615, 0.049864981323480606, 0.07590346038341522, 0.05040839686989784, 0.01026314590126276, 0.042538680136203766, 0.006861493457108736, -0.024991801008582115, 0.017031298950314522, -0.06211630254983902, -0.039180003106594086, 0.010860171169042587, -0.06907788664102554, -0.06471653282642365, -0.07973504066467285, -0.03295538201928139, -0.0001983019319595769, -0.004832331091165543, 0.007829221896827221, 0.013280073180794716, 0.017057863995432854, -0.06061051785945892, -0.051781706511974335, 0.06020732969045639, -0.009458868764340878, -0.007206408306956291, 0.03126206248998642, -0.02030020020902157, 0.0392865389585495, 0.01267688162624836, -0.04079371318221092, 0.04718807339668274, -0.048719972372055054, -0.00720204459503293, -0.01908276602625847, 0.00007072250446071848, 0.030915318056941032, -0.015031327493488789, -0.005693197250366211, -0.027073899284005165, -0.003058843547478318, 0.00005720366971218027, 0.009119176305830479, -0.008222261443734169, 0.0042740157805383205, 0.0008144780294969678, -0.003916076850146055, -0.00898555014282465, 0.002809788566082716, 0.024428846314549446, 0.024112390354275703, 0.012208985164761543, -0.01896621100604534, 0.02386527508497238, 0.009035438299179077, -0.016261538490653038, -0.023350045084953308, -0.026241032406687737, -0.043742746114730835, -0.00000580417054152349, 0.016187163069844246, 0.014274894259870052, 0.002828122116625309, -0.03554883971810341, -0.026428785175085068, -0.006008248310536146, 0.01269494742155075, 0.028252139687538147, -0.007820473983883858, -0.006741977762430906, 0.016157401725649834, 0.05686429888010025, -0.0455409474670887, -0.004725470673292875, -0.04750170186161995, -0.05328268185257912, 0.02132137306034565, 0.00019804424664471298, 0.018613243475556374, 0.012099726125597954, -0.00220375950448215, -0.017504796385765076, -0.010673156008124352, 0.005737467668950558, 0.013381884433329105, -0.1031690239906311, -0.019927211105823517, 0.007755293045192957, -0.017862627282738686, 0.014124392531812191, -0.017710119485855103, 0.03420764580368996, -0.0617622472345829, -0.016806095838546753, -0.010586162097752094, 0.0019875711295753717, -0.028929566964507103, -0.04311537742614746, 0.003023608587682247, -0.019483400508761406, -0.0299750454723835, -0.027057986706495285, 0.019431445747613907, -0.002006287919357419, 0.004553304519504309, -0.046760767698287964, 0.00928737036883831, -0.004360993392765522, -0.004790586419403553, -0.011565692722797394, 0.006114141084253788, 0.010042172856628895, 0.005966460332274437, -0.007941256277263165, -0.06436917185783386, -0.001365058240480721, 0.017765572294592857, -0.010911288671195507, 0.01416379027068615, -0.053102556616067886, 0.015043633989989758, 0.006505111698061228, 0.024319054558873177, -0.012872396036982536, 0.015280392952263355, 0.00669035455211997, 0.01947949267923832, 0.02822735160589218, 0.012274921871721745, 0.022477557882666588, -0.04963395744562149, 0.005761737935245037, 0.027243420481681824, 0.06875882297754288, 0.02672511897981167, 0.0062959762290120125, 0.023441340774297714, 0.004185003694146872, 0.06585709750652313, 0.04250621050596237, 0.012141072191298008, 0.018372777849435806, -0.03176983818411827, -0.0022542544174939394, 0.02220338210463524, 0.0013967729173600674, 0.009666262194514275, 0.0280333012342453, -0.03677831590175629, -0.0038782265037298203, 0.04283062368631363, 0.004838262218981981, 0.007988803088665009, -0.03996456041932106, 0.006838398985564709, 0.04927908256649971, 0.022137435153126717, -0.00888148508965969, -0.005276711191982031, 0.012360240332782269, -0.03172232583165169, -0.0806044340133667, -0.033662501722574234, 0.036978207528591156, 0.030490096658468246, -0.03216692432761192, -0.023769289255142212, -0.026264270767569542, -0.028048934414982796, -0.022310229018330574, 0.038704466074705124, 0.009571561589837074, -0.0012284747790545225, 0.008486252278089523, 0.04861636459827423, -0.013588850386440754, -0.03166443854570389, -0.041432205587625504, -0.010704142972826958, -0.028216907754540443, -0.0015155414585024118, 0.03395341336727142, 0.04433053731918335, 0.008049700409173965, -0.010403799824416637, 0.009760696440935135, -0.010600687004625797, -0.022605864331126213, 0.010980501770973206, 0.0009423951269127429, 0.050695184618234634, -0.05936993658542633, -0.06765672564506531, 0.008662659674882889, 0.02991388365626335, 0.04224114492535591, -0.007471733260899782, 0.003376806154847145, -0.0032232266385108232, 0.00628929166123271, 0.02676106058061123, 0.0001392020785715431, -0.03281253203749657, -0.03228963911533356, 0.032573144882917404, -0.029773037880659103, -0.032519642263650894, 0.010474534705281258, 0.04433869943022728, -0.005712395533919334, -0.011593726463615894, -0.006834124214947224, -0.03127255663275719, -0.02334573306143284, 0.007146631833165884, -0.016379429027438164, -0.03512657806277275, -0.01125914603471756, -0.037723999470472336, -0.012587340548634529, 0.029617490246891975, 0.016230905428528786, 0.02892652526497841, -0.051782768219709396, -0.04464397951960564, -0.005315094254910946, 0.03191802650690079, 0.04171032831072807, -0.022588660940527916, 0.014275521039962769, -0.011739173904061317, 0.0071243359707295895, 0.006356266792863607, -0.007883336395025253, 0.035248562693595886, -0.009824004024267197, -0.05598650872707367, -0.023074964061379433, 0.07137896120548248, 0.009977417066693306, -0.019956355914473534, -0.018160127103328705, 0.001860597636550665, -0.0008270003600046039, 0.013014598749577999, -0.01411659549921751, -0.008646909147500992, -0.0388617217540741, 0.03259385749697685, 0.006979554891586304, -0.0018482019659131765, -0.01301344484090805, -0.030623678117990494, -0.011102051474153996, -0.015442953445017338, -0.025830809026956558, 0.004229167476296425, 0.030478131026029587, -0.027382057160139084, 0.03278817608952522, 0.04107026383280754, 0.01220815908163786, -0.008445343933999538, -0.0027751775924116373, 0.02166530303657055, -0.024554770439863205, -0.0016406362410634756, 0.009977118112146854, -0.019856657832860947, 0.025350358337163925, -0.018917245790362358, 0.060380805283784866, -0.021560778841376305, -0.03125109523534775, 0.039524272084236145, -0.013845759443938732, -0.0034251532051712275, -0.06358776241540909, 0.04696860536932945, -0.018427886068820953, 0.0032168622128665447, -0.019758064299821854, -0.016449060291051865, -0.03650689497590065, -0.016403937712311745, 0.0756249651312828, 0.04233498126268387, -0.005277570802718401, 0.02521028369665146, -0.011620164848864079, 0.02514914609491825, 0.03519483283162117, 0.015214826911687851, 0.03296128660440445, -0.04578031972050667, -0.01149115338921547, 0.0020052799955010414, 0.0321970209479332, 0.007223585154861212, -0.012931116856634617, -0.04215780273079872, 0.027748243883252144, 0.02213463932275772, -0.024899249896407127, 0.03758237883448601, 0.04254511743783951, 0.018811680376529694, -0.02402745932340622, 0.021792737767100334, 0.008780010975897312, -0.035442329943180084, -0.021756978705525398, 0.025482384487986565, -0.03240421786904335, 0.0020676208660006523, 0.02628147602081299, -0.02378806471824646, -0.011148774065077305, 0.015834394842386246, -0.03244653344154358, 0.0009161661728285253, -0.03641209006309509, 0.006829009857028723, 0.01178919430822134, -0.025434527546167374, -0.031180938705801964, -0.04110347852110863, -0.03259633854031563, 0.0030369614250957966, -0.010561545379459858, 0.043992601335048676, 0.02312053181231022, 0.0005742539069615304, 0.025129001587629318, 0.003205246524885297, 0.022954316809773445, 0.0337955504655838, -0.007324279751628637, 0.005585364997386932, 0.0002034555363934487, 0.030646327883005142, -0.03197340667247772, 0.016890736296772957, 0.05363158881664276, -0.032692741602659225, 0.0213793758302927, -0.02608647383749485, -0.022031983360648155, 0.036575306206941605, -0.025422321632504463, -0.010796899907290936, 0.01650211028754711, -0.03404161334037781, 0.00294565805234015, 0.010141778737306595, -0.036466989666223526, 0.003317219903692603, 0.06290502846240997, 0.017093975096940994, -0.02093273214995861, -0.06190860643982887, 0.07042253017425537, -0.006622075568884611, 0.0068977149203419685, -0.014063075184822083, 0.05714987963438034, 0.04602188244462013, 0.06654683500528336, 0.018388986587524414, 0.024026893079280853, 0.018396759405732155, 0.07803168892860413, -0.01964453049004078, 0.022083155810832977, 0.038857653737068176, -0.0177942905575037, 0.002305900678038597, -0.003946539480239153, -0.02206714265048504, -0.029828712344169617, -0.014455689117312431, 0.012251828797161579, -0.0020687710493803024, 0.006448779720813036, 0.017430098727345467, 0.0455017052590847, -0.02755550853908062, 0.0444011427462101, 0.03225107863545418, -0.014151142910122871, 0.048797909170389175, -0.008465342223644257, 0.03173113986849785, 0.02384253963828087, -0.022651685401797295, -0.014934270642697811, -0.027432512491941452, -0.023968977853655815, 0.022555753588676453, -0.05955374985933304, -0.05240693688392639, 0.009006388485431671, -0.0017488764133304358, 0.021062806248664856, -0.03323008120059967, 0.020814653486013412, -0.02005673199892044, -0.025732150301337242, -0.023587167263031006, -0.018222877755761147, -0.003192685777321458, 0.01796727627515793, -0.009408845566213131, -0.026730448007583618, -0.030841372907161713, -0.0011410430306568742, 0.03490607440471649, -0.057448409497737885, -0.01680716872215271, 0.00025752035435289145, 0.017793670296669006, 0.00808695238083601, 0.03916841745376587, -0.03888062387704849, 0.023107750341296196, -0.028966009616851807, 0.03254912048578262, 0.012290721759200096, 0.04489034041762352, -0.037576235830783844, -0.000017579954146640375, 0.004163418896496296, 0.005795225966721773, -0.0043564834631979465, 0.008580578491091728, -0.006697143893688917, 0.009783966466784477, -0.041658125817775726, 0.015517085790634155, -0.042705029249191284, -0.014900034293532372, 0.005968572571873665, -0.024496065452694893, 0.02195609174668789, -0.007981425151228905, 0.05709820240736008, -0.0009062257595360279, 0.0127074234187603, -0.030278032645583153, -0.061159439384937286, -0.025115355849266052, 0.04313327372074127, -0.039473000913858414, 0.015305396169424057, -0.0055894129909574986, -0.041740793734788895, -0.0065032923594117165, -0.019855046644806862, 0.03879500925540924, 0.0076141078025102615, -0.010219218209385872, 0.06360190361738205, -0.028649963438510895, 0.010348879732191563, -0.0005502812564373016, 0.02813970297574997, 0.05217001214623451, 0.007502865511924028, 0.0056108711287379265, -0.014988996088504791, 0.03785001486539841, -0.06310515105724335, -0.00014102761633694172, 0.028802478685975075, 0.043719083070755005, 0.006633702665567398, -0.04481535404920578, -0.029784435406327248, 0.02935493178665638, -0.04700421169400215, 0.03123670630156994, -0.05899403244256973, 0.013253115117549896, 0.019845061004161835, 0.03353889659047127, 0.0004610648029483855, 0.022880790755152702, 0.03743419051170349, 0.018118906766176224, 0.01801077090203762, -0.019475508481264114, 0.02450075000524521, -0.05204836279153824, -0.011480304412543774, 0.02760603278875351, 0.03525982052087784, 0.04588298499584198, -0.016028448939323425, 0.027062421664595604, 0.030468255281448364, -0.05370999500155449, -0.047073401510715485, 0.009407317265868187, 0.03782646358013153, 0.01269264705479145, -0.014192367903888226, -0.013292253017425537, 0.039331160485744476, 0.04569138213992119, -0.007957763969898224, 0.005097166635096073, -0.062350329011678696, 0.01848607324063778, -0.01700334995985031, -0.04495485499501228, 0.009776873514056206, 0.037874069064855576, 0.013363570906221867, 0.012023227289319038, 0.014241358265280724, -0.010982862673699856, 0.02421676740050316, 0.0011528539471328259, -0.006889315787702799, 0.001635755063034594, -0.04466594383120537, 0.032428037375211716, -0.027585027739405632, 0.008134109899401665, -0.026184888556599617, -0.08160906285047531, 0.055735521018505096, -0.006521411705762148, -0.02437695488333702, -0.02827204391360283, -0.007169653195887804, -0.056702520698308945, -0.003157966071739793, 0.025145042687654495, -0.010667495429515839, 0.03907189145684242, 0.05044953152537346, -0.007667058613151312, 0.01742575317621231, 0.0029201675206422806 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
BERT BERT is an encoder-only model, which maps an input sequence \(\mathbf{X}{1:n}\) to a contextualized encoded sequence \(\mathbf{\overline{X}}{1:n}\): $$ f{\theta_{\text{BERT}}}: \mathbf{X}{1:n} \to \mathbf{\overline{X}}{1:n}. $$ BERT\'s contextualized encoded sequence \(\mathbf{\overline{X}}{1:n}\) can then further be processed by a classification layer for NLU classification tasks, such as sentiment analysis, natural language inference, etc. To do so, the classification layer, i.e. typically a pooling layer followed by a feed-forward layer, is added as a final layer on top of BERT to map the contextualized encoded sequence \(\mathbf{\overline{X}}{1:n}\) to a class \(c\): $$ f_{\theta{\text{p,c}}}: \mathbf{\overline{X}}{1:n} \to c. $$ It has been shown that adding a pooling- and classification layer, defined as \(\theta{\text{p,c}}\), on top of a pre-trained BERT model \(\theta_{\text{BERT}}\) and subsequently fine-tuning the complete model \({\theta_{\text{p,c}}, \theta_{\text{BERT}}}\) can yield state-of-the-art performances on a variety of NLU tasks, cf. to BERT by Devlin et al.. Let\'s visualize BERT. The BERT model is shown in grey. The model stacks multiple BERT blocks, each of which is composed of bi-directional self-attention layers (shown in the lower part of the red box) and two feed-forward layers (short in the upper part of the red box). Each BERT block makes use of bi-directional self-attention to process an input sequence \(\mathbf{x'}1, \ldots, \mathbf{x'}_n\) (shown in light grey) to a more \"refined\" contextualized output sequence \(\mathbf{x''}_1, \ldots, \mathbf{x''}_n\) (shown in slightly darker grey) \({}^4\). The contextualized output sequence of the final BERT block, i.e. \(\mathbf{\overline{X}}{1:n}\), can then be mapped to a single output class \(c\) by adding a task-specific classification layer (shown in orange) as explained above. Encoder-only models can only map an input sequence to an output sequence of a priori known output length. In conclusion, the output dimension does not depend on the input sequence, which makes it disadvantageous and impractical to use encoder-only models for sequence-to-sequence tasks. As for all encoder-only models, BERT\'s architecture corresponds exactly to the architecture of the encoder part of transformer-based encoder-decoder models as shown in the \"Encoder\" section in the Encoder-Decoder notebook.
[ 0.024381009861826897, -0.025651009753346443, 0.03946701064705849, -0.004534849431365728, 0.08459941297769547, 0.06511181592941284, -0.03637939319014549, 0.10050460696220398, -0.02678593434393406, -0.027368921786546707, -0.10974793881177902, 0.06058488041162491, -0.02202378213405609, 0.04287656396627426, -0.035258978605270386, 0.04806314408779144, 0.08075933158397675, -0.04131661728024483, -0.008579189889132977, -0.05179227516055107, -0.02402433380484581, -0.07939255982637405, 0.05645494908094406, -0.032033033668994904, 0.024646980687975883, -0.015431108884513378, 0.021538984030485153, -0.007522941567003727, -0.06797634810209274, 0.03819894790649414, -0.06065140664577484, 0.0013278614496812224, 0.02927333489060402, 0.015356047078967094, -0.017984401434659958, -0.01598738692700863, -0.0917467549443245, 0.025789571925997734, 0.029809951782226562, -0.042266592383384705, -0.041055113077163696, -0.03892742469906807, -0.07740186899900436, 0.05462857708334923, -0.04045351594686508, 0.01552069652825594, -0.16394516825675964, 0.08227560669183731, -0.04083140939474106, -0.01914999820291996, -0.10285532474517822, 0.008678832091391087, -0.04025125503540039, 0.07788063585758209, -0.04361883923411369, 0.02414168231189251, -0.017662139609456062, -0.037493087351322174, 0.04552847892045975, -0.02133847400546074, 0.011979084461927414, -0.0011490993201732635, 0.011146007105708122, 0.053296130150556564, 0.02391134575009346, 0.01836991496384144, -0.03473355248570442, 0.005790917202830315, -0.05520132929086685, 0.004618701059371233, -0.015520544722676277, -0.028555292636156082, -0.01207607053220272, 0.00548131950199604, 0.00578266941010952, -0.045448847115039825, 0.020640898495912552, -0.029373154044151306, 0.03677956014871597, -0.0049396720714867115, 0.044871509075164795, 0.02662470191717148, 0.004296616651117802, 0.10310449451208115, 0.027982797473669052, -0.02235032431781292, 0.08641447871923447, -0.07163674384355545, -0.027936628088355064, 0.06324759870767593, -0.08387544751167297, -0.15819792449474335, 0.0060300445184111595, -0.017127735540270805, 0.033539894968271255, -0.06987512856721878, 0.006428160704672337, 0.03862069174647331, 0.009310181252658367, 0.013174169696867466, 0.02371099404990673, -0.040629930794239044, 0.0530894473195076, -0.022330375388264656, -0.08588071167469025, 0.06002720445394516, 0.026165492832660675, -0.09603281319141388, -0.0607130229473114, -0.012228523381054401, 0.019700787961483, -0.028333529829978943, 0.0055357301607728004, 0.0641116350889206, -0.07942263782024384, -0.0035042911767959595, -0.010751374997198582, 0.008767498657107353, 0.04112229496240616, 0.015641409903764725, 0.00023920906824059784, 0.07502113282680511, 0.05200759321451187, -0.024360639974474907, 0.006463775411248207, 0.0371713861823082, -0.004433665424585342, -0.02832021564245224, -0.004563549533486366, -0.02215157449245453, 0.07838201522827148, 0.01909354329109192, 0.06857001781463623, 0.03253038600087166, -0.04942783713340759, -0.0010336044942960143, -0.0402846485376358, -0.09935791790485382, -0.0007761635351926088, -0.013144433498382568, -0.08005405962467194, 0.04212186112999916, -0.016617458313703537, 0.0018726425478234887, 0.05716198310256004, -0.022207660600543022, -0.07136224210262299, 0.06890594959259033, 0.004272789694368839, 0.03691306710243225, -0.04888390377163887, 0.00883552897721529, -0.016506871208548546, -0.04891237989068031, -0.0012841919669881463, 0.059504229575395584, 0.0311728585511446, -0.05640387162566185, -0.06619708240032196, -0.0088869733735919, 0.02004851959645748, 0.025589844211935997, 0.011622603051364422, 0.011156551539897919, 0.02924000844359398, -0.07954700291156769, 0.01762930117547512, 0.00535640399903059, -0.029224185273051262, 0.03371591493487358, 0.008858311921358109, -0.009835915639996529, 0.10347849130630493, 0.03702949360013008, -0.07056112587451935, 0.022488338872790337, 0.017303477972745895, 0.07586407661437988, -0.005494854412972927, -0.015727713704109192, -0.037998002022504807, 0.014444762840867043, 0.030958104878664017, -0.0035965421702712774, 0.039256416261196136, -0.06190270557999611, -0.00022754012024961412, -0.047469425946474075, -0.04840072989463806, 0.06595292687416077, -0.002557444619014859, 0.003717656945809722, 0.03009890951216221, -0.046333443373441696, 0.01896398514509201, -0.07180140167474747, -0.05820223316550255, 0.08990462869405746, 0.06016010418534279, 0.017019659280776978, 0.08061852306127548, 0.02016632817685604, 0.035600267350673676, 0.019062675535678864, 0.007625708356499672, 0.019229339435696602, -0.0027147161308676004, -0.017866576090455055, 0.08131670206785202, -0.05784927308559418, 0.000985965016297996, -0.09326694905757904, -0.01122122909873724, -0.06130079925060272, -0.009853821247816086, -0.06981367617845535, -0.015322314575314522, 0.01678840070962906, -0.019616378471255302, -0.009585768915712833, 0.1683373749256134, -0.051824621856212616, -0.04120178520679474, -0.03533778712153435, 0.006067595910280943, -0.005864684469997883, 0.06690911203622818, -0.02153567224740982, 0.09648740291595459, -0.04511015862226486, -0.061627939343452454, -0.020433390513062477, 0.04336380586028099, -0.01008088793605566, -0.04440677911043167, -0.024424832314252853, -0.0361618846654892, 0.0003208909183740616, 0.043239329010248184, -0.06239726021885872, -0.020483914762735367, 0.013395083136856556, 0.017835186794400215, 0.057358115911483765, -0.0610027052462101, -0.01918039470911026, 0.01593472808599472, 0.02734869159758091, -0.029096156358718872, 0.010263517498970032, -0.0812285989522934, 0.05080507695674896, -0.0405769906938076, -0.09626144915819168, -0.010382949374616146, 0.08146982640028, -0.02304220013320446, -0.02084953896701336, 0.0096410121768713, 0.006685991771519184, -0.01858302392065525, -0.03913765400648117, -0.027261968702077866, -0.047313716262578964, -0.019470898434519768, -0.023606818169355392, -0.004578044172376394, 0.043344948440790176, 0.017450422048568726, 0.05891266092658043, -0.00125628721434623, -0.0034404946491122246, 0.017818499356508255, 0.04007094353437424, 0.03523758053779602, 0.025129854679107666, 0.031082337722182274, -0.048009343445301056, -0.029437948018312454, -0.017480531707406044, -0.026205824688076973, -0.02410171367228031, 0.053150929510593414, 0.028466610237956047, -0.008217643946409225, 0.0206527728587389, -0.015423838049173355, -0.04024990275502205, -0.0018379497341811657, 0.013373944908380508, 0.028628157451748848, 0.036656029522418976, -0.014924254268407822, -0.035502441227436066, -0.009710805490612984, 0.009544691070914268, -0.0022948412224650383, 0.007012273650616407, -0.028809761628508568, 0.02115689590573311, 0.04240534082055092, 0.031188903376460075, -0.0014382193330675364, -0.010897732339799404, -0.018712306395173073, 0.025739148259162903, 0.044879231601953506, 0.06171223521232605, -0.10287298262119293, -0.023075195029377937, 0.023538874462246895, 0.022527724504470825, 0.015353119932115078, -0.05560645833611488, 0.036050088703632355, 0.014224531129002571, -0.04377443343400955, -0.0032813088037073612, 0.028256719931960106, -0.018525203689932823, 0.015090879052877426, 0.020597461611032486, 0.009069767780601978, -0.013295626267790794, -0.006572342943400145, 0.016297753900289536, 0.03110368736088276, 0.01928323693573475, -0.025917300954461098, 0.009407817386090755, -0.015163255855441093, 0.024287018924951553, -0.03995661064982414, -0.01299810316413641, -0.00029281547176651657, 0.011957302689552307, 0.0403573252260685, -0.004719085060060024, -0.0535614900290966, -0.026991527527570724, -0.01747942715883255, 0.0014613523380830884, -0.023981375619769096, 0.004285627976059914, 0.03785493224859238, 0.05015480890870094, 0.01047113910317421, 0.05477528274059296, 0.04058663547039032, 0.013344884850084782, -0.009395926259458065, -0.002482252661138773, -0.00150933931581676, -0.012079926207661629, 0.02286137267947197, -0.034040361642837524, 0.02945062890648842, -0.028891386464238167, -0.021537097170948982, -0.01024668663740158, -0.03309618681669235, 0.025790419429540634, -0.03000100515782833, 0.0010929281124845147, -0.016648966819047928, -0.032299645245075226, -0.019213635474443436, -0.004031560383737087, -0.03379348665475845, 0.025892015546560287, -0.0006047093775123358, -0.001674060127697885, -0.01983233354985714, 0.028365695849061012, 0.016504429280757904, 0.02635308727622032, 0.002469940111041069, 0.02241353690624237, -0.0071480353362858295, -0.0002744496741797775, 0.02034774236381054, 0.003806447144597769, 0.005464985966682434, 0.005956574808806181, -0.02762707695364952, -0.011867382563650608, 0.07399281859397888, -0.01019126083701849, 0.0015828658360987902, 0.014407231472432613, -0.024688927456736565, 0.0163035336881876, 0.0037988375406712294, 0.028169866651296616, -0.010672440752387047, 0.00269909854978323, 0.045590490102767944, 0.009965790435671806, -0.012216901406645775, -0.0016568709397688508, 0.02878474071621895, 0.017412465065717697, -0.011701415292918682, -0.007723276969045401, 0.015110749751329422, 0.00048290000995621085, 0.010664805769920349, 0.026719186455011368, 0.054866380989551544, -0.04616958647966385, -0.03964811563491821, 0.004738341551274061, 0.002903667977079749, 0.03325032815337181, -0.03273972496390343, 0.0017731419065967202, 0.04102270305156708, -0.005169530399143696, 0.0026046326383948326, -0.0008205858175642788, 0.02656489424407482, 0.0393669568002224, 0.05402015149593353, 0.019148308783769608, -0.02158491313457489, -0.07032808661460876, -0.06111536920070648, 0.025655418634414673, -0.013992443680763245, 0.025777535513043404, 0.021197354421019554, -0.007020862773060799, 0.01748965121805668, 0.0025103483349084854, 0.036802101880311966, 0.03313164412975311, 0.0023176358081400394, -0.0314202681183815, -0.02231859602034092, -0.022712625563144684, 0.032619722187519073, 0.02167675457894802, 0.02352500893175602, 0.026595190167427063, 0.021104728803038597, 0.02515842579305172, 0.010098202154040337, -0.05563130974769592, -0.016912056133151054, 0.014495516195893288, 0.02419031597673893, -0.019241472706198692, 0.021382123231887817, -0.01179350446909666, -0.04618464782834053, -0.02521587535738945, -0.015054202638566494, 0.0022950363345444202, 0.06545255333185196, 0.013343165628612041, -0.06739114224910736, 0.004608503542840481, 0.02443879283964634, -0.021945156157016754, -0.013122549280524254, 0.04613327234983444, 0.025682471692562103, 0.05485980212688446, 0.0011717935558408499, 0.007602012250572443, -0.06603267788887024, 0.00425877096131444, 0.052293699234724045, 0.004238596186041832, 0.0037995693273842335, -0.049703724682331085, 0.008624410256743431, 0.005005091428756714, -0.0006268622819334269, -0.0250050388276577, -0.00093143928097561, -0.02387242205440998, 0.01497594267129898, 0.011212333105504513, -0.008466140367090702, -0.01631353795528412, -0.0007825024658814073, 0.01296975277364254, -0.008907755836844444, 0.02884533442556858, -0.009492802433669567, 0.005815028678625822, 0.016779862344264984, 0.0053336904384195805, 0.03331022337079048, 0.05719573423266411, -0.00805650744587183, 0.05591803044080734, 0.03362580016255379, 0.005962490104138851, 0.009316512383520603, -0.029731402173638344, -0.007686059456318617, -0.003222438506782055, -0.003579945070669055, 0.034098777920007706, -0.01731879822909832, 0.004171598237007856, 0.008731338195502758, 0.02451554499566555, 0.0020412628073245287, -0.014689904637634754, 0.02756696380674839, -0.036004502326250076, -0.017767105251550674, -0.06597557663917542, -0.0160057432949543, -0.019253214821219444, -0.008883162401616573, -0.018688198179006577, -0.004369432106614113, 0.013301769271492958, 0.019396860152482986, -0.04532371088862419, -0.03580371290445328, 0.024131564423441887, 0.046513307839632034, 0.03171409294009209, 0.003616339759901166, -0.010680122300982475, -0.018863147124648094, 0.01970091089606285, -0.02749345637857914, -0.05741138011217117, 0.0034219364169985056, 0.007555937860161066, -0.0037110059056431055, 0.03969745337963104, 0.05466816574335098, -0.021827997639775276, -0.01267168764024973, 0.04567340016365051, -0.04204978421330452, -0.0379096083343029, -0.029576420783996582, 0.03661143779754639, 0.032819364219903946, 0.0070266202092170715, 0.01488390751183033, 0.008709121495485306, -0.032526444643735886, 0.03117387741804123, -0.04674747213721275, 0.009996442124247551, 0.0653955414891243, -0.0033210625406354666, 0.029752831906080246, 0.00850878469645977, 0.025172239169478416, 0.0008734564762562513, -0.02372490055859089, 0.014378619380295277, 0.01600249856710434, 0.033602531999349594, 0.039825353771448135, 0.022164741531014442, 0.041208479553461075, 0.03128492832183838, 0.018017347902059555, -0.043359432369470596, 0.0035889851860702038, 0.013539286330342293, -0.05351919308304787, 0.019969725981354713, 0.0043869102373719215, -0.0012520323507487774, 0.029003558680415154, 0.0675104632973671, 0.03886305168271065, 0.012797825038433075, -0.014978490769863129, -0.010088696144521236, -0.0023987432941794395, 0.010112356394529343, 0.022198786959052086, 0.05254627391695976, 0.0036192843690514565, 0.03216882422566414, -0.011114289052784443, 0.03455828130245209, 0.03881936892867088, 0.011350593529641628, 0.029529942199587822, 0.015133642591536045, 0.05643036589026451, -0.008125019259750843, 0.022089418023824692, -0.0027990860398858786, 0.0012532490072771907, 0.004326908383518457, -0.0331026092171669, -0.021509381011128426, -0.062237560749053955, -0.004348312970250845, 0.02922343835234642, -0.017571263015270233, 0.04037749394774437, -0.025788186118006706, 0.019878236576914787, 0.05498698353767395, 0.012544738128781319, 0.004310624208301306, 0.00017714263231027871, 0.01634960062801838, 0.007534820586442947, 0.007283765822649002, 0.015480116941034794, 0.024291470646858215, -0.003350240644067526, 0.028306521475315094, 0.001206069951876998, 0.035706888884305954, 0.006083698011934757, -0.06411581486463547, 0.0575709231197834, -0.025609835982322693, -0.0012384657748043537, 0.02874624915421009, 0.007981699891388416, -0.001207460300065577, 0.010561066679656506, -0.0013706684112548828, -0.01799367368221283, 0.010307149961590767, 0.033330366015434265, 0.01581653021275997, 0.023437783122062683, -0.016936248168349266, 0.019479000940918922, 0.0418267697095871, 0.0035745720379054546, -0.026943352073431015, -0.028445981442928314, 0.013176064006984234, -0.020584722980856895, 0.024556659162044525, 0.00793969165533781, -0.03789813071489334, -0.023963144049048424, -0.023650046437978745, -0.010703579522669315, 0.03308375924825668, 0.0010984058026224375, -0.00789615884423256, 0.02397090196609497, 0.029918698593974113, -0.003392944810912013, 0.038868729025125504, 0.023775555193424225, -0.011125871911644936, -0.03234630450606346, -0.02124917320907116, -0.027891989797353745, -0.024635381996631622, -0.004404114559292793, -0.06700258702039719, -0.01834864169359207, -0.011181719601154327, 0.021725600585341454, 0.03215419873595238, 0.03072023205459118, -0.045100025832653046, -0.03012038581073284, -0.005478758364915848, 0.013780125416815281, -0.035508640110492706, 0.0021303221583366394, 0.04301704838871956, -0.019726134836673737, -0.01164319459348917, -0.014429192058742046, -0.04824856296181679, -0.030557559803128242, 0.011668968945741653, 0.025009889155626297, 0.03279811143875122, -0.011856534518301487, -0.034137509763240814, 0.025637978687882423, 0.007277746684849262, -0.000638576690107584, 0.06585417687892914, 0.0013083707308396697, 0.029952989891171455, -0.0352528914809227, 0.028176607564091682, -0.028570089489221573, 0.003501994302496314, -0.04319939389824867, -0.028387736529111862, -0.03478255867958069, 0.029529523104429245, -0.00751942303031683, 0.016449177637696266, -0.02113484777510166, 0.02051173895597458, -0.032817259430885315, -0.04115700721740723, -0.028516171500086784, 0.01943276636302471, 0.05863448232412338, 0.01697571575641632, 0.0088173383846879, 0.00232562399469316, -0.03967675194144249, -0.04100443795323372, -0.030823534354567528, 0.009483853355050087, 0.06511949747800827, -0.005988205783069134, 0.0018054565880447626, 0.0027293337043374777, 0.008012514561414719, -0.005374034401029348, -0.04437427595257759, -0.01832970231771469, 0.020826544612646103, 0.0011425766861066222, -0.0016986723057925701, -0.004377816338092089, 0.011928091756999493, -0.016622791066765785, 0.0071560414507985115, 0.004043486434966326, -0.01864495687186718, -0.027561841532588005, -0.0024176461156457663, -0.04078048840165138, -0.020923105999827385, -0.005244414787739515, -0.017192238941788673, 0.08443807810544968, 0.014828083105385303, 0.01857841946184635, 0.026322847232222557, 0.01128990389406681, 0.023485347628593445, 0.010629394091665745, -0.024190612137317657, -0.03181722015142441, 0.017658205702900887, 0.010450750589370728, -0.021839933469891548, -0.001515314681455493, 0.013391458429396152, 0.057782433927059174, -0.011756575666368008, 0.0186483021825552, 0.007832957431674004, -0.0065871416591107845, -0.05209650844335556, 0.049955759197473526, 0.004143696743994951, 0.05204513669013977, 0.005221615545451641, 0.029372910037636757, 0.049688708037137985, 0.032218087464571 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Warm-starting encoder-decoder models (Theory) Having read the introduction, we are now familiar with encoder-only- and decoder-only models. We have noticed that the encoder-decoder model architecture is essentially a composition of a stand-alone encoder model and a stand-alone decoder model, which led us to the question of how one can warm-start encoder-decoder models from stand-alone model checkpoints. There are multiple possibilities to warm-start an encoder-decoder model. One can 1. initialize both the encoder and decoder part from an encoder-only model checkpoint, e.g. BERT, 2. initialize the encoder part from an encoder-only model checkpoint, e.g. BERT, and the decoder part from and a decoder-only checkpoint, e.g. GPT2, 3. initialize only the encoder part with an encoder-only model checkpoint, or 4. initialize only the decoder part with a decoder-only model checkpoint. In the following, we will put the focus on possibilities 1. and 2. Possibilities 3. and 4. are trivial after having understood the first two.
[ 0.0068126218393445015, 0.01375231146812439, 0.02660561539232731, -0.018686184659600258, 0.047928616404533386, 0.0504036508500576, -0.0090086804702878, -0.018566086888313293, -0.017048941925168037, -0.07427553087472916, -0.06265637278556824, 0.0656830295920372, -0.06024852767586708, 0.04504594951868057, -0.013672890141606331, -0.022490333765745163, 0.008851759135723114, -0.09118629992008209, -0.02606595680117607, 0.005517855286598206, 0.0398537814617157, -0.060881778597831726, -0.01509087160229683, -0.02580096572637558, 0.04379134625196457, -0.08664915710687637, -0.003889960702508688, 0.015388614498078823, -0.016511425375938416, 0.028567584231495857, -0.05368927866220474, 0.032253991812467575, 0.07009731233119965, -0.04272084683179855, 0.04873085767030716, 0.06402131915092468, -0.11283760517835617, 0.041908059269189835, 0.045586057007312775, -0.06249547377228737, -0.02339819446206093, -0.0006630175048485398, -0.008881413377821445, 0.0029011203441768885, -0.04412945732474327, -0.03977319225668907, -0.186798095703125, 0.06165899336338043, -0.025262905284762383, -0.0693461149930954, -0.06852870434522629, 0.04654465243220329, 0.0020271227695047855, 0.07196490466594696, -0.04471011087298393, 0.002934807213023305, 0.03257930651307106, -0.06760983914136887, 0.06959056109189987, 0.003642455441877246, 0.09901716560125351, 0.033040665090084076, -0.02482115663588047, 0.025871550664305687, 0.03448691591620445, 0.02492605522274971, -0.06295756250619888, -0.027073107659816742, 0.011023442260921001, 0.001838824013248086, -0.0801965519785881, -0.04298694431781769, 0.0019071042770519853, 0.026756158098578453, 0.07402995973825455, -0.06571785360574722, 0.06138364598155022, -0.01952425204217434, 0.028364980593323708, 0.013086200691759586, -0.008928469382226467, 0.012550745159387589, -0.04177583009004593, -0.002748055849224329, 0.0699189305305481, -0.017504170536994934, 0.009556982666254044, -0.05127033591270447, -0.022847650572657585, 0.06092539429664612, -0.034901514649391174, -0.15295034646987915, 0.0504368394613266, -0.012859905138611794, 0.030624326318502426, 0.00019027436792384833, -0.006233246996998787, 0.04215296730399132, 0.037997689098119736, -0.013862998224794865, 0.0043563274666666985, -0.045436084270477295, -0.0007577069918625057, -0.036842767149209976, -0.023023519665002823, 0.022855473682284355, -0.012792079709470272, -0.08775594085454941, -0.05269208550453186, -0.01326771266758442, 0.017787935212254524, -0.06385212391614914, -0.011520535685122013, 0.049992166459560394, -0.12000146508216858, 0.04539451003074646, 0.03768327832221985, -0.0583563894033432, 0.01063518412411213, 0.03636990860104561, 0.020287398248910904, 0.05672609806060791, 0.03848651424050331, -0.045232802629470825, -0.0013343575410544872, 0.03778240457177162, 0.012687833979725838, 0.028919642791152, 0.01297809649258852, 0.0076021458953619, 0.09423939138650894, 0.014813609421253204, 0.021711964160203934, -0.01002525258809328, 0.04967706650495529, -0.014487587846815586, -0.013678384013473988, -0.0030562470201402903, -0.029550064355134964, 0.012833734974265099, -0.11167890578508377, 0.058271098881959915, 0.06414798647165298, -0.060246068984270096, 0.03197773918509483, 0.04732203483581543, -0.09361641108989716, 0.06783568114042282, 0.010479634627699852, 0.033110395073890686, -0.04308043420314789, 0.04003462195396423, -0.04574766382575035, -0.0797019749879837, 0.00043447804637253284, 0.05305038392543793, -0.0185936838388443, -0.00602946849539876, -0.05046021193265915, -0.00754404254257679, 0.016781101003289223, 0.015947634354233742, -0.026825567707419395, 0.0008013348560780287, 0.03195542097091675, -0.08649026602506638, 0.004670690279453993, 0.06276114284992218, -0.009231275878846645, 0.02742421068251133, -0.02101748250424862, 0.0004582737456075847, 0.10375583916902542, -0.012343959882855415, 0.019641559571027756, 0.02436158061027527, -0.0051091378554701805, 0.07697337120771408, 0.024088306352496147, -0.008333652280271053, -0.0319649800658226, -0.009290815331041813, -0.031702928245067596, 0.038137007504701614, 0.03624046593904495, -0.01127662230283022, 0.006173199508339167, -0.07145904004573822, -0.0838528424501419, 0.006362361367791891, -0.037208229303359985, -0.0034722290001809597, 0.024368302896618843, -0.006075769662857056, 0.030822638422250748, -0.05556000769138336, -0.07117488980293274, 0.07562708109617233, 0.02790590561926365, 0.05715818703174591, 0.12689447402954102, 0.03670905902981758, 0.06245223432779312, 0.023343835026025772, -0.020867979153990746, 0.04318415746092796, 0.06460592150688171, -0.03616778925061226, 0.10982666909694672, -0.02056589536368847, 0.02246726118028164, -0.058435000479221344, -0.01807238720357418, -0.07679563760757446, 0.05195729061961174, -0.03626261651515961, 0.010260379873216152, -0.02091291919350624, 0.015534057281911373, -0.0026277995202690363, 0.13796408474445343, -0.05640741437673569, -0.008289447985589504, -0.01753523014485836, -0.007192337419837713, 0.037870634347200394, 0.07787319272756577, -0.02664480172097683, 0.09643897414207458, -0.05054057389497757, -0.00030324480030685663, -0.028965989127755165, -0.04338590055704117, 0.023370692506432533, 0.018546495586633682, 0.032926298677921295, -0.008044657297432423, 0.025092072784900665, 0.0358271487057209, -0.0817917212843895, 0.011877598240971565, -0.01954660564661026, 0.028446707874536514, -0.02030036225914955, -0.02741154283285141, 0.011250010691583157, 0.055171601474285126, 0.001432020217180252, -0.03069562092423439, -0.015839332714676857, -0.08229856193065643, 0.03296208381652832, 0.0234820693731308, -0.08509474247694016, 0.043343253433704376, 0.009579231031239033, -0.042350031435489655, -0.020800886675715446, 0.020067891106009483, 0.0012738569639623165, 0.00914453249424696, -0.035826582461595535, -0.015883831307291985, -0.03268038481473923, -0.03501766920089722, -0.025632161647081375, -0.04906585067510605, -0.007674848660826683, 0.014706980437040329, 0.0032002744264900684, 0.07486286014318466, -0.05563870817422867, 0.03794984146952629, 0.027161210775375366, 0.027217315509915352, -0.021284671500325203, 0.03256902098655701, -0.024737760424613953, -0.033229634165763855, -0.016967875882983208, 0.022272661328315735, -0.020833881571888924, -0.00787204597145319, 0.015751535072922707, -0.005627996753901243, 0.008682242594659328, 0.008403073996305466, -0.005001289304345846, -0.0027582282200455666, 0.053526997566223145, -0.00594366155564785, 0.039704330265522, -0.01626359298825264, 0.015028108842670918, 0.00186860968824476, 0.035677459090948105, -0.005021381191909313, -0.023038623854517937, -0.0025357967242598534, -0.015159757807850838, -0.005309820640832186, 0.02439935691654682, 0.02825840935111046, -0.03785945475101471, -0.07590145617723465, 0.022124631330370903, 0.05183390900492668, 0.025420894846320152, -0.10430994629859924, -0.030512012541294098, -0.0012267676647752523, 0.0027250642888247967, 0.02930997684597969, -0.027665527537465096, 0.054875824600458145, -0.020011793822050095, -0.01305595226585865, 0.0009780528489500284, 0.018238026648759842, -0.027693841606378555, 0.0028999156784266233, 0.022132238373160362, -0.05442985147237778, -0.032866429537534714, -0.027891162782907486, 0.005069229286164045, 0.020099787041544914, -0.032082658261060715, 0.011568784713745117, -0.0075017958879470825, 0.01876494288444519, 0.0068832989782094955, -0.016794675961136818, -0.03506876900792122, 0.028647689148783684, 0.035850245505571365, 0.002663350198417902, 0.005004339385777712, -0.0008346443646587431, -0.01434068288654089, -0.014593846164643764, 0.033145926892757416, -0.018319565802812576, 0.004547519143670797, 0.05071813240647316, 0.007677940186113119, 0.05543312802910805, 0.03728624805808067, -0.00448970403522253, 0.03250447288155556, 0.0005005773855373263, 0.010059517808258533, -0.02231135405600071, -0.017423253506422043, 0.015535068698227406, -0.0032346686348319054, 0.02208477444946766, -0.016220761463046074, 0.0019324098248034716, -0.0024113452527672052, 0.020699648186564445, -0.0007929167477414012, -0.013030623085796833, 0.006016440689563751, 0.011148502118885517, 0.030161986127495766, 0.023768799379467964, -0.04304181784391403, -0.027848338708281517, -0.008037762716412544, -0.012228825129568577, -0.04912901297211647, -0.04422318935394287, 0.0337887778878212, 0.023741621524095535, 0.030645182356238365, 0.01505027711391449, 0.039509523659944534, -0.032239317893981934, 0.00153031584341079, 0.015283207409083843, 0.009005071595311165, -0.007220251485705376, 0.03847701475024223, -0.045026253908872604, -0.027111735194921494, 0.07615135610103607, 0.023942086845636368, 0.018909087404608727, 0.00780145451426506, -0.047486960887908936, -0.013117226772010326, 0.017631342634558678, 0.020203767344355583, 0.01071708183735609, 0.025281134992837906, 0.04260443523526192, 0.013119596056640148, 0.015572747215628624, -0.032385218888521194, -0.0030496730469167233, -0.038377419114112854, -0.0019071788992732763, -0.001372084952890873, 0.0066462429240345955, 0.03221181407570839, 0.03227750211954117, 0.008044039830565453, -0.01162966713309288, -0.05980297550559044, -0.025563431903719902, 0.020640918985009193, -0.01761746034026146, 0.012349111028015614, -0.00042211817344650626, -0.054452184587717056, 0.03754234313964844, -0.0342717282474041, -0.014205701649188995, 0.007900822907686234, 0.014213478192687035, -0.003884513396769762, 0.021930959075689316, 0.04762395843863487, -0.013945197686553001, -0.04867565259337425, 0.005088528152555227, 0.004263874609023333, -0.0014489080058410764, 0.0037962968926876783, 0.013975400477647781, 0.0018076620763167739, 0.01016262173652649, -0.036913540214300156, 0.04144077003002167, -0.021631883457303047, 0.019631754606962204, -0.017337381839752197, -0.04924742504954338, 0.01732960343360901, 0.03793448954820633, -0.02913089655339718, 0.0016472020652145147, -0.012121723964810371, -0.01947869546711445, 0.0395745150744915, 0.03699536621570587, -0.03569572791457176, 0.007732992991805077, 0.01090855710208416, 0.03814682364463806, -0.057030752301216125, 0.05990908667445183, 0.020415684208273888, -0.02151680178940296, 0.018396742641925812, -0.011427047662436962, 0.012622566893696785, 0.05111446976661682, -0.006975717376917601, -0.05466315150260925, 0.01385786198079586, 0.010186786763370037, -0.033372145146131516, 0.006115000694990158, -0.007117573171854019, 0.026538321748375893, 0.03331003338098526, 0.009557854384183884, 0.012362685054540634, -0.023144135251641273, 0.004120287951081991, -0.009892172180116177, 0.01461742538958788, -0.032847385853528976, -0.011017021723091602, 0.0050799124874174595, 0.0005685559590347111, -0.00478421151638031, -0.034223515540361404, 0.023944949731230736, -0.022631986066699028, 0.038713376969099045, -0.00839049369096756, 0.0423109345138073, 0.011524160392582417, -0.005077575799077749, 0.014261369593441486, -0.00452052429318428, 0.012192278169095516, -0.021111642941832542, -0.010609525255858898, 0.0022418845910578966, 0.027018051594495773, 0.06684372574090958, 0.03769543021917343, 0.05077625811100006, 0.01444968767464161, 0.03276003524661064, 0.012124031782150269, 0.05423619970679283, -0.00611845264211297, -0.017916228622198105, -0.02262069098651409, -0.02333136461675167, -0.004138353280723095, -0.018507283180952072, 0.008380493149161339, 0.007187372539192438, 0.03847462311387062, -0.02861020341515541, -0.02004292793571949, 0.017961259931325912, -0.05329470336437225, -0.018802465870976448, -0.05189380422234535, 0.047372858971357346, -0.028551969677209854, -0.008783978410065174, -0.04271846264600754, 0.0035903938114643097, 0.01739748939871788, 0.01677176170051098, 0.018227219581604004, -0.03573637083172798, 0.031432945281267166, 0.032396350055933, 0.044851530343294144, 0.01571200229227543, -0.004020683467388153, -0.029859444126486778, 0.007085597142577171, -0.008232193998992443, -0.026440490037202835, -0.025003207847476006, 0.02274770475924015, -0.006530587561428547, 0.009192241355776787, 0.03234951198101044, -0.019338231533765793, 0.020722754299640656, 0.017999235540628433, -0.02649722434580326, -0.021386951208114624, -0.03649095445871353, 0.00010413416748633608, 0.02825980633497238, 0.0007236082456074655, -0.010406749323010445, -0.012502568773925304, 0.011813389137387276, -0.008509321138262749, -0.037025753408670425, 0.00804063305258751, 0.03733105957508087, 0.006473179440945387, 0.02140256203711033, 0.01902672089636326, 0.042219895869493484, -0.00617649732157588, 0.027666231617331505, -0.016577694565057755, 0.04350626468658447, 0.016457606106996536, 0.024444669485092163, -0.025833865627646446, -0.0012897594133391976, 0.019375640898942947, 0.037344563752412796, -0.042373448610305786, 0.0195827167481184, 0.03492847457528114, -0.06584970653057098, 0.01483850833028555, -0.01583298109471798, -0.032183706760406494, 0.0019384955521672964, 0.01559357438236475, 0.01990528032183647, -0.0011698215967044234, -0.023293206468224525, 0.016264373436570168, 0.05027119070291519, -0.0018303841352462769, 0.05131959915161133, 0.052053432911634445, -0.014399257488548756, 0.01544804684817791, 0.013685254380106926, 0.009883992373943329, 0.028678590431809425, -0.004335059318691492, -0.03174477815628052, -0.002705934690311551, 0.04963570833206177, 0.020087528973817825, 0.018278438597917557, 0.03751370310783386, -0.008419430814683437, -0.0009802122367545962, -0.02148088999092579, 0.017320388928055763, -0.004714917857199907, 0.015387197956442833, -0.0483664944767952, -0.007657787762582302, 0.015453970059752464, -0.04076544567942619, 0.02706374041736126, 0.05688300356268883, -0.01625792309641838, -0.039301011711359024, 0.05026732012629509, 0.0632336363196373, -0.004763615317642689, 0.01885661669075489, 0.00642309570685029, 0.02737429365515709, 0.007806841284036636, 0.04066608473658562, 0.012013447470963001, -0.009017696604132652, 0.03176167979836464, -0.00564408116042614, 0.039141394197940826, -0.008163231424987316, -0.005468118004500866, -0.010831966996192932, 0.033800847828388214, -0.015451915562152863, -0.017711559310555458, -0.0010190843604505062, -0.04245402663946152, 0.004248789045959711, 0.006238602567464113, -0.01519270334392786, -0.0000944123457884416, 0.005989114288240671, 0.030712613835930824, 0.01764695905148983, -0.026936490088701248, -0.0013367518549785018, -0.011902066878974438, 0.005648390855640173, -0.0022868290543556213, 0.015275668352842331, -0.026856334879994392, -0.034859683364629745, -0.053967803716659546, -0.005607937462627888, -0.02127794548869133, 0.05913084000349045, -0.025245817378163338, -0.022202514111995697, 0.08006124943494797, 0.0026999912224709988, -0.007513189222663641, 0.005557149648666382, 0.04175449535250664, 0.02012438327074051, -0.024713998660445213, -0.03213925659656525, -0.032828617841005325, -0.06271660327911377, 0.009044383652508259, -0.04821540415287018, 0.025880955159664154, -0.025258492678403854, 0.0565643347799778, 0.013123617507517338, 0.02712455950677395, -0.029177226126194, -0.008383950218558311, -0.026434030383825302, -0.03276941552758217, 0.0009019910939969122, 0.01170317828655243, 0.007501787040382624, -0.004894896410405636, 0.015296326950192451, -0.012717555277049541, -0.009472066536545753, -0.04222414270043373, 0.007892739959061146, 0.03652355447411537, -0.033394161611795425, -0.012571192346513271, -0.02403956837952137, 0.049234598875045776, -0.033270541578531265, 0.025591474026441574, 0.032501183450222015, 0.013807125389575958, 0.0287171583622694, -0.06340647488832474, -0.005148354452103376, -0.0049299998208880424, 0.006628940813243389, -0.015953341498970985, -0.04002831503748894, -0.01449331920593977, 0.02651199884712696, 0.016235902905464172, 0.002188111888244748, -0.004875896032899618, -0.012208867818117142, -0.0682654082775116, 0.006217312533408403, -0.018275994807481766, 0.06285924464464188, -0.000194823500351049, -0.0005495714722201228, 0.05245402827858925, 0.03206254914402962, -0.0069448319263756275, -0.023000432178378105, -0.03273351863026619, 0.021779749542474747, 0.05588160455226898, -0.0023828803095966578, -0.05034180358052254, -0.01210736483335495, -0.03117533214390278, 0.012968425638973713, -0.01409874577075243, -0.01786220073699951, 0.010316189378499985, -0.03555162250995636, -0.024082671850919724, -0.02217295952141285, -0.015439177863299847, 0.0054345810785889626, 0.009256184101104736, 0.03469807282090187, -0.05061997100710869, 0.0016019399045035243, 0.01843503676354885, -0.01764477789402008, -0.03721921890974045, -0.014667646959424019, 0.01454986073076725, 0.024191495031118393, 0.035143692046403885, 0.002024266868829727, -0.007757105398923159, -0.04156942665576935, 0.031164254993200302, 0.020191406831145287, -0.012420178391039371, -0.004961132071912289, -0.005390545353293419, 0.030088169500231743, -0.027870096266269684, -0.02821747399866581, 0.01250940840691328, 0.048772070556879044, -0.01858777552843094, 0.05289647728204727, -0.007820380851626396, -0.01287906989455223, -0.021281365305185318, 0.04449354112148285, -0.04868630692362785, 0.0793597474694252, 0.04715350270271301, 0.011968041770160198, 0.002318568527698517, 0.047262243926525116 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Introduction Recently, pre-trained language models \({}^1\) have revolutionized the field of natural language processing (NLP). The first pre-trained language models were based on recurrent neural networks (RNN) as proposed Dai et al. (2015). Dai et. al showed that pre-training an RNN-based model on unlabelled data and subsequently fine-tuning \({}^2\) it on a specific task yields better results than training a randomly initialized model directly on such a task. However, it was only in 2018, when pre-trained language models become widely accepted in NLP. ELMO by Peters et al. and ULMFit by Howard et al. were the first pre-trained language model to significantly improve the state-of-the-art on an array of natural language understanding (NLU) tasks. Just a couple of months later, OpenAI and Google published transformer-based pre-trained language models, called GPT by Radford et al. and BERT by Devlin et al. respectively. The improved efficiency of transformer-based language models over RNNs allowed GPT2 and BERT to be pre-trained on massive amounts of unlabeled text data. Once pre-trained, BERT and GPT were shown to require very little fine-tuning to shatter state-of-art results on more than a dozen NLU tasks \({}^3\). The capability of pre-trained language models to effectively transfer task-agnostic knowledge to task-specific knowledge turned out to be a great catalyst for NLU. Whereas engineers and researchers previously had to train a language model from scratch, now publicly available checkpoints of large pre-trained language models can be fine-tuned at a fraction of the cost and time. This can save millions in industry and allows for faster prototyping and better benchmarks in research. Pre-trained language models have established a new level of performance on NLU tasks and more and more research has been built upon leveraging such pre-trained language models for improved NLU systems. However, standalone BERT and GPT models have been less successful for sequence-to-sequence tasks, e.g. text-summarization, machine translation, sentence-rephrasing, etc. Sequence-to-sequence tasks are defined as a mapping from an input sequence \(\mathbf{X}{1:n}\) to an output sequence \(\mathbf{Y}{1:m}\) of a-priori unknown output length \(m\). Hence, a sequence-to-sequence model should define the conditional probability distribution of the output sequence \(\mathbf{Y}{1:m}\) conditioned on the input sequence \(\mathbf{X}{1:n}\): $$ p_{\theta_{\text{model}}}(\mathbf{Y}{1:m} | \mathbf{X}{1:n}). $$ Without loss of generality, an input word sequence of \(n\) words is hereby represented by the vector sequnece \(\mathbf{X}{1:n} = \mathbf{x}_1, \ldots, \mathbf{x}_n\) and an output sequence of \(m\) words as \(\mathbf{Y}{1:m} = \mathbf{y}1, \ldots, \mathbf{y}_m\). Let\'s see how BERT and GPT2 would be fit to model sequence-to-sequence tasks.
[ 0.03953409567475319, -0.029414737597107887, 0.028847068548202515, 0.013979563489556313, 0.05128942057490349, 0.09705950319766998, 0.016079824417829514, 0.0886308029294014, -0.046867650002241135, -0.01874956116080284, -0.04993356391787529, 0.08321946859359741, -0.01845620945096016, 0.0818072035908699, 0.016082124784588814, -0.012753629125654697, 0.026122894138097763, -0.03281889483332634, -0.00844605453312397, -0.009311441332101822, -0.013852173462510109, -0.03460785001516342, 0.07110840827226639, -0.026378735899925232, 0.03591589257121086, -0.025370635092258453, -0.003237365046516061, -0.00406494690105319, -0.06643097847700119, 0.011440685950219631, -0.1466268002986908, -0.004197529051452875, 0.0021847039461135864, 0.014360548928380013, -0.023002859205007553, -0.020217619836330414, -0.04447998106479645, 0.020736096426844597, -0.005996825639158487, -0.012054440565407276, -0.0509163960814476, 0.0003723616828210652, -0.06531213223934174, 0.047791387885808945, -0.06463926285505295, 0.0036134093534201384, -0.21673157811164856, 0.10284242779016495, -0.008563072420656681, -0.0421619787812233, -0.08575572818517685, 0.02333601750433445, -0.027048947289586067, 0.01380948256701231, -0.026034081354737282, 0.01867511309683323, 0.0016855354188010097, -0.10030160844326019, 0.005672738421708345, -0.024154819548130035, 0.030835719779133797, 0.025759896263480186, -0.01192884985357523, -0.03158947825431824, 0.03310414403676987, 0.002184198470786214, 0.02664044499397278, 0.018101483583450317, -0.0843132883310318, 0.0013674325309693813, 0.00846766121685505, -0.05299629643559456, -0.06613324582576752, -0.008347319439053535, -0.007591528818011284, -0.04214034602046013, -0.0208012405782938, 0.04384780302643776, 0.010737147182226181, 0.01632765494287014, 0.006155747454613447, 0.038137465715408325, 0.022375563159585, 0.03016475960612297, 0.029532259330153465, 0.011020271107554436, 0.11340576410293579, -0.038862187415361404, -0.042042288929224014, 0.04058938845992088, -0.029180733487010002, -0.13760581612586975, 0.0003704230475705117, -0.013532020151615143, 0.036025021225214005, -0.027122745290398598, 0.020605646073818207, 0.0557003952562809, -0.04302726313471794, -0.042293041944503784, 0.03310263529419899, -0.029540469869971275, 0.04479627683758736, -0.011498484760522842, -0.05166063457727432, 0.027093688026070595, -0.03153007850050926, -0.061558324843645096, -0.028545349836349487, -0.01248250249773264, 0.03200576454401016, 0.03063099831342697, 0.022694077342748642, 0.04748938977718353, -0.09469740092754364, 0.04151029884815216, 0.02650441601872444, -0.005036883521825075, 0.02476596087217331, 0.003208575304597616, 0.0027272978331893682, 0.02190517447888851, 0.032366249710321426, 0.014188586734235287, -0.010450759902596474, 0.0536469966173172, 0.023865237832069397, 0.007341788616031408, -0.024877777323126793, -0.03756491839885712, 0.06708043813705444, -0.015808653086423874, 0.04955871030688286, 0.03273029252886772, -0.01111750677227974, -0.01714155077934265, -0.0007790149538777769, -0.07194221019744873, 0.017299531027674675, 0.006297554355114698, -0.029610222205519676, 0.06152929365634918, -0.03038574755191803, 0.011894466355443, 0.07630538940429688, 0.004585903603583574, -0.10343129932880402, 0.08101289719343185, -0.02192571572959423, -0.005097544752061367, -0.08317902684211731, 0.030748581513762474, -0.10191511362791061, -0.05080088973045349, 0.03886762261390686, 0.07163950800895691, 0.0025329492054879665, -0.035117316991090775, -0.04926187917590141, -0.002893669530749321, -0.06544718891382217, 0.024429047480225563, -0.03191487863659859, -0.015896925702691078, 0.0005300712073221803, -0.09496353566646576, 0.0007996978238224983, 0.06017133966088295, 0.00545865623280406, 0.029039978981018066, 0.017078543081879616, 0.027847234159708023, 0.1210225522518158, -0.005933218635618687, -0.06229284405708313, 0.02393554337322712, -0.007480923552066088, 0.028342535719275475, 0.01963360607624054, -0.0003412481164559722, -0.01700369268655777, 0.05070342496037483, 0.021358193829655647, 0.04372932016849518, 0.04985843226313591, -0.11119969189167023, -0.025520917028188705, -0.029277481138706207, -0.02458837814629078, 0.06249309703707695, -0.0469292514026165, -0.021055324003100395, 0.09878816455602646, -0.01932389847934246, 0.03752145916223526, -0.09349880367517471, -0.00026001958758570254, 0.1539023220539093, 0.03185134008526802, 0.08411016315221786, 0.10692209005355835, -0.006062163971364498, 0.01773487590253353, -0.05987605080008507, -0.02596491575241089, -0.03294983133673668, 0.02053811028599739, 0.011238090693950653, 0.043751854449510574, -0.021576421335339546, 0.03127923980355263, -0.11177488416433334, 0.01127192098647356, -0.05514700338244438, 0.010863101109862328, -0.032539281994104385, -0.013681369833648205, 0.008559316396713257, 0.0226923618465662, -0.05465102940797806, 0.14199593663215637, -0.04285838082432747, -0.001505836844444275, 0.02329353615641594, -0.015700483694672585, 0.05224309861660004, 0.0744466558098793, 0.035729825496673584, 0.055606305599212646, -0.027193360030651093, -0.002148883882910013, -0.11640561372041702, 0.02228255197405815, 0.0211410541087389, 0.0014890801394358277, -0.002181514399126172, -0.009561014361679554, -0.02927192859351635, -0.00979265384376049, 0.006482250988483429, 0.0053797392174601555, 0.016625776886940002, 0.0020525732543319464, 0.06278572231531143, -0.012678485363721848, -0.024564875289797783, 0.03366652503609657, 0.004151755478233099, -0.015859901905059814, -0.03100890852510929, -0.09541404992341995, 0.03658672794699669, -0.02097916789352894, -0.024723565205931664, 0.02895512245595455, 0.044639382511377335, -0.0127281304448843, -0.006592816207557917, 0.005260472651571035, 0.01684054732322693, -0.004950161091983318, -0.03915425017476082, -0.019072066992521286, -0.04987214505672455, -0.006382650695741177, -0.025169823318719864, -0.014695597812533379, -0.00863181333988905, 0.0284658782184124, 0.040213361382484436, 0.005707582458853722, -0.003911627922207117, 0.045972760766744614, 0.04363222047686577, -0.001257089665159583, 0.05509994179010391, 0.0016685224836692214, -0.02869495004415512, -0.037162065505981445, -0.019557151943445206, 0.0002354280004510656, -0.043771106749773026, 0.020598681643605232, 0.02547556348145008, 0.014623799361288548, -0.013122557662427425, 0.012289022095501423, -0.026125168427824974, -0.011300860904157162, 0.03452127426862717, -0.000057117529649985954, 0.011532570235431194, -0.05025666207075119, -0.055589932948350906, -0.022348390892148018, -0.025581255555152893, 0.003588679013773799, -0.018865374848246574, 0.0032549514435231686, 0.014891799539327621, -0.007950524799525738, 0.015013285912573338, -0.01139107346534729, 0.005638579837977886, -0.027639877051115036, 0.02639160305261612, 0.03328564763069153, 0.041548945009708405, -0.11728183180093765, -0.04960907995700836, 0.04271530359983444, 0.007849394343793392, -0.007635670248419046, -0.007095597684383392, 0.05060679093003273, -0.019212590530514717, -0.018715795129537582, 0.01084381714463234, 0.00011233961413381621, 0.026006773114204407, 0.0383872427046299, 0.007503212429583073, -0.027499999850988388, -0.0072354902513325214, -0.016113491728901863, 0.0009915310656651855, 0.01029928121715784, 0.037420086562633514, -0.023032348603010178, 0.025561070069670677, -0.025426296517252922, 0.013837927021086216, -0.040670737624168396, 0.008296418935060501, 0.01188231073319912, 0.004791735205799341, 0.015470844693481922, -0.03305809944868088, -0.04526372253894806, -0.003822098718956113, -0.01630879007279873, 0.04440050572156906, -0.010539418086409569, -0.03243309259414673, 0.008433355018496513, 0.07391119748353958, -0.0031936310697346926, 0.036846697330474854, 0.04242350906133652, -0.022787567228078842, 0.0012351303594186902, -0.006524560507386923, -0.009757711552083492, 0.012885302305221558, 0.01586378924548626, -0.005971626844257116, 0.01130865141749382, -0.04708206653594971, -0.030036073178052902, 0.006887434516102076, -0.01530372817069292, 0.05500014126300812, 0.027114545926451683, 0.015609614551067352, -0.009707201272249222, -0.014557157643139362, 0.009821423329412937, 0.008232415653765202, -0.02548910677433014, 0.044374462217092514, -0.0044305529445409775, -0.004110760521143675, -0.051646698266267776, 0.07073909789323807, 0.023407984524965286, 0.040039729326963425, -0.003615302499383688, 0.05467494577169418, 0.0004479362105485052, 0.04807812348008156, -0.0064512877725064754, 0.005023762583732605, -0.009201489388942719, -0.004293302074074745, -0.01376383937895298, 0.019885165616869926, 0.07480377703905106, 0.015530196018517017, -0.03370416909456253, -0.032703157514333725, -0.050687577575445175, -0.02548605017364025, 0.022099871188402176, 0.017925716936588287, -0.0015073419781401753, -0.014742502011358738, 0.03300667554140091, 0.027000969275832176, 0.005261256825178862, 0.008431860245764256, 0.014088950119912624, 0.011852633208036423, 0.03116116113960743, -0.008546932600438595, 0.03656618669629097, -0.009492550976574421, -0.000767107296269387, -0.0046997894532978535, 0.041193440556526184, -0.03882617503404617, -0.006508521270006895, 0.011713061481714249, -0.023170270025730133, 0.04313160106539726, -0.019095564261078835, -0.02418076992034912, -0.015198808163404465, -0.011147440411150455, -0.011043190956115723, 0.006482284981757402, 0.03295939788222313, 0.011437838897109032, 0.01839800737798214, 0.016046134755015373, -0.01128145307302475, -0.01327055599540472, -0.03342631086707115, 0.0266644898802042, -0.03800290450453758, 0.028688961640000343, -0.016643118113279343, 0.00933966226875782, 0.03817996382713318, -0.019943339750170708, 0.010934887453913689, 0.021177565678954124, -0.015306086279451847, 0.002457136521115899, -0.012055215425789356, -0.025780458003282547, 0.02329767681658268, 0.007821117527782917, -0.0010160825913771987, 0.00746955955401063, 0.0012129389215260744, -0.015938136726617813, -0.032927803695201874, -0.026439549401402473, 0.008019616827368736, -0.010935639031231403, 0.0165718961507082, -0.011756321415305138, 0.057315893471241, 0.007061594165861607, -0.02678525447845459, -0.03649008274078369, 0.006505681201815605, 0.018062015995383263, 0.0477614551782608, -0.020959025248885155, -0.03340335190296173, 0.014203829690814018, 0.03638264164328575, -0.017064275220036507, -0.017155442386865616, 0.049586713314056396, 0.005800996441394091, 0.05773913115262985, 0.0054236180149018764, -0.01604713685810566, -0.04713893309235573, 0.004819547291845083, 0.017388135194778442, -0.01373616699129343, -0.014588680118322372, -0.004630620591342449, -0.0086794039234519, 0.026945674791932106, 0.021853119134902954, -0.029500920325517654, -0.02088124305009842, -0.02559897117316723, 0.015945982187986374, 0.00945707131177187, -0.00524522690102458, 0.018224459141492844, -0.012338223867118359, 0.044659800827503204, 0.0032158279791474342, 0.014973466284573078, -0.0003002255689352751, 0.044380709528923035, -0.014380024746060371, 0.003147234907373786, 0.051280427724123, 0.027089614421129227, 0.020174477249383926, 0.025976411998271942, 0.00015022733714431524, -0.0009519814630039036, 0.05027752369642258, -0.023260939866304398, 0.010296869091689587, 0.002326497808098793, 0.005741022527217865, 0.03340195491909981, -0.021336739882826805, -0.0020177168771624565, 0.021349657326936722, 0.03867686539888382, -0.012006456032395363, -0.019216084852814674, 0.023583954200148582, 0.013240967877209187, -0.0322374626994133, -0.048464495688676834, -0.01930149458348751, -0.013487549498677254, -0.013144555501639843, 0.03200186789035797, -0.026114361360669136, -0.026457546278834343, -0.019376153126358986, -0.031839530915021896, 0.0024644643999636173, 0.05084564536809921, 0.02578691579401493, 0.03488241881132126, 0.006125877611339092, -0.01411772146821022, -0.03638681396842003, -0.014242434874176979, 0.01723533496260643, -0.02498358115553856, -0.005251070484519005, 0.026558412238955498, 0.012982209213078022, 0.021698126569390297, 0.015611951239407063, -0.03769488260149956, 0.010417907498776913, 0.04239694029092789, -0.003127399133518338, -0.026919497177004814, -0.027483176440000534, 0.02044599875807762, 0.0018086143536493182, -0.003659894224256277, -0.003525888081640005, -0.03025755286216736, -0.038856685161590576, 0.0033826229628175497, -0.053446490317583084, 0.011819984763860703, 0.05651115998625755, -0.04225432872772217, 0.0048596616834402084, 0.029763562604784966, 0.01062903180718422, -0.006757598835974932, -0.0020286603830754757, 0.008970394730567932, 0.014581232331693172, 0.030738597735762596, 0.007413158193230629, 0.004958165809512138, -0.0260847769677639, 0.011688299477100372, 0.010105549357831478, -0.06523443013429642, -0.007479345891624689, 0.04814906790852547, -0.034412723034620285, 0.011389396153390408, 0.01933955028653145, -0.0429585799574852, 0.012917018495500088, 0.029645903035998344, 0.021634884178638458, 0.005208231043070555, -0.013473200611770153, -0.006195147521793842, -0.0034877718426287174, -0.02913527749478817, 0.018609102815389633, 0.04841424152255058, -0.021728074178099632, 0.07974823564291, 0.040351688861846924, 0.030426381155848503, 0.047787878662347794, 0.008001499809324741, 0.005064469762146473, 0.028972232714295387, 0.06640306860208511, -0.0023470146115869284, 0.02028236910700798, 0.006562078837305307, -0.015237413346767426, -0.0325227789580822, -0.035504210740327835, -0.013301611877977848, -0.03381814435124397, 0.005430377088487148, 0.047418393194675446, -0.00038160537951625884, 0.017457500100135803, -0.03425293415784836, 0.028559129685163498, 0.06432346254587173, 0.03449191898107529, -0.001632298226468265, 0.025111274793744087, 0.04620848596096039, 0.03302653133869171, 0.018059810623526573, 0.013571854680776596, -0.005668432451784611, 0.01803923398256302, 0.0330774150788784, 0.04222414270043373, 0.03197595477104187, -0.025512857362627983, -0.023055996745824814, 0.025413690134882927, -0.010822946205735207, -0.0010860583279281855, 0.024098534137010574, -0.009162768721580505, -0.0012832778738811612, -0.018310829997062683, 0.003990775905549526, -0.03335185721516609, 0.004666989203542471, 0.0019125989638268948, -0.002596580423414707, 0.015012077987194061, -0.04308590665459633, -0.01482213381677866, 0.0382954478263855, -0.00028396141715347767, -0.035144127905368805, -0.032236285507678986, -0.0018639708869159222, 0.009755885228514671, 0.022796159610152245, 0.0058287945576012135, -0.021287109702825546, 0.0005918648093938828, -0.02344674989581108, -0.019159262999892235, 0.01121124904602766, -0.008818014524877071, -0.004966778680682182, 0.018638459965586662, 0.013272332958877087, -0.028993073850870132, 0.034060414880514145, 0.03305625542998314, -0.003647473407909274, -0.02700987085700035, 0.02756352350115776, -0.032248806208372116, -0.020333876833319664, 0.017889637500047684, -0.08485155552625656, 0.005433761514723301, -0.03202027827501297, 0.024310527369379997, 0.055926211178302765, 0.08226308971643448, -0.031033694744110107, -0.026765935122966766, -0.014263223856687546, -0.01024013664573431, -0.006497012916952372, -0.0019175169290974736, 0.024872342124581337, -0.022975929081439972, 0.006717801094055176, 0.004504899960011244, -0.022560996934771538, -0.030562331900000572, -0.022429831326007843, 0.032689932733774185, -0.004226417746394873, -0.010383892804384232, -0.03390774875879288, 0.04488576203584671, 0.013943522237241268, 0.01571560464799404, 0.05542699247598648, 0.008846960961818695, 0.04994098097085953, -0.05460546538233757, 0.030546939000487328, -0.04266213998198509, 0.021066943183541298, -0.0365501306951046, -0.06016181781888008, -0.03317204490303993, 0.02132045291364193, 0.0055372342467308044, 0.0013265196466818452, -0.05490116775035858, -0.0028054926078766584, -0.0595230869948864, 0.021008016541600227, -0.00832707155495882, 0.015773575752973557, 0.06414981931447983, 0.0012599165784195065, 0.0019764963071793318, -0.01299163419753313, -0.002784754615277052, -0.02927442081272602, -0.011056238785386086, -0.012861372902989388, 0.034103382378816605, -0.013402693904936314, 0.000608976639341563, -0.007233875337988138, 0.009669431485235691, -0.03468078002333641, -0.016412287950515747, 0.020258700475096703, 0.04870712384581566, 0.012772118672728539, -0.01174137368798256, 0.028117159381508827, -0.023483097553253174, -0.0025038588792085648, 0.016729865223169327, 0.017876815050840378, -0.02773943357169628, 0.009020030498504639, 0.00019832806719932705, -0.048747558146715164, -0.016323694959282875, 0.008788499049842358, 0.030471544712781906, 0.07182524353265762, 0.04409883916378021, 0.03412748500704765, -0.014213483780622482, -0.02065250836312771, 0.029389558359980583, 0.027824580669403076, -0.030548162758350372, -0.04259059950709343, 0.0052800835110247135, -0.0035964534617960453, -0.0119226248934865, -0.023494431748986244, 0.04979175701737404, 0.023680584505200386, -0.018732357770204544, -0.024734359234571457, 0.004254742991179228, 0.001634254353120923, -0.03369823098182678, 0.04128475487232208, 0.010781406424939632, 0.05927444249391556, 0.05450214818120003, -0.0015674559399485588, -0.011193424463272095, 0.010970864444971085 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Experiments The above models were trained and evaluated on four sequence-to-sequence tasks of increasing complexity: sentence-level fusion, sentence-level splitting, translation, and abstractive summarization. The following table shows which datasets were used for each task. |Seq2Seq Task |Datasets |Paper |🤗datasets | |-------------------------- |-----------------------------------------------------------------------|----------------------------------------------------------------------- |----------------------------------------------------------------------------------------- | |Sentence Fusion |DiscoFuse |Geva et al. (2019) |link | |Sentence Splitting |WikiSplit |Botha et al. (2018) |-| |Translation |WMT14 EN => DE |Bojar et al. (2014) |link| |WMT14 DE => EN |Bojar et al. (2014) | |link | |Abstractive Summarizaion |CNN/Dailymail | Hermann et al. (2015) |link| |BBC XSum |Narayan et al. (2018a) | |link | |Gigaword |Napoles et al. (2012) | |link | Depending on the task, a slightly different training regime was used. E.g. according to the size of the dataset and the specific task, the number of training steps ranges from 200K to 500K, the batch size is set to either 128 or 256, the input length ranges from 128 to 512 and the output length varies between 32 to 128. It shall be emphasized however that within each task, all models were trained and evaluated using the same hyperparameters to ensure a fair comparison. For more information on the task-specific hyperparameter settings, the reader is advised to see the Experiments section in the paper. We will now give a condensed overview of the results for each task.
[ 0.03937816619873047, -0.01978582888841629, -0.02349153161048889, -0.006471044383943081, 0.040202945470809937, 0.07548676431179047, -0.02675214409828186, 0.050302643328905106, -0.07836460322141647, -0.05440307408571243, -0.0759415328502655, 0.023287581279873848, -0.027767205610871315, 0.010447554290294647, -0.007592165842652321, -0.0033105178736150265, 0.04802783206105232, 0.0027025765739381313, 0.04355457425117493, -0.035903461277484894, -0.015821505337953568, -0.018438834697008133, 0.024513421580195427, -0.03731899708509445, 0.01554916799068451, -0.027492638677358627, 0.03015778586268425, -0.035441964864730835, -0.06205151230096817, 0.022302113473415375, -0.13533146679401398, -0.04772142320871353, -0.022033819928765297, 0.009926042519509792, -0.041837144643068314, -0.017363330349326134, -0.12479668855667114, 0.012330887839198112, 0.046533890068531036, -0.051945436745882034, -0.03127330541610718, -0.014940133318305016, -0.09051910042762756, 0.07368778437376022, -0.028608117252588272, 0.06374652683734894, -0.10999282449483871, 0.023933054879307747, -0.016776777803897858, -0.028670603409409523, -0.0734713152050972, 0.09194760769605637, 0.029002167284488678, -0.012227604165673256, 0.023466086015105247, 0.028898412361741066, 0.016713282093405724, -0.06159982085227966, 0.05721506103873253, 0.004411643836647272, -0.017332550138235092, -0.04488129913806915, -0.022118933498859406, -0.00453579006716609, -0.0048405686393380165, -0.007901656441390514, 0.007164692971855402, 0.0746951624751091, -0.08114045858383179, 0.0018867930630221963, 0.014434360899031162, -0.02930840291082859, -0.014771850779652596, -0.008266354911029339, 0.0117292245849967, -0.07181596755981445, -0.01126261055469513, -0.01370543148368597, 0.02085471898317337, 0.0014585377648472786, 0.018060464411973953, 0.07225959002971649, 0.03044552356004715, 0.06263010203838348, 0.014446801505982876, -0.004327267874032259, 0.043163858354091644, -0.04280915856361389, -0.054664235562086105, 0.041751496493816376, 0.0013730544596910477, -0.1016155332326889, -0.007567246910184622, 0.05219206213951111, 0.047751229256391525, -0.03639676421880722, -0.013291296549141407, 0.08017802238464355, -0.03201103210449219, -0.04300754517316818, 0.0017402498051524162, -0.022117793560028076, 0.08164414763450623, -0.011960546486079693, -0.04011970013380051, 0.0545094758272171, -0.09090206772089005, -0.05102049186825752, -0.04848843440413475, -0.00041386528755538166, 0.018780769780278206, 0.016517046838998795, -0.05497348681092262, 0.05930574610829353, -0.09953770041465759, 0.054887622594833374, -0.03172025457024574, 0.035455215722322464, -0.026378998532891273, 0.05300826206803322, -0.053075797855854034, 0.06482631713151932, 0.04776598885655403, 0.011724845506250858, -0.005294745322316885, 0.015486558899283409, -0.013916485011577606, -0.04320763051509857, -0.034708138555288315, -0.029077233746647835, 0.022654086351394653, 0.02336193434894085, 0.08255691081285477, 0.03539750352501869, 0.005128728225827217, -0.06667672842741013, -0.011771307326853275, -0.039831746369600296, 0.015325953252613544, 0.009206091985106468, -0.048929065465927124, 0.057535603642463684, 0.017381496727466583, 0.015324592590332031, 0.05912831425666809, 0.03981546312570572, -0.07236947864294052, 0.037127893418073654, 0.017862288281321526, -0.006996332202106714, -0.05523303896188736, 0.023622339591383934, -0.12309516221284866, -0.07432163506746292, 0.09654540568590164, 0.0020502624101936817, 0.031779706478118896, -0.029727820307016373, -0.04014306887984276, -0.016615519300103188, 0.020326627418398857, 0.03615080565214157, -0.024972913786768913, 0.014048287644982338, 0.026633813977241516, -0.0814751461148262, 0.03351037576794624, 0.05712750181555748, 0.015105846337974072, -0.02844971790909767, 0.02397320419549942, 0.03171130642294884, 0.04954710230231285, 0.007754851132631302, -0.09226567298173904, 0.05512009933590889, -0.007632894441485405, 0.035797618329524994, 0.030829310417175293, 0.0021787702571600676, -0.04469403624534607, 0.013306754641234875, -0.03085365518927574, -0.02979169227182865, 0.05080827698111534, -0.09363056719303131, 0.03497987240552902, -0.004445116966962814, -0.010914099402725697, 0.03983234986662865, -0.08631429821252823, 0.012866223230957985, 0.09874826669692993, 0.0038095538038760424, 0.025232622399926186, -0.10001347213983536, 0.02785658836364746, 0.08270930498838425, 0.04315650463104248, 0.1103706955909729, 0.04706093296408653, 0.044699475169181824, 0.06787143647670746, -0.03408770263195038, -0.014014199376106262, -0.007021045777946711, -0.022922175005078316, -0.04201755300164223, 0.03278731554746628, -0.02808319963514805, 0.0029120254330337048, -0.10922642052173615, -0.013884305953979492, -0.08303698897361755, -0.032861512154340744, 0.007954898290336132, 0.012841949239373207, 0.04963705688714981, 0.020603874698281288, -0.06075455993413925, 0.14331085979938507, -0.028040781617164612, -0.023630628362298012, 0.004591813310980797, -0.022239595651626587, 0.04507597163319588, 0.05562594160437584, 0.05071215704083443, 0.03678653761744499, -0.020487762987613678, -0.01864270307123661, -0.04242027923464775, 0.04813972860574722, 0.05565543472766876, 0.009163826704025269, 0.01639556884765625, -0.01229894906282425, 0.024286622181534767, 0.005312521476298571, -0.05331089720129967, 0.05159882456064224, 0.05847221612930298, 0.028600413352251053, 0.052648305892944336, -0.016795381903648376, -0.05388064682483673, 0.05841818451881409, -0.0038443671073764563, -0.03546488285064697, -0.05297498404979706, -0.04386361688375473, 0.06451205909252167, -0.009828389622271061, -0.04665381833910942, 0.05191803351044655, 0.034917932003736496, 0.03528425842523575, -0.013083990663290024, -0.015482814982533455, -0.022184578701853752, -0.01488284207880497, -0.0233442522585392, -0.008910765871405602, -0.03395473212003708, 0.035964470356702805, -0.032525692135095596, 0.030329346656799316, -0.055469512939453125, -0.0047722384333610535, 0.005805117078125477, -0.01710375025868416, 0.0018102785106748343, 0.01833256706595421, 0.04291529580950737, 0.02039111778140068, -0.006612644996494055, 0.04732494801282883, -0.034183189272880554, -0.03333882614970207, -0.0337698869407177, 0.0007364964112639427, -0.023282071575522423, 0.026805471628904343, 0.03379347547888756, 0.06096220016479492, -0.02649124711751938, -0.02355942688882351, -0.020719468593597412, -0.024326523765921593, 0.04464730992913246, 0.021790608763694763, 0.025314878672361374, -0.00838564895093441, -0.021075518801808357, 0.025653857737779617, -0.013823426328599453, -0.0339958593249321, 0.012117365375161171, -0.010717655532062054, -0.007247332949191332, -0.02143356204032898, 0.010616619139909744, -0.042107630521059036, -0.008432963863015175, -0.01257482822984457, 0.02262662537395954, 0.022783301770687103, 0.054444704204797745, -0.10095477849245071, 0.019630881026387215, 0.0339745357632637, 0.026362981647253036, -0.013980020768940449, 0.024811556562781334, 0.05823613703250885, -0.017541805282235146, -0.035195376724004745, -0.0068720984272658825, -0.014119364321231842, -0.01935528963804245, 0.018435265868902206, -0.010267387144267559, -0.012802560813724995, 0.010313743725419044, 0.008880862034857273, -0.011351541616022587, 0.007667121011763811, 0.042892936617136, -0.013616912998259068, 0.011722185648977757, -0.004129438195377588, -0.034641947597265244, -0.05771363526582718, -0.017728056758642197, 0.06271295994520187, 0.04234879091382027, 0.021616941317915916, -0.03719769045710564, -0.03099938854575157, 0.00005068322570878081, 0.006667650304734707, 0.01773945800960064, -0.034217629581689835, -0.014087267220020294, 0.018109111115336418, 0.0647507905960083, 0.028346460312604904, 0.03960830718278885, 0.040365587919950485, -0.03925950825214386, 0.03955089673399925, -0.025842346251010895, 0.029948189854621887, 0.028600890189409256, 0.04619871452450752, -0.015959730371832848, 0.04749422147870064, -0.060112711042165756, 0.005365048535168171, 0.02313372679054737, -0.0064627667888998985, 0.08048544824123383, 0.013383666053414345, 0.00004300177897675894, 0.0013593222247436643, -0.0022633878979831934, 0.022156696766614914, -0.02360188402235508, -0.03572605177760124, 0.03185901790857315, -0.0390375591814518, 0.0024356709327548742, -0.015131502412259579, 0.09774676710367203, -0.004541357513517141, 0.002101263264194131, -0.007672986947000027, 0.034136123955249786, -0.027430051937699318, 0.05104246735572815, -0.007583907805383205, -0.0018536864081397653, -0.030191490426659584, -0.028217066079378128, -0.03940116614103317, -0.007980273105204105, 0.05639905482530594, 0.05260283127427101, -0.04290669411420822, -0.04836560785770416, -0.03980874642729759, -0.0546271838247776, 0.029202008619904518, 0.02343096397817135, -0.023337192833423615, -0.02964046224951744, -0.0013706507161259651, 0.011082134209573269, 0.0013802213361486793, -0.018262455239892006, 0.013983954675495625, 0.02668960951268673, 0.01628376916050911, -0.010777687653899193, 0.05075491592288017, 0.026681730523705482, 0.041500117629766464, -0.012547751888632774, 0.014206280000507832, -0.022929901257157326, 0.012723498046398163, -0.02672620303928852, -0.0026949814055114985, 0.029756218194961548, -0.047470636665821075, -0.010935517027974129, -0.05012434348464012, -0.007815005257725716, 0.029672792181372643, -0.013926154933869839, 0.01512220874428749, 0.009137915447354317, 0.02982248179614544, 0.020865824073553085, 0.0035036057233810425, -0.018789101392030716, -0.037913545966148376, -0.0041541289538145065, -0.009153212420642376, -0.01596537046134472, 0.007591609843075275, 0.006824351381510496, -0.00016028473328333348, -0.00441166153177619, -0.021597130224108696, 0.03555971756577492, -0.009504471905529499, -0.0023820677306503057, -0.029734022915363312, -0.034064773470163345, -0.06355751305818558, 0.02145509235560894, 0.024004554376006126, 0.009124765172600746, 0.003225908614695072, 0.033784329891204834, -0.030716465786099434, -0.055300094187259674, -0.019028564915060997, 0.015179439447820187, 0.027269886806607246, -0.017932375892996788, 0.04074391350150108, -0.016642767935991287, -0.011493290774524212, -0.028511755168437958, -0.02110123261809349, -0.002747809048742056, 0.029077433049678802, 0.000042238702008035034, -0.0512707382440567, 0.04003789648413658, 0.024460474029183388, 0.004202135372906923, -0.0019451681291684508, 0.033109210431575775, 0.005126829259097576, 0.06054956838488579, -0.03168404474854469, -0.01667148992419243, -0.06304824352264404, 0.04507983848452568, 0.0043066381476819515, -0.02225870080292225, -0.0070815845392644405, -0.05261409655213356, 0.00959049817174673, 0.02756209298968315, 0.0022442652843892574, -0.05191986635327339, 0.016001153737306595, -0.009094247594475746, 0.040360335260629654, -0.010713587515056133, -0.017381126061081886, 0.04454924911260605, 0.025441035628318787, 0.0301787368953228, -0.021785248070955276, -0.040516436100006104, 0.010486148297786713, 0.008857478387653828, 0.03125173598527908, 0.0034039511810988188, 0.02652052231132984, 0.031037794426083565, 0.0010537937050685287, 0.01290344912558794, 0.0001499252684880048, -0.01662910357117653, 0.006028413772583008, -0.021016055718064308, -0.01523037999868393, 0.016075439751148224, 0.04895490035414696, 0.01101774349808693, -0.016163108870387077, 0.026897957548499107, -0.003872168716043234, 0.053929299116134644, 0.0033478420227766037, -0.03833790123462677, 0.029546795412898064, 0.015224830247461796, -0.02391904778778553, -0.050370413810014725, 0.03676373139023781, -0.03212660923600197, -0.022901572287082672, -0.013151557184755802, -0.046645164489746094, -0.018444836139678955, 0.013583245687186718, 0.0017855761107057333, 0.010591951198875904, 0.025348620489239693, 0.019971422851085663, 0.050271160900592804, -0.011316260322928429, -0.0021771180909126997, 0.013958802446722984, -0.02497052028775215, 0.004288678057491779, 0.004310548305511475, 0.0012489999644458294, 0.017343034967780113, 0.05812946334481239, 0.033293403685092926, 0.027920285239815712, 0.018224360421299934, -0.022975942119956017, 0.030086180195212364, -0.021760785952210426, -0.02983563020825386, 0.010290195234119892, 0.033524200320243835, 0.03182724863290787, -0.01761234737932682, 0.02015693672001362, -0.02148696593940258, -0.015896718949079514, -0.005851136054843664, -0.04025743156671524, 0.06280923634767532, 0.05514361709356308, -0.011876720935106277, 0.010754810646176338, -0.014469385147094727, 0.04417360946536064, -0.010198873467743397, 0.026827020570635796, 0.009902671910822392, -0.00012174202129244804, 0.021764390170574188, -0.009673938155174255, -0.011647171340882778, 0.017257804051041603, 0.013332011178135872, 0.004405029118061066, -0.027940312400460243, -0.0011148335179314017, 0.014993643388152122, -0.0401228703558445, -0.010175352916121483, 0.010919957421720028, -0.030495913699269295, 0.051681745797395706, 0.06280287355184555, 0.0073248036205768585, 0.011848765425384045, -0.013182658702135086, 0.012275570072233677, -0.045173149555921555, 0.025751708075404167, -0.0014158134581521153, 0.06760931760072708, 0.013238281011581421, 0.018404969945549965, 0.018761111423373222, 0.010219874791800976, 0.03917453810572624, -0.009855193085968494, -0.02596665732562542, 0.011202150024473667, 0.05333361029624939, 0.005060158669948578, -0.011757063679397106, 0.015452533029019833, -0.005425720941275358, -0.05464877188205719, -0.04328150302171707, -0.0007372997351922095, -0.025437254458665848, 0.044073402881622314, 0.03938724473118782, -0.007524106185883284, 0.009354839101433754, -0.0172759797424078, 0.05540546774864197, 0.04513879120349884, -0.024233773350715637, 0.001611490617506206, -0.015072360634803772, 0.044471267610788345, -0.0019415180431678891, 0.01679064705967903, 0.04455926641821861, -0.03626019135117531, 0.004035658668726683, 0.045929886400699615, -0.002048347843810916, 0.030774012207984924, -0.01744769886136055, -0.013448921032249928, -0.030457360669970512, -0.048755284398794174, -0.0010487806284800172, 0.030028263106942177, 0.01996334083378315, -0.019337741658091545, 0.030794944614171982, 0.008754437789320946, -0.010247820988297462, 0.04432220011949539, 0.000381914374884218, 0.011420387774705887, -0.0032799704931676388, -0.03398941084742546, 0.009098554030060768, 0.04937677085399628, -0.02219417504966259, -0.022626755759119987, -0.02961776778101921, -0.005925860721617937, -0.02087154984474182, 0.006971242371946573, -0.009055630303919315, -0.036054305732250214, 0.02674129046499729, -0.0019861645996570587, 0.008876737207174301, 0.04332531988620758, -0.021010903641581535, -0.01640835963189602, -0.0032255311962217093, 0.013220835477113724, -0.05814157798886299, -0.0027849841862916946, -0.003057963214814663, 0.024412300437688828, -0.0034604347310960293, 0.02223741076886654, -0.04389272257685661, -0.02947726473212242, 0.04694546386599541, -0.0509057380259037, 0.00493454048410058, -0.02298794873058796, 0.018764019012451172, 0.0428212471306324, 0.016941223293542862, -0.008107422851026058, -0.014779582619667053, -0.04268000274896622, -0.030178753659129143, 0.006961388047784567, 0.04593805968761444, 0.01777605526149273, -0.011645360849797726, -0.029298463836312294, -0.008524180389940739, -0.02066962979733944, -0.023609934374690056, 0.0014839011710137129, 0.010534693486988544, -0.0019675104413181543, -0.03412867709994316, -0.021221967414021492, 0.0356978103518486, 0.031671855598688126, 0.020382512360811234, 0.006402014289051294, 0.00418815715238452, 0.04394557327032089, -0.02331913448870182, 0.04270236939191818, -0.005152693018317223, 0.04026496782898903, -0.02179727517068386, -0.03510015457868576, -0.06936226785182953, 0.030889643356204033, -0.024907344952225685, -0.0018090031808242202, -0.022133976221084595, 0.008837591856718063, -0.0325193852186203, 0.006520678289234638, -0.017081892117857933, -0.0037770026829093695, 0.0600115992128849, 0.013442888855934143, 0.01135742012411356, 0.03616980463266373, -0.010892639867961407, -0.013879661448299885, -0.024788856506347656, 0.03676752373576164, 0.0437563993036747, 0.004545608069747686, -0.013565623201429844, -0.027182765305042267, 0.03147603198885918, -0.02444452792406082, -0.035633400082588196, 0.007779483217746019, 0.04442569613456726, 0.007454076316207647, -0.050651080906391144, 0.0020897879730910063, -0.005167531315237284, 0.043676361441612244, 0.02812190167605877, 0.0020581979770213366, -0.038911573588848114, 0.014424430206418037, 0.014722873456776142, -0.023122575134038925, -0.02581264264881611, -0.0028669238090515137, 0.02291184477508068, 0.021143881604075432, 0.0205384511500597, 0.0207764133810997, 0.025876503437757492, -0.004468479659408331, 0.03273783624172211, -0.009827700443565845, -0.041386839002370834, -0.04722031205892563, -0.0012286186683923006, -0.018153322860598564, -0.037797704339027405, -0.010964252054691315, 0.05479158088564873, 0.023757625371217728, 0.008745207451283932, -0.059694476425647736, 0.003190848743543029, 0.005609956104308367, -0.04308667778968811, 0.022185413166880608, 0.028159014880657196, 0.03683263435959816, 0.04788273200392723, 0.04562011733651161, -0.003670615144073963, 0.004003702197223902 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Evaluation In a final step, we might want to evaluate the BERT2BERT model on the test data. To start, instead of loading the dummy model, let\'s load a BERT2BERT model that was finetuned on the full training dataset. Also, we load its tokenizer, which is just a copy of bert-base-cased\'s tokenizer. python from transformers import BertTokenizer bert2bert = EncoderDecoderModel.from_pretrained("patrickvonplaten/bert2bert_cnn_daily_mail").to("cuda") tokenizer = BertTokenizer.from_pretrained("patrickvonplaten/bert2bert_cnn_daily_mail") Next, we load just 2% of CNN/Dailymail\'s test data. For the full evaluation, one should obviously use 100% of the data. python test_data = datasets.load_dataset("cnn_dailymail", "3.0.0", split="test[:2%]") Now, we can again leverage 🤗dataset\'s handy map() function to generate a summary for each test sample. For each data sample we: - first, tokenize the "article", - second, generate the output token ids, and - third, decode the output token ids to obtain our predicted summary. python def generate_summary(batch): # cut off at BERT max length 512 inputs = tokenizer(batch["article"], padding="max_length", truncation=True, max_length=512, return_tensors="pt") input_ids = inputs.input_ids.to("cuda") attention_mask = inputs.attention_mask.to("cuda") outputs = bert2bert.generate(input_ids, attention_mask=attention_mask) output_str = tokenizer.batch_decode(outputs, skip_special_tokens=True) batch["pred_summary"] = output_str return batch Let\'s run the map function to obtain the results dictionary that has the model\'s predicted summary stored for each sample. Executing the following cell may take ca. 10min ☕. python batch_size = 16 # change to 64 for full evaluation results = test_data.map(generate_summary, batched=True, batch_size=batch_size, remove_columns=["article"]) Finally, we compute the ROUGE score. python rouge.compute(predictions=results["pred_summary"], references=results["highlights"], rouge_types=["rouge2"])["rouge2"].mid python OUTPUT: ------- Score(precision=0.10389454113300968, recall=0.1564771201053348, fmeasure=0.12175271663717585) That\'s it. We\'ve shown how to warm-start a BERT2BERT model and fine-tune/evaluate it on the CNN/Dailymail dataset. The fully trained BERT2BERT model is uploaded to the 🤗model hub under patrickvonplaten/bert2bert_cnn_daily_mail. The model achieves a ROUGE-2 score of 18.22 on the full evaluation data, which is even a little better than reported in the paper. For some summarization examples, the reader is advised to use the online inference API of the model, here. Thanks a lot to Sascha Rothe, Shashi Narayan, and Aliaksei Severyn from Google Research, and Victor Sanh, Sylvain Gugger, and Thomas Wolf from 🤗Hugging Face for proof-reading and giving very much appreciated feedback.
[ 0.013857117854058743, -0.02165142446756363, -0.002261004876345396, 0.025782126933336258, -0.006795905996114016, 0.06346135586500168, 0.0474078506231308, 0.018716782331466675, -0.021197117865085602, -0.010339569300413132, -0.05699083209037781, 0.0056144241243600845, 0.003774014301598072, 0.03265010565519333, -0.01866547018289566, -0.004652572330087423, 0.0985645055770874, -0.06097477674484253, 0.011364963836967945, 0.03293057903647423, -0.014366618357598782, -0.07588645815849304, 0.035704925656318665, 0.023465575650334358, 0.0233164019882679, -0.023262664675712585, 0.031782545149326324, -0.0017295406432822347, -0.027050727978348732, 0.03557969629764557, -0.12928085029125214, -0.00652793375775218, -0.017508722841739655, 0.007883870042860508, -0.06766968220472336, 0.005467431619763374, -0.07268650829792023, 0.03536645323038101, 0.06431354582309723, -0.0075990851037204266, -0.002333232667297125, 0.007154211867600679, -0.05106431990861893, 0.007733134552836418, -0.00644115824252367, -0.011405346915125847, -0.14781762659549713, 0.07569795101881027, -0.004120717756450176, -0.05544109269976616, -0.03543640300631523, 0.10468067228794098, -0.03575553745031357, -0.005605269223451614, -0.004934478085488081, -0.008379917591810226, 0.004972983617335558, -0.040161121636629105, 0.05208398401737213, 0.01443670503795147, 0.03138156235218048, -0.004446466453373432, 0.03697780892252922, 0.04523611068725586, 0.031203649938106537, 0.031176503747701645, 0.01786652021110058, 0.019117094576358795, -0.061807651072740555, -0.055756501853466034, -0.010163961909711361, -0.07723651826381683, -0.04236004874110222, 0.004057265352457762, 0.027393119409680367, -0.09371209144592285, -0.0035293318796902895, -0.028769390657544136, 0.029705127701163292, 0.09456533193588257, -0.041125863790512085, 0.02128208987414837, -0.04032287001609802, -0.0029887512791901827, 0.042717259377241135, 0.030274083837866783, 0.0407235287129879, -0.06945863366127014, -0.06706056743860245, 0.06371928006410599, -0.06089990586042404, -0.11786766350269318, -0.011577128432691097, -0.03665750473737717, 0.006240437272936106, -0.049752719700336456, 0.02629905194044113, 0.0005071295308880508, 0.004101949743926525, -0.043892256915569305, 0.05431720241904259, -0.07424736768007278, 0.009888689033687115, -0.026202533394098282, -0.1267736852169037, 0.005372979212552309, -0.012146788649260998, -0.10545693337917328, 0.0008752539870329201, 0.02841929905116558, 0.023419296368956566, -0.03575623780488968, -0.04864273965358734, 0.054283831268548965, -0.08783672749996185, -0.04555995389819145, -0.032984521239995956, 0.047101303935050964, -0.018639450892806053, 0.021431103348731995, -0.003140993183478713, 0.08772137016057968, 0.07512795925140381, -0.049873512238264084, -0.004724080674350262, -0.008520242758095264, -0.005685740616172552, 0.021402936428785324, 0.012700356543064117, 0.031725890934467316, 0.011687389574944973, 0.00415824307128787, 0.06064087152481079, 0.02846265584230423, -0.021357044577598572, -0.023384548723697662, -0.04370332881808281, -0.06271377205848694, 0.00019502907525748014, -0.03664247691631317, -0.03578728437423706, 0.062129609286785126, -0.017332544550299644, 0.03592279553413391, 0.036102309823036194, -0.010062561370432377, -0.06699396669864655, 0.09591364115476608, 0.029757730662822723, 0.032237909734249115, -0.11158459633588791, 0.05475110560655594, -0.031528692692518234, -0.02904106304049492, 0.04897577688097954, 0.07056934386491776, -0.01768733188509941, -0.046064626425504684, -0.11519401520490646, 0.015371411107480526, 0.03540539741516113, 0.056001611053943634, -0.03760917857289314, -0.010168193839490414, -0.011932886205613613, -0.020636042580008507, 0.02933746762573719, 0.002847955096513033, 0.0446164533495903, 0.015728885307908058, -0.0013611858012154698, -0.008869236335158348, 0.055133771151304245, -0.005989964120090008, 0.012529403902590275, 0.05160271003842354, 0.05467243120074272, 0.02135756053030491, -0.00259110308252275, -0.01637020707130432, -0.0854729562997818, 0.05580779165029526, 0.0018963688053190708, 0.037353113293647766, 0.0876525267958641, -0.09534633904695511, 0.02435581013560295, -0.017407450824975967, -0.009149582125246525, 0.07814683020114899, -0.02938293293118477, -0.0020065593998879194, 0.03607746586203575, -0.0724785178899765, 0.023861918598413467, -0.03953249379992485, -0.032145142555236816, 0.0977504700422287, 0.03455990180373192, 0.04974294453859329, 0.0028474503196775913, 0.022452840581536293, 0.037465572357177734, -0.04452276974916458, 0.014700728468596935, -0.04332125559449196, 0.002818154403939843, -0.08145289868116379, 0.041310444474220276, 0.04509824886918068, 0.0426437072455883, -0.0610295869410038, 0.03814583644270897, -0.10952737182378769, -0.047794122248888016, -0.035569529980421066, -0.013303779065608978, 0.036853089928627014, 0.02048799954354763, -0.054169874638319016, 0.13250665366649628, -0.04061461612582207, 0.023113958537578583, -0.06516674160957336, -0.06686858087778091, 0.03954864293336868, 0.0376703143119812, 0.008568198420107365, 0.0641472265124321, -0.057364705950021744, -0.06044521927833557, -0.04292495921254158, 0.006213903892785311, 0.03284410014748573, -0.045597873628139496, -0.05315638706088066, -0.05956151708960533, 0.023182692006230354, 0.020196454599499702, -0.024746589362621307, -0.011380655691027641, 0.004612401127815247, 0.012848412618041039, 0.10705012083053589, -0.0642043873667717, 0.019851522520184517, 0.015694139525294304, 0.0023695523850619793, -0.05112692713737488, -0.03589218109846115, 0.013902286998927593, 0.029998013749718666, -0.007205274887382984, -0.058216169476509094, 0.043396223336458206, 0.03372478112578392, -0.030056079849600792, 0.0038494321051985025, -0.031683724373579025, 0.029501475393772125, 0.011539977975189686, -0.039436936378479004, -0.04855255037546158, -0.019850974902510643, -0.012709145434200764, -0.04239802435040474, -0.0024229579139500856, 0.0032864154782146215, -0.01811012253165245, -0.004265124909579754, -0.006626945920288563, 0.0016406028298661113, 0.04185253754258156, 0.011292489245533943, 0.028821690008044243, 0.034293558448553085, 0.03371234983205795, 0.005785712972283363, -0.03057282418012619, -0.014803627505898476, 0.0021129734814167023, -0.035435646772384644, 0.03899618983268738, 0.03724919632077217, 0.027582142502069473, 0.008897455409169197, -0.019874384626746178, -0.021884337067604065, -0.011638428084552288, 0.02519034408032894, 0.0169125497341156, 0.025033630430698395, -0.0055948891676962376, -0.03599919378757477, 0.024684615433216095, 0.034666500985622406, 0.003939792048186064, -0.04765080660581589, 0.000037606037949444726, -0.003108365461230278, -0.033553000539541245, 0.005863838829100132, -0.02438049018383026, -0.014461792074143887, -0.011842264793813229, 0.01914146915078163, 0.029228439554572105, 0.008608468808233738, -0.09856811165809631, 0.014319823123514652, 0.05727102607488632, -0.011207596398890018, -0.0177222341299057, 0.005081105511635542, 0.07559935748577118, 0.01037557888776064, -0.026441309601068497, 0.014217245392501354, 0.020366758108139038, -0.01812686212360859, 0.004687861073762178, 0.0029196792747825384, 0.010920717380940914, -0.028122924268245697, 0.013077919371426105, -0.020013265311717987, 0.0371028371155262, 0.00876507256180048, -0.007917541079223156, 0.02280489169061184, 0.005147947929799557, -0.01043669879436493, -0.011815814301371574, 0.012817636132240295, 0.01337719988077879, 0.05402982234954834, 0.052468571811914444, 0.036477476358413696, -0.019358262419700623, -0.03244412690401077, -0.004220960196107626, -0.003352675586938858, -0.01830192655324936, 0.004653305280953646, 0.013155290856957436, 0.01973220519721508, -0.015982074663043022, 0.010220224969089031, 0.016725633293390274, -0.027427515015006065, 0.014647095464169979, -0.018891509622335434, -0.0003501474275253713, -0.030245976522564888, 0.017306068912148476, -0.04205545037984848, 0.0007638534880243242, -0.036680325865745544, -0.029893698170781136, -0.009851154871284962, -0.020452206954360008, 0.05719741806387901, -0.013303807005286217, -0.014458958990871906, 0.004202027805149555, 0.01265990175306797, 0.04850754141807556, -0.01701250672340393, -0.019179247319698334, 0.0017687598010525107, 0.006988084875047207, 0.010471351444721222, -0.01587596908211708, 0.027254967018961906, 0.0024132460821419954, -0.006206495687365532, -0.019152728840708733, 0.04873950034379959, 0.010407336056232452, 0.03532019630074501, 0.023762766271829605, 0.00324449734762311, -0.0012730922317132354, 0.03154129907488823, -0.002639319282025099, -0.02428065799176693, 0.03385272994637489, -0.0047154612839221954, -0.015195519663393497, -0.018793916329741478, -0.012405880726873875, 0.02144351415336132, -0.015682153403759003, 0.0233612023293972, 0.0005841696402058005, -0.01571742445230484, 0.029589541256427765, 0.012160763144493103, 0.0368855744600296, -0.020374564453959465, 0.006258834153413773, 0.0030963411554694176, -0.026539523154497147, -0.015099630691111088, 0.007890063337981701, 0.004400570876896381, -0.005056250374764204, -0.004818114917725325, 0.018872197717428207, -0.03714791685342789, 0.00016707248869352043, 0.004687786102294922, 0.018842369318008423, 0.021588530391454697, -0.07439721375703812, -0.04083005711436272, 0.014043757691979408, -0.01072716899216175, 0.023094693198800087, -0.01049092784523964, -0.026984622702002525, 0.0015268790302798152, 0.05461949110031128, 0.050243549048900604, 0.017216257750988007, -0.03185020759701729, 0.001293335109949112, 0.0431654155254364, -0.03528915345668793, 0.04004804417490959, 0.026806998997926712, -0.013228042051196098, 0.03856195509433746, -0.007276974618434906, 0.02697204239666462, 0.05005341023206711, 0.02804652601480484, -0.032002080231904984, -0.05869227647781372, -0.005293972324579954, 0.010593084618449211, -0.021530885249376297, 0.011958896182477474, 0.02803204394876957, 0.008293616585433483, -0.027978507801890373, 0.00599328801035881, -0.03207233548164368, 0.021657781675457954, -0.01251337118446827, 0.0056064254604279995, -0.017149657011032104, 0.023358054459095, -0.015344888903200626, -0.024412624537944794, -0.03340141847729683, -0.0454835519194603, -0.012229952029883862, 0.0384279303252697, -0.010450094938278198, -0.08878684043884277, 0.01231776736676693, 0.04764251410961151, 0.0092000812292099, 0.017890743911266327, 0.039651211351156235, 0.034982845187187195, 0.03385588899254799, -0.03883318975567818, -0.005183809902518988, -0.02525324560701847, 0.013731773942708969, 0.020913058891892433, -0.02455771528184414, 0.005654526874423027, -0.08652523159980774, 0.027969317510724068, -0.0021375115029513836, -0.025064200162887573, -0.00027286860859021544, -0.015245608985424042, -0.005946352146565914, 0.03769874945282936, 0.04032231867313385, 0.00588645413517952, 0.002615252509713173, -0.0015851446660235524, 0.01251189410686493, 0.0018621758790686727, -0.041163600981235504, 0.007293053902685642, 0.003954949788749218, 0.014825201593339443, 0.03250356763601303, 0.003039227332919836, 0.04516606405377388, -0.01721789687871933, 0.023857520893216133, 0.0011559724807739258, -0.012953965924680233, -0.008666908368468285, -0.04793126881122589, -0.012379875406622887, 0.026582321152091026, -0.00982334092259407, 0.015836305916309357, -0.04560735821723938, -0.0036292411386966705, 0.028045427054166794, 0.02507493458688259, -0.023109789937734604, -0.0029588905163109303, 0.0315185971558094, 0.00042277248576283455, 0.01216871477663517, -0.06222081929445267, 0.04324207827448845, -0.022866809740662575, 0.019629554823040962, 0.009979857131838799, -0.026877328753471375, 0.03443843498826027, 0.027956178411841393, -0.01160275936126709, -0.020161492750048637, 0.04763314872980118, 0.01997477374970913, 0.021507617086172104, -0.03821682929992676, -0.040674544870853424, -0.009230225346982479, 0.021646449342370033, 0.011091606691479683, -0.05887565761804581, 0.011882422491908073, -0.017230913043022156, 0.002668807515874505, 0.05527658760547638, 0.04657194763422012, 0.0036126417107880116, 0.0017886406276375055, 0.060461390763521194, -0.006865523289889097, -0.004732288885861635, 0.00801504123955965, 0.06182045489549637, 0.007709020283073187, -0.013959263451397419, -0.0035090006422251463, -0.032778333872556686, -0.0317656435072422, 0.02111477591097355, -0.0384751595556736, 0.027517169713974, 0.023305652663111687, -0.006735500879585743, 0.06194343417882919, 0.017244618386030197, 0.008654480800032616, 0.03686543181538582, -0.032444071024656296, 0.037066277116537094, -0.009235916659235954, 0.017366185784339905, -0.0110778221860528, -0.013360543176531792, 0.04539324343204498, 0.05765801668167114, 0.028091318905353546, -0.031942203640937805, 0.020295260474085808, 0.008723542094230652, -0.003764402586966753, 0.033269722014665604, -0.013295336626470089, -0.030393408611416817, -0.008043170906603336, 0.015171550214290619, 0.028000064194202423, 0.04929802566766739, 0.008937877602875233, 0.035073552280664444, 0.05437536910176277, 0.00848078541457653, -0.02219397947192192, 0.024675676599144936, -0.029518352821469307, 0.033934012055397034, 0.01796145737171173, 0.033398423343896866, 0.013065097853541374, 0.024512246251106262, 0.011061037890613079, -0.022108333185315132, 0.05724369361996651, -0.007598681375384331, -0.028804317116737366, 0.01435411162674427, 0.035788413137197495, -0.015602990984916687, -0.017564527690410614, -0.04661312326788902, -0.020966816693544388, -0.01495048776268959, 0.03857692331075668, -0.014088413678109646, 0.026866169646382332, -0.010985936969518661, 0.03956645727157593, 0.05975516140460968, 0.02493187226355076, -0.024295473471283913, 0.02090827003121376, 0.05149628967046738, 0.006699467543512583, 0.018025469034910202, 0.034113962203264236, 0.016759773716330528, -0.015728358179330826, 0.05921132117509842, -0.0035041263327002525, 0.010067321360111237, 0.04234622046351433, -0.028397077694535255, 0.011415936052799225, -0.03008336015045643, -0.03801453113555908, 0.03495505452156067, 0.008828363381326199, -0.019278092309832573, -0.005679342430084944, 0.04093644395470619, -0.05345539748668671, 0.012597817927598953, -0.026249565184116364, -0.03570368513464928, -0.03911498561501503, -0.03590475022792816, -0.021498244255781174, 0.08632192760705948, -0.00443600257858634, -0.05557387322187424, 0.03014521487057209, 0.02226732112467289, 0.03178638964891434, 0.03775392845273018, -0.010292505845427513, -0.023376399651169777, -0.033487141132354736, 0.007585593964904547, -0.04288918524980545, 0.02537163905799389, -0.044327717274427414, 0.04580221697688103, 0.03239961341023445, 0.011326124891638756, 0.021495556458830833, 0.026569683104753494, 0.033181559294462204, 0.03304089978337288, -0.003570971079170704, 0.02804815024137497, 0.02653960883617401, -0.026435771957039833, 0.025574328377842903, -0.08017782121896744, -0.04028315469622612, 0.002731307176873088, 0.03892187774181366, 0.03907931223511696, 0.03235281631350517, -0.013079946860671043, -0.011480904184281826, -0.012561353854835033, -0.00887754000723362, -0.0642886608839035, 0.027330422773957253, 0.025853468105196953, 0.030401231721043587, 0.020535429939627647, -0.0003577712632250041, -0.023798413574695587, 0.0013000357430428267, -0.021471548825502396, 0.025975964963436127, -0.006288700271397829, -0.011708362028002739, -0.020593490451574326, 0.04666450247168541, 0.00806584395468235, 0.0223630852997303, 0.03574546426534653, 0.0016105278627946973, 0.0394357405602932, -0.006170934997498989, 0.03176382556557655, -0.056221865117549896, -0.01739928126335144, -0.025344854220747948, -0.03253215178847313, -0.021735459566116333, 0.020531196147203445, -0.06428992748260498, 0.03344278782606125, -0.04103052243590355, -0.018872270360589027, -0.04222135245800018, 0.00011722523049684241, -0.044413670897483826, -0.00671530282124877, 0.057628195732831955, 0.019745009019970894, 0.05536793917417526, 0.02585829608142376, -0.06086831912398338, 0.005263526923954487, -0.03807493671774864, 0.01785506308078766, 0.03197718411684036, 0.02144140750169754, -0.01734963245689869, 0.01432368066161871, -0.007504371926188469, 0.034138694405555725, -0.03068695403635502, 0.02603202499449253, 0.022782733663916588, 0.004678559023886919, -0.0033235440496355295, 0.02369670197367668, 0.04315609112381935, -0.0019322038860991597, 0.03038160875439644, -0.0011005840497091413, -0.009329427033662796, -0.04667409136891365, 0.034444354474544525, -0.07073976844549179, -0.008300738409161568, -0.024896152317523956, -0.010645848698914051, 0.03696371614933014, 0.018098313361406326, 0.036647599190473557, 0.01306072622537613, -0.00561863137409091, -0.019213739782571793, 0.0031040851026773453, -0.038961261510849, -0.03442965820431709, 0.018120961263775826, 0.045487526804208755, -0.0450952984392643, -0.009952264837920666, 0.04180575907230377, 0.025656336918473244, -0.007285383529961109, 0.00520276976749301, 0.0070071956142783165, 0.045634929090738297, -0.006814967840909958, 0.004205233417451382, -0.028700310736894608, 0.049873773008584976, 0.019906355068087578, 0.006118342280387878, 0.030055653303861618, 0.022291606292128563 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
# Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models Transformer-based encoder-decoder models were proposed in Vaswani et al. (2017) and have recently experienced a surge of interest, e.g. Lewis et al. (2019), Raffel et al. (2019), Zhang et al. (2020), Zaheer et al. (2020), Yan et al. (2020). Similar to BERT and GPT2, massive pre-trained encoder-decoder models have shown to significantly boost performance on a variety of sequence-to-sequence tasks Lewis et al. (2019), Raffel et al. (2019). However, due to the enormous computational cost attached to pre-training encoder-decoder models, the development of such models is mainly limited to large companies and institutes. In Leveraging Pre-trained Checkpoints for Sequence Generation Tasks (2020), Sascha Rothe, Shashi Narayan and Aliaksei Severyn initialize encoder-decoder model with pre-trained encoder and/or decoder-only checkpoints (e.g. BERT, GPT2) to skip the costly pre-training. The authors show that such warm-started encoder-decoder models yield competitive results to large pre-trained encoder-decoder models, such as T5, and Pegasus on multiple sequence-to-sequence tasks at a fraction of the training cost. In this notebook, we will explain in detail how encoder-decoder models can be warm-started, give practical tips based on Rothe et al. (2020), and finally go over a complete code example showing how to warm-start encoder-decoder models with 🤗Transformers. This notebook is divided into 4 parts: - Introduction - Short summary of pre-trained language models in NLP and the need for warm-starting encoder-decoder models. - Warm-starting encoder-decoder models (Theory) - Illustrative explanation on how encoder-decoder models are warm-started? - Warm-starting encoder-decoder models (Analysis) - Summary of Leveraging Pre-trained Checkpoints for Sequence Generation Tasks (2020) - What model combinations are effective to warm-start encoder-decoder models; How does it differ from task to task? - Warm-starting encoder-decoder models with 🤗Transformers (Practice) - Complete code example showcasing in-detail how to use the EncoderDecoderModel framework to warm-start transformer-based encoder-decoder models. It is highly recommended (probably even necessary) to have read this blog post about transformer-based encoder-decoder models. Let\'s start by giving some back-ground on warm-starting encoder-decoder models.
[ 0.010919067077338696, 0.007983028888702393, -0.027393274009227753, -0.005060385912656784, 0.03850913792848587, 0.10784550756216049, 0.032658740878105164, 0.005974307656288147, -0.008052779361605644, -0.01014232449233532, -0.05896249786019325, 0.06563323736190796, -0.038595546036958694, 0.05234162509441376, 0.007817743346095085, -0.06914982944726944, 0.01624542661011219, -0.07549894601106644, -0.016726812347769737, -0.02788296341896057, 0.018746454268693924, -0.04978594556450844, 0.028502220287919044, 0.012722866609692574, 0.0463402234017849, -0.037618812173604965, -0.0034692753106355667, -0.017910201102495193, 0.0006107413792051375, 0.056719329208135605, -0.07619387656450272, 0.02372114360332489, 0.03793967515230179, -0.011958972550928593, 0.04084337502717972, 0.004187298007309437, -0.08680769801139832, 0.030569730326533318, 0.03445053473114967, -0.03082282654941082, -0.05857830122113228, 0.0021282536908984184, -0.030161388218402863, 0.0030012503266334534, -0.04535139352083206, -0.02328898198902607, -0.14008444547653198, 0.04020335525274277, -0.018268296495079994, -0.062071166932582855, -0.07057680934667587, 0.07089574635028839, 0.013494185172021389, 0.047574128955602646, -0.027578899636864662, 0.006020641885697842, -0.026746902614831924, -0.08908075839281082, 0.030595777556300163, -0.02585000917315483, 0.043867941945791245, 0.04893377050757408, -0.005738673731684685, -0.004822765942662954, 0.04203253984451294, 0.008984568528831005, -0.01998136378824711, 0.06987089663743973, -0.042978107929229736, -0.024605754762887955, -0.027749117463827133, -0.060733020305633545, -0.041618552058935165, 0.03930584713816643, -0.009265853092074394, -0.04017427936196327, 0.023332374170422554, -0.0012973626144230366, -0.0027444122824817896, 0.004947274457663298, -0.025911670178174973, 0.058257464319467545, -0.02483844943344593, -0.029275698587298393, 0.06095874682068825, 0.029355891048908234, 0.07524769753217697, -0.07209620624780655, -0.03418181836605072, 0.051425751298666, 0.0015804462600499392, -0.12101160734891891, 0.0030604321509599686, -0.02770867571234703, 0.03291971608996391, 0.018714675679802895, 0.022990750148892403, 0.08662808686494827, -0.009904280304908752, -0.04698534682393074, -0.002302036853507161, -0.06233946979045868, 0.03691854327917099, -0.044827088713645935, -0.05009846389293671, 0.013361995108425617, -0.03837209939956665, -0.05731411278247833, -0.023518061265349388, -0.027253560721874237, 0.05384691804647446, -0.01756279356777668, -0.0814860388636589, 0.037139490246772766, -0.09586949646472931, 0.03032650798559189, 0.007770037278532982, -0.03615787625312805, -0.01323037687689066, 0.032526835799217224, 0.005102678667753935, 0.06625337153673172, 0.045558907091617584, -0.03404555097222328, -0.04573596641421318, 0.06448037922382355, -0.030214812606573105, 0.021324798464775085, 0.03549758344888687, 0.01437446940690279, 0.07090428471565247, -0.01677320897579193, 0.03639312461018562, 0.018187113106250763, 0.016680315136909485, -0.02357485704123974, 0.01413543988019228, -0.04573029652237892, -0.020520327612757683, 0.014733366668224335, -0.11093421280384064, 0.06483606994152069, 0.04974586144089699, -0.10589728504419327, 0.02722932957112789, 0.0004776122805196792, -0.1132822036743164, 0.07445849478244781, 0.07065582275390625, 0.053697288036346436, -0.05939444154500961, 0.015480905771255493, -0.06426278501749039, -0.04442927986383438, 0.009303392842411995, 0.09412024170160294, -0.005659662187099457, -0.0072478787042200565, -0.07458347082138062, -0.051589760929346085, -0.02593875676393509, 0.00370365334674716, -0.040234990417957306, -0.013935895636677742, 0.03342728689312935, -0.08839080482721329, -0.00212381174787879, 0.023619944229722023, 0.012258214876055717, 0.10943504422903061, 0.020370125770568848, 0.03016667813062668, 0.11156991869211197, -0.0008613945101387799, -0.02199365571141243, 0.03612440451979637, -0.016108928248286247, 0.06819790601730347, 0.03330747410655022, -0.02382170408964157, -0.05054419860243797, 0.008013328537344933, -0.02214689739048481, 0.05912279710173607, 0.043534934520721436, -0.06699447333812714, -0.017464404925704002, -0.02889503538608551, -0.09178877621889114, 0.0309608094394207, -0.03812262415885925, 0.04671446606516838, 0.05305587127804756, -0.007188369985669851, -0.007696697022765875, -0.059499744325876236, 0.0019495554734021425, 0.12461494654417038, 0.03921477124094963, 0.07597798854112625, 0.10860606282949448, 0.03418337553739548, 0.06245899200439453, 0.00032736986759118736, -0.04213402047753334, 0.004098963923752308, 0.017482955008745193, -0.042750682681798935, 0.06326793134212494, 0.011859873309731483, 0.047447241842746735, -0.060334645211696625, -0.02454724721610546, -0.054084088653326035, 0.01924530602991581, -0.041705936193466187, -0.01853489689528942, 0.002958659315481782, 0.005149727687239647, -0.03171481564640999, 0.1498556286096573, -0.037399113178253174, -0.026726247742772102, -0.01160389743745327, 0.013910144567489624, 0.024204285815358162, 0.03339472413063049, 0.01976262964308262, 0.07245176285505295, -0.05637815222144127, -0.032655853778123856, -0.09932944178581238, -0.03579437732696533, 0.01380504947155714, -0.022283535450696945, -0.0008601953159086406, -0.0008826642879284918, 0.005292690359055996, 0.04723949730396271, -0.003528804983943701, -0.020482046529650688, -0.013393552042543888, 0.005519228056073189, 0.02111520804464817, 0.0076458086259663105, 0.006482560187578201, 0.04406385123729706, 0.007920295931398869, -0.02299696020781994, -0.028917143121361732, -0.061570316553115845, 0.042797431349754333, 0.0038979884702712297, -0.096446193754673, 0.011413381434977055, 0.06226962432265282, -0.008975793607532978, -0.018065817654132843, -0.0022512918803840876, 0.00035081454552710056, 0.009585797786712646, -0.039898864924907684, -0.07428983598947525, -0.05009462684392929, -0.027168994769454002, -0.03097052127122879, -0.028050541877746582, -0.03988724574446678, 0.004328984301537275, 0.0025621179956942797, 0.03702230378985405, -0.02853003889322281, 0.02773713693022728, 0.029177751392126083, 0.021618936210870743, 0.01152462512254715, -0.010731260292232037, -0.04868777096271515, -0.047472305595874786, -0.03081188164651394, -0.016374584287405014, -0.04340215399861336, 0.005506542045623064, 0.020285220816731453, -0.0014369048876687884, 0.009823521599173546, -0.02148471027612686, -0.009932663291692734, 0.02012220211327076, 0.06149071082472801, -0.003494630102068186, 0.019436420872807503, -0.026807744055986404, -0.008317389525473118, -0.028306180611252785, 0.021061165258288383, 0.00763994175940752, -0.003033940913155675, -0.008519247174263, 0.039152733981609344, -0.0548928827047348, 0.00447619566693902, 0.020886285230517387, -0.0244036503136158, -0.03188198804855347, 0.009363694116473198, 0.03772852197289467, 0.047835368663072586, -0.0848078578710556, -0.02736072428524494, 0.004482456017285585, -0.011539030820131302, -0.018236501142382622, -0.0319027341902256, 0.05296282842755318, -0.04046959802508354, -0.029692865908145905, -0.0035183378495275974, -0.006454815622419119, -0.002553926780819893, 0.008095720782876015, 0.023906810209155083, -0.053068727254867554, -0.005247902125120163, -0.02410121262073517, 0.005375637207180262, 0.019575444981455803, -0.015424508601427078, -0.018773125484585762, -0.011179991066455841, 0.007204374764114618, 0.006768309511244297, -0.028228603303432465, -0.013859542086720467, 0.023234950378537178, -0.00405094213783741, 0.016746673732995987, -0.007855819538235664, -0.027496635913848877, -0.020108459517359734, -0.0046081324107944965, 0.028454791754484177, 0.003881334327161312, -0.027371354401111603, 0.01733586937189102, 0.055197823792696, 0.03530985116958618, 0.01155787706375122, 0.0007337242132052779, -0.022521527484059334, 0.0171827245503664, 0.007535272743552923, 0.015423791483044624, -0.024558154866099358, 0.03653879463672638, -0.06010821461677551, 0.025698387995362282, -0.0024292622692883015, -0.05189777538180351, 0.01483751367777586, 0.0011775607708841562, 0.039611510932445526, 0.029628310352563858, 0.020481524989008904, 0.015520276501774788, 0.012011905200779438, 0.022509394213557243, 0.004321953281760216, -0.041639599949121475, 0.02806374616920948, 0.007855639792978764, -0.021624214947223663, -0.043824661523103714, 0.05599185824394226, 0.00973432045429945, 0.008177891373634338, -0.006272232625633478, 0.06318367272615433, -0.006646322086453438, 0.007149494718760252, 0.023547708988189697, 0.007259585428982973, -0.02827482298016548, 0.020148999989032745, -0.01782483048737049, 0.020583784207701683, 0.06977821886539459, 0.008545421063899994, 0.011339024640619755, -0.014580229297280312, -0.07345573604106903, -0.02459603175520897, 0.028436388820409775, 0.034060634672641754, 0.003942742943763733, -0.011366267688572407, 0.026071570813655853, 0.00070330745074898, 0.03732417896389961, 0.0042065950110554695, -0.002312874887138605, -0.01745540462434292, 0.021218575537204742, -0.01354599092155695, -0.00016411427350249141, 0.03423389047384262, -0.010589725337922573, -0.018724747002124786, 0.003736147191375494, -0.03374818339943886, 0.01584220491349697, 0.024791602045297623, -0.00908071082085371, 0.008571716956794262, -0.020526768639683723, -0.01790844462811947, 0.018040856346488, 0.018063809722661972, 0.004759274888783693, 0.006852961145341396, 0.01017217431217432, 0.02622133120894432, -0.01565016433596611, 0.04581136628985405, 0.01295025460422039, -0.029918599873781204, 0.01875736564397812, 0.0157375019043684, -0.03679341822862625, 0.00706368638202548, -0.004119641613215208, 0.012955795973539352, 0.04316537827253342, -0.03658991679549217, 0.024564750492572784, -0.010668780654668808, 0.002882960019633174, -0.0319717712700367, -0.042630840092897415, -0.013896874152123928, 0.04831555858254433, -0.018251808360219002, -0.01328588929027319, 0.015218015760183334, -0.04699350520968437, 0.004839132074266672, -0.012560379691421986, -0.032454319298267365, 0.014661004766821861, 0.009021934121847153, 0.0238969624042511, -0.015710823237895966, 0.04723326116800308, -0.029976826161146164, 0.0072679342702031136, -0.020902516320347786, 0.025126008316874504, 0.0016487383982166648, 0.041132450103759766, 0.00953733827918768, -0.03166864812374115, 0.005492891184985638, 0.05426739901304245, -0.030468041077256203, -0.012919541448354721, 0.03416990116238594, 0.05585717782378197, 0.011649822816252708, 0.013939650729298592, 0.0179455503821373, -0.06801670044660568, -0.008773304522037506, 0.004862470552325249, -0.014319252222776413, -0.04746408760547638, -0.018809422850608826, 0.007929712533950806, 0.034838829189538956, -0.001348543562926352, -0.036837685853242874, 0.016636455431580544, 0.01080970000475645, 0.011121807619929314, -0.028529291972517967, 0.011776340194046497, 0.016606654971837997, -0.018858008086681366, 0.009648671373724937, 0.025842322036623955, 0.017413679510354996, -0.005072213709354401, 0.0383647121489048, -0.010031492449343204, 0.02311050519347191, 0.041560765355825424, 0.03963969275355339, 0.01879829913377762, -0.014340645633637905, 0.024816742166876793, -0.013953006826341152, 0.06744435429573059, -0.0015208807308226824, -0.011819594539701939, -0.03385914862155914, -0.019655898213386536, 0.03570563718676567, -0.04446804150938988, 0.0003662571543827653, 0.03439812734723091, 0.024494512006640434, -0.003532214555889368, -0.0012492339592427015, 0.01851731166243553, -0.03333373740315437, -0.060152817517519, -0.027219032868742943, 0.018242793157696724, -0.029037678614258766, -0.006500368472188711, 0.0015157354064285755, -0.02090599574148655, -0.007034467067569494, 0.004211888648569584, 0.004657496232539415, 0.00357839441858232, 0.05750171095132828, 0.0576891228556633, 0.04161335527896881, -0.002622852334752679, -0.01486643310636282, -0.0279324222356081, -0.020023563876748085, -0.005897643975913525, -0.0444515123963356, -0.012652764096856117, 0.004319002851843834, 0.020030800253152847, -0.02481793239712715, 0.010778995230793953, -0.006921977736055851, 0.0232068058103323, 0.04765576496720314, -0.027272455394268036, -0.042277466505765915, -0.03350906819105148, -0.0020387559197843075, 0.0038168022874742746, 0.006970839574933052, -0.012376440688967705, -0.028966659680008888, -0.015208328142762184, 0.010344049893319607, -0.04413338750600815, 0.0542498417198658, 0.011121797375380993, -0.03231756389141083, 0.028375614434480667, 0.03746987506747246, 0.042050838470458984, -0.0012272747699171305, 0.026745881885290146, 0.015002910979092121, 0.05413889139890671, 0.006496957968920469, -0.01306596677750349, -0.02184535376727581, 0.0068115293979644775, -0.006419097539037466, 0.016462692990899086, -0.04042651504278183, 0.030014175921678543, 0.03989012539386749, -0.0513274148106575, 0.0070879519917070866, -0.024229714646935463, -0.04468117654323578, 0.006201207172125578, 0.017907069995999336, 0.02390197478234768, -0.015176281332969666, -0.022729860618710518, -0.0006422056467272341, 0.014889662154018879, -0.008245527744293213, 0.04910982772707939, 0.07452421635389328, -0.017127899453043938, 0.037319209426641464, 0.025838572531938553, -0.017329437658190727, 0.02078866958618164, 0.01581287384033203, -0.026377424597740173, -0.009943565353751183, 0.05898941680788994, 0.019399266690015793, 0.00850676279515028, 0.01224147342145443, -0.013366559520363808, -0.0013103761011734605, -0.05493253469467163, -0.01766035333275795, -0.013449316844344139, -0.009055610746145248, -0.012424117885529995, -0.028851142153143883, 0.03837870433926582, -0.04202538728713989, 0.05744029954075813, 0.04511561617255211, -0.0011914954520761967, -0.004917579237371683, 0.052737344056367874, 0.031966015696525574, 0.02217327617108822, 0.038225047290325165, 0.04568547382950783, 0.016398269683122635, -0.0012839994160458446, 0.029042262583971024, 0.05226531997323036, 0.032374218106269836, 0.030503207817673683, 0.00816243328154087, 0.03576098009943962, -0.02710546739399433, -0.003421478671953082, 0.022571975365281105, 0.01736229844391346, -0.024674056097865105, -0.020086152479052544, 0.02240750566124916, -0.06847507506608963, 0.022849055007100105, 0.0015020796563476324, -0.015821358188986778, -0.0076035200618207455, 0.006185722537338734, -0.0036340767983347178, 0.042636655271053314, -0.028067031875252724, -0.06779197603464127, -0.01752707175910473, -0.003499675542116165, -0.008638961240649223, 0.010149000212550163, -0.029069310054183006, -0.033230941742658615, -0.02555878274142742, -0.007959933951497078, -0.012367854826152325, 0.04147644340991974, -0.02525615319609642, -0.009371418505907059, 0.07428965717554092, 0.01286508422344923, -0.006493468303233385, 0.02032485604286194, 0.04490158334374428, 0.004003680776804686, -0.005593949928879738, -0.008118754252791405, -0.0008886365103535354, -0.07335583865642548, 0.04687368869781494, -0.06670943647623062, 0.017229722812771797, -0.018048157915472984, 0.058416347950696945, 0.03600858896970749, 0.05152393877506256, -0.016049131751060486, -0.02795424312353134, -0.04624825716018677, -0.0038409519474953413, 0.007964817807078362, 0.031547661870718, 0.0032921198289841413, 0.009600486606359482, 0.02504049614071846, -0.016859328374266624, -0.030827758833765984, -0.016999492421746254, -0.027987761422991753, 0.05515245720744133, -0.042444806545972824, -0.011969116516411304, -0.024075767025351524, 0.048421718180179596, -0.016347359865903854, 0.028552930802106857, 0.03579216077923775, 0.00362572493031621, 0.029278524219989777, -0.06417958438396454, -0.015035724267363548, -0.02605890855193138, 0.014584223739802837, -0.0307175125926733, -0.02736646682024002, -0.0001458359183743596, 0.045281603932380676, -0.01218336634337902, 0.020562823861837387, -0.007789728231728077, 0.014647455886006355, -0.08858974277973175, 0.023621344938874245, 0.018138326704502106, 0.038703348487615585, 0.036549296230077744, -0.012619558721780777, 0.09010884910821915, 0.03134651482105255, -0.004166309256106615, -0.013305285945534706, -0.053186506032943726, -0.004228064324706793, 0.04001063480973244, -0.007541932165622711, -0.039871182292699814, -0.015172640793025494, -0.03302442654967308, 0.029243124648928642, -0.018976565450429916, -0.002312007825821638, 0.027395596727728844, -0.012583673931658268, -0.0015425069723278284, 0.017911627888679504, -0.006851190235465765, -0.010950155556201935, 0.009207473136484623, 0.015934858471155167, -0.03775719180703163, 0.007741472218185663, -0.009894601069390774, -0.02001175656914711, -0.0420919768512249, -0.003859131131321192, 0.029163433238863945, 0.06327217817306519, 0.04843374714255333, 0.029539186507463455, -0.0014678495936095715, -0.012643867172300816, 0.02790539152920246, 0.02678513154387474, 0.005919254384934902, -0.030697161331772804, 0.0026852753944694996, 0.045460570603609085, -0.0036686507519334555, -0.027306662872433662, 0.035174962133169174, 0.0317901149392128, 0.023175174370408058, 0.005211552605032921, 0.010136445052921772, -0.007088397163897753, -0.01851772516965866, 0.03675888851284981, 0.008056613616645336, 0.06999164074659348, 0.03917047008872032, -0.0017370434943586588, -0.01886139251291752, 0.015830762684345245 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Machine Translation (WMT14) Next, the authors evaluated warm-started encoder-decoder models on the probably most common benchmark in machine translation (MT) - the En \(\to\) De and De \(\to\) En WMT14 dataset. In this notebook, we present the results on the newstest2014 eval dataset. Because the benchmark requires the model to understand both an English and a German vocabulary the BERT-initialized encoder-decoder models were warm-started from the multilingual pre-trained checkpoint bert-base-multilingual-cased. Because there is no publicly available multilingual RoBERTa checkpoint, RoBERTa-initialized encoder-decoder models were excluded for MT. GPT2-initialized models were initialized from the gpt2 pre-trained checkpoint as in the previous experiment. The translation results are reported using the BLUE-4 score metric \({}^1\). |Model |En \(\to\) De (BLEU-4) |De \(\to\) En (BLEU-4) |--------------------------- |---------------------- |---------------------- |Rnd2Rnd | 26.0 | 29.1 |Rnd2BERT | 27.2 | 30.4 |BERT2Rnd | 30.1 | 32.7 |Rnd2GPT2 | 19.6 | 23.2 |BERT2BERT | 30.1 | 32.7 |BERTShare | 29.6 | 32.6 |BERT2GPT2 | 23.2 | 31.4 |--- | --- | --- |BERT2Rnd (large, custom) | 31.7 | 34.2 |BERTShare (large, custom) | 30.5 | 33.8 Again, we observe a significant performance boost by warm-starting the encoder-part, with BERT2Rnd and BERT2BERT yielding the best results on both the En \(\to\) De and De \(\to\) En tasks. GPT2 initialized models perform significantly worse even than the Rnd2Rnd baseline on En \(\to\) De. Taking into consideration that the gpt2 checkpoint was trained only on English text, it is not very surprising that BERT2GPT2 and Rnd2GPT2 models have difficulties generating German translations. This hypothesis is supported by the competitive results (e.g. 31.4 vs. 32.7) of BERT2GPT2 on the De \(\to\) En task for which GPT2\'s vocabulary fits the English output format. Contrary to the results obtained on sentence fusion and sentence splitting, sharing encoder and decoder weight parameters does not yield a performance boost in MT. Possible reasons for this as stated by the authors include - the encoder-decoder model capacity is an important factor in MT, and - the encoder and decoder have to deal with different grammar and vocabulary Since the bert-base-multilingual-cased checkpoint was trained on more than 100 languages, its vocabulary is probably undesirably large for En \(\to\) De and De \(\to\) En MT. Thus, the authors pre-trained a large BERT encoder-only checkpoint on the English and German subset of the Wikipedia dump and subsequently used it to warm-start a BERT2Rnd and BERTShare encoder-decoder model. Thanks to the improved vocabulary, another significant performance boost is observed, with BERT2Rnd (large, custom) significantly outperforming all other models.
[ -0.02737484499812126, 0.03846113383769989, -0.02266129106283188, 0.010715676471590996, 0.013659081421792507, 0.08437316864728928, 0.04352404922246933, -0.020031282678246498, -0.0339643619954586, -0.03870091587305069, -0.029418788850307465, 0.04820684716105461, 0.029252691194415092, 0.011951134540140629, 0.055285338312387466, -0.013506941497325897, -0.00827766302973032, -0.0712175965309143, 0.023347489535808563, -0.05539854243397713, 0.015969369560480118, -0.04300139471888542, 0.0911654606461525, -0.013311771675944328, 0.04693128541111946, -0.04089614376425743, 0.019653264433145523, -0.013712693937122822, -0.04050498083233833, -0.006112466100603342, -0.09602928161621094, 0.04016777127981186, 0.017718201503157616, 0.004973489325493574, 0.0009917502757161856, 0.08523502945899963, -0.03442719206213951, 0.05673583224415779, -0.0031266282312572002, -0.09005537629127502, -0.016949258744716644, -0.014331456273794174, 0.027745073661208153, 0.05185864120721817, -0.02988842874765396, 0.03348507732152939, -0.08592954277992249, 0.029561007395386696, 0.010329149663448334, -0.0466381274163723, -0.09105076640844345, 0.011325441300868988, 0.03325697034597397, 0.04927565157413483, 0.015588471665978432, 0.0411490760743618, -0.04479394480586052, -0.09408010542392731, 0.09341716021299362, -0.02588420733809471, 0.023020392283797264, -0.013250569812953472, 0.007925228215754032, 0.016780653968453407, -0.016437912359833717, 0.0031350154895335436, -0.09720664471387863, 0.01541680283844471, -0.002999099437147379, -0.04999300837516785, -0.07214882224798203, -0.061732687056064606, 0.01990664005279541, 0.0007982226670719683, 0.024321570992469788, -0.07697711884975433, 0.0162952933460474, -0.030900288373231888, 0.00808671023696661, 0.007730438839644194, -0.03733077272772789, 0.06336144357919693, 0.03877880796790123, -0.024649957194924355, 0.018011217936873436, 0.001820565084926784, 0.10689841955900192, -0.07013768702745438, -0.06765561550855637, 0.05782686918973923, -0.00753360940143466, -0.10878998786211014, 0.00992969237267971, 0.01298283040523529, 0.04330465570092201, -0.020092356950044632, -0.025778472423553467, 0.05539830029010773, -0.03175850212574005, -0.03861436992883682, 0.02901902236044407, -0.058655016124248505, 0.08485087752342224, -0.04182213544845581, -0.04698680713772774, 0.012887991964817047, -0.0683959573507309, -0.11134140938520432, 0.021371247246861458, -0.013421420939266682, 0.027788737788796425, -0.026620743796229362, -0.0326789990067482, -0.003620769362896681, -0.07071306556463242, 0.016210850328207016, -0.020011702552437782, -0.058947011828422546, -0.022581875324249268, 0.06911889463663101, 0.03469380363821983, -0.019376462325453758, 0.005012925248593092, -0.08011303097009659, -0.02666468359529972, 0.023403620347380638, 0.014932945370674133, -0.02883736602962017, 0.04323472082614899, -0.0024139387533068657, 0.09370797872543335, -0.00901562999933958, 0.08819824457168579, -0.014366860501468182, 0.006051662843674421, -0.017872998490929604, 0.06431698054075241, -0.04815159738063812, -0.0488416850566864, -0.05121077597141266, -0.08479291945695877, 0.04026284068822861, -0.05740638077259064, -0.04868334159255028, -0.003337388625368476, 0.04846826195716858, -0.09949542582035065, -0.007616386748850346, 0.07173748314380646, 0.04858139902353287, -0.06963437050580978, 0.018697064369916916, -0.023016318678855896, -0.0008612347301095724, 0.09689389169216156, 0.06018418073654175, -0.04732609912753105, -0.03452279418706894, -0.05739317461848259, -0.037090711295604706, -0.06611714512109756, 0.025367936119437218, -0.018634401261806488, -0.026773404330015182, -0.0037244781851768494, -0.09156011790037155, 0.008293842896819115, 0.051308196038007736, -0.01769794523715973, 0.022681353613734245, 0.05483030527830124, 0.014789094217121601, 0.10915132611989975, 0.03431202471256256, -0.023671871051192284, 0.07401880621910095, 0.018835321068763733, 0.036251477897167206, 0.046840064227581024, -0.008295368403196335, -0.006389627233147621, 0.032508958131074905, 0.016412070021033287, 0.03433803468942642, 0.09813317656517029, -0.03548797219991684, 0.021302079781889915, -0.06143010035157204, -0.06643202900886536, 0.03565586358308792, -0.04727581515908241, 0.01000057253986597, 0.10536360740661621, -0.05034356936812401, -0.0714600533246994, -0.03367841988801956, 0.035970717668533325, 0.08402993530035019, 0.02772611379623413, 0.03050779178738594, 0.10534826666116714, -0.0003041275776922703, 0.07043067365884781, 0.010585245676338673, -0.008299591019749641, -0.02765592373907566, 0.01859484240412712, -0.009872926399111748, -0.0038022741209715605, 0.02023763209581375, 0.05485664680600166, -0.04541981220245361, -0.02290106564760208, 0.009378507733345032, 0.02848680503666401, -0.02634771540760994, -0.02875269576907158, -0.01879473589360714, 0.0356912836432457, -0.01882675103843212, 0.11803172528743744, -0.057021088898181915, 0.008904718793928623, -0.020998738706111908, -0.017841776832938194, 0.08505252748727798, 0.03640266880393028, 0.007171126548200846, 0.09761448204517365, -0.007915151305496693, -0.04760025441646576, -0.0799979642033577, 0.028281565755605698, 0.04186640679836273, -0.034888457506895065, -0.07516210526227951, 0.0003015914116986096, -0.04663236439228058, 0.022332698106765747, -0.02237681671977043, 0.01469661295413971, 0.03025955520570278, 0.04707867279648781, 0.060207709670066833, -0.06419695168733597, 0.008010257966816425, 0.05662601441144943, -0.058892473578453064, 0.006129170302301645, -0.014108176343142986, -0.0011025759158656001, -0.0024184505455195904, -0.03505925089120865, -0.08271906524896622, 0.011291669681668282, 0.026440026238560677, -0.0008470606408081949, 0.02079291269183159, -0.0204327329993248, 0.02411966398358345, 0.0037355441600084305, -0.009344554506242275, -0.03431468829512596, -0.011621730402112007, 0.011774727143347263, -0.02048649452626705, -0.06376931071281433, 0.004563404247164726, 0.004308268893510103, -0.006513195112347603, -0.00362194050103426, -0.018960334360599518, -0.012910314835608006, 0.022637661546468735, 0.015799306333065033, 0.004050837829709053, 0.004038144368678331, -0.04687226191163063, -0.06560422480106354, -0.01956406980752945, 0.005224263295531273, -0.021760737523436546, 0.01801837421953678, 0.01984008401632309, -0.04570210725069046, 0.025423312559723854, -0.002888719318434596, -0.0062042223289608955, -0.002808225341141224, 0.03758353367447853, 0.03944965824484825, -0.009533345699310303, -0.02721036598086357, 0.021462880074977875, 0.03631376102566719, 0.00001587465339980554, -0.016159644350409508, -0.029015328735113144, -0.0017788135446608067, 0.032707102596759796, -0.04278810694813728, 0.009992880746722221, -0.03944164142012596, -0.010149739682674408, -0.045454662293195724, 0.0032658581621944904, 0.015634983777999878, 0.01571892388164997, -0.07850221544504166, 0.0020735985599458218, 0.02743389457464218, -0.0029035042971372604, -0.014199596829712391, -0.0258660726249218, 0.035409364849328995, -0.009195191785693169, -0.04115169867873192, 0.006987707689404488, -0.005522293504327536, -0.03348057344555855, -0.0011278438614681363, 0.0017470514867454767, -0.04500753432512283, -0.005534837022423744, -0.05206939950585365, -0.014925575815141201, 0.01602262444794178, 0.025476349517703056, 0.058597858995199203, -0.020201053470373154, 0.003673779545351863, 0.006577932275831699, -0.036512717604637146, 0.02553248219192028, 0.0407729409635067, -0.006191624794155359, 0.03571383282542229, 0.0014414414763450623, -0.007846472784876823, 0.0064401691779494286, -0.0015649390406906605, 0.005546963773667812, -0.010443177074193954, -0.03861681744456291, 0.004874840844422579, 0.06464677304029465, 0.04979095980525017, 0.0055356635712087154, 0.03682410717010498, 0.01483944896608591, 0.00882505439221859, 0.011754190549254417, 0.031239746138453484, -0.021434206515550613, 0.008565545082092285, -0.00864859763532877, 0.042112063616514206, -0.009457032196223736, -0.006507215555757284, 0.001491416827775538, -0.015930110588669777, 0.02184479311108589, 0.006199443247169256, 0.022914469242095947, -0.02370065450668335, 0.015165665186941624, 0.002648488385602832, -0.0020712174009531736, -0.03436967730522156, 0.022371314465999603, -0.019594119861721992, -0.028998402878642082, -0.03340679779648781, 0.0036640698090195656, -0.02261529304087162, 0.03022773750126362, -0.005137589760124683, 0.0199494156986475, 0.00865156203508377, -0.002512970706447959, -0.0015398107934743166, -0.007516155019402504, -0.02187741920351982, -0.010395262390375137, -0.038207728415727615, -0.047615956515073776, 0.06081868335604668, -0.01779320277273655, -0.0009703076211735606, 0.012913212180137634, -0.056437887251377106, -0.05240911990404129, 0.022185686975717545, 0.0062243458814918995, 0.03423936292529106, -0.03443746641278267, 0.020113535225391388, 0.012579377740621567, 0.015623067505657673, -0.0066604455932974815, -0.02312062680721283, -0.006296274717897177, -0.004304362460970879, -0.033814672380685806, 0.002243434777483344, 0.0033116736449301243, -0.005369084421545267, 0.008928632363677025, 0.00600413279607892, -0.08116835355758667, -0.02711299993097782, 0.003003882011398673, 0.004380065482109785, 0.034074459224939346, 0.0020763890352100134, -0.02109682187438011, 0.04958634078502655, 0.027708658948540688, 0.007377453614026308, 0.008024041540920734, -0.037986911833286285, 0.020066583529114723, 0.02670150436460972, 0.027019303292036057, 0.029011176899075508, -0.05501694232225418, -0.005752406548708677, -0.016136804595589638, 0.0028845355845987797, -0.012471443973481655, 0.036918673664331436, 0.038753896951675415, 0.03369460999965668, 0.0010070942807942629, 0.006447948981076479, 0.019552892073988914, -0.021401727572083473, -0.05796284228563309, -0.09546179324388504, -0.03206316754221916, 0.008770392276346684, -0.03488093242049217, 0.008294777013361454, 0.006718653254210949, 0.022932833060622215, 0.025993172079324722, 0.0005266580265015364, -0.04012622311711311, 0.037459295243024826, 0.00473957322537899, 0.019829077646136284, -0.04654110595583916, 0.03735260292887688, -0.0009111918043345213, 0.025361452251672745, -0.007008579559624195, 0.004137835465371609, 0.013489579781889915, 0.051914602518081665, -0.004317313898354769, -0.04340938478708267, 0.014015360735356808, 0.017119737342000008, 0.004360176622867584, -0.01287943497300148, 0.010214590467512608, 0.040273651480674744, 0.02193073369562626, 0.026673659682273865, -0.010753966867923737, -0.03481101244688034, 0.008548500016331673, 0.000370694586308673, -0.0014100773259997368, 0.010496361181139946, 0.002961886813864112, 0.031145205721259117, -0.004349748138338327, 0.04418217018246651, -0.010392344556748867, 0.009327846579253674, 0.022440265864133835, 0.014300955459475517, 0.003564149374142289, -0.019028520211577415, 0.025413691997528076, 0.017338508740067482, 0.00727900629863143, 0.013752924278378487, -0.029686206951737404, -0.012450974434614182, 0.018823498860001564, -0.02604551985859871, 0.018070805817842484, 0.04732517898082733, 0.04837760701775551, 0.0570431612432003, 0.0009823702275753021, -0.025668734684586525, 0.028912076726555824, 0.021988125517964363, -0.010192480869591236, -0.02695125713944435, -0.0274171344935894, 0.020636387169361115, 0.04925720393657684, -0.019283154979348183, 0.03274507448077202, 0.03413504362106323, 0.04950645938515663, 0.017358658835291862, -0.026265447959303856, 0.021297086030244827, -0.034095119684934616, -0.06284087151288986, -0.055782660841941833, 0.01176187302917242, -0.05591585859656334, -0.031966693699359894, 0.024361424148082733, 0.007870260626077652, 0.020986327901482582, 0.011690132319927216, -0.03981613367795944, 0.03011508844792843, 0.022200893610715866, 0.03930414468050003, 0.024555303156375885, 0.008921555243432522, 0.028659768402576447, -0.01827358640730381, -0.02271246910095215, -0.02082645706832409, -0.025623327121138573, -0.008339673280715942, -0.02224838361144066, -0.01069506537169218, 0.015209859237074852, 0.004859334789216518, -0.019829299300909042, -0.003068657824769616, 0.027783909812569618, -0.007806719280779362, -0.034232765436172485, 0.04273281618952751, -0.0031797299161553383, 0.029025781899690628, 0.00915123987942934, 0.008368588984012604, -0.0231916680932045, 0.030357563868165016, 0.03525838628411293, -0.06077815592288971, 0.048272013664245605, 0.03130557760596275, -0.009294825606048107, 0.017506849020719528, 0.01679355651140213, 0.02359597571194172, 0.019401174038648605, 0.0022446580696851015, 0.04123707115650177, 0.01428389735519886, -0.029821446165442467, -0.015147498808801174, 0.000009909226719173603, 0.015062118880450726, 0.006288512144237757, 0.027817392721772194, -0.00932123139500618, 0.04585558548569679, 0.038036104291677475, -0.047175332903862, 0.020987942814826965, 0.0101957768201828, -0.06875163316726685, 0.013963820412755013, 0.04179465025663376, -0.0023419393692165613, -0.015541777946054935, -0.0367429181933403, 0.004011826124042273, 0.08130480349063873, -0.028312157839536667, 0.00842765811830759, 0.05852888897061348, 0.003156464546918869, -0.001395602710545063, 0.006246021017432213, -0.006655840203166008, 0.024448806419968605, 0.012503787875175476, -0.028026627376675606, -0.021907761693000793, 0.03782161697745323, 0.03166000172495842, 0.024121074005961418, 0.02225283905863762, 0.018010955303907394, -0.021781960502266884, -0.0437307208776474, -0.021067596971988678, -0.010874909348785877, 0.016488343477249146, 0.005919191986322403, -0.006226496770977974, -0.0006668320274911821, -0.01962396688759327, 0.059131454676389694, 0.03988168016076088, 0.03427194803953171, -0.019531354308128357, 0.05090779438614845, 0.020427672192454338, 0.0522020198404789, 0.013181849382817745, 0.034941673278808594, 0.022792240604758263, -0.023456260561943054, 0.03791765123605728, 0.016203615814447403, -0.016372384503483772, 0.015169558115303516, -0.010247447527945042, -0.025923574343323708, -0.011257489211857319, 0.006731225177645683, 0.04190715029835701, 0.0473102405667305, -0.026909494772553444, -0.026941031217575073, 0.06905074417591095, -0.016530929133296013, 0.007216267287731171, 0.01914070174098015, -0.023883672431111336, -0.037567779421806335, -0.017007464542984962, 0.01886322721838951, 0.07564181089401245, -0.032679859548807144, -0.04950762540102005, -0.027105839923024178, -0.02251826412975788, -0.0010811577085405588, 0.04157799109816551, -0.012101210653781891, -0.012842926196753979, -0.018005086109042168, 0.013885648921132088, -0.047490108758211136, 0.011870687827467918, -0.011623949743807316, -0.017053360119462013, 0.030181385576725006, -0.004183856770396233, 0.015150422230362892, -0.015984168276190758, 0.01662295125424862, -0.005009285639971495, 0.003845316357910633, -0.015160306356847286, -0.03792237862944603, -0.055658213794231415, 0.06687930971384048, -0.07344948500394821, -0.010581131093204021, 0.0026260530576109886, 0.05485169216990471, 0.057022906839847565, 0.057854268699884415, -0.02191116288304329, -0.03564133867621422, -0.04018288105726242, -0.012992901727557182, -0.0367538258433342, 0.00035186324384994805, -0.0009912605164572597, 0.01642349548637867, 0.014671463519334793, -0.049275998026132584, 0.01271599717438221, -0.01784537360072136, -0.03264147415757179, 0.04994708672165871, -0.05497031286358833, -0.0025370903313159943, -0.054705601185560226, 0.03275904804468155, 0.00540580227971077, 0.05653444305062294, 0.02022591605782509, -0.04465596377849579, 0.0444943867623806, 0.0025140440557152033, 0.030240029096603394, 0.027455052360892296, 0.01357320137321949, 0.0013409791281446815, -0.025322310626506805, -0.030464069917798042, 0.017753876745700836, -0.010700944811105728, 0.020944617688655853, -0.025247715413570404, 0.03040192648768425, -0.09045280516147614, 0.014088097028434277, 0.020776648074388504, 0.011483829468488693, 0.0006505865603685379, -0.006835340987890959, 0.030504576861858368, 0.01305962074548006, 0.007550145033746958, 0.008984575979411602, -0.01875169947743416, 0.008001094684004784, 0.04731358587741852, 0.0061236280016601086, -0.0324665792286396, -0.006577818654477596, -0.0025964307133108377, -0.01991688646376133, -0.019378522410988808, 0.02851007506251335, 0.02565528079867363, 0.014039239846169949, -0.011448627337813377, -0.015533914789557457, -0.022477295249700546, -0.01186732854694128, 0.0008114328375086188, 0.05202891305088997, -0.006834746804088354, -0.01248891744762659, -0.026524070650339127, -0.030488695949316025, -0.029820479452610016, 0.008466443978250027, -0.006551104597747326, 0.047083258628845215, 0.004854606464505196, 0.03430771455168724, 0.01066672708839178, 0.006856398191303015, 0.020457115024328232, 0.019737033173441887, -0.009793881326913834, -0.01217531505972147, 0.013098567724227905, 0.07518292963504791, -0.01750291883945465, -0.05232478678226471, 0.05193948745727539, 0.017368504777550697, 0.0010345977498218417, 0.007715623825788498, -0.00577726261690259, -0.028074372559785843, -0.045546889305114746, 0.008811956271529198, 0.01454170886427164, 0.03851182386279106, 0.02234627865254879, 0.046471718698740005, 0.019643278792500496, 0.03288662061095238 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
GPT2 GPT2 is a decoder-only model, which makes use of uni-directional (i.e. \"causal\") self-attention to define a mapping from an input sequence \(\mathbf{Y}{0: m - 1}\) \({}^1\) to a \"next-word\" logit vector sequence \(\mathbf{L}{1:m}\): $$ f_{\theta_{\text{GPT2}}}: \mathbf{Y}{0: m - 1} \to \mathbf{L}{1:m}. $$ By processing the logit vectors \(\mathbf{L}{1:m}\) with the softmax operation, the model can define the probability distribution of the word sequence \(\mathbf{Y}{1:m}\). To be exact, the probability distribution of the word sequence \(\mathbf{Y}{1:m}\) can be factorized into \(m-1\) conditional \"next word\" distributions: $$ p{\theta_{\text{GPT2}}}(\mathbf{Y}{1:m}) = \prod{i=1}^{m} p_{\theta_{\text{GPT2}}}(\mathbf{y}i | \mathbf{Y}{0:i-1}). $$ \(p_{\theta_{\text{GPT2}}}(\mathbf{y}i | \mathbf{Y}{0:i-1})\) hereby presents the probability distribution of the next word \(\mathbf{y}i\) given all previous words \(\mathbf{y}_0, \ldots, \mathbf{y}{i-1}\) \({}^3\) and is defined as the softmax operation applied on the logit vector \(\mathbf{l}i\). To summarize, the following equations hold true. $$ p{\theta_{\text{gpt2}}}(\mathbf{y}i | \mathbf{Y}{0:i-1}) = \textbf{Softmax}(\mathbf{l}i) = \textbf{Softmax}(f{\theta_{\text{GPT2}}}(\mathbf{Y}{0: i - 1})).$$ For more detail, please refer to the decoder section of the encoder-decoder blog post. Let\'s visualize GPT2 now as well. Analogous to BERT, GPT2 is composed of a stack of GPT2 blocks. In contrast to BERT block, GPT2 block makes use of uni-directional self-attention to process some input vectors \(\mathbf{y'}_0, \ldots, \mathbf{y'}{m-1}\) (shown in light blue on the bottom right) to an output vector sequence \(\mathbf{y''}0, \ldots, \mathbf{y''}{m-1}\) (shown in darker blue on the top right). In addition to the GPT2 block stack, the model also has a linear layer, called LM Head, which maps the output vectors of the final GPT2 block to the logit vectors \(\mathbf{l}1, \ldots, \mathbf{l}_m\). As mentioned earlier, a logit vector \(\mathbf{l}_i\) can then be used to sample of new input vector \(\mathbf{y}_i\) \({}^5\). GPT2 is mainly used for open-domain text generation. First, an input prompt \(\mathbf{Y}{0:i-1}\) is fed to the model to yield the conditional distribution \(p_{\theta_{\text{gpt2}}}(\mathbf{y} | \mathbf{Y}{0:i-1})\). Then the next word \(\mathbf{y}_i\) is sampled from the distribution (represented by the grey arrows in the graph above) and consequently append to the input. In an auto-regressive fashion the word \(\mathbf{y}{i+1}\) can then be sampled from \(p_{\theta_{\text{gpt2}}}(\mathbf{y} | \mathbf{Y}{0:i})\) and so on. GPT2 is therefore well-suited for language generation, but less so for conditional generation. By setting the input prompt \(\mathbf{Y}{0: i-1}\) equal to the sequence input \(\mathbf{X}{1:n}\), GPT2 can very well be used for conditional generation. However, the model architecture has a fundamental drawback compared to the encoder-decoder architecture as explained in Raffel et al. (2019) on page 17. In short, uni-directional self-attention forces the model\'s representation of the sequence input \(\mathbf{X}{1:n}\) to be unnecessarily limited since \(\mathbf{x}i\) cannot depend on \(\mathbf{x}{i+1}, \forall i \in {1,\ldots, n}\).
[ 0.011512622237205505, -0.10467776656150818, 0.11331644654273987, -0.030818670988082886, 0.0569700263440609, 0.06720311939716339, 0.006677289493381977, 0.04326951503753662, -0.023880571126937866, -0.03699599578976631, -0.07841186225414276, 0.06527732312679291, -0.0016142629319801927, 0.09115691483020782, -0.05393771827220917, 0.023320423439145088, -0.008156617172062397, -0.08073988556861877, 0.037213485687971115, -0.05309999734163284, 0.03933178633451462, 0.019303329288959503, 0.015195677056908607, -0.06827652454376221, 0.014522509649395943, -0.01885688677430153, -0.008152317255735397, 0.0001551934692543, -0.05818901211023331, 0.0035370108671486378, -0.10070586204528809, 0.011906519532203674, 0.005507795140147209, -0.009912781417369843, -0.006951699033379555, -0.01697816140949726, -0.17221130430698395, -0.017572233453392982, 0.08604387193918228, -0.03200735151767731, -0.017370808869600296, 0.017926491796970367, -0.07608380168676376, 0.0032605454325675964, -0.018082814291119576, 0.023912865668535233, -0.19570976495742798, 0.09455764293670654, -0.03057752177119255, -0.10838250070810318, -0.04906895384192467, 0.028993947431445122, -0.08015397191047668, 0.04301911219954491, -0.0014143314911052585, 0.01956777833402157, 0.0021090907976031303, -0.081657774746418, 0.01670326292514801, -0.044820353388786316, 0.012276191264390945, -0.019499104470014572, 0.008821743540465832, 0.05405595153570175, -0.0009242712403647602, -0.04571589455008507, 0.013976204209029675, 0.026723893359303474, -0.05282993242144585, -0.039080895483493805, -0.055833589285612106, -0.024168068543076515, -0.04015261307358742, -0.0053582508116960526, -0.01450817845761776, -0.05159016326069832, -0.040656927973032, 0.030828213319182396, -0.031926803290843964, 0.01889295130968094, 0.03037450835108757, 0.0029600944835692644, 0.06001698225736618, 0.06727685779333115, 0.00078419508645311, -0.015232006087899208, 0.06914752721786499, -0.05669454112648964, -0.008722440339624882, 0.03999652341008186, -0.04515693709254265, -0.12950898706912994, 0.02488698996603489, -0.01682755909860134, 0.04097389057278633, -0.018693935126066208, 0.0007446609088219702, 0.011998636648058891, -0.02492453157901764, 0.01409806776791811, -0.031634096056222916, -0.015050266869366169, 0.037800829857587814, -0.014612111262977123, -0.026189949363470078, 0.03031298890709877, 0.007918952964246273, -0.041597384959459305, -0.06777618080377579, 0.04835262522101402, -0.011331088840961456, 0.005825158208608627, 0.00519843865185976, 0.012950981967151165, -0.10071182250976562, 0.03623347356915474, 0.04146929457783699, -0.017836326733231544, 0.029700418934226036, 0.03341466560959816, -0.04318104684352875, 0.01997223310172558, 0.014781973324716091, 0.025231117382645607, 0.011559761129319668, -0.048388153314590454, 0.024959933012723923, 0.004944003187119961, -0.08477306365966797, -0.023184530436992645, 0.05156128481030464, -0.00942638237029314, 0.017584756016731262, 0.010137546807527542, -0.02132202498614788, -0.040330905467271805, 0.012961557134985924, -0.0032376532908529043, -0.015003832057118416, -0.008728677406907082, -0.019504128023982048, 0.00042937914258800447, -0.02926943637430668, 0.011350128799676895, 0.08409786224365234, 0.023539312183856964, -0.048343926668167114, 0.033138666301965714, -0.021454619243741035, 0.03410713002085686, -0.03833993524312973, 0.05415590852499008, 0.016268925741314888, -0.0770018920302391, 0.03830418363213539, -0.003139141947031021, -0.0306180939078331, -0.03496025130152702, -0.08406110852956772, -0.02032279223203659, 0.02315627411007881, 0.014096752740442753, -0.019359340891242027, -0.006371949799358845, 0.06112592667341232, -0.0526902936398983, 0.05536680296063423, 0.06579390168190002, -0.020915409550070763, 0.011677850969135761, 0.002944677136838436, -0.035785917192697525, 0.09082495421171188, 0.025925664231181145, -0.023478016257286072, 0.03395804017782211, -0.02759244106709957, 0.093556709587574, 0.01857548952102661, -0.051732901483774185, -0.07271476835012436, -0.011365879327058792, 0.02451964281499386, -0.013855560682713985, 0.03233163431286812, -0.05523037910461426, -0.08952341973781586, -0.03470997512340546, -0.00816916674375534, 0.0346343107521534, -0.03417402505874634, -0.04318903014063835, 0.06455045193433762, -0.03814622014760971, 0.00753558287397027, -0.10159620642662048, -0.004233124200254679, 0.07232823967933655, 0.0882725641131401, 0.025490183383226395, 0.05625475198030472, -0.01770608313381672, 0.004107384942471981, -0.033355217427015305, -0.019492434337735176, -0.001294673653319478, 0.049253564327955246, 0.025848332792520523, 0.028710216283798218, 0.016301630064845085, -0.033153221011161804, -0.07273424416780472, -0.030294952914118767, -0.08329778164625168, -0.0018957178108394146, -0.02908332273364067, 0.004872263874858618, 0.05927031859755516, -0.0026264938060194254, -0.012895953841507435, 0.11629025638103485, -0.06515802443027496, -0.016011470928788185, 0.008284819312393665, 0.00901716947555542, 0.0760219618678093, 0.10429298132658005, 0.01225405465811491, 0.06969726830720901, -0.0195293091237545, -0.046749014407396317, -0.08469626307487488, 0.08294897526502609, 0.02893569879233837, 0.023648008704185486, 0.0012658656341955066, 0.009678548201918602, 0.029322601854801178, 0.05059177801012993, -0.05637883394956589, 0.02919698692858219, 0.017984580248594284, -0.043007832020521164, 0.03675799071788788, -0.04894355684518814, -0.062279462814331055, 0.07347407937049866, -0.011452128179371357, -0.0472872257232666, -0.0031329263001680374, -0.06424935162067413, 0.06414081156253815, 0.044959668070077896, -0.029289808124303818, 0.0019395477138459682, 0.040516115725040436, 0.019003773108124733, 0.012140458449721336, 0.0018032199004665017, 0.017213761806488037, -0.0025396086275577545, -0.020620884373784065, 0.021056298166513443, -0.019756384193897247, -0.027730731293559074, 0.017742404714226723, 0.030167631804943085, 0.04969275742769241, 0.0037499726749956608, 0.029811302199959755, 0.006271451245993376, 0.017663033679127693, -0.0022716419771313667, 0.025171518325805664, -0.0036498871631920338, -0.018663665279746056, 0.014096790924668312, 0.012328589335083961, -0.002577336272224784, -0.021096421405673027, 0.009747816249728203, -0.004433763679116964, 0.03685235604643822, 0.05317787081003189, 0.023743227124214172, 0.022167138755321503, 0.0005247576627880335, -0.005370035767555237, 0.008106205612421036, 0.047344278544187546, -0.034513864666223526, 0.02136184461414814, -0.015039988793432713, -0.04762755334377289, -0.01096449326723814, 0.0049352324567735195, -0.02855093590915203, -0.022427359595894814, -0.019637366756796837, 0.03165861591696739, 0.014760149642825127, 0.021361691877245903, 0.01661652885377407, -0.000025103132429649122, -0.014801660552620888, 0.03943062201142311, 0.03236627206206322, 0.05303017050027847, -0.10518151521682739, -0.04193092882633209, 0.03337913006544113, 0.010016567073762417, 0.009334462694823742, -0.017513789236545563, 0.06182769313454628, 0.018215402960777283, -0.035793304443359375, -0.04202970862388611, 0.04563116282224655, -0.0025581291411072016, 0.023829905316233635, -0.007091302890330553, -0.027411125600337982, -0.019319307059049606, 0.006081758998334408, -0.01829672046005726, 0.028475875034928322, -0.024509795010089874, 0.02941576950252056, 0.02473197691142559, -0.0404282845556736, 0.02339855022728443, -0.05325374752283096, -0.005331649444997311, 0.005696398206055164, -0.004895070102065802, 0.012159102596342564, -0.0042582908645272255, -0.05701213702559471, 0.02710903435945511, 0.00009814780059969053, 0.04738805443048477, 0.00566153833642602, 0.03645654395222664, 0.021545229479670525, 0.03084069862961769, -0.0012639715569093823, 0.060473546385765076, 0.0009444498573429883, -0.0031493683345615864, 0.0007275064708665013, -0.01405161153525114, -0.01736852154135704, -0.00744725251570344, 0.017953287810087204, -0.04336398467421532, 0.010193823836743832, -0.023451847955584526, -0.03297105431556702, 0.0010546710109338164, -0.04538554325699806, 0.04362768679857254, 0.031357716768980026, 0.02059178240597248, 0.02149823307991028, 0.02458505891263485, 0.027615666389465332, 0.04018773138523102, -0.006023713853210211, -0.010448080487549305, 0.03278691694140434, -0.015459135174751282, -0.017050741240382195, 0.04923709109425545, 0.026051819324493408, 0.04199651628732681, -0.002715306356549263, 0.021267294883728027, -0.007452389225363731, 0.018665913492441177, 0.016229555010795593, 0.00312475161626935, 0.02671739272773266, 0.05893343314528465, -0.057082030922174454, 0.028926922008395195, 0.10307680815458298, 0.023483140394091606, 0.002042752457782626, 0.0014067193260416389, -0.01673571579158306, -0.02163919061422348, -0.010515536181628704, 0.0004812732804566622, 0.01369002740830183, -0.026783393695950508, 0.04925856739282608, -0.004757309332489967, 0.006226728204637766, -0.010261058807373047, 0.02847275510430336, -0.01870512217283249, -0.030710749328136444, 0.06609699875116348, 0.004233463667333126, -0.007205840665847063, 0.04612685367465019, 0.028338346630334854, 0.01555566769093275, -0.06081663444638252, -0.007102335803210735, 0.00667144451290369, -0.033464886248111725, 0.05859893932938576, -0.00032819464104250073, -0.01357321161776781, 0.044659338891506195, 0.0013139165239408612, 0.060664862394332886, 0.025186076760292053, 0.023033566772937775, -0.0066042132675647736, 0.060047708451747894, -0.01259691547602415, -0.00849960371851921, -0.05492250621318817, 0.0012869187630712986, 0.006213394924998283, -0.019448067992925644, 0.0002957742544822395, -0.03859563544392586, 0.008563277311623096, 0.039561204612255096, -0.008580184541642666, 0.019012000411748886, -0.015145931392908096, -0.0028335959650576115, -0.011836362071335316, -0.008168327622115612, -0.006250123493373394, 0.0017650239169597626, -0.020556112751364708, -0.0012761559337377548, 0.007671983912587166, 0.02216116525232792, 0.04680781066417694, 0.004909213166683912, -0.07992804050445557, -0.012055656872689724, -0.04210469499230385, 0.037197839468717575, -0.01079985685646534, 0.005162224173545837, -0.007168557960540056, -0.009407799690961838, 0.006848522927612066, 0.00009999673056881875, 0.0017062558326870203, 0.03690561279654503, -0.03540425002574921, -0.03796862065792084, 0.02823389694094658, -0.001867016195319593, 0.005102628841996193, -0.007984617725014687, 0.032659657299518585, -0.031212203204631805, 0.05077974125742912, 0.023155780509114265, -0.03671235963702202, -0.056018613278865814, 0.013025393709540367, 0.0012588356621563435, 0.03398136794567108, 0.002785314107313752, -0.032124102115631104, 0.018109481781721115, 0.019472872838377953, -0.01041977759450674, -0.014245924539864063, -0.0004721280711237341, -0.012882168404757977, 0.0017296357546001673, 0.015465226024389267, -0.01218835636973381, 0.007951924577355385, -0.02117718756198883, 0.011243114247918129, -0.02221176028251648, 0.03408757224678993, -0.007838365621864796, 0.015917420387268066, -0.03722628206014633, 0.03751526027917862, 0.03018711321055889, 0.04474387317895889, 0.012306485325098038, 0.04713914170861244, 0.054236311465501785, -0.023895733058452606, 0.010808438062667847, -0.06178584322333336, 0.007385494187474251, 0.04682627320289612, 0.01705564744770527, 0.04536082223057747, -0.00929231196641922, 0.005159109830856323, 0.02699279971420765, 0.028816169127821922, -0.034872207790613174, -0.043451737612485886, 0.011125661432743073, -0.025999875739216805, -0.01720275543630123, -0.03862226381897926, 0.022426798939704895, 0.002401712816208601, 0.0041848295368254185, -0.03199378773570061, -0.03235688805580139, -0.05227865278720856, -0.034800030291080475, -0.012536715716123581, -0.016156209632754326, 0.057462651282548904, -0.0053471727296710014, 0.050144296139478683, 0.006526323966681957, 0.010728259570896626, -0.03012441098690033, -0.002150175394490361, 0.004522404633462429, -0.007282968144863844, -0.05617300793528557, 0.00946337915956974, 0.03765048831701279, 0.022768303751945496, 0.01264210045337677, -0.06233379617333412, -0.03275680914521217, 0.04180140048265457, -0.004499339964240789, -0.065955251455307, -0.04844069480895996, 0.029761550948023796, -0.012132320553064346, 0.03271907567977905, 0.025064457207918167, -0.019283730536699295, 0.005077567882835865, -0.020835401490330696, -0.04557094722986221, -0.004735082853585482, 0.039187993854284286, -0.012486417777836323, 0.00438214186578989, 0.021011270582675934, 0.018135065212845802, -0.00010695034870877862, 0.0033120850566774607, 0.02201177552342415, 0.028505848720669746, 0.03603868559002876, 0.0482180081307888, 0.008000753819942474, -0.006728240288794041, 0.024759776890277863, 0.02526106685400009, -0.02911168709397316, -0.0021051005460321903, 0.041874829679727554, -0.03609728068113327, 0.012978751212358475, 0.009693983010947704, -0.009780625812709332, -0.010544993914663792, 0.025577938184142113, 0.018618058413267136, 0.0026649003848433495, -0.050068844109773636, -0.00401761569082737, -0.02351866289973259, 0.016106104478240013, -0.010118062607944012, 0.057669028639793396, -0.024689221754670143, 0.0501188263297081, -0.0009266970446333289, 0.043492354452610016, 0.056155622005462646, -0.008440155535936356, 0.0012707674177363515, 0.025256576016545296, 0.03851550072431564, 0.013055534102022648, 0.016514206305146217, 0.01659552939236164, 0.02478446066379547, -0.003607735736295581, -0.029569022357463837, -0.015862632542848587, -0.016734110191464424, 0.02435445226728916, 0.03337005898356438, -0.005791941192001104, 0.029981976374983788, -0.0076319193467497826, 0.050473570823669434, 0.06462046504020691, 0.024443697184324265, -0.012566017918288708, -0.004285580012947321, 0.034189656376838684, 0.024089688435196877, 0.00548768462613225, 0.01991613581776619, -0.04017719626426697, 0.026774605736136436, 0.013293983414769173, -0.004242892377078533, 0.04227028414607048, -0.009859263896942139, -0.04186142608523369, 0.0372428223490715, 0.015314104966819286, -0.011284444481134415, 0.013845055364072323, 0.032735425978899, -0.011045302264392376, 0.024952063336968422, -0.026511458680033684, 0.006943101529031992, 0.008656257763504982, 0.018024178221821785, 0.04459276422858238, 0.0069092875346541405, -0.026732321828603745, -0.000300511164823547, 0.0196898952126503, -0.005347246304154396, 0.005047980230301619, -0.03985239937901497, -0.007876556366682053, -0.0025883170310407877, -0.0038321781903505325, -0.06023696810007095, -0.04071243479847908, -0.007890358567237854, -0.01498299092054367, -0.013752504251897335, -0.006105679087340832, -0.024047521874308586, -0.011011541821062565, 0.023240961134433746, 0.048007477074861526, -0.041804082691669464, 0.005302238743752241, 0.03532860055565834, 0.0006049741059541702, -0.02989293821156025, -0.007210873067378998, -0.01778986118733883, -0.002712540328502655, -0.025961246341466904, -0.03544009476900101, -0.04493347927927971, -0.01482731755822897, 0.006402807310223579, 0.0263063982129097, 0.02864118665456772, -0.007420548237860203, -0.015453041531145573, -0.0046359156258404255, -0.034929268062114716, -0.002091762376949191, -0.002960359677672386, 0.0082832220941782, -0.01427424419671297, 0.010027982294559479, -0.009695346467196941, -0.02760409750044346, -0.022752385586500168, 0.02049301564693451, 0.023831509053707123, 0.009769955649971962, -0.006577002350240946, -0.005764483008533716, 0.05876285210251808, -0.017706578597426414, 0.008953765034675598, 0.03501696512103081, 0.030273087322711945, 0.04455525055527687, -0.009955308400094509, 0.032676488161087036, -0.037063293159008026, 0.014262520708143711, -0.00960170105099678, -0.069667287170887, -0.011588092893362045, 0.03414307162165642, 0.010455852374434471, -0.01930963806807995, -0.026104072108864784, -0.01874016784131527, -0.036030154675245285, 0.03324942663311958, -0.026763245463371277, -0.002015221631154418, 0.03909842669963837, -0.0042338063940405846, 0.03746097907423973, -0.017586862668395042, -0.004201492760330439, -0.03454712778329849, 0.012357011437416077, 0.0407574325799942, 0.06416933238506317, 0.019991355016827583, 0.006128801964223385, -0.028631053864955902, 0.014488914981484413, -0.025411933660507202, -0.021832173690199852, 0.019455641508102417, 0.009513902477920055, -0.019297398626804352, 0.009995896369218826, 0.031211065128445625, -0.038544319570064545, 0.019629718735814095, 0.01271404791623354, 0.023957598954439163, 0.014373891986906528, -0.03601327911019325, -0.00977766327559948, -0.0517401322722435, -0.003206829307600856, -0.0048820930533111095, 0.03067081980407238, 0.012868013232946396, 0.04694438353180885, 0.03420702740550041, 0.019239654764533043, 0.022261302918195724, 0.021477146074175835, 0.02929481491446495, -0.010369968600571156, -0.043923269957304, -0.0041965097188949585, -0.027076484635472298, -0.04239578917622566, -0.059374693781137466, 0.015661530196666718, 0.02298944629728794, -0.02635050006210804, -0.014861924573779106, 0.013271581381559372, 0.04241219535470009, -0.029775092378258705, 0.04112662002444267, 0.017841966822743416, 0.0749414935708046, 0.015895893797278404, 0.0017028541769832373, 0.00516702001914382, 0.0017195751424878836 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Encoder-Decoder Because encoder-only models require to know the output length a priori, they seem unfit for sequence-to-sequence tasks. Decoder-only models can function well for sequence-to-sequence tasks, but also have certain architectural limitations as explained above. The current predominant approach to tackle sequence-to-sequence tasks are transformer-based encoder-decoder models - often also called seq2seq transformer models. Encoder-decoder models were introduced in Vaswani et al. (2017) and since then have been shown to perform better on sequence-to-sequence tasks than stand-alone language models (i.e. decoder-only models), e.g. Raffel et al. (2020). In essence, an encoder-decoder model is the combination of a stand-alone encoder, such as BERT, and a stand-alone decoder model, such as GPT2. For more details on the exact architecture of transformer-based encoder-decoder models, please refer to this blog post. Now, we know that freely available checkpoints of large pre-trained stand-alone encoder and decoder models, such as BERT and GPT, can boost performance and reduce training cost for many NLU tasks, We also know that encoder-decoder models are essentially the combination of stand-alone encoder and decoder models. This naturally brings up the question of how one can leverage stand-alone model checkpoints for encoder-decoder models and which model combinations are most performant on certain sequence-to-sequence tasks. In 2020, Sascha Rothe, Shashi Narayan, and Aliaksei Severyn investigated exactly this question in their paper Leveraging Pre-trained Checkpoints for Sequence Generation Tasks. The paper offers a great analysis of different encoder-decoder model combinations and fine-tuning techniques, which we will study in more detail later. Composing an encoder-decoder model of pre-trained stand-alone model checkpoints is defined as warm-starting the encoder-decoder model. The following sections show how warm-starting an encoder-decoder model works in theory, how one can put the theory into practice with 🤗Transformers, and also gives practical tips for better performance. ------------------------------------------------------------------------ \({}^1\) A pre-trained language model is defined as a neural network: - that has been trained on unlabeled text data, i.e. in a task-agnostic, unsupervised fashion, and - that processes a sequence of input words into a context-dependent embedding. E.g. the continuous bag-of-words and skip-gram model from Mikolov et al. (2013) is not considered a pre-trained language model because the embeddings are context-agnostic. \({}^2\) Fine-tuning is defined as the task-specific training of a model that has been initialized with the weights of a pre-trained language model. \({}^3\) The input vector \(\mathbf{y}0\) corresponds hereby to the \(\text{BOS}\) embedding vector required to predict the very first output word \(\mathbf{y}_1\). \({}^4\) Without loss of generalitiy, we exclude the normalization layers to not clutter the equations and illustrations. \({}^5\) For more detail on why uni-directional self-attention is used for \"decoder-only\" models, such as GPT2, and how sampling works exactly, please refer to the decoder section of the encoder-decoder blog post.
[ 0.022362612187862396, -0.02581346593797207, 0.013979997485876083, 0.01028943620622158, 0.05528733879327774, 0.07501856982707977, 0.023240508511662483, -0.023985596373677254, -0.038687773048877716, -0.04405863210558891, -0.07063513994216919, 0.05458589270710945, -0.04526229947805405, 0.06717180460691452, -0.0195955578237772, -0.011133940890431404, 0.0327150784432888, -0.03186839818954468, 0.007381713017821312, -0.024423077702522278, -0.008275396190583706, -0.03755895793437958, 0.030639000236988068, -0.041585635393857956, 0.015017129480838776, -0.06424583494663239, -0.024076921865344048, -0.026162438094615936, -0.08221716433763504, 0.030354591086506844, -0.12235531955957413, 0.018934879451990128, 0.03518463671207428, -0.0259112436324358, 0.00392038282006979, -0.023915916681289673, -0.1155981495976448, 0.02229796163737774, 0.05948740243911743, -0.014514240436255932, -0.07672564685344696, -0.012693801894783974, -0.05852625146508217, 0.02855343371629715, -0.021905601024627686, 0.006157692987471819, -0.19913065433502197, 0.06061401590704918, -0.03621448203921318, -0.034892208874225616, -0.038682855665683746, 0.07849010825157166, 0.0027992066461592913, 0.05333481729030609, 0.006943823769688606, -0.007844279520213604, 0.0017498846864327788, -0.09732505679130554, 0.03972567245364189, -0.007525639142841101, 0.054768156260252, 0.009749085642397404, -0.0338670052587986, -0.023367412388324738, 0.025043517351150513, 0.024172911420464516, -0.02438526786863804, 0.02316807210445404, -0.018493060022592545, 0.0040207309648394585, -0.052874259650707245, -0.09102486819028854, -0.031132349744439125, 0.03053894080221653, 0.006752250716090202, -0.0722862035036087, 0.008395242504775524, 0.004246564116328955, 0.03232315555214882, 0.024195479229092598, 0.0036232967395335436, 0.03217751532793045, 0.009271419607102871, 0.020299706608057022, 0.048548948019742966, 0.0159001387655735, 0.0628269761800766, -0.06548893451690674, -0.023458067327737808, 0.08766070008277893, -0.04711254686117172, -0.16192926466464996, -0.005604565143585205, -0.0169514250010252, 0.009759502485394478, 0.010279410518705845, 0.004072542767971754, 0.07579808682203293, 0.007576270028948784, -0.034077517688274384, 0.0037163232918828726, -0.028760623186826706, 0.052131809294223785, -0.05187632888555527, -0.04019252583384514, 0.018759606406092644, -0.04738911613821983, -0.06201642379164696, -0.035856183618307114, -0.012070952914655209, 0.024716509506106377, -0.00536046689376235, -0.05335995927453041, 0.07005249708890915, -0.10851012915372849, 0.04611251875758171, 0.027458952739834785, -0.0085015082731843, -0.0072996364906430244, 0.008933095261454582, 0.006131777074187994, 0.08415309339761734, 0.03800411522388458, -0.021275348961353302, -0.007568432949483395, 0.014955631457269192, -0.009756084531545639, -0.029712144285440445, -0.021474525332450867, -0.0279826819896698, 0.052985627204179764, 0.008392917923629284, 0.060456883162260056, 0.02411884255707264, -0.0038259876891970634, -0.07112226635217667, -0.030953299254179, -0.040496353060007095, -0.02589503675699234, 0.01960388384759426, -0.09794323891401291, 0.07638046145439148, 0.02873033471405506, -0.04289904609322548, 0.038640961050987244, 0.01736808568239212, -0.10624264180660248, 0.07473348826169968, 0.058053821325302124, 0.0069969273172318935, -0.04794268310070038, 0.03495071083307266, -0.044965922832489014, -0.11505454778671265, -0.004452385473996401, 0.03468025103211403, -0.021268146112561226, -0.003290622727945447, -0.059470824897289276, -0.02476079948246479, -0.04676252231001854, 0.014693262055516243, -0.0021815141662955284, -0.001970883458852768, 0.03959657624363899, -0.09662272781133652, 0.01889297366142273, 0.033485863357782364, -0.0038200700655579567, 0.008984616957604885, -0.016123760491609573, 0.056863754987716675, 0.09413985162973404, -0.031651586294174194, -0.04520699381828308, 0.017272308468818665, -0.03190411627292633, 0.07263851165771484, 0.04262583330273628, -0.04562985897064209, -0.022868184372782707, 0.009261464700102806, 0.006258000619709492, 0.021147027611732483, 0.04626419022679329, -0.06626448035240173, -0.005201330874115229, -0.027101341634988785, -0.07329843193292618, 0.012308100238442421, -0.06354136019945145, -0.032864682376384735, 0.060935575515031815, -0.015272535383701324, -0.009651564992964268, -0.06919024139642715, -0.022429948672652245, 0.1337982416152954, 0.025300662964582443, 0.05649079382419586, 0.1049988716840744, 0.04704585671424866, 0.06941460072994232, -0.0008848391007632017, -0.05185319483280182, 0.01687864027917385, 0.020724618807435036, -0.01762271113693714, 0.07671808451414108, -0.03334156051278114, 0.016816122457385063, -0.06414835900068283, -0.05246204510331154, -0.07214988768100739, 0.027082601562142372, -0.03604556992650032, 0.01714480109512806, -0.02667485550045967, 0.022999174892902374, -0.04072500765323639, 0.14144177734851837, -0.05355416610836983, -0.05194363370537758, -0.014587265439331532, -0.0011469541350379586, 0.041533686220645905, 0.0560770258307457, 0.006013213191181421, 0.07365532219409943, -0.03900601342320442, -0.026978036388754845, -0.07798843085765839, 0.010821337811648846, 0.021836211904883385, 0.012218066491186619, -0.010627193376421928, -0.004641762003302574, 0.022707780823111534, 0.04910266771912575, -0.012189310044050217, -0.0053323120810091496, 0.017032623291015625, 0.01497145090252161, 0.04246200621128082, -0.042305998504161835, -0.013018728233873844, 0.047580018639564514, 0.0026889548171311617, -0.026932258158922195, -0.014447584748268127, -0.0702538788318634, 0.058836616575717926, 0.0018861580174416304, -0.09036722034215927, 0.059457674622535706, 0.0524631030857563, -0.009321031160652637, -0.013951615430414677, 0.013308893889188766, -0.014371402561664581, -0.01192963495850563, -0.05185713246464729, -0.009527021087706089, -0.03882845863699913, -0.026054011657834053, -0.04162317514419556, -0.017458559945225716, -0.020314160734415054, 0.017107533290982246, 0.02982449159026146, 0.02547723986208439, -0.01068116631358862, 0.0445956215262413, 0.03138314187526703, 0.02634412981569767, 0.0008884517592377961, 0.041685231029987335, -0.03668001666665077, -0.029703794047236443, -0.004564539063721895, 0.009723191149532795, -0.03346503525972366, 0.035683151334524155, 0.01430030819028616, 0.03459225222468376, 0.023879414424300194, 0.01509171724319458, -0.02270285040140152, 0.008343410678207874, 0.03441610932350159, 0.009746326133608818, 0.02271631918847561, -0.013757523149251938, -0.034472689032554626, -0.009099850431084633, 0.012525828555226326, -0.004877807106822729, -0.008339249528944492, 0.017545603215694427, 0.0014320536283776164, -0.012312703765928745, 0.034917715936899185, 0.013571766205132008, -0.028269417583942413, -0.05002410337328911, 0.025391684845089912, 0.060335513204336166, 0.04582089185714722, -0.11020875722169876, -0.049925513565540314, 0.007963410578668118, 0.014446845278143883, -0.009928393177688122, -0.03193303197622299, 0.07350243628025055, -0.02756674960255623, -0.035473331809043884, -0.01729462295770645, 0.04543343186378479, 0.005313809495419264, 0.0401727594435215, 0.011908919550478458, -0.052772946655750275, -0.016788074746727943, -0.009605196304619312, 0.003417849773541093, 0.03507954627275467, -0.0007353306282311678, -0.015786321833729744, 0.005278593394905329, -0.0004919644561596215, 0.012506130151450634, -0.03568192198872566, -0.015142472460865974, 0.03565824404358864, -0.006719726603478193, -0.005603001452982426, -0.027012638747692108, -0.001798404031433165, -0.015756020322442055, -0.023254582658410072, 0.030088014900684357, -0.03046845644712448, -0.013269411399960518, 0.0049785044975578785, 0.02513226307928562, 0.03901343420147896, 0.03995233401656151, 0.014891507104039192, -0.004039296414703131, 0.00452348543331027, 0.009798888117074966, 0.009725287556648254, -0.02314024604856968, 0.03362254053354263, -0.03163033723831177, 0.0279588233679533, -0.025377117097377777, -0.018206454813480377, -0.020495561882853508, 0.008833939209580421, 0.042265161871910095, 0.02306373603641987, 0.008595253340899944, 0.00468304380774498, 0.016596907749772072, 0.010475214570760727, -0.005450290162116289, -0.04846169427037239, 0.010149209760129452, 0.007233979180455208, -0.010659056715667248, -0.04658537358045578, 0.07961134612560272, 0.0033475011587142944, 0.033455297350883484, -0.008605830371379852, 0.05839674174785614, -0.03018544428050518, 0.009305581450462341, 0.020788539201021194, 0.005281508434563875, -0.012557697482407093, 0.016474617645144463, -0.029413973912596703, 0.0293421670794487, 0.07265003025531769, 0.01235513761639595, -0.007810146082192659, -0.003317107679322362, -0.05051901564002037, 0.00589274475350976, 0.029779421165585518, 0.03359449654817581, -0.00165746605489403, -0.0014145757304504514, 0.023116324096918106, 0.0008137400727719069, 0.022832753136754036, -0.0031328722834587097, 0.00994978379458189, -0.027806079015135765, 0.02558806724846363, 0.01211911253631115, 0.022991523146629333, 0.01551368273794651, 0.014838522300124168, 0.008089564740657806, 0.028607206419110298, -0.0515245757997036, 0.0149347810074687, 0.013869616203010082, -0.0028491001576185226, 0.037865303456783295, -0.037859056144952774, -0.015277550555765629, 0.009679869748651981, -0.020956669002771378, 0.024893570691347122, -0.014909307472407818, 0.03351619094610214, 0.004505437798798084, 0.030519777908921242, 0.025857452303171158, 0.011228678748011589, -0.056613363325595856, -0.0193710345774889, 0.019378000870347023, -0.01883261650800705, 0.012203458696603775, -0.009160102345049381, 0.013932703994214535, 0.03344152122735977, -0.013367201201617718, 0.020458444952964783, -0.008744301274418831, 0.004729483276605606, -0.004103038925677538, -0.04801156371831894, -0.0026710336096584797, 0.020032471045851707, -0.04866137355566025, 0.025533732026815414, 0.007756292354315519, 0.010384814813733101, 0.024614540860056877, -0.009177898056805134, -0.04409351572394371, 0.005673098843544722, -0.009718766435980797, 0.028766531497240067, -0.028530890122056007, 0.03463563695549965, -0.015979548916220665, -0.002385428873822093, -0.0005027798470109701, -0.010905224829912186, 0.00733049213886261, 0.05635886266827583, -0.024286478757858276, -0.038505807518959045, 0.015960128977894783, 0.03304295241832733, -0.028570003807544708, -0.008534171618521214, 0.042299915105104446, 0.013163427822291851, 0.01990981586277485, 0.007466213312000036, 0.008684265427291393, -0.04438638314604759, 0.017047856003046036, -0.01034814864397049, 0.015597939491271973, -0.042941659688949585, -0.03193608298897743, 0.007921775802969933, 0.015581942163407803, 0.009164607152342796, -0.057612814009189606, 0.025650210678577423, -0.0063030775636434555, 0.016136066988110542, 0.006091063376516104, 0.005236324854195118, 0.027219243347644806, -0.0007504966342821717, 0.027400968596339226, 0.010045505128800869, 0.02223885990679264, 0.014226854778826237, 0.03331726789474487, 0.010460416786372662, 0.004900886677205563, 0.07332853227853775, 0.05827716365456581, 0.02818850800395012, 0.010791330598294735, 0.043586377054452896, -0.0016395336715504527, 0.039228763431310654, -0.015280686318874359, -0.009193142876029015, -0.01313127763569355, 0.009198117069900036, 0.03385784476995468, -0.03176775947213173, 0.017544567584991455, 0.015382119454443455, 0.012847616337239742, -0.016272710636258125, -0.027826836332678795, 0.012670549564063549, -0.0388682596385479, -0.03356470912694931, -0.04692748561501503, 0.02023455873131752, -0.0330304317176342, 0.014345399104058743, -0.006611909717321396, -0.02977915294468403, 0.008064567111432552, 0.006458465941250324, -0.010710046626627445, -0.011442838236689568, 0.0633259266614914, 0.04655131697654724, 0.03466922044754028, 0.0038183352444320917, -0.01377053465694189, -0.013502524234354496, 0.014393226243555546, 0.019040700048208237, -0.024277638643980026, -0.008985180407762527, 0.01898796670138836, 0.02372247539460659, 0.0021908399648964405, 0.017745302990078926, -0.022902943193912506, -0.03441948816180229, 0.03915785998106003, -0.01336787361651659, -0.03404931724071503, -0.017717743292450905, 0.013196371495723724, 0.013748643919825554, 0.0209353044629097, -0.007953587919473648, -0.021732062101364136, 0.0050489348359405994, 0.02921428345143795, -0.04501292482018471, 0.03989523649215698, 0.012406868860125542, -0.019427284598350525, 0.006264461670070887, 0.019086452201008797, 0.08935834467411041, -0.032958630472421646, 0.02915007434785366, -0.0008356424514204264, 0.026357460767030716, 0.04796212166547775, -0.002442355500534177, -0.02251484803855419, 0.011103103868663311, 0.017029859125614166, 0.017060933634638786, -0.061421845108270645, 0.018598288297653198, 0.04102163016796112, -0.052658360451459885, 0.022972460836172104, 0.0003275595372542739, -0.04126680642366409, 0.020419536158442497, 0.01909503899514675, 0.017804065719246864, 0.007783659268170595, 0.001957571366801858, 0.0009709639707580209, 0.03286987915635109, 0.005751750431954861, 0.034928955137729645, 0.08699709922075272, -0.001032735570333898, 0.051092490553855896, 0.018149083480238914, 0.016179069876670837, 0.03444591537117958, 0.0104574179276824, -0.02381996065378189, 0.011788366362452507, 0.06327393651008606, 0.007985040545463562, 0.012839192524552345, 0.018147196620702744, -0.016612788662314415, -0.01000688225030899, -0.027083463966846466, 0.004080832004547119, -0.04053104668855667, -0.00801063422113657, -0.011139575392007828, 0.004136848263442516, 0.06323516368865967, -0.03310109302401543, 0.04026136174798012, 0.0574764758348465, -0.02323048934340477, -0.007080931216478348, 0.026655009016394615, 0.05656158924102783, 0.024328745901584625, 0.03725006803870201, 0.0297615397721529, -0.013497522100806236, 0.0026064550038427114, 0.05239494889974594, 0.029293106868863106, 0.013809716328978539, 0.025505751371383667, -0.031086640432476997, 0.02594538778066635, -0.01116951648145914, 0.00784730352461338, 0.021613288670778275, 0.030381159856915474, -0.02316858433187008, 0.016067931428551674, 0.00517034437507391, -0.04395593702793121, 0.018204396590590477, 0.017765121534466743, -0.012656018137931824, 0.0005434218910522759, -0.016953760758042336, 0.00991786364465952, 0.04964395985007286, -0.027026746422052383, -0.025470925495028496, -0.022590965032577515, -0.0117334621027112, -0.00466301990672946, 0.033067647367715836, 0.007475435733795166, -0.024032389745116234, -0.03449861332774162, -0.017279520630836487, -0.02314283698797226, 0.033133070915937424, -0.028974656015634537, -0.026970043778419495, 0.058530326932668686, 0.02321496419608593, -0.0069353762082755566, 0.016144506633281708, 0.039110373705625534, 0.02281840518116951, -0.01600179634988308, -0.008464915677905083, -0.024692116305232048, -0.03101303242146969, 0.005151822231709957, -0.04901246726512909, 0.024254323914647102, -0.015282252803444862, 0.032008472830057144, 0.010868082754313946, 0.02362416684627533, -0.026629943400621414, -0.017319319769740105, -0.031476374715566635, -0.016573777422308922, 0.0015326684806495905, 0.00848075095564127, 0.030238572508096695, -0.009594934992492199, 0.006458313204348087, -0.013831800781190395, -0.02892874926328659, -0.00818683672696352, 0.002012359444051981, 0.031146131455898285, -0.018612727522850037, -0.023460667580366135, -0.03817015141248703, 0.07028764486312866, -0.0011051363544538617, 0.03645533695816994, 0.021367859095335007, 0.007471629884094, 0.03614253178238869, -0.05857548862695694, 0.004341348074376583, -0.03422774001955986, 0.014826049096882343, -0.03665028512477875, -0.03919891268014908, -0.01081062387675047, 0.03550992161035538, -0.022384418174624443, -0.01686081849038601, -0.011659997515380383, 0.009321830235421658, -0.06293263286352158, 0.0009096169378608465, 0.004349472466856241, 0.026867156848311424, 0.03073742799460888, 0.008807642385363579, 0.03817120939493179, 0.03263881057500839, -0.019657006487250328, -0.04008856043219566, -0.04166213423013687, 0.024484645575284958, 0.06254343688488007, -0.0006656527984887362, -0.014891167171299458, -0.029550844803452492, -0.03249497711658478, -0.0029305957723408937, -0.004452887922525406, -0.005360837560147047, 0.05974428728222847, -0.03173418343067169, -0.01257298607379198, -0.0018556158756837249, -0.009231909178197384, -0.0031872650142759085, 0.007067542988806963, 0.02660997025668621, -0.04494195058941841, 0.00007861616177251562, 0.013086688704788685, -0.02873319387435913, -0.034805018454790115, -0.007604419719427824, 0.015606262721121311, 0.045660898089408875, 0.031710218638181686, -0.0007479421328753233, 0.0014287211233749986, -0.017149001359939575, 0.03249812498688698, 0.0070266928523778915, 0.005546219181269407, -0.024431077763438225, 0.0199686661362648, 0.012317773886024952, -0.02300071530044079, -0.02835802547633648, 0.05488630756735802, 0.03251492232084274, 0.004617772065103054, 0.007553430739790201, -0.0032891365699470043, 0.008257775567471981, -0.024652322754263878, 0.034254807978868484, -0.020951762795448303, 0.09102382510900497, 0.047370098531246185, 0.022821322083473206, -0.0004000164335593581, 0.023343004286289215 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Recap Encoder-Decoder Model First, let\'s do a quick recap of the encoder-decoder architecture. The encoder (shown in green) is a stack of encoder blocks. Each encoder block is composed of a bi-directional self-attention layer, and two feed-forward layers \({}^1\). The decoder (shown in orange) is a stack of decoder blocks, followed by a dense layer, called LM Head. Each decoder block is composed of a uni-directional self-attention layer, a cross-attention layer, and two feed-forward layers. The encoder maps the input sequence \(\mathbf{X}{1:n}\) to a contextualized encoded sequence \(\mathbf{\overline{X}}{1:n}\) in the exact same way BERT does. The decoder then maps the contextualized encoded sequence \(\mathbf{\overline{X}}{1:n}\) and a target sequence \(\mathbf{Y}{0:m-1}\) to the logit vectors \(\mathbf{L}{1:m}\). Analogous to GPT2, the logits are then used to define the distribution of the target sequence \(\mathbf{Y}{1:m}\) conditioned on the input sequence \(\mathbf{X}{1:n}\) by means of a softmax operation. To put it into mathematical terms, first, the conditional distribution is factorized into \(m - 1\) conditional distributions of the next word \(\mathbf{y}i\) by Bayes\' rule. $$ p{\theta_{\text{enc, dec}}}(\mathbf{Y}{1:m} | \mathbf{X}{1:n}) = p_{\theta_{\text{dec}}}(\mathbf{Y}{1:m} | \mathbf{\overline{X}}{1:n}) = \prod_{i=1}^m p_{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i -1}, \mathbf{\overline{X}}{1:n}), \text{ with } \mathbf{\overline{X}}{1:n} = f_{\theta_{\text{enc}}}(\mathbf{X}{1:n}). $$ Each \"next-word\" conditional distributions is thereby defined by the softmax of the logit vector as follows. $$ p{\theta_{\text{dec}}}(\mathbf{y}i | \mathbf{Y}{0: i -1}, \mathbf{\overline{X}}{1:n}) = \textbf{Softmax}(\mathbf{l}_i). $$ For more detail, please refer to the Encoder-Decoder notebook.
[ 0.03652266412973404, -0.02087125927209854, 0.06582975387573242, -0.03551356866955757, 0.07103225588798523, 0.07060138881206512, -0.021967368200421333, -0.005872990470379591, -0.014882246032357216, 0.0017349766567349434, -0.06130130961537361, 0.06361812353134155, -0.004988660104572773, 0.06224824860692024, -0.04833878204226494, 0.019122686237096786, 0.017695458605885506, -0.089891716837883, 0.011728583835065365, -0.05144016072154045, 0.02529158629477024, -0.08102414757013321, 0.05704457312822342, -0.033704619854688644, 0.012754452414810658, -0.016246484592556953, -0.04131979122757912, 0.002513966988772154, -0.05915290489792824, 0.055482085794210434, -0.08422056585550308, 0.0065613132901489735, 0.005924904718995094, -0.04248620942234993, -0.027449188753962517, -0.03038950264453888, -0.1665571630001068, 0.021548844873905182, 0.019422346726059914, 0.002702157711610198, -0.040802422910928726, -0.03982342779636383, -0.0767369419336319, 0.053604379296302795, -0.013159421272575855, -0.012190643697977066, -0.19628600776195526, 0.0625438392162323, -0.05779379978775978, -0.04726225137710571, -0.07542162388563156, 0.05620738863945007, -0.09784482419490814, 0.06821878254413605, -0.04517446458339691, -0.004455137066543102, 0.017216145992279053, -0.056142933666706085, 0.0385592021048069, -0.00401125056669116, 0.028731096535921097, 0.04204898327589035, 0.0022913736756891012, 0.05759134143590927, 0.013889763504266739, -0.009166613221168518, -0.0025708579923957586, -0.009264303371310234, -0.00577567471191287, 0.006668404210358858, -0.05978801101446152, -0.03284580633044243, -0.011815316043794155, 0.0032550408504903316, 0.002570579992607236, -0.06186529994010925, 0.029614731669425964, 0.016121214255690575, 0.03071255423128605, 0.004221806302666664, 0.00823047012090683, 0.012957506813108921, 0.0344596765935421, 0.07582098245620728, 0.037214744836091995, 0.024521108716726303, 0.045405998826026917, -0.07936988025903702, -0.049093056470155716, 0.08559657633304596, -0.08102268725633621, -0.15568876266479492, 0.015557998791337013, 0.008343670517206192, 0.026118077337741852, -0.029347876086831093, 0.003929564729332924, 0.0051252045668661594, -0.005451108794659376, -0.016240352764725685, 0.022576240822672844, -0.002231503836810589, 0.063068687915802, -0.02391859143972397, -0.030245164409279823, 0.03183576092123985, -0.02486833557486534, -0.10078664869070053, -0.08587414026260376, 0.00661642849445343, 0.03764111548662186, -0.0248472448438406, -0.008697543293237686, 0.00799690093845129, -0.08686389774084091, 0.01511991024017334, 0.030289670452475548, -0.028185712173581123, 0.014707433991134167, 0.04755403846502304, -0.028247429057955742, 0.055960267782211304, 0.025662070140242577, -0.01850573532283306, 0.018284203484654427, -0.004944527056068182, -0.04928523302078247, -0.008411937393248081, -0.025726767256855965, -0.03824396803975105, 0.0728812962770462, -0.014710965566337109, 0.06208020821213722, 0.03143303841352463, -0.02622394822537899, -0.02599206753075123, -0.019684094935655594, -0.03566444292664528, -0.01645056903362274, -0.021701838821172714, -0.10096646845340729, 0.035539839416742325, 0.013793748803436756, 0.002688074018806219, 0.04586424678564072, 0.0007479462074115872, -0.06507398933172226, 0.06688543409109116, 0.05024418979883194, 0.04560769349336624, -0.02652294933795929, -0.01508118025958538, 0.026721077039837837, -0.06005682051181793, 0.005154332611709833, 0.022935926914215088, 0.021708721294999123, -0.05439993366599083, -0.07545796781778336, 0.008258446119725704, 0.03251352906227112, 0.023282742127776146, -0.020259365439414978, 0.016886785626411438, 0.036080267280340195, -0.05766682326793671, 0.02323031984269619, 0.01986703835427761, -0.047120679169893265, 0.032703857868909836, -0.05156248062849045, -0.016012119129300117, 0.09537601470947266, 0.03369336947798729, -0.03358472138643265, 0.01782827079296112, 0.027012823149561882, 0.08541936427354813, -0.004644853062927723, -0.0346817709505558, -0.030978187918663025, -0.03068958781659603, 0.03662261739373207, -0.004950969014316797, -0.01844753883779049, -0.03803094103932381, 0.00185577932279557, -0.050494756549596786, -0.04842539504170418, 0.05160040408372879, -0.03729693219065666, -0.01636999100446701, 0.04488828405737877, -0.040564388036727905, 0.047674160450696945, -0.05474613606929779, -0.03483716398477554, 0.09583849459886551, 0.09989392757415771, 0.025148466229438782, 0.05524853989481926, 0.007081484422087669, 0.042148392647504807, -0.021031316369771957, 0.011223128996789455, -0.007814906537532806, 0.008060666732490063, -0.02874070778489113, 0.047368913888931274, -0.02628447487950325, 0.0037715472280979156, -0.04948902502655983, -0.029577599838376045, -0.09390486776828766, 0.03717801719903946, -0.017587140202522278, 0.05168163776397705, 0.03201404958963394, -0.012030704878270626, 0.012262380681931973, 0.1336938440799713, -0.07001226395368576, -0.006406436674296856, -0.026424920186400414, 0.021390466019511223, 0.0019512010039761662, 0.0707191601395607, -0.03328360244631767, 0.08774163573980331, -0.02462998405098915, -0.034384194761514664, -0.05963617190718651, 0.05856270343065262, 0.003380879294127226, -0.020684652030467987, -0.031088700518012047, -0.008603175170719624, 0.029157577082514763, 0.04879910126328468, -0.07585549354553223, 0.031045906245708466, -0.0009175916784442961, 0.005968496669083834, -0.008918875828385353, -0.08771511912345886, -0.010310857556760311, 0.03656131401658058, -0.0016363339964300394, -0.08037520200014114, 0.01805104874074459, -0.05236198753118515, 0.0521601140499115, 0.008730282075703144, -0.0821259468793869, 0.004930156748741865, 0.06108102947473526, -0.009391425177454948, -0.04190989211201668, -0.006058435887098312, 0.00846162810921669, -0.018068376928567886, -0.007052787113934755, 0.0051862685941159725, -0.052290767431259155, -0.04001474753022194, -0.01316159125417471, 0.00001744624023558572, 0.030428411439061165, -0.012355797924101353, 0.02400660328567028, 0.004026569426059723, 0.004044963978230953, 0.05133514478802681, 0.045877400785684586, 0.06078355759382248, -0.016403665766119957, 0.039146967232227325, -0.0626162737607956, -0.025727948173880577, -0.0400407612323761, 0.016051752492785454, -0.01915040798485279, 0.04999127984046936, 0.04906105622649193, 0.0351400189101696, 0.006437799893319607, -0.013148549944162369, 0.008075105957686901, 0.019884461537003517, 0.02594071440398693, 0.02760913223028183, 0.03188745304942131, -0.002153454814106226, -0.0021251633297652006, 0.0069185649044811726, -0.022974614053964615, -0.014671542681753635, -0.004480131436139345, -0.020512789487838745, 0.039290763437747955, 0.009227716363966465, 0.05328139290213585, 0.009850465692579746, 0.007794581353664398, -0.014943607151508331, 0.011545312590897083, 0.05841519683599472, 0.08781304210424423, -0.09988024085760117, -0.04170484468340874, 0.02126404084265232, -0.010290701873600483, 0.012024302035570145, -0.04521079361438751, 0.05640917271375656, 0.028215155005455017, -0.025294171646237373, -0.029849372804164886, 0.05503905937075615, -0.02027272619307041, 0.018102038651704788, 0.0016939155757427216, -0.017171287909150124, -0.02410227805376053, -0.0007711420184932649, -0.007244049571454525, 0.05528087541460991, -0.01643831469118595, 0.023460498079657555, 0.0218108631670475, 0.0025173048488795757, 0.001507256063632667, -0.038023803383111954, -0.010488118045032024, 0.037623122334480286, -0.014859051443636417, 0.008485718630254269, -0.006699176970869303, -0.05607088655233383, -0.025392333045601845, -0.006689036730676889, -0.011265372857451439, -0.026198426261544228, 0.00812081340700388, 0.02667444944381714, -0.00365179474465549, 0.02063489519059658, 0.06310095638036728, 0.029720190912485123, 0.03707071766257286, 0.010192504152655602, 0.0027041323482990265, 0.031795479357242584, -0.017591292038559914, 0.03982327878475189, -0.01032768003642559, 0.010644434951245785, -0.040435176342725754, -0.0344388373196125, -0.037907134741544724, -0.027272479608654976, 0.03596026077866554, 0.02208031713962555, 0.006355005782097578, -0.0066972048953175545, 0.00039942795410752296, 0.03663923218846321, 0.022071650251746178, -0.021061768755316734, 0.01128869317471981, -0.008777911774814129, -0.02287250943481922, -0.02681039646267891, 0.021233627572655678, 0.02873903140425682, 0.024579619988799095, -0.016317900270223618, 0.034937214106321335, -0.011337351985275745, 0.0031296832021325827, 0.012043931521475315, 0.004537391476333141, 0.012674098834395409, 0.02644706889986992, -0.029926961287856102, 0.011543983593583107, 0.09768056124448776, -0.008666629903018475, 0.021262384951114655, 0.017038580030202866, -0.04079096391797066, 0.005773620214313269, 0.010158133693039417, 0.015720585361123085, -0.00411394564434886, -0.016485700383782387, 0.03738036006689072, 0.0004935653996653855, 0.011305520310997963, -0.01706327497959137, 0.014502731151878834, 0.028057580813765526, -0.008755490183830261, 0.02017941325902939, 0.006829042918980122, 0.014482934027910233, 0.03449832648038864, 0.03893807902932167, 0.02085353620350361, -0.07488089054822922, -0.008718091994524002, -0.016332117840647697, -0.016910644248127937, 0.04640103504061699, -0.022745076566934586, -0.02185167372226715, 0.04797099903225899, -0.026995383203029633, 0.031041087582707405, -0.008929385803639889, 0.023811157792806625, 0.018889717757701874, 0.044828321784734726, -0.0012531442334875464, -0.027345875278115273, -0.08550473302602768, 0.0070732212625443935, 0.0042802696116268635, -0.013630206696689129, -0.021130627021193504, 0.003857477568089962, -0.003872830653563142, 0.02432137168943882, -0.008688594214618206, 0.03427328169345856, 0.0039616734720766544, -0.01228833757340908, -0.028818117454648018, -0.03228696808218956, -0.0061706118285655975, 0.03472539037466049, -0.03152933344244957, 0.03385923430323601, 0.03123314306139946, 0.03308563679456711, 0.04314151778817177, 0.011285620741546154, -0.07325000315904617, -0.008093341253697872, 0.01251847855746746, 0.051521919667720795, -0.033647023141384125, 0.011683821678161621, -0.017027176916599274, -0.026398060843348503, 0.00903227087110281, -0.029635213315486908, 0.015322512947022915, 0.04175567626953125, -0.004030630923807621, -0.09025635570287704, 0.021346740424633026, -0.008661551401019096, -0.016424132511019707, 0.012053286656737328, 0.051011014729738235, 0.0029931727331131697, 0.028949350118637085, 0.011779747903347015, -0.0017939824610948563, -0.07019148766994476, 0.013255375437438488, 0.028305690735578537, 0.030698496848344803, -0.03445969894528389, -0.031262967735528946, 0.0321882925927639, 0.005372514016926289, 0.010075938887894154, -0.010668110102415085, 0.02176813781261444, -0.004367116838693619, -0.0066688149236142635, 0.005773945711553097, -0.02454778552055359, -0.001737551880069077, -0.012118770740926266, 0.004850055556744337, -0.02467835508286953, 0.008462563157081604, -0.007294970098882914, -0.0022764564491808414, -0.0014026535209268332, 0.0155419260263443, 0.06482799351215363, 0.05319182947278023, -0.0120964664965868, 0.04109344631433487, 0.06010248512029648, -0.005098139401525259, 0.021218454465270042, -0.029752489179372787, 0.0010899733752012253, 0.023331791162490845, 0.013125298544764519, 0.02531794086098671, -0.024499770253896713, -0.003168317722156644, 0.02936677820980549, 0.03491273894906044, -0.010247980244457722, -0.015062629245221615, 0.028618134558200836, -0.04641875624656677, 0.0044062938541173935, -0.03531757742166519, -0.003734021680429578, -0.0202636756002903, 0.025552161037921906, -0.03661057725548744, -0.009598548524081707, -0.002226924756541848, 0.001745239133015275, -0.053970012813806534, -0.041885923594236374, 0.006133062765002251, 0.02237808145582676, 0.053987350314855576, -0.00907378364354372, 0.0036484107840806246, -0.02214980684220791, 0.022238418459892273, 0.0027818467933684587, -0.035807352513074875, -0.020807385444641113, -0.0008017271175049245, -0.0018991511315107346, 0.02183631621301174, 0.05527201667428017, -0.0511411651968956, -0.03601042181253433, 0.03458896279335022, -0.031511761248111725, -0.024277102202177048, -0.023034239187836647, 0.04590114206075668, 0.013493375852704048, 0.028495177626609802, 0.028388602659106255, -0.004482272081077099, -0.0188808124512434, 0.036873988807201385, -0.04323329031467438, 0.02059296704828739, 0.04581902176141739, -0.018107393756508827, 0.036498963832855225, 0.0009595743031241, 0.04245027154684067, 0.0031774777453392744, -0.008375504054129124, 0.03779720142483711, 0.023224331438541412, 0.04254399985074997, 0.04005879536271095, -0.011546430177986622, -0.005573836620897055, 0.02422071434557438, 0.02386780083179474, -0.028313910588622093, 0.0004490925057325512, -0.00649361964315176, -0.019498201087117195, 0.023224448785185814, -0.018292125314474106, -0.01314392127096653, 0.02107090689241886, 0.010629282332956791, 0.010458353906869888, 0.004289287608116865, -0.036685045808553696, 0.0010543756652623415, -0.011444956995546818, -0.027134962379932404, 0.020758455619215965, 0.08028838783502579, 0.009683452546596527, 0.037725213915109634, 0.006160189863294363, 0.0058561209589242935, 0.053227733820676804, 0.023805320262908936, 0.006161088589578867, 0.011054938659071922, 0.03188304230570793, 0.00875167828053236, 0.02038693055510521, 0.019005168229341507, -0.0031863574404269457, 0.0337652824819088, -0.026116380468010902, -0.011517244391143322, -0.042362991720438004, 0.02498622238636017, 0.006742988713085651, -0.04887346550822258, 0.05078822746872902, -0.033656779676675797, 0.035478271543979645, 0.06572392582893372, 0.007950820960104465, -0.002419484779238701, 0.020856650546193123, 0.0352209247648716, 0.024335214868187904, 0.031476378440856934, 0.03880758211016655, -0.009486059658229351, -0.0022372575476765633, 0.02985522150993347, 0.01399948913604021, 0.04292377457022667, 0.014275722205638885, -0.06438792496919632, 0.006026113871484995, -0.011355284601449966, -0.011978396214544773, -0.00038788921665400267, 0.01916065253317356, -0.03810977190732956, -0.01929461769759655, -0.0117863230407238, -0.026299968361854553, 0.0065485453233122826, 0.05069594085216522, 0.014418420381844044, 0.012349365279078484, -0.015965253114700317, 0.0003554775030352175, 0.031744588166475296, -0.0036511190701276064, -0.004873531870543957, -0.0405416376888752, -0.018141889944672585, 0.0028585297986865044, 0.0050190528854727745, -0.016711004078388214, -0.03576159104704857, -0.021684207022190094, 0.03938605636358261, -0.07592084258794785, 0.022689836099743843, -0.017579490318894386, -0.03828279674053192, 0.06539920717477798, 0.01530330628156662, -0.010388001799583435, 0.017728442326188087, 0.00673723267391324, 0.0010205411817878485, -0.027606187388300896, 0.0001146124632214196, -0.026145847514271736, -0.01009453646838665, -0.038183748722076416, -0.010862152092158794, -0.02463102713227272, 0.008753840811550617, 0.030663179233670235, 0.034154631197452545, 0.025658167898654938, -0.024049699306488037, -0.042246293276548386, -0.011968863196671009, 0.013738925568759441, -0.019160211086273193, 0.00782432034611702, 0.024024955928325653, 0.010179797187447548, 0.011361604556441307, 0.00019796415290329605, -0.01896381564438343, -0.041312914341688156, 0.031579941511154175, 0.025081943720579147, 0.005559196230024099, -0.013071014545857906, -0.006166860461235046, 0.049022361636161804, -0.010378009639680386, 0.027919486165046692, 0.04279713332653046, 0.027769872918725014, 0.012617630884051323, -0.04405803978443146, 0.00849038828164339, -0.017002273350954056, 0.0037769677583128214, -0.020097868517041206, -0.051421262323856354, -0.011470633558928967, 0.016424382105469704, 0.01980016753077507, 0.012900029309093952, -0.033405203372240067, 0.005148500669747591, -0.03244905546307564, -0.011774327605962753, -0.004235501866787672, 0.03550070896744728, 0.03516572341322899, -0.017260072752833366, 0.018578972667455673, -0.029277386143803596, -0.026006270200014114, -0.05092039331793785, -0.022718265652656555, 0.02646520547568798, 0.06714767962694168, 0.03236201032996178, 0.024212593212723732, 0.008618531748652458, -0.033134575933218, -0.018953487277030945, -0.007568589877337217, 0.002370173344388604, 0.009340118616819382, -0.016919370740652084, -0.004208758007735014, 0.015064162202179432, -0.0020283698104321957, 0.00047249204362742603, -0.006771466229110956, 0.037378523498773575, -0.0055600982159376144, -0.030537405982613564, 0.016258681192994118, -0.02625654637813568, -0.02947079949080944, -0.004549320787191391, 0.0075401668436825275, 0.039841178804636, 0.02123507298529148, 0.03519098088145256, 0.04363870993256569, 0.0019603148102760315, -0.00366893969476223, 0.008399911224842072, -0.009114331565797329, -0.010463076643645763, -0.010882186703383923, -0.0012402049032971263, -0.04250488430261612, -0.008233621716499329, 0.01777803711593151, 0.025032205507159233, 0.011385195888578892, 0.004846401046961546, -0.01720690354704857, 0.017642073333263397, -0.05041586980223656, 0.05627584084868431, -0.01031604316085577, 0.08781227469444275, -0.009225760586559772, 0.03598193824291229, 0.030704127624630928, 0.022018736228346825 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Sentence Fusion and -Splitting (DiscoFuse, WikiSplit) Sentence Fusion is the task of combining multiple sentences into a single coherent sentence. E.g. the two sentences: As a run-blocker, Zeitler moves relatively well. Zeitler too often struggles at the point of contact in space. should be connected with a fitting linking word, such as: As a run-blocker, Zeitler moves relatively well. However, he too often struggles at the point of contact in space. As can be seen the linking word \"however\" provides a coherent transition from the first sentence to the second one. A model that is capable of generating such a linking word has arguably learned to infer that the two sentences above contrast to each other. The inverse task is called Sentence splitting and consists of splitting a single complex sentence into multiple simpler ones that together retain the same meaning. Sentence splitting is considered as an important task in text simplification, cf. to Botha et al. (2018). As an example, the sentence: Street Rod is the first in a series of two games released for the PC and Commodore 64 in 1989 can be simplified into Street Rod is the first in a series of two games . It was released for the PC and Commodore 64 in 1989 It can be seen that the long sentence tries to convey two important pieces of information. One is that the game was the first of two games being released for the PC, and the second being the year in which it was released. Sentence splitting, therefore, requires the model to understand which part of the sentence should be divided into two sentences, making the task more difficult than sentence fusion. A common metric to evaluate the performance of models on sentence fusion resp. -splitting tasks is SARI (Wu et al. (2016), which is broadly based on the F1-score of label and model output. Let\'s see how the models perform on sentence fusion and -splitting. |Model | 100% DiscoFuse (SARI) |10% DiscoFuse (SARI) |100% WikiSplit (SARI) |---------------------- |----------------------- |---------------------- |----------------------- |Rnd2Rnd | 86.9 | 81.5 | 61.7 |Rnd2BERT | 87.6 | 82.1 | 61.8 |BERT2Rnd | 89.3 | 86.1 | 63.1 |Rnd2GPT2 | 86.5 | 81.4 | 61.3 |BERT2BERT | 89.3 | 86.1 | 63.2 |BERTShare | 89.2 | 86.0 | 63.5 |RoBERTaShare | 89.7 | 86.0 | 63.4 |BERT2GPT2 | 88.4 | 84.1 | 62.4 |RoBERTa2GPT2 | 89.9 | 87.1 | 63.2 |--- | --- | --- | --- |RoBERTaShare (large) | 90.3 | 87.7 | 63.8 The first two columns show the performance of the encoder-decoder models on the DiscoFuse evaluation data. The first column states the results of encoder-decoder models trained on all (100%) of the training data, while the second column shows the results of the models trained only on 10% of the training data. We observe that warm-started models perform significantly better than the randomly initialized baseline models Rnd2Rnd, Rnd2Bert, and Rnd2GPT2. A warm-started RoBERTa2GPT2 model trained only on 10% of the training data is on par with an Rnd2Rnd model trained on 100% of the training data. Interestingly, the Bert2Rnd baseline performs equally well as a fully warm-started Bert2Bert model, which indicates that warm-starting the encoder-part is more effective than warm-starting the decoder-part. The best results are obtained by RoBERTa2GPT2, followed by RobertaShare. Sharing encoder and decoder weight parameters does seem to slightly increase the model\'s performance. On the more difficult sentence splitting task, a similar pattern emerges. Warm-started encoder-decoder models significantly outperform encoder-decoder models whose encoder is randomly initialized and encoder-decoder models with shared weight parameters yield better results than those with uncoupled weight parameters. On sentence splitting the BertShare models yields the best performance closely followed by RobertaShare. In addition to the 12-layer model variants, the authors also trained and evaluated a 24-layer RobertaShare (large) model which outperforms all 12-layer models significantly.
[ 0.022469475865364075, 0.029431818053126335, 0.02442772127687931, 0.020902100950479507, 0.08870600163936615, 0.05304953455924988, -0.03872644901275635, 0.025636430829763412, -0.06280620396137238, -0.05990223586559296, -0.04018525406718254, -0.04488075152039528, -0.06310101598501205, 0.01909519173204899, -0.06384876370429993, 0.10553939640522003, 0.03883444145321846, -0.030768387019634247, 0.04530380293726921, -0.08887455612421036, -0.012929165735840797, 0.051851991564035416, -0.010389627888798714, 0.00560425641015172, 0.1039971336722374, 0.00013110222062096, -0.005972492974251509, -0.03259165585041046, -0.006563228089362383, 0.043758127838373184, -0.040636733174324036, -0.022534364834427834, -0.047785889357328415, 0.03319578617811203, 0.00791686587035656, 0.040185604244470596, -0.05665203928947449, 0.048265665769577026, 0.060607947409152985, -0.05597949028015137, -0.05876817926764488, -0.03721374273300171, -0.007697324734181166, -0.05539150908589363, 0.0036842268891632557, -0.007295344024896622, -0.08732834458351135, 0.11004228889942169, -0.07208027690649033, -0.0490448884665966, -0.08871744573116302, 0.017747750505805016, -0.004322133958339691, -0.026766842231154442, -0.03637465089559555, 0.033653873950242996, -0.008760131895542145, -0.053431835025548935, 0.09099035710096359, 0.040656182914972305, 0.002570453332737088, -0.08295425027608871, -0.0165848471224308, -0.0145383570343256, 0.023956432938575745, 0.02499249391257763, -0.055212631821632385, 0.06782335788011551, -0.10753920674324036, -0.014485129155218601, 0.04286472126841545, 0.014131576754152775, -0.013924737460911274, -0.012464889325201511, 0.0676758661866188, -0.028277738019824028, 0.02372894249856472, 0.03160867094993591, -0.026894232258200645, -0.09162380546331406, -0.02137111872434616, 0.03861190751194954, 0.012237190268933773, 0.053941383957862854, 0.027251077815890312, -0.08862782269716263, -0.04935567453503609, -0.008868912234902382, -0.07819703221321106, 0.06394309550523758, 0.03933339938521385, -0.07574138045310974, 0.011891217902302742, 0.08974562585353851, 0.029232675209641457, 0.024431442841887474, 0.032259076833724976, 0.032070063054561615, -0.01339389756321907, -0.03068631887435913, 0.04965178668498993, -0.03630121052265167, 0.06720872223377228, -0.007177975028753281, 0.02711612358689308, 0.08812752366065979, -0.06299199163913727, 0.05808253586292267, -0.0001858511968748644, 0.056924499571323395, 0.014669213443994522, 0.05411244556307793, -0.020669111981987953, 0.0703878179192543, -0.0963028147816658, 0.03486303240060806, 0.017672495916485786, 0.07839538156986237, -0.07355150580406189, 0.03080068901181221, -0.012856918387115002, 0.04176836460828781, 0.10683663189411163, 0.04718601703643799, -0.005269892048090696, 0.022520901635289192, -0.012578574009239674, 0.004495023284107447, 0.021331632509827614, -0.0014830961590632796, 0.007756460923701525, 0.037226174026727676, 0.01653771661221981, 0.006395659875124693, -0.04020216688513756, -0.0805269330739975, 0.02437497302889824, -0.010220414958894253, 0.02022976614534855, -0.04317929223179817, 0.028727469965815544, 0.030044596642255783, -0.023570187389850616, 0.03319045901298523, -0.028319811448454857, 0.0843028798699379, -0.06800507754087448, -0.02344379760324955, 0.02398630790412426, 0.03677104786038399, -0.04099538177251816, 0.012343645095825195, -0.06620996445417404, -0.04073353111743927, 0.0578618086874485, 0.04681575670838356, 0.010596263222396374, 0.013820060528814793, 0.034454282373189926, -0.017608938738703728, 0.03334978595376015, 0.0036525498144328594, -0.023332582786679268, 0.010334915481507778, 0.013769341632723808, -0.013802888803184032, -0.01949245296418667, 0.07765095680952072, 0.00938643142580986, -0.01712041161954403, -0.024759480729699135, -0.01651124469935894, 0.05127229541540146, -0.06761125475168228, 0.007308088708668947, 0.05855468288064003, 0.045311104506254196, 0.09006787836551666, 0.008640330284833908, -0.011889692395925522, 0.008222226984798908, -0.03349936753511429, -0.035267673432826996, 0.006006335373967886, -0.0037871673703193665, -0.02520265057682991, 0.06800497323274612, -0.09460709989070892, 0.0487799197435379, 0.05951685085892677, -0.03267613798379898, -0.04166273772716522, 0.039909135550260544, -0.0056908768601715565, 0.08433422446250916, -0.07493115216493607, -0.0649302676320076, 0.06379221379756927, 0.08547576516866684, 0.03927694633603096, 0.042473096400499344, -0.04713991656899452, 0.04720126464962959, -0.011069468222558498, -0.0348249152302742, 0.013859482482075691, 0.055167220532894135, -0.04467342421412468, 0.05223701894283295, -0.025806168094277382, 0.014514037407934666, -0.06589020788669586, 0.047091301530599594, -0.07653025537729263, -0.046084389090538025, -0.03081606887280941, 0.010506222024559975, 0.02204430289566517, -0.005983957555145025, -0.006158481352031231, 0.0995909571647644, -0.026518842205405235, -0.010567592456936836, 0.0025604935362935066, 0.020100850611925125, 0.025190236046910286, 0.034298211336135864, 0.06350729614496231, -0.006085035391151905, -0.020455345511436462, -0.07868234813213348, 0.024876778945326805, 0.017544718459248543, 0.02971169538795948, -0.02443472295999527, 0.0017605931498110294, 0.033014390617609024, 0.05586093291640282, 0.040588729083538055, -0.025249864906072617, 0.02595464140176773, -0.034791313111782074, 0.06001170352101326, 0.11339864879846573, 0.05725708231329918, -0.02170933037996292, 0.07659502327442169, -0.009995733387768269, 0.032399002462625504, 0.01090097613632679, 0.007338173687458038, -0.010747569613158703, 0.00758225005120039, -0.020179511979222298, 0.04704608395695686, -0.019339127466082573, 0.027356674894690514, -0.02689412049949169, 0.0007289742934517562, -0.012173974886536598, -0.06288545578718185, -0.026787564158439636, 0.004612715449184179, -0.028937790542840958, 0.02497694455087185, -0.012513299472630024, 0.007001130376011133, 0.009025240316987038, -0.01755646802484989, 0.015109286643564701, -0.03365597501397133, -0.04118872806429863, 0.0066165803000330925, -0.007038874085992575, 0.012948832474648952, -0.014719093218445778, 0.04074802249670029, -0.04198494553565979, -0.00796007551252842, 0.02201458066701889, -0.0375535674393177, -0.0017359742196276784, 0.023673271760344505, 0.033215899020433426, -0.03440671041607857, -0.008644651621580124, -0.011559882201254368, -0.03241909295320511, -0.013136159628629684, 0.030203066766262054, 0.005840475205332041, 0.03563858941197395, -0.0037692743353545666, 0.006100217346101999, 0.04468173906207085, -0.004833977669477463, -0.014451971277594566, -0.021396856755018234, -0.07647933065891266, -0.06899731606245041, 0.004654611460864544, 0.01593426801264286, -0.07023074477910995, -0.0063676065765321255, -0.005448576062917709, 0.0007665605517104268, 0.03775033727288246, 0.05375088378787041, -0.08577359467744827, -0.009201937355101109, -0.002482066163793206, -0.03471897169947624, -0.01053101010620594, 0.0045624696649611, 0.07603131979703903, -0.034689247608184814, -0.028413068503141403, -0.012276025488972664, -0.0027372450567781925, -0.039512332528829575, -0.014632179401814938, 0.045372795313596725, 0.03858659788966179, -0.002349885180592537, 0.03820308670401573, 0.018974771723151207, -0.04784396290779114, 0.02257428504526615, -0.028939632698893547, 0.010696389712393284, -0.02140234224498272, -0.0339878685772419, -0.0037379900459200144, -0.0016048793913796544, -0.00599059509113431, 0.0030335853807628155, 0.042983733117580414, -0.06906557083129883, -0.02181716077029705, 0.012095434591174126, -0.023138662800192833, -0.0023305262438952923, -0.0738678127527237, -0.04136258736252785, 0.027088703587651253, 0.048310134559869766, 0.047076042741537094, 0.03272984176874161, -0.0063915736973285675, 0.008566620759665966, 0.026599280536174774, -0.014102530665695667, -0.005656926427036524, -0.017138764262199402, -0.01944260112941265, -0.013324915431439877, -0.03100753203034401, -0.037491753697395325, -0.0003865822800435126, 0.008124349638819695, 0.030627416446805, 0.023140547797083855, -0.002545393770560622, -0.006314082536846399, 0.041128795593976974, -0.00035642454167827964, 0.03984074667096138, -0.04493148997426033, -0.0423869788646698, 0.009352421388030052, -0.029713939875364304, -0.04261499643325806, 0.008040886372327805, 0.06580258905887604, -0.0003583645448088646, 0.019011154770851135, 0.02258961647748947, 0.05889401212334633, 0.008908955380320549, 0.002294046338647604, -0.006747460924088955, 0.006486903876066208, -0.031127240508794785, -0.007747985888272524, -0.03828152269124985, 0.01985906809568405, 0.04666350409388542, 0.04318734630942345, -0.0647939145565033, -0.02699471451342106, -0.03418174013495445, -0.04731406643986702, -0.00723679456859827, -0.01841699704527855, -0.0024857609532773495, 0.011513006873428822, 0.028696421533823013, 0.005713795777410269, -0.02036595530807972, -0.0209039393812418, -0.005156089086085558, 0.028594955801963806, -0.034171074628829956, -0.012478422373533249, -0.003213124116882682, 0.03481273353099823, 0.018711715936660767, -0.03469746559858322, 0.03702390193939209, -0.0029485425911843777, 0.00008067562157521024, -0.03826014697551727, 0.030283711850643158, 0.010897570289671421, -0.02881542034447193, 0.024698909372091293, -0.02808203361928463, -0.015919279307127, 0.061761241406202316, 0.00270612514577806, -0.03652506694197655, -0.0454157292842865, 0.02095135487616062, 0.009708154946565628, -0.016352608799934387, -0.03560097888112068, -0.03320632502436638, 0.021853433921933174, 0.006410343572497368, -0.01855373941361904, 0.06798357516527176, -0.011270510964095592, -0.03677655756473541, 0.03323863074183464, -0.0023449852596968412, -0.028504319489002228, 0.004738539457321167, -0.027309665456414223, -0.025350263342261314, -0.0059042274951934814, -0.013592718169093132, 0.013076097704470158, 0.026325806975364685, -0.02452072873711586, 0.015312128700315952, 0.05807924270629883, 0.0057143704034388065, 0.0199872013181448, 0.008441082201898098, -0.033093977719545364, 0.02329786866903305, -0.013514135964214802, -0.0013904602965340018, -0.02639020048081875, -0.02901678904891014, -0.02144421637058258, -0.017269451171159744, 0.014364457689225674, -0.04325007647275925, -0.013720917515456676, -0.08686184883117676, -0.021205533295869827, 0.033485401421785355, -0.005034259054809809, 0.005556857213377953, -0.017924651503562927, 0.005642774514853954, 0.06116257607936859, -0.01082888524979353, 0.0068817706778645515, -0.043001752346754074, 0.0060195219703018665, 0.016189081594347954, -0.03502765670418739, 0.0032044844701886177, 0.005788199137896299, -0.006929012481123209, -0.004904385190457106, -0.013353949412703514, 0.020532313734292984, -0.012691128998994827, -0.004267479293048382, 0.027556519955396652, 0.004898104816675186, -0.028098737820982933, 0.07489930838346481, 0.004400521516799927, -0.047279857099056244, 0.0035594196524471045, -0.014466363936662674, -0.04434571415185928, -0.01508105918765068, -0.018696801736950874, -0.023738782852888107, 0.03325051814317703, -0.021740267053246498, -0.03454125300049782, 0.00086400838335976, -0.015312308445572853, 0.008783240802586079, 0.017030976712703705, -0.01671118475496769, 0.05006064474582672, 0.0013184561394155025, -0.00819253921508789, 0.013527014292776585, -0.020976189523935318, 0.013983550481498241, 0.019184188917279243, 0.014674141071736813, 0.013180755078792572, -0.01901252195239067, -0.013263355009257793, 0.021458406001329422, -0.005423653870820999, -0.004695040639489889, -0.05954952910542488, -0.05112394690513611, -0.019044438377022743, -0.03469882532954216, -0.0050105140544474125, 0.01362475473433733, 0.007739929482340813, 0.03610224649310112, -0.03991278260946274, -0.03818930685520172, -0.03221512585878372, 0.031588710844516754, 0.026796292513608932, -0.015187922865152359, -0.010028405115008354, 0.03210335969924927, -0.006058363243937492, -0.0022967937402427197, 0.029023954644799232, 0.025047780945897102, -0.0004019482294097543, 0.003972264006733894, 0.012932764366269112, 0.035434141755104065, 0.039189890027046204, 0.013554812408983707, -0.05368943512439728, -0.007932404056191444, 0.00835602916777134, -0.009403168223798275, 0.027671517804265022, 0.013319524936378002, 0.013433938845992088, -0.016956500709056854, -0.026881901547312737, 0.01465672254562378, -0.045661311596632004, 0.019558172672986984, 0.027981944382190704, -0.020964592695236206, 0.010464983992278576, 0.009024877101182938, 0.01951463334262371, -0.024746155366301537, -0.030496016144752502, -0.022353528067469597, 0.05626677721738815, -0.0011609751963987947, 0.04119102284312248, 0.0019249909091740847, -0.015123153105378151, -0.02508525736629963, 0.009834633208811283, -0.0632132813334465, -0.026440894231200218, -0.009354897774755955, -0.04277012497186661, -0.030349528416991234, -0.005712775979191065, -0.05294618010520935, 0.005349815357476473, 0.024521490558981895, 0.02479908987879753, -0.013471877202391624, -0.009770828299224377, 0.03440595045685768, -0.011084092780947685, 0.01944064348936081, 0.01347166858613491, 0.04384787380695343, -0.037046048790216446, -0.006312768906354904, 0.08042828738689423, 0.03266792371869087, 0.021291619166731834, -0.009444298222661018, -0.03292277827858925, 0.030744491145014763, 0.062321651726961136, 0.011405307799577713, -0.004100887570530176, -0.012624929659068584, 0.0005498948157764971, -0.0015991702675819397, -0.006321003194898367, -0.029968375340104103, -0.06489448249340057, 0.04641205444931984, 0.06111810356378555, 0.00787801668047905, -0.016361627727746964, 0.0036302278749644756, 0.02671738900244236, -0.04238855838775635, -0.0011425612028688192, -0.008412188850343227, -0.0026779028121382, 0.013394992798566818, 0.016556046903133392, 0.04209958761930466, 0.039395153522491455, -0.03170299902558327, 0.018440740182995796, 0.04691320285201073, -0.004916479345411062, 0.025919966399669647, 0.011004578322172165, 0.012303070165216923, -0.008162286132574081, -0.031273119151592255, 0.009775678627192974, 0.03250119090080261, 0.0011134318774566054, -0.0060447100549936295, 0.0183186586946249, 0.016544610261917114, 0.0026254779659211636, 0.0017613263335078955, 0.04850386455655098, 0.0407455675303936, 0.045665621757507324, -0.04578213393688202, 0.0056922282092273235, -0.028507813811302185, -0.012842652387917042, -0.022922568023204803, -0.045768771320581436, -0.02609938569366932, 0.03014915995299816, -0.007044804748147726, -0.06419514119625092, -0.03209728002548218, -0.04539429023861885, -0.01798548921942711, 0.0036738039925694466, 0.030714116990566254, -0.01860811747610569, -0.027192426845431328, 0.006380971055477858, 0.005666251759976149, -0.05878390371799469, 0.02191823534667492, 0.014798114076256752, 0.05784779414534569, -0.03575589135289192, 0.06070714071393013, 0.023804495111107826, -0.0027099272701889277, -0.008167758584022522, -0.031232252717018127, -0.008959951810538769, -0.0060185776092112064, 0.022985953837633133, -0.024484185501933098, 0.028497029095888138, 0.01429067738354206, -0.012112604454159737, -0.00207089283503592, -0.01986122317612171, -0.020611988380551338, -0.039559803903102875, 0.02655932307243347, 0.006186103448271751, -0.031065301969647408, -0.0377417616546154, -0.00236304197460413, -0.025005590170621872, 0.005207464098930359, 0.00483557116240263, -0.022161705419421196, -0.029796509072184563, -0.02260795794427395, -0.014582397416234016, 0.014370948076248169, 0.012960076332092285, -0.0029600888956338167, 0.0267352107912302, 0.010403730906546116, 0.006534240208566189, 0.039087194949388504, -0.0040136235766112804, 0.013485093601047993, 0.022707141935825348, 0.014807307161390781, -0.046054136008024216, 0.004639483522623777, 0.012861888855695724, 0.04758019372820854, -0.003426607698202133, 0.007291789632290602, -0.0036129718646407127, 0.006454566027969122, 0.04816344752907753, -0.027358537539839745, 0.002153298817574978, -0.032140254974365234, 0.0035094248596578836, 0.05691476911306381, 0.020931702107191086, -0.004823750350624323, 0.002673900919035077, 0.048728976398706436, -0.021892189979553223, 0.00485837459564209, -0.006082004867494106, -0.007466487120836973, 0.03899649903178215, -0.037580739706754684, -0.007879704236984253, -0.01873541995882988, 0.05769365653395653, -0.054092682898044586, -0.017914652824401855, 0.02498834952712059, 0.02895308844745159, 0.02124686725437641, -0.013866398483514786, 0.018064429983496666, -0.03749452903866768, 0.031533051282167435, -0.0011233995901420712, -0.022073347121477127, -0.05623018369078636, -0.015834243968129158, 0.06516798585653305, 0.020087605342268944, 0.05070023238658905, 0.0404498353600502, -0.049224138259887695, 0.007317112758755684, -0.05169885233044624, -0.020591631531715393, -0.05036212131381035, -0.034709006547927856, -0.027202431112527847, 0.05468878522515297, -0.034354452043771744, -0.004254924599081278, 0.0069731008261442184, -0.001515257521532476, -0.027011167258024216, -0.002166904741898179, 0.09439753741025925, 0.016197271645069122, -0.025416797026991844, 0.0586605966091156, 0.04018634930253029, 0.017739392817020416, 0.0017624980537220836, 0.03473973274230957, 0.006087317131459713, 0.024397969245910645 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Warm-starting encoder-decoder models (Analysis) In this section, we will summarize the findings on warm-starting encoder-decoder models as presented in Leveraging Pre-trained Checkpoints for Sequence Generation Tasks by Sascha Rothe, Shashi Narayan, and Aliaksei Severyn. The authors compared the performance of warm-started encoder-decoder models to randomly initialized encoder-decoder models on multiple sequence-to-sequence tasks, notably summarization, translation, sentence splitting, and sentence fusion. To be more precise, the publicly available pre-trained checkpoints of BERT, RoBERTa, and GPT2 were leveraged in different variations to warm-start an encoder-decoder model. E.g. a BERT-initialised encoder was paired with a BERT-initialized decoder yielding a BERT2BERT model or a RoBERTa-initialized encoder was paired with a GPT2-initialized decoder to yield a RoBERTa2GPT2 model. Additionally, the effect of sharing the encoder and decoder weights (as explained in the previous section) was investigated for RoBERTa, i.e. RoBERTaShare, and for BERT, i.e. BERTShare. Randomly or partly randomly initialized encoder-decoder models were used as a baseline, such as a fully randomly initialized encoder-decoder model, coined Rnd2Rnd or a BERT-initialized decoder paired with a randomly initialized encoder, defined as Rnd2BERT. The following table shows a complete list of all investigated model variants including the number of randomly initialized weights, i.e. \"random\", and the number of weights initialized from the respective pre-trained checkpoints, i.e. \"leveraged\". All models are based on a 12-layer architecture with 768-dim hidden size embeddings, corresponding to the bert-base-cased, bert-base-uncased, roberta-base, and gpt2 checkpoints in the 🤗Transformers model hub. |Model |random |leveraged |total |-------------- |:------- |---------- |------- |Rnd2Rnd |221M |0 |221M |Rnd2BERT |112M |109M |221M |BERT2Rnd |112M |109M |221M |Rnd2GPT2 |114M |125M |238M |BERT2BERT |26M |195M |221M |BERTShare |26M |109M |135M |RoBERTaShare |26M |126M |152M |BERT2GPT2 |26M |234M |260M |RoBERTa2GPT2 |26M |250M |276M The model Rnd2Rnd, which is based on the BERT2BERT architecture, contains 221M weight parameters - all of which are randomly initialized. The other two \"BERT-based\" baselines Rnd2BERT and BERT2Rnd have roughly half of their weights, i.e. 112M parameters, randomly initialized. The other 109M weight parameters are leveraged from the pre-trained bert-base-uncased checkpoint for the encoder- or decoder part respectively. The models BERT2BERT, BERT2GPT2, and RoBERTa2GPT2 have all of their encoder weight parameters leveraged (from bert-base-uncased, roberta-base respectively) and most of the decoder weight parameter weights as well (from gpt2, bert-base-uncased respectively). 26M decoder weight parameters, which correspond to the 12 cross-attention layers, are thereby randomly initialized. RoBERTa2GPT2 and BERT2GPT2 are compared to the Rnd2GPT2 baseline. Also, it should be noted that the shared model variants BERTShare and RoBERTaShare have significantly fewer parameters because all encoder weight parameters are shared with the respective decoder weight parameters.
[ -0.003095806809142232, -0.004236363340169191, 0.002382403239607811, 0.01939491182565689, 0.01817026175558567, 0.1192670464515686, -0.02092667669057846, -0.00037116120802238584, -0.06298079341650009, -0.07945318520069122, -0.05702139809727669, 0.04428870603442192, 0.00018607761012390256, 0.04528604820370674, -0.015289523638784885, -0.030502432957291603, 0.015427852980792522, -0.08814941346645355, -0.012937987223267555, -0.05780521035194397, 0.023457994684576988, -0.056780073791742325, 0.017918076366186142, -0.02528693899512291, 0.07361722737550735, -0.032310601323843, 0.0117604099214077, -0.04803077504038811, -0.03659680485725403, 0.02476004883646965, -0.097686767578125, 0.020534075796604156, 0.06679420918226242, -0.04111853241920471, 0.042560406029224396, 0.0006282658432610333, -0.09917207062244415, 0.06187625601887703, 0.057326510548591614, -0.03317505121231079, -0.024797149002552032, -0.02478833496570587, -0.014273902401328087, 0.003283899510279298, -0.04565238207578659, -0.03127311170101166, -0.13254579901695251, 0.07030957192182541, 0.015698833391070366, -0.07692625373601913, -0.06961880624294281, 0.039906904101371765, 0.0005501486011780798, 0.034047000110149384, -0.01626477763056755, 0.024976367130875587, 0.010285651311278343, -0.060345590114593506, 0.11994682997465134, -0.04201662167906761, 0.036328211426734924, -0.0024298960343003273, -0.015846723690629005, 0.031027015298604965, 0.0416855625808239, 0.044924296438694, -0.02873324230313301, 0.028305983170866966, 0.02162015251815319, -0.017438748851418495, -0.040692247450351715, -0.014388855546712875, -0.03567364439368248, 0.016381656751036644, 0.0029295014683157206, -0.018157990649342537, 0.04401499032974243, -0.017874961718916893, 0.017802000045776367, -0.04020997881889343, -0.014366249553859234, 0.07964406907558441, -0.05015833303332329, -0.008472568355500698, 0.06194351240992546, 0.01015439722687006, 0.0795082226395607, -0.06571891903877258, -0.054993148893117905, 0.05519893392920494, -0.038279470056295395, -0.13647668063640594, 0.041488610208034515, 0.006958514917641878, 0.0054876115173101425, -0.0038574272766709328, -0.009921884164214134, 0.058101627975702286, 0.014193725772202015, -0.025903716683387756, 0.015189168974757195, -0.07655215263366699, 0.06077251210808754, -0.032157301902770996, -0.055583175271749496, 0.034614868462085724, -0.01548326201736927, -0.08593365550041199, -0.027945000678300858, -0.022664079442620277, 0.06556148827075958, -0.029860924929380417, -0.03888167440891266, 0.021596262231469154, -0.10829439014196396, 0.019227409735322, -0.010194079019129276, -0.02913440391421318, -0.009689942002296448, 0.012923809699714184, -0.011685616336762905, 0.02522953785955906, 0.03517931327223778, -0.05804290249943733, -0.06067856028676033, 0.060188744217157364, -0.004540373105555773, 0.006262374576181173, 0.04885273054242134, 0.03328761085867882, 0.054561637341976166, 0.00020049735030625015, 0.023419100791215897, -0.0038839648477733135, -0.0051546767354011536, -0.027953239157795906, -0.00003067634315812029, -0.03475886583328247, -0.02444976195693016, -0.013857914134860039, -0.1238514631986618, 0.08787557482719421, 0.006570013239979744, -0.05801016092300415, 0.01203070767223835, 0.03389675170183182, -0.10574088990688324, 0.03502891585230827, 0.054684706032276154, 0.05694439634680748, -0.04156865179538727, 0.02922944724559784, -0.07985135167837143, -0.06234924867749214, 0.03728603199124336, 0.08110596239566803, -0.021721282973885536, -0.03287674859166145, -0.011897975578904152, -0.027972418814897537, -0.021880391985177994, 0.04534538835287094, -0.02591734379529953, -0.009245128370821476, 0.013887043111026287, -0.0731455385684967, 0.007714793086051941, 0.033711083233356476, 0.01788199320435524, 0.08325852453708649, 0.02092326059937477, 0.038587573915719986, 0.13061882555484772, 0.011368511244654655, -0.019875751808285713, 0.09413468837738037, 0.03498704731464386, 0.06176494061946869, 0.03569449111819267, -0.023743007332086563, -0.040659449994564056, 0.010941572487354279, -0.012549841776490211, 0.030194861814379692, 0.04769829660654068, -0.059739742428064346, 0.010794507339596748, -0.03802911192178726, -0.06393332034349442, 0.0858081802725792, -0.018683087080717087, 0.02819107472896576, 0.055320125073194504, -0.007244231645017862, 0.014260892756283283, -0.08331400901079178, 0.010533527471125126, 0.07988672703504562, 0.03857392445206642, 0.04195315018296242, 0.10894645750522614, 0.03531621769070625, 0.07157505303621292, -0.0098901791498065, -0.03930680453777313, -0.02545212022960186, 0.002195738023146987, -0.019474545493721962, 0.07815335690975189, 0.005628262646496296, 0.05146091431379318, -0.07791745662689209, -0.01538094226270914, -0.05117025226354599, 0.06835144758224487, -0.04359661787748337, 0.014128067530691624, -0.026759210973978043, 0.054723288863897324, -0.014825386926531792, 0.15213672816753387, -0.053449034690856934, 0.012695183977484703, -0.011401526629924774, -0.009419145993888378, 0.05929887667298317, 0.03621399402618408, 0.01288757473230362, 0.07643108814954758, -0.04610003903508186, -0.0011264134664088488, -0.07736863195896149, 0.023632219061255455, 0.014534912072122097, 0.00016968527052085847, 0.03157456964254379, -0.01824205368757248, 0.0031785902101546526, -0.0019336207769811153, -0.07816583663225174, 0.013031142763793468, 0.02734944596886635, 0.023908454924821854, 0.011232968419790268, -0.03666967526078224, 0.021286679431796074, 0.037940170615911484, -0.00041922047967091203, -0.024762678891420364, -0.02595297247171402, -0.06972063332796097, 0.03030463121831417, 0.03411385044455528, -0.06322057545185089, 0.03166911378502846, 0.056103672832250595, -0.02068108692765236, -0.010838530957698822, 0.0012445856118574739, 0.008405360393226147, 0.017247367650270462, -0.06955257058143616, -0.06686387211084366, -0.021789664402604103, 0.003864892292767763, -0.019066497683525085, -0.037464242428541183, -0.020847851410508156, 0.0031103966757655144, 0.01818177103996277, 0.05699949711561203, -0.03487151116132736, 0.02423090860247612, 0.03195478767156601, 0.0066920677199959755, -0.004135996103286743, 0.020733555778861046, -0.03475117310881615, -0.03202185407280922, 0.006872603669762611, 0.007203326094895601, -0.03504970669746399, 0.002145269885659218, 0.021348895505070686, -0.015985559672117233, 0.018982812762260437, -0.019716504961252213, -0.022481728345155716, 0.0013881638878956437, 0.05693062022328377, 0.0012485928600654006, 0.018445683643221855, -0.029978901147842407, -0.0014483266277238727, 0.0031752537470310926, 0.0415128692984581, -0.034590307623147964, -0.0033019462134689093, -0.012068307027220726, -0.005068913102149963, -0.026151783764362335, 0.002997208386659622, -0.017315519973635674, -0.007577665615826845, -0.04614065960049629, 0.01854182407259941, 0.026214485988020897, 0.06382772326469421, -0.09232214093208313, -0.013431422412395477, 0.03491153568029404, -0.003148657036945224, -0.019392432644963264, -0.02801247127354145, 0.06161979213356972, -0.05009002611041069, -0.035564884543418884, 0.015357613563537598, -0.00031938281608745456, -0.011698807589709759, -0.021639369428157806, 0.01114258449524641, -0.04166584089398384, -0.003957193810492754, -0.04755663871765137, 0.00946850050240755, 0.026215873658657074, 0.006042806897312403, 0.01991698332130909, -0.030313411727547646, -0.004043108318001032, -0.021040380001068115, -0.03908297047019005, -0.008707885630428791, 0.014701277948915958, -0.00138250517193228, 0.015680843964219093, -0.005833453498780727, -0.030874470248818398, -0.010981407947838306, 0.014350616373121738, 0.02051449567079544, -0.019855791702866554, -0.014372177422046661, 0.028104910627007484, 0.04873234033584595, 0.034208450466394424, 0.019946152344346046, 0.017436739057302475, -0.007546883542090654, 0.01439411100000143, 0.021075649186968803, 0.025146018713712692, -0.017577053979039192, 0.023218005895614624, -0.013901221565902233, 0.022749055176973343, -0.015518026426434517, -0.004974629729986191, -0.004364317283034325, -0.007893066853284836, 0.015351840294897556, 0.012125732377171516, -0.005493864882737398, -0.014228332787752151, 0.023861244320869446, 0.0073962025344371796, -0.02246161177754402, -0.04693243280053139, -0.0008270660182461143, 0.0017718059243634343, -0.029237210750579834, -0.033941514790058136, 0.025569235906004906, 0.018129795789718628, 0.017482688650488853, -0.0030919956043362617, 0.051117680966854095, -0.018440010026097298, 0.023179417476058006, 0.017816564068198204, -0.0030340261291712523, -0.04597644507884979, 0.0044750613160431385, -0.03904922306537628, -0.009201427921652794, 0.07322420924901962, -0.015737377107143402, 0.0030498248524963856, 0.01327631063759327, -0.05147615820169449, -0.019616935402154922, -0.001830534776672721, 0.03022361546754837, 0.0019811210222542286, -0.00034898900776170194, 0.03442354500293732, -0.005354040302336216, 0.016096021980047226, -0.009265843778848648, -0.015572694130241871, -0.006692826282233, 0.027345994487404823, 0.004155131988227367, -0.0024007773026823997, 0.050814542919397354, 0.020466908812522888, 0.00020464995759539306, 0.009000473655760288, -0.050748903304338455, -0.021190844476222992, -0.014043230563402176, -0.01108681783080101, 0.04424949362874031, -0.03780396655201912, -0.034856412559747696, -0.001152224955148995, -0.019222360104322433, 0.013345601968467236, 0.026186762377619743, -0.003955722786486149, 0.013553992845118046, 0.03350197523832321, 0.03407750278711319, 0.01992192305624485, -0.06945792585611343, 0.01049336139112711, 0.01062675192952156, -0.03488848730921745, -0.0008323768270201981, 0.02094361186027527, 0.025373654440045357, 0.023529700934886932, -0.014265025965869427, 0.017138201743364334, -0.006147490348666906, 0.0004501021758187562, -0.046583142131567, -0.047475337982177734, -0.0036091022193431854, 0.018586941063404083, -0.04761150851845741, -0.0032576355151832104, -0.001628398080356419, -0.01301271840929985, 0.01834987662732601, 0.009225603193044662, -0.05335891991853714, 0.02691044472157955, 0.022090554237365723, 0.025645645335316658, -0.03701942414045334, 0.078232541680336, 0.0019733512308448553, 0.00548871885985136, -0.019192295148968697, -0.004292154219001532, -0.01853444054722786, 0.028088148683309555, -0.0051285866647958755, -0.049267686903476715, 0.019069936126470566, 0.030966993421316147, -0.05741339176893234, -0.013648469932377338, 0.02768290974199772, 0.03273121640086174, 0.022205207496881485, 0.01998032256960869, 0.013481694273650646, -0.05967577174305916, 0.016652211546897888, -0.0037276686634868383, -0.01456558145582676, -0.012117520906031132, -0.01162291131913662, 0.010238357819616795, 0.03652922809123993, 0.003866924438625574, -0.040924593806266785, 0.01682306081056595, -0.009383520111441612, 0.03975521773099899, 0.004318416118621826, -0.01339173223823309, 0.006105263251811266, 0.01547054573893547, -0.006495380774140358, 0.013607227243483067, 0.008320940658450127, -0.009119760245084763, -0.012475273571908474, 0.006778986193239689, 0.021780170500278473, 0.042495548725128174, 0.05252404883503914, 0.02477082423865795, -0.0014283850323408842, 0.0047113834880292416, -0.0052680387161672115, 0.07172419130802155, -0.004170788452029228, -0.04225737601518631, -0.01407657191157341, -0.01633540913462639, 0.034393392503261566, -0.030472254380583763, 0.007517510559409857, 0.03298940509557724, 0.05094164237380028, -0.017062915489077568, -0.024183154106140137, 0.016676997765898705, -0.03387772664427757, -0.04409736022353172, -0.05087510123848915, 0.03376498445868492, -0.023219453170895576, 0.0019258731044828892, 0.0006162725621834397, -0.017764117568731308, -0.0005209996015764773, 0.027550382539629936, 0.00290034431964159, -0.00330634624697268, 0.04235892742872238, 0.06661666929721832, 0.04162691906094551, -0.019464919343590736, 0.007572885137051344, -0.05437197908759117, -0.0050951275043189526, -0.0426989383995533, -0.04950254037976265, -0.014566473662853241, 0.007361896336078644, -0.01772988773882389, 0.024484699591994286, 0.040001872926950455, -0.015030842274427414, 0.024553226307034492, 0.03338131308555603, -0.04766959324479103, -0.035074230283498764, 0.014581973664462566, -0.0014973774086683989, 0.005435439758002758, 0.015757059678435326, 0.0074536059983074665, -0.021407723426818848, 0.0186338871717453, 0.006968372035771608, -0.03699582815170288, 0.026930948719382286, 0.027504729107022285, -0.026691116392612457, 0.049713414162397385, 0.03804103657603264, 0.027401035651564598, -0.010636110790073872, 0.0071295034140348434, -0.0039243753999471664, 0.038119345903396606, -0.00315553555265069, -0.019118657335639, -0.024869481101632118, 0.022494016215205193, 0.027025297284126282, 0.025413790717720985, -0.03799501433968544, 0.025257987901568413, 0.04516635462641716, -0.06709174811840057, 0.012134553864598274, 0.01103998813778162, -0.03233464062213898, 0.03564172610640526, 0.01594279706478119, 0.006209641695022583, 0.005483231041580439, -0.020822228863835335, -0.0023424369283020496, 0.033758629113435745, 0.01269339770078659, 0.04779906943440437, 0.060212764889001846, -0.010835244320333004, 0.02368845045566559, 0.05129694566130638, 0.008652946911752224, 0.03164597600698471, 0.025812750682234764, -0.026622874662280083, -0.04078293219208717, 0.046010822057724, 0.02770378813147545, 0.010867176577448845, 0.030870145186781883, -0.015581193380057812, -0.013200337998569012, -0.02765939012169838, -0.01831679977476597, -0.007627349346876144, 0.009243456646800041, -0.011814994737505913, -0.012035630643367767, 0.020973900333046913, 0.006605265662074089, 0.029696783050894737, 0.042905647307634354, 0.0065119024366140366, -0.0006492456304840744, 0.06653700023889542, 0.01860406994819641, 0.03582426905632019, 0.0034161836374551058, 0.027858173474669456, 0.013137176632881165, -0.04013388603925705, 0.029184693470597267, 0.03567446395754814, 0.003902996191754937, 0.02286490797996521, -0.013052552007138729, -0.006094726268202066, -0.018215389922261238, -0.015512141399085522, 0.004631355870515108, 0.0212174691259861, -0.0017137565882876515, -0.03987341374158859, 0.04187681898474693, -0.039268858730793, 0.02124715782701969, 0.014873453415930271, -0.00788452010601759, 0.01629778929054737, 0.025185707956552505, 0.023258311673998833, 0.05781514197587967, -0.02534194104373455, -0.05544438585639, -0.006730816327035427, 0.0015774606727063656, -0.01465962640941143, 0.03139088302850723, -0.033517833799123764, -0.04512833431363106, -0.006099938880652189, -0.0064704325050115585, -0.023631220683455467, 0.05780304968357086, -0.044330086559057236, -0.015410277061164379, 0.05616829916834831, 0.023458892479538918, -0.010592238046228886, 0.015692088752985, 0.02124231681227684, -0.011570530012249947, -0.01375973504036665, -0.02208426408469677, -0.020342934876680374, -0.056990861892700195, 0.04779442772269249, -0.042918313294649124, 0.005619590636342764, -0.05071806162595749, 0.06830772012472153, 0.023563135415315628, 0.04596551135182381, -0.0351211354136467, -0.01933557167649269, -0.036517973989248276, -0.02829499915242195, -0.008926406502723694, 0.020596912130713463, 0.02275758795440197, 0.001977843465283513, 0.019343389198184013, -0.03438688814640045, -0.02355397865176201, -0.04038991406559944, 0.0011470000026747584, 0.04013298451900482, -0.032030265778303146, -0.02597804181277752, -0.015181263908743858, 0.029599225148558617, -0.004494157154113054, 0.03359935060143471, 0.03277347609400749, -0.018966982141137123, 0.06764587759971619, -0.038391076028347015, -0.021141057834029198, -0.02545391023159027, 0.02075694128870964, 0.006217192858457565, -0.03886068984866142, -0.03690934553742409, 0.022631561383605003, -0.001331132953055203, 0.03349249064922333, -0.0241521168500185, 0.009293847717344761, -0.07681731879711151, 0.02412368915975094, 0.0003399401612114161, 0.0378410778939724, 0.03024386800825596, -0.01315488014370203, 0.04891142621636391, 0.013401382602751255, 0.015204866416752338, -0.013092088513076305, -0.03004595637321472, 0.017354901880025864, 0.029411692172288895, -0.006194829475134611, -0.037809792906045914, -0.012879869900643826, -0.010844804346561432, -0.00010110089351655915, -0.009239112958312035, -0.0038558098021894693, 0.019430605694651604, -0.015564559027552605, -0.035507556051015854, 0.004755140747874975, -0.0199404489248991, -0.017616378143429756, 0.017143458127975464, 0.00989589560776949, -0.05488791689276695, -0.02171408012509346, 0.004320534877479076, -0.039783038198947906, -0.05449117347598076, -0.019256137311458588, 0.023893892765045166, 0.03383364528417587, 0.031578969210386276, 0.01829829253256321, 0.011815576814115047, -0.008355330675840378, 0.018419723957777023, 0.03519061952829361, -0.04293990880250931, -0.012559747323393822, 0.021846622228622437, 0.03996533527970314, 0.0032173702493309975, -0.011532294563949108, 0.01672164537012577, 0.026159118860960007, 0.008810588158667088, 0.02722281403839588, 0.007685756776481867, -0.011066952720284462, -0.040797408670186996, 0.030286576598882675, -0.023623213171958923, 0.07131652534008026, 0.028629330918192863, 0.013938410207629204, 0.007083964068442583, 0.02642751857638359 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Warm-staring Encoder-Decoder with BERT Let\'s now illustrate how a pre-trained BERT model can be used to warm-start the encoder-decoder model. BERT\'s pre-trained weight parameters are used to both initialize the encoder\'s weight parameters as well as the decoder\'s weight parameters. To do so, BERT\'s architecture is compared to the encoder\'s architecture and all layers of the encoder that also exist in BERT will be initialized with the pre-trained weight parameters of the respective layers. All layers of the encoder that do not exist in BERT will simply have their weight parameters be randomly initialized. Let\'s visualize. We can see that the encoder architecture corresponds 1-to-1 to BERT\'s architecture. The weight parameters of the bi-directional self-attention layer and the two feed-forward layers of all encoder blocks are initialized with the weight parameters of the respective BERT blocks. This is illustrated examplary for the second encoder block (red boxes at bottow) whose weight parameters \(\theta{\text{enc}}^{\text{self-attn}, 2}\) and \(\theta_{\text{enc}}^{\text{feed-forward}, 2}\) are set to BERT\'s weight parameters \(\theta_{\text{BERT}}^{\text{feed-forward}, 2}\) and \(\theta_{\text{BERT}}^{\text{self-attn}, 2}\), respectively at initialization. Before fine-tuning, the encoder therefore behaves exactly like a pre-trained BERT model. Assuming the input sequence \(\mathbf{x}1, \ldots, \mathbf{x}_n\) (shown in green) passed to the encoder is equal to the input sequence \(\mathbf{x}_1^{\text{BERT}}, \ldots, \mathbf{x}_n^{\text{BERT}}\) (shown in grey) passed to BERT, this means that the respective output vector sequences \(\mathbf{\overline{x}}_1, \ldots, \mathbf{\overline{x}}_n\) (shown in darker green) and \(\mathbf{\overline{x}}_1^{\text{BERT}}, \ldots, \mathbf{\overline{x}}_n^{\text{BERT}}\) (shown in darker grey) also have to be equal. Next, let\'s illustrate how the decoder is warm-started. The architecture of the decoder is different from BERT\'s architecture in three ways. 1. First, the decoder has to be conditioned on the contextualized encoded sequence \(\mathbf{\overline{X}}{1:n}\) by means of cross-attention layers. Consequently, randomly initialized cross-attention layers are added between the self-attention layer and the two feed-forward layers in each BERT block. This is represented exemplary for the second block by \(+\theta_{\text{dec}}^{\text{cross-attention, 2}}\) and illustrated by the newly added fully connected graph in red in the lower red box on the right. This necessarily changes the behavior of each modified BERT block so that an input vector, e.g. \(\mathbf{y'}0\) now yields a random output vector \(\mathbf{y''}_0\) (highlighted by the red border around the output vector \(\mathbf{y''}_0\)). 2. Second, BERT\'s bi-directional self-attention layers have to be changed to uni-directional self-attention layers to comply with auto-regressive generation. Because both the bi-directional and the uni-directional self-attention layer are based on the same key, query and value projection weights, the decoder\'s self-attention layer weights can be initialized with BERT\'s self-attention layer weights. E.g. the query, key and value weight parameters of the decoder\'s uni-directional self-attention layer are initialized with those of BERT\'s bi-directional self-attention layer \(\theta{\text{BERT}}^{\text{self-attn}, 2} = {\mathbf{W}{\text{BERT}, k}^{\text{self-attn}, 2}, \mathbf{W}{\text{BERT}, v}^{\text{self-attn}, 2}, \mathbf{W}{\text{BERT}, q}^{\text{self-attn}, 2} } \to \theta{\text{dec}}^{\text{self-attn}, 2} = {\mathbf{W}{\text{dec}, k}^{\text{self-attn}, 2}, \mathbf{W}{\text{dec}, v}^{\text{self-attn}, 2}, \mathbf{W}{\text{dec}, q}^{\text{self-attn}, 2} }. \) However, in uni-directional self-attention each token only attends to all previous tokens, so that the decoder\'s self-attention layers yield different output vectors than BERT\'s self-attention layers even though they share the same weights. Compare e.g., the decoder\'s causally connected graph in the right box versus BERT\'s fully connected graph in the left box. 3. Third, the decoder outputs a sequence of logit vectors \(\mathbf{L}{1:m}\) in order to define the conditional probability distribution \(p_{\theta_{\text{dec}}}(\mathbf{Y}{1:n} | \mathbf{\overline{X}})\). As a result, a LM Head layer is added on top of the last decoder block. The weight parameters of the LM Head layer usually correspond to the weight parameters of the word embedding \(\mathbf{W}{\text{emb}}\) and thus are not randomly initialized. This is illustrated in the top by the initialization \(\theta_{\text{BERT}}^{\text{word-emb}} \to \theta_{\text{dec}}^{\text{lm-head}}\). To conclude, when warm-starting the decoder from a pre-trained BERT model only the cross-attention layer weights are randomly initialized. All other weights including those of the self-attention layer and LM Head are initialized with BERT\'s pre-trained weight parameters. Having warm-stared the encoder-decoder model, the weights are then fine-tuned on a sequence-to-sequence downstream task, such as summarization.
[ 0.01784958876669407, 0.015024959109723568, 0.053017064929008484, 0.0013211100595071912, 0.011790460906922817, 0.06502079218626022, -0.04277155175805092, 0.03046775981783867, -0.05345228314399719, -0.014521253295242786, -0.09266170114278793, 0.0750025287270546, -0.014493082650005817, 0.020253363996744156, -0.015972768887877464, -0.006982463411986828, 0.052278388291597366, -0.04745869338512421, -0.017876077443361282, -0.026552386581897736, 0.049748845398426056, -0.06754761189222336, 0.06789403408765793, -0.01915751025080681, 0.07955440133810043, -0.06109178811311722, 0.0017942944541573524, 0.018686754629015923, -0.025366559624671936, 0.031579501926898956, -0.06516215950250626, -0.016607612371444702, 0.07215854525566101, -0.06121983006596565, 0.007160368375480175, 0.03617071732878685, -0.08676423132419586, 0.06390802562236786, 0.03649027273058891, -0.05203017219901085, -0.0362323559820652, 0.0025387476198375225, -0.020847929641604424, 0.017769787460565567, -0.04654860869050026, -0.0334787592291832, -0.11997281014919281, 0.08772163093090057, -0.04381619766354561, -0.038885124027729034, -0.06581762433052063, 0.0052758981473743916, -0.03199680149555206, 0.07037414610385895, -0.04592936113476753, 0.003133245278149843, -0.00772210955619812, -0.020845754072070122, 0.039560943841934204, -0.02875576540827751, 0.07679787278175354, 0.003546260530129075, -0.008904245682060719, 0.09030993282794952, 0.0185704343020916, 0.041519876569509506, -0.06569909304380417, -0.02260325476527214, 0.0036755697801709175, 0.009509598836302757, -0.04614870995283127, -0.006711218971759081, -0.00011970231571467593, 0.0036150056403130293, 0.017989689484238625, -0.038050662726163864, 0.050298064947128296, -0.019846156239509583, 0.024790626019239426, 0.013167202472686768, -0.029076015576720238, 0.03253737837076187, -0.03567931428551674, 0.04673171043395996, 0.02889183722436428, 0.03194805979728699, 0.05810203775763512, -0.04278726130723953, -0.030145756900310516, 0.04947376623749733, -0.11100507527589798, -0.1617431491613388, 0.020594656467437744, -0.005348843988031149, 0.044134028255939484, -0.00870050210505724, -0.027737686410546303, 0.02701251395046711, 0.01221898477524519, -0.015935001894831657, 0.0018015947425737977, -0.06837949901819229, 0.07439857721328735, -0.062085576355457306, -0.0470002256333828, 0.015071381814777851, 0.019725412130355835, -0.12725193798542023, -0.05311419069766998, -0.03288750723004341, 0.03872770443558693, -0.038600169122219086, -0.023477880284190178, 0.0207856185734272, -0.07000488042831421, 0.002881400054320693, 0.008055604062974453, -0.0434831939637661, 0.018030783161520958, 0.0019327453337609768, -0.0333862230181694, 0.05212535709142685, 0.06000004708766937, -0.05918186902999878, -0.02394270896911621, 0.033622775226831436, -0.0004792910476680845, 0.026454759761691093, 0.030412698164582253, 0.024287372827529907, 0.09810768067836761, 0.008550835773348808, 0.0649714395403862, -0.027743667364120483, 0.011364906094968319, 0.013458682224154472, -0.07126182317733765, -0.048400335013866425, -0.049519095569849014, -0.02355882152915001, -0.12239982187747955, 0.06844495981931686, 0.051727499812841415, -0.02470245212316513, 0.019369827583432198, 0.021456429734826088, -0.06660039722919464, 0.07453539967536926, 0.031538140028715134, 0.09664738923311234, -0.024604087695479393, 0.009709449484944344, 0.0032712840475142, -0.031898561865091324, -0.02848675288259983, 0.05627384036779404, -0.04894072934985161, -0.04105701670050621, -0.06750532239675522, 0.017835212871432304, 0.003940609283745289, 0.04404361546039581, -0.026461049914360046, 0.03036915324628353, 0.02002628706395626, -0.09101716428995132, -0.014239046722650528, 0.03726767748594284, 0.01464910339564085, 0.05975647643208504, 0.002600177191197872, 0.010361631400883198, 0.0747009739279747, 0.023874575272202492, -0.017259160056710243, 0.029242439195513725, 0.009697807021439075, 0.07630337029695511, -0.02990865893661976, -0.002154142362996936, -0.032721687108278275, 0.020199161022901535, 0.023321906104683876, 0.01637578196823597, 0.01577773503959179, -0.0035732181277126074, -0.028972528874874115, -0.061167262494564056, -0.06897840648889542, 0.061878349632024765, -0.019505083560943604, 0.041058581322431564, 0.02562304586172104, -0.02889700047671795, 0.002499256981536746, -0.02674814872443676, -0.058334700763225555, 0.07073522359132767, 0.021730251610279083, 0.045966193079948425, 0.09705238789319992, 0.007409162353724241, 0.08071666210889816, 0.029850143939256668, -0.0008141093421727419, -0.03654506057500839, 0.03624201565980911, -0.04400518909096718, 0.07844710350036621, -0.0005073873326182365, 0.03435879573225975, -0.08054020255804062, 0.00041764421621337533, -0.03779724985361099, 0.0546785332262516, -0.03811178728938103, 0.004512850660830736, -0.013852322474122047, -0.019144302234053612, 0.012839780189096928, 0.12190419435501099, -0.034709248691797256, 0.009124989621341228, -0.0579390823841095, -0.0012537349248304963, 0.0013431075494736433, 0.04964685067534447, -0.04435758665204048, 0.08506784588098526, -0.05292759835720062, -0.0485270731151104, -0.04549022391438484, -0.0026861836668103933, 0.004810874350368977, -0.04309115558862686, -0.024557793512940407, -0.04156904295086861, -0.01740425080060959, 0.04396090283989906, -0.0946134626865387, 0.02155867964029312, 0.020881783217191696, 0.00824776291847229, -0.00923189241439104, -0.0832095742225647, -0.017429139465093613, 0.04921793192625046, 0.0007744707399979234, -0.050845805555582047, 0.041548773646354675, -0.029788782820105553, 0.05101199075579643, -0.016760462895035744, -0.11804132908582687, -0.011448265053331852, 0.07503101229667664, -0.05458023399114609, -0.01037444919347763, 0.02056650072336197, 0.011217094026505947, -0.008884334936738014, -0.021659651771187782, -0.0359155498445034, -0.00885283574461937, -0.03572840988636017, -0.014683340676128864, -0.04452796280384064, 0.033289868384599686, 0.008235564455389977, 0.039774347096681595, 0.05092558264732361, -0.015687474980950356, 0.03494983911514282, 0.03040904365479946, 0.040339935570955276, 0.00454113120213151, 0.05445900931954384, -0.06506414711475372, -0.03879370167851448, -0.02423638105392456, -0.00001527296262793243, 0.00027953620883636177, 0.00019936045282520354, 0.02272973582148552, -0.025854090228676796, 0.03761701658368111, -0.020477144047617912, -0.01687423139810562, 0.005479301325976849, 0.026495886966586113, -0.008509175851941109, 0.02071118913590908, 0.017264297232031822, 0.011643481440842152, -0.01886836066842079, 0.04619002714753151, 0.015079065226018429, -0.01567249558866024, -0.020529761910438538, 0.010181327350437641, 0.009364708326756954, 0.0017993614310398698, 0.018978064879775047, -0.02236676774919033, -0.041620515286922455, 0.0034722748678177595, 0.04235107824206352, 0.06904382258653641, -0.0879041999578476, 0.018168451264500618, 0.043756913393735886, 0.006534168496727943, 0.009697195142507553, -0.046771395951509476, 0.013760799542069435, -0.013562287203967571, -0.007488044444471598, 0.019891224801540375, 0.004613648168742657, -0.03403880074620247, -0.005847485736012459, 0.027453521266579628, -0.0032936101779341698, -0.01421401184052229, -0.021311840042471886, 0.003098367713391781, 0.019343741238117218, -0.031367745250463486, 0.025631070137023926, -0.01419606152921915, 0.011097665876150131, 0.022932296618819237, -0.023427417501807213, -0.005277527961879969, 0.018003292381763458, 0.016915449872612953, 0.023915087804198265, -0.011006251908838749, -0.02036392316222191, -0.051649510860443115, 0.00425654835999012, 0.0036142421886324883, -0.027591979131102562, -0.009089726954698563, 0.04388785362243652, 0.000027160824174643494, 0.034759730100631714, 0.05458759143948555, 0.01341443695127964, 0.03375326842069626, 0.014577222988009453, 0.028198106214404106, 0.03285042941570282, -0.03515638783574104, 0.012578140012919903, -0.006657026242464781, 0.0287878829985857, -0.026929810643196106, 0.009174846112728119, -0.020442426204681396, -0.023447105661034584, -0.02551550231873989, -0.022565510123968124, 0.0012153496500104666, 0.008758281357586384, 0.03455423191189766, 0.008821019902825356, -0.03367423266172409, -0.03805095702409744, 0.008286130614578724, -0.005796938668936491, -0.034331291913986206, -0.03913433104753494, -0.0018993448466062546, 0.021161546930670738, 0.02463756874203682, 0.02824551612138748, 0.01376370619982481, -0.00831431895494461, -0.02905494160950184, 0.03562631085515022, 0.007106823846697807, 0.01698448322713375, 0.0028802340384572744, -0.026994846761226654, -0.02285548858344555, 0.08646582067012787, -0.0174470953643322, 0.03475271537899971, 0.03984712436795235, -0.026760751381516457, -0.0050294529646635056, -0.013644630089402199, 0.012148392386734486, -0.02335074357688427, -0.0007606431026943028, 0.0581231452524662, -0.01242836844176054, 0.00050746911438182, -0.015105584636330605, -0.007158350199460983, -0.0022332454100251198, -0.009839825332164764, -0.011489637196063995, -0.0014353551669046283, 0.01619570516049862, 0.05334428325295448, 0.00770007586106658, 0.011766299605369568, -0.08887452632188797, -0.02081979438662529, 0.008667690679430962, -0.013592643663287163, 0.03364908695220947, -0.03181540593504906, -0.036233190447092056, 0.05488693341612816, -0.030308423563838005, -0.008495735004544258, -0.021290330216288567, -0.0012224562233313918, 0.05455896630883217, 0.05961291491985321, 0.038146696984767914, -0.020267510786652565, -0.06459596008062363, -0.009115507826209068, 0.0031689032912254333, -0.03190525993704796, 0.01987152360379696, 0.004652123432606459, -0.003388066543266177, 0.03393149748444557, -0.0214521661400795, 0.028157247230410576, 0.02919934317469597, -0.005635997746139765, -0.06206517666578293, -0.05294111371040344, -0.03551571071147919, 0.06098130717873573, -0.03582630679011345, -0.01165008544921875, 0.02972739189863205, -0.02585194818675518, 0.018532613292336464, 0.011392519809305668, -0.06261058151721954, -0.01792142726480961, 0.029285382479429245, 0.03011499159038067, -0.03600793704390526, 0.05372443422675133, 0.006266212556511164, -0.032889824360609055, -0.0005651780520565808, -0.007707490120083094, 0.010560758411884308, 0.04783537611365318, 0.027843685820698738, -0.07126231491565704, 0.012228576466441154, 0.042727790772914886, -0.04298730939626694, 0.003147626994177699, 0.023192530497908592, 0.053469154983758926, 0.033242467790842056, 0.008607031777501106, -0.011613640002906322, -0.05279111489653587, -0.01670868881046772, 0.0018214622978121042, 0.006754519417881966, 0.003341485746204853, -0.03680168464779854, 0.007999812252819538, -0.006488588638603687, -0.006528686266392469, -0.020571747794747353, 0.0022526897955685854, -0.015623961575329304, 0.0057257176376879215, -0.0017529408214613795, -0.020605789497494698, -0.026853056624531746, 0.011547138914465904, 0.0004910473362542689, 0.016946081072092056, 0.015318275429308414, 0.008664049208164215, 0.006755912210792303, -0.027647895738482475, 0.023787876591086388, 0.02182244136929512, 0.04249849170446396, 0.023959675803780556, 0.021863136440515518, 0.005316112190485001, 0.011711602099239826, 0.03566921502351761, 0.005497480742633343, -0.05367306247353554, -0.008281473070383072, -0.009340581484138966, -0.03124278411269188, 0.0066630421206355095, -0.013096533715724945, 0.004318044520914555, 0.03632377088069916, -0.013105090707540512, -0.026034880429506302, 0.027500366792082787, -0.04911467060446739, -0.02634108066558838, -0.06118934601545334, 0.005144165363162756, -0.045173101127147675, 0.007904907688498497, 0.011317196302115917, 0.020710362121462822, -0.0016773546813055873, 0.030171222984790802, -0.01573028229176998, -0.03276267275214195, 0.010876726359128952, 0.05400633439421654, 0.03211960569024086, 0.0018793788040056825, 0.002082056598737836, -0.046047307550907135, -0.004270852543413639, -0.034493979066610336, -0.05538032948970795, 0.00395118398591876, -0.00044272991362959146, 0.009930030442774296, 0.019678618758916855, 0.05558222159743309, -0.01620214805006981, 0.004110465291887522, 0.038440268486738205, -0.04255736991763115, -0.035715218633413315, -0.02961328998208046, 0.012742212973535061, -0.018782775849103928, 0.004178435076028109, 0.022850599139928818, -0.008085726760327816, 0.008954713121056557, 0.026564165949821472, -0.007614704314619303, 0.02266567014157772, 0.05034865438938141, -0.025959206745028496, 0.07223253697156906, 0.015259374864399433, 0.05103437602519989, 0.017398808151483536, -0.006268348544836044, -0.000040219347283709794, 0.018068334087729454, 0.0012585018994286656, 0.02095745876431465, -0.009781862609088421, 0.024573085829615593, 0.02497139386832714, 0.028918910771608353, -0.050832368433475494, 0.02561693824827671, 0.029158741235733032, -0.016266804188489914, 0.04980923980474472, 0.005627550650388002, -0.025014836341142654, 0.03012646548449993, 0.04274627938866615, 0.03651001676917076, -0.007665864657610655, -0.02837185561656952, -0.020956309512257576, 0.05687634274363518, 0.012944282032549381, 0.019506553187966347, 0.05235083028674126, -0.01044382993131876, 0.031740471720695496, 0.0011044202838093042, -0.003950267098844051, 0.026027260348200798, 0.012095611542463303, -0.0015303632244467735, -0.005268500652164221, 0.05770494043827057, 0.019077211618423462, 0.0271859560161829, 0.027828585356473923, 0.011477100662887096, 0.026289088651537895, -0.02990575134754181, -0.009409600868821144, -0.008371736854314804, 0.030278652906417847, -0.022556399926543236, -0.02568276971578598, 0.025659389793872833, -0.03397813066840172, 0.023686513304710388, 0.057655300945043564, 0.02133309096097946, 0.002440572017803788, 0.05763397738337517, 0.018364334478974342, 0.03417152538895607, 0.003850724082440138, 0.019794676452875137, 0.04359995573759079, -0.035740651190280914, 0.03392302617430687, -0.0026767877861857414, 0.015618241392076015, 0.0453324094414711, -0.03811556100845337, 0.04520951956510544, -0.01774434745311737, -0.0009037870913743973, 0.02389204502105713, 0.019886760041117668, -0.027984952554106712, -0.0013904699590057135, 0.04434286430478096, -0.014407840557396412, 0.011736011132597923, 0.026112306863069534, -0.01768956333398819, -0.01735866814851761, 0.009392672218382359, 0.010592780075967312, 0.051353417336940765, -0.04198206588625908, -0.017867781221866608, -0.016260305419564247, 0.016276085749268532, -0.0168383177369833, 0.018611395731568336, -0.03645722195506096, -0.04519767314195633, -0.059224870055913925, -0.021959224715828896, -0.03930242732167244, 0.046448659151792526, 0.00886722281575203, -0.00040014085243456066, 0.061509862542152405, 0.009924868121743202, -0.0033210779074579477, 0.018156716600060463, 0.0004624749708455056, -0.003541291458532214, -0.020388979464769363, -0.027704428881406784, -0.01851019449532032, -0.03505193442106247, 0.021982965990900993, -0.056479595601558685, 0.008307642303407192, 0.005133661907166243, 0.022671205922961235, 0.034177426248788834, 0.040204569697380066, -0.05582205951213837, -0.03960118442773819, -0.004371752496808767, -0.02061397396028042, -0.0018804738065227866, -0.012144750915467739, 0.012893523089587688, -0.006663239095360041, 0.03368968889117241, -0.005905468948185444, -0.051323432475328445, -0.050806134939193726, 0.01349683478474617, 0.03510887175798416, -0.01838117279112339, -0.028502730652689934, -0.02609453722834587, 0.04856177046895027, -0.004820590373128653, -0.0024394767824560404, 0.0611274354159832, -0.011696023866534233, 0.05731987580657005, -0.014004966244101524, 0.032710857689380646, 0.008321397006511688, 0.023456169292330742, -0.02806197479367256, -0.03452357277274132, -0.009190171025693417, 0.03292784467339516, 0.008874168619513512, 0.03280596807599068, -0.025710618123412132, 0.011940906755626202, -0.06950342655181885, -0.012447967194020748, -0.030116094276309013, 0.05027909204363823, 0.02942592464387417, -0.010352455079555511, 0.034419137984514236, 0.01298458781093359, -0.02741115167737007, -0.044089749455451965, -0.01760687492787838, 0.005194912664592266, 0.046473998576402664, 0.0065695736557245255, -0.027757318690419197, 0.02446538209915161, -0.017988592386245728, -0.006920969113707542, -0.013950718566775322, 0.0042369491420686245, 0.0002456551301293075, -0.03272685408592224, 0.00656627444550395, -0.018970519304275513, -0.009978261776268482, 0.007037203758955002, -0.004093212075531483, 0.030202986672520638, -0.04841603711247444, -0.01327542681246996, 0.021723400801420212, -0.03269336372613907, -0.024818984791636467, -0.006027200724929571, -0.005466440226882696, 0.0738852247595787, -0.00047920664655976, 0.04793719947338104, 0.01737646758556366, 0.014099148102104664, 0.011468108743429184, 0.03888118639588356, -0.0321924053132534, 0.006343891378492117, 0.018771788105368614, 0.04125455394387245, -0.022072693333029747, -0.012145290151238441, -0.00439517991617322, 0.037901345640420914, -0.022858837619423866, 0.027076665312051773, 0.002867509610950947, -0.021717503666877747, -0.029346203431487083, 0.03129120171070099, -0.02664078399538994, 0.05731821060180664, -0.004560863599181175, 0.015348518267273903, 0.013031216338276863, 0.02743741311132908 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Warm-staring Encoder-Decoder with BERT and GPT2 Instead of warm-starting both the encoder and decoder with a BERT checkpoint, we can instead leverage the BERT checkpoint for the encoder and a GPT2 checkpoint for the decoder. At first glance, a decoder-only GPT2 checkpoint seems to be better-suited to warm-start the decoder because it has already been trained on causal language modeling and uses uni-directional self-attention layers. Let\'s illustrate how a GPT2 checkpoint can be used to warm-start the decoder. We can see that decoder is more similar to GPT2 than it is to BERT. The weight parameters of decoder\'s LM Head can directly be initialized with GPT2\'s LM Head weight parameters, e.g. \(\theta_{\text{GPT2}}^{\text{lm-head}} \to \theta_{\text{dec}}^{\text{lm-head}}\). In addition, the blocks of the decoder and GPT2 both make use of uni-directional self-attention so that the output vectors of the decoder\'s self-attention layer are equivalent to GPT2\'s output vectors assuming the input vectors are the same, e.g. \(\mathbf{y'}0^{\text{GPT2}} = \mathbf{y'}_0\). In contrast to the BERT-initialized decoder, the GPT2-initialized decoder, therefore, keeps the causal connected graph of the self-attention layer as can be seen in the red boxes on the bottom. Nevertheless, the GPT2-initialized decoder also has to condition the decoder on \(\mathbf{\overline{X}}{1:n}\). Analoguos to the BERT-initialized decoder, randomly initialized weight parameters for the cross-attention layer are therefore added to each decoder block. This is illustrated e.g. for the second encoder block by \(+\theta_{\text{dec}}^{\text{cross-attention, 2}}\). Even though GPT2 resembles the decoder part of an encoder-decoder model more than BERT, a GPT2-initialized decoder will also yield random logit vectors \(\mathbf{L}{1:m}\) without fine-tuning due to randomly initialized cross-attention layers in every decoder block. It would be interesting to investigate whether a GPT2-initialized decoder yields better results or can be fine-tuned more efficiently.
[ -0.008511679247021675, -0.05126144364476204, 0.022372493520379066, 0.009455211460590363, -0.02935980260372162, 0.03095323033630848, -0.04695873707532883, 0.015593555755913258, -0.02920585311949253, -0.05296831205487251, -0.05230849236249924, 0.07067976891994476, -0.009859216399490833, 0.07733859121799469, -0.008347157388925552, 0.0007041142089292407, 0.03083183616399765, -0.09212174266576767, -0.04268568009138107, -0.035517822951078415, 0.06618605554103851, -0.04296135902404785, 0.024738766252994537, -0.032737161964178085, 0.0441536121070385, -0.06815046817064285, -0.018132105469703674, 0.026269733905792236, -0.012213676236569881, 0.05163127928972244, -0.04772576689720154, 0.03098466247320175, 0.05813009291887283, -0.047180239111185074, 0.03455768898129463, 0.0249323770403862, -0.09650766104459763, 0.011856894008815289, 0.06385045498609543, -0.027054885402321815, -0.043946512043476105, -0.018265921622514725, -0.039756398648023605, 0.007240963634103537, -0.05327362194657326, -0.02572374977171421, -0.11642894893884659, 0.08365272730588913, -0.005240992642939091, -0.07720472663640976, -0.08417091518640518, 0.05314796790480614, -0.049126997590065, 0.053719766438007355, -0.02925843931734562, 0.01830802857875824, -0.029010003432631493, -0.06312628835439682, 0.05013881251215935, -0.03955596685409546, 0.0401536226272583, 0.008320776745676994, -0.023934196680784225, 0.09325588494539261, 0.001879412797279656, 0.003731519915163517, -0.09785623103380203, -0.03378641605377197, -0.017535394057631493, -0.024361208081245422, -0.0582815445959568, 0.0058135343715548515, 0.000014808500054641627, 0.008461780846118927, 0.025721188634634018, -0.0303517933934927, 0.022016825154423714, -0.019371481612324715, -0.029591290280222893, 0.0005047581507824361, 0.005365666467696428, 0.015219715423882008, -0.04115929454565048, -0.01816343143582344, 0.029526591300964355, 0.009504761546850204, 0.04102347418665886, -0.12066284567117691, -0.032644517719745636, 0.013506160117685795, -0.07994712144136429, -0.1301356703042984, 0.0073351869359612465, -0.02805333398282528, 0.05816243588924408, 0.016059445217251778, -0.037773434072732925, 0.016180749982595444, 0.009457752108573914, -0.03877304121851921, 0.023767679929733276, -0.0701475441455841, 0.0724131241440773, -0.030093396082520485, -0.040321581065654755, -0.0023853210732340813, -0.02858821675181389, -0.08182363212108612, -0.048978883773088455, -0.01744832657277584, 0.03607530519366264, -0.01800704188644886, -0.030604878440499306, 0.011089317500591278, -0.09718802571296692, 0.03658764064311981, 0.017492305487394333, -0.06500419229269028, 0.015619674697518349, 0.05188056454062462, -0.0066200438886880875, 0.043919820338487625, 0.04853985086083412, -0.07371142506599426, -0.005594357848167419, 0.03727211430668831, -0.02139250747859478, 0.0614650584757328, 0.04180849716067314, 0.03893927484750748, 0.10006552934646606, -0.0008138295379467309, 0.03599109128117561, -0.036472875624895096, 0.04029792919754982, -0.002155032940208912, 0.003596049966290593, -0.048277970403432846, -0.05671881139278412, 0.011559026315808296, -0.10631261765956879, 0.03255845606327057, 0.03668805584311485, -0.054303128272295, 0.021797722205519676, 0.05515992268919945, -0.14921076595783234, 0.041225120425224304, 0.05385042726993561, 0.06709691137075424, -0.05407913401722908, 0.03853362426161766, -0.002212942810729146, -0.038735270500183105, -0.022024260833859444, 0.05349954590201378, -0.030896391719579697, -0.0178003441542387, -0.07052674144506454, -0.014936957508325577, 0.0015120062744244933, 0.017687363550066948, -0.033182933926582336, 0.0278019942343235, 0.03593125566840172, -0.07034451514482498, -0.010898342356085777, -0.0018515342380851507, -0.039666756987571716, 0.05316414311528206, 0.02885165624320507, 0.03253866732120514, 0.1057787537574768, 0.02966989390552044, 0.023809731006622314, 0.033064473420381546, -0.00214181886985898, 0.08898625522851944, -0.029162120074033737, -0.041409123688936234, -0.06061592325568199, -0.0026791442651301622, 0.02327859401702881, 0.019666898995637894, -0.01633475348353386, -0.026149950921535492, -0.03177241235971451, -0.05807876214385033, -0.07654526829719543, 0.014633920975029469, -0.020223122090101242, 0.02841908298432827, 0.016863441094756126, -0.01173684187233448, -0.020144077017903328, -0.04781103506684303, -0.04886697977781296, 0.07762224227190018, 0.04708264395594597, 0.048368778079748154, 0.08154626190662384, 0.023439008742570877, 0.07806544005870819, 0.014736809767782688, -0.011620980687439442, -0.030232273042201996, 0.06613937020301819, -0.03448307141661644, 0.05763551592826843, 0.005404296331107616, 0.03799334913492203, -0.08089081943035126, -0.011734641157090664, -0.03988785296678543, 0.028449907898902893, -0.014197501353919506, 0.01885739341378212, -0.0026392899453639984, 0.01698382943868637, 0.008919275365769863, 0.11692727357149124, -0.052818480879068375, 0.0034177068155258894, -0.028700217604637146, 0.0017916442593559623, 0.056929491460323334, 0.07590930163860321, -0.019427552819252014, 0.07982142269611359, -0.04782075062394142, -0.05245190113782883, -0.08737147599458694, 0.025601927191019058, -0.002873343648388982, -0.06092623621225357, 0.0034849487710744143, 0.001675041508860886, -0.020806439220905304, 0.06439181417226791, -0.09543593227863312, -0.010404479689896107, -0.00678247818723321, -0.0034702534321695566, -0.0070467558689415455, -0.036376360803842545, -0.02719021588563919, 0.03921883553266525, -0.01391485147178173, -0.047599535435438156, 0.008665359579026699, -0.05269934609532356, 0.04047784209251404, -0.005070856306701899, -0.11171993613243103, -0.0008596067782491446, 0.017527330666780472, -0.03309447318315506, -0.041485745459795, 0.016939906403422356, 0.015599655918776989, 0.018150674179196358, -0.031709399074316025, -0.023306818678975105, -0.008379793725907803, -0.020154859870672226, -0.009330861270427704, -0.027378952130675316, 0.028204405680298805, 0.002399622928351164, 0.010916200466454029, 0.041900791227817535, -0.016718938946723938, 0.016058016568422318, 0.0485193207859993, 0.041909363120794296, -0.0008391384035348892, 0.023940064013004303, -0.051270969212055206, -0.057144951075315475, -0.008845445699989796, 0.025416545569896698, -0.029599979519844055, 0.004567899741232395, 0.019598033279180527, -0.027024373412132263, 0.043579861521720886, -0.025639116764068604, -0.00044238055124878883, 0.012112371623516083, 0.04679354652762413, -0.001427711104042828, 0.007339583244174719, -0.00868898257613182, 0.017306458204984665, -0.023426979780197144, 0.041381459683179855, 0.012430074624717236, -0.02005309984087944, -0.005169384181499481, 0.02748197503387928, -0.013251527212560177, 0.03445170074701309, 0.020938832312822342, -0.018671901896595955, -0.05611772835254669, 0.013808771036565304, 0.02149241976439953, 0.04340461269021034, -0.07963287830352783, -0.030415261164307594, 0.045716602355241776, 0.011723888106644154, -0.005274643190205097, -0.041493970900774, 0.049598369747400284, -0.001986663555726409, -0.02250504121184349, -0.012717334553599358, 0.022627349942922592, -0.011217793449759483, 0.008392690680921078, 0.026893654838204384, -0.02314802259206772, -0.00236274441704154, -0.016839709132909775, -0.005535897798836231, 0.036452896893024445, -0.04056433588266373, 0.0246293805539608, -0.013420655392110348, 0.017665250226855278, 0.018130101263523102, -0.01330610178411007, 0.0015050721121951938, -0.00013463414506986737, -0.0038379610050469637, 0.0367143489420414, 0.008147008717060089, -0.02803153172135353, -0.04134703800082207, 0.012775070033967495, 0.049117084592580795, -0.026370292529463768, 0.0066644917242228985, 0.04163368418812752, 0.012792586348950863, 0.022767450660467148, 0.054308824241161346, -0.0015997731825336814, 0.02381298877298832, 0.019857002422213554, -0.009480409324169159, 0.037574898451566696, -0.04668748378753662, 0.017079239711165428, -0.03257615119218826, 0.03634277358651161, -0.019597560167312622, 0.009660630486905575, 0.0005001976387575269, -0.024363497272133827, -0.02584857866168022, -0.021460648626089096, 0.02338608354330063, 0.01631135866045952, 0.03782296180725098, 0.015357009135186672, -0.014598428271710873, -0.030935393646359444, -0.02653317339718342, -0.0003149158146698028, -0.028692064806818962, -0.0553363636136055, 0.022680042311549187, 0.022689344361424446, 0.010944153182208538, 0.016751006245613098, 0.014772609807550907, 0.0035264252219349146, -0.03615933284163475, 0.029744980856776237, 0.008365553803741932, 0.027853025123476982, 0.03296826034784317, -0.033914901316165924, -0.009369364008307457, 0.07794734090566635, -0.02545996941626072, 0.01727874018251896, 0.021574627608060837, -0.024218108505010605, -0.008841346949338913, 0.005071769934147596, 0.03267822414636612, 0.0011345897801220417, -0.0024773050099611282, 0.04660394415259361, -0.030833525583148003, 0.013709661550819874, -0.035651590675115585, 0.006445957813411951, -0.032492317259311676, -0.012050168588757515, 0.00043318161624483764, -0.006563257426023483, 0.047092463821172714, 0.05017615482211113, 0.024735599756240845, -0.04118272289633751, -0.060274478048086166, 0.012585111893713474, 0.009638726711273193, -0.004082337487488985, 0.01944306120276451, -0.023154880851507187, -0.005821639206260443, 0.04851360246539116, -0.020641639828681946, 0.02111872285604477, 0.01474288571625948, 0.004144446924328804, 0.04206564277410507, 0.043430861085653305, 0.029713742434978485, 0.00504793506115675, -0.052199218422174454, 0.018148770555853844, 0.006879204884171486, -0.013234351761639118, 0.0006345259607769549, 0.005952003411948681, 0.007004910614341497, 0.053601596504449844, 0.000128521875012666, 0.028444835916161537, -0.030872927978634834, 0.004967083223164082, -0.016041314229369164, -0.05598733201622963, -0.023077376186847687, 0.051055219024419785, -0.040847618132829666, 0.016607606783509254, -0.005350696854293346, -0.012254842557013035, 0.047067318111658096, 0.021861404180526733, -0.05215201526880264, 0.005435864441096783, 0.0021644849330186844, 0.05170266330242157, -0.058090273290872574, 0.024754611775279045, -0.013722549192607403, -0.004166650585830212, 0.03525597229599953, -0.012108339928090572, 0.0013777290005236864, 0.04344005882740021, 0.00205888319760561, -0.0922575518488884, 0.03621801361441612, 0.040569934993982315, -0.0007270398200489581, 0.001740682520903647, 0.004924333654344082, 0.042700737714767456, 0.0356207974255085, 0.022270366549491882, -0.0007108315476216376, -0.0438183955848217, -0.021999184042215347, 0.022125499323010445, 0.02179069072008133, 0.02145063504576683, -0.019720660522580147, 0.00862747710198164, -0.012776744551956654, -0.014707905240356922, -0.027101241052150726, 0.012053330428898335, 0.0015107939252629876, -0.0006472612149082124, -0.00817770417779684, -0.006427387241274118, 0.007067441940307617, -0.004002446308732033, 0.005843397229909897, 0.00496028084307909, 0.008829723112285137, -0.0000883627581060864, 0.0008750707493163645, -0.01008689496666193, 0.030285706743597984, 0.019288908690214157, 0.054187092930078506, 0.028202202171087265, 0.01675380766391754, 0.008407661691308022, 0.0028686716686934233, 0.047009993344545364, 0.016905896365642548, -0.014999061822891235, -0.022496527060866356, -0.006764439400285482, 0.008698683232069016, -0.004568147473037243, 0.006405905820429325, 0.0037401134613901377, 0.01563960872590542, -0.019226618111133575, -0.0032241521403193474, 0.02011185884475708, -0.047063764184713364, -0.03418475389480591, -0.04836125671863556, 0.01308873388916254, -0.018266627565026283, 0.006004860159009695, -0.005394892767071724, 0.004079541191458702, -0.03518771752715111, 0.0066480692476034164, 0.003213661490008235, 0.005014695227146149, 0.020260881632566452, 0.05797836184501648, 0.04771319404244423, 0.006833459250628948, -0.0033438208047300577, -0.046675752848386765, -0.027166545391082764, -0.05549104884266853, -0.03315804898738861, -0.0261432696133852, 0.03720318526029587, 0.01743193529546261, 0.029554879292845726, 0.043487079441547394, -0.016815239563584328, 0.007356173824518919, 0.04701151326298714, -0.05243832990527153, -0.07150930911302567, -0.043348584324121475, 0.010690538212656975, 0.010453218594193459, 0.016052495688199997, 0.026325391605496407, 0.0002703832578845322, 0.007834585383534431, -0.02567845769226551, -0.05307108908891678, 0.02285732515156269, 0.03651466593146324, -0.03026425652205944, 0.03988809883594513, 0.00918812956660986, 0.061556532979011536, 0.013484107330441475, 0.004597650840878487, 0.009037255309522152, 0.05014216899871826, 0.007983976043760777, 0.026522794738411903, -0.009562209248542786, 0.028950583189725876, 0.03439376503229141, 0.0150979682803154, -0.06738574802875519, 0.030501719564199448, 0.03621045872569084, -0.04708163067698479, 0.03466227650642395, 0.012161888182163239, -0.029619937762618065, 0.004257287364453077, 0.024007244035601616, 0.03357026353478432, -0.025187531486153603, -0.03879290074110031, -0.022675078362226486, 0.03180959075689316, -0.013290059752762318, 0.018754445016384125, 0.06335114687681198, -0.0133564667776227, 0.027827037498354912, 0.04469588026404381, -0.0016718582483008504, 0.028360528871417046, 0.02525075525045395, -0.014987746253609657, -0.022186050191521645, 0.04823930934071541, 0.02332283928990364, 0.03499220684170723, 0.03267311304807663, -0.009556273929774761, 0.0040451716631650925, -0.04059167951345444, -0.010080969892442226, 0.011045077815651894, 0.019226955249905586, 0.001766209490597248, -0.014134911820292473, 0.011909880675375462, -0.030828170478343964, 0.06581049412488937, 0.06829046458005905, 0.031495846807956696, -0.030323538929224014, 0.06883357465267181, 0.005089127458631992, 0.04911038279533386, 0.012780924327671528, 0.033596668392419815, 0.02283802628517151, -0.01096042525023222, 0.010968895629048347, 0.02013646811246872, 0.03824425861239433, 0.034283943474292755, -0.02765018306672573, 0.037011973559856415, 0.0007358172442764044, -0.014696256257593632, 0.021560320630669594, 0.045103076845407486, -0.01170539204031229, -0.00732111930847168, 0.025748882442712784, -0.021516164764761925, 0.015358679927885532, 0.004421998746693134, 0.0027307672426104546, 0.022348780184984207, 0.008305552415549755, 0.02407897636294365, 0.018586620688438416, -0.03302012011408806, -0.005965657066553831, 0.00985036138445139, 0.028565268963575363, -0.010227708145976067, 0.02964167669415474, -0.06677042692899704, -0.03871457278728485, -0.051701225340366364, 0.0032728654332458973, -0.03354824706912041, 0.050370391458272934, 0.001623086049221456, -0.013451188802719116, 0.04937852919101715, 0.046486545354127884, -0.0064424676820635796, 0.010613759979605675, 0.016706854104995728, -0.009709089063107967, -0.005750562995672226, -0.03935429826378822, 0.001857366762124002, -0.06908097118139267, 0.02489634044468403, -0.06840161979198456, -0.02623250149190426, -0.01769086718559265, 0.0495804026722908, 0.03603740781545639, 0.026491288095712662, -0.019500387832522392, -0.03209133818745613, -0.009606607258319855, 0.022094804793596268, -0.024917813017964363, 0.013315829448401928, 0.025264719501137733, 0.0031570035498589277, 0.013378924690186977, -0.02796182781457901, -0.004404586274176836, -0.032629940658807755, 0.01711096428334713, 0.04246052727103233, -0.009228181093931198, -0.030441390350461006, -0.006757416762411594, 0.037569791078567505, -0.02403533272445202, 0.01768059842288494, 0.03469448164105415, -0.022043224424123764, 0.0577978789806366, -0.027699552476406097, 0.01114126481115818, -0.024076178669929504, 0.002047022106125951, -0.02568848244845867, -0.019223153591156006, 0.0006884860340505838, 0.03793693706393242, 0.019336629658937454, 0.02734392322599888, 0.007664172910153866, -0.0013250901829451323, -0.0919489860534668, -0.0011805124813690782, -0.006945593282580376, 0.046422939747571945, 0.024327637627720833, -0.026213450357317924, 0.032966841012239456, 0.011895670555531979, 0.001399633358232677, -0.039129942655563354, -0.002030824776738882, 0.013372881338000298, 0.049861468374729156, 0.019507886841893196, -0.0641326755285263, 0.02078656107187271, -0.04494686797261238, -0.002037486992776394, -0.00735856220126152, 0.009048444218933582, -0.007481350097805262, 0.0035162048880010843, -0.006975105032324791, -0.00700902147218585, -0.005076633766293526, 0.03492371365427971, -0.004680531099438667, 0.043841972947120667, -0.03747318685054779, -0.010564569383859634, 0.0076042236760258675, -0.03614102303981781, -0.021425675600767136, -0.024914512410759926, 0.007155187893658876, 0.051448989659547806, 0.031145917251706123, 0.024887826293706894, 0.0062536923214793205, 0.019086843356490135, 0.016112586483359337, 0.022797370329499245, -0.026395779103040695, -0.011707446537911892, 0.05381805822253227, 0.023359917104244232, -0.0432574562728405, -0.009855630807578564, 0.01863252744078636, 0.03258329629898071, -0.002779183443635702, 0.04925378039479256, -0.015920177102088928, -0.003213814925402403, -0.011688563972711563, 0.04133353382349014, 0.007476670667529106, 0.06494858115911484, 0.007099332753568888, 0.01198502816259861, 0.0023205389734357595, 0.030431825667619705 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Data Preprocessing In this section, we show how the data can be pre-processed for training. More importantly, we try to give the reader some insight into the process of deciding how to preprocess the data. We will need datasets and transformers to be installed. python !pip install datasets==1.0.2 !pip install transformers==4.2.1 Let's start by downloading the CNN/Dailymail dataset. python import datasets train_data = datasets.load_dataset("cnn_dailymail", "3.0.0", split="train") Alright, let\'s get a first impression of the dataset. Alternatively, the dataset can also be visualized using the awesome datasets viewer online. python train_data.info.description Our input is called article and our labels are called highlights. Let\'s now print out the first example of the training data to get a feeling for the data. python import pandas as pd from IPython.display import display, HTML from datasets import ClassLabel df = pd.DataFrame(train_data[:1]) del df["id"] for column, typ in train_data.features.items(): if isinstance(typ, ClassLabel): df[column] = df[column].transform(lambda i: typ.names[i]) display(HTML(df.to_html())) python OUTPUT: ------- Article: """It's official: U.S. President Barack Obama wants lawmakers to weigh in on whether to use military force in Syria. Obama sent a letter to the heads of the House and Senate on Saturday night, hours after announcing that he believes military action against Syrian targets is the right step to take over the alleged use of chemical weapons. The proposed legislation from Obama asks Congress to approve the use of military force "to deter, disrupt, prevent and degrade the potential for future uses of chemical weapons or other weapons of mass destruction." It's a step that is set to turn an international crisis into a fierce domestic political battle. There are key questions looming over the debate: What did U.N. weapons inspectors find in Syria? What happens if Congress votes no? And how will the Syrian government react? In a televised address from the White House Rose Garden earlier Saturday, the president said he would take his case to Congress, not because he has to -- but because he wants to. "While I believe I have the authority to carry out this military action without specific congressional authorization, I know that the country will be stronger if we take this course, and our actions will be even more effective," he said. "We should have this debate, because the issues are too big for business as usual." Obama said top congressional leaders had agreed to schedule a debate when the body returns to Washington on September 9. The Senate Foreign Relations Committee will hold a hearing over the matter on Tuesday, Sen. Robert Menendez said. Transcript: Read Obama's full remarks . Syrian crisis: Latest developments . U.N. inspectors leave Syria . Obama's remarks came shortly after U.N. inspectors left Syria, carrying evidence that will determine whether chemical weapons were used in an attack early last week in a Damascus suburb. "The aim of the game here, the mandate, is very clear -- and that is to ascertain whether chemical weapons were used -- and not by whom," U.N. spokesman Martin Nesirky told reporters on Saturday. But who used the weapons in the reported toxic gas attack in a Damascus suburb on August 21 has been a key point of global debate over the Syrian crisis. Top U.S. officials have said there's no doubt that the Syrian government was behind it, while Syrian officials have denied responsibility and blamed jihadists fighting with the rebels. British and U.S. intelligence reports say the attack involved chemical weapons, but U.N. officials have stressed the importance of waiting for an official report from inspectors. The inspectors will share their findings with U.N. Secretary-General Ban Ki-moon Ban, who has said he wants to wait until the U.N. team's final report is completed before presenting it to the U.N. Security Council. The Organization for the Prohibition of Chemical Weapons, which nine of the inspectors belong to, said Saturday that it could take up to three weeks to analyze the evidence they collected. "It needs time to be able to analyze the information and the samples," Nesirky said. He noted that Ban has repeatedly said there is no alternative to a political solution to the crisis in Syria, and that "a military solution is not an option." Bergen: Syria is a problem from hell for the U.S. Obama: 'This menace must be confronted' Obama's senior advisers have debated the next steps to take, and the president's comments Saturday came amid mounting political pressure over the situation in Syria. Some U.S. lawmakers have called for immediate action while others warn of stepping into what could become a quagmire. Some global leaders have expressed support, but the British Parliament's vote against military action earlier this week was a blow to Obama's hopes of getting strong backing from key NATO allies. On Saturday, Obama proposed what he said would be a limited military action against Syrian President Bashar al-Assad. Any military attack would not be open-ended or include U.S. ground forces, he said. Syria's alleged use of chemical weapons earlier this month "is an assault on human dignity," the president said. A failure to respond with force, Obama argued, "could lead to escalating use of chemical weapons or their proliferation to terrorist groups who would do our people harm. In a world with many dangers, this menace must be confronted." Syria missile strike: What would happen next? Map: U.S. and allied assets around Syria . Obama decision came Friday night . On Friday night, the president made a last-minute decision to consult lawmakers. What will happen if they vote no? It's unclear. A senior administration official told CNN that Obama has the authority to act without Congress -- even if Congress rejects his request for authorization to use force. Obama on Saturday continued to shore up support for a strike on the al-Assad government. He spoke by phone with French President Francois Hollande before his Rose Garden speech. "The two leaders agreed that the international community must deliver a resolute message to the Assad regime -- and others who would consider using chemical weapons -- that these crimes are unacceptable and those who violate this international norm will be held accountable by the world," the White House said. Meanwhile, as uncertainty loomed over how Congress would weigh in, U.S. military officials said they remained at the ready. 5 key assertions: U.S. intelligence report on Syria . Syria: Who wants what after chemical weapons horror . Reactions mixed to Obama's speech . A spokesman for the Syrian National Coalition said that the opposition group was disappointed by Obama's announcement. "Our fear now is that the lack of action could embolden the regime and they repeat his attacks in a more serious way," said spokesman Louay Safi. "So we are quite concerned." Some members of Congress applauded Obama's decision. House Speaker John Boehner, Majority Leader Eric Cantor, Majority Whip Kevin McCarthy and Conference Chair Cathy McMorris Rodgers issued a statement Saturday praising the president. "Under the Constitution, the responsibility to declare war lies with Congress," the Republican lawmakers said. "We are glad the president is seeking authorization for any military action in Syria in response to serious, substantive questions being raised." More than 160 legislators, including 63 of Obama's fellow Democrats, had signed letters calling for either a vote or at least a "full debate" before any U.S. action. British Prime Minister David Cameron, whose own attempt to get lawmakers in his country to support military action in Syria failed earlier this week, responded to Obama's speech in a Twitter post Saturday. "I understand and support Barack Obama's position on Syria," Cameron said. An influential lawmaker in Russia -- which has stood by Syria and criticized the United States -- had his own theory. "The main reason Obama is turning to the Congress: the military operation did not get enough support either in the world, among allies of the US or in the United States itself," Alexei Pushkov, chairman of the international-affairs committee of the Russian State Duma, said in a Twitter post. In the United States, scattered groups of anti-war protesters around the country took to the streets Saturday. "Like many other Americans...we're just tired of the United States getting involved and invading and bombing other countries," said Robin Rosecrans, who was among hundreds at a Los Angeles demonstration. What do Syria's neighbors think? Why Russia, China, Iran stand by Assad . Syria's government unfazed . After Obama's speech, a military and political analyst on Syrian state TV said Obama is "embarrassed" that Russia opposes military action against Syria, is "crying for help" for someone to come to his rescue and is facing two defeats -- on the political and military levels. Syria's prime minister appeared unfazed by the saber-rattling. "The Syrian Army's status is on maximum readiness and fingers are on the trigger to confront all challenges," Wael Nader al-Halqi said during a meeting with a delegation of Syrian expatriates from Italy, according to a banner on Syria State TV that was broadcast prior to Obama's address. An anchor on Syrian state television said Obama "appeared to be preparing for an aggression on Syria based on repeated lies." A top Syrian diplomat told the state television network that Obama was facing pressure to take military action from Israel, Turkey, some Arabs and right-wing extremists in the United States. "I think he has done well by doing what Cameron did in terms of taking the issue to Parliament," said Bashar Jaafari, Syria's ambassador to the United Nations. Both Obama and Cameron, he said, "climbed to the top of the tree and don't know how to get down." The Syrian government has denied that it used chemical weapons in the August 21 attack, saying that jihadists fighting with the rebels used them in an effort to turn global sentiments against it. British intelligence had put the number of people killed in the attack at more than 350. On Saturday, Obama said "all told, well over 1,000 people were murdered." U.S. Secretary of State John Kerry on Friday cited a death toll of 1,429, more than 400 of them children. No explanation was offered for the discrepancy. Iran: U.S. military action in Syria would spark 'disaster' Opinion: Why strikes in Syria are a bad idea .""" Summary: """Syrian official: Obama climbed to the top of the tree, "doesn't know how to get down"\nObama sends a letter to the heads of the House and Senate .\nObama to seek congressional approval on military action against Syria .\nAim is to determine whether CW were used, not by whom, says U.N. spokesman""" The input data seems to consist of short news articles. Interestingly, the labels appear to be bullet-point-like summaries. At this point, one should probably take a look at a couple of other examples to get a better feeling for the data. One should also notice here that the text is case-sensitive. This means that we have to be careful if we want to use case-insensitive models. As CNN/Dailymail is a summarization dataset, the model will be evaluated using the ROUGE metric. Checking the description of ROUGE in 🤗datasets, cf. here, we can see that the metric is case-insensitive, meaning that upper case letters will be normalized to lower case letters during evaluation. Thus, we can safely leverage uncased checkpoints, such as bert-base-uncased. Cool! Next, let\'s get a sense of the length of input data and labels. As models compute length in token-length, we will make use of the bert-base-uncased tokenizer to compute the article and summary length. First, we load the tokenizer. python from transformers import BertTokenizerFast tokenizer = BertTokenizerFast.from_pretrained("bert-base-uncased") Next, we make use of .map() to compute the length of the article and its summary. Since we know that the maximum length that bert-base-uncased can process amounts to 512, we are also interested in the percentage of input samples being longer than the maximum length. Similarly, we compute the percentage of summaries that are longer than 64, and 128 respectively. We can define the .map() function as follows. python # map article and summary len to dict as well as if sample is longer than 512 tokens def map_to_length(x): x["article_len"] = len(tokenizer(x["article"]).input_ids) x["article_longer_512"] = int(x["article_len"] > 512) x["summary_len"] = len(tokenizer(x["highlights"]).input_ids) x["summary_longer_64"] = int(x["summary_len"] > 64) x["summary_longer_128"] = int(x["summary_len"] > 128) return x It should be sufficient to look at the first 10000 samples. We can speed up the mapping by using multiple processes with num_proc=4. python sample_size = 10000 data_stats = train_data.select(range(sample_size)).map(map_to_length, num_proc=4) Having computed the length for the first 10000 samples, we should now average them together. For this, we can make use of the .map() function with batched=True and batch_size=-1 to have access to all 10000 samples within the .map() function. python def compute_and_print_stats(x): if len(x["article_len"]) == sample_size: print( "Article Mean: {}, %-Articles > 512:{}, Summary Mean:{}, %-Summary > 64:{}, %-Summary > 128:{}".format( sum(x["article_len"]) / sample_size, sum(x["article_longer_512"]) / sample_size, sum(x["summary_len"]) / sample_size, sum(x["summary_longer_64"]) / sample_size, sum(x["summary_longer_128"]) / sample_size, ) ) output = data_stats.map( compute_and_print_stats, batched=True, batch_size=-1, ) python OUTPUT: ------- Article Mean: 847.6216, %-Articles > 512:0.7355, Summary Mean:57.7742, %-Summary > 64:0.3185, %-Summary > 128:0.0 We can see that on average an article contains 848 tokens with ca. 3/4 of the articles being longer than the model\'s max_length 512. The summary is on average 57 tokens long. Over 30% of our 10000-sample summaries are longer than 64 tokens, but none are longer than 128 tokens. bert-base-cased is limited to 512 tokens, which means we would have to cut possibly important information from the article. Because most of the important information is often found at the beginning of articles and because we want to be computationally efficient, we decide to stick to bert-base-cased with a max_length of 512 in this notebook. This choice is not optimal but has shown to yield good results on CNN/Dailymail. Alternatively, one could leverage long-range sequence models, such as Longformer to be used as the encoder. Regarding the summary length, we can see that a length of 128 already includes all of the summary labels. 128 is easily within the limits of bert-base-cased, so we decide to limit the generation to 128. Again, we will make use of the .map() function - this time to transform each training batch into a batch of model inputs. "article" and "highlights" are tokenized and prepared as the Encoder\'s "input_ids" and Decoder\'s "decoder_input_ids" respectively. "labels" are shifted automatically to the left for language modeling training. Lastly, it is very important to remember to ignore the loss of the padded labels. In 🤗Transformers this can be done by setting the label to -100. Great, let\'s write down our mapping function then. python encoder_max_length=512 decoder_max_length=128 def process_data_to_model_inputs(batch): # tokenize the inputs and labels inputs = tokenizer(batch["article"], padding="max_length", truncation=True, max_length=encoder_max_length) outputs = tokenizer(batch["highlights"], padding="max_length", truncation=True, max_length=decoder_max_length) batch["input_ids"] = inputs.input_ids batch["attention_mask"] = inputs.attention_mask batch["labels"] = outputs.input_ids.copy() # because BERT automatically shifts the labels, the labels correspond exactly to `decoder_input_ids`. # We have to make sure that the PAD token is ignored batch["labels"] = [[-100 if token == tokenizer.pad_token_id else token for token in labels] for labels in batch["labels"]] return batch In this notebook, we train and evaluate the model just on a few training examples for demonstration and set the batch_size to 4 to prevent out-of-memory issues. The following line reduces the training data to only the first 32 examples. The cell can be commented out or not run for a full training run. Good results were obtained with a batch_size of 16. python train_data = train_data.select(range(32)) Alright, let\'s prepare the training data. python # batch_size = 16 batch_size=4 train_data = train_data.map( process_data_to_model_inputs, batched=True, batch_size=batch_size, remove_columns=["article", "highlights", "id"] ) Taking a look at the processed training dataset we can see that the column names article, highlights, and id have been replaced by the arguments expected by the EncoderDecoderModel. python train_data python OUTPUT: ------- Dataset(features: {'attention_mask': Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None), 'decoder_attention_mask': Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None), 'decoder_input_ids': Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None), 'input_ids': Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None), 'labels': Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None)}, num_rows: 32) So far, the data was manipulated using Python\'s List format. Let\'s convert the data to PyTorch Tensors to be trained on GPU. python train_data.set_format( type="torch", columns=["input_ids", "attention_mask", "labels"], ) Awesome, the data processing of the training data is finished. Analogous, we can do the same for the validation data. First, we load 10% of the validation dataset: python val_data = datasets.load_dataset("cnn_dailymail", "3.0.0", split="validation[:10%]") For demonstration purposes, the validation data is then reduced to just 8 samples, python val_data = val_data.select(range(8)) the mapping function is applied, python val_data = val_data.map( process_data_to_model_inputs, batched=True, batch_size=batch_size, remove_columns=["article", "highlights", "id"] ) and, finally, the validation data is also converted to PyTorch tensors. python val_data.set_format( type="torch", columns=["input_ids", "attention_mask", "labels"], ) Great! Now we can move to warm-starting the EncoderDecoderModel.
[ 0.023238008841872215, 0.01236693374812603, 0.0204185638576746, 0.05050390958786011, 0.05070338025689125, 0.08174024522304535, 0.03505552187561989, 0.03725248575210571, -0.05417468026280403, 0.0008660113089717925, -0.08024219423532486, 0.06436262279748917, -0.07857067137956619, 0.02284190244972706, 0.03292171284556389, -0.046191778033971786, 0.05126215144991875, -0.025765322148799896, -0.010821960866451263, 0.08748029917478561, -0.00335831381380558, -0.037971265614032745, 0.010452243499457836, 0.07432247698307037, 0.007539692334830761, -0.024717282503843307, 0.07157359272241592, 0.00005884999336558394, -0.03429514914751053, 0.0906863734126091, -0.11645147949457169, -0.032172102481126785, -0.027129191905260086, -0.013513953424990177, -0.031528692692518234, -0.02137024886906147, -0.05831899866461754, 0.06185784935951233, 0.09366951882839203, -0.05642443895339966, -0.02876870706677437, -0.029101088643074036, -0.09962750226259232, 0.05387235805392265, -0.03522172570228577, -0.09832990914583206, -0.16533012688159943, 0.09589230269193649, 0.03196243196725845, -0.0321376696228981, -0.08633015304803848, 0.09230475127696991, 0.04010774940252304, -0.03200659528374672, -0.025448942556977272, -0.008038030005991459, -0.0010573483305051923, -0.01469001080840826, 0.014354011043906212, 0.03931561857461929, 0.037979066371917725, 0.03072381764650345, 0.03287399560213089, -0.01350528933107853, 0.053959451615810394, -0.032631054520606995, -0.007326547522097826, 0.11756014823913574, -0.0640476867556572, -0.07474780827760696, 0.0003172717406414449, -0.05624980479478836, -0.010191407985985279, -0.023620981723070145, 0.023207802325487137, -0.0099854851141572, -0.031422972679138184, 0.03882227838039398, -0.057787757366895676, 0.0565936341881752, 0.004557706881314516, 0.043522775173187256, 0.031034016981720924, 0.007515930570662022, 0.07380431145429611, 0.0017591520445421338, 0.03645021468400955, 0.03960326686501503, -0.05714617669582367, 0.08036407083272934, -0.012622739188373089, -0.04273558408021927, 0.018922219052910805, 0.0027559944428503513, 0.019562337547540665, -0.033347900956869125, -0.020491737872362137, -0.01884113997220993, -0.011166151612997055, -0.06408572942018509, -0.010178230702877045, -0.09202204644680023, 0.08244539797306061, -0.04789305850863457, -0.05845949426293373, 0.03486035019159317, -0.05722730979323387, -0.019592465832829475, -0.030857525765895844, 0.022771595045924187, 0.02001718059182167, 0.026673167943954468, -0.02005588263273239, 0.07100451737642288, -0.07857350260019302, 0.055065032094717026, 0.03776326775550842, 0.0035115249920636415, -0.016210444271564484, 0.02199355699121952, 0.002416522242128849, 0.10075505822896957, 0.029352782294154167, 0.020850770175457, -0.0066461083479225636, 0.03432125225663185, 0.022448377683758736, 0.017835119739174843, 0.007200172636657953, 0.009446106851100922, 0.007718957029283047, -0.0042579881846904755, 0.04517331346869469, -0.025408487766981125, -0.0071920002810657024, -0.05287569388747215, -0.044372860342264175, 0.041623663157224655, 0.04848529025912285, -0.01979765109717846, 0.025030845776200294, 0.07752672582864761, 0.0052668130956590176, 0.04849492385983467, -0.02096952684223652, -0.023678064346313477, -0.04000018909573555, 0.06778522580862045, 0.027293920516967773, 0.007261096499860287, -0.0031474153511226177, 0.05596395581960678, 0.007644090801477432, -0.009998221881687641, 0.061595041304826736, 0.08707637339830399, -0.007452229503542185, -0.02778621017932892, -0.10337478667497635, 0.006151932291686535, 0.015721019357442856, 0.050830040127038956, -0.00022232660558074713, 0.01348674576729536, 0.0457536056637764, -0.08547269552946091, -0.005929829552769661, -0.018263237550854683, 0.03989898040890694, 0.0037987090181559324, -0.03688112273812294, -0.04602259024977684, 0.07057347148656845, 0.04985949024558067, 0.025795090943574905, 0.03731228783726692, 0.019372161477804184, 0.023113636299967766, 0.02745058387517929, -0.00729999877512455, -0.024293560534715652, 0.03314438462257385, -0.0386926643550396, 0.03359575197100639, 0.05186066776514053, -0.04500887915492058, 0.04170750081539154, -0.0733364075422287, 0.012521235272288322, 0.07293393462896347, -0.07075236737728119, 0.0005005650455132127, 0.0657850131392479, -0.01237681694328785, 0.04313176870346069, -0.08886778354644775, -0.050199709832668304, 0.09105990082025528, -0.007026143837720156, 0.08955801278352737, -0.004216729663312435, -0.005529511254280806, 0.03699181601405144, -0.06180266663432121, 0.008002538233995438, -0.011100036092102528, -0.0005507299210876226, -0.039970576763153076, 0.06826489418745041, 0.02111392468214035, -0.02076689898967743, -0.08852257579565048, 0.026664700359106064, -0.05146070569753647, -0.02944015897810459, 0.0013925880193710327, -0.058710627257823944, 0.027032073587179184, -0.005337662063539028, -0.02109362930059433, 0.11172579228878021, -0.01948440447449684, 0.04138791933655739, -0.004399572499096394, -0.02645348571240902, 0.03744949400424957, 0.09251002222299576, 0.10672406852245331, 0.03517758101224899, -0.10021243244409561, -0.025047125294804573, -0.011061843484640121, 0.011460001580417156, 0.008775812573730946, -0.03252391889691353, -0.03605348616838455, -0.005453153979033232, 0.045067448168992996, 0.04151234030723572, -0.018948635086417198, 0.048505622893571854, -0.023414842784404755, -0.020244412124156952, 0.015895657241344452, -0.05780728906393051, -0.04378192499279976, 0.06872676312923431, -0.01088835671544075, -0.021960793063044548, -0.05261647328734398, -0.02755122072994709, 0.016935739666223526, 0.021759741008281708, -0.03646640479564667, -0.017384206876158714, 0.039326779544353485, 0.014245051890611649, 0.02788291685283184, -0.03216182067990303, 0.03778770565986633, 0.00922306813299656, -0.024416591972112656, -0.05118170380592346, -0.08490199595689774, -0.0048143998719751835, -0.02823774516582489, 0.016309572383761406, -0.027672335505485535, 0.02718210406601429, -0.013585241511464119, -0.0011149575002491474, -0.03024747595191002, 0.039605360478162766, 0.002038115169852972, 0.022451097145676613, 0.025359969586133957, 0.008139623329043388, 0.021227866411209106, -0.009221331216394901, -0.04132271185517311, 0.00001534675720904488, -0.04744242876768112, 0.005631531123071909, 0.03732889145612717, 0.03888046741485596, -0.015104098245501518, 0.008980991318821907, 0.011409697122871876, -0.01772253029048443, 0.02943219244480133, -0.0161886028945446, 0.04264840483665466, 0.005012705456465483, -0.02395343966782093, 0.03842116519808769, -0.040233176201581955, -0.00828660000115633, -0.011410393752157688, -0.0075159030966460705, -0.014401094056665897, -0.0050523956306278706, -0.010311377234756947, 0.011876877397298813, -0.006523936055600643, -0.021152012050151825, 0.01766309328377247, 0.023558106273412704, 0.04319366067647934, -0.10220567882061005, -0.0010429874528199434, 0.055229704827070236, -0.02558496780693531, -0.0001734144752845168, -0.025387389585375786, 0.08078870922327042, -0.004238729830831289, -0.0025615643244236708, 0.014258703216910362, -0.011242100037634373, -0.003914274740964174, 0.005981024354696274, -0.0037472518160939217, 0.03643875569105148, -0.020404966548085213, 0.011824963614344597, 0.0068155271001160145, 0.032242435961961746, 0.04507489129900932, -0.04418504983186722, 0.06672201305627823, 0.020659903064370155, 0.02860690839588642, -0.019834889099001884, 0.035688772797584534, 0.05020064488053322, 0.046659018844366074, 0.010738912038505077, 0.008773008361458778, -0.004606342874467373, -0.028151633217930794, 0.004230637568980455, 0.011725267395377159, -0.013380512595176697, -0.007818165235221386, -0.013571224175393581, 0.022734951227903366, -0.005668755155056715, 0.03999662771821022, -0.04569695144891739, 0.01370638981461525, -0.0007818746962584555, 0.017612837255001068, 0.033868156373500824, 0.011667500250041485, -0.015573607757687569, -0.033136121928691864, -0.0010147785069420934, -0.05644344538450241, -0.024677159264683723, -0.00506327860057354, -0.0027510016225278378, 0.05116090551018715, 0.016205664724111557, 0.021332750096917152, 0.04433418810367584, 0.014946818351745605, 0.03366458788514137, -0.03515934199094772, -0.00652865506708622, 0.0582893006503582, 0.012847242876887321, 0.0001825201470637694, -0.021482037380337715, 0.01670239306986332, 0.004169474355876446, 0.020972827449440956, 0.007929912768304348, 0.04463280364871025, -0.027407018467783928, -0.003293118439614773, 0.01750684343278408, -0.001971201039850712, 0.0175041314214468, -0.01786869578063488, 0.00844293087720871, -0.010775228962302208, 0.04680098593235016, 0.04932473599910736, -0.037820346653461456, -0.0623282864689827, -0.017696227878332138, -0.044920820742845535, 0.008021405898034573, -0.010184843093156815, -0.008149383589625359, -0.03636457026004791, 0.0297051090747118, 0.004923644941300154, 0.0051076048985123634, -0.040827427059412, -0.025931423529982567, -0.011682672426104546, -0.03592006489634514, -0.004668012261390686, 0.018683992326259613, -0.03984496742486954, -0.0333767905831337, -0.015344355255365372, -0.011536607518792152, -0.07517735660076141, -0.012972764670848846, 0.011158742010593414, -0.058503735810518265, -0.008566067554056644, -0.039729055017232895, -0.0258334968239069, -0.027041561901569366, -0.03697105869650841, 0.0019167817663401365, -0.004772582557052374, -0.006397422403097153, -0.039013031870126724, -0.006899695377796888, 0.0474211685359478, -0.007208993658423424, -0.01872318610548973, -0.00031913508428260684, 0.04629861190915108, -0.02876172587275505, 0.01484384573996067, -0.04229161888360977, -0.050900738686323166, -0.012501884251832962, -0.02920692414045334, 0.04540928825736046, 0.04030057415366173, 0.01533297449350357, -0.04233806952834129, -0.0193640049546957, -0.026914028450846672, -0.017893362790346146, 0.009639720432460308, 0.027380404993891716, -0.012569042854011059, -0.020837942138314247, 0.017221886664628983, 0.029225032776594162, -0.02349485456943512, -0.020231975242495537, -0.03159491717815399, 0.04946788027882576, 0.02089836820960045, 0.04069767892360687, -0.008180968463420868, -0.036846984177827835, -0.0027747908607125282, -0.013759801164269447, -0.011648595333099365, 0.0031326559837907553, 0.026492470875382423, -0.03570704162120819, 0.004468044266104698, 0.025293026119470596, -0.012205877341330051, 0.03107370249927044, 0.004453087691217661, 0.008241552859544754, 0.03175199404358864, -0.043004147708415985, -0.04565715044736862, -0.033431533724069595, 0.011848238296806812, 0.006688936147838831, -0.025729749351739883, 0.020929329097270966, -0.02835153043270111, 0.010166826657950878, -0.01524288859218359, -0.013716145418584347, -0.00005781965228379704, 0.006177097093313932, -0.008957534097135067, 0.022714737802743912, 0.014023431576788425, 0.006292493082582951, 0.029879163950681686, -0.013249384239315987, 0.010400776751339436, 0.0033015685621649027, -0.03688595071434975, -0.00629241019487381, 0.033113203942775726, -0.020198995247483253, 0.03533788397908211, 0.0021462556906044483, 0.03376934677362442, -0.0043986146338284016, 0.016225887462496758, 0.012128891423344612, -0.06993702054023743, 0.010295414365828037, -0.05707941949367523, -0.014737286604940891, 0.034830860793590546, -0.007600640412420034, 0.005413195118308067, -0.028210032731294632, -0.03260758891701698, -0.01574300043284893, 0.06062151491641998, -0.01021413691341877, -0.01331210508942604, -0.012431572191417217, 0.004097219556570053, -0.014525369741022587, -0.019551998004317284, 0.007638964802026749, -0.0600043348968029, 0.039268992841243744, -0.016167230904102325, -0.009258974343538284, -0.008358877152204514, -0.015954267233610153, -0.013193957507610321, -0.026030246168375015, -0.0032610727939754725, 0.011327527463436127, 0.04609347879886627, -0.02924073301255703, -0.018999315798282623, -0.004208606667816639, 0.05187266319990158, 0.04134070873260498, -0.017142273485660553, 0.010207044892013073, -0.010647207498550415, 0.02722090110182762, 0.0057676248252391815, 0.006499232724308968, 0.05423213168978691, 0.022340159863233566, 0.04538881033658981, 0.005007733590900898, -0.023643383756279945, -0.029515204951167107, 0.04772002622485161, 0.023880889639258385, -0.01956319250166416, -0.04378149285912514, -0.031586866825819016, -0.048952918499708176, 0.013185115531086922, 0.0022890926338732243, 0.03840884938836098, 0.03692302852869034, 0.007693741470575333, 0.025982890278100967, -0.003982636611908674, -0.003608369268476963, 0.03021158091723919, -0.006575005128979683, -0.026136700063943863, 0.006661562714725733, 0.01130176242440939, -0.017916012555360794, -0.0019644491840153933, 0.042298562824726105, 0.007248643320053816, -0.01830163411796093, -0.029646093025803566, 0.017128873616456985, -0.002909247297793627, -0.0098203020170331, 0.005312823224812746, 0.030324377119541168, -0.025238268077373505, 0.013997157104313374, 0.0062375059351325035, 0.03450479730963707, 0.06734923273324966, 0.008245748467743397, 0.02316332422196865, -0.01929602585732937, -0.0030302461236715317, -0.01189772505313158, 0.05913679674267769, -0.02061205543577671, 0.029378049075603485, -0.016052328050136566, 0.01180943287909031, 0.04445802792906761, -0.010773816145956516, 0.009933745488524437, -0.023298192769289017, 0.05731724202632904, 0.03074539080262184, 0.00467239273712039, 0.008622551336884499, -0.012734103947877884, -0.013139509595930576, -0.10508237779140472, -0.02702438458800316, -0.00329327373765409, 0.015531953424215317, 0.03307057544589043, -0.023323392495512962, 0.017390834167599678, -0.034528568387031555, 0.06898947060108185, 0.035826344043016434, 0.029484685510396957, 0.02163362130522728, 0.01677033305168152, 0.0652584657073021, 0.020619619637727737, 0.02752307616174221, 0.02814091369509697, 0.011262236163020134, -0.024916037917137146, 0.03251408785581589, 0.029477614909410477, 0.048592377454042435, 0.0024914101231843233, -0.007644772529602051, -0.006020714528858662, -0.02705806866288185, -0.022516388446092606, -0.00006621766806347296, -0.01045521255582571, -0.04792739823460579, -0.014376112259924412, 0.03473638743162155, -0.04237902909517288, 0.0032517851796001196, -0.01760009676218033, -0.01093932706862688, -0.04694768041372299, -0.011655440554022789, -0.045665446668863297, 0.04863487929105759, -0.028314320370554924, -0.033299755305051804, -0.04269157722592354, -0.005257312674075365, 0.009637854062020779, 0.014014661312103271, -0.020060647279024124, -0.04711262881755829, -0.05540360510349274, -0.010580526664853096, 0.014846713282167912, 0.05736616626381874, -0.014460412785410881, 0.0037428676150739193, -0.011937473900616169, -0.0037840032018721104, -0.026856679469347, 0.03252937272191048, 0.00824747048318386, 0.047458499670028687, -0.0246697086840868, 0.024712013080716133, -0.03647152706980705, -0.023651180788874626, 0.03678277134895325, -0.034320902079343796, 0.018105437979102135, -0.06228983774781227, 0.042161837220191956, -0.008695154450833797, 0.03582026809453964, -0.004436285234987736, -0.03745945170521736, 0.000538419175427407, -0.005846089217811823, -0.013209665194153786, 0.037436407059431076, 0.01844807155430317, -0.008639776147902012, 0.026552552357316017, -0.003998377826064825, -0.027314171195030212, -0.024735072627663612, -0.0015985973877832294, 0.020783869549632072, -0.02505313605070114, -0.020424704998731613, 0.014751330018043518, 0.027662338688969612, 0.02421838603913784, 0.013020526617765427, -0.026077555492520332, 0.03315361961722374, 0.022558728232979774, -0.004628043621778488, 0.007907677441835403, -0.06111788749694824, 0.03530124947428703, -0.02364731766283512, -0.06397879123687744, -0.02366814576089382, 0.025216659530997276, -0.01840304769575596, 0.012234026566147804, -0.04613214731216431, 0.010995469987392426, -0.018284577876329422, -0.008077689446508884, -0.0221469197422266, -0.02480195462703705, 0.03840361908078194, 0.015563147142529488, 0.04391646012663841, 0.03827064484357834, -0.046294793486595154, 0.013936882838606834, -0.004898338112980127, 0.007274611387401819, -0.0007403779309242964, 0.00010150121670449153, -0.002850281773135066, -0.00327593507245183, 0.016261955723166466, -0.01612115278840065, -0.05490375682711601, -0.0397079661488533, 0.018436482176184654, -0.009802780114114285, 0.005853147711604834, 0.005678489804267883, 0.035906776785850525, 0.02970205992460251, -0.008763991296291351, -0.01568857580423355, -0.003250567242503166, 0.046692006289958954, -0.02384444884955883, -0.06185907870531082, 0.02956787683069706, -0.0015352434711530805, 0.020436476916074753, 0.008119127713143826, 0.026177117601037025, 0.016642523929476738, -0.005309047177433968, 0.0350436270236969, -0.01299288310110569, 0.029317796230316162, -0.04164094850420952, -0.012262248434126377, -0.007567483000457287, 0.06695163995027542, -0.016805754974484444, -0.0439421571791172, -0.005035321693867445, 0.015507263131439686, 0.0067342412658035755, 0.008072981610894203, 0.001163239125162363, 0.02778489701449871, -0.03180396184325218, 0.042519353330135345, 0.0028653922490775585, 0.03844523802399635, 0.002739295130595565, 0.006205333862453699, -0.023154692724347115, 0.022801944985985756 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Fine-Tuning Warm-Started Encoder-Decoder Models In this section, we will show how one can make use of the Seq2SeqTrainer to fine-tune a warm-started encoder-decoder model. Let\'s first import the Seq2SeqTrainer and its training arguments Seq2SeqTrainingArguments. python from transformers import Seq2SeqTrainer, Seq2SeqTrainingArguments In addition, we need a couple of python packages to make the Seq2SeqTrainer work. python !pip install git-python==1.0.3 !pip install rouge_score !pip install sacrebleu The Seq2SeqTrainer extends 🤗Transformer\'s Trainer for encoder-decoder models. In short, it allows using the generate(...) function during evaluation, which is necessary to validate the performance of encoder-decoder models on most sequence-to-sequence tasks, such as summarization. For more information on the Trainer, one should read through this short tutorial. Let\'s begin by configuring the Seq2SeqTrainingArguments. The argument predict_with_generate should be set to True, so that the Seq2SeqTrainer runs the generate(...) on the validation data and passes the generated output as predictions to the compute_metric(...) function which we will define later. The additional arguments are derived from TrainingArguments and can be read upon here. For a complete training run, one should change those arguments as needed. Good default values are commented out below. For more information on the Seq2SeqTrainer, the reader is advised to take a look at the code. python training_args = Seq2SeqTrainingArguments( predict_with_generate=True, evaluation_strategy="steps", per_device_train_batch_size=batch_size, per_device_eval_batch_size=batch_size, fp16=True, output_dir="./", logging_steps=2, save_steps=10, eval_steps=4, # logging_steps=1000, # save_steps=500, # eval_steps=7500, # warmup_steps=2000, # save_total_limit=3, ) Also, we need to define a function to correctly compute the ROUGE score during validation. Since we activated predict_with_generate, the compute_metrics(...) function expects predictions that were obtained using the generate(...) function. Like most summarization tasks, CNN/Dailymail is typically evaluated using the ROUGE score. Let\'s first load the ROUGE metric using the 🤗datasets library. python rouge = datasets.load_metric("rouge") Next, we will define the compute_metrics(...) function. The rouge metric computes the score from two lists of strings. Thus we decode both the predictions and labels - making sure that -100 is correctly replaced by the pad_token_id and remove all special characters by setting skip_special_tokens=True. python def compute_metrics(pred): labels_ids = pred.label_ids pred_ids = pred.predictions pred_str = tokenizer.batch_decode(pred_ids, skip_special_tokens=True) labels_ids[labels_ids == -100] = tokenizer.pad_token_id label_str = tokenizer.batch_decode(labels_ids, skip_special_tokens=True) rouge_output = rouge.compute(predictions=pred_str, references=label_str, rouge_types=["rouge2"])["rouge2"].mid return { "rouge2_precision": round(rouge_output.precision, 4), "rouge2_recall": round(rouge_output.recall, 4), "rouge2_fmeasure": round(rouge_output.fmeasure, 4), } Great, now we can pass all arguments to the Seq2SeqTrainer and start finetuning. Executing the following cell will take ca. 10 minutes ☕. Finetuning BERT2BERT on the complete CNN/Dailymail training data takes ca. model takes ca. 8h on a single TITAN RTX GPU. python # instantiate trainer trainer = Seq2SeqTrainer( model=bert2bert, tokenizer=tokenizer, args=training_args, compute_metrics=compute_metrics, train_dataset=train_data, eval_dataset=val_data, ) trainer.train() Awesome, we should now be fully equipped to finetune a warm-started encoder-decoder model. To check the result of our fine-tuning let\'s take a look at the saved checkpoints. python !ls bash OUTPUT: ------- bert2bert checkpoint-20 runs seq2seq_trainer.py checkpoint-10 __pycache__ sample_data seq2seq_training_args.py Finally, we can load the checkpoint as usual via the EncoderDecoderModel.from_pretrained(...) method. python dummy_bert2bert = EncoderDecoderModel.from_pretrained("./checkpoint-20")
[ 0.04542194679379463, 0.0017988369800150394, 0.039684902876615524, -0.021362630650401115, 0.025605566799640656, 0.061808593571186066, 0.03365558385848999, 0.019182251766324043, -0.034413162618875504, -0.020520010963082314, -0.049586981534957886, 0.06814602762460709, -0.013918020762503147, 0.011982431635260582, 0.006771680433303118, -0.046243514865636826, 0.014239232055842876, -0.038458406925201416, -0.011503107845783234, 0.016210706904530525, 0.027292339131236076, -0.06289957463741302, 0.014437948353588581, -0.001483286265283823, 0.02759028784930706, -0.04473094642162323, 0.011206441558897495, -0.0034808178897947073, -0.06498546153306961, -0.004097545053809881, -0.10033590346574783, 0.01073240116238594, -0.011140738613903522, -0.04936257377266884, -0.004538442473858595, 0.046215225011110306, -0.1047382801771164, 0.04909689351916313, 0.060220494866371155, -0.020829932764172554, -0.0035874352324754, -0.028053058311343193, 0.01711639016866684, 0.013596839271485806, 0.02168850600719452, -0.03153703734278679, -0.13913846015930176, -0.013752574101090431, 0.003433713922277093, -0.09193318337202072, -0.020691148936748505, 0.07949849218130112, 0.04676379635930061, -0.019594192504882812, 0.027733372524380684, -0.029519254341721535, -0.0018693882739171386, -0.013589751906692982, 0.01821204274892807, 0.0413907952606678, 0.04197784140706062, -0.0015028398483991623, -0.011122684925794601, 0.04028220474720001, 0.020758215337991714, -0.0070700570940971375, -0.057919468730688095, 0.05509401485323906, -0.005328678991645575, -0.044770464301109314, -0.035220928490161896, -0.07659339904785156, 0.027784813195466995, 0.0024663840886205435, -0.019615063443779945, -0.1056184247136116, 0.016949918121099472, -0.0026382673531770706, 0.03953627496957779, 0.06393276900053024, -0.04141370207071304, 0.07158512622117996, -0.02692411281168461, 0.02216540090739727, 0.03810593858361244, 0.06657931208610535, 0.032739460468292236, -0.05092429369688034, -0.04118499159812927, 0.04904686659574509, 0.0006033508689142764, -0.13251054286956787, 0.029722096398472786, -0.015432894229888916, 0.001834335969761014, 0.037281036376953125, -0.008212469518184662, 0.0011331125861033797, -0.03234712779521942, 0.0012081156019121408, -0.01431206427514553, -0.06722140312194824, 0.02682204730808735, -0.05319611728191376, -0.005260576959699392, 0.03863760828971863, -0.03862498328089714, -0.058011744171381, -0.049438897520303726, 0.016420984640717506, 0.03017573617398739, -0.008409521542489529, -0.08104139566421509, 0.06476078927516937, -0.08707784116268158, 0.021249981597065926, 0.016518479213118553, -0.05196583643555641, -0.04912335425615311, -0.0033074875827878714, -0.005155721679329872, 0.09450631588697433, 0.05318167433142662, -0.03294144198298454, -0.05716296285390854, 0.07050636410713196, 0.022461343556642532, 0.018250562250614166, 0.04277780279517174, 0.024347595870494843, 0.015196860767900944, 0.014211175963282585, 0.014575229957699776, 0.02645493857562542, 0.0076116593554615974, -0.03988458216190338, 0.006845733150839806, -0.031201284378767014, -0.02567155286669731, 0.06317952275276184, -0.07343186438083649, 0.10880173742771149, 0.02962317131459713, -0.02513292245566845, -0.014836393296718597, 0.01122060976922512, -0.06040935590863228, 0.07164212316274643, 0.06373158097267151, 0.05555551499128342, -0.05043938755989075, 0.09359011054039001, -0.0664919838309288, -0.07985566556453705, 0.030754858627915382, 0.059293389320373535, -0.073689304292202, -0.009931410662829876, -0.07840783149003983, 0.006805201526731253, -0.0013346681371331215, 0.042063284665346146, -0.03804789111018181, 0.010588818229734898, 0.02535880357027054, -0.05166462063789368, 0.04280412569642067, 0.04148660600185394, 0.03973974287509918, 0.024793092161417007, 0.03333849832415581, 0.04086431860923767, 0.07421740889549255, 0.007101654540747404, -0.00013241710257716477, 0.04348505288362503, -0.012945973314344883, 0.11035178601741791, 0.012226921506226063, -0.059738364070653915, -0.04922986030578613, 0.07270030677318573, -0.05181479826569557, 0.09228893369436264, 0.0504394955933094, -0.08158529549837112, 0.011675050482153893, -0.03972296789288521, -0.060750946402549744, 0.05154323950409889, -0.03245840594172478, -0.004125052131712437, 0.0975373387336731, -0.0314018651843071, 0.012578160502016544, -0.05090423673391342, -0.003772368421778083, 0.0644460991024971, 0.026930617168545723, 0.03840986266732216, 0.047667067497968674, 0.02840949036180973, 0.10136396437883377, 0.00864240899682045, -0.02831772156059742, 0.021168196573853493, 0.01240110769867897, -0.08651160448789597, 0.09521680325269699, 0.012973661534488201, 0.043753840029239655, -0.09824862331151962, 0.014593865722417831, -0.1027931272983551, 0.058766014873981476, -0.022708730772137642, 0.012661605142056942, -0.04294781759381294, 0.015137365087866783, 0.01626451313495636, 0.11507521569728851, 0.019130483269691467, 0.011653904803097248, -0.0460645854473114, -0.024591114372015, 0.0004084323882125318, 0.06366131454706192, 0.01806163229048252, 0.053925126791000366, -0.06223269924521446, -0.03592837601900101, -0.044809821993112564, -0.08909328281879425, 0.016062214970588684, -0.028505906462669373, -0.0419466458261013, -0.02477389946579933, 0.0212952122092247, 0.00842502061277628, -0.061264123767614365, 0.04276663064956665, 0.025460049510002136, -0.03791772946715355, -0.0013855062425136566, -0.055564913898706436, 0.01315052155405283, 0.0716262087225914, -0.017889801412820816, -0.020037047564983368, -0.032175324857234955, -0.04153095558285713, 0.06978043913841248, 0.027708571404218674, -0.07331649959087372, 0.03513235226273537, 0.04837045446038246, -0.04052235931158066, -0.00077738770050928, 0.0010850562248378992, 0.017123006284236908, 0.012594110332429409, -0.004578202031552792, -0.031192928552627563, -0.004484940320253372, 0.014351209625601768, -0.03115936554968357, -0.018643463030457497, 0.008411049842834473, 0.00895615853369236, -0.007221809588372707, 0.026072990149259567, -0.016839582473039627, 0.03830111026763916, 0.0023516742512583733, 0.04045743867754936, 0.020224129781126976, 0.06480835378170013, -0.03939538076519966, -0.029902944341301918, 0.000021645761080435477, 0.026513295248150826, -0.01599392667412758, -0.0048499563708901405, 0.019185714423656464, -0.019156543537974358, 0.019920142367482185, -0.021009936928749084, -0.007264625281095505, -0.007149340584874153, 0.033726174384355545, 0.006067190319299698, 0.026354877278208733, 0.0035308764781802893, -0.007795107550919056, -0.010883492417633533, 0.043504711240530014, -0.007886060513556004, -0.062378980219364166, 0.018059801310300827, -0.016330895945429802, -0.0452512763440609, 0.006756483111530542, 0.01815502718091011, -0.00797385536134243, -0.052460718899965286, 0.00865945965051651, 0.02338777296245098, 0.006591965444386005, -0.09455718845129013, 0.0025629184674471617, 0.004045787733048201, -0.014123467728495598, -0.024816013872623444, -0.008442804217338562, 0.048681389540433884, -0.0012056726263836026, -0.021054692566394806, 0.016973568126559258, -0.022903665900230408, 0.00897197425365448, -0.0016133629251271486, 0.015920288860797882, -0.031621962785720825, -0.01900630071759224, -0.04253494367003441, 0.00033756878110580146, 0.020432114601135254, 0.021321967244148254, 0.010929756797850132, 0.01057587843388319, 0.016688697040081024, -0.0032223842572420835, -0.010081135667860508, 0.02107911743223667, 0.03376679867506027, 0.021488681435585022, -0.04778524488210678, -0.027149243280291557, -0.010437344200909138, -0.009628868661820889, -0.0007340910960920155, 0.016748329624533653, 0.005335067864507437, -0.038626737892627716, 0.019651107490062714, -0.03358851745724678, 0.02448485605418682, 0.012877736240625381, -0.011232592165470123, -0.00725083751603961, 0.009763021022081375, 0.010075705125927925, 0.019909529015421867, -0.02969691902399063, 0.0032008637208491564, -0.028014348819851875, 0.02036375366151333, -0.0037965753581374884, -0.023227903991937637, 0.01691647619009018, -0.020771151408553123, 0.0385504849255085, -0.01565035805106163, 0.028400853276252747, 0.01087450236082077, 0.05732908844947815, 0.04572412371635437, -0.009679506532847881, -0.0609864667057991, 0.012143696658313274, -0.009440802969038486, -0.019315605983138084, -0.017162678763270378, 0.022796757519245148, 0.01649775356054306, 0.03179057687520981, -0.013496539555490017, 0.03302053362131119, -0.01898571476340294, -0.018833773210644722, 0.026774846017360687, 0.011284424923360348, -0.030454281717538834, 0.01731579378247261, -0.0386071614921093, -0.0035937565844506025, 0.05486522987484932, 0.049217041581869125, -0.021936502307653427, -0.03851913660764694, -0.03646491840481758, -0.039273206144571304, 0.027472537010908127, 0.014090761542320251, 0.013652434572577477, -0.0295687485486269, 0.04354795813560486, -0.007037431001663208, 0.0027916468679904938, -0.00816227588802576, -0.012462157756090164, -0.013934902846813202, -0.00950632430613041, -0.02889595553278923, 0.003644434502348304, 0.027788449078798294, 0.026664406061172485, 0.012230472639203072, 0.004157377872616053, -0.08550011366605759, -0.00855268631130457, 0.002608872251585126, -0.01622096076607704, 0.0008599628345109522, -0.039232037961483, -0.05306081846356392, -0.010058197192847729, -0.009308678098022938, 0.01975756697356701, -0.03162737935781479, 0.012726389802992344, -0.01199520006775856, 0.01615033484995365, 0.06349492073059082, 0.02358284778892994, -0.053338125348091125, 0.0397900752723217, 0.018639342859387398, -0.012585772201418877, 0.01709720492362976, 0.002468039281666279, -0.02497721090912819, 0.04527757316827774, -0.0036436528898775578, 0.03975163772702217, 0.036859262734651566, -0.005966078955680132, -0.014187668450176716, -0.015628458932042122, 0.025353427976369858, 0.011402182281017303, -0.05291615426540375, 0.00701105734333396, 0.005677219945937395, -0.013496658764779568, -0.0008923315326683223, 0.012212966568768024, -0.01575695537030697, 0.0007406450458802283, 0.021988246589899063, 0.035084642469882965, 0.007688817568123341, 0.03633740544319153, 0.015869541093707085, -0.024077842012047768, 0.002749331295490265, -0.006832695100456476, -0.012864954769611359, 0.03670955449342728, -0.004728136118501425, -0.022293033078312874, -0.001399446278810501, 0.027499333024024963, -0.03606196865439415, -0.030443036928772926, 0.03968459367752075, 0.013070099987089634, 0.035980887711048126, 0.012973986566066742, -0.002184069948270917, -0.024309450760483742, 0.00545215979218483, -0.009525833651423454, 0.018261335790157318, -0.049189381301403046, -0.02076190523803234, -0.008000098168849945, -0.012879196554422379, -0.020409373566508293, -0.016910094767808914, 0.010776192881166935, -0.033065080642700195, -0.0014925863360986114, -0.0018930572550743818, -0.004683130886405706, 0.017765328288078308, -0.0229716245085001, 0.011857814155519009, 0.012525388039648533, -0.005099358968436718, 0.009770110249519348, 0.0036002134438604116, 0.0003076739958487451, 0.01865035481750965, 0.04604646563529968, 0.02108144946396351, 0.03939105197787285, -0.0025042921770364046, 0.012552820146083832, -0.04317707568407059, 0.02177305705845356, -0.017658669501543045, -0.05050864443182945, 0.012888748198747635, -0.00457157613709569, 0.012176882475614548, -0.047329600900411606, 0.005711977370083332, 0.05097505822777748, 0.02089592069387436, -0.009508299641311169, -0.05865083634853363, 0.045178864151239395, -0.04521917924284935, -0.0380941778421402, -0.001230835565365851, 0.03397887200117111, -0.062303971499204636, 0.013827349990606308, -0.009855326265096664, -0.0128717590123415, -0.00443902937695384, -0.004807375371456146, -0.013006871566176414, -0.03064519539475441, 0.054912030696868896, 0.04731021076440811, 0.02544468827545643, -0.045794375240802765, 0.004707131069153547, -0.030295103788375854, -0.012691433541476727, -0.013974863104522228, -0.04762402921915054, 0.02123361825942993, -0.008810890838503838, 0.0023072129115462303, 0.025162074714899063, 0.04135292023420334, 0.0015052398666739464, 0.009544134140014648, 0.03259570524096489, 0.020212354138493538, -0.023861141875386238, -0.03437979519367218, 0.020253226161003113, 0.013640440069139004, -0.006552748382091522, -0.028284460306167603, -0.022636014968156815, 0.015807272866368294, 0.001877675182186067, -0.0407637283205986, 0.04156465083360672, 0.03675420209765434, -0.028256410732865334, 0.022048279643058777, 0.013454453088343143, 0.054736390709877014, 0.02391892485320568, 0.02336782030761242, 0.019652770832180977, 0.020833652466535568, 0.0014121124986559153, 0.019976478070020676, -0.022084657102823257, 0.03365929424762726, -0.0001984011469176039, 0.01480448804795742, -0.06479018181562424, 0.04626205191016197, 0.054668039083480835, 0.003349853679537773, 0.05413910746574402, 0.007991837337613106, -0.051526714116334915, 0.02904866449534893, 0.04372362419962883, 0.007887572981417179, 0.011677292175590992, 0.01488982979208231, 0.03860825300216675, 0.01274926494807005, -0.007478323299437761, 0.010574866086244583, 0.0744035392999649, -0.026576638221740723, 0.010780470445752144, 0.034089379012584686, -0.0005159597494639456, -0.005673488136380911, 0.00804887991398573, -0.01189951691776514, -0.011744009330868721, 0.06324458867311478, 0.01603354886174202, -0.01475626602768898, 0.05307406932115555, 0.0337747223675251, -0.020789697766304016, -0.047716330736875534, -0.031861986964941025, 0.008642452768981457, -0.002589188516139984, 0.019570976495742798, -0.00687446491792798, 0.04205162823200226, -0.011745456606149673, 0.0809297114610672, 0.05135970190167427, 0.003781309351325035, -0.014203772880136967, 0.0556144081056118, 0.06347731500864029, 0.0179135762155056, -0.001454905141144991, 0.00011235903366468847, -0.013288849964737892, -0.044724542647600174, 0.0389985516667366, 0.006279999855905771, 0.03009171038866043, 0.017291169613599777, -0.02781437337398529, 0.0004617548838723451, -0.02450217679142952, -0.02108459547162056, 0.024106724187731743, 0.016291143372654915, -0.0007678138790652156, -0.011636153794825077, 0.03664643317461014, -0.04834511876106262, -0.00581860076636076, -0.019923707470297813, -0.015354973264038563, -0.030762644484639168, 0.011564034037292004, -0.01972375437617302, 0.059043727815151215, -0.03443433716893196, -0.028669308871030807, -0.009860067628324032, 0.016717497259378433, -0.03252183645963669, 0.06623808294534683, -0.021607503294944763, -0.052336741238832474, -0.06547830998897552, -0.016827315092086792, -0.003470322582870722, 0.05750296637415886, -0.04186993092298508, -0.04016048088669777, 0.04093489795923233, -0.02802613377571106, -0.023105550557374954, 0.015841476619243622, 0.01392950676381588, 0.005495200399309397, -0.03310137242078781, 0.011099235154688358, 0.016196513548493385, -0.054125770926475525, 0.07896397262811661, -0.040788475424051285, 0.013989104889333248, -0.004357939586043358, 0.05566021054983139, 0.015122507698833942, 0.014869979582726955, -0.031300920993089676, -0.0029059387743473053, -0.01727626658976078, -0.03237607330083847, 0.006924409884959459, 0.04522264003753662, -0.0014113311190158129, 0.03647932410240173, 0.009625876322388649, -0.025182224810123444, -0.01811663806438446, 0.011910533532500267, 0.004472949076443911, 0.03792772814631462, -0.04553122818470001, -0.017795443534851074, -0.015456457622349262, 0.043982263654470444, 0.007516092155128717, 0.03158940002322197, 0.029200561344623566, 0.014157411642372608, 0.06699749082326889, -0.02957795560359955, -0.03699168935418129, -0.032274018973112106, 0.006844280753284693, -0.059687692672014236, -0.059079915285110474, -0.01296937745064497, 0.02683229185640812, -0.0550612211227417, 0.029452882707118988, -0.023808153346180916, -0.0009007490007206798, -0.07490555942058563, 0.0024792251642793417, -0.0038230144418776035, 0.06127696484327316, 0.03307522460818291, 0.031898386776447296, 0.029077431187033653, 0.020970076322555542, -0.029097793623805046, 0.009920842945575714, -0.03426371142268181, 0.018902001902461052, 0.06055136397480965, 0.018866807222366333, -0.03355604410171509, -0.006318230181932449, 0.03867639601230621, 0.03705395758152008, -0.02853998914361, -0.04023908078670502, -0.002103580627590418, -0.05139029398560524, -0.013262825086712837, 0.0008259791065938771, 0.0361245833337307, 0.004215951543301344, 0.039100851863622665, 0.009559253230690956, -0.03692691773176193, -0.0005135120009072125, -0.007639145478606224, -0.01722707971930504, -0.02168867364525795, -0.016858749091625214, -0.014498856849968433, -0.0027214516885578632, -0.0017500468529760838, 0.024416452273726463, 0.008919041603803635, -0.030780984088778496, -0.022668469697237015, 0.00426893774420023, -0.0029571079649031162, -0.020751435309648514, 0.028126347810029984, 0.04688452184200287, -0.0027333509642630816, -0.05471731349825859, 0.04206068441271782, 0.009365618228912354, -0.03551139310002327, 0.012218888849020004, 0.02448234148323536, -0.02012345753610134, -0.0020248705986887217, 0.01736346445977688, -0.011621051467955112, 0.040842026472091675, 0.02419019676744938, -0.04234275221824646, -0.0014210778754204512, 0.0071289450861513615 ]
Leveraging Pre-trained Language Model Checkpoints for Encoder-Decoder Models
patrickvonplaten
November 09, 2020
warm-starting-encoder-decoder
guide, nlp
https://huggingface.co/blog/warm-starting-encoder-decoder
Conclusion Alright, let\'s draw a conclusion and try to derive some practical tips. - We have observed on all tasks that a warm-started encoder-part gives a significant performance boost compared to encoder-decoder models having a randomly initialized encoder. On the other hand, warm-starting the decoder seems to be less important, with BERT2BERT being on par with BERT2Rnd on most tasks. An intuitive reason would be that since a BERT- or RoBERTa-initialized encoder part has none of its weight parameters randomly initialized, the encoder can fully exploit the acquired knowledge of BERT\'s or RoBERTa\'s pre-trained checkpoints, respectively. In contrast, the warm-started decoder always has parts of its weight parameters randomly initialized which possibly makes it much harder to effectively leverage the knowledge acquired by the checkpoint used to initialize the decoder. - Next, we noticed that it is often beneficial to share encoder and decoder weights, especially if the target distribution is similar to the input distribution (e.g. BBC XSum). However, for datasets whose target data distribution differs more significantly from the input data distribution and for which model capacity \({}^2\) is known to play an important role, e.g. WMT14, encoder-decoder weight sharing seems to be disadvantageous. - Finally, we have seen that it is very important that the vocabulary of the pre-trained \"stand-alone\" checkpoints fit the vocabulary required to solve the sequence-to-sequence task. E.g. a warm-started BERT2GPT2 encoder-decoder will perform poorly on En \(\to\) De MT because GPT2 was pre-trained on English whereas the target language is German. The overall poor performance of the BERT2GPT2, Rnd2GPT2, and RoBERTa2GPT2 compared to BERT2BERT, BERTShared, and RoBERTaShared suggests that it is more effective to have a shared vocabulary. Also, it shows that initializing the decoder part with a pre-trained GPT2 checkpoint is not more effective than initializing it with a pre-trained BERT checkpoint besides GPT2 being more similar to the decoder in its architecture. For each of the above tasks, the most performant models were ported to 🤗Transformers and can be accessed here: - RoBERTaShared (large) - Wikisplit: google/roberta2roberta_L-24_wikisplit. - RoBERTaShared (large) - Discofuse: google/roberta2roberta_L-24_discofuse. - BERT2BERT (large) - WMT en \(\to\) de: google/bert2bert_L-24_wmt_en_de. - BERT2BERT (large) - WMT de \(\to\) en: google/bert2bert_L-24_wmt_de_en. - RoBERTaShared (large) - CNN/Dailymail: google/roberta2roberta_L-24_cnn_daily_mail. - RoBERTaShared (large) - BBC XSum: google/roberta2roberta_L-24_bbc. - RoBERTaShared (large) - Gigaword: google/roberta2roberta_L-24_gigaword. ------------------------------------------------------------------------ \({}^1\) To retrieve BLEU-4 scores, a script from the Tensorflow Official Transformer implementation https://github.com/tensorflow/models/tree master/official/nlp/transformer was used. Note that, differently from the tensor2tensor/utils/ get_ende_bleu.sh used by Vaswani et al. (2017), this script does not split noun compounds, but utf-8 quotes were normalized to ascii quotes after having noted that the pre-processed training set contains only ascii quotes. \({}^2\) Model capacity is an informal definition of how good the model is at modeling complex patterns. It is also sometimes defined as the ability of a model to learn from more and more data. Model capacity is broadly measured by the number of trainable parameters - the more parameters, the higher the model capacity. # Warm-starting encoder-decoder models with 🤗Transformers (Practice) We have explained the theory of warm-starting encoder-decoder models, analyzed empirical results on multiple datasets, and have derived practical conclusions. Let\'s now walk through a complete code example showcasing how a BERT2BERT model can be warm-started and consequently fine-tuned on the CNN/Dailymail summarization task. We will be leveraging the 🤗datasets and 🤗Transformers libraries. In addition, the following list provides a condensed version of this and other notebooks on warm-starting other combinations of encoder-decoder models. - for BERT2BERT on CNN/Dailymail (a condensed version of this notebook), click here. - for RoBERTaShare on BBC XSum, click here. - for BERT2Rnd on WMT14 En \(\to\) De, click here. - for RoBERTa2GPT2 on DiscoFuse, click here. Note: This notebook only uses a few training, validation, and test data samples for demonstration purposes. To fine-tune an encoder-decoder model on the full training data, the user should change the training and data preprocessing parameters accordingly as highlighted by the comments.
[ 0.02457200177013874, 0.005472536198794842, 0.03730391710996628, 0.06595989316701889, -0.005695689935237169, 0.07161121815443039, -0.0014671939425170422, -0.002772468840703368, -0.05530761927366257, -0.060333363711833954, -0.05273732170462608, 0.04904511943459511, 0.023812251165509224, 0.041283439844846725, -0.018141206353902817, -0.030998066067695618, 0.06913380324840546, -0.09424393624067307, 0.012293179519474506, 0.021257953718304634, 0.02163200080394745, -0.05077168717980385, 0.030194146558642387, -0.028476040810346603, 0.06942819058895111, -0.05482886731624603, -0.015338670462369919, 0.008644616231322289, -0.020417574793100357, 0.0034552153665572405, -0.14719708263874054, 0.006978351157158613, 0.05232550948858261, -0.025054030120372772, 0.021422434598207474, 0.02476891689002514, -0.06778943538665771, 0.05962541326880455, 0.031137993559241295, -0.049906738102436066, -0.01513681560754776, -0.022479664534330368, -0.01172318309545517, -0.01247294433414936, -0.08740706741809845, -0.046713024377822876, -0.14521321654319763, 0.0834260806441307, 0.030989842489361763, -0.07208233326673508, -0.07873154431581497, 0.048875097185373306, -0.022162167355418205, 0.0958847776055336, -0.0008144904859364033, -0.007943401113152504, 0.003039324190467596, -0.08829371631145477, 0.05129798501729965, -0.019668255001306534, 0.039464566856622696, 0.000010003838724514935, -0.0012940445449203253, 0.009631974622607231, 0.012753807008266449, 0.032487355172634125, -0.05658762902021408, -0.0012263152748346329, -0.007843001745641232, -0.0259627066552639, -0.04915435612201691, -0.06344274431467056, -0.035057783126831055, 0.010125403292477131, 0.023502200841903687, -0.022875934839248657, 0.0506490133702755, -0.04090297222137451, 0.0014442682731896639, -0.00911706406623125, -0.02885768935084343, 0.0825762003660202, -0.03414657711982727, -0.011041613295674324, 0.08371379971504211, 0.005372779909521341, 0.09298361092805862, -0.05802735686302185, -0.08507303148508072, 0.03450764715671539, -0.0501641221344471, -0.1074262335896492, 0.02976584993302822, 0.000787171593401581, 0.07500188797712326, -0.021255092695355415, -0.02238353155553341, 0.027013204991817474, -0.005492362659424543, -0.022450145334005356, -0.01697397418320179, -0.08865906298160553, 0.018375199288129807, -0.04206179454922676, -0.04974504932761192, 0.04150329902768135, -0.045222196727991104, -0.1058134213089943, -0.009928750805556774, 0.015905030071735382, 0.052786558866500854, -0.005887649487704039, -0.030767014250159264, 0.007243948057293892, -0.09169456362724304, 0.005144962575286627, -0.018094731494784355, -0.04862438887357712, 0.008844908326864243, 0.030923685058951378, -0.0030007041059434414, 0.04494602605700493, -0.0004035001329611987, -0.04172053560614586, -0.050042055547237396, 0.038596585392951965, 0.009524079971015453, 0.02709609642624855, 0.025715483352541924, 0.00846956018358469, 0.08921626955270767, 0.03652501106262207, 0.004408048000186682, 0.01827159710228443, 0.0013922657817602158, -0.016115453094244003, -0.013434415683150291, -0.04075486958026886, -0.05115780979394913, -0.012053697369992733, -0.1315341740846634, 0.0782540962100029, -0.011617407202720642, -0.035018254071474075, -0.025301752611994743, 0.0683584064245224, -0.09626224637031555, 0.01659453846514225, 0.044540997594594955, 0.030015327036380768, -0.06051089987158775, 0.038724612444639206, -0.06283357739448547, -0.0753125473856926, 0.03927861154079437, 0.11078207194805145, -0.04272947460412979, -0.04844182729721069, -0.019170919433236122, 0.00478158937767148, -0.02695664018392563, 0.00887087918817997, -0.0037889452651143074, -0.019145281985402107, -0.005134679842740297, -0.08344579488039017, -0.004515401087701321, 0.03177250176668167, 0.006752156186848879, 0.06564301252365112, -0.002426900900900364, 0.017005259171128273, 0.09400586783885956, -0.0037358731497079134, -0.019009904935956, 0.09628825634717941, 0.002734765876084566, 0.06095638871192932, 0.017637446522712708, -0.00896781962364912, -0.03507990762591362, 0.04168933257460594, -0.003553353250026703, 0.051494333893060684, 0.05483606830239296, -0.05032780393958092, -0.008628817275166512, -0.07985479384660721, -0.053825605660676956, 0.053825847804546356, -0.017862169072031975, 0.011581223458051682, 0.04963422194123268, -0.017377912998199463, -0.02348279394209385, -0.06304709613323212, -0.005540814250707626, 0.11143332719802856, 0.03481113165616989, 0.031135067343711853, 0.10910098254680634, 0.020219845697283745, 0.049573905766010284, 0.031168831512331963, -0.03832245618104935, -0.02644963189959526, 0.024890154600143433, -0.034980908036231995, 0.04915057122707367, 0.014550524763762951, 0.03173393756151199, -0.08675362169742584, -0.025663694366812706, -0.06179330125451088, 0.039217930287122726, -0.01909235678613186, 0.03401617705821991, -0.0099409818649292, 0.03471861034631729, -0.010742492973804474, 0.11162730306386948, -0.08442070335149765, 0.02938692644238472, 0.006842440459877253, -0.01873883046209812, 0.05156043916940689, 0.06074470281600952, 0.013595802709460258, 0.1193159893155098, -0.05983772128820419, -0.03747965022921562, -0.07267643511295319, 0.03487318381667137, 0.034848012030124664, 0.002511897124350071, 0.014466061256825924, -0.02213149145245552, -0.030030447989702225, -0.013674699701368809, -0.05892908573150635, 0.001565507729537785, 0.028450794517993927, -0.001398376771248877, 0.041794851422309875, -0.02614741213619709, 0.004442877601832151, 0.02899359166622162, -0.021757597103714943, -0.023878151550889015, -0.040439702570438385, -0.04393769055604935, 0.03223249316215515, 0.0032462517265230417, -0.05831392481923103, 0.019722310826182365, 0.0015630205161869526, -0.02394085004925728, -0.007767428644001484, 0.0044381520710885525, 0.02256283350288868, 0.03108910843729973, -0.052711352705955505, -0.05895456671714783, -0.014648460783064365, 0.02161877229809761, -0.035518109798431396, -0.055806320160627365, -0.014211793430149555, 0.0028996572364121675, -0.0014252292457967997, 0.04801372438669205, -0.04435918107628822, 0.041430626064538956, 0.04191222041845322, 0.013733746483922005, -0.0009746067225933075, 0.005272396840155125, -0.05114346742630005, -0.04891202226281166, -0.01418252568691969, 0.005961781833320856, -0.03737303987145424, 0.006587504409253597, 0.030473826453089714, -0.05289848521351814, 0.026208845898509026, -0.00917015504091978, 0.01829899102449417, -0.025195345282554626, 0.04654233157634735, 0.02321247197687626, 0.029933491721749306, -0.041858166456222534, -0.008074896410107613, 0.008577167987823486, 0.011096381582319736, -0.0155614810064435, -0.027024971321225166, 0.0003097423177678138, 0.007270257920026779, -0.03930758684873581, 0.003752031596377492, 0.006792792584747076, -0.02136404439806938, -0.04447654262185097, 0.015644026920199394, 0.014195485971868038, 0.029849596321582794, -0.09527811408042908, -0.026596996933221817, 0.05002182722091675, 0.03153330460190773, -0.020230621099472046, 0.008326777257025242, 0.06943375617265701, -0.03355695679783821, -0.046010978519916534, 0.019937369972467422, 0.013074830174446106, -0.001780149876140058, 0.003511555725708604, 0.015209581702947617, -0.02125803381204605, -0.013616545125842094, -0.02367076650261879, -0.006484479643404484, 0.04365021735429764, 0.002313931006938219, 0.04185201972723007, -0.0262850821018219, -0.012930835597217083, 0.008191283792257309, -0.04494689032435417, -0.02761450782418251, 0.007212343625724316, 0.027195127680897713, -0.0012267200509086251, -0.019091948866844177, -0.018678266555070877, -0.017527081072330475, 0.01789364404976368, 0.009369960054755211, -0.013592103496193886, 0.0077049932442605495, 0.02611408941447735, 0.05459579452872276, 0.013044023886322975, 0.033712148666381836, 0.00021804501011501998, -0.008043983951210976, 0.017797786742448807, 0.00431022047996521, 0.01178576610982418, -0.026771364733576775, 0.012864349409937859, -0.021923143416643143, 0.038255222141742706, -0.010351059027016163, -0.005829541943967342, 0.01292671263217926, 0.0024331407621502876, 0.021967994049191475, 0.004933306016027927, 0.01761031709611416, -0.00677156588062644, 0.029694583266973495, -0.0019897352904081345, 0.002804923104122281, -0.02336038649082184, 0.017656467854976654, 0.02493397891521454, -0.03283905237913132, -0.03512647747993469, 0.037839002907276154, 0.019292078912258148, 0.009544300846755505, 0.015913620591163635, 0.038240235298871994, -0.01298502366989851, 0.029475217685103416, 0.03393075615167618, 0.0016682788264006376, 0.0027509278152137995, 0.019939662888646126, -0.01912602409720421, -0.024989299476146698, 0.060803476721048355, -0.011256813071668148, -0.011392579413950443, 0.0038222570437937975, -0.026922112330794334, -0.024917369708418846, -0.008839857764542103, 0.04379383102059364, 0.008118349127471447, 0.0015973038971424103, 0.026881955564022064, -0.004469930659979582, 0.027513355016708374, -0.016455845907330513, 0.02310158871114254, 0.006849044002592564, -0.012153140269219875, 0.0010822743643075228, 0.00584068289026618, 0.027313590049743652, 0.005357085727155209, -0.033448297530412674, 0.005413494072854519, -0.07052750885486603, 0.016424886882305145, 0.023461883887648582, -0.0015551481628790498, 0.042188264429569244, 0.001620829221792519, -0.02176956832408905, 0.03908222168684006, -0.00959611777216196, 0.015879783779382706, 0.01572759822010994, 0.0074744937010109425, 0.03759767487645149, 0.03921207785606384, 0.037466369569301605, 0.00009375860099680722, -0.0409126840531826, 0.0009617513278499246, 0.013944338075816631, -0.02185816690325737, 0.0051842923276126385, 0.016353895887732506, 0.025615252554416656, 0.04981660842895508, -0.010391511023044586, 0.020076069980859756, 0.0007974596810527146, -0.007411757484078407, -0.043173983693122864, -0.08141851425170898, -0.020818496122956276, 0.019188717007637024, -0.0711221769452095, 0.003123614238575101, 0.002377679105848074, -0.0015290103619918227, 0.02704194001853466, 0.03668634966015816, -0.04289189353585243, 0.027202583849430084, 0.013422380201518536, 0.045823127031326294, -0.03392474725842476, 0.06226692721247673, -0.001634274609386921, -0.013434448279440403, -0.012382613494992256, -0.023068377748131752, -0.022387806326150894, 0.021812710911035538, -0.015340869314968586, -0.05303599312901497, 0.034865256398916245, 0.030930915847420692, -0.048480529338121414, 0.007912842556834221, 0.03894162178039551, 0.040458787232637405, 0.0192786306142807, 0.007319457363337278, -0.00954845268279314, -0.04302957281470299, 0.002846013056114316, 0.002280500251799822, -0.018426844850182533, -0.004491063300520182, -0.002144235884770751, 0.030064476653933525, 0.024626923725008965, 0.012322381138801575, 0.008721113204956055, 0.015886539593338966, -0.009954710491001606, 0.042420584708452225, -0.0034602617379277945, -0.005727251525968313, 0.019248148426413536, 0.0197336096316576, 0.012405682355165482, 0.005381607450544834, 0.0010617633815854788, -0.022365793585777283, -0.012342550791800022, -0.005240433383733034, -0.002230640733614564, 0.05980581417679787, 0.056049805134534836, 0.03054070845246315, 0.01919856294989586, 0.012316497042775154, 0.01945304311811924, 0.04920613393187523, -0.013445738703012466, -0.0346251018345356, -0.02184283174574375, -0.017281820997595787, 0.009076902642846107, -0.018566882237792015, 0.022736845538020134, 0.017623664811253548, 0.05986015498638153, -0.005268746521323919, -0.02246353030204773, 0.020909665152430534, -0.00738364364951849, -0.0031847667414695024, -0.05899226292967796, 0.026677526533603668, -0.02572709135711193, 0.005618696566671133, -0.00007455129525624216, -0.005116754211485386, 0.011031866073608398, 0.004762584809213877, -0.03670823946595192, -0.03738320991396904, 0.0607011653482914, 0.07113879173994064, 0.03467449173331261, 0.0013893302530050278, 0.011774704791605473, -0.07550051063299179, -0.023649923503398895, -0.02163563296198845, -0.04896877706050873, -0.018268875777721405, 0.01408048439770937, -0.00121304951608181, 0.01789955608546734, 0.021431855857372284, -0.03965521603822708, 0.018799331039190292, 0.04396958276629448, -0.033561866730451584, -0.05623357743024826, 0.046324606984853745, 0.02113715559244156, 0.005876750685274601, 0.0031490700785070658, 0.007017831783741713, -0.015920056030154228, 0.03501824662089348, 0.011027210392057896, -0.04557894542813301, 0.030838996171951294, 0.04092475399374962, -0.004977546166628599, 0.030352313071489334, 0.020814845338463783, 0.03174027055501938, -0.011423150077462196, 0.01231845747679472, 0.019091038033366203, 0.028400685638189316, -0.023657161742448807, -0.02146717719733715, -0.006126657593995333, 0.0038829336408525705, 0.03569384291768074, 0.00940300989896059, -0.047110769897699356, 0.018689610064029694, 0.026020925492048264, -0.029539356008172035, 0.03425159305334091, 0.028627298772335052, -0.05375820770859718, 0.013163812458515167, -0.0024132439866662025, 0.006993924267590046, 0.009501947090029716, -0.019926995038986206, 0.0030542195308953524, 0.03483958542346954, 0.02135217934846878, 0.026807203888893127, 0.02463296428322792, -0.0009884326718747616, 0.018620334565639496, 0.04546003416180611, 0.006940985098481178, 0.05135251581668854, -0.0038921618834137917, -0.011161744594573975, -0.015220086090266705, 0.04441814869642258, 0.029552895575761795, 0.014923885464668274, 0.032294806092977524, -0.0007282072911038995, -0.024120790883898735, -0.015990301966667175, -0.01029377244412899, -0.008119026198983192, 0.01734994910657406, -0.01111319474875927, 0.0006696793134324253, 0.028167104348540306, -0.030037472024559975, 0.027110876515507698, 0.03748587518930435, 0.03206881135702133, -0.00784244667738676, 0.06158492714166641, 0.01840796135365963, 0.007392279338091612, 0.012455523945391178, 0.02030937746167183, 0.01986314170062542, -0.03871402144432068, 0.027697786688804626, 0.040144145488739014, 0.02813911624252796, 0.02833433821797371, -0.022287443280220032, 0.020609349012374878, -0.0005261281039565802, 0.026847977191209793, 0.03577134385704994, 0.03410835564136505, -0.03058094158768654, -0.016050809994339943, 0.05273061245679855, -0.047880616039037704, 0.030373400077223778, 0.015973394736647606, -0.004830959718674421, 0.016594531014561653, -0.005008221138268709, 0.027060316875576973, 0.06744617223739624, -0.024719614535570145, -0.033150892704725266, 0.0077370950020849705, 0.017960743978619576, -0.018500275909900665, 0.02918320521712303, -0.03473924472928047, -0.03837819769978523, -0.024985190480947495, -0.002042938955128193, -0.015905912965536118, 0.03665880113840103, -0.021365037187933922, -0.013627571985125542, 0.03485405445098877, -0.016466204077005386, -0.014482177793979645, -0.006236610468477011, 0.020323580130934715, -0.023615749552845955, -0.0111721595749259, -0.02604806050658226, -0.0123537452891469, -0.04650742933154106, 0.047112949192523956, -0.07009066641330719, -0.003443212015554309, -0.0290940310806036, 0.054573722183704376, 0.022622670978307724, 0.05104859918355942, -0.03354211524128914, -0.011034481227397919, -0.017584985122084618, -0.02632482349872589, -0.016238076612353325, -0.006448880769312382, 0.03636566922068596, -0.008946510031819344, 0.01634843274950981, -0.03934452310204506, -0.032000910490751266, -0.030221635475754738, -0.009026306681334972, 0.05403660982847214, -0.047485753893852234, -0.018958834931254387, -0.00004696976611739956, 0.06846829503774643, -0.03471929207444191, 0.009103069081902504, 0.025841666385531425, -0.009978442452847958, 0.04129863902926445, -0.02689083106815815, -0.0028208657167851925, -0.02008964493870735, 0.014479996636509895, 0.0027400723192840815, -0.041467443108558655, -0.01911398023366928, 0.01651759445667267, -0.01988031528890133, 0.00367947481572628, -0.04172223433852196, -0.016189856454730034, -0.06430719792842865, 0.021708747372031212, -0.017602868378162384, 0.053086984902620316, 0.023596348240971565, -0.01024426706135273, 0.03532484173774719, 0.0078805573284626, -0.005524762440472841, -0.009052596054971218, -0.02845114655792713, 0.011758052743971348, 0.040838923305273056, 0.01597907952964306, -0.04430502653121948, -0.02483886107802391, -0.017690911889076233, -0.011086014099419117, 0.015324268490076065, -0.005739584099501371, 0.01621890440583229, -0.008560450747609138, -0.0057615842670202255, -0.011818863451480865, -0.005626796279102564, -0.02037695050239563, 0.025717588141560555, 0.031175076961517334, -0.058559346944093704, -0.006949976552277803, -0.003996385261416435, -0.013955655507743359, -0.010634349659085274, -0.0181284099817276, 0.010398278012871742, 0.06720735877752304, 0.022153817117214203, 0.013269921764731407, 0.0035201222635805607, -0.04138198494911194, 0.0028155951295048, 0.041741978377103806, -0.025606980547308922, -0.023741405457258224, 0.0339045450091362, 0.041425276547670364, -0.020819485187530518, -0.030428221449255943, 0.01863347366452217, 0.013178497552871704, -0.007952377200126648, 0.028262628242373466, -0.013896346092224121, -0.002214456209912896, -0.01727251335978508, 0.025699803605675697, 0.0033448566682636738, 0.09090903401374817, 0.04395812377333641, 0.010789511725306511, 0.007736776489764452, 0.029691057279706 ]