Bill Cai commited on
Commit
a9d3acf
1 Parent(s): 4f8e9c4

added model

Browse files
README.md CHANGED
@@ -1,3 +1,103 @@
1
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: apache-2.0
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ - zh
5
+ - ms
6
+ - ta
7
+ datasets:
8
+ - billcai/ospc-dataset-v2
9
+ tags:
10
+ - multilingual
11
+ - mistral
12
+ - sft
13
+ - chat
14
+ - instruction
15
+ - gptq
16
+ widget:
17
+ - text: "Hello World"
18
+ example_title: "Sample prompt"
19
  license: apache-2.0
20
+ base_model: openchat/openchat-3.5-0106
21
  ---
22
+
23
+ This model achieved 0.7600 AUROC for the [Online Safety Prize Challenge](https://ospc.aisingapore.org/) organized by AI Singapore. It is fine-tuned from [Openchat model](https://huggingface.co/openchat/openchat-3.5-0106). Note, this model is already quantized to 4-bit GPTQ.
24
+
25
+ ## Training details
26
+ This model is trained on a synthetic dataset generated by Apache 2.0 licensed LLMs (Mistral and Mixtral).
27
+
28
+ ## How to use
29
+
30
+ You can either use it to classify text or text + extracted visual description.
31
+
32
+ ```python
33
+ from transformers import AutoModelForCausalLM, AutoTokenizer
34
+ device = "cuda"
35
+
36
+ model = AutoModelForCausalLM.from_pretrained(
37
+ 'billcai/openchat-model-ospc',
38
+ torch_dtype="auto",
39
+ device_map="auto"
40
+ )
41
+
42
+ tokenizer = AutoTokenizer.from_pretrained('billcai/openchat-model-ospc')
43
+
44
+ promptText = "<the prompt to be tested>"
45
+ # promptText = "Image: <image caption>, Caption: <text within image>"
46
+
47
+ prompt = """Check if there is unsafe content in the following message. Unsafe content is defined in the following categories.
48
+ <BEGIN UNSAFE CONTENT CATEGORIES>
49
+ Contains hate speech and harmful content. Harmful content centres on divisive and contentious subject matters. Typical areas include:
50
+ - Racial disparities
51
+ - Religious beliefs and practices
52
+ - Sexual orientation
53
+ - Nationalistic sentiments and xenophobia against migrants
54
+ - Socio-economic divides and class struggles
55
+ - Age-related biases
56
+ - Gender discrimination
57
+ - Discrimination based on illnesses and disabilities
58
+ These content may be based on Singapore context, including the use of non-English languages like Mandarin, Malay and Tamil.
59
+ <END UNSAFE CONTENT CATEGORIES>
60
+
61
+ This is the message you are checking if it contains unsafe content.
62
+ <BEGIN MESSAGE>
63
+ {}
64
+ <END MESSAGE>
65
+
66
+ Provide your safety assessment for the message above. Your first line MUST read 'safe' or 'unsafe'.
67
+ """.format(
68
+ promptText
69
+ )
70
+
71
+ messages = [
72
+ {"role": "system", "content": "You are a helpful assistant deciding whether a piece of content is safe or unsafe based on specific criteria. The content may contain irrelevant words as it has been extracted from an image."},
73
+ {"role": "user", "content": prompt}
74
+ ]
75
+ text = tokenizer.apply_chat_template(
76
+ messages,
77
+ tokenize=False,
78
+ add_generation_prompt=True
79
+ )
80
+
81
+ model_inputs = tokenizer([text], return_tensors="pt").to('cuda')
82
+ generation_output = llm.generate(
83
+ model_inputs.input_ids,
84
+ max_new_tokens=10,
85
+ temperature=0.1,
86
+ output_logits=True,
87
+ return_dict_in_generate=True
88
+ )
89
+ generated_sequences = generation_output['sequences']
90
+ generated_logits = generation_output['logits']
91
+ unsafeTokenId = tokenizer.encode('unsafe')[1]
92
+ safeTokenId = tokenizer.encode('safe')[1]
93
+ firstLogit = generated_logits[0].cpu().numpy()
94
+ prob = softmax([
95
+ firstLogit[0,unsafeTokenId],
96
+ firstLogit[0,safeTokenId],
97
+ ])
98
+ print(prob) # first is score for unsafe token.
99
+ ```
100
+
101
+ # License
102
+
103
+ Apache 2.0
added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "<|end_of_turn|>": 32000,
3
+ "<|pad_0|>": 32001
4
+ }
config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/home/tars/memes/memes2024/openchat-3.5-0106",
3
+ "architectures": [
4
+ "MistralForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "eos_token_id": 32000,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 4096,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 14336,
13
+ "max_position_embeddings": 8192,
14
+ "model_type": "mistral",
15
+ "num_attention_heads": 32,
16
+ "num_hidden_layers": 32,
17
+ "num_key_value_heads": 8,
18
+ "quantization_config": {
19
+ "bits": 4,
20
+ "damp_percent": 0.1,
21
+ "dataset": "c4-new",
22
+ "desc_act": false,
23
+ "group_size": 128,
24
+ "modules_in_block_to_quantize": null,
25
+ "quant_method": "gptq",
26
+ "sym": true,
27
+ "true_sequential": true
28
+ },
29
+ "rms_norm_eps": 1e-05,
30
+ "rope_theta": 10000.0,
31
+ "sliding_window": 4096,
32
+ "tie_word_embeddings": false,
33
+ "torch_dtype": "float32",
34
+ "transformers_version": "4.39.1",
35
+ "use_cache": true,
36
+ "vocab_size": 32002
37
+ }
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 1,
3
+ "eos_token_id": 32000,
4
+ "max_length": 8192,
5
+ "pad_token_id": 0,
6
+ "transformers_version": "4.39.1"
7
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d6ae2e57f096c5d7fe8d5c0be87e4202032509fa628f96be7e7f45bd7ef9bbdb
3
+ size 4795352944
special_tokens_map.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|end_of_turn|>",
4
+ "<|pad_0|>"
5
+ ],
6
+ "bos_token": {
7
+ "content": "<s>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false
12
+ },
13
+ "eos_token": {
14
+ "content": "<|end_of_turn|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false
19
+ },
20
+ "pad_token": "<unk>",
21
+ "unk_token": {
22
+ "content": "<unk>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false
27
+ }
28
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dadfd56d766715c61d2ef780a525ab43b8e6da4de6865bda3d95fdef5e134055
3
+ size 493443
tokenizer_config.json ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "32000": {
30
+ "content": "<|end_of_turn|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "32001": {
38
+ "content": "<|pad_0|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ }
45
+ },
46
+ "additional_special_tokens": [
47
+ "<|end_of_turn|>",
48
+ "<|pad_0|>"
49
+ ],
50
+ "bos_token": "<s>",
51
+ "chat_template": "{{ bos_token }}{% for message in messages %}{{ 'GPT4 Correct ' + message['role'].title() + ': ' + message['content'] + '<|end_of_turn|>'}}{% endfor %}{% if add_generation_prompt %}{{ 'GPT4 Correct Assistant:' }}{% endif %}",
52
+ "clean_up_tokenization_spaces": false,
53
+ "eos_token": "<|end_of_turn|>",
54
+ "legacy": true,
55
+ "model_max_length": 8192,
56
+ "pad_token": "<unk>",
57
+ "padding_side": "right",
58
+ "sp_model_kwargs": {},
59
+ "spaces_between_special_tokens": false,
60
+ "tokenizer_class": "LlamaTokenizer",
61
+ "unk_token": "<unk>",
62
+ "use_default_system_prompt": true
63
+ }