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:
- A bookstore chain that wanted its own recommender instead of paying for a third-party one. Products are books. Users are web customers and CRM accounts (people who buy off-site).
- A magazine and newspaper distributor. The “users” are retail shops. The “items” are magazine titles. The signal is how many copies a shop sold on a given day.
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:
- Defining what counts as a “rating” when nobody left stars.
- Building hybrid features (text, price, categories, shop attributes) and wiring them into Cornac.
- Training several model families on the same split, comparing them on ranking metrics, not only RMSE.
- Writing a custom content-based recommender that plugged into Cornac’s evaluation loop.
- Solving cold start for new users, books, and shops, then blending models by averaging ranks (not raw scores - CDL and CVAE do not live on the same scale).
- Fighting deployment details: pickle, id maps, subclassing a library model when
score()refused unknown users, rebuilding sparse matrices after extending latent space.
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
- Drop books published before a cutoff year (older stock did not help).
- Fill missing publish dates (mean) and page counts (median).
- Normalize messy customer ids (decimal-looking strings → integers).
- Remove rare users and rare items, in a loop until both sides satisfy the cutoff. One pass is not enough: dropping sparse books can make a user sparse, and vice versa.
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)
- CDL (Collaborative Deep Learning) - stacked autoencoder on book text + matrix factorization jointly (e.g. tuned latent size ~26, autoencoder width ~200, heavy regularization).
- CVAE - variational text encoder instead of a point autoencoder.
- ContentBased - my own
Recommendersubclass: rating-weighted average of features on each side, dot-product scores, blend user-side and item-side views. Always has an opinion because it only needs features. - BiVAE was explored and dropped from the final pair; the shipped blend was CDL + CVAE (+ content and popularity at predict time).
Magazine distributor
- ConvMF - CNN on short titles + matrix factorization.
- PCRL with a subclass so
score()works for users absent from training (stock PCRL refused). - SoRec - MF plus a user-user graph built from shop-feature similarity (not a literal social network).
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:
- Collaborative cold start - new user row in
Ufilled 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. - 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).
- 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)
- A lambda inside Cornac’s text tokenizer would not pickle; I replaced it with an ordinary method with the same cleaning steps before
pickle.dump. - Id maps (
global_uid_map,global_iid_map) are part of the model. Lose them and every index points at the wrong person. - Tuned online hyperparameters were not trusted on the CRM slice - comments in code show weights reverted toward library defaults when the population changed.
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
- Decide what an affinity is - clicks, carts, copies sold - because nobody gives you stars.
- Throw away entities too rare to estimate, iteratively.
- Add text and attributes so new rows are not invisible.
- Fit more than one model; merge with ranks when scales disagree.
- Judge the order; adapt K when “users” are heterogeneous shops.
- 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.