shihab17 commited on
Commit
e4bc2fb
·
1 Parent(s): a17e40e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +0 -151
README.md CHANGED
@@ -1,151 +0,0 @@
1
- ---
2
- pipeline_tag: sentence-similarity
3
- tags:
4
- - sentence-transformers
5
- - feature-extraction
6
- - sentence-similarity
7
- - transformers
8
- language:
9
- - bn
10
- metrics:
11
- - accuracy
12
- ---
13
-
14
- # {shihab17/bangla-sentence-transformer }
15
-
16
- 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.
17
-
18
- <!--- Describe your model here -->
19
-
20
- ## How to get sentence similarity
21
-
22
- ```python
23
- from sentence_transformers import SentenceTransformer
24
- from sentence_transformers.util import pytorch_cos_sim
25
-
26
-
27
- transformer = SentenceTransformer('shihab17/bangla-sentence-transformer')
28
-
29
- sentences = ['আমি আপেল খেতে পছন্দ করি। ', 'আমার একটি আপেল মোবাইল আছে।','এইবার কমলার ফলনা ভাল হয়নি', 'বাচ্চাটি দেখতে আপেলের মত সুন্দর','আপেলের জুস আমার অনেক প্রিয়']
30
-
31
- sentences_embeddings = transformer.encode(sentences)
32
-
33
- for i in range(len(sentences)):
34
- for j in range(i, len(sentences)):
35
- sen_1 = sentences[i]
36
- sen_2 = sentences[j]
37
- sim_score = float(pytorch_cos_sim(sentences_embeddings[i], sentences_embeddings[j]))
38
- print(sen_1, '----->', sen_2, sim_score)
39
- ```
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
- sentences = ['আমি আপেল খেতে পছন্দ করি। ', 'আমার একটি আপেল মোবাইল আছে।','আপনি কি এখানে কাছাকাছি থাকেন?', 'আশেপাশে কেউ আছেন?']
54
-
55
- model = SentenceTransformer('shihab17/bangla-sentence-transformer ')
56
- embeddings = model.encode(sentences)
57
- print(embeddings)
58
- ```
59
-
60
-
61
-
62
- ## Usage (HuggingFace Transformers)
63
- 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.
64
-
65
- ```python
66
- from transformers import AutoTokenizer, AutoModel
67
- import torch
68
-
69
-
70
- #Mean Pooling - Take attention mask into account for correct averaging
71
- def mean_pooling(model_output, attention_mask):
72
- token_embeddings = model_output[0] #First element of model_output contains all token embeddings
73
- input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
74
- return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
75
-
76
-
77
- # Sentences we want sentence embeddings for
78
- sentences = ['আমি আপেল খেতে পছন্দ করি। ', 'আমার একটি আপেল মোবাইল আছে।','আপনি কি এখানে কাছাকাছি থাকেন?', 'আশেপাশে কেউ আছেন?']
79
-
80
- # Load model from HuggingFace Hub
81
- tokenizer = AutoTokenizer.from_pretrained('shihab17/bangla-sentence-transformer')
82
- model = AutoModel.from_pretrained('shihab17/bangla-sentence-transformer')
83
-
84
- # Tokenize sentences
85
- encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
86
-
87
- # Compute token embeddings
88
- with torch.no_grad():
89
- model_output = model(**encoded_input)
90
-
91
- # Perform pooling. In this case, mean pooling.
92
- sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
93
-
94
- print("Sentence embeddings:")
95
- print(sentence_embeddings)
96
- ```
97
-
98
-
99
- ## Evaluation Results
100
-
101
- <!--- Describe how your model was evaluated -->
102
- ## Best MSE: 7.57528096437454
103
-
104
- For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
105
-
106
-
107
- ## Training
108
- The model was trained with the parameters:
109
-
110
- **DataLoader**:
111
-
112
- `torch.utils.data.dataloader.DataLoader` of length 237094 with parameters:
113
- ```
114
- {'batch_size': 32, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
115
- ```
116
-
117
- **Loss**:
118
-
119
- `sentence_transformers.losses.MSELoss.MSELoss`
120
-
121
- Parameters of the fit()-Method:
122
- ```
123
- {
124
- "epochs": 10,
125
- "evaluation_steps": 500,
126
- "evaluator": "sentence_transformers.evaluation.SequentialEvaluator.SequentialEvaluator",
127
- "max_grad_norm": 1,
128
- "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
129
- "optimizer_params": {
130
- "eps": 1e-06,
131
- "lr": 2e-05
132
- },
133
- "scheduler": "WarmupLinear",
134
- "steps_per_epoch": null,
135
- "warmup_steps": 8000,
136
- "weight_decay": 0.01
137
- }
138
- ```
139
-
140
-
141
- ## Full Model Architecture
142
- ```
143
- SentenceTransformer(
144
- (0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: XLMRobertaModel
145
- (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})
146
- )
147
- ```
148
-
149
- ## Citing & Authors
150
-
151
- <!--- Describe where people can find more information -->