fgaim commited on
Commit
b56d37b
·
1 Parent(s): 3beac25

Add README

Browse files
Files changed (1) hide show
  1. README.md +109 -0
README.md ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language: ti
4
+ library_name: sentence-transformers
5
+ pipeline_tag: sentence-similarity
6
+ tags:
7
+ - sentence-transformers
8
+ - feature-extraction
9
+ - sentence-similarity
10
+ - transformers
11
+ widget:
12
+ - text: "ግራፋይት ኣብ መላእ ዓለም ዳርጋ ብምዕሩይ ዝርጋሐ’ዩ ዝርከብ"
13
+ ---
14
+
15
+ # TiELECTRA BiEncoder Model
16
+
17
+ This model is a [sentence-transformers](https://www.SBERT.net) model for the Tigrinya language based on [TiELECTRA-small](https://huggingface.co/fgaim/tielectra-bi-encoder).
18
+ The maps sentences & paragraphs to a 256 dimensional dense vector space and can be used for tasks like clustering or semantic search.
19
+
20
+ ## Using Sentence-Transformers
21
+
22
+ Using this model becomes easy when you have sentence-transformersinstalled:
23
+
24
+ ```shell
25
+ pip install -U sentence-transformers
26
+ ```
27
+
28
+ Then use the model as follows:
29
+
30
+ ```python
31
+ from sentence_transformers import SentenceTransformer
32
+ sentences = ["ሓደ ሰብኣይ ፈረስ ይጋልብ ኣሎ።", "ሓንቲ ጓል ክራር ትጻወት ኣላ።"]
33
+
34
+ model = SentenceTransformer('fgaim/tielectra-bi-encoder')
35
+ embeddings = model.encode(sentences)
36
+ print(embeddings)
37
+ ```
38
+
39
+ ## Using 🤗 Transformers
40
+
41
+ Use the transformers library as follows:
42
+ Pass the input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
43
+
44
+ ```python
45
+ import torch
46
+ from transformers import AutoModel, AutoTokenizer
47
+
48
+
49
+ # Mean Pooling - Take attention mask into account for correct averaging
50
+ def mean_pooling(model_output, attention_mask):
51
+ token_embeddings = model_output[0] # First element of model_output contains all token embeddings
52
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
53
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
54
+
55
+
56
+ # Sentences we want sentence embeddings for
57
+ sentences = ["ሓደ ሰብኣይ ፈረስ ይጋልብ ኣሎ።", "ሓንቲ ጓል ክራር ትጻወት ኣላ።"]
58
+
59
+ # Load model from HuggingFace Hub
60
+ tokenizer = AutoTokenizer.from_pretrained("fgaim/tielectra-bi-encoder")
61
+ model = AutoModel.from_pretrained("fgaim/tielectra-bi-encoder")
62
+
63
+ # Tokenize sentences
64
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors="pt")
65
+
66
+ # Compute token embeddings
67
+ with torch.no_grad():
68
+ model_output = model(**encoded_input)
69
+
70
+ # Perform pooling. In this case, mean pooling.
71
+ sentence_embeddings = mean_pooling(model_output, encoded_input["attention_mask"])
72
+
73
+ print("Sentence embeddings:", sentence_embeddings)
74
+ ```
75
+
76
+ ## Architecture
77
+
78
+ ### Base Model
79
+
80
+ The model properties:
81
+ | Model Size | Layers | Attn. Heads | Hidden Size | FFN | Parameters | Max. Seq |
82
+ |------------|----|----|-----|------|------|------|
83
+ | SMALL | 12 | 4 | 256 | 1024 | 14M | 512 |
84
+
85
+ ### BiEncoder Model
86
+
87
+ - Max Seq Length: `512`
88
+ - Word embedding dimension: `256`
89
+
90
+ ```
91
+ SentenceTransformer(
92
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: ElectraModel
93
+
94
+ (1): Pooling({'word_embedding_dimension': 256, '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})
95
+ )
96
+ ```
97
+
98
+ ## Cite
99
+
100
+ If you use this model in your product or research, you can cite it as follows:
101
+
102
+ ```bibtex
103
+ @article{Fitsum2021TiPLMs,
104
+ author={Fitsum Gaim and Wonsuk Yang and Jong C. Park},
105
+ title={Monolingual Pre-trained Language Models for Tigrinya},
106
+ year=2021,
107
+ publisher={WiNLP 2021 co-located EMNLP 2021}
108
+ }
109
+ ```