Latensis STS — Turkish Semantic Textual Similarity

Understanding Beyond the Visible

Latensis STS is a Turkish semantic textual similarity model fine-tuned on top of Latensis RoBERTa Base using a two-stage training pipeline: NLI pretraining → STS fine-tuning with CoSENT loss.

Benchmark Results

Evaluated on TrGLUE STS-b test set (300 examples).

Metric Our Model Emrecan
Pearson 0.7722 0.8340
Spearman 0.7976 0.8300

Emrecan model uses 482k NLI + full STS-b-TR. Our model uses only 50k NLI examples (~10x less data).

Training Details

Property Value
Base model Latensis RoBERTa Base (500k steps, val loss 3.21)
Stage 1 NLI pretraining — 50k examples (emrecan/all-nli-tr)
Stage 2 STS fine-tuning — TrGLUE STS-b (2,458 train examples)
Loss function CoSENT Loss
Pooling Mean pooling
Tokenizer Hecemen Unigram 128k
Learning rate 4e-6
Batch size 16

Usage

import torch
import torch.nn as nn
import sentencepiece as spm
from transformers import RobertaModel, RobertaConfig
from huggingface_hub import hf_hub_download

# Load tokenizer
spm_path = hf_hub_download(
    repo_id="mursideaki/hecemen-tokenizer-unigram-128k",
    filename="tr_unigram_tokenizer.model"
)
sp = spm.SentencePieceProcessor()
sp.load(spm_path)

PAD_ID = sp.piece_to_id("<pad>")
BOS_ID = sp.piece_to_id("<s>")
EOS_ID = sp.piece_to_id("</s>")
MAX_LENGTH = 128

# Load model
config = RobertaConfig.from_pretrained("mursideaki/latensis-sts-tr")

class STSModel(nn.Module):
    def __init__(self, config):
        super().__init__()
        self.roberta = RobertaModel(config)

    def mean_pool(self, hidden, mask):
        mask_exp = mask.unsqueeze(-1).float()
        return (hidden * mask_exp).sum(1) / mask_exp.sum(1).clamp(min=1e-9)

    def forward(self, input_ids, attention_mask):
        out = self.roberta(input_ids=input_ids, attention_mask=attention_mask)
        return self.mean_pool(out.last_hidden_state, attention_mask)

model = STSModel(config)
# Load weights from HuggingFace
from transformers import RobertaModel
roberta = RobertaModel.from_pretrained("mursideaki/latensis-sts-tr")
model.roberta = roberta
model.eval()

def encode(text):
    ids  = sp.encode_as_ids(str(text))
    ids  = [BOS_ID] + ids[:MAX_LENGTH-2] + [EOS_ID]
    mask = [1] * len(ids)
    if len(ids) < MAX_LENGTH:
        pad_len = MAX_LENGTH - len(ids)
        ids  = ids  + [PAD_ID] * pad_len
        mask = mask + [0]      * pad_len
    return ids, mask

def similarity(text1, text2):
    ids1, mask1 = encode(text1)
    ids2, mask2 = encode(text2)

    with torch.no_grad():
        e1 = model(
            torch.tensor([ids1], dtype=torch.long),
            torch.tensor([mask1], dtype=torch.long)
        )
        e2 = model(
            torch.tensor([ids2], dtype=torch.long),
            torch.tensor([mask2], dtype=torch.long)
        )

    e1 = nn.functional.normalize(e1, dim=-1)
    e2 = nn.functional.normalize(e2, dim=-1)
    return (e1 * e2).sum().item()

score = similarity(
    "Köpek bahçede koşuyor.",
    "Bir köpek dışarıda koşuyor."
)
print(f"Similarity: {score:.4f}")  # → ~0.95

Companion Models

Citation

@misc{latensis2026,
  author    = {Mürşide Aki},
  title     = {Latensis: Turkish NLP Model Suite},
  year      = {2026},
  publisher = {Hugging Face},
  url       = {https://huggingface.co/mursideaki/latensis-sts-tr}
}

License

MIT

Downloads last month
-
Safetensors
Model size
0.2B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support