You can use the model with sentence-transformers like this:
python
1from sentence_transformers import SentenceTransformer
2sentences =["This is an example sentence","Each sentence is converted"]34model = SentenceTransformer('kevinkrahn/shlm-grc-en')5embeddings = model.encode(sentences)6print(embeddings)
Usage (HuggingFace Transformers)
Without sentence-transformers, you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
python
1from transformers import AutoTokenizer, AutoModel
2import torch
345defcls_pooling(model_output):6return model_output[0][:,0]789# Sentences we want sentence embeddings for10sentences =['This is an English sentence','Ὁ Παρθενών ἐστιν ἱερὸν καλὸν τῆς Ἀθήνης.']1112# Load model from HuggingFace Hub13model = AutoModel.from_pretrained('kevinkrahn/shlm-grc-en', trust_remote_code=True)14tokenizer = AutoTokenizer.from_pretrained('kevinkrahn/shlm-grc-en', trust_remote_code=True)1516# Tokenize sentences17encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')1819# Compute token embeddings20with torch.no_grad():21 model_output = model(**encoded_input)2223# Perform pooling. In this case, cls pooling.24sentence_embeddings = cls_pooling(model_output)2526print("Sentence embeddings:")27print(sentence_embeddings)28
Citing & Authors
If you use this model please cite the following papers:
@inproceedings{riemenschneider-krahn-2024-heidelberg,
title = "Heidelberg-Boston @ {SIGTYP} 2024 Shared Task: Enhancing Low-Resource Language Analysis With Character-Aware Hierarchical Transformers",
author = "Riemenschneider, Frederick and
Krahn, Kevin",
editor = "Hahn, Michael and
Sorokin, Alexey and
Kumar, Ritesh and
Shcherbakov, Andreas and
Otmakhova, Yulia and
Yang, Jinrui and
Serikov, Oleg and
Rani, Priya and
Ponti, Edoardo M. and
Murado{\u{g}}lu, Saliha and
Gao, Rena and
Cotterell, Ryan and
Vylomova, Ekaterina",
booktitle = "Proceedings of the 6th Workshop on Research in Computational Linguistic Typology and Multilingual NLP",
month = mar,
year = "2024",
address = "St. Julian's, Malta",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2024.sigtyp-1.16",
pages = "131--141",
}
@inproceedings{krahn-etal-2023-sentence,
title = "Sentence Embedding Models for {A}ncient {G}reek Using Multilingual Knowledge Distillation",
author = "Krahn, Kevin and
Tate, Derrick and
Lamicela, Andrew C.",
editor = "Anderson, Adam and
Gordin, Shai and
Li, Bin and
Liu, Yudong and
Passarotti, Marco C.",
booktitle = "Proceedings of the Ancient Language Processing Workshop",
month = sep,
year = "2023",
address = "Varna, Bulgaria",
publisher = "INCOMA Ltd., Shoumen, Bulgaria",
url = "https://aclanthology.org/2023.alp-1.2",
pages = "13--22",
}