pulkitmehtawork
commited on
Commit
·
f165449
1
Parent(s):
a8e4867
Fill mask modern bert
Browse files- app.py +28 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# Initialize the model pipeline
|
| 7 |
+
pipe = pipeline(
|
| 8 |
+
"fill-mask",
|
| 9 |
+
model="answerdotai/ModernBERT-base",
|
| 10 |
+
torch_dtype=torch.bfloat16,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# Function to run the model
|
| 14 |
+
def fill_mask(input_text):
|
| 15 |
+
return pipe(input_text)
|
| 16 |
+
|
| 17 |
+
# Set up the Gradio interface
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=fill_mask,
|
| 20 |
+
inputs="text",
|
| 21 |
+
outputs="json",
|
| 22 |
+
title="Mask Filling with ModernBERT",
|
| 23 |
+
description="Enter a sentence with a [MASK] token, and the model will predict the missing word."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Launch the interface
|
| 27 |
+
iface.launch()
|
| 28 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers @ git+https://github.com/huggingface/transformers.git
|
| 3 |
+
gradio
|
| 4 |
+
|