lightfm
Operate LightFM recommendation models, data/feature matrices, evaluation metrics, and repository maintenance workflows.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- lightfm
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Operate LightFM recommendation models, data/feature matrices, evaluation metrics, and repository maintenance workflows.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/repo-provenance.md2.2 KB
- 参考文档references/repo-routing-metadata.json311 B
- 参考文档references/troubleshooting.md4.3 KB
- 脚本scripts/check_lightfm_environment.py6.6 KB
03 SKILL.md 正文
LightFM repo skill
Use this skill when a task involves the lightfm Python package: building hybrid recommendation inputs, training or scoring LightFM models, evaluating ranking metrics, or maintaining the LightFM source checkout.
LightFM is a CPU-only recommender-system package. It implements hybrid matrix-factorization models for implicit and explicit feedback, including logistic, bpr, warp, and warp-kos losses. It can combine user/item identity features with side metadata so models can handle cold-start or metadata-aware recommendations when the feature schema is planned correctly.
Start here
-
Install the package in an isolated Python environment:
python -m pip install lightfm # or, for conda users conda install -c conda-forge lightfmFor source checkout maintenance, use the
repo-developmentroute instead of the end-user install path. -
Run a minimal import and CPU smoke check:
python scripts/check_lightfm_environment.py --tiny-run -
Choose the route below based on the user's task. Read the nearest sub-skill before giving detailed commands or API advice.
Route map
| User task or signal | Read this |
|---|---|
Train a LightFM model, choose warp/bpr/logistic, resume with fit_partial, predict recommendations, inspect embeddings, handle sample weights, tune regularization, serialize a model, or use optional ANN indexes from representations. |
sub-skills/model-training/SKILL.md |
| Convert raw user/item ids, interactions, weights, metadata, or built-in MovieLens/StackExchange data into LightFM sparse matrices and feature mappings; design cold-start user/item features. | sub-skills/data-features/SKILL.md |
Split interactions, compute precision_at_k, recall_at_k, auc_score, reciprocal_rank, use predict_rank, preserve user rows, or debug train/test intersection leakage. |
sub-skills/evaluation-splitting/SKILL.md |
| Work on the LightFM repository itself: editable install, compiled extension/OpenMP/no-OpenMP behavior, Cython regeneration, focused tests, docs, lint, CI, or build failures. | sub-skills/repo-development/SKILL.md |
Common package workflow
- Build or load a SciPy sparse interactions matrix. If raw ids or metadata are involved, use
data-featuresto create stable mappings and feature matrices. - Instantiate
LightFM(...). Useloss="warp"for many implicit top-k tasks,loss="bpr"for implicit pairwise ranking/AUC-style objectives, andloss="logistic"when explicit positive and negative labels are represented ininteractions.data. - Fit with
model.fit(...)for a fresh model ormodel.fit_partial(...)for resumed/epoch-by-epoch training. Passuser_featuresand/oritem_featuresconsistently whenever the model was trained with side features. - Score items with
model.predict(user_ids, item_ids, ...)or rank sparse held-out interactions withpredict_rank/evaluation utilities. - Evaluate with a disjoint train/test split and
train_interactions=trainso known positives are excluded from test rankings.
Important constraints
- There is no GPU implementation. OpenMP is only CPU multithreading; do not install CUDA packages or promise GPU acceleration for LightFM.
- Feature column schemas are model state. Adding new user/item feature names after training changes the embedding dimensions and normally requires retraining or a deliberate model-resize workflow.
Dataset.build_interactionsreturns both an interactions matrix and a weights matrix. If usingsample_weight, the weight COO entries must have the same shape and entry order as the interactions COO matrix.- Evaluation treats non-zero test entries as positives. Remove negative labels before ranking metrics unless you intentionally evaluate on the training labels.
- Built-in dataset fetchers may download public data. For offline or deterministic checks, use the bundled tiny scripts instead of MovieLens/StackExchange downloads.
Bundled references and scripts
references/troubleshooting.md: cross-cutting install/import, CPU/OpenMP, dataset download, feature schema, and evaluation leakage guidance.references/repo-provenance.md: source snapshot and refresh baseline for this generated skill.scripts/check_lightfm_environment.py: package import/version/compiled-extension/tiny-fit diagnostic.
When not to use this skill
- The task is about a different recommender package such as implicit, Surprise, LensKit, RecBole, Cornac, or a deep-learning recommender framework without LightFM APIs.
- The task is pure database/product ranking design with no
lightfmpackage usage. - The user asks to export this generated repo skill into another agent tool; use the managed repo-skill import/export workflow instead.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).