Views
No views yet
A ->+ B (positive) and A ->- B (negative) from natural-language paragraphs.License: Derivative of Qwen/Qwen2.5-1.5B. SeeLICENSE. Users must comply with the base license.
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3import re
4
5MODEL = "dorito96/qwen2.5-1.5b_causal"
6
7tok = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
8model = AutoModelForCausalLM.from_pretrained(
9 MODEL,
10 dtype=(torch.bfloat16 if torch.cuda.is_available() and torch.cuda.is_bf16_supported()
11 else (torch.float16 if torch.cuda.is_available() else torch.float32)),
12 device_map=("auto" if torch.cuda.is_available() else "cpu"),
13 trust_remote_code=True,
14)
15model.eval()
16
17PROMPT_PREFIX = "### Paragraph:\n"
18TARGET_PREFIX = "\n\n### Targets:\n"
19
20paragraph = "More rainfall increases crop yield."
21prompt = f"{PROMPT_PREFIX}{paragraph}{TARGET_PREFIX}"
22
23inputs = tok(prompt, return_tensors="pt").to(next(model.parameters()).device)
24gen = model.generate(
25 **inputs,
26 max_new_tokens=128,
27 num_beams=6,
28 do_sample=False,
29 eos_token_id=tok.eos_token_id,
30 pad_token_id=tok.pad_token_id,
31 no_repeat_ngram_size=3,
32)
33text = tok.decode(gen[0, inputs['input_ids'].shape[1]:], skip_special_tokens=True).strip()
34print(text) # rainfall ->+ crop yield