Run this model with HF Jobs
Run clfegg/content_based_recommend on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/clfegg/content_based_recommend. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/clfegg/content_based_recommend on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use clfegg/content_based_recommend with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use clfegg/content_based_recommend with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import ContentBasedRecommender model = ContentBasedRecommender.from_pretrained("clfegg/content_based_recommend", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update handler.py
Browse files3 unmodified lines4567893 unmodified linesimport pandas as pdimport osclass EndpointHandler:def __init__(self, path=""):model_path = os.path.join(path, "model.pkl")3 unmodified lines45678910111213141516171819202122232425262728293031323334353637383 unmodified linesimport pandas as pdimport osclass ContentBasedRecommender:def __init__(self, train_data):self.train_data = train_datadef predict(self, user_id, k=10):user_books = set(self.train_data[self.train_data['user_id'] == user_id]['book_id'])similar_books = set().union(*(self.train_data[self.train_data['book_id'] == book_id]['similar_books'].iloc[0] for book_id in user_books))recommended_books = list(similar_books - user_books)return np.random.choice(recommended_books, size=k, replace=False) if len(recommended_books) >= k else recommended_booksdef evaluate(self, test_data, k=10):user_ids = test_data['user_id'].unique()hit_rate, ndcg_scores = [], []for user_id in user_ids[:100]:true_books = set(test_data[test_data['user_id'] == user_id]['book_id'])pred_books = set(self.predict(user_id, k))hits = len(true_books & pred_books)hit_rate.append(hits / min(k, len(true_books)))dcg = sum(1 / math.log2(rank + 2) for rank, book in enumerate(pred_books) if book in true_books)idcg = sum(1 / math.log2(i + 2) for i in range(min(k, len(true_books))))ndcg = dcg / idcg if idcg > 0 else 0ndcg_scores.append(ndcg)return np.mean(hit_rate), np.mean(ndcg_scores)class EndpointHandler:def __init__(self, path=""):model_path = os.path.join(path, "model.pkl")
handler.py+29