This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Loading Model...') | |
home_ = process.cwd() | |
model_path = "file://"+ home_ + "/model/model.json" | |
console.log('Model Loaded Successfull') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Loading Model...') | |
model = await tf.loadLayersModel("file:///home/Projects/recommender-sys/recommender-books/model/model.json", false); | |
console.log('Model Loaded Successfull') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
const express = require("express"); | |
const bodyParser = require("body-parser"); | |
const expressHbs = require("express-handlebars"); | |
const books = require("./data/web_book_data.json") | |
const model = require("./model") | |
const app = express(); | |
app.set("views", "./views"); | |
app.set("view engine", "hbs"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b_id =list(ratings_df.book_id.unique()) | |
b_id.remove(10000) | |
dict_map = {} | |
for i in b_id: | |
dict_map[i] = books_df_copy.iloc[i]['title'] | |
out_v = open('vecs.tsv', 'w') | |
out_m = open('meta.tsv', 'w') | |
for i in b_id: | |
book = dict_map[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hist = model.fit([Xtrain.book_id, Xtrain.user_id], Xtrain.rating, | |
batch_size=64, | |
epochs=5, | |
verbose=1, | |
validation_data=([Xtest.book_id, Xtest.user_id], Xtest.rating)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Book input network | |
input_books = tf.layers.Input(shape=[1]) | |
embed_books = tf.layers.Embedding(nbook_id + 1,15)(input_books) | |
books_out = tf.layers.Flatten()(embed_books) | |
#user input network | |
input_users = tf.layers.Input(shape=[1]) | |
embed_users = tf.layers.Embedding(nuser_id + 1,15)(input_users) | |
users_out = tf.layers.Flatten()(embed_users) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import train_test_split | |
Xtrain, Xtest = train_test_split(ratings_df, test_size=0.2, random_state=1) | |
print(f"Shape of train data: {Xtrain.shape}") | |
print(f"Shape of test data: {Xtest.shape}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" | |
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tf = require('@tensorflow/tfjs-node') | |
const books = require("./data/web_book_data.json") | |
async function loadModel() { | |
console.log('Loading Model...') | |
model = await tf.loadLayersModel("file:///home/dsn/personal/Tfjs/TensorFlowjs_Projects/recommender-sys/recommender-books/model/model.json", false); | |
console.log('Model Loaded Successfull') | |
// model.summary() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get("/recommend", (req, res) => { | |
let userId = req.query.userId | |
if (Number(userId) > 53424 || Number(userId) < 0) { | |
res.send("User Id cannot be greater than 53,424 or less than 0!") | |
} else { | |
recs = model.recommend(userId) | |
.then((recs) => { | |
res.render("index", { recommendations: recs, forUser: true }) | |
}) | |
} |