WOLFRAM NOTEBOOK

In[]:=
SeedRandom[234234];net={EmbLayer["size"->10,"dim"->16],TransformerLayer["inputDim"->16,"outputDim"->32,"windowSize"->10,"functions"->{8,6}],TemporalLayer["innerLayer"->XorLinearLayer["inputDim"->32,"outputDim"->10]]};
In[]:=
allNetsPacked=CloudImport[CloudObject["https://www.wolframcloud.com/obj/f09ef8d1-58be-4bdd-bf0b-bd80a91c7ed6"]];
In[]:=
Length[allNetsPacked]
Out[]=
10001
In[]:=
allnets=UnpackNetwork[CloneNetwork[net],#]&/@allNetsPacked;
In[]:=
ArrayPlot[ArrayReshape[allnets[[#]][[1]]["GetParameters"][],{10,16}],Mesh->True]&/@{1,5,10,50,100,500,1000,5000,10000}
Out[]=
,
,
,
,
,
,
,
,
In[]:=
GraphicsRow[Table[GraphicsRow[{Graphics[Style[Line[{{0,y},{1,y}}],Thick,ColorData[97][1]],PlotRange{{0,1},{0,10}},AspectRatio10],ArrayPlot[List/@ArrayReshape[allnets[[#]][[1]]["GetParameters"][],{10,16}][[y]],MeshTrue]}],{y,10}],ImageSize->{110,Automatic}]&/@{1,5,10,50,100,500,1000,5000,10000}
Out[]=
,
,
,
,
,
,
,
,
In[]:=
GraphicsRow[Table[GraphicsRow[{Graphics[Style[Line[{{0,y},{1,y}}],Thick,ColorData[97][1]],PlotRange{{0,1},{0,10}},AspectRatio10],ArrayPlot[List/@RandomInteger[1,5],MeshTrue]}],{y,10}]]
In[]:=
sinedata=Table[Floor[1+9(1+Sin[x/200*2Pi*4])/2+1/2],{x,0,47}];
In[]:=
(With[{cb=ArrayReshape[allnets[[#]][[1]]["GetParameters"][],{10,16}]},cb[[#]]&/@sinedata]//Transpose//ArrayPlot)&/@{1,5,10,50,100,500,1000,5000,10000}
Out[]=
,
,
,
,
,
,
,
,
In[]:=
(With[{cb=ArrayReshape[allnets[[#]][[1]]["GetParameters"][],{10,16}]},cb[[#]]&/@Take[sinedata,10]]//Transpose//ArrayPlot[#,Mesh->True]&)&/@{1,5,10,50,100,500,1000,5000,10000}
Out[]=
,
,
,
,
,
,
,
,
In[]:=
RenderTransformerNetwork[input_List,transformer_List,inDimensions_Integer,outDimensions_Integer,windowSize_Integer]:=Graphics[{EdgeForm[GrayLevel[.6]],Table[{GrayLevel[(1-input[[j,i]])*.98],Rectangle[{i,j},{i+1,j+1}]},{i,windowSize},{j,inDimensions}],Table[With[{el=transformer[[i]]},With[{inputs=Table[input[[c[[2]],c[[1]]]],{c,Last[el]}]},Table[{{Gray,Arrowheads[{{.03,.95}}],Arrow[Line[{{First[c]+1/2,Last[c]+1/2},{windowSize+3,inDimensions/2-outDimensions/2+i+1/2}}]]},Style[Disk[{First[c]+1/2,Last[c]+1/2},0.2],Blend[{Red,Red},input[[c[[2]],c[[1]]]]]],FaceForm[Blend[{RuleArrayColors[[el[[1]]]],Darker[RuleArrayColors[[el[[1]]]],0.4]},Boole[BooleanFunction[el[[1]],2]@@inputs]],RuleArrayColors[[el[[1]]]]],Rotate[RegularPolygon[N@{windowSize+3,inDimensions/2-outDimensions/2+i+1/2},1/3,6],Pi/6.]},{c,Last[el]}]]],{i,Length[transformer]}]}]
In[]:=
transformerf[netw_]:=With[{parameters=netw[[2]]["GetParameters"][],inputDim=16,nFunctions=2,windowSize=10},With[{functionBits=Ceiling[Log2[nFunctions]],windowBits=Ceiling[Log2[windowSize]],inputBits=Ceiling[Log2[inputDim]]},{Mod[FromDigits[#[[;;functionBits]],2],nFunctions,1],{{Mod[FromDigits[#[[functionBits+1;;functionBits+windowBits]],2],windowSize,1],Mod[FromDigits[#[[functionBits+windowBits+1;;functionBits+windowBits+inputBits]],2],inputDim,1]},{Mod[FromDigits[#[[functionBits+windowBits+inputBits+1;;functionBits+windowBits+inputBits+windowBits]],2],windowSize,1],Mod[FromDigits[#[[functionBits+windowBits+inputBits+windowBits+1;;functionBits+windowBits+inputBits+windowBits+inputBits]],2],inputDim,1]}}}&/@Partition[parameters,functionBits+(windowBits+inputBits)*2]]]

Mesh Nets

Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.