einqimiaozi / transformer4keras Goto Github PK
View Code? Open in Web Editor NEW基于keras实现的transformer
基于keras实现的transformer
作者您好:
我在使用该模型时:输入为(bs, seq_length), 然后用Embedding为(bs, seq_length,64),然后输入Transformer,报错了请问一下原因:
我的模型如下:
def transformer(bs,time_steps, alphabet_size):
model = Sequential()
model.add(Embedding(alphabet_size, 64, input_length=64))
model.add(Transformer(num_layers=2,vocab_size=alphabet_size,heads=8,model_dim=64,
drop_rate=0.2,units_dim=512,epsilon=0.001))
model.add(Dense(alphabet_size, activation='softmax'))
return model
报错如下:
ValueError: Dimensions must be equal, but are 64 and 8 for 'transformer/encoder/encoder_layer_1/add' (op: 'AddV2') with input shapes: [?,64,64,64,64], [?,64,64,64,64,8,64].
您好,感谢您提供的代码,我在运行中碰到了很多环境问题,比如tensorflow和keras,
from tensorflow.python.keras.engine.base_layer import Layer ImportError: cannot import name 'Layer'
等,能否提供一个requirements文件。
我安装了tensorflow-cpu 1.15.0,keras==2.3.1
您好,我想使用该项目训练自己的数据集,但是我的数据处理后shape为(n,50,30)的数据,而该项目inputs shape好像只能是(n,m)的维度,我将自己的数据reshape成(n,m)的shape后,loss不降低,测试结果都是0,请问怎么修改能满足我的数据呢?
inputs = Input(shape=(maxlen,), name="inputs")
您好,我利用transhformer去训练负荷预测的数据,用20个时间段的数据预测1个时间段,shape为(10000,20),output shape为(10000,1),其中超参数:
`vocab_size = 5000
maxlen = 20
model_dim = 512 # 词嵌入的维度
batch_size = 32
epochs = 10
num_layers = 2
inputs = Input(shape=(maxlen,), name="inputs")
transformer = Transformer(num_layers=num_layers, vocab_size=vocab_size, heads=8, model_dim=model_dim,
drop_rate=0.2, units_dim=512, epsilon=0.001)(inputs)
x_n_data,y_n_data = generate_data(maxlen,1)# 我自己生成训练数据的函数
#我将最后transformer的输出加入两层Dense层,以适应我的数据
outputs = Dense(256, activation='relu')(transformer)
outputs = Dense(1, activation='relu')(outputs)
model = Model(inputs=inputs, outputs=outputs)
model.compile(optimizer=Adam(learning_rate=1e-3),
loss='mse', metrics=['mse'])`
最后训练出来发现结果很差,loss mse在0.2左右,实际预测的结果都是0,我不知道是哪儿出了问题,不知道您是否能解答一下?
I have looked at the source code of a lot of transformers, and think yours is great, and each step is clearly encapsulated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.