Doron Adler commited on
Commit
c8ddd98
1 Parent(s): 363236f

Updated model metadata, Added temperature slider

Browse files
app.py CHANGED
@@ -22,7 +22,7 @@ def load_model(model_name):
22
  model = AutoModelForCausalLM.from_pretrained(model_name)
23
  return model, tokenizer
24
 
25
- def extend(input_text, max_size=20, top_k=50, top_p=0.95):
26
  if len(input_text) == 0:
27
  input_text = ""
28
 
@@ -40,9 +40,10 @@ def extend(input_text, max_size=20, top_k=50, top_p=0.95):
40
  input_ids=input_ids,
41
  max_length=max_size + len(encoded_prompt[0]),
42
  top_k=top_k,
43
- top_p=top_p,
 
44
  do_sample=True,
45
- repetition_penalty=5.0,
46
  num_return_sequences=1)
47
 
48
  # Remove the batch dimension when returning multiple sequences
@@ -100,9 +101,10 @@ if __name__ == "__main__":
100
 
101
  st.sidebar.subheader("Configurable parameters")
102
 
103
- max_len = st.sidebar.slider("Max-Length", 0, 512, 160,help="The maximum length of the sequence to be generated.")
104
  top_k = st.sidebar.slider("Top-K", 0, 100, 40, help="The number of highest probability vocabulary tokens to keep for top-k-filtering.")
105
  top_p = st.sidebar.slider("Top-P", 0.0, 1.0, 0.92, help="If set to float < 1, only the most probable tokens with probabilities that add up to top_p or higher are kept for generation.")
 
106
 
107
  if st.button("Generate Text"):
108
  with st.spinner(text="Generating results..."):
@@ -113,12 +115,13 @@ if __name__ == "__main__":
113
  result = extend(input_text=text_area,
114
  max_size=int(max_len),
115
  top_k=int(top_k),
116
- top_p=float(top_p))
 
117
 
118
  print("Done length: " + str(len(result)) + " bytes")
119
  #<div class="rtl" dir="rtl" style="text-align:right;">
120
  st.markdown(f"<p dir=\"rtl\" style=\"text-align:right;\"> {result} </p>", unsafe_allow_html=True)
121
- st.write("\n\nResult length: " + str(len(result)) + " bytes\n Random seed: " + str(random_seed) + "\ntop_k: " + str(top_k) + "\ntop_p: " + str(top_p) + "\nmax_len: " + str(max_len) + "\ndevice: " + str(device) + "\nn_gpu: " + str(n_gpu))
122
  print(f"\"{result}\"")
123
 
124
  st.markdown(
 
22
  model = AutoModelForCausalLM.from_pretrained(model_name)
23
  return model, tokenizer
24
 
25
+ def extend(input_text, max_size=20, top_k=50, top_p=0.95, temperature=0.7):
26
  if len(input_text) == 0:
27
  input_text = ""
28
 
 
40
  input_ids=input_ids,
41
  max_length=max_size + len(encoded_prompt[0]),
42
  top_k=top_k,
43
+ top_p=top_p,
44
+ temperature=temperature,
45
  do_sample=True,
46
+ repetition_penalty=2.0,
47
  num_return_sequences=1)
48
 
49
  # Remove the batch dimension when returning multiple sequences
 
101
 
102
  st.sidebar.subheader("Configurable parameters")
103
 
104
+ max_len = st.sidebar.slider("Max-Length", 0, 256, 160,help="The maximum length of the sequence to be generated.")
105
  top_k = st.sidebar.slider("Top-K", 0, 100, 40, help="The number of highest probability vocabulary tokens to keep for top-k-filtering.")
106
  top_p = st.sidebar.slider("Top-P", 0.0, 1.0, 0.92, help="If set to float < 1, only the most probable tokens with probabilities that add up to top_p or higher are kept for generation.")
107
+ temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 1.0, help="The value used to module the randomness of the output tokens.")
108
 
109
  if st.button("Generate Text"):
110
  with st.spinner(text="Generating results..."):
 
115
  result = extend(input_text=text_area,
116
  max_size=int(max_len),
117
  top_k=int(top_k),
118
+ top_p=float(top_p),
119
+ temperature=float(temperature))
120
 
121
  print("Done length: " + str(len(result)) + " bytes")
122
  #<div class="rtl" dir="rtl" style="text-align:right;">
123
  st.markdown(f"<p dir=\"rtl\" style=\"text-align:right;\"> {result} </p>", unsafe_allow_html=True)
124
+ st.write("\n\nResult length: " + str(len(result)) + " bytes\n Random seed: " + str(random_seed) + "\ntop_k: " + str(top_k) + "\ntop_p: " + str(top_p) + "\ntemperature: " + str(temperature) + "\nmax_len: " + str(max_len) + "\ndevice: " + str(device) + "\nn_gpu: " + str(n_gpu))
125
  print(f"\"{result}\"")
126
 
127
  st.markdown(
model/added_tokens.json CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "<|endoftext|>": 50257,
3
- "<|pad|>": 50260,
4
- "<|startoftext|>": 50258,
5
- "<|unknown|>": 50259
6
- }
 
1
+ {
2
+ "<|endoftext|>": 50257,
3
+ "<|pad|>": 50260,
4
+ "<|startoftext|>": 50258,
5
+ "<|unknown|>": 50259
6
+ }
model/config.json CHANGED
@@ -1,54 +1,54 @@
1
- {
2
- "_name_or_path": "Norod78/hebrew-gpt_neo-small",
3
- "activation_function": "gelu_new",
4
- "architectures": [
5
- "GPTNeoForCausalLM"
6
- ],
7
- "attention_dropout": 0,
8
- "attention_layers": [
9
- "global",
10
- "global",
11
- "global",
12
- "global",
13
- "global",
14
- "global",
15
- "global",
16
- "global",
17
- "global",
18
- "global",
19
- "global",
20
- "global"
21
- ],
22
- "attention_types": [
23
- [
24
- [
25
- "global"
26
- ],
27
- 12
28
- ]
29
- ],
30
- "bos_token_id": 50256,
31
- "embed_dropout": 0,
32
- "eos_token_id": 50256,
33
- "gradient_checkpointing": false,
34
- "hidden_size": 768,
35
- "initializer_range": 0.02,
36
- "intermediate_size": null,
37
- "layer_norm_epsilon": 1e-05,
38
- "max_position_embeddings": 2048,
39
- "model_type": "gpt_neo",
40
- "num_heads": 12,
41
- "num_layers": 12,
42
- "pad_token_id": 50256,
43
- "resid_dropout": 0,
44
- "summary_activation": null,
45
- "summary_first_dropout": 0.1,
46
- "summary_proj_to_labels": true,
47
- "summary_type": "cls_index",
48
- "summary_use_proj": true,
49
- "torch_dtype": "float32",
50
- "transformers_version": "4.21.0",
51
- "use_cache": true,
52
- "vocab_size": 50261,
53
- "window_size": 256
54
- }
 
1
+ {
2
+ "_name_or_path": "./FantasyChildrenScifi-hebrew-gpt_neo-small/model",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPTNeoForCausalLM"
6
+ ],
7
+ "attention_dropout": 0,
8
+ "attention_layers": [
9
+ "global",
10
+ "global",
11
+ "global",
12
+ "global",
13
+ "global",
14
+ "global",
15
+ "global",
16
+ "global",
17
+ "global",
18
+ "global",
19
+ "global",
20
+ "global"
21
+ ],
22
+ "attention_types": [
23
+ [
24
+ [
25
+ "global"
26
+ ],
27
+ 12
28
+ ]
29
+ ],
30
+ "bos_token_id": 50256,
31
+ "embed_dropout": 0,
32
+ "eos_token_id": 50256,
33
+ "gradient_checkpointing": false,
34
+ "hidden_size": 768,
35
+ "initializer_range": 0.02,
36
+ "intermediate_size": null,
37
+ "layer_norm_epsilon": 1e-05,
38
+ "max_position_embeddings": 2048,
39
+ "model_type": "gpt_neo",
40
+ "num_heads": 12,
41
+ "num_layers": 12,
42
+ "pad_token_id": 50256,
43
+ "resid_dropout": 0,
44
+ "summary_activation": null,
45
+ "summary_first_dropout": 0.1,
46
+ "summary_proj_to_labels": true,
47
+ "summary_type": "cls_index",
48
+ "summary_use_proj": true,
49
+ "torch_dtype": "float32",
50
+ "transformers_version": "4.21.0",
51
+ "use_cache": true,
52
+ "vocab_size": 50261,
53
+ "window_size": 256
54
+ }
model/special_tokens_map.json CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "bos_token": "<|startoftext|>",
3
- "eos_token": "<|endoftext|>",
4
- "pad_token": "<|pad|>",
5
- "unk_token": "<unk>"
6
- }
 
1
+ {
2
+ "bos_token": "<|startoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "pad_token": "<|pad|>",
5
+ "unk_token": "<unk>"
6
+ }
model/tokenizer_config.json CHANGED
@@ -1,22 +1,22 @@
1
- {
2
- "add_bos_token": false,
3
- "add_prefix_space": false,
4
- "bos_token": "<|startoftext|>",
5
- "do_lower_case": false,
6
- "eos_token": "<|endoftext|>",
7
- "errors": "replace",
8
- "full_tokenizer_file": null,
9
- "max_len": 1024,
10
- "name_or_path": "Norod78/hebrew-gpt_neo-small",
11
- "pad_token": "<|pad|>",
12
- "special_tokens_map_file": "special_tokens_map.json",
13
- "tokenizer_class": "GPT2Tokenizer",
14
- "unk_token": {
15
- "__type": "AddedToken",
16
- "content": "<|endoftext|>",
17
- "lstrip": false,
18
- "normalized": true,
19
- "rstrip": false,
20
- "single_word": false
21
- }
22
- }
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "bos_token": "<|startoftext|>",
5
+ "do_lower_case": false,
6
+ "eos_token": "<|endoftext|>",
7
+ "errors": "replace",
8
+ "full_tokenizer_file": null,
9
+ "max_len": 1024,
10
+ "name_or_path": "./FantasyChildrenScifi-hebrew-gpt_neo-small/model",
11
+ "pad_token": "<|pad|>",
12
+ "special_tokens_map_file": "special_tokens_map.json",
13
+ "tokenizer_class": "GPT2Tokenizer",
14
+ "unk_token": {
15
+ "__type": "AddedToken",
16
+ "content": "<|endoftext|>",
17
+ "lstrip": false,
18
+ "normalized": true,
19
+ "rstrip": false,
20
+ "single_word": false
21
+ }
22
+ }