Spaces:
Running
Running
last one worked! add new model for text-gen
Browse filesrework flow into single func for each because output parsing is diff per model
sketch.js
CHANGED
|
@@ -10,29 +10,56 @@ let PROMPT_INPUT = `Happy people are better than [MASK].` // a field for writing
|
|
| 10 |
let OUTPUT_LIST = [] // a blank array to store the results from the model
|
| 11 |
let pField
|
| 12 |
|
| 13 |
-
// RUN MODEL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
async function fillInTask(input){
|
| 15 |
console.log('fill-in task initiated')
|
| 16 |
|
| 17 |
-
const pipe = await pipeline('fill-mask'
|
|
|
|
| 18 |
|
| 19 |
var out = await pipe(input);
|
| 20 |
|
| 21 |
console.log(await out) // yields { score, sequence, token, token_str } for each result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
// console.log(o) // yields { score, sequence, token, token_str } for each result
|
| 25 |
-
// OUTPUT_LIST.push(o.sequence) // put only the full sequence in a list
|
| 26 |
-
// })
|
| 27 |
-
|
| 28 |
-
// console.log(await OUTPUT_LIST)
|
| 29 |
|
| 30 |
// displayResults(await OUTPUT_LIST)
|
| 31 |
|
| 32 |
console.log('fill-in task completed')
|
| 33 |
|
| 34 |
-
return await out
|
| 35 |
-
|
| 36 |
}
|
| 37 |
|
| 38 |
// PROCESS MODEL OUTPUT
|
|
@@ -97,9 +124,11 @@ new p5(function (p5){
|
|
| 97 |
PROMPT_INPUT = pField.value() // updates prompt if it's changed
|
| 98 |
console.log("latest prompt: ", PROMPT_INPUT)
|
| 99 |
|
| 100 |
-
let fillIn = await fillInTask(PROMPT_INPUT)
|
| 101 |
|
| 102 |
-
let outs = await getOutputs(fillIn)
|
|
|
|
|
|
|
| 103 |
|
| 104 |
console.log(outs)
|
| 105 |
|
|
@@ -109,20 +138,6 @@ new p5(function (p5){
|
|
| 109 |
await outText.html(outs, false)
|
| 110 |
}
|
| 111 |
|
| 112 |
-
// async function makeOutputDisplay(){
|
| 113 |
-
// console.log('button pressed')
|
| 114 |
-
// let outHead = p5.createElement('h4',"Results:")
|
| 115 |
-
|
| 116 |
-
// let out = await fillInTask() //just model no parsing
|
| 117 |
-
// // let out = await getOutputs(fillInTask()) // model and parsing
|
| 118 |
-
|
| 119 |
-
// out = str(await out)
|
| 120 |
-
// console.log(out)
|
| 121 |
-
|
| 122 |
-
// let outText = p5.createP('')
|
| 123 |
-
// await outText.html(out)
|
| 124 |
-
// }
|
| 125 |
-
|
| 126 |
});
|
| 127 |
|
| 128 |
|
|
|
|
| 10 |
let OUTPUT_LIST = [] // a blank array to store the results from the model
|
| 11 |
let pField
|
| 12 |
|
| 13 |
+
// RUN TEXT-GEN MODEL
|
| 14 |
+
|
| 15 |
+
async function textGenTask(input{
|
| 16 |
+
console.log('text-gen task initiated')
|
| 17 |
+
|
| 18 |
+
const pipe = await pipeline('text-generation')
|
| 19 |
+
|
| 20 |
+
var out = await pipe(input)
|
| 21 |
+
|
| 22 |
+
console.log(await out)
|
| 23 |
+
console.log('text-gen task completed')
|
| 24 |
+
|
| 25 |
+
// parsing of output
|
| 26 |
+
await out.forEach(o => {
|
| 27 |
+
console.log(o)
|
| 28 |
+
OUTPUT_LIST.push(o.generated_text)
|
| 29 |
+
})
|
| 30 |
+
|
| 31 |
+
console.log(OUTPUT_LIST)
|
| 32 |
+
console.log('text-gen parsing complete')
|
| 33 |
+
|
| 34 |
+
return await OUTPUT_LIST
|
| 35 |
+
// return await out
|
| 36 |
+
})
|
| 37 |
+
|
| 38 |
+
// RUN FILL-IN MODEL
|
| 39 |
async function fillInTask(input){
|
| 40 |
console.log('fill-in task initiated')
|
| 41 |
|
| 42 |
+
const pipe = await pipeline('fill-mask');
|
| 43 |
+
//, 'Xenova/bert-base-uncased'
|
| 44 |
|
| 45 |
var out = await pipe(input);
|
| 46 |
|
| 47 |
console.log(await out) // yields { score, sequence, token, token_str } for each result
|
| 48 |
+
|
| 49 |
+
// parsing of output
|
| 50 |
+
await out.forEach(o => {
|
| 51 |
+
console.log(o) // yields { score, sequence, token, token_str } for each result
|
| 52 |
+
OUTPUT_LIST.push(o.sequence) // put only the full sequence in a list
|
| 53 |
+
})
|
| 54 |
|
| 55 |
+
console.log(await OUTPUT_LIST)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
// displayResults(await OUTPUT_LIST)
|
| 58 |
|
| 59 |
console.log('fill-in task completed')
|
| 60 |
|
| 61 |
+
// return await out
|
| 62 |
+
return await OUTPUT_LIST
|
| 63 |
}
|
| 64 |
|
| 65 |
// PROCESS MODEL OUTPUT
|
|
|
|
| 124 |
PROMPT_INPUT = pField.value() // updates prompt if it's changed
|
| 125 |
console.log("latest prompt: ", PROMPT_INPUT)
|
| 126 |
|
| 127 |
+
// let fillIn = await fillInTask(PROMPT_INPUT)
|
| 128 |
|
| 129 |
+
// let outs = await getOutputs(fillIn)
|
| 130 |
+
|
| 131 |
+
let outs = await textGenTask(PROMPT_INPUT)
|
| 132 |
|
| 133 |
console.log(outs)
|
| 134 |
|
|
|
|
| 138 |
await outText.html(outs, false)
|
| 139 |
}
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
});
|
| 142 |
|
| 143 |
|