Views
No views yet
" Input: \"{sentence}\""1import torch
2
3from transformers import AutoModelForCausalLM, AutoTokenizer
4from transformers.trainer_utils import set_seed
5
6target_word = "long"
7instruction = f"Give a brief definition of the word \"{target_word}\" in the sentence given as input. Generate only the definition."
8input_sentence = "How long has it been since you reviewed the objectives of your benefit and service program?"
9
10model_id = "swap-uniba/LLM-wsd-FT-ALL"
11
12set_seed(42)
13
14tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
15
16tokenizer.padding_side = "left"
17
18model = AutoModelForCausalLM.from_pretrained(
19 model_id,
20 device_map='cuda',
21 torch_dtype=torch.bfloat16,
22).eval()
23
24terminators = [
25 tokenizer.eos_token_id,
26 tokenizer.convert_tokens_to_ids("<|eot_id|>")
27]
28
29messages = [
30 {"role": "user", "content": instruction + " Input: \"" + input_sentence + "\""},
31]
32
33input_ids = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
34
35outputs = model.generate(
36 input_ids.to('cuda'),
37 max_new_tokens=512,
38 eos_token_id=terminators,
39 num_beams=1,
40 do_sample=False
41)
42
43print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))1import torch
2
3from transformers import AutoModelForCausalLM, AutoTokenizer
4from transformers.trainer_utils import set_seed
5
6target_word = "hurry"
7instruction = f"Given the word \"{target_word}\" in the input sentence, choose the correct meaning from the following:\n1) Move very fast\n2) Urge to an unnatural speed\n\nGenerate only the number of the selected option."
8input_sentence = "If you hurry you might beat the headquarters boys."
9
10model_id = "swap-uniba/LLM-wsd-FT-ALL"
11
12set_seed(42)
13
14tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
15
16tokenizer.padding_side = "left"
17
18model = AutoModelForCausalLM.from_pretrained(
19 model_id,
20 device_map='cuda',
21 torch_dtype=torch.bfloat16,
22).eval()
23
24terminators = [
25 tokenizer.eos_token_id,
26 tokenizer.convert_tokens_to_ids("<|eot_id|>")
27]
28
29messages = [
30 {"role": "user", "content": instruction + " Input: \"" + input_sentence + "\""},
31]
32
33input_ids = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
34
35outputs = model.generate(
36 input_ids.to('cuda'),
37 max_new_tokens=512,
38 eos_token_id=terminators,
39 num_beams=1,
40 do_sample=False
41)
42
43print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))1@misc{basile2025exploringwordsensedisambiguation,
2 title={Exploring the Word Sense Disambiguation Capabilities of Large Language Models},
3 author={Pierpaolo Basile and Lucia Siciliani and Elio Musacchio and Giovanni Semeraro},
4 year={2025},
5 eprint={2503.08662},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2503.08662},
9}"Give a brief definition of the word \"{target_word}\" in the sentence given as input. Generate only the definition.""Donnez une brève définition du mot \"{target_word}\" dans la phrase d’entrée donnée. Ne donnez que la définition.""Geben Sie eine kurze Definition des Wortes \"{target_word}\" in dem gegebenen Satz an. Erzeugen Sie nur die Definition.""Fornisci una breve definizione della parola \"{target_word}\" nella frase data in input. Genera solo la definizione.""Proporciona una definición breve de la palabra \"{target_word}\" en la frase dada en entrada. Genera solo la definición.""Give a brief definition of the {occurrence} occurrence of the word \"{target_word}\" in the sentence given as input. Generate only the definition.""Donnez une brève définition de l'occurrence {occurrence} du mot \"{target_word}\" dans la phrase d’entrée donnée. Ne donnez que la définition.""Geben Sie eine kurze Definition des {occurrence} Vorkommens des Wortes \"{target_word}\" in dem gegebenen Eingabesatz an. Erzeugen Sie nur die Definition.""Fornisci una breve definizione della {occurrence} occorrenza della parola \"{target_word}\" nella frase data in input. Genera solo la definizione.""Proporciona una definición breve de la {occurrence} ocurrencia de la palabra \"{target_word}\" en la frase dada en entrada. Genera solo la definición.""Given the word \"{target_word}\" in the input sentence, choose the correct meaning from the following:\n{options}\n\nGenerate only the number of the selected option.""Étant donné le mot \"{target_word}\" dans la phrase saisie, choisissez la signification correcte parmi les suivantes:\n{options}\n\nNe donnez que le numéro de l’option sélectionnée.""Wählen Sie für das Wort \"{target_word}\" im Eingabesatz die richtige Bedeutung aus den folgenden Angaben:\n{options}\n\nErzeugt nur die Nummer der ausgewählten Option""Data la parola \"{target_word}\" nella frase in input, scegli il significato corretto tra i seguenti:\n{options}\n\nGenera solo il numero dell'opzione selezionata.""Dada la palabra \"{target_word}\" en la frase de entrada, elija el significado correcto entre los siguientes:\n{options}\n\nGenera solo el número de la opción seleccionada.""Given the word \"{target_word}\" in the input sentence, choose the correct meaning from the following:\n{options}\n\nGenerate only the number of the selected option.""Étant donné l'occurrence {occurrence} du mot \"{target_word}\" dans la phrase d'entrée, choisissez la signification correcte parmi les suivantes:\n{options}\n\nNe donnez que le numéro de l’option sélectionnée.""Wählen Sie angesichts des {occurrence} Vorkommens des Wortes \"{target_word}\" im Eingabesatz die richtige Bedeutung aus der folgenden Liste aus:\n{options}\n\nErzeugt nur die Nummer der ausgewählten Option.""Data la {occurrence} occorrenza della parola \"{target_word}\" nella frase in input, scegli il significato corretto tra i seguenti:\n{options}\n\nGenera solo il numero dell'opzione selezionata.""Dada la {occurrence} ocurrencia de la palabra \"{target_word}\" en la frase de entrada, elije el significado correcto entre los siguientes:\n{options}\n\nGenera solo el número de la opción seleccionada."