Views
No views yet
BramVanroy/GEITje-7B-ultra for the task of sense-preserving definitional expansion in Dutch.GEITje-7B-ultra model was a key subject in the study for testing the domain mismatch hypothesis. As a model heavily aligned for conversational interaction its performance was analysed to see if this stylistic prior would conflict with the formal structured nature of lexicographical text.1import torch
2from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, BitsAndBytesConfig
3from peft import PeftModel
4
5base_model_id = "BramVanroy/GEITje-7B-ultra"
6adapter_id = "RobbedoesHF/geitje-7b-ultra-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 attn_implementation="flash_attention_2", # Recommended for GEITje
20)
21tokenizer = AutoTokenizer.from_pretrained(base_model_id)
22tokenizer.pad_token = tokenizer.eos_token # Set pad token
23
24# Apply the LoRA adapter
25model = PeftModel.from_pretrained(model, adapter_id)
26
27print("Model loaded successfully!")1# Define the lemma and short definition you want to expand
2lemma = "ecoroman"
3short_def = "roman over milieuproblematiek"
4
5
6# Create the chat prompt using the tokenizer's template
7chat = [
8 {"role": "system", "content": "Je bent een expert-lexicograaf die definities schrijft voor een Nederlands woordenboek."},
9 {"role": "user", "content": f"Breid de volgende korte definitie voor het woord '{lemma}' uit tot een volledige definitie: '{short_def}'"}
10]
11prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
12
13# Tokenize the prompt
14inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
15
16# Generate the output tokens
17print("
18Generating definition...")
19with torch.no_grad():
20 outputs = model.generate(
21 **inputs,
22 max_new_tokens=512, # Chosen based on the longest full definition's token length for this model
23 num_beams=4, # What was used for the thesis
24 early_stopping=True,
25 pad_token_id=tokenizer.eos_token_id
26 )
27
28# Decode and clean the output
29# The output includes the prompt so we split for the assistant's response
30decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
31assistant_response = decoded_output.split("<|assistant|>")[1].strip()
32
33print("\n--- Prompt ---")
34print(prompt)
35print("\n--- Model Output ---")
36print(decoded_output)