qiaojin/PubMedQA
Viewer β’ Updated β’ 274k β’ 38.4k β’ 336
How to use Gyeti123/wrag2-text-classifier with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="Gyeti123/wrag2-text-classifier") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("Gyeti123/wrag2-text-classifier", device_map="auto")WRAG 2.0 is a novel neural architecture that uses dynamic weight retrieval during the forward pass to achieve domain specialization without retraining the base model.
Trained on 3 domains with only 500 samples per domain (5 epochs):
| Domain | Accuracy |
|---|---|
| Medical (PubMedQA) | 70% |
| Legal (LexGLUE) | 84% |
| Code (CodeSearchNet) | 95% |
| Average | 83% |
from modeling_wrag2 import WRAG2TextModel
import torch
# Load model
model = WRAG2TextModel(
base_model_name="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
num_shards=10,
k=3,
num_wr_layers=3
)
# Load trained weights
state_dict = torch.load("pytorch_model.bin")
model.load_state_dict(state_dict, strict=False)
# Move to device
device = "cuda" if torch.cuda.is_available() else "cpu"
model = model.to(device)
model.eval()
# Inference
text = ["Question: What is the treatment for diabetes?"]
inputs = model.tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=256).to(device)
with torch.no_grad():
logits, shard_scores = model(**inputs)
prediction = logits.argmax(dim=-1)
print(f"Prediction: {prediction.item()}") # 0 or 1
Input Text
β
Frozen TinyLlama-1.1B (feature extraction)
β
Mean Pooling
β
Weight Retrieval Layer 1 (10 shards, k=3)
β ReLU
Weight Retrieval Layer 2 (10 shards, k=3)
β ReLU
Weight Retrieval Layer 3 (10 shards, k=3)
β ReLU
Classification Head (2 classes)
β
Output
pip install torch transformers huggingface_hub
WRAG 2.0 uses dynamic weight retrieval:
This allows the model to specialize for different domains without retraining the base model!
@misc{wrag2-2025,
title={WRAG 2.0: Weight-Retrieval Augmented Generation},
year={2025},
url={https://huggingface.co/YOUR_USERNAME/wrag2-text-classifier}
}
Apache 2.0
Issues and pull requests welcome!