Views
No views yet
sentence-transformers/paraphrase-multilingual-mpnet-base-v2. See our paper Contextual Embeddings for Ukrainian: A Large Language Model Approach to Word Sense Disambiguation for details.pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2sentences = ["This is an example sentence", "Each sentence is converted"]
3model = SentenceTransformer('lang-uk/ukr-paraphrase-multilingual-mpnet-base')
4embeddings = model.encode(sentences)
5print(embeddings)1from transformers import AutoTokenizer, AutoModel
2import torch
3#Mean Pooling - Take attention mask into account for correct averaging
4def mean_pooling(model_output, attention_mask):
5 token_embeddings = model_output[0] #First element of model_output contains all token embeddings
6 input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
7 return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
8# Sentences we want sentence embeddings for
9sentences = ['This is an example sentence', 'Each sentence is converted']
10# Load model from HuggingFace Hub
11tokenizer = AutoTokenizer.from_pretrained('lang-uk/ukr-paraphrase-multilingual-mpnet-base')
12model = AutoModel.from_pretrained('lang-uk/ukr-paraphrase-multilingual-mpnet-base')
13# Tokenize sentences
14encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
15# Compute token embeddings
16with torch.no_grad():
17 model_output = model(**encoded_input)
18# Perform pooling. In this case, average pooling
19sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
20print("Sentence embeddings:")
21print(sentence_embeddings)1@inproceedings{laba-etal-2023-contextual,
2 title = "Contextual Embeddings for {U}krainian: A Large Language Model Approach to Word Sense Disambiguation",
3 author = "Laba, Yurii and
4 Mudryi, Volodymyr and
5 Chaplynskyi, Dmytro and
6 Romanyshyn, Mariana and
7 Dobosevych, Oles",
8 editor = "Romanyshyn, Mariana",
9 booktitle = "Proceedings of the Second Ukrainian Natural Language Processing Workshop (UNLP)",
10 month = may,
11 year = "2023",
12 address = "Dubrovnik, Croatia",
13 publisher = "Association for Computational Linguistics",
14 url = "https://aclanthology.org/2023.unlp-1.2",
15 doi = "10.18653/v1/2023.unlp-1.2",
16 pages = "11--19",
17 abstract = "This research proposes a novel approach to the Word Sense Disambiguation (WSD) task in the Ukrainian language based on supervised fine-tuning of a pre-trained Large Language Model (LLM) on the dataset generated in an unsupervised way to obtain better contextual embeddings for words with multiple senses. The paper presents a method for generating a new dataset for WSD evaluation in the Ukrainian language based on the SUM dictionary. We developed a comprehensive framework that facilitates the generation of WSD evaluation datasets, enables the use of different prediction strategies, LLMs, and pooling strategies, and generates multiple performance reports. Our approach shows 77,9{\%} accuracy for lexical meaning prediction for homonyms.",
18}