You need to agree to share your contact information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this model content.

NMIXX-QWEN

This repository contains a gte-Qwen2-1.5B-instruct-based SentenceTransformer model fine-tuned with a triplet-loss setup on the nmixx-fin/NMIXX_train dataset. It produces high-quality sentence embeddings for Korean financial text, optimized for semantic similarity tasks in the finance domain.


How to Use

from transformers import AutoTokenizer, AutoModel
import torch
import torch.nn.functional as F

def last_token_pool(last_hidden_states, attention_mask):
    """
    Last token pooling for decoder-based models like GTE-Qwen
    """
    left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
    if left_padding:
        return last_hidden_states[:, -1]
    else:
        sequence_lengths = attention_mask.sum(dim=1) - 1
        batch_size = last_hidden_states.shape[0]
        return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]

# 1. Load tokenizer & model from Hugging Face Hub
repo_name = "nmixx-fin/nmixx-qwen"
tokenizer = AutoTokenizer.from_pretrained(repo_name)
model = AutoModel.from_pretrained(repo_name)

# 2. Move to GPU if available
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval()

# 3. Prepare input sentences
sentences = [
    "์ด ๋ชจ๋ธ์€ ํ•œ๊ตญ ๊ธˆ์œต ๋„๋ฉ”์ธ์— ํŠนํ™”๋œ ์ž„๋ฒ ๋”ฉ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.",
    "NMIXX ๋ฐ์ดํ„ฐ์…‹์œผ๋กœ fine-tuning๋œ sentence transformer์ž…๋‹ˆ๋‹ค."
]

# 4. Tokenize
encoded_input = tokenizer(
    sentences,
    padding=True,
    truncation=True,
    max_length=512,
    return_tensors="pt"
)
input_ids = encoded_input["input_ids"].to(device)
attention_mask = encoded_input["attention_mask"].to(device)

# 5. Forward pass (token embeddings)
with torch.no_grad():
    model_output = model(input_ids=input_ids, attention_mask=attention_mask)

# 6. Last Token Pooling (GTE-Qwen uses last token)
sentence_embeddings = last_token_pool(model_output.last_hidden_state, attention_mask)

# 7. L2 Normalization
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)

print("Sentence embeddings shape:", sentence_embeddings.shape)
print(sentence_embeddings.cpu())
Downloads last month
2
Safetensors
Model size
1.54B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for nmixx-fin/nmixx-qwen

Finetuned
(26)
this model

Dataset used to train nmixx-fin/nmixx-qwen