Spaces:
Sleeping
Sleeping
File size: 1,176 Bytes
3bf3346 33e4eda 3bf3346 33e4eda 3bf3346 063bf3b 33e4eda 063bf3b 33e4eda 063bf3b 3bf3346 33e4eda 3bf3346 |
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 |
import gradio as gr
from sentence_transformers import CrossEncoder
# Load a Semantic Textual Similarity CrossEncoder
model = CrossEncoder("cross-encoder/stsb-roberta-large")
def predict_similarity(s1, s2):
score = model.predict([(s1, s2)])[0] # already continuous
return round(float(score), 4)
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("## π Semantic Textual Similarity (CrossEncoder)")
gr.Markdown("Score ranges 0 (unrelated) β 1 (identical meaning).")
with gr.Row():
s1 = gr.Textbox(label="Sentence 1", placeholder="Type first sentence...")
s2 = gr.Textbox(label="Sentence 2", placeholder="Type second sentence...")
btn = gr.Button("Compute Similarity π")
out = gr.Number(label="Similarity Score (0β1)")
btn.click(fn=predict_similarity, inputs=[s1, s2], outputs=out)
gr.Examples(
examples=[
["I am a boy", "I am a girl"],
["I am happy today", "I am feeling a bit curious and joyful today"],
["I am going", "I am moving from you"],
["The sun is hot", "Ice cream is cold"],
],
inputs=[s1, s2],
)
demo.launch()
|