Spaces:
Build error
Build error
File size: 1,610 Bytes
8c0b646 13f7861 8c0b646 2bf7c7e 13f7861 2bf7c7e 8c0b646 b5b3297 8c0b646 13f7861 8c0b646 b5b3297 38bdfc6 8c0b646 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import gradio as gr
import numpy as np
from transformers import pipeline, Pipeline
unmasker = pipeline("fill-mask", model="anferico/bert-for-patents")
example = 'A crustless sandwich made from two slices of baked bread'
# class TempScalePipe(Pipeline):
# def _forward(self, model_inputs):
# outputs = self.model(**model_inputs)
# return outputs
#
# def postprocess(self, model_outputs, temp=1e3):
# out = model_outputs["logits"] / temp
# idx = np.random.randint(-3, 0)
# best_class = out.softmax(idx)
# return best_class
#
def unmask(text):
text = add_mask(text)
res = unmasker(text)
out = {item["token_str"]: item["score"] for item in res}
return out
textbox = gr.Textbox(label="Type language here", lines=5)
import gradio as gr
from transformers import pipeline, Pipeline
# unmasker = pipeline("fill-mask", model="anferico/bert-for-patents")
#
#
# def add_mask(text, size=1):
# split_text = text.split()
# idx = np.random.randint(len(split_text), size=size)
# for i in idx:
# split_text[i] = '[MASK]'
# return ' '.join(split_text)
#
#
# def unmask(text):
# text = add_mask(text)
# res = unmasker(text)
# out = {item["token_str"]: item["score"] for item in res}
# return out
#
#
# textbox = gr.Textbox(label="Type language here", lines=5)
#
# demo = gr.Interface(
# fn=unmask,
# inputs=textbox,
# outputs="label",
# examples=[
#
# ],
# )
demo.launch()
demo = gr.Interface(
fn=unmask,
inputs=textbox,
outputs="label",
examples=[
],
)
demo.launch() |