Spaces:
Running
Running
new chaining of model processing
Browse files
index.js
CHANGED
|
@@ -6,19 +6,17 @@ import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers
|
|
| 6 |
env.allowLocalModels = false;
|
| 7 |
|
| 8 |
// GLOBAL VARIABLES
|
| 9 |
-
let PROMPT_INPUT = `The
|
| 10 |
let OUTPUT_LIST = [] // a blank array to store the results from the model
|
| 11 |
|
| 12 |
|
| 13 |
// RUN MODEL
|
| 14 |
-
async function fillInTask(){
|
| 15 |
console.log('fill-in task initiated')
|
| 16 |
|
| 17 |
-
// PROMPT_INPUT = pField.value()
|
| 18 |
-
|
| 19 |
const pipe = await pipeline('fill-mask', 'Xenova/bert-base-uncased');
|
| 20 |
|
| 21 |
-
var out = await pipe(
|
| 22 |
|
| 23 |
console.log(await out) // yields { score, sequence, token, token_str } for each result
|
| 24 |
|
|
@@ -39,21 +37,25 @@ async function fillInTask(){
|
|
| 39 |
|
| 40 |
// PROCESS MODEL OUTPUT
|
| 41 |
// a generic function to pass in different model task functions
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
// await getOutputs(fillInTask()) // getOutputs will later connect to the interface to display results
|
| 55 |
|
| 56 |
-
await fillInTask()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
//// p5.js Instance
|
| 59 |
|
|
|
|
| 6 |
env.allowLocalModels = false;
|
| 7 |
|
| 8 |
// GLOBAL VARIABLES
|
| 9 |
+
let PROMPT_INPUT = `The [MASK] went to Paris and the [MASK] went to Palestine.` // a field for writing or changing a text value
|
| 10 |
let OUTPUT_LIST = [] // a blank array to store the results from the model
|
| 11 |
|
| 12 |
|
| 13 |
// RUN MODEL
|
| 14 |
+
async function fillInTask(input){
|
| 15 |
console.log('fill-in task initiated')
|
| 16 |
|
|
|
|
|
|
|
| 17 |
const pipe = await pipeline('fill-mask', 'Xenova/bert-base-uncased');
|
| 18 |
|
| 19 |
+
var out = await pipe(input);
|
| 20 |
|
| 21 |
console.log(await out) // yields { score, sequence, token, token_str } for each result
|
| 22 |
|
|
|
|
| 37 |
|
| 38 |
// PROCESS MODEL OUTPUT
|
| 39 |
// a generic function to pass in different model task functions
|
| 40 |
+
async function getOutputs(task){
|
| 41 |
+
let output = await task
|
| 42 |
|
| 43 |
+
await output.forEach(o => {
|
| 44 |
+
OUTPUT_LIST.push(o.sequence) // put only the full sequence in a list
|
| 45 |
+
})
|
| 46 |
|
| 47 |
+
console.log(OUTPUT_LIST)
|
| 48 |
|
| 49 |
+
return await OUTPUT_LIST
|
| 50 |
+
}
|
| 51 |
|
| 52 |
// await getOutputs(fillInTask()) // getOutputs will later connect to the interface to display results
|
| 53 |
|
| 54 |
+
let fillIn = await fillInTask(PROMPT_INPUT)
|
| 55 |
+
|
| 56 |
+
let outs = await getOutputs(fillIn)
|
| 57 |
+
|
| 58 |
+
console.log(outs)
|
| 59 |
|
| 60 |
//// p5.js Instance
|
| 61 |
|