Text Generation
Transformers
Safetensors
English
qwen3
information-extraction
named-entity-recognition
relation-extraction
grpo
reinforcement-learning
scientific-text
biomedical
conversational
text-generation-inference
Instructions to use InternScience/Agents-K1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use InternScience/Agents-K1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="InternScience/Agents-K1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("InternScience/Agents-K1") model = AutoModelForMultimodalLM.from_pretrained("InternScience/Agents-K1") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use InternScience/Agents-K1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "InternScience/Agents-K1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "InternScience/Agents-K1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/InternScience/Agents-K1
- SGLang
How to use InternScience/Agents-K1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "InternScience/Agents-K1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "InternScience/Agents-K1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "InternScience/Agents-K1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "InternScience/Agents-K1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use InternScience/Agents-K1 with Docker Model Runner:
docker model run hf.co/InternScience/Agents-K1
File size: 6,654 Bytes
1cdc247 da3f3a9 4b93c32 1a11a5e 1cdc247 4b93c32 1cdc247 4b93c32 1cdc247 4b93c32 1cdc247 4b93c32 1cdc247 4b93c32 da3f3a9 4b93c32 1cdc247 4b93c32 1cdc247 4b93c32 1cdc247 4b93c32 da3f3a9 4b93c32 1a11a5e 4b93c32 1cdc247 4b93c32 1cdc247 4b93c32 1cdc247 4b93c32 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | ---
license: apache-2.0
language:
- en
library_name: transformers
pipeline_tag: text-generation
base_model: Qwen/Qwen3-4B-Instruct-2507
tags:
- information-extraction
- named-entity-recognition
- relation-extraction
- grpo
- reinforcement-learning
- qwen3
- scientific-text
- biomedical
---
# Agents-K1
**Knowledge extraction model in Agents-K1** is a 4B-parameter language model fine-tuned from
[`Qwen/Qwen3-4B-Instruct-2507`](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507)
with **GRPO** (Group Relative Policy Optimization) on the information-extraction
corpus, targeting **Named Entity Recognition (NER)** and **Relation Extraction (RE)**
in English scientific and general-domain text.
The model produces structured JSON extractions with explicit step-by-step
reasoning, enabling its use as a building block in downstream knowledge-graph
construction, citation linking, and multi-hop QA pipelines.
## Highlights
- **+3.3 absolute F1** averaged over 10 NER/RE benchmarks vs. the
Qwen3-4B-Instruct base model, with **gains on every dataset evaluated**
(including held-out CrossNER domains).
- Trained with rule-based rewards (format + JSON validity + entity/relation F1),
no human preference data required.
- Outputs follow a strict `<think>β¦</think><answer>β¦</answer>` schema, making
reasoning auditable and JSON parsing reliable.
## Intended use
Designed as an extraction backbone for:
- Scientific-literature mining (entities/relations in biomedicine, chemistry,
CS, etc.)
- Knowledge-graph construction
- Pre-processing for retrieval / multi-hop QA systems
Not intended for general-purpose chat β it has been specialized for structured
extraction.
## Usage
The model uses the same chat template as Qwen3-4B-Instruct and expects a
schema-driven user prompt. The reply will contain a `<think>` block followed by
an `<answer>` block with a JSON object.
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "InternScience/Agents-K1"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype="bfloat16", device_map="auto")
system = (
"You are an expert in information extraction. Given a task instruction "
"with schema definitions and input text, extract the required information.\n\n"
"You should think step by step about the extraction task, then provide "
"your answer in JSON format.\n\n"
"Format your response as:\n"
"<think>\nYour step-by-step reasoning...\n</think>\n"
"<answer>\nYour JSON extraction result here\n</answer>"
)
user = (
"You are an expert in named entity recognition. Please extract entities "
"that match the schema definition from the input. Return an empty list if "
"the entity type does not exist. Please respond in the format of a JSON "
"dictionary.\n\n"
'Entity types to extract: ["person", "organization", "location"]\n\n'
"Input text: Marie Curie worked at the University of Paris.\n\n"
"Please think step by step and respond in the following format:\n"
"<think>\nYour reasoning process...\n</think>\n"
"<answer>\nYour JSON extraction result\n</answer>"
)
messages = [{"role": "system", "content": system},
{"role": "user", "content": user}]
inputs = tok.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)
print(tok.decode(out[0][inputs.shape[-1]:], skip_special_tokens=True))
```
For RE, replace the user template with `Relation types to extract: [...]`
and a relation-extraction instruction; the output schema is a JSON dict mapping
relation types to lists of `{head, tail}` pairs.
## Training data
Training data comes from **IEPile**, restricted to:
- English NER and RE tasks
- 22 source datasets, mixing scientific (SciERC, GENIA_NER, BC5CDR, BC2GM,
BC4CHEMD, AnatEM, NCBI) and general-domain (CoNLL2003, conll04, FabNER,
MultiNERD, NYT11, kbp37, β¦) corpora
| Split | Size | Notes |
|-----------:|-------:|-------|
| Train | 14,400 | 90/10 split, seed=42; each source capped to balance the mix |
| Validation | 1,600 | |
70% of samples have non-empty gold labels; 30% are empty-label cases (to prevent
the model from defaulting to non-empty outputs).
## Training procedure
- **Algorithm:** GRPO (PPO without a critic), implemented in
[veRL](https://github.com/volcengine/verl).
- **Reward** β \[0, 1\]:
- format reward: `0.1 Β· π[has <think>] + 0.1 Β· π[has <answer>]`
- JSON validity: `0.1 Β· π[valid JSON dict]` (or `0.05` for non-dict valid JSON)
- task F1: `0.7 Β· F1(pred, gold)` β entity-set F1 for NER, triple-set F1 for RE
## Evaluation
Reported numbers are micro-F1 on each benchmark's official test split, using
the same prompt template as training. Gains are **base β Agents-K1 (GRPO)**.
| Dataset | Task | n | Base F1 | Agent-K1 F1 | Ξ |
|---------------------------------|:----:|------:|--------:|--------------:|------:|
| CoNLL2003 | NER | 3,184 | 0.6547 | **0.7007** | +0.046 |
| NCBI-Disease | NER | 937 | 0.6737 | **0.7340** | +0.060 |
| BC5CDR | NER | 4,788 | 0.7126 | **0.7494** | +0.037 |
| CrossNER β AI *(held-out)* | NER | 430 | 0.4862 | **0.5400** | +0.054 |
| CrossNER β Literature *(held)* | NER | 416 | 0.5462 | **0.5736** | +0.027 |
| CrossNER β Music *(held)* | NER | 457 | 0.5791 | **0.6050** | +0.026 |
| CrossNER β Politics *(held)* | NER | 650 | 0.6611 | **0.6855** | +0.024 |
| CrossNER β Science *(held)* | NER | 532 | 0.5928 | **0.6132** | +0.020 |
| SciERC | NER | 397 | 0.1166 | **0.1270** | +0.010 |
| conll04 | RE | 287 | 0.2933 | **0.3181** | +0.025 |
| **Average** | | | 0.5317 | **0.5647** | **+0.033** |
All 10/10 benchmarks improve, including the 5 CrossNER domains that are
**not** in the training mix β evidence of generalization rather than mere
fitting to in-distribution sources.
## Limitations
- **Schema-driven prompting required.** Free-form questions will likely
return malformed JSON; always supply explicit entity / relation type lists.
## License
Released under the **Apache-2.0** license, following the upstream
[Qwen3-4B-Instruct-2507](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507)
license. Users must also comply with the licenses of the IEPile component
datasets when using this model in derivative works.
|