Downloads · 30 days
0
Jpcosta90/cosdoc
cosdoc is a machine learning model from Jpcosta90. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
CosDoc is a visual document embedding model trained with supervised metric learning and hard-example selection via a Reinforcement Learning professor network.
Downloads · 30 days
0
Access
Public
Updated Jun 9, 2026
Repo size
182 MB
Likes
0
Public
Click a slice to open those files.
.pt182 MB · 100%
From the Hugging Face model README
CosDoc is a visual document embedding model trained with supervised metric learning and hard-example selection via a Reinforcement Learning professor network.
Pooler variant: Attention nq=1 (baseline) — Standard attention pooler, num_queries=1.
| Component | Value |
|---|---|
| Backbone | InternVL3-2B (OpenGVLab/InternVL3-2B) |
| Cut layer | 27 |
| Pooler | attention (num_queries=1) |
| Embedding dim | 1536 |
| Loss | Sub-Center CosFace (m=0.35, s=32, k=3) |
| Embedding prompt | <image> Analyze this document |
| Dataset | EER |
|---|---|
| LA-CDIP (5-fold CV) | 1.44% |
Source run: Sprint3b_S0_subcenter_cosface_seed42_s32k3_fase1_E10
import torch
from huggingface_hub import hf_hub_download
from cavl_doc.models.backbone_loader import load_model
from cavl_doc.models.modeling_cavl import build_cavl_model
device = "cuda" if torch.cuda.is_available() else "cpu"
# Download fine-tuned weights
ckpt_path = hf_hub_download(repo_id="Jpcosta90/cosdoc", filename="best_model.pt")
ckpt = torch.load(ckpt_path, map_location=device, weights_only=False)
cfg = ckpt["config"]
backbone, _, tokenizer, _, _ = load_model("InternVL3-2B")
model = build_cavl_model(
backbone=backbone,
cut_layer=cfg["cut_layer"],
pooler_type=cfg["pooler_type"],
num_queries=cfg.get("num_queries", 1),
)
model.pool.load_state_dict(ckpt["siam_pool"])
model.head.load_state_dict(ckpt["siam_head"])
model.eval().to(device)
@misc{cosdoc2026,
title = {CosDoc: Cosine-Margin Document Embeddings with RL-guided Hard Mining},
author = {Costa, João Paulo},
year = {2026},
url = {https://huggingface.co/Jpcosta90/cosdoc}
}