Im working on a project but im getting an error and i dont even know where to head


do you guys know what the issue is because I cant find the problem, I have downloaded tensorflow using python?

Hi @Fmosh, Could you please provide more details about the error as I can not see any error in the above screen shot. And also let us know the Tensorflow version you are using and please provide the code in the text format instead of giving the screen shot because it will be easy to reproduce and debug the error. Thank You.

import tensorflow as tf
import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Embedding, Flatten
from tensorflow.keras.optimizers import Adam
import numpy as np

class RecommendationModel:
def init(self, num_users, num_articles, embedding_size=50):
self.num_users = num_users
self.num_articles = num_articles
self.embedding_size = embedding_size
self.model = self._build_model()

def _build_model(self):
    model = Sequential([
        Embedding(self.num_users, self.embedding_size, input_length=1),
        Flatten(),
        Dense(100, activation='relu'),
        Dense(50, activation='relu'),
        Dense(self.num_articles, activation='softmax')
    ])
    model.compile(optimizer=Adam(learning_rate=0.001),
                  loss='categorical_crossentropy',
                  metrics=['accuracy'])
    return model

def train(self, user_ids, article_ids, labels, epochs=10, batch_size=32):
    self.model.fit(user_ids, labels, epochs=epochs, batch_size=batch_size)

def predict(self, user_id):
    user_id = np.array([user_id])
    predictions = self.model.predict(user_id)
    return predictions[0]

def prepare_data(user_history):
# Convert user history to training data
user_ids =
article_ids =
labels =
for user_id, articles in user_history.items():
for article_id in articles:
user_ids.append(user_id)
article_ids.append(article_id)
label = [0] * len(user_history)
label[article_id] = 1
labels.append(label)
return np.array(user_ids), np.array(article_ids), np.array(labels)

i did pip install tensorflow and i upgraded it so it should be te latest version, but im getting the:

Import “tensorflow.keras.models” could not be resolvedPylancereportMissingImports

im so confused how there is a missing import though.

Hi @Fmosh, The reportMissingImports error occurs when you try to import the package that is not present or not properly installed in the current environment. Could you please try to create a new environment and install the dependencies and then import the packages. If you still face the issue let us know the environment details you are facing the error. Thank You.