firqaaa commited on
Commit
d079683
1 Parent(s): a7f17b6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +66 -4
README.md CHANGED
@@ -7,7 +7,7 @@ tags:
7
 
8
  ---
9
 
10
- # {MODEL_NAME}
11
 
12
  This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 2048 dimensional dense vector space and can be used for tasks like clustering or semantic search.
13
 
@@ -25,14 +25,55 @@ Then you can use the model like this:
25
 
26
  ```python
27
  from sentence_transformers import SentenceTransformer
28
- sentences = ["This is an example sentence", "Each sentence is converted"]
 
 
 
29
 
30
- model = SentenceTransformer('{MODEL_NAME}')
31
  embeddings = model.encode(sentences)
32
  print(embeddings)
33
  ```
34
 
 
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  ## Evaluation Results
38
 
@@ -87,4 +128,25 @@ SentenceTransformer(
87
 
88
  ## Citing & Authors
89
 
90
- <!--- Describe where people can find more information -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  ---
9
 
10
+ # indo-sentence-bert-large
11
 
12
  This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 2048 dimensional dense vector space and can be used for tasks like clustering or semantic search.
13
 
 
25
 
26
  ```python
27
  from sentence_transformers import SentenceTransformer
28
+ sentences = ["Ibukota Perancis adalah Paris",
29
+ "Menara Eifel terletak di Paris, Perancis",
30
+ "Pizza adalah makanan khas Italia",
31
+ "Saya kuliah di Carneige Mellon University"]
32
 
33
+ model = SentenceTransformer('firqaaa/indo-sentence-bert-large')
34
  embeddings = model.encode(sentences)
35
  print(embeddings)
36
  ```
37
 
38
+ ## Usage (HuggingFace Transformers)
39
+ 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.
40
 
41
+ ```python
42
+ from transformers import AutoTokenizer, AutoModel
43
+ import torch
44
+
45
+
46
+ #Mean Pooling - Take attention mask into account for correct averaging
47
+ def mean_pooling(model_output, attention_mask):
48
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
49
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
50
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
51
+
52
+
53
+ # Sentences we want sentence embeddings for
54
+ sentences = ["Ibukota Perancis adalah Paris",
55
+ "Menara Eifel terletak di Paris, Perancis",
56
+ "Pizza adalah makanan khas Italia",
57
+ "Saya kuliah di Carneige Mellon University"]
58
+
59
+
60
+ # Load model from HuggingFace Hub
61
+ tokenizer = AutoTokenizer.from_pretrained('firqaaa/indo-sentence-bert-large')
62
+ model = AutoModel.from_pretrained('firqaaa/indo-sentence-bert-large')
63
+
64
+ # Tokenize sentences
65
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
66
+
67
+ # Compute token embeddings
68
+ with torch.no_grad():
69
+ model_output = model(**encoded_input)
70
+
71
+ # Perform pooling. In this case, mean pooling.
72
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
73
+
74
+ print("Sentence embeddings:")
75
+ print(sentence_embeddings)
76
+ ```
77
 
78
  ## Evaluation Results
79
 
 
128
 
129
  ## Citing & Authors
130
 
131
+ <!--- Describe where people can find more information -->
132
+
133
+ ```
134
+ @inproceedings{reimers-2019-sentence-bert,
135
+ title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
136
+ author = "Reimers, Nils and Gurevych, Iryna",
137
+ booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
138
+ month = "11",
139
+ year = "2019",
140
+ publisher = "Association for Computational Linguistics",
141
+ url = "https://arxiv.org/abs/1908.10084",
142
+ ```
143
+
144
+ ```
145
+ author = "Arasyi, Firqa",
146
+ title = "indo-sentence-bert: Sentence Transformer for Bahasa Indonesia with Multiple Negative Ranking Loss",
147
+ year = "2024",
148
+ month = "2"
149
+ publisher = "Huggingface",
150
+ journal = "Huggingface"
151
+ howpublished = "https://huggingface.co/firqaaa/indo-sentence-bert-large/",
152
+ ```