Miloš Vlainić

My GitHub blog: things you might be interested, and probably not...

Hyperplane (2020-2022)

Machine Learning consultant

At Hyperplane, almost everything I touched in this period was a recommender system: given people and products, score what each person might want next - and the reverse, which people should hear about a given product.

Two real businesses sat behind the code:

The bookstore brief had four goals. I worked seriously on the first three: recommendations on the online shop, a personalized newsletter (including “this title is on discount, tell the readers who would care”), and seasonal or event pushes. Sales forecasting and a full logistics optimizer were out of scope for what I shipped in code.


My role

I owned the shared pipeline end to end for both clients: from raw logs to deployable experiments. That meant:

Versions were copied forward (v0 → v1 → fix) until something was stable enough to treat as deployment. Hyperparameter search was on the todo list (Hyperopt); in practice a lot was hand-tuned.


The pipeline every project shared

raw table
  → clean and filter
  → turn behavior into a rating
  → (user, item, rating) triples
  → train / validation split
  → attach side information ("modalities")
  → train several models
  → score them with ranking metrics
  → save the whole experiment
  → at prediction time, handle ids the model has never seen
  → blend the models into one ranked list

That sequence is the real product. The two clients only changed the schema and the model list.


Turning clicks and sales into ratings

A recommender trains on who, what, how much they liked it - not on a raw event log.

Bookstore website had no star ratings. I mapped events by hand:

Event Rating
BUY 5
ADD_TO_CART 4
ADD_TO_FAVORITES 3
VIEW, OPENBIGPICTURE, DESCRIPTION_ON_SCREEN 2
REMOVE_FROM_CART 1
REMOVE_FROM_FAVORITES 0
anything else 0

Several events on the same person, book, and day collapse to the maximum for that day, so a purchase beats a view.

CRM / offline purchases were positive-only: every kept row is rating 1.0. Online training explicitly excludes those rows; offline models use only them - the notes treated them as a different population (including very large wholesale accounts that are not “a normal reader”).

Magazine distributor already had a number: daily copies sold. I clipped extreme days and rescaled to 0-5 so a few huge sales could not dominate. Issue codes were truncated so different issues of the same title collapse to one product.

Lesson: implicit feedback is a judgment call. The business will not hand you an affinity; you invent one and live with the consequences.


Cleaning and who gets into the matrix

Online bookstore used lighter cutoffs; offline CRM stricter; the distributor kept shops with at least a minimum number of distinct titles.

Lesson: collaborative filtering dies on sparse junk. One-touch users and one-touch items teach the model nothing.


Hybrid side information

Matrix factorization only sees the rating table. These projects also built features and passed them to Cornac as modalities.

Books: price, page count, publish date; title and description as text (vocabulary capped on the online model); user side = pivot of how many books each customer touched per product category (taste without a profile form).

Shops and magazines: wide one-hot tables - geography, channel, capacity, venue type for shops; yesterday’s sales, shelf life, publisher, format, weekday, category, bundled extras for issues.

Features were min-max scaled (sometimes row-wise so each entity sits on 0-1). Row i of the feature matrix must match entity index i inside the model - a boring detail that breaks everything when you get it wrong.

Cornac then got a text modality (bag of words, sometimes concatenated with numerics) and a graph modality (each entity linked to k nearest neighbors by cosine similarity on features).

Lesson: content is what lets you speak about a brand-new book or shop before anyone has co-purchased with it.


Models I trained (and one I wrote)

Bookstore (online and offline)

Magazine distributor

Item-to-item (no neural model)

Classical neighborhood on the item-user matrix: cosine, inverted Euclidean, RBF, Pearson; plus content bonuses (same author, same category, shared customers, same receipt). Sparse top-100 neighbors; at query time sum rows for books the person liked. The related-products rail and it still runs when you do not want to load CDL.

Lesson: user→item and item→user are one factorization read two ways; item→item is a different object. That is why the folder has both Cornac stacks and a similarity matrix.


Evaluation: order of the list, not just the number

Cornac Experiment + RatioSplit; some runs held out validation (distributor ~25%), some trained on everything because deployment was the goal.

Metrics: Precision@K, Recall@K, nDCG@K, MAP, AUC for ranking; RMSE/MAE for rating error. For a shop catalogue, ranking usually matters more.

I added dynamic ranking so K is not the same for everyone: for a shop, K scales with how many distinct titles that shop carries (divided by a kappa). A kiosk and a large store should not be judged on the same list length. Items already liked in training are removed from negatives.

Lesson: a recommender is judged by the order of the list. RMSE can look fine while the top ten is useless.


Cold start and prediction-time blending

Three layers stacked:

  1. Collaborative cold start - new user row in U filled with the mean of known users (or the item analogue). Rebuild the sparse rating matrix after the latent space grows; Cornac will not notice on its own.
  2. Neighbor cold start - embed from features, dot-product similarity against known entities, keep neighbors above a threshold (looser for sparse user category vectors, tighter for items).
  3. Content + popularity - content model always runs; popularity (value_counts) as last resort and tie-break.

Online bookstore predict: each model → scores → ranks → average ranks → break ties with popularity.

Offline item → users: pass book ids; extend item latent space; invert the factor read so the question is “who should we email about this title / discount / season?” Batch output is {item: [users]} - newsletter shape.

Blending ranks not raw scores matters because neural hybrids do not share a calibration.


The three questions the business actually asked

Query Product use
User → items On-site widget, newsletter for one reader
Item → users Push a title, discount, or Christmas list to the right CRM accounts
Item → items “Because you liked this” / related books

That map is why one pipeline still had two training slices (web vs CRM) and a separate similarity engine.


Deployment scars (small but real)


Side task: customer segments (notes + some experiments)

Not fully in the recommender repos, but part of the same engagement: separate wholesale from retail without ready labels (tax ids, manual labeling, company-name heuristics); cluster retail after cutting spend tails (100k, 200k, …); UMAP + K-means on scaled features; keep clustering on books and drop comics/maps ISBN noise. Unsupervised structure before you recommend.


What I actually learned

  1. Decide what an affinity is - clicks, carts, copies sold - because nobody gives you stars.
  2. Throw away entities too rare to estimate, iteratively.
  3. Add text and attributes so new rows are not invisible.
  4. Fit more than one model; merge with ranks when scales disagree.
  5. Judge the order; adapt K when “users” are heterogeneous shops.
  6. Define behavior for unseen ids, then persist the whole experiment (maps, features, popularity, patched tokenizer).

Honest gaps

I did not deliver the bookstore sales-forecast module or a logistics optimizer. Hyperparameter search stayed partly aspirational. The codebase is successive copies of the same class stabilizing toward deploy, not a polished package. Supply-chain simulation logs that lived beside deployments were unrelated poultry-plant output from another thread - not part of this recommender work.


I hope this explains what I did at Hyperplane and what I would reuse on the next recsys job. Corrections welcome.