Imageomics / Imageomics/pybioclip

Consider adding a flag for user to configure normalization with the `embed` command

Open
#164 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
67
Forks
14
PR merge metrics
No merged PRs in 30d

Description

Embeddings currently come out at [raw magnitude](https://github.com/Imageomics/pybioclip/blob/5f13513e00d9740deddc157ebb0172e787568dbb/src/bioclip/__main__.py#L102).

This is probably a reasonable default, preserving any information in the norm in the (maybe unexpected) case that the norm isn't purely noise ...

Although in training and inference, L2 norm is applied for cosine similarity. Having `pybioclip` optionally give normalized embeddings would most accurately present outputs in the geometry BioCLIP intends.

While normalization is simple post hoc, it might not be an obvious step.

Proposing the option of a flag for something like the following to configure [`normalize=True/False`](https://github.com/Imageomics/pybioclip/blob/5f13513e00d9740deddc157ebb0172e787568dbb/src/bioclip/__main__.py#L102):
```
bioclip embed --normalize=True Ursus-arctos.jpeg # sets normalize=True
bioclip embed --normalize=False Ursus-arctos.jpeg # sets normalize=False
bioclip embed Ursus-arctos.jpeg # default behavior, sets normalize=False
```
(or perhaps a simple boolean `--normalize` where present is `True`, absent is `False`)

Along with a brief CLI description and perhaps an exposition in docs.

Strongest case for keeping the default behavior of `normalize=False` I think is to avoid a breaking change.

This was motivated by an error `Floating point exception (core dumped)` during UMAP on raw embeddings, which might be due to numerically instability with large magnitude embeddings.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/bioclip/__main__.py at the referenced embed command and inspect how its arguments are handled. Confirm the intended flag behavior and help text, then verify that the option can request normalized embeddings while the existing default remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, machine-learning
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.