Skip to content

About

Lightweight 3-step CLI pipeline to automatically classify and tag Codabench competitions using LLMs and regex.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

Codabench Competition Auto-Tagger

A lightweight 3-step pipeline to automatically tag untagged pre-existing competitions in Codabench. Because export, inference, and import run as separate steps using JSON files, you can export competitions from your Codabench server, run LLM inference on any separate machine (ideally with a GPU), and safely import the resulting tags back into Codabench.

[Codabench DB] ──▶ 1. export.py ──▶ competitions_to_tag.json
                                              │
                                              ▼
      [Ollama] ◀────────────────────▶ 2. predict.py
                                              │
                                              ▼
[Codabench DB] ◀── 3. import_tags.py ◀── predicted_tags.json

Files

File Role
export.py Exports competitions and the active database taxonomy to JSON
predict.py Classifies competitions using Ollama (LLM) and title-based regex matching
import_tags.py Validates predicted tags against the database and imports them atomically
taxonomy.json Defines tag categories, modes (llm / regex), tag descriptions, and regex patterns
taxonomy.py Loads taxonomy.json, syncs with DB tags, and builds the LLM prompt and JSON schema
requirements.txt Lists the Python packages required to run the scripts

Requirements

  • Inference Machine (predict.py):
    • Python 3.8+
    • Ollama installed (a GPU is recommended for faster inference)
    • Python dependencies:
      pip install -r requirements.txt
      # or simply:
      pip install ollama
  • Codabench Server (export.py, import_tags.py):
    • Runs directly inside the Codabench Docker container (docker compose exec django ...), where Django and all required dependencies are already installed.

Quickstart

1. Export competitions

export.py queries your Codabench database via the Django ORM, extracts each competition's title, description, and key pages, and bundles them together with your instance's active TagCategory and Tag definitions into a single JSON file. By default, only untagged competitions are exported (use --all to export everything, or --limit 10 for a quick test).

docker compose exec django python export.py -o output/competitions_to_tag.json

2. Predict tags for exported competitions

predict.py connects to Ollama (and starts a local ollama serve automatically if none is running), loads your taxonomy and prompt rules from taxonomy.json and taxonomy.py (see Custom Taxonomy & Tag Definitions), and classifies each competition. Make sure taxonomy.py and taxonomy.json are located in the same directory as predict.py (unless you specify another JSON path with --taxonomy).

Results are written atomically to disk after each competition. If the run is interrupted, simply re-run the same command (it skips already processed IDs and resumes automatically where it left off).

Tip: You can adapt the model to any Ollama model depending on your hardware specs (e.g., qwen2.5:14b is recommended for good accuracy with ~9 GB VRAM, or qwen2.5:7b for lighter setups with < 8 GB VRAM).

# 1. Pull model (e.g. 14b)
ollama pull qwen2.5:14b

# 2. Run prediction
python3 predict.py \
    -i output/competitions_to_tag.json \
    -o output/predicted_tags.json \
    -m qwen2.5:14b \
    --workers 1

3. Import back the predicted tags

import_tags.py checks that all predicted tags exist in your Codabench database before applying them. If any tag is missing, the script aborts without modifying the database. You can preview the changes first with --dry-run without modifying the database. If everything looks good, run the same command without --dry-run to apply the changes.

# 1. Preview changes (Dry-run, does not modify database):
docker compose exec django python import_tags.py -i output/predicted_tags.json --dry-run

# 2. Apply to database:
docker compose exec django python import_tags.py -i output/predicted_tags.json

Custom Taxonomy & Tag Definitions

By default, export.py reads the active TagCategory and Tag entries from your Codabench database and writes them in the exported JSON. When predict.py runs, it automatically syncs with your database tags and looks up their definitions in taxonomy.json.

How to add custom tags or categories

  1. Create the category/tags in Codabench first (via Django Admin) so import_tags.py recognizes them.
  2. Add their definitions in taxonomy.json (or pass a custom file with --taxonomy my_taxonomy.json). (If a tag exists in your database but is not listed in taxonomy.json, it will still be included with a generic fallback description/regex, though writing an explicit definition gives much better accuracy.)

Structure of taxonomy.json

Each top-level key is a TagCategory name with two fields:

  • "mode":
    • "llm" — classified by the Ollama model using a strict JSON Schema, a brief reasoning step before outputting tags (which significantly reduces false positives), and the tag descriptions below.
    • "regex" — matched strictly against the competition title using regular expressions (such as Conference by default).
  • "tags":
    • For "llm" mode: maps each tag name to a short description guiding the model.
    • For "regex" mode: maps each tag name to a list of regex patterns.

The following is an example of a custom taxonomy with one LLM category and one regex category:

{
  "Machine Learning Domain": {
    "mode": "llm",
    "tags": {
      "Computer Vision": "Image classification, object detection, segmentation, OCR.",
      "My Custom Tag": "Explain what this tag covers so the LLM selects it accurately."
    }
  },
  "Conference": {
    "mode": "regex",
    "tags": {
      "NeurIPS": ["neurips", "\\bnips\\b"]
    }
  }
}

Customizing the prompt (taxonomy.py)

taxonomy.py dynamically builds the Ollama JSON Schema and system prompt from taxonomy.json.

Note on PROMPT_FOOTER: Inside taxonomy.py, the PROMPT_FOOTER constant contains negative rules and few-shot examples tailored to the default Codabench taxonomy (Machine Learning Domain, Fields of Application, etc.). If you use a heavily customized or completely different taxonomy, you should edit PROMPT_FOOTER in taxonomy.py to match your own rules and examples.


Script Options

1. export.py

Flag Description Default
-o, --output Output JSON path output/competitions_to_tag.json
-a, --all Export all competitions (instead of untagged only) Disabled
-l, --limit Maximum number of competitions to export All

2. predict.py

Flag Description Default
-i, --input Input competitions JSON output/competitions_to_tag.json
-o, --output Output predicted tags JSON output/predicted_tags.json
--taxonomy Custom taxonomy definitions JSON taxonomy.json
-m, --model Ollama model name qwen2.5:14b
-w, --workers Parallel worker threads 2
--ollama-url Ollama server URL http://localhost:11434
--output-csv Optional CSV export path None
-l, --limit Limit number of competitions to process All
--think Enable native thinking mode for reasoning models (e.g. qwen3:14b) Disabled
--num-predict Maximum tokens to generate per competition (recommended 2048 with --think for models like qwen3:14b) 512

3. import_tags.py

Flag Description Default
-i, --input Input predicted tags JSON output/predicted_tags.json
--dry-run Preview tag assignments without modifying the database Disabled
--clear-existing Clear existing tags on competitions before adding new ones Disabled

Tip: You can use -h or --help with any script to see all available options and their descriptions.

About

Lightweight 3-step CLI pipeline to automatically classify and tag Codabench competitions using LLMs and regex.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages