Categories
Mastering Development

How do I present the data to a Keras LSTM?

I want to use an LSTM to predict the next element in a sequence, but I am having trouble wrapping my head around how to formulate the problem, and, more specifically, how to structure the data and present it to the mdel. I should say that I am fairly new to LSTMs – I have […]

Categories
Artificial Intelligence (AI) Mastering Development

Understanding Basic notions of Neural Networks Terms

i have read a lot of information about several notions, like batch_size, epochs,iterations, but because of explanation was without numerical examples and i am not native speaker, i have some kind of problem of understanding still about those terms, so i decided to work with data and step by step show what i have done […]

Categories
Mastering Development

How to make BERT model converge?

I am trying to use BERT for sentiment analysis but I suspect I am doing something wrong. In my code I am fine tuning bert using bert-for-tf2 but after 1 epoch I am getting an accuracy of 42% when a simple GRU model was getting around 73% accuracy. What should I be doing different to […]

Categories
Development

Data frame inverse reshaping memory

So I have two dataframs that I’m using on a GRU model. I had to reshape them in order to apply it, but at the end of the code I wanted to plot y_predicted with y_test. It works but what used to be the x-axis is now the y-axis and vice versa. I though that […]

Categories
Development

TensorFlow 2.0 model fit for batches of size 1

I have got the following simple TensorFlow model with the following optimizer: self.model = tf.keras.Sequential() self.model.add(tf.keras.layers.Dense(64, activation=’relu’, input_shape=(self.inputs,))) self.model.add(tf.keras.layers.Dense(64, activation=’relu’, input_shape=(self.inputs,))) self.model.add(tf.keras.layers.Dense(self.outputs, activation=’softmax’)) self.model.compile(optimizer=tf.keras.optimizers.RMSprop(), # Optimizer # Loss function to minimize loss=tf.keras.losses.CategoricalCrossentropy(from_logits=True), # List of metrics to monitor metrics=[tf.keras.metrics.CategoricalCrossentropy()]) I have to call the following fit function with batch_size=1 rapidly in a for-loop: self.model.fit(training_input, target_output, […]

Categories
Development

Incompatible shapes: [84,6] vs. [128,6]. Error at end of first epoch

This is the model that I built. Please do help me understand if the problem with my model or any other problem I am facing this issue. The error occurs after this: Train on 63828 samples, validate on 95743 samples Epoch 1/1 63744/63828 [============================>.] – ETA: 2s – loss: 0.3427 – acc: 0.9943 The error […]

Categories
Development

How to write a generator for keras fit_generator?

This question is a further step of this question. My data inputs are tens of .csv files, I have already read input data until the follow format: # train_x is data, train_y is label print(train_x.shape) # (2000000,10,100) 3D array print(train_y.shape) # (2000000,) labels I already can fit & evaluate them using: model.fit(train_x, train_y, batch_size=32, epochs=10) […]

Categories
Development

Keras: How to store history after each epoch?

I want to change my input after every epoch and at the end I want to plot learning curve. To change the input I have function which I can use as below for _ in range(num_epochs): x, y = generate_data() history = model.fit(x, y, epochs=1, batch_size=64) But I am not able to capture the complete […]

Categories
Development

transpose expects a vector of size 0

I created a custom layer in keras with following code: class drawLines(Layer): def __init__(self, output_dim, **kwargs): self.output_dim = output_dim super(drawLines, self, ).__init__(**kwargs) def build(self, input_shape): super(drawLines, self).build(input_shape) def call(self, input): xout = tf.py_function(image_tensor_func, [input], ‘float32’) xout.set_shape([input.shape[0], input.shape[1], input.shape[2], 1]) return xout def compute_output_shape(self, input_shape): output_shape = list(input_shape) c_axis, h_axis, w_axis = 3, 1, 2 output_shape[c_axis] […]

Categories
Artificial Intelligence (AI) Development

How to reproduce neural network training with keras

I want to see the effects of changing some training parameters (batch size, learning rate, optimizer…) to the accuracy obtained. The problem is that with the same parameters I get significantlly different results (up to 5%). I load the same weights before training and I deactivated the shuffle. To my understanding this should be enough […]