sarahciston commited on
Commit
8cfe734
1 Parent(s): 1b99d9a

add to max tokens

Browse files
Files changed (1) hide show
  1. sketch.js +22 -31
sketch.js CHANGED
@@ -10,11 +10,10 @@ env.allowLocalModels = false;
10
  var PREPROMPT = `Please continue the story, and fill any [MASK] with your own words:`
11
  // let PREPROMPT = `Please complete the phrase and fill in any [MASK]: `
12
  var PROMPT_INPUT = `The [BLANK] has a job as a [MASK] but...` // a field for writing or changing a text value
13
- var pField // an html element for the prompt
14
- var outText // an html element for the results
15
- var blanksArray = []
16
- // a list for all the variable inputs, e.g. ["woman", "man", "non-binary person"]
17
-
18
 
19
  // RUN TEXT-GEN MODEL
20
 
@@ -25,7 +24,7 @@ async function textGenTask(pre, prompt, blanks){
25
  let promptArray = []
26
  promptArray.push(pre) // add preprompt to the list of prompts
27
 
28
- // fill in blanks from our sample prompt and make new prompts using our variable list 'blanksArray'
29
  blanks.forEach(b => {
30
  let p = prompt.replace('[BLANK]', b) // replace the string segment with an item from the blanksArray
31
  promptArray.push(p) // add the new prompt to the list we created
@@ -54,27 +53,20 @@ async function textGenTask(pre, prompt, blanks){
54
  // const pipe = await pipeline('text-generation', MODEL) //different task type, also for text generation
55
  const pipe = await pipeline('text2text-generation', MODEL)
56
 
57
- var hyperparameters = { max_new_tokens: 60, top_k: 90, repetition_penalty: 1.5 }
58
  // setting hyperparameters
59
- // max_new_tokens: 256, top_k: 50, temperature: 0.7, do_sample: true, no_repeat_ngram_size: 2,
60
- // , num_return_sequences: 2 (must be 1?)
61
-
62
- // let OUTPUT_LIST = [] // a blank array to store the results from the model
63
 
64
  // change model run to iterative for each prompt generated locally — will be more expensive??
65
- // promptArray.forEach(async i => {
66
 
67
  // RUN INPUT THROUGH MODEL,
68
- var out = await pipe(INPUT, hyperparameters)
69
-
70
- console.log(await out)
71
- console.log('text-gen task completed')
72
-
73
- // PARSE RESULTS as a list of outputs, two different ways depending on the model
74
 
75
- // OUTPUT_LIST.push(out[0].generated_text)
76
-
77
- // }) //this was a loop to wrap model run multiple times
 
78
 
79
  // parsing of output
80
  // await out.forEach(o => {
@@ -89,6 +81,7 @@ async function textGenTask(pre, prompt, blanks){
89
  // })
90
 
91
  let OUTPUT_LIST = out[0].generated_text //not a list anymore just one result
 
92
 
93
  console.log(OUTPUT_LIST)
94
  console.log('text-gen parsing complete')
@@ -147,11 +140,11 @@ new p5(function (p5){
147
  }
148
 
149
  function makeFields(){
150
- pField = p5.createInput(PROMPT_INPUT) // turns the string into an input; now access the text via PROMPT_INPUT.value()
151
- pField.size(700)
152
- pField.attribute('label', `Write a text prompt with one [MASK] that the model will fill in.`)
153
- p5.createP(pField.attribute('label'))
154
- pField.addClass("prompt")
155
 
156
  const fieldsDiv = p5.createDiv()
157
  fieldsDiv.id('fieldsDiv')
@@ -183,21 +176,19 @@ new p5(function (p5){
183
  // insert waiting dots into results space of interface
184
  outText.html('...', false)
185
 
186
- PROMPT_INPUT = pField.value() // grab update to the prompt if it's been changed
 
187
  console.log("latest prompt: ", PROMPT_INPUT)
188
 
189
- // let blanksValues = blanksArray.map(b => b.value)
190
  let blanksValues = []
191
  blanksArray.forEach(b => {
192
  blanksValues.push(b.value())
193
  })
194
  console.log(blanksValues)
195
-
196
- // blanksArray.forEach(b => console.log(b.value()))
197
 
198
  // call the function that runs the model for the task of your choice here
199
  // make sure to use the PROMPT_INPUT as a parameter, or also the PREPROMPT if valid for that task
200
-
201
  let outs = await textGenTask(PREPROMPT, PROMPT_INPUT, blanksValues)
202
  console.log(outs)
203
 
 
10
  var PREPROMPT = `Please continue the story, and fill any [MASK] with your own words:`
11
  // let PREPROMPT = `Please complete the phrase and fill in any [MASK]: `
12
  var PROMPT_INPUT = `The [BLANK] has a job as a [MASK] but...` // a field for writing or changing a text value
13
+ var promptField // an html element to hold the prompt
14
+ var outText // an html element to hold the results
15
+ var blanksArray = [] // an empty list to store all the variables we enter to modify the prompt
16
+ // e.g. ["woman", "man", "non-binary person"]
 
17
 
18
  // RUN TEXT-GEN MODEL
19
 
 
24
  let promptArray = []
25
  promptArray.push(pre) // add preprompt to the list of prompts
26
 
27
+ // Fill in blanks from our sample prompt and make new prompts using our variable list 'blanksArray'
28
  blanks.forEach(b => {
29
  let p = prompt.replace('[BLANK]', b) // replace the string segment with an item from the blanksArray
30
  promptArray.push(p) // add the new prompt to the list we created
 
53
  // const pipe = await pipeline('text-generation', MODEL) //different task type, also for text generation
54
  const pipe = await pipeline('text2text-generation', MODEL)
55
 
56
+ var hyperparameters = { max_new_tokens: 200, top_k: 90, repetition_penalty: 1.5 }
57
  // setting hyperparameters
58
+ // max_new_tokens: 256, top_k: 50, temperature: 0.7, do_sample: true, no_repeat_ngram_size: 2, num_return_sequences: 2 (must be 1?)
 
 
 
59
 
60
  // change model run to iterative for each prompt generated locally — will be more expensive??
61
+ // promptArray.forEach(async i => {} //this was a loop to wrap model run multiple times
62
 
63
  // RUN INPUT THROUGH MODEL,
64
+ var out = await pipe(INPUT, hyperparameters)
 
 
 
 
 
65
 
66
+ console.log(await out)
67
+ console.log('text-gen task completed')
68
+
69
+ // PARSE RESULTS as a list of outputs, two different ways depending on the model
70
 
71
  // parsing of output
72
  // await out.forEach(o => {
 
81
  // })
82
 
83
  let OUTPUT_LIST = out[0].generated_text //not a list anymore just one result
84
+ // OUTPUT_LIST.push(out[0].generated_text)
85
 
86
  console.log(OUTPUT_LIST)
87
  console.log('text-gen parsing complete')
 
140
  }
141
 
142
  function makeFields(){
143
+ promptField = p5.createInput(PROMPT_INPUT) // turns the string into an input; now access the text via PROMPT_INPUT.value()
144
+ promptField.size(700)
145
+ promptField.attribute('label', `Write a text prompt with one [MASK] that the model will fill in.`)
146
+ p5.createP(promptField.attribute('label'))
147
+ promptField.addClass("prompt")
148
 
149
  const fieldsDiv = p5.createDiv()
150
  fieldsDiv.id('fieldsDiv')
 
176
  // insert waiting dots into results space of interface
177
  outText.html('...', false)
178
 
179
+ // GRAB CURRENT FIELD INPUTS FROM PROMPT & BLANKS
180
+ PROMPT_INPUT = promptField.value() // grab update to the prompt if it's been changed
181
  console.log("latest prompt: ", PROMPT_INPUT)
182
 
 
183
  let blanksValues = []
184
  blanksArray.forEach(b => {
185
  blanksValues.push(b.value())
186
  })
187
  console.log(blanksValues)
188
+ // let blanksValues = blanksArray.map(b => b.value)
 
189
 
190
  // call the function that runs the model for the task of your choice here
191
  // make sure to use the PROMPT_INPUT as a parameter, or also the PREPROMPT if valid for that task
 
192
  let outs = await textGenTask(PREPROMPT, PROMPT_INPUT, blanksValues)
193
  console.log(outs)
194