Keep first gene mentions in the CellGemma model card example

#8
by rpinho1 - opened

The model card's parse_genes passes repeated mentions to the expression decoder. Repeats change the directional ranks and list lengths. A gene mentioned in both directions receives two deltas at the same output index. This patch keeps the first valid mention, matching the hosted demo.

I replayed one saved 8-bit Panobinostat example with the released Tahoe decoder. The response contained 4,096 valid signed mentions for 3,356 distinct genes. The patch changed 2,871 of 19,720 reconstructed expression values by more than 0.00001, with a maximum absolute change of 0.500 in log-normalized expression. A separate NumPy replay reproduced the count.

I ran the following regression test from the repository root. It exits 1 on the published README and 0 with the patch. It needs only the Python standard library.

python - README.md <<'PY'
import ast
from pathlib import Path
import sys

readme = Path(sys.argv[1]).read_text()
example = readme.split("```python\n")[2].split("\n```", 1)[0]
parser = next(node for node in ast.parse(example).body
              if isinstance(node, ast.FunctionDef) and node.name == "parse_genes")
namespace = {}
exec(compile(ast.Module(body=[parser], type_ignores=[]), "<example>", "exec"), namespace)
parse_genes = namespace["parse_genes"]
genes = {"A": 0, "B-2": 1, "C": 2, "D": 3}
assert parse_genes("-a +B-2 +unknown +A +b-2 -C +D -c", genes) == (["B-2", "D"], ["A", "C"])
assert parse_genes("A + - +unknown", genes) == ([], [])
assert parse_genes("+A -C +B-2", genes) == (["A", "B-2"], ["C"])
PY

🤖 Generated with Claude Code

Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment