Downloads · 30 days
17
3% of all-time downloads
kyriemao/gtr-t5-base
gtr-t5-base is a machine learning model from kyriemao. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
This is the huggingface transformers (HF) version of sentencetrannsformers/gtr-t5-base, which is originally in SentenceTransformer form.
Downloads · 30 days
17
3% of all-time downloads
All-time downloads
617
Public
Parameters
110M
441 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors441 MB · 100%
From the Hugging Face model README
This is the huggingface transformers (HF) version of sentence_trannsformers/gtr-t5-base, which is originally in SentenceTransformer form.
The model architecture:
class GTR(T5PreTrainedModel):
def __init__(self, config):
super().__init__(config)
# T5EncoderModel.__init__(self, config)
self.t5_encoder = T5EncoderModel(config)
self.embeddingHead = nn.Linear(config.hidden_size, config.hidden_size, bias=False) # gtr has
self.activation = torch.nn.Identity()
self.model_parallel = False
def pooling(self, token_embeddings, attention_mask):
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1)
sum_mask = input_mask_expanded.sum(1)
sum_mask = torch.clamp(sum_mask, min=1e-9)
return sum_embeddings / sum_mask
def forward(self, input_ids, attention_mask):
output = self.t5_encoder(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state
output = self.pooling(output, attention_mask)
output = self.activation(self.embeddingHead(output))
output = F.normalize(output, p=2, dim=1)
return output
The operations of this model follow the standard operations of HF. For example,
To load the model, run
model = GTR.from_pretrainend('kyriemao/gtr-t5-base')
To get the forward embeddings:
from transformers import AutoTokenizer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = GTR.from_pretrained('kyriemao/gtr-t5-base')
tokenizer = AutoTokenizer.from_pretrained('kyriemao/gtr-t5-base')
input_encodings = tokenizer(sentences, padding=True, return_tensors='pt')
output = model(**input_encodings)