Views
No views yet
meta-llama/Llama-3.2-1B-Instruct for generating concise one-line Python docstrings from function bodies.meta-llama/Llama-3.2-1B-Instruct (Meta Llama 3.2 Community License)meta-llama/Llama-3.2-1B-Instruct1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3
4base_model_id = "meta-llama/Llama-3.2-1B-Instruct"
5adapter_id = "Abdul1102/llama32-1b-python-docstrings-qlora"
6
7tokenizer = AutoTokenizer.from_pretrained(base_model_id)
8model = AutoModelForCausalLM.from_pretrained(base_model_id, device_map="auto")
9model = PeftModel.from_pretrained(model, adapter_id)
10
11def make_prompt(code: str) -> str:
12 return
13 f'Write a one-line Python docstring for this function:\n\n{code}\n\n"""'
14
15code = "def add(a, b):\n return a + b"
16inputs = tokenizer(make_prompt(code), return_tensors="pt").to(model.device)
17outputs = model.generate(**inputs, max_new_tokens=32, do_sample=False)
18text = tokenizer.decode(outputs[0], skip_special_tokens=True)
19print(text)Nan-Do/code-search-net-python)code column (full Python function body)docstringTrainercode → one-line docstring mapping.