Improve language tag (#2)
Browse files- Improve language tag (bd0e35bc876d28574df2691408350da7d27de47d)
Co-authored-by: Loïck BOURDOIS <[email protected]>
README.md
CHANGED
@@ -1,104 +1,116 @@
|
|
1 |
-
---
|
2 |
-
library_name: transformers
|
3 |
-
license: apache-2.0
|
4 |
-
license_link: https://huggingface.co/huihui-ai/Qwen2.5-32B-Instruct-abliterated/blob/main/LICENSE
|
5 |
-
language:
|
6 |
-
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
-
|
11 |
-
-
|
12 |
-
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
#
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers
|
3 |
+
license: apache-2.0
|
4 |
+
license_link: https://huggingface.co/huihui-ai/Qwen2.5-32B-Instruct-abliterated/blob/main/LICENSE
|
5 |
+
language:
|
6 |
+
- zho
|
7 |
+
- eng
|
8 |
+
- fra
|
9 |
+
- spa
|
10 |
+
- por
|
11 |
+
- deu
|
12 |
+
- ita
|
13 |
+
- rus
|
14 |
+
- jpn
|
15 |
+
- kor
|
16 |
+
- vie
|
17 |
+
- tha
|
18 |
+
- ara
|
19 |
+
pipeline_tag: text-generation
|
20 |
+
base_model: Qwen/Qwen2.5-32B-Instruct
|
21 |
+
tags:
|
22 |
+
- chat
|
23 |
+
- abliterated
|
24 |
+
- uncensored
|
25 |
+
---
|
26 |
+
|
27 |
+
# huihui-ai/Qwen2.5-32B-Instruct-abliterated
|
28 |
+
|
29 |
+
|
30 |
+
This is an uncensored version of [Qwen2.5-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-32B-Instruct) created with abliteration (see [this article](https://huggingface.co/blog/mlabonne/abliteration) to know more about it).
|
31 |
+
|
32 |
+
Special thanks to [@FailSpy](https://huggingface.co/failspy) for the original code and technique. Please follow him if you're interested in abliterated models.
|
33 |
+
|
34 |
+
## ollama
|
35 |
+
|
36 |
+
You can use [huihui_ai/qwen2.5-abliterate:32b](https://ollama.com/huihui_ai/qwen2.5-abliterate:32b) directly,
|
37 |
+
```
|
38 |
+
ollama run huihui_ai/qwen2.5-abliterate:32b
|
39 |
+
```
|
40 |
+
|
41 |
+
## Usage
|
42 |
+
You can use this model in your applications by loading it with Hugging Face's `transformers` library:
|
43 |
+
|
44 |
+
|
45 |
+
```python
|
46 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
47 |
+
|
48 |
+
# Load the model and tokenizer
|
49 |
+
model_name = "huihui-ai/Qwen2.5-32B-Instruct-abliterated"
|
50 |
+
model = AutoModelForCausalLM.from_pretrained(
|
51 |
+
model_name,
|
52 |
+
torch_dtype="auto",
|
53 |
+
device_map="auto"
|
54 |
+
)
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
56 |
+
|
57 |
+
# Initialize conversation context
|
58 |
+
initial_messages = [
|
59 |
+
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."}
|
60 |
+
]
|
61 |
+
messages = initial_messages.copy() # Copy the initial conversation context
|
62 |
+
|
63 |
+
# Enter conversation loop
|
64 |
+
while True:
|
65 |
+
# Get user input
|
66 |
+
user_input = input("User: ").strip() # Strip leading and trailing spaces
|
67 |
+
|
68 |
+
# If the user types '/exit', end the conversation
|
69 |
+
if user_input.lower() == "/exit":
|
70 |
+
print("Exiting chat.")
|
71 |
+
break
|
72 |
+
|
73 |
+
# If the user types '/clean', reset the conversation context
|
74 |
+
if user_input.lower() == "/clean":
|
75 |
+
messages = initial_messages.copy() # Reset conversation context
|
76 |
+
print("Chat history cleared. Starting a new conversation.")
|
77 |
+
continue
|
78 |
+
|
79 |
+
# If input is empty, prompt the user and continue
|
80 |
+
if not user_input:
|
81 |
+
print("Input cannot be empty. Please enter something.")
|
82 |
+
continue
|
83 |
+
|
84 |
+
# Add user input to the conversation
|
85 |
+
messages.append({"role": "user", "content": user_input})
|
86 |
+
|
87 |
+
# Build the chat template
|
88 |
+
text = tokenizer.apply_chat_template(
|
89 |
+
messages,
|
90 |
+
tokenize=False,
|
91 |
+
add_generation_prompt=True
|
92 |
+
)
|
93 |
+
|
94 |
+
# Tokenize input and prepare it for the model
|
95 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
96 |
+
|
97 |
+
# Generate a response from the model
|
98 |
+
generated_ids = model.generate(
|
99 |
+
**model_inputs,
|
100 |
+
max_new_tokens=8192
|
101 |
+
)
|
102 |
+
|
103 |
+
# Extract model output, removing special tokens
|
104 |
+
generated_ids = [
|
105 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
106 |
+
]
|
107 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
108 |
+
|
109 |
+
# Add the model's response to the conversation
|
110 |
+
messages.append({"role": "assistant", "content": response})
|
111 |
+
|
112 |
+
# Print the model's response
|
113 |
+
print(f"Qwen: {response}")
|
114 |
+
|
115 |
+
```
|
116 |
+
|