andykr1k commited on
Commit
6cbcc1b
·
1 Parent(s): 07f113d

Added freshness and dont recommend users posts

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -102,7 +102,7 @@ def compute_score(sim_score: float, popularity: float, freshness: float) -> floa
102
  - Popularity is log-transformed.
103
  - Freshness is combined linearly.
104
  """
105
- return 0.6 * (sim_score ** 2) + 0.3 * np.log1p(popularity) + 0.1 * freshness
106
 
107
 
108
  class Recommender:
@@ -272,14 +272,15 @@ class Recommender:
272
  now = datetime.now(TIMEZONE)
273
 
274
  for post_id, feature in post_features.items():
275
- if post_id in seen_posts:
 
276
  continue
277
 
278
  sim_score = np.dot(user_profile, feature) if np.any(
279
  user_profile) else 0
280
  time_diff = now - post_metadata[post_id]['created_at']
281
- # Freshness is defined as an exponential decay based on weeks old
282
- freshness = math.exp(-time_diff.days / 7.0)
283
  score = compute_score(
284
  sim_score, self.post_popularity[post_id], freshness)
285
  # Adding a small random noise for exploration
 
102
  - Popularity is log-transformed.
103
  - Freshness is combined linearly.
104
  """
105
+ return 0.4 * (sim_score ** 2) + 0.3 * np.log1p(popularity) + 0.3 * freshness
106
 
107
 
108
  class Recommender:
 
272
  now = datetime.now(TIMEZONE)
273
 
274
  for post_id, feature in post_features.items():
275
+ post = post_metadata[post_id]
276
+ if post_id in seen_posts or post.get("author") == user_id:
277
  continue
278
 
279
  sim_score = np.dot(user_profile, feature) if np.any(
280
  user_profile) else 0
281
  time_diff = now - post_metadata[post_id]['created_at']
282
+ # Freshness is defined as an exponential decay based on three days old
283
+ freshness = math.exp(-time_diff.days / 3.0)
284
  score = compute_score(
285
  sim_score, self.post_popularity[post_id], freshness)
286
  # Adding a small random noise for exploration