vankiet commited on
Commit
3a68ede
·
verified ·
1 Parent(s): 3c3f744

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - NghiemAbe/Vi-Legal-Bi-Encoder-v2
4
+ library_name: sentence-transformers
5
+ pipeline_tag: sentence-similarity
6
+ tags:
7
+ - bnb-my-repo
8
+ - sentence-transformers
9
+ - feature-extraction
10
+ - sentence-similarity
11
+ - transformers
12
+ language:
13
+ - vi
14
+ ---
15
+ # NghiemAbe/Vi-Legal-Bi-Encoder-v2 (Quantized)
16
+
17
+ ## Description
18
+ This model is a quantized version of the original model [`NghiemAbe/Vi-Legal-Bi-Encoder-v2`](https://huggingface.co/NghiemAbe/Vi-Legal-Bi-Encoder-v2).
19
+
20
+ It's quantized using the BitsAndBytes library to 4-bit using the [bnb-my-repo](https://huggingface.co/spaces/bnb-community/bnb-my-repo) space.
21
+
22
+ ## Quantization Details
23
+ - **Quantization Type**: int4
24
+ - **bnb_4bit_quant_type**: nf4
25
+ - **bnb_4bit_use_double_quant**: False
26
+ - **bnb_4bit_compute_dtype**: float32
27
+ - **bnb_4bit_quant_storage**: float32
28
+
29
+
30
+
31
+ # 📄 Original Model Information
32
+
33
+
34
+
35
+ # NghiemAbe/Vi-Legal-Bi-Encoder-v2
36
+
37
+ 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.
38
+
39
+ <!--- Describe your model here -->
40
+
41
+ ## Usage (Sentence-Transformers)
42
+
43
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
44
+
45
+ ```
46
+ pip install -U sentence-transformers
47
+ ```
48
+
49
+ Then you can use the model like this:
50
+
51
+ ```python
52
+ from sentence_transformers import SentenceTransformer
53
+ from pyvi.ViTokenizer import tokenize
54
+ sentences = [tokenize("This is an example sentence"), tokenize("Each sentence is converted")]
55
+
56
+ model = SentenceTransformer('NghiemAbe/Vi-Legal-Bi-Encoder-v2')
57
+ embeddings = model.encode(sentences)
58
+ print(embeddings)
59
+ ```
60
+
61
+
62
+
63
+ ## Usage (HuggingFace Transformers)
64
+ 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.
65
+
66
+ ```python
67
+ from transformers import AutoTokenizer, AutoModel
68
+ import torch
69
+
70
+
71
+ #Mean Pooling - Take attention mask into account for correct averaging
72
+ def mean_pooling(model_output, attention_mask):
73
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
74
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
75
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
76
+
77
+
78
+ # Sentences we want sentence embeddings for
79
+ sentences = [tokenize("This is an example sentence"), tokenize("Each sentence is converted")]
80
+
81
+ # Load model from HuggingFace Hub
82
+ tokenizer = AutoTokenizer.from_pretrained('NghiemAbe/Vi-Legal-Bi-Encoder-v2')
83
+ model = AutoModel.from_pretrained('NghiemAbe/Vi-Legal-Bi-Encoder-v2')
84
+
85
+ # Tokenize sentences
86
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
87
+
88
+ # Compute token embeddings
89
+ with torch.no_grad():
90
+ model_output = model(**encoded_input)
91
+
92
+ # Perform pooling. In this case, mean pooling.
93
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
94
+
95
+ print("Sentence embeddings:")
96
+ print(sentence_embeddings)
97
+ ```
98
+
99
+
100
+
101
+ ## Evaluation Results
102
+
103
+ I evaluated my [Dev-Legal-Dataset](https://huggingface.co/datasets/NghiemAbe/dev_legal) and here are the results:
104
+
105
+ | Model | R@1 | R@5 | R@10 | R@20 | R@100 | MRR@5 | MRR@10 | MRR@20 | MRR@100 | Avg |
106
+ |------------------------------------------------------------------------|------|------|------|------|-------|-------|--------|--------|---------|------|
107
+ | keepitreal/vietnamese-sbert | 0.278| 0.552| 0.649| 0.734| 0.842 | 0.396 | 0.409 | 0.415 | 0.417 | 0.521|
108
+ | sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 | 0.314| 0.486| 0.585| 0.662| 0.854 | 0.395 | 0.409 | 0.414 | 0.419 | 0.504|
109
+ | sentence-transformers/paraphrase-multilingual-mpnet-base-v2 | 0.354| 0.553| 0.646| 0.750| 0.896 | 0.449 | 0.461 | 0.468 | 0.472 | 0.561|
110
+ | intfloat/multilingual-e5-small | 0.488| 0.746| 0.835| 0.906| 0.962 | 0.610 | 0.620 | 0.624 | 0.625 | 0.713|
111
+ | intfloat/multilingual-e5-base | 0.466| 0.740| 0.840| 0.907| 0.952 | 0.596 | 0.608 | 0.612 | 0.613 | 0.704|
112
+ | bkai-foundation-models/vietnamese-bi-encoder | 0.644| 0.881| 0.924| 0.954| 0.986 | 0.752 | 0.757 | 0.758 | 0.759 | 0.824|
113
+ | Vi-Legal-Bi-Encoder-v2 | 0.720| 0.884| 0.935| 0.963| 0.986 | 0.796 | 0.802 | 0.803 | 0.804 | 0.855|
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<mask>": 64000
3
+ }
bpe.codes ADDED
The diff for this file is too large to render. See raw diff
 
config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RobertaModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "classifier_dropout": null,
8
+ "eos_token_id": 2,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-05,
15
+ "max_position_embeddings": 258,
16
+ "model_type": "roberta",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 1,
20
+ "position_embedding_type": "absolute",
21
+ "quantization_config": {
22
+ "_load_in_4bit": true,
23
+ "_load_in_8bit": false,
24
+ "bnb_4bit_compute_dtype": "float32",
25
+ "bnb_4bit_quant_storage": "float32",
26
+ "bnb_4bit_quant_type": "nf4",
27
+ "bnb_4bit_use_double_quant": false,
28
+ "llm_int8_enable_fp32_cpu_offload": false,
29
+ "llm_int8_has_fp16_weight": false,
30
+ "llm_int8_skip_modules": null,
31
+ "llm_int8_threshold": 6.0,
32
+ "load_in_4bit": true,
33
+ "load_in_8bit": false,
34
+ "quant_method": "bitsandbytes"
35
+ },
36
+ "tokenizer_class": "PhobertTokenizer",
37
+ "torch_dtype": "float32",
38
+ "transformers_version": "4.53.1",
39
+ "type_vocab_size": 1,
40
+ "use_cache": true,
41
+ "vocab_size": 64001
42
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:391f2ab12f6b0e3c7932dd3f10ece9aa2ec4ca593e4d526694faa2b7fbf61d1d
3
+ size 248090248
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "</s>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "<unk>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "64000": {
36
+ "content": "<mask>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "<s>",
45
+ "clean_up_tokenization_spaces": true,
46
+ "cls_token": "<s>",
47
+ "eos_token": "</s>",
48
+ "extra_special_tokens": {},
49
+ "mask_token": "<mask>",
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "pad_token": "<pad>",
52
+ "sep_token": "</s>",
53
+ "tokenizer_class": "PhobertTokenizer",
54
+ "unk_token": "<unk>"
55
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff