Views
No views yet
google/mt5-xl for the task of sense-preserving definitional expansion in Dutch.mT5-xl model represents a key baseline in the study acting as the "unaligned blank slate" against which more modern instruction-tuned models were compared. Unlike models pre-aligned for conversational interaction mT5 was pre-trained exclusively on an unsupervised objective without instruction tuning making it a pure test of domain adaptation through fine-tuning.1import torch
2from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, BitsAndBytesConfig
3from peft import PeftModel
4
5base_model_id = "google/mt5-xl"
6adapter_id = "RobbedoesHF/mt5-xl-dutch-definition-expansion-qlora" # The repo ID of this adapter
7
8# Load the base model with 4-bit quantization
9bnb_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype=torch.bfloat16,
13)
14
15model = AutoModelForSeq2SeqLM.from_pretrained(
16 base_model_id,
17 quantization_config=bnb_config,
18 device_map="auto",
19)
20tokenizer = AutoTokenizer.from_pretrained(base_model_id)
21
22# Apply the LoRA adapter
23model = PeftModel.from_pretrained(model, adapter_id)
24
25print("Model loaded successfully!")1# Define the lemma and short definition you want to expand
2lemma = "ecoroman"
3short_def = "roman over milieuproblematiek"
4
5# Define the prompt components, matching the training script
6system_prompt = "Je bent een expert-lexicograaf die definities schrijft voor een Nederlands woordenboek."
7instruction = f"Breid de volgende korte definitie voor het woord '{lemma}' uit tot een volledige definitie: '{short_def}'"
8prompt = f"{system_prompt}\n\n{instruction}"
9
10# Tokenize the prompt
11inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
12
13# Generate the output tokens
14print("
15Generating definition...")
16with torch.no_grad():
17 outputs = model.generate(
18 **inputs,
19 max_new_tokens=512, # Chosen based on the longest full definition's token length for this model
20 num_beams=4, # What was used for the thesis
21 early_stopping=True
22 )
23
24# Decode the tokens into a string
25decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
26
27print("\n--- Prompt ---")
28print(prompt)
29print("\n--- Model Output ---")
30print(decoded_output)