CoolFace
Modelpublic

varin/embeddinggemma-thai-law

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes81downloads
Model Card

SentenceTransformer based on varin/embeddinggemma-thai-law

This is a sentence-transformers model finetuned from varin/embeddinggemma-thai-law on the json dataset. It maps sentences & paragraphs to a 768-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.

Model Details

Model Description

  • Model Type: Sentence Transformer
  • Base model: varin/embeddinggemma-thai-law <!-- at revision 4e1a0afc96d074aa32bc1b88c9f485060810d51f -->
  • Maximum Sequence Length: 256 tokens
  • Output Dimensionality: 768 dimensions
  • Similarity Function: Cosine Similarity
  • Training Dataset:
  • json <!-- - Language: Unknown --> <!-- - License: Unknown -->

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'max_seq_length': 256, 'do_lower_case': False, 'architecture': 'Gemma3TextModel'})
  (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
  (2): Dense({'in_features': 768, 'out_features': 3072, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity'})
  (3): Dense({'in_features': 3072, 'out_features': 768, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity'})
  (4): Normalize()
)

Usage

Direct Usage (Sentence Transformers)

First install the Sentence Transformers library:

bash
pip install -U sentence-transformers

Then you can load this model and run inference.

python
from sentence_transformers import SentenceTransformer

# Download from the 🤗 Hub
model = SentenceTransformer("varin/embeddinggemma-thai-law")
# Run inference
queries = [
    "\u0e2b\u0e32\u0e01\u0e1c\u0e39\u0e49\u0e40\u0e1b\u0e47\u0e19\u0e2b\u0e38\u0e49\u0e19\u0e2a\u0e48\u0e27\u0e19\u0e17\u0e31\u0e49\u0e07\u0e2b\u0e21\u0e14\u0e43\u0e2b\u0e49\u0e04\u0e27\u0e32\u0e21\u0e22\u0e34\u0e19\u0e22\u0e2d\u0e21 \u0e2b\u0e49\u0e32\u0e07\u0e2b\u0e38\u0e49\u0e19\u0e2a\u0e48\u0e27\u0e19\u0e08\u0e14\u0e17\u0e30\u0e40\u0e1a\u0e35\u0e22\u0e19\u0e2a\u0e2d\u0e07\u0e41\u0e2b\u0e48\u0e07\u0e08\u0e30\u0e04\u0e27\u0e1a\u0e23\u0e27\u0e21\u0e01\u0e31\u0e19\u0e44\u0e14\u0e49\u0e2b\u0e23\u0e37\u0e2d\u0e44\u0e21\u0e48?",
]
documents = [
    'ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1073 ห้างหุ้นส่วนจดทะเบียนห้างหนึ่งจะควบเข้าเป็นอันเดียวกับห้างหุ้นส่วนจดทะเบียนอีกห้างหนึ่งก็ได้ โดยความยินยอมของผู้เป็นหุ้นส่วนทั้งหมด เว้นแต่จะได้ตกลงกันไว้เป็นอย่างอื่น',
    'การควบห้างหุ้นส่วนจดทะเบียนต้องกระทำโดยความยินยอมของหุ้นส่วนไม่น้อยกว่าสามในสี่ของจำนวนหุ้นส่วนทั้งหมดเท่านั้น',
    'ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1061 เมื่อห้างหุ้นส่วนเลิกกันแล้วก็ให้จัดการชำระบัญชี เว้นแต่จะได้ตกลงกันให้จัดการทรัพย์สินโดยวิธีอื่นในระหว่างผู้เป็นหุ้นส่วนด้วยกัน หรือว่าห้างหุ้นส่วนนั้นศาลได้พิพากษาให้ล้มละลาย ถ้าการเลิกห้างหุ้นส่วนนั้นได้เป็นไปโดยที่เจ้าหนี้เฉพาะตัวของผู้เป็นหุ้นส่วนคนใดคนหนึ่งได้ให้คำบอกกล่าวก็ดี หรือโดยที่ผู้เป็นหุ้นส่วนคนใดคนหนึ่งล้มละลายก็ดี ท่านว่าจะงดการชำระบัญชีเสียได้ต่อเมื่อเจ้าหนี้คนนั้น หรือเจ้าพนักงานรักษาทรัพย์ยินยอมด้วย การชำระบัญชีนั้น ให้ผู้เป็นหุ้นส่วนทั้งหมดด้วยกันจัดทำหรือให้บุคคลอื่นซึ่งผู้เป็นหุ้นส่วนได้ตั้งแต่งขึ้นนั้นเป็นผู้จัดทำ การตั้งแต่งผู้ชำระบัญชี ให้วินิจฉัยชี้ขาดโดยคะแนนเสียงข้างมากของผู้เป็นหุ้นส่วน',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 768] [3, 768]

# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.7431, 0.0676, 0.1604]])

<!--

Direct Usage (Transformers)

<details><summary>Click to see the direct usage in Transformers</summary>

</details> -->

<!--

Downstream Usage (Sentence Transformers)

You can finetune this model on your own dataset.

<details><summary>Click to expand</summary>

</details> -->

<!--

Out-of-Scope Use

List how the model may foreseeably be misused and address what users ought not to do with the model. -->

<!--

Bias, Risks and Limitations

What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model. -->

<!--

Recommendations

What are recommendations with respect to the foreseeable issues? For example, filtering explicit content. -->

Training Details

Training Dataset

json
  • Dataset: json
  • Size: 20,750 training samples
  • Columns: <code>anchor</code>, <code>positive</code>, and <code>negative</code>
  • Approximate statistics based on the first 1000 samples: | | anchor | positive | negative | |:--------|:-----------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------| | type | string | string | string | | details | <ul><li>min: 10 tokens</li><li>mean: 31.91 tokens</li><li>max: 58 tokens</li></ul> | <ul><li>min: 39 tokens</li><li>mean: 116.71 tokens</li><li>max: 256 tokens</li></ul> | <ul><li>min: 9 tokens</li><li>mean: 30.03 tokens</li><li>max: 54 tokens</li></ul> |
  • Samples: | anchor | positive | negative | |:-----------------------------------------------------|:------------------------------------------------------------------------------------------------|:----------------------------------------------------------| | <code>กฎหมายนี้มีชื่อเรียกว่าอะไร</code> | <code>ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1 กฎหมายนี้ให้เรียกว่า ประมวลกฎหมายแพ่งและพาณิชย์</code> | <code>พระราชบัญญัติว่าด้วยธุรกรรมทางอิเล็กทรอนิกส์</code> | | <code>ชื่อของประมวลกฎหมายนี้คืออะไร</code> | <code>ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1 กฎหมายนี้ให้เรียกว่า ประมวลกฎหมายแพ่งและพาณิชย์</code> | <code>ประมวลรัษฎากร</code> | | <code>กฎหมายที่กล่าวถึงในมาตรานี้เรียกว่าอะไร</code> | <code>ประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 1 กฎหมายนี้ให้เรียกว่า ประมวลกฎหมายแพ่งและพาณิชย์</code> | <code>พระราชบัญญัติล้มละลาย</code> |
  • Loss: <code>CachedMultipleNegativesRankingLoss</code> with these parameters:
json
  {
      "scale": 20.0,
      "similarity_fct": "cos_sim",
      "mini_batch_size": 8,
      "gather_across_devices": false
  }

Training Hyperparameters

Non-Default Hyperparameters
  • per_device_train_batch_size: 16
  • learning_rate: 2e-05
  • num_train_epochs: 1
  • warmup_ratio: 0.1
  • bf16: True
  • push_to_hub: True
  • hub_model_id: varin/embeddinggemma-thai-law
  • hub_strategy: end
All Hyperparameters

<details><summary>Click to expand</summary>

  • overwrite_output_dir: False
  • do_predict: False
  • eval_strategy: no
  • prediction_loss_only: True
  • per_device_train_batch_size: 16
  • per_device_eval_batch_size: 8
  • per_gpu_train_batch_size: None
  • per_gpu_eval_batch_size: None
  • gradient_accumulation_steps: 1
  • eval_accumulation_steps: None
  • torch_empty_cache_steps: None
  • learning_rate: 2e-05
  • weight_decay: 0.0
  • adam_beta1: 0.9
  • adam_beta2: 0.999
  • adam_epsilon: 1e-08
  • max_grad_norm: 1.0
  • num_train_epochs: 1
  • max_steps: -1
  • lr_scheduler_type: linear
  • lr_scheduler_kwargs: {}
  • warmup_ratio: 0.1
  • warmup_steps: 0
  • log_level: passive
  • log_level_replica: warning
  • log_on_each_node: True
  • logging_nan_inf_filter: True
  • save_safetensors: True
  • save_on_each_node: False
  • save_only_model: False
  • restore_callback_states_from_checkpoint: False
  • no_cuda: False
  • use_cpu: False
  • use_mps_device: False
  • seed: 42
  • data_seed: None
  • jit_mode_eval: False
  • bf16: True
  • fp16: False
  • fp16_opt_level: O1
  • half_precision_backend: auto
  • bf16_full_eval: False
  • fp16_full_eval: False
  • tf32: None
  • local_rank: 0
  • ddp_backend: None
  • tpu_num_cores: None
  • tpu_metrics_debug: False
  • debug: []
  • dataloader_drop_last: False
  • dataloader_num_workers: 0
  • dataloader_prefetch_factor: None
  • past_index: -1
  • disable_tqdm: False
  • remove_unused_columns: True
  • label_names: None
  • load_best_model_at_end: False
  • ignore_data_skip: False
  • fsdp: []
  • fsdp_min_num_params: 0
  • fsdp_config: {'minnumparams': 0, 'xla': False, 'xlafsdpv2': False, 'xlafsdpgrad_ckpt': False}
  • fsdp_transformer_layer_cls_to_wrap: None
  • accelerator_config: {'splitbatches': False, 'dispatchbatches': None, 'evenbatches': True, 'useseedablesampler': True, 'nonblocking': False, 'gradientaccumulationkwargs': None}
  • parallelism_config: None
  • deepspeed: None
  • label_smoothing_factor: 0.0
  • optim: adamwtorchfused
  • optim_args: None
  • adafactor: False
  • group_by_length: False
  • length_column_name: length
  • project: huggingface
  • trackio_space_id: trackio
  • ddp_find_unused_parameters: None
  • ddp_bucket_cap_mb: None
  • ddp_broadcast_buffers: False
  • dataloader_pin_memory: True
  • dataloader_persistent_workers: False
  • skip_memory_metrics: True
  • use_legacy_prediction_loop: False
  • push_to_hub: True
  • resume_from_checkpoint: None
  • hub_model_id: varin/embeddinggemma-thai-law
  • hub_strategy: end
  • hub_private_repo: None
  • hub_always_push: False
  • hub_revision: None
  • gradient_checkpointing: False
  • gradient_checkpointing_kwargs: None
  • include_inputs_for_metrics: False
  • include_for_metrics: []
  • eval_do_concat_batches: True
  • fp16_backend: auto
  • push_to_hub_model_id: None
  • push_to_hub_organization: None
  • mp_parameters:
  • auto_find_batch_size: False
  • full_determinism: False
  • torchdynamo: None
  • ray_scope: last
  • ddp_timeout: 1800
  • torch_compile: False
  • torch_compile_backend: None
  • torch_compile_mode: None
  • include_tokens_per_second: False
  • include_num_input_tokens_seen: no
  • neftune_noise_alpha: None
  • optim_target_modules: None
  • batch_eval_metrics: False
  • eval_on_start: False
  • use_liger_kernel: False
  • liger_kernel_config: None
  • eval_use_gather_object: False
  • average_tokens_across_devices: True
  • prompts: None
  • batch_sampler: batch_sampler
  • multi_dataset_batch_sampler: proportional
  • router_mapping: {}
  • learning_rate_mapping: {}

</details>

Training Logs

<details><summary>Click to expand</summary>

EpochStepTraining Loss
0.0077100.0347
0.0154200.0056
0.0231300.0127
0.0308400.0101
0.0386500.056
0.0463600.003
0.0540700.0061
0.0617800.0134
0.0694900.0114
0.07711000.0013
0.08481100.0107
0.09251200.02
0.10021300.002
0.10791400.0016
0.11571500.1214
0.12341600.0062
0.13111700.0322
0.13881800.0354
0.14651900.0267
0.15422000.0176
0.16192100.0139
0.16962200.0469
0.17732300.0268
0.18502400.0361
0.19282500.0369
0.20052600.0902
0.20822700.1318
0.21592800.0116
0.22362900.0204
0.23133000.0166
0.23903100.147
0.24673200.0124
0.25443300.0251
0.26213400.0138
0.26993500.043
0.27763600.0814
0.28533700.0181
0.29303800.0328
0.30073900.0273
0.30844000.1388
0.31614100.031
0.32384200.0443
0.33154300.0219
0.33924400.0065
0.34704500.0201
0.35474600.043
0.36244700.0411
0.37014800.1481
0.37784900.0352
0.38555000.0208
0.39325100.0159
0.40095200.0161
0.40865300.007
0.41635400.0227
0.42415500.0221
0.43185600.0166
0.43955700.007
0.44725800.0291
0.45495900.0152
0.46266000.0158
0.47036100.0344
0.47806200.0184
0.48576300.0126
0.49346400.0091
0.50126500.0154
0.50896600.0155
0.51666700.0096
0.52436800.017
0.53206900.0108
0.53977000.0119
0.54747100.007
0.55517200.0273
0.56287300.0232
0.57057400.0186
0.57837500.0246
0.58607600.0118
0.59377700.0035
0.60147800.0133
0.60917900.026
0.61688000.0038
0.62458100.044
0.63228200.0076
0.63998300.0334
0.64768400.0173
0.65548500.0111
0.66318600.0385
0.67088700.0082
0.67858800.0114
0.68628900.0071
0.69399000.0414
0.70169100.0038
0.70939200.0065
0.71709300.0049
0.72479400.1457
0.73259500.0117
0.74029600.0146
0.74799700.0162
0.75569800.0132
0.76339900.0035
0.771010000.0103
0.778710100.0409
0.786410200.0157
0.794110300.1586
0.801910400.0205
0.809610500.0915
0.817310600.015
0.825010700.0103
0.832710800.0016
0.840410900.0198
0.848111000.0393
0.855811100.0241
0.863511200.0043
0.871211300.0114
0.879011400.0215
0.886711500.0174
0.894411600.0286
0.902111700.006
0.909811800.0155
0.917511900.0292
0.925212000.0117
0.932912100.0153
0.940612200.0135
0.948312300.0203
0.956112400.0091
0.963812500.0282
0.971512600.0142
0.979212700.0983
0.986912800.0126
0.994612900.0159

</details>

Framework Versions

  • Python: 3.10.12
  • Sentence Transformers: 5.2.0
  • Transformers: 4.57.3
  • PyTorch: 2.9.1+cu128
  • Accelerate: 1.12.0
  • Datasets: 4.4.2
  • Tokenizers: 0.22.1

Citation

BibTeX

Sentence Transformers
bibtex
@inproceedings{reimers-2019-sentence-bert,
    title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
    author = "Reimers, Nils and Gurevych, Iryna",
    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
    month = "11",
    year = "2019",
    publisher = "Association for Computational Linguistics",
    url = "https://arxiv.org/abs/1908.10084",
}
CachedMultipleNegativesRankingLoss
bibtex
@misc{gao2021scaling,
    title={Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
    author={Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
    year={2021},
    eprint={2101.06983},
    archivePrefix={arXiv},
    primaryClass={cs.LG}
}

<!--

Glossary

Clearly define terms in order to be accessible across audiences. -->

<!--

Model Card Authors

Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction. -->

<!--

Model Card Contact

Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors. -->