Transformers
Safetensors
Generated from Trainer
trl
sft
NiGuLa commited on
Commit
e7dfb06
·
verified ·
1 Parent(s): 3167db2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +67 -0
README.md CHANGED
@@ -18,6 +18,8 @@ language:
18
  - uk
19
  - zh
20
  license: apache-2.0
 
 
21
  ---
22
 
23
 
@@ -26,7 +28,72 @@ It has been trained using [TRL](https://github.com/huggingface/trl) with [textde
26
 
27
  ## Quick start
28
 
 
 
 
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
 
32
  ### Training framework versions
 
18
  - uk
19
  - zh
20
  license: apache-2.0
21
+ datasets:
22
+ - textdetox/detoxification_pairwise_style_evaluation
23
  ---
24
 
25
 
 
28
 
29
  ## Quick start
30
 
31
+ ```python
32
+ from transformers import AutoTokenizer, AutoModelForCausalLM
33
+ from peft import PeftModel
34
+ import torch
35
 
36
+ # Load base model and tokenizer
37
+ base_model = "meta-llama/Meta-Llama-3-8B-Instruct"
38
+ model = AutoModelForCausalLM.from_pretrained(
39
+ base_model,
40
+ device_map="auto",
41
+ torch_dtype=torch.bfloat16,
42
+ token=<your-token>
43
+ )
44
+ tokenizer = AutoTokenizer.from_pretrained(base_model)
45
+
46
+ # Load LoRA adapter
47
+ lora_model = "textdetox/Llama-pairwise-toxicity-evaluator"
48
+ model = PeftModel.from_pretrained(model, lora_model)
49
+
50
+ # Set to eval mode
51
+ model.eval()
52
+
53
+ # === Input texts (example) ===
54
+ text1 = "You're such a waste of space, nobody likes you."
55
+ text2 = "I don't agree with you, but I respect your opinion."
56
+
57
+ # === Prompt ===
58
+ prompt = f"""You are given with two texts. Your task is to compare which text is more toxic.
59
+
60
+ Options:
61
+
62
+ - text1 (text1 is more toxic than text2)
63
+ - text2 (text2 is more toxic than text1)
64
+ - None (both texts have equal toxicity - both of them are either toxic or non-toxic at the same time)
65
+
66
+ Examples:
67
+ text1: "I hate you, you are the worst person ever."
68
+ text2: "I love you, you are the best person ever."
69
+ Answer: text1
70
+
71
+ text1: "You are so smart, I can't believe you did that."
72
+ text2: "You are so stupid, I can't believe you did that."
73
+ Answer: text2
74
+
75
+ text1: "I think you are a great person."
76
+ text2: "I think you are a very good man"
77
+ Answer: none
78
+
79
+ You must return ONLY one of the options. Do not add any explanations or additional information.
80
+
81
+ text1: {text1}
82
+ text2: {text2}
83
+ Answer:"""
84
+
85
+ # Tokenize
86
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
87
+
88
+ # Generate output
89
+ with torch.no_grad():
90
+ outputs = model.generate(**inputs, max_new_tokens=5)
91
+ answer = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
92
+
93
+ # Print result
94
+ print("Model prediction:", answer.strip())
95
+
96
+ ```
97
 
98
 
99
  ### Training framework versions