Downloads · 30 days
0
cometadata/funding-parsing-and-extraction-Llama-3.1-8B-Instruct-lora
funding-parsing-and-extraction-Llama-3.1-8B-Instruct-lora is a machine learning model from cometadata. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Two-stage LoRA for joint funding-statement extraction (stage 1) and funder parsing (stage 2), trained on top of meta-llama/Llama-3.1-8B-Instruct.
Downloads · 30 days
0
Access
Public
Updated Apr 23, 2026
Repo size
1.3 GB
Likes
0
Public
Click a slice to open those files.
.safetensors1.3 GB · 100%
From the Hugging Face model README
Two-stage LoRA for joint funding-statement extraction (stage 1) and
funder parsing (stage 2), trained on top of
meta-llama/Llama-3.1-8B-Instruct.
sft/ # Stage A: supervised fine-tuning LoRA adapter
dapo/ # Stage B: DAPO (RL) LoRA adapter — applied after SFT is merged
Each folder is a standard PEFT LoRA: adapter_config.json +
adapter_model.safetensors.
Given a research article (or a chunk of one), the adapter produces funding metadata in two stages:
Both stages share the same weights; only the system prompt changes.
Both stages must be called with the exact prompts below.
You are a funding statement extractor. Given an article or text chunk, identify all funding acknowledgment statements. Return ONLY valid JSON in this exact format: {"statements": ["statement1", "statement2", ...]}. Each statement must be copied verbatim from the source text. If no funding statements exist, return {"statements": []}. Do not include any text outside the JSON object.
User message: the article text (or chunk) as-is.
You are an expert at extracting structured funding metadata from academic papers. Given a funding statement, extract all funders and their associated awards. Return a JSON array of funder objects. Each funder has:
- "funder_name": string or null
- "awards": array of objects with "award_ids" (array of strings), "funding_scheme" (array of strings), and "award_title" (array of strings)
Return ONLY the JSON array, no other text.
User message:
Extract funding information from the following statement:
<funding statement here>
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
BASE = "meta-llama/Llama-3.1-8B-Instruct"
REPO = "cometadata/funding-parsing-and-extraction-Llama-3.1-8B-Instruct-lora"
tokenizer = AutoTokenizer.from_pretrained(BASE)
model = AutoModelForCausalLM.from_pretrained(BASE, torch_dtype=torch.bfloat16, device_map="auto")
# Stage A: apply and merge the SFT adapter
model = PeftModel.from_pretrained(model, REPO, subfolder="sft")
model = model.merge_and_unload()
# Stage B: apply and merge the DAPO adapter on top of the SFT-merged model
model = PeftModel.from_pretrained(model, REPO, subfolder="dapo")
model = model.merge_and_unload()
model.eval()
The DAPO adapter's deltas are computed relative to the SFT-merged base, so the adapters must be applied in order: SFT first, then DAPO.
SYSTEM_EXTRACT = (
"You are a funding statement extractor. Given an article or text chunk, "
"identify all funding acknowledgment statements. Return ONLY valid JSON "
'in this exact format: {"statements": ["statement1", "statement2", ...]}. '
"Each statement must be copied verbatim from the source text. "
'If no funding statements exist, return {"statements": []}. '
"Do not include any text outside the JSON object."
)
def extract(article_text: str) -> str:
messages = [
{"role": "system", "content": SYSTEM_EXTRACT},
{"role": "user", "content": article_text},
]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt"
).to(model.device)
out = model.generate(inputs, max_new_tokens=512, do_sample=False)
return tokenizer.decode(out[0, inputs.shape[1]:], skip_special_tokens=True)
SYSTEM_PARSE = (
"You are an expert at extracting structured funding metadata from academic papers. "
"Given a funding statement, extract all funders and their associated awards. "
"Return a JSON array of funder objects. Each funder has:\n"
'- "funder_name": string or null\n'
'- "awards": array of objects with "award_ids" (array of strings), '
'"funding_scheme" (array of strings), and "award_title" (array of strings)\n'
"Return ONLY the JSON array, no other text."
)
def parse(funding_statement: str) -> str:
user = f"Extract funding information from the following statement:\n\n{funding_statement}"
messages = [
{"role": "system", "content": SYSTEM_PARSE},
{"role": "user", "content": user},
]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt"
).to(model.device)
out = model.generate(inputs, max_new_tokens=1024, do_sample=False)
return tokenizer.decode(out[0, inputs.shape[1]:], skip_special_tokens=True)
Articles longer than ~7500 tokens are split into overlapping 7500-token chunks with 1024 overlap at training time. For inference on long documents, apply stage 1 to each chunk, dedupe/concat the extracted statements, then pass the joined text to stage 2 once per article.
meta-llama/Llama-3.1-8B-Instructtarget_modules=all-linear
(q,k,v,o,gate,up,down proj)cometadata/funding-extraction-artifact-data-mix-grpo-mixed-reward
dataset (articles + gold funding statements + structured funder metadata)eps_clip_low=0.2, eps_clip_high=0.28, token-mean loss reduction)use_kl_loss=true (coef=0.001), entropy_loss_coef=0.01
— essential to prevent the all-empty collapse we observed without
regularizationtemperature=0.9, top_p=0.9, n_samples=16 per prompt,
step-wise trajectories (10 extract rollouts + 1 parse rollout per article){"statements": []}), so
the chunk component was dropped in favor of KL / entropy regularization.r = 0.50 · funder_F0.5 + 0.40 · award_id_F0.5 + 0.10 · flat_award_id_F0.5
with soft ID matching (edit-distance-1 partial credit on award_id).
Empty gold ↔ empty prediction gets r=1.0; mismatched empty prediction with
non-empty gold gets r=0.0.
| metric | value |
|---|---|
| reward/avg_raw_reward | ~0.90 |
| reward/avg_pass_at_16 | ~0.99 |
| avg response length | ~30 tokens |
Best single step: reward 0.941, pass@16 1.0 at step 33/36.
Training code: [github TODO — the rl/ directory of the
funding-statement-identification repo].
Trained by the comet-data / funding extraction effort, 2026-04.