Instructions to use pat-jj/text2graph-llama-3.2-3b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pat-jj/text2graph-llama-3.2-3b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="pat-jj/text2graph-llama-3.2-3b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("pat-jj/text2graph-llama-3.2-3b") model = AutoModelForCausalLM.from_pretrained("pat-jj/text2graph-llama-3.2-3b") 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]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use pat-jj/text2graph-llama-3.2-3b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pat-jj/text2graph-llama-3.2-3b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pat-jj/text2graph-llama-3.2-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/pat-jj/text2graph-llama-3.2-3b
- SGLang
How to use pat-jj/text2graph-llama-3.2-3b 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 "pat-jj/text2graph-llama-3.2-3b" \ --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": "pat-jj/text2graph-llama-3.2-3b", "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 "pat-jj/text2graph-llama-3.2-3b" \ --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": "pat-jj/text2graph-llama-3.2-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use pat-jj/text2graph-llama-3.2-3b with Docker Model Runner:
docker model run hf.co/pat-jj/text2graph-llama-3.2-3b
text2graph-llama-3.2-3b
This model is a fine-tuned version of unsloth/Llama-3.2-3B-Instruct on a text2triple dataset curated by Sonnet-3.5.
This model has much faster inference speed than our previous trained T5-based model. Also, it performs better for longer (> 512 tokens) input.
Example Input:
"William Gerald Standridge (November 27, 1953 – April 12, 2014) was an American stock car racing driver. He was a competitor in the NASCAR Winston Cup Series and Busch Series."
Example Output:
(S> William gerald standridge| P> Nationality| O> American),
(S> William gerald standridge| P> Occupation| O> Stock car racing driver),
(S> William gerald standridge| P> Competitor| O> Busch series),
(S> William gerald standridge| P> Competitor| O> Nascar winston cup series),
(S> William gerald standridge| P> Birth date| O> November 27, 1953),
(S> William gerald standridge| P> Death date| O> April 12, 2014)
How to Use?
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "pat-jj/text2graph-llama-3.2-3b"
def load_model_and_tokenizer():
# Load the model and tokenizer
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Set up chat template
tokenizer.chat_template = tokenizer.chat_template or "llama-3.1"
return model, tokenizer
def generate_triples(model, tokenizer, input_text, max_length=2048):
# Format the input using chat template
messages = [{
"role": "user",
"content": f"Convert the following text to triples:\n\nText: {input_text}"
}]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
# Tokenize input
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
# Generate response
outputs = model.generate(
**inputs,
max_length=max_length,
num_return_sequences=1,
temperature=0.7,
do_sample=True,
pad_token_id=tokenizer.pad_token_id
)
# Decode and return the response
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
def main():
print("Loading model and tokenizer...")
model, tokenizer = load_model_and_tokenizer()
print("\nModel loaded! Enter text to convert to triples (type 'quit' to exit):")
while True:
user_input = input("\nEnter text: ")
if user_input.lower() == 'quit':
break
print("\nGenerating triples...")
response = generate_triples(model, tokenizer, user_input)
print("\nResponse:", response)
if __name__ == "__main__":
main()
Training procedure
Training hyperparameters
The following hyperparameters were used during training:
- learning_rate: 2e-05
- train_batch_size: 3
- eval_batch_size: 1
- seed: 42
- distributed_type: multi-GPU
- num_devices: 3
- gradient_accumulation_steps: 3
- total_train_batch_size: 27
- total_eval_batch_size: 3
- optimizer: Use adamw_torch with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
- lr_scheduler_type: cosine
- lr_scheduler_warmup_ratio: 0.1
- num_epochs: 1
Framework versions
- Transformers 4.48.1
- Pytorch 2.1.2+cu121
- Datasets 2.21.0
- Tokenizers 0.21.0
Cite Our Paper
@misc{jiang2025rasretrievalandstructuringknowledgeintensivellm,
title={RAS: Retrieval-And-Structuring for Knowledge-Intensive LLM Generation},
author={Pengcheng Jiang and Lang Cao and Ruike Zhu and Minhao Jiang and Yunyi Zhang and Jimeng Sun and Jiawei Han},
year={2025},
eprint={2502.10996},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2502.10996},
}
- Downloads last month
- 69
Model tree for pat-jj/text2graph-llama-3.2-3b
Base model
meta-llama/Llama-3.2-3B-Instruct