Add Model Card
Browse files
README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 bi-encoder model for the Tigrinya language based on [TiELECTRA-small](https://huggingface.co/fgaim/tielectra-small).
|
| 18 |
+
The model maps sentences & paragraphs to a 256 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 larger and more powerful model look at [TiRoBERTa-bi-encoder](https://huggingface.co/fgaim/tiroberta-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/tielectra-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/tielectra-bi-encoder")
|
| 63 |
+
model = AutoModel.from_pretrained("fgaim/tielectra-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 |
+
| SMALL | 12 | 4 | 256 | 1024 | 14M | 512 |
|
| 87 |
+
|
| 88 |
+
### BiEncoder Model
|
| 89 |
+
|
| 90 |
+
- Max Seq Length: `512`
|
| 91 |
+
- Word embedding dimension: `256`
|
| 92 |
+
|
| 93 |
+
```text
|
| 94 |
+
SentenceTransformer(
|
| 95 |
+
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: ElectraModel
|
| 96 |
+
|
| 97 |
+
(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})
|
| 98 |
+
)
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
## Citation
|
| 102 |
+
|
| 103 |
+
If you use this model in your product or research, you can cite it as follows:
|
| 104 |
+
|
| 105 |
+
```bibtex
|
| 106 |
+
@misc{gaim-2024-semantic-search,
|
| 107 |
+
title = {{Semantic Search Models for Tigrinya}},
|
| 108 |
+
author = {Fitsum Gaim},
|
| 109 |
+
month = {January},
|
| 110 |
+
year = {2024},
|
| 111 |
+
publisher = {Hugging Face Hub},
|
| 112 |
+
doi = {10.57967/hf/6068},
|
| 113 |
+
url = {https://huggingface.co/fgaim/tiroberta-bi-encoder}
|
| 114 |
+
}
|
| 115 |
+
```
|