初始化项目,由ModelHub XC社区提供模型

Model: jhgan/ko-sbert-nli
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-05-13 18:58:22 +08:00
commit f17758393b
15 changed files with 32245 additions and 0 deletions

27
.gitattributes vendored Normal file
View File

@@ -0,0 +1,27 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bin.* filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zstandard filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text

7
1_Pooling/config.json Normal file
View File

@@ -0,0 +1,7 @@
{
"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
}

140
README.md Normal file
View File

@@ -0,0 +1,140 @@
---
pipeline_tag: sentence-similarity
tags:
- sentence-transformers
- feature-extraction
- sentence-similarity
- transformers
---
# ko-sbert-nli
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
<!--- Describe your model here -->
## Usage (Sentence-Transformers)
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
```
pip install -U sentence-transformers
```
Then you can use the model like this:
```python
from sentence_transformers import SentenceTransformer
sentences = ["안녕하세요?", "한국어 문장 임베딩을 위한 버트 모델입니다."]
model = SentenceTransformer('jhgan/ko-sbert-nli')
embeddings = model.encode(sentences)
print(embeddings)
```
## Usage (HuggingFace Transformers)
Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
```python
from transformers import AutoTokenizer, AutoModel
import torch
#Mean Pooling - Take attention mask into account for correct averaging
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
# Sentences we want sentence embeddings for
sentences = ['This is an example sentence', 'Each sentence is converted']
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained('jhgan/ko-sbert-nli')
model = AutoModel.from_pretrained('jhgan/ko-sbert-nli')
# Tokenize sentences
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
model_output = model(**encoded_input)
# Perform pooling. In this case, mean pooling.
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
```
## Evaluation Results
<!--- Describe how your model was evaluated -->
KorNLI 학습 데이터셋으로 학습한 후 KorSTS 평가 데이터셋으로 평가한 결과입니다.
- Cosine Pearson: 82.24
- Cosine Spearman: 83.16
- Euclidean Pearson: 82.19
- Euclidean Spearman: 82.31
- Manhattan Pearson: 82.18
- Manhattan Spearman: 82.30
- Dot Pearson: 79.30
- Dot Spearman: 78.78
## Training
The model was trained with the parameters:
**DataLoader**:
`sentence_transformers.datasets.NoDuplicatesDataLoader.NoDuplicatesDataLoader` of length 8885 with parameters:
```
{'batch_size': 64}
```
**Loss**:
`sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss` with parameters:
```
{'scale': 20.0, 'similarity_fct': 'cos_sim'}
```
Parameters of the fit()-Method:
```
{
"epochs": 1,
"evaluation_steps": 1000,
"evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
"max_grad_norm": 1,
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
"optimizer_params": {
"lr": 2e-05
},
"scheduler": "WarmupLinear",
"steps_per_epoch": null,
"warmup_steps": 889,
"weight_decay": 0.01
}
```
## Full Model Architecture
```
SentenceTransformer(
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
(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})
)
```
## Citing & Authors
<!--- Describe where people can find more information -->
- Ham, J., Choe, Y. J., Park, K., Choi, I., & Soh, H. (2020). Kornli and korsts: New benchmark datasets for korean natural language understanding. arXiv preprint arXiv:2004.03289
- Reimers, Nils and Iryna Gurevych. “Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks.” ArXiv abs/1908.10084 (2019)
- Reimers, Nils and Iryna Gurevych. “Making Monolingual Sentence Embeddings Multilingual Using Knowledge Distillation.” EMNLP (2020).

25
config.json Normal file
View File

@@ -0,0 +1,25 @@
{
"_name_or_path": "klue/bert-base",
"architectures": [
"BertModel"
],
"attention_probs_dropout_prob": 0.1,
"classifier_dropout": null,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"initializer_range": 0.02,
"intermediate_size": 3072,
"layer_norm_eps": 1e-12,
"max_position_embeddings": 512,
"model_type": "bert",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"pad_token_id": 0,
"position_embedding_type": "absolute",
"torch_dtype": "float32",
"transformers_version": "4.13.0",
"type_vocab_size": 2,
"use_cache": true,
"vocab_size": 32000
}

View File

@@ -0,0 +1,7 @@
{
"__version__": {
"sentence_transformers": "2.1.0",
"transformers": "4.13.0",
"pytorch": "1.7.0+cu110"
}
}

View File

@@ -0,0 +1,10 @@
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
0,1000,0.8372857942987225,0.8407208269518864,0.8331424356011922,0.8367494746988681,0.8333311193829283,0.8364053623608307,0.7555444012061884,0.744732863819921
0,2000,0.8384571735085646,0.8427977198516319,0.8395402988547136,0.8418592841472897,0.8395654989362198,0.8415884958448266,0.7893000921359432,0.7803491268015889
0,3000,0.8447124003133899,0.8461849677528527,0.8432619695088145,0.8461802072109135,0.8433874596745925,0.8461781573874295,0.7925640282674101,0.78423865973145
0,4000,0.8453789660882316,0.8460689854659939,0.8452735127932355,0.8470702523115023,0.8451842211475988,0.8468726916764162,0.7996871181431277,0.7914618871297846
0,5000,0.8477376315192559,0.8490169394681855,0.849286916319091,0.851709951255318,0.8491886477866232,0.8514469759841669,0.8078648844394252,0.8000196545938207
0,6000,0.8530499053415126,0.8544498186816301,0.852523916636149,0.8557239237869968,0.8524879108829966,0.8556097012879373,0.8172847589442498,0.8103997863031938
0,7000,0.8477881460062954,0.8500802249032595,0.8469030605246687,0.8498526866234515,0.8470032318169344,0.8500158735692439,0.8076917053286744,0.8009867976091513
0,8000,0.8494143474821899,0.8504967999253196,0.8486672124534856,0.8520583554112752,0.8488057004942539,0.8523250566636555,0.8092360981402517,0.8023885832728013
0,-1,0.8498525999309121,0.8507844389148806,0.8486482705661437,0.852027076030175,0.8487839147678554,0.8522168562786069,0.812279339935303,0.8054841619187971
1 epoch steps cosine_pearson cosine_spearman euclidean_pearson euclidean_spearman manhattan_pearson manhattan_spearman dot_pearson dot_spearman
2 0 1000 0.8372857942987225 0.8407208269518864 0.8331424356011922 0.8367494746988681 0.8333311193829283 0.8364053623608307 0.7555444012061884 0.744732863819921
3 0 2000 0.8384571735085646 0.8427977198516319 0.8395402988547136 0.8418592841472897 0.8395654989362198 0.8415884958448266 0.7893000921359432 0.7803491268015889
4 0 3000 0.8447124003133899 0.8461849677528527 0.8432619695088145 0.8461802072109135 0.8433874596745925 0.8461781573874295 0.7925640282674101 0.78423865973145
5 0 4000 0.8453789660882316 0.8460689854659939 0.8452735127932355 0.8470702523115023 0.8451842211475988 0.8468726916764162 0.7996871181431277 0.7914618871297846
6 0 5000 0.8477376315192559 0.8490169394681855 0.849286916319091 0.851709951255318 0.8491886477866232 0.8514469759841669 0.8078648844394252 0.8000196545938207
7 0 6000 0.8530499053415126 0.8544498186816301 0.852523916636149 0.8557239237869968 0.8524879108829966 0.8556097012879373 0.8172847589442498 0.8103997863031938
8 0 7000 0.8477881460062954 0.8500802249032595 0.8469030605246687 0.8498526866234515 0.8470032318169344 0.8500158735692439 0.8076917053286744 0.8009867976091513
9 0 8000 0.8494143474821899 0.8504967999253196 0.8486672124534856 0.8520583554112752 0.8488057004942539 0.8523250566636555 0.8092360981402517 0.8023885832728013
10 0 -1 0.8498525999309121 0.8507844389148806 0.8486482705661437 0.852027076030175 0.8487839147678554 0.8522168562786069 0.812279339935303 0.8054841619187971

14
modules.json Normal file
View File

@@ -0,0 +1,14 @@
[
{
"idx": 0,
"name": "0",
"path": "",
"type": "sentence_transformers.models.Transformer"
},
{
"idx": 1,
"name": "1",
"path": "1_Pooling",
"type": "sentence_transformers.models.Pooling"
}
]

3
pytorch_model.bin Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b093a51d0656212a1db1fe67a5b538cb00ec72f879ea9d851043604b15c36edb
size 442555895

View File

@@ -0,0 +1,4 @@
{
"max_seq_length": 128,
"do_lower_case": false
}

View File

@@ -0,0 +1,2 @@
epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman
-1,-1,0.822441302887688,0.8315860698074092,0.8219138412440101,0.8231020395802463,0.8218065249741794,0.82299617187023,0.7930471227376389,0.7877806505699242
1 epoch steps cosine_pearson cosine_spearman euclidean_pearson euclidean_spearman manhattan_pearson manhattan_spearman dot_pearson dot_spearman
2 -1 -1 0.822441302887688 0.8315860698074092 0.8219138412440101 0.8231020395802463 0.8218065249741794 0.82299617187023 0.7930471227376389 0.7877806505699242

1
special_tokens_map.json Normal file
View File

@@ -0,0 +1 @@
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}

3
tf_model.h5 Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:91836d6f1fed0133287121986a537edad213f177c07ec7d7cbff552bd1aec20e
size 442736616

1
tokenizer.json Normal file

File diff suppressed because one or more lines are too long

1
tokenizer_config.json Normal file
View File

@@ -0,0 +1 @@
{"do_lower_case": false, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "do_basic_tokenize": true, "never_split": null, "model_max_length": 512, "special_tokens_map_file": "/home/jhgan/.cache/huggingface/transformers/aeaaa3afd086a040be912f92ffe7b5f85008b744624f4517c4216bcc32b51cf0.054ece8d16bd524c8a00f0e8a976c00d5de22a755ffb79e353ee2954d9289e26", "name_or_path": "klue/bert-base", "tokenizer_class": "BertTokenizer"}

32000
vocab.txt Normal file

File diff suppressed because it is too large Load Diff