Skip to content

Instantly share code, notes, and snippets.

train(epochs=20, bs)
def recommend_item_for_user(model, user_id):
m = model.eval().cpu()
user_ids = torch.LongTensor([user2idx[u] for u in [user_id]*len(items)])
item_ids = torch.LongTensor([item2idx[b] for b in items])
remove = set(ratings[ratings[user_col] == user_id][item_col].values)
preds = m(user_ids,item_ids).detach().numpy()
pred_item = [(p,b) for p,b in sorted(zip(preds,items), reverse = True) if b not in remove]
return pred_item
def recommend_user_for_item(model, item_id):
# Making life easier with fast.ai
# required library -> fastai (https://github.com/fastai/fastai/)
from fastai.collab import *
from fastai.tabular import *
# loading the dataframe
ratings = pd.read_csv('ratings.csv')
# creating data object
data = CollabDataBunch.from_df(ratings, seed=42, valid_pct=0.1)
// Program to perform summation on two numbers using do-while loop
int a, b, c;
Scanner scanner = new Scanner(System.in);
do {
System.out.println("Enter first number: ");
a = scanner.nextInt();
System.out.println("Enter second number: ");
b = scanner.nextInt();
System.out.printf("Sum is %d \n", a + b);
System.out.println("Press 1 to add more numbers, 0 to exit: ");
// Program to print first 10 odd numbers using while loop
int i = 1, count = 0;
while(count != 10) {
if(i%2==1) {
count++;
System.out.printf("%d ", i);
}
i++;
}
// Print a pyramid pattern using for loop
for(int i = 1; i <= 5; i++) {
for(int j = 1; j <= i; j++) {
System.out.printf("%d ", j);
}
System.out.print("\n");
}
// Print names using enhanced for loop
List<String> names = List.of("Rahul", "Virat", "Sourav");
for(String name:names) {
System.out.println(name);
}
package com.invictalabs.helloworld;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
// Code to show different primitive data types in Java
boolean isStudent = true;
short age = 22;
long stipend = 50000;
char section = 'D';
System.out.printf("The details are: %b, %d, %d %c", isStudent, age, stipend, section);
// Program to perform Type Casting in Java
int num = 1000;
// Leads to loss of information
byte narrowCasting = (byte) num;
// No loss of information
double wideCasting = (double) num;
System.out.println("Original integer : " + num); // Prints 1000