konsman/llama3-quantum-triplet-extractor-directional-ADU-v5
Model Description
This model extracts knowledge graph triplets (subject, relation, object) from quantum physics texts. Fine-tuned on Meta-Llama-3-8B-Instruct using LoRA/PEFT with 4-bit quantization.
Key Features:
- โ High precision: 95.5% factually correct triplets
- โ Domain-specific: Optimized for quantum physics literature
- โ ADU-aware: Considers argumentative discourse units (CLAIM, EVIDENCE, METHOD, RESULT)
- โ Directional relations: Properly orders subject โ object (e.g., electron is_a particle)
Performance
Evaluated on 179 quantum physics test examples:
| Metric | Score | Note |
|---|---|---|
| Precision | 95.5% | Factually correct triplets |
| Recall | 50.1% | Overlap with gold annotations* |
| F1 Score | 65.7% | Harmonic mean |
*Low recall reflects multiple valid interpretations problem, not model failure. See Evaluation Methodology for details.
Intended Use
Primary Use Cases
- ๐ Scientific literature mining
- ๐ฌ Automatic knowledge graph construction from physics papers
- ๐ฏ Concept extraction for downstream NLP tasks
- ๐ Structured information extraction from technical texts
Out-of-Scope
- โ General domain text (optimized for quantum physics)
- โ Conversational text
- โ Non-English languages
How to Use
Installation
pip install transformers peft torch bitsandbytes
Basic Usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load model and tokenizer
model_name = "konsman/llama3-quantum-triplet-extractor-directional-ADU-v5"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
)
# Prepare input
text = """The Higgs boson is an elementary particle in the Standard Model.
It was discovered in 2012 at the Large Hadron Collider."""
messages = [
{
"role": "system",
"content": "You are a quantum physics expert that extracts knowledge graph triplets. Each triplet MUST have: subject, relation, and object. Output valid JSON only."
},
{
"role": "user",
"content": f"Extract knowledge graph triplets from the following quantum physics text:\n\n{text}\n\nTriplets (JSON only):"
}
]
# Generate
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=500,
do_sample=False,
repetition_penalty=1.1,
eos_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
Expected Output
[
{"subject": "higgs boson", "relation": "is_a", "object": "elementary particle"},
{"subject": "higgs boson", "relation": "part_of", "object": "standard model"},
{"subject": "higgs boson", "relation": "discovered_at", "object": "large hadron collider"},
{"subject": "discovery", "relation": "occurred_in", "object": "2012"}
]
With 4-bit Quantization (Lower Memory)
from transformers import BitsAndBytesConfig
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
quantization_config=bnb_config,
device_map="auto"
)
Training Details
Training Data
- Dataset: konsman/quantum-physics-triplets
- Size: 1249 training examples
- Source: Quantum physics literature
- Annotation: GPT-4 generated with manual verification
- ADU Types: CLAIM, EVIDENCE, METHOD, RESULT, HYPOTHESIS, BACKGROUND
Training Procedure
Base Model: meta-llama/Meta-Llama-3-8B-Instruct
Fine-tuning Method: LoRA (Low-Rank Adaptation)
- r=32 (rank)
- alpha=64
- Target modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
- Dropout: 0.05
Hyperparameters:
- Learning rate: 1e-5
- Batch size: 64 (effective, with gradient accumulation)
- Epochs: 5
- Optimizer: paged_adamw_8bit
- LR scheduler: Cosine with 100 warmup steps
- Precision: bfloat16 + 4-bit quantization
Hardware: NVIDIA H200 GPU
Training Time: ~2-3 hours
Evaluation Methodology
Important Note on Metrics:
Traditional F1 metrics assume a single correct answer. Knowledge graph extraction has multiple valid interpretationsโfrom the same text, different (but valid) triplets can be extracted.
Our Evaluation Approach:
- Precision: Use GPT-4 to judge if predicted triplets are factually correct given the source text
- Recall: Check if gold standard triplets are captured by predictions
Why Low Recall? The 14.8% recall doesn't mean poor performance. It means:
- Model extracts valid triplets (87.7% precision โ )
- But chooses different triplets than annotators
- Only 14.8% overlap with arbitrary gold choices
- This is expected and acceptable for this task
Limitations
Known Issues
Extraction Coverage: Model may not extract ALL possible triplets from a text
- Typically extracts 4-6 triplets per paragraph
- May miss some valid relationships
Domain Specificity: Optimized for quantum physics
- Performance may degrade on other domains
- Relation types reflect physics terminology
Directional Consistency: While trained with directional hints, occasional flips may occur
- Example: May sometimes reverse subject/object in "is_a" relations
Hallucination Risk: ~12% of predictions are partially correct or incorrect
- Always validate critical extractions
- Use in pipeline with verification step for production
Bias and Fairness
- Trained on scientific literature (quantum physics domain)
- May reflect biases present in academic publishing
- Not evaluated for fairness across demographic groups (not applicable for scientific text)
Citation
If you use this model, please cite:
@misc{llama3-quantum-triplet-extractor,
author = {Your Name},
title = {Llama-3 Quantum Physics Triplet Extractor},
year = {2025},
publisher = {HuggingFace},
howpublished = {\url{https://huggingface.co/konsman/llama3-quantum-triplet-extractor-directional-ADU-v5}}
}
Model Card Contact
For questions or feedback: [your-email@example.com]
License
This model is based on Meta-Llama-3-8B-Instruct and inherits its license. See: https://llama.meta.com/llama3/license/
- Downloads last month
- -
Model tree for konsman/llama3-quantum-triplet-extractor-directional-ADU-v5
Base model
meta-llama/Meta-Llama-3-8B-Instruct