BGE-M3 relation encoder (LoRA)

LoRA adapter (r=8, alpha=16, on query/key/value) for BAAI/bge-m3. It scores how relevant a knowledge-graph relation is to a question. It was fine-tuned contrastively on WebQSP train questions paired with relation names (3 epochs, lr 1e-4, temperature 0.1). Questions are split so that train and dev share no entities.

Usage

Before encoding, turn each relation into text: replace . and _ with spaces. Encode with CLS pooling and L2 normalisation. The score is the cosine similarity between the question and relation embeddings.

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()

def encode(texts, max_len):
    b = tok(texts, max_length=max_len, truncation=True, padding=True, return_tensors="pt")
    with torch.no_grad():
        h = model(**b).last_hidden_state[:, 0]
    return torch.nn.functional.normalize(h, dim=-1)

q = encode(["what country is the grand bahama island in"], 96)
r = encode(["location location containedby", "people person nationality"], 48)
print(q @ r.T)
Downloads last month
19
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for minhnvm/bge-m3-relation-lora

Base model

BAAI/bge-m3
Adapter
(35)
this model