Add README
Browse files
README.md
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 is a [sentence-transformers](https://www.SBERT.net) model for the Tigrinya language based on [TiRoBERTa-base](https://huggingface.co/fgaim/tiroberta-base).
|
18 |
+
The maps sentences & paragraphs to a 768 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 |
+
|
33 |
+
sentences = ["ሓደ ሰብኣይ ፈረስ ይጋልብ ኣሎ።", "ሓንቲ ጓል ክራር ትጻወት ኣላ።"]
|
34 |
+
model = SentenceTransformer('fgaim/tiroberta-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/tiroberta-bi-encoder")
|
61 |
+
model = AutoModel.from_pretrained("fgaim/tiroberta-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 |
+
| BASE | 12 | 12 | 768 | 3072 | 125M | 512 |
|
84 |
+
|
85 |
+
### BiEncoder Model
|
86 |
+
|
87 |
+
- Max Seq Length: `512`
|
88 |
+
- Word embedding dimension: `768`
|
89 |
+
|
90 |
+
```
|
91 |
+
SentenceTransformer(
|
92 |
+
Transformer(
|
93 |
+
{
|
94 |
+
'max_seq_length': 512,
|
95 |
+
'do_lower_case': False
|
96 |
+
}
|
97 |
+
) # with Transformer model: RobertaModel
|
98 |
+
|
99 |
+
Pooling(
|
100 |
+
{
|
101 |
+
'word_embedding_dimension': 768,
|
102 |
+
'pooling_mode_cls_token': False,
|
103 |
+
'pooling_mode_mean_tokens': True,
|
104 |
+
'pooling_mode_max_tokens': False,
|
105 |
+
'pooling_mode_mean_sqrt_len_tokens': False,
|
106 |
+
'pooling_mode_weightedmean_tokens': False,
|
107 |
+
'pooling_mode_lasttoken': False,
|
108 |
+
'include_prompt': True,
|
109 |
+
}
|
110 |
+
)
|
111 |
+
)
|
112 |
+
```
|
113 |
+
|
114 |
+
## Cite
|
115 |
+
|
116 |
+
If you use this model in your product or research, you can cite it as follows:
|
117 |
+
|
118 |
+
```bibtex
|
119 |
+
@article{Fitsum2021TiPLMs,
|
120 |
+
author={Fitsum Gaim and Wonsuk Yang and Jong C. Park},
|
121 |
+
title={Monolingual Pre-trained Language Models for Tigrinya},
|
122 |
+
year=2021,
|
123 |
+
publisher={WiNLP 2021 co-located EMNLP 2021}
|
124 |
+
}
|
125 |
+
```
|