minhnvm/bge-m3-relation-lora
scoring knowledge graph relations for a question
2 min read
This adapter scores how well a knowledge graph relation matches a given question and returns their similarity via cosine distance between vector embeddings. Built on top of BAAI/bge-m3 using LoRA (a lightweight add-on over the base model weights) by author minhnvm, it was trained contrastively on question and relation-name pairs from the WebQSP dataset with entity-disjoint train and dev splits. Useful for developers building question answering systems over knowledge graphs and linking questions to ontologies.
Key features
- LoRA adapter with rank r=8 and alpha=16 on the query, key, and value layers over BAAI/bge-m3.
- Uses CLS pooling and L2 embedding normalization to compute cosine similarity.
- Trained contrastively on the WebQSP dataset (3 epochs, lr 1e-4, temperature 0.1).
- Train and dev splits are separated so entities do not overlap.
What you can do
- Plug it into KGQA pipelines to select relevant knowledge graph relations for a user question.
- Use it in search and agentic systems to rank candidate paths and predicates.
- Pair it with relation-name preprocessing (replacing dots and underscores with spaces) before encoding.
Example
import torch
from transformers import AutoModel, AutoTokenizer
from peft import PeftModel
tok = AutoTokenizer.from_pretrained("BAAI/bge-m3")
model = PeftModel.from_pretrained(AutoModel.from_pretrained("BAAI/bge-m3"), "minhnvm/bge-m3-relation-lora").eval()
q = tok(["what country is the grand bahama island in"], max_length=96, truncation=True, padding=True, return_tensors="pt")
r = tok(["location location containedby", "people person nationality"], max_length=48, truncation=True, padding=True, return_tensors="pt")Read more
DetailsBase model: BAAI/bge-m3, library: peft, task: sentence-similarity.
Training: 3 epochs, learning rate 1e-4, temperature 0.1 on WebQSP.
Before encoding, replace dots and underscores in relation names with spaces.










Comments