mrpeerat/Thai-Sentence-Vector-Benchmark

Benchmark for Thai sentence representation

137

stars

191

commits

Jupyter Notebook

primary language

May 27, 2025

updated

natural-language-processing
nlp
sentence-embedding

README

Thai-Sentence-Vector-Benchmark

Benchmark for Thai sentence representation based on Thai STS-B, Text classification, and Retrieval datasets.

Motivation

Sentence representation plays a crucial role in NLP downstream tasks such as NLI, text classification, and STS. Recent sentence representation training techniques require NLI or STS datasets. However, no equivalent Thai NLI or STS datasets exist for sentence representation training. To address this problem, we create "Thai sentence vector benchmark" to demonstrate that we can train Thai sentence representation without any supervised dataset.

Our first preliminary results demonstrate that we can train a robust sentence representation model with an unsupervised technique called SimCSE. We show that it is possible to train SimCSE with 1.3 M sentences from Wikipedia within 2 hours on the Google Colab (V100), where the performance of SimCSE-XLM-R is similar to mDistil-BERT<-mUSE (train on > 1B sentences).

Moreover, we provide the Thai sentence vector benchmark. Our benchmark aims to evaluate the effectiveness of sentence embedding models on Thai zero-shot and transfer learning tasks. The tasks comprise of four tasks: Semantic ranking on STS-B, text classification (transfer), pair classification, and retrieval question answering (QA).

Install

conda create -n thai_sentence_vector_benchmark python==3.11.4
conda activate thai_sentence_vector_benchmark

# Select the appropriate PyTorch version based on your CUDA version
# CUDA 11.8
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 pytorch-cuda=11.8 -c pytorch -c nvidia
# CUDA 12.1
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 pytorch-cuda=12.1 -c pytorch -c nvidia
# CPU Only
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 cpuonly -c pytorch

pip install -e .

Reproduce the results

python scripts/eval_all.py \
--cohere_api_key <YOUR_COHERE_API_KEY> \
--openai_api_key <YOUR_OPENAI_API_KEY>

Usage

from sentence_transformers import SentenceTransformer
from thai_sentence_vector_benchmark.benchmark import ThaiSentenceVectorBenchmark

model = SentenceTransformer("intfloat/e5-mistral-7b-instruct")
benchmark = ThaiSentenceVectorBenchmark()
results = benchmark(
  model,
  task_prompts={
    "sts": "Instruct: Retrieve semantically similar text.\nQuery: ",
    "retrieval": "Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: ",
    "pair_classification": "Instruct: Retrieve parallel sentences.\nQuery: ",
    "text_classification": "Instruct: Classify the sentiment of the text.\nText: ",
  },
  batch_size=1, 
)
>> {
  "STS": {
    "sts_b": {"Spearman_Correlation": float},
    "Average": {"Spearman_Correlation": float},
  },
  "Text_Classification": {
    "wisesight": {"Accuracy": float, "F1": float},
    "wongnai": {"Accuracy": float, "F1": float},
    "generated_reviews": {"Accuracy": float, "F1": float},
    "Average": {"Accuracy": float, "F1": float},
  },
  "Pair_Classification": {
    "xnli": {"AP": float},
    "Average": {"AP": float},
  },
  "Retrieval": {
    "xquad": {"R@1": float, "MRR@10": float},
    "miracl": {"R@1": float, "MRR@10": float},
    "tydiqa": {"R@1": float, "MRR@10": float},
    "Average": {"R@1": float, "MRR@10": float},
  },
  "Average": float,
}

How do we train unsupervised sentence representation?

We provide simple and effective sentence embedding methods that do not require supervised labels (unsupervised learning) as follows:

SimCSE

ConGen

SCT

Why do we select these techniques?

  • Easy to train
  • Compatible with every model
  • Do not require any annotated dataset
  • The best sentence representation method (for now) in terms of the performance on STS and downstream tasks (SCT outperformed ConGen and SimCSE in their paper).

What about other techniques?

We also consider other techniques (supervised and unsupervised methods) in this repository. Currently, we have various methods tested on our benchmarks, such as:

  • Supervised learning: sentence-bert.
  • Multilingual sentence representation alignment: CL-ReLKT (NAACL'22)

Thai semantic textual similarity benchmark

Base ModelSpearman's Correlation (*100)Supervised?Latency(ms)
simcse-model-distil-m-bert44.277.22 ± 0.53
simcse-model-m-bert-thai-cased43.9511.66 ± 0.72
simcse-model-XLMR63.9810.95 ± 0.41
simcse-model-wangchanberta60.9510.54 ± 0.33
simcse-model-phayathaibert68.2811.4 ± 1.01
SCT-model-XLMR68.9010.52 ± 0.46
SCT-model-wangchanberta71.3510.61 ± 0.62
SCT-model-phayathaibert74.0610.64 ± 0.72
SCT-Distil-model-XLMR78.7810.69 ± 0.48
SCT-Distil-model-wangchanberta77.7710.86 ± 0.55
SCT-Distil-model-phayathaibert77.8911.01 ± 0.62
SCT-Distil-model-phayathaibert-bge-m376.71
ConGen-model-XLMR79.6910.79 ± 0.38
ConGen-model-wangchanberta79.2010.44 ± 0.5
ConGen-model-phayathaibert78.9010.32 ± 0.31
ConGen-BGE_M3-model-phayathaibert76.8210.91 ± 0.43
distiluse-base-multilingual-cased-v265.37:heavy_check_mark:9.38 ± 1.34
paraphrase-multilingual-mpnet-base-v280.49:heavy_check_mark:10.93 ± 0.55
BGE M-377.22:heavy_check_mark:23.5 ± 3.07
Cohere-embed-multilingual-v2.068.03:heavy_check_mark:

Thai transfer benchmark

Wisesight

Wongnai

Generated Review

Thai pair classification benchmark

Thai retrieval benchmark

XQuAD

Base ModelR@1MRR@10Supervised?Latency(second)
simcse-model-distil-m-bert18.2427.190.61
simcse-model-m-bert-thai-cased22.9430.291.02
simcse-model-XLMR52.0262.940.85
simcse-model-wangchanberta53.8765.510.81
simcse-model-phayathaibert73.9581.670.79
SCT-model-XLMR55.2965.231.24
SCT-model-wangchanberta66.3076.141.23
SCT-model-phayathaibert67.5676.141.19
SCT-Distil-model-XLMR68.9178.191.24
SCT-Distil-model-wangchanberta62.2772.531.35
SCT-Distil-model-phayathaibert71.4380.181.21
SCT-Distil-model-phayathaibert-bge-m380.5086.75
ConGen-model-XLMR71.7680.011.24
ConGen-model-wangchanberta70.9279.591.21
ConGen-model-phayathaibert71.8580.331.19
ConGen-BGE_M3-model-phayathaibert85.8090.481.3
distiluse-base-multilingual-cased-v249.1658.19:heavy_check_mark:1.05
paraphrase-multilingual-mpnet-base-v271.2679.63:heavy_check_mark:1.24
BGE M-390.5094.33:heavy_check_mark:7.22
Cohere-embed-multilingual-v2.082.5287.78:heavy_check_mark:XXX

MIRACL

Base ModelR@1MRR@10Supervised?Latency(second)
simcse-model-distil-m-bert28.5137.054.31
simcse-model-m-bert-thai-cased26.1936.116.66
simcse-model-XLMR34.9247.516.17
simcse-model-wangchanberta36.2948.966.09
simcse-model-phayathaibert43.2557.286.18
SCT-model-XLMR28.5140.8416.29
SCT-model-wangchanberta35.3348.1916.0
SCT-model-phayathaibert37.5251.0215.8
SCT-Distil-model-XLMR40.3851.6816.17
SCT-Distil-model-wangchanberta39.4350.6116.04
SCT-Distil-model-phayathaibert45.1656.5215.82
SCT-Distil-model-phayathaibert-bge-m364.8074.46
ConGen-model-XLMR43.1155.5116.4
ConGen-model-wangchanberta41.0653.3115.98
ConGen-model-phayathaibert44.3455.7715.97
ConGen-BGE_M3-model-phayathaibert70.4079.3315.83
distiluse-base-multilingual-cased-v217.7427.78:heavy_check_mark:9.84
paraphrase-multilingual-mpnet-base-v238.2049.65:heavy_check_mark:16.22
BGE M-379.6786.68:heavy_check_mark:91.27
Cohere-embed-multilingual-v2.066.9877.58:heavy_check_mark:XXX

TyDiQA

Base ModelR@1MRR@10Supervised?Latency(second)
simcse-model-distil-m-bert44.6951.391.6
simcse-model-m-bert-thai-cased45.0952.372.46
simcse-model-XLMR58.0664.722.35
simcse-model-wangchanberta62.6570.022.32
simcse-model-phayathaibert71.4378.162.28
SCT-model-XLMR49.2858.623.15
SCT-model-wangchanberta58.1968.053.21
SCT-model-phayathaibert63.4371.733.21
SCT-Distil-model-XLMR56.3665.183.3
SCT-Distil-model-wangchanberta56.2365.183.18
SCT-Distil-model-phayathaibert58.3267.423.21
SCT-Distil-model-phayathaibert-bge-m378.3784.01
ConGen-model-XLMR60.2968.563.28
ConGen-model-wangchanberta59.1167.423.19
ConGen-model-phayathaibert59.2467.693.15
ConGen-BGE_M3-model-phayathaibert83.3688.293.14
distiluse-base-multilingual-cased-v232.5042.20:heavy_check_mark:2.05
paraphrase-multilingual-mpnet-base-v254.3963.12:heavy_check_mark:3.16
BGE M-389.1293.43:heavy_check_mark:20.87
Cohere-embed-multilingual-v2.085.4590.33:heavy_check_mark:XXX

Thank you for the many codes from

Acknowledgments:

  • Can: proofread
  • Charin: proofread + idea

1_3JJRwT1f2zTK1hx36-qXdg (1)

Contributors

mrpeerat

119 commits

panuthept

31 commits

KornWtp

29 commits

sitiporn

9 commits

mrpeerat/Thai-Sentence-Vector-Benchmark

Benchmark for Thai sentence representation

137

stars

191

commits

Jupyter Notebook

primary language

May 27, 2025

updated

natural-language-processing
nlp
sentence-embedding

README

Thai-Sentence-Vector-Benchmark

Benchmark for Thai sentence representation based on Thai STS-B, Text classification, and Retrieval datasets.

Motivation

Sentence representation plays a crucial role in NLP downstream tasks such as NLI, text classification, and STS. Recent sentence representation training techniques require NLI or STS datasets. However, no equivalent Thai NLI or STS datasets exist for sentence representation training. To address this problem, we create "Thai sentence vector benchmark" to demonstrate that we can train Thai sentence representation without any supervised dataset.

Our first preliminary results demonstrate that we can train a robust sentence representation model with an unsupervised technique called SimCSE. We show that it is possible to train SimCSE with 1.3 M sentences from Wikipedia within 2 hours on the Google Colab (V100), where the performance of SimCSE-XLM-R is similar to mDistil-BERT<-mUSE (train on > 1B sentences).

Moreover, we provide the Thai sentence vector benchmark. Our benchmark aims to evaluate the effectiveness of sentence embedding models on Thai zero-shot and transfer learning tasks. The tasks comprise of four tasks: Semantic ranking on STS-B, text classification (transfer), pair classification, and retrieval question answering (QA).

Install

conda create -n thai_sentence_vector_benchmark python==3.11.4
conda activate thai_sentence_vector_benchmark

# Select the appropriate PyTorch version based on your CUDA version
# CUDA 11.8
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 pytorch-cuda=11.8 -c pytorch -c nvidia
# CUDA 12.1
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 pytorch-cuda=12.1 -c pytorch -c nvidia
# CPU Only
conda install pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 cpuonly -c pytorch

pip install -e .

Reproduce the results

python scripts/eval_all.py \
--cohere_api_key <YOUR_COHERE_API_KEY> \
--openai_api_key <YOUR_OPENAI_API_KEY>

Usage

from sentence_transformers import SentenceTransformer
from thai_sentence_vector_benchmark.benchmark import ThaiSentenceVectorBenchmark

model = SentenceTransformer("intfloat/e5-mistral-7b-instruct")
benchmark = ThaiSentenceVectorBenchmark()
results = benchmark(
  model,
  task_prompts={
    "sts": "Instruct: Retrieve semantically similar text.\nQuery: ",
    "retrieval": "Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: ",
    "pair_classification": "Instruct: Retrieve parallel sentences.\nQuery: ",
    "text_classification": "Instruct: Classify the sentiment of the text.\nText: ",
  },
  batch_size=1, 
)
>> {
  "STS": {
    "sts_b": {"Spearman_Correlation": float},
    "Average": {"Spearman_Correlation": float},
  },
  "Text_Classification": {
    "wisesight": {"Accuracy": float, "F1": float},
    "wongnai": {"Accuracy": float, "F1": float},
    "generated_reviews": {"Accuracy": float, "F1": float},
    "Average": {"Accuracy": float, "F1": float},
  },
  "Pair_Classification": {
    "xnli": {"AP": float},
    "Average": {"AP": float},
  },
  "Retrieval": {
    "xquad": {"R@1": float, "MRR@10": float},
    "miracl": {"R@1": float, "MRR@10": float},
    "tydiqa": {"R@1": float, "MRR@10": float},
    "Average": {"R@1": float, "MRR@10": float},
  },
  "Average": float,
}

How do we train unsupervised sentence representation?

We provide simple and effective sentence embedding methods that do not require supervised labels (unsupervised learning) as follows:

SimCSE

ConGen

SCT

Why do we select these techniques?

  • Easy to train
  • Compatible with every model
  • Do not require any annotated dataset
  • The best sentence representation method (for now) in terms of the performance on STS and downstream tasks (SCT outperformed ConGen and SimCSE in their paper).

What about other techniques?

We also consider other techniques (supervised and unsupervised methods) in this repository. Currently, we have various methods tested on our benchmarks, such as:

  • Supervised learning: sentence-bert.
  • Multilingual sentence representation alignment: CL-ReLKT (NAACL'22)

Thai semantic textual similarity benchmark

Base ModelSpearman's Correlation (*100)Supervised?Latency(ms)
simcse-model-distil-m-bert44.277.22 ± 0.53
simcse-model-m-bert-thai-cased43.9511.66 ± 0.72
simcse-model-XLMR63.9810.95 ± 0.41
simcse-model-wangchanberta60.9510.54 ± 0.33
simcse-model-phayathaibert68.2811.4 ± 1.01
SCT-model-XLMR68.9010.52 ± 0.46
SCT-model-wangchanberta71.3510.61 ± 0.62
SCT-model-phayathaibert74.0610.64 ± 0.72
SCT-Distil-model-XLMR78.7810.69 ± 0.48
SCT-Distil-model-wangchanberta77.7710.86 ± 0.55
SCT-Distil-model-phayathaibert77.8911.01 ± 0.62
SCT-Distil-model-phayathaibert-bge-m376.71
ConGen-model-XLMR79.6910.79 ± 0.38
ConGen-model-wangchanberta79.2010.44 ± 0.5
ConGen-model-phayathaibert78.9010.32 ± 0.31
ConGen-BGE_M3-model-phayathaibert76.8210.91 ± 0.43
distiluse-base-multilingual-cased-v265.37:heavy_check_mark:9.38 ± 1.34
paraphrase-multilingual-mpnet-base-v280.49:heavy_check_mark:10.93 ± 0.55
BGE M-377.22:heavy_check_mark:23.5 ± 3.07
Cohere-embed-multilingual-v2.068.03:heavy_check_mark:

Thai transfer benchmark

Wisesight

Wongnai

Generated Review

Thai pair classification benchmark

Thai retrieval benchmark

XQuAD

Base ModelR@1MRR@10Supervised?Latency(second)
simcse-model-distil-m-bert18.2427.190.61
simcse-model-m-bert-thai-cased22.9430.291.02
simcse-model-XLMR52.0262.940.85
simcse-model-wangchanberta53.8765.510.81
simcse-model-phayathaibert73.9581.670.79
SCT-model-XLMR55.2965.231.24
SCT-model-wangchanberta66.3076.141.23
SCT-model-phayathaibert67.5676.141.19
SCT-Distil-model-XLMR68.9178.191.24
SCT-Distil-model-wangchanberta62.2772.531.35
SCT-Distil-model-phayathaibert71.4380.181.21
SCT-Distil-model-phayathaibert-bge-m380.5086.75
ConGen-model-XLMR71.7680.011.24
ConGen-model-wangchanberta70.9279.591.21
ConGen-model-phayathaibert71.8580.331.19
ConGen-BGE_M3-model-phayathaibert85.8090.481.3
distiluse-base-multilingual-cased-v249.1658.19:heavy_check_mark:1.05
paraphrase-multilingual-mpnet-base-v271.2679.63:heavy_check_mark:1.24
BGE M-390.5094.33:heavy_check_mark:7.22
Cohere-embed-multilingual-v2.082.5287.78:heavy_check_mark:XXX

MIRACL

Base ModelR@1MRR@10Supervised?Latency(second)
simcse-model-distil-m-bert28.5137.054.31
simcse-model-m-bert-thai-cased26.1936.116.66
simcse-model-XLMR34.9247.516.17
simcse-model-wangchanberta36.2948.966.09
simcse-model-phayathaibert43.2557.286.18
SCT-model-XLMR28.5140.8416.29
SCT-model-wangchanberta35.3348.1916.0
SCT-model-phayathaibert37.5251.0215.8
SCT-Distil-model-XLMR40.3851.6816.17
SCT-Distil-model-wangchanberta39.4350.6116.04
SCT-Distil-model-phayathaibert45.1656.5215.82
SCT-Distil-model-phayathaibert-bge-m364.8074.46
ConGen-model-XLMR43.1155.5116.4
ConGen-model-wangchanberta41.0653.3115.98
ConGen-model-phayathaibert44.3455.7715.97
ConGen-BGE_M3-model-phayathaibert70.4079.3315.83
distiluse-base-multilingual-cased-v217.7427.78:heavy_check_mark:9.84
paraphrase-multilingual-mpnet-base-v238.2049.65:heavy_check_mark:16.22
BGE M-379.6786.68:heavy_check_mark:91.27
Cohere-embed-multilingual-v2.066.9877.58:heavy_check_mark:XXX

TyDiQA

Base ModelR@1MRR@10Supervised?Latency(second)
simcse-model-distil-m-bert44.6951.391.6
simcse-model-m-bert-thai-cased45.0952.372.46
simcse-model-XLMR58.0664.722.35
simcse-model-wangchanberta62.6570.022.32
simcse-model-phayathaibert71.4378.162.28
SCT-model-XLMR49.2858.623.15
SCT-model-wangchanberta58.1968.053.21
SCT-model-phayathaibert63.4371.733.21
SCT-Distil-model-XLMR56.3665.183.3
SCT-Distil-model-wangchanberta56.2365.183.18
SCT-Distil-model-phayathaibert58.3267.423.21
SCT-Distil-model-phayathaibert-bge-m378.3784.01
ConGen-model-XLMR60.2968.563.28
ConGen-model-wangchanberta59.1167.423.19
ConGen-model-phayathaibert59.2467.693.15
ConGen-BGE_M3-model-phayathaibert83.3688.293.14
distiluse-base-multilingual-cased-v232.5042.20:heavy_check_mark:2.05
paraphrase-multilingual-mpnet-base-v254.3963.12:heavy_check_mark:3.16
BGE M-389.1293.43:heavy_check_mark:20.87
Cohere-embed-multilingual-v2.085.4590.33:heavy_check_mark:XXX

Thank you for the many codes from

Acknowledgments:

  • Can: proofread
  • Charin: proofread + idea

1_3JJRwT1f2zTK1hx36-qXdg (1)

Contributors

mrpeerat

119 commits

panuthept

31 commits

KornWtp

29 commits

sitiporn

9 commits

Languages

Jupyter Notebook

92.1%

Python

7.9%