Skip to content

feat: WeightedRanker with IDF tag weighting (Jaccard fallback, train/save/load) - #370

Open
laurentketterle-hub wants to merge 1 commit into
mergeos-bounties:masterfrom
laurentketterle-hub:feat/weighted-ranker
Open

feat: WeightedRanker with IDF tag weighting (Jaccard fallback, train/save/load)#370
laurentketterle-hub wants to merge 1 commit into
mergeos-bounties:masterfrom
laurentketterle-hub:feat/weighted-ranker

Conversation

@laurentketterle-hub

Copy link
Copy Markdown

Summary

Adds WeightedRanker — a trainable tag-based plant species ranker that extends the existing ToyPlantIdentifier (Jaccard baseline) with IDF-like weighted tag scoring.

What's new

  • src/plantguide/models/weighted_ranker.pyWeightedRanker class with:

    • train() — compute per-tag IDF weights from the species catalog (sklearn TF-IDF when available, pure-Python IDF fallback otherwise)
    • save(path) / load(path) — persist/restore learned weights as JSON
    • identify(tags, top_k) — 70/30 blend of weighted score + Jaccard for stable ranking; pure Jaccard fallback when weights aren't trained
    • Compatible interface with existing ToyPlantIdentifier
  • src/plantguide/models/__init__.py — exports WeightedRanker

  • tests/test_weighted_ranker.py — 10 pytest tests covering:

    • Pure-Python IDF training and idempotency
    • Save/load round-trip + partial-tag loading
    • Weighted identification (correct top match, score fields)
    • Jaccard fallback (identical results to ToyPlantIdentifier when untrained)
    • Edge cases (empty query, single tag)
    • Integration: top-1 hit rate on labeled samples vs Jaccard baseline

Results

59 passed in 96s (all existing + 10 new, zero regressions)

Fixes #11

@laurentketterle-hub

Copy link
Copy Markdown
Author

/attempt 11

@laurentketterle-hub

Copy link
Copy Markdown
Author

Friendly ping 👋 — this PR has been open for 3 days. Is there anything needed for review? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[50 MRG] Ranking model beyond Jaccard (embeddings or weighted tags)

1 participant