fgaim commited on
Commit
af37583
·
1 Parent(s): daa810b

Add Model Card

Browse files
Files changed (1) hide show
  1. README.md +131 -0
README.md ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # TiRoBERTa BiEncoder Model
16
+
17
+ This model is a bi-encoder model for the Tigrinya language based on [TiRoBERTa-base](https://huggingface.co/fgaim/tiroberta-base).
18
+ The model maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like text embedding, clustering, or semantic search.
19
+
20
+ This is part of a work that introduces monolingual bi-encoder language models for Tigrinya. For a smaller and lightweight model look at [TiELECTRA-bi-encoder](https://huggingface.co/fgaim/tielectra-bi-encoder). The models are based on the [sentence-transformers](https://www.sbert.net) architecture and are trained on Tigrinya question-answering and information retrieval datasets. The models are designed to support semantic search tasks, such as information retrieval, text representation, and question answering.
21
+
22
+ ## Using Model with Sentence-Transformers
23
+
24
+ Using this model becomes easy when you have sentence-transformers installed:
25
+
26
+ ```shell
27
+ pip install -U sentence-transformers
28
+ ```
29
+
30
+ Then use the model as follows:
31
+
32
+ ```python
33
+ from sentence_transformers import SentenceTransformer
34
+ sentences = ["ሓደ ሰብኣይ ፈረስ ይጋልብ ኣሎ።", "ሓንቲ ጓል ክራር ትጻወት ኣላ።"]
35
+
36
+ model = SentenceTransformer('fgaim/tiroberta-bi-encoder')
37
+ embeddings = model.encode(sentences)
38
+ print(embeddings)
39
+ ```
40
+
41
+ ## Using Model with 🤗 Transformers
42
+
43
+ Use the transformers library as follows:
44
+ Pass the input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
45
+
46
+ ```python
47
+ import torch
48
+ from transformers import AutoModel, AutoTokenizer
49
+
50
+
51
+ # Mean Pooling - Take attention mask into account for correct averaging
52
+ def mean_pooling(model_output, attention_mask):
53
+ token_embeddings = model_output[0] # First element of model_output contains all token embeddings
54
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
55
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
56
+
57
+
58
+ # Sentences we want sentence embeddings for
59
+ sentences = ["ሓደ ሰብኣይ ፈረስ ይጋልብ ኣሎ።", "ሓንቲ ጓል ክራር ትጻወት ኣላ።"]
60
+
61
+ # Load model from HuggingFace Hub
62
+ tokenizer = AutoTokenizer.from_pretrained("fgaim/tiroberta-bi-encoder")
63
+ model = AutoModel.from_pretrained("fgaim/tiroberta-bi-encoder")
64
+
65
+ # Tokenize sentences
66
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors="pt")
67
+
68
+ # Compute token embeddings
69
+ with torch.no_grad():
70
+ model_output = model(**encoded_input)
71
+
72
+ # Perform pooling. In this case, mean pooling.
73
+ sentence_embeddings = mean_pooling(model_output, encoded_input["attention_mask"])
74
+
75
+ print("Sentence embeddings:", sentence_embeddings)
76
+ ```
77
+
78
+ ## Architecture
79
+
80
+ ### Base Model
81
+
82
+ The model properties:
83
+
84
+ | Model Size | Layers | Attn. Heads | Hidden Size | FFN | Parameters | Max. Seq |
85
+ |------------|----|----|-----|------|------|------|
86
+ | BASE | 12 | 12 | 768 | 3072 | 125M | 512 |
87
+
88
+ ### BiEncoder Model
89
+
90
+ - Maximum sequence length: `512`
91
+ - Word embedding dimension: `768`
92
+
93
+ ```text
94
+ SentenceTransformer(
95
+ Transformer(
96
+ {
97
+ 'max_seq_length': 512,
98
+ 'do_lower_case': False
99
+ }
100
+ ) # with Transformer model: RobertaModel
101
+
102
+ Pooling(
103
+ {
104
+ 'word_embedding_dimension': 768,
105
+ 'pooling_mode_cls_token': False,
106
+ 'pooling_mode_mean_tokens': True,
107
+ 'pooling_mode_max_tokens': False,
108
+ 'pooling_mode_mean_sqrt_len_tokens': False,
109
+ 'pooling_mode_weightedmean_tokens': False,
110
+ 'pooling_mode_lasttoken': False,
111
+ 'include_prompt': True,
112
+ }
113
+ )
114
+ )
115
+ ```
116
+
117
+ ## Citation
118
+
119
+ If you use this model in your product or research, you can cite it as follows:
120
+
121
+ ```bibtex
122
+ @misc{gaim-2024-semantic-search,
123
+ title = {{Semantic Search Models for Tigrinya}},
124
+ author = {Fitsum Gaim},
125
+ month = {January},
126
+ year = {2024},
127
+ publisher = {Hugging Face Hub},
128
+ doi = {10.57967/hf/6068},
129
+ url = {https://huggingface.co/fgaim/tiroberta-bi-encoder}
130
+ }
131
+ ```