from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import statistics
import keras
import numpy as np
import pandas as pd
from keras.models import Sequential
from keras.layers import Dense
import tensorflow as tf
import textdistance
import sys
print(tf.executing_eagerly())
def custom_error_finder(y_actual,y_pred):
print(tf.executing_eagerly())
count = 0
ya = ((y_actual[0].numpy()).decode())
yp = ((y_pred[0].numpy()).decode())
for i,j in ya,yp:
if i!=j:
count = count+1
mse = pow(count,2)/len(ya)
return mse
model = Sequential()
scraper_data = pd.read_csv("C:/Users/Desktop/Projects/Chatbot/Combined_new.csv")
scraper_data_columns = scraper_data.columns
predictors = scraper_data["Given"]
target = scraper_data['Target']
X_train, X_test, y_train, y_test = train_test_split(predictors, target, test_size=0.3, random_state=42)
n_cols = predictors.shape[0]
model.add(Dense(1, activation = 'relu', input_shape = (n_cols,)))
model.add(Dense(10, activation = 'relu'))
model.add(Dense(10, activation = 'relu'))
model.add(Dense(1, activation = 'relu'))
model.compile(optimizer = 'adam',run_eagerly=True, loss = custom_error_finder)
model.run_eagerly = True
model.fit(X_train, y_train,epochs=200)
predictions = model.predict(X_test)
I am extremely new to designing deep learning models and this is literally my first model, ever.
I have defined a custom error metric and for some reason i get this error:
AttributeError: 'Tensor' object has no attribute 'numpy'
I don't know if this helps but the outer "print(tf.executing_eagerly())" print "True" while the inner one prints "False".
"y_actual" are the true values from the dataset and "y_pred" are the predicted values by the model.
I would honestly appreciate any help I can get on this since I've been working on this model for weeks now.
Thanks in advance.
(The "Given" column has strings in it and the "Target" column has strings I'm trying to extract from the "Given" column)