File size: 481 Bytes
c43d538
 
0ce0c70
c43d538
 
 
 
 
fdbab8e
c43d538
0ce0c70
 
 
 
 
c43d538
62fb656
c43d538
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
from transformers import pipeline
import random

top_k = 10
masker = pipeline("fill-mask", model="distilroberta-base")

def get_mask(txt):
    txt = txt.replace("...", masker.tokenizer.mask_token, count=1)
    result = masker(txt, top_k=top_k)
    random.shuffle(result)
    result_seq = []
    for r in result:
        result_seq.append(r['sequence'])
    return result_seq

inf = gr.Interface(fn=get_mask, inputs="text", outputs=["text"] * top_k)
inf.launch()