Sarah Ciston
commited on
Commit
·
456b82c
1
Parent(s):
f9569e7
try fillMask version test
Browse files
README.md
CHANGED
@@ -11,9 +11,10 @@ hf_oauth_scopes:
|
|
11 |
- write-repos
|
12 |
- inference-api
|
13 |
models:
|
|
|
14 |
# - gpt-3.5-turbo
|
15 |
-
- bigscience/bloom-560m
|
16 |
-
- Xenova/distilgpt2
|
17 |
# - HuggingFaceH4/zephyr-7b-gemma-v0.1
|
18 |
# - HuggingFaceH4/zephyr-7b-beta
|
19 |
# - openai-community/gpt2
|
|
|
11 |
- write-repos
|
12 |
- inference-api
|
13 |
models:
|
14 |
+
- bert-base-uncased
|
15 |
# - gpt-3.5-turbo
|
16 |
+
# - bigscience/bloom-560m
|
17 |
+
# - Xenova/distilgpt2
|
18 |
# - HuggingFaceH4/zephyr-7b-gemma-v0.1
|
19 |
# - HuggingFaceH4/zephyr-7b-beta
|
20 |
# - openai-community/gpt2
|
sketch.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
// connect to API via module
|
2 |
|
3 |
// import { AutoTokenizer, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
|
4 |
-
|
5 |
|
6 |
/// AUTHORIZATION
|
7 |
-
import { textGeneration } from 'https://esm.sh/@huggingface/inference';
|
8 |
import { oauthLoginUrl, oauthHandleRedirectIfPresent } from 'https://esm.sh/@huggingface/hub';
|
9 |
|
10 |
const oauthResult = await oauthHandleRedirectIfPresent();
|
@@ -34,6 +34,7 @@ console.log(HF_TOKEN)
|
|
34 |
// establish global variables to reference later
|
35 |
var promptInput
|
36 |
var blanksArray = []
|
|
|
37 |
|
38 |
// pick a model (see list of models)
|
39 |
// INFERENCE MODELS
|
@@ -140,6 +141,29 @@ new p5(function (p5) {
|
|
140 |
}
|
141 |
}
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
async function getInputs(){
|
144 |
// Map the list of blanks text values to a new list
|
145 |
let BLANKSVALUES = blanksArray.map(i => i.value())
|
@@ -150,15 +174,25 @@ new p5(function (p5) {
|
|
150 |
|
151 |
// BLANKS = inputValues // get ready to feed array list into model
|
152 |
|
153 |
-
let
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
// we pass PROMPT and PREPROMPT to the model function, don't need to pass BLANKSVALUES bc it's passed into the PREPROMPT already here
|
156 |
|
157 |
// Please return an array of sentences based on the sample sentence to follow. In each sentence,
|
158 |
|
159 |
-
let modelResult = await runModel(PREPROMPT, PROMPT)
|
|
|
160 |
|
161 |
-
await displayModel(
|
162 |
}
|
163 |
|
164 |
async function displayModel(m){
|
@@ -171,61 +205,61 @@ new p5(function (p5) {
|
|
171 |
///// MODEL STUFF
|
172 |
|
173 |
|
174 |
-
async function runModel(PREPROMPT, PROMPT){
|
175 |
-
|
176 |
|
177 |
-
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
// let out = await inference.textGeneration(INPUT, {
|
195 |
-
// model: MODELNAME,
|
196 |
-
// max_new_tokens: 128
|
197 |
-
// })
|
198 |
-
|
199 |
-
// let out = await inference.textGeneration(INPUT, 'bigscience/bloom-560m')
|
200 |
-
|
201 |
-
// text-generation-inference
|
202 |
-
// Uncaught (in promise) Error: HfApiJson(Deserialize(Error("unknown variant `transformers.js`, expected one of `text-generation-inference`, `transformers`, `allennlp`, `flair`, `espnet`, `asteroid`, `speechbrain`, `timm`, `sentence-transformers`, `spacy`, `sklearn`, `stanza`, `adapter-transformers`, `fasttext`, `fairseq`, `pyannote-audio`, `doctr`, `nemo`, `fastai`, `k2`, `diffusers`, `paddlenlp`, `mindspore`, `open_clip`, `span-marker`, `bertopic`, `peft`, `setfit`", line: 1, column: 397)))
|
203 |
-
|
204 |
-
// let out = await inference.textGeneration({
|
205 |
-
// accessToken: HF_TOKEN,
|
206 |
-
// model: MODELNAME,
|
207 |
-
// messages: [{
|
208 |
-
// role: "system",
|
209 |
-
// content: PREPROMPT
|
210 |
-
// },{
|
211 |
-
// role: "user",
|
212 |
-
// content: PROMPT
|
213 |
-
// }],
|
214 |
-
// max_new_tokens: 128
|
215 |
-
// });
|
216 |
|
217 |
-
|
|
|
|
|
|
|
218 |
|
219 |
-
|
220 |
|
221 |
-
|
|
|
222 |
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
-
|
228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
|
230 |
|
231 |
//inference.fill_mask({
|
@@ -309,4 +343,23 @@ async function runModel(PREPROMPT, PROMPT){
|
|
309 |
|
310 |
// return modelResult
|
311 |
|
312 |
-
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
// connect to API via module
|
2 |
|
3 |
// import { AutoTokenizer, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
|
4 |
+
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
|
5 |
|
6 |
/// AUTHORIZATION
|
7 |
+
// import { textGeneration } from 'https://esm.sh/@huggingface/inference';
|
8 |
import { oauthLoginUrl, oauthHandleRedirectIfPresent } from 'https://esm.sh/@huggingface/hub';
|
9 |
|
10 |
const oauthResult = await oauthHandleRedirectIfPresent();
|
|
|
34 |
// establish global variables to reference later
|
35 |
var promptInput
|
36 |
var blanksArray = []
|
37 |
+
var resultsArray = []
|
38 |
|
39 |
// pick a model (see list of models)
|
40 |
// INFERENCE MODELS
|
|
|
141 |
}
|
142 |
}
|
143 |
|
144 |
+
// async function getInputs(){
|
145 |
+
// // Map the list of blanks text values to a new list
|
146 |
+
// let BLANKSVALUES = blanksArray.map(i => i.value())
|
147 |
+
// console.log(BLANKSVALUES)
|
148 |
+
|
149 |
+
// // Do model stuff in this function instead of in general
|
150 |
+
// let PROMPT = promptInput.value() // updated check of the prompt field
|
151 |
+
|
152 |
+
// // BLANKS = inputValues // get ready to feed array list into model
|
153 |
+
|
154 |
+
// let PREPROMPT = `In the sentence I provide, please fill in the [BLANK] with each word in the array ${BLANKSVALUES}, replace any [MASK] with a word of your choice. Here is the SAMPLE SENTENCE: `
|
155 |
+
|
156 |
+
// // we pass PROMPT and PREPROMPT to the model function, don't need to pass BLANKSVALUES bc it's passed into the PREPROMPT already here
|
157 |
+
|
158 |
+
// // Please return an array of sentences based on the sample sentence to follow. In each sentence,
|
159 |
+
|
160 |
+
// // let modelResult = await runModel(PREPROMPT, PROMPT)
|
161 |
+
// let modelResult = await runModel(BLANKSVALUES, PROMPT)
|
162 |
+
|
163 |
+
// await displayModel(modelResult)
|
164 |
+
// }
|
165 |
+
|
166 |
+
// creating multiple prompt inputs rather than instructing model to do so
|
167 |
async function getInputs(){
|
168 |
// Map the list of blanks text values to a new list
|
169 |
let BLANKSVALUES = blanksArray.map(i => i.value())
|
|
|
174 |
|
175 |
// BLANKS = inputValues // get ready to feed array list into model
|
176 |
|
177 |
+
let PROMPTS = []
|
178 |
+
for (let b in BLANKSVALUES){
|
179 |
+
console.log(b)
|
180 |
+
p = PROMPT.replace('[BLANK]', `${b}`)
|
181 |
+
console.log(p)
|
182 |
+
PROMPTS.add(p)
|
183 |
+
}
|
184 |
+
console.log(PROMPTS)
|
185 |
+
|
186 |
+
// let PREPROMPT = `In the sentence I provide, please fill in the [BLANK] with each word in the array ${BLANKSVALUES}, replace any [MASK] with a word of your choice. Here is the SAMPLE SENTENCE: `
|
187 |
|
188 |
// we pass PROMPT and PREPROMPT to the model function, don't need to pass BLANKSVALUES bc it's passed into the PREPROMPT already here
|
189 |
|
190 |
// Please return an array of sentences based on the sample sentence to follow. In each sentence,
|
191 |
|
192 |
+
// let modelResult = await runModel(PREPROMPT, PROMPT)
|
193 |
+
let modelResult = await runModel(PROMPTS)
|
194 |
|
195 |
+
await displayModel(resultsArray[0], resultsArray[1])
|
196 |
}
|
197 |
|
198 |
async function displayModel(m){
|
|
|
205 |
///// MODEL STUFF
|
206 |
|
207 |
|
208 |
+
// async function runModel(PREPROMPT, PROMPT){
|
209 |
+
// // inference API version
|
210 |
|
211 |
+
// let INPUT = PREPROMPT + PROMPT
|
212 |
|
213 |
+
// // let MODELNAME = "HuggingFaceH4/zephyr-7b-beta"
|
214 |
+
// // let MODELNAME = "openai-community/gpt2"
|
215 |
+
// // let MODELNAME = 'mistral_inference'
|
216 |
+
// // let MODELNAME = 'Xenova/distilgpt2'
|
217 |
+
// let MODELNAME = 'bigscience/bloom-560m'
|
218 |
|
219 |
+
// let out = await textGeneration({
|
220 |
+
// accessToken: HF_TOKEN,
|
221 |
+
// model: MODELNAME,
|
222 |
+
// inputs: INPUT,
|
223 |
+
// parameters: {
|
224 |
+
// max_new_tokens: 128
|
225 |
+
// }
|
226 |
+
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
+
// // let out = await inference.textGeneration(INPUT, {
|
229 |
+
// // model: MODELNAME,
|
230 |
+
// // max_new_tokens: 128
|
231 |
+
// // })
|
232 |
|
233 |
+
// // let out = await inference.textGeneration(INPUT, 'bigscience/bloom-560m')
|
234 |
|
235 |
+
// // text-generation-inference
|
236 |
+
// // Uncaught (in promise) Error: HfApiJson(Deserialize(Error("unknown variant `transformers.js`, expected one of `text-generation-inference`, `transformers`, `allennlp`, `flair`, `espnet`, `asteroid`, `speechbrain`, `timm`, `sentence-transformers`, `spacy`, `sklearn`, `stanza`, `adapter-transformers`, `fasttext`, `fairseq`, `pyannote-audio`, `doctr`, `nemo`, `fastai`, `k2`, `diffusers`, `paddlenlp`, `mindspore`, `open_clip`, `span-marker`, `bertopic`, `peft`, `setfit`", line: 1, column: 397)))
|
237 |
|
238 |
+
// // let out = await inference.textGeneration({
|
239 |
+
// // accessToken: HF_TOKEN,
|
240 |
+
// // model: MODELNAME,
|
241 |
+
// // messages: [{
|
242 |
+
// // role: "system",
|
243 |
+
// // content: PREPROMPT
|
244 |
+
// // },{
|
245 |
+
// // role: "user",
|
246 |
+
// // content: PROMPT
|
247 |
+
// // }],
|
248 |
+
// // max_new_tokens: 128
|
249 |
+
// // });
|
250 |
|
251 |
+
// console.log(out)
|
252 |
+
|
253 |
+
// console.log(out.token.text, out.generated_text)
|
254 |
+
|
255 |
+
// // modelResult = await out.messages[0].content
|
256 |
+
|
257 |
+
// // var modelResult = await out.choices[0].message.content
|
258 |
+
// var modelResult = await out[0].generated_text
|
259 |
+
// console.log(modelResult);
|
260 |
+
|
261 |
+
// return modelResult
|
262 |
+
// }
|
263 |
|
264 |
|
265 |
//inference.fill_mask({
|
|
|
343 |
|
344 |
// return modelResult
|
345 |
|
346 |
+
// }
|
347 |
+
|
348 |
+
|
349 |
+
async function runModel(PROMPTS){
|
350 |
+
|
351 |
+
let MODELNAME = "bert-base-uncased"
|
352 |
+
|
353 |
+
let unmasker = await pipeline('fill-mask', 'bert-base-uncased')
|
354 |
+
|
355 |
+
for (let p in PROMPTS){
|
356 |
+
var res = unmasker(p)
|
357 |
+
console.log(res)
|
358 |
+
|
359 |
+
var modelResult = res[0].token_str
|
360 |
+
console.log(modelResult)
|
361 |
+
|
362 |
+
resultsArray.add(modelResult)
|
363 |
+
}
|
364 |
+
return resultsArray
|
365 |
+
}
|