Omartificial-Intelligence-Space
commited on
Commit
•
c8be4d8
1
Parent(s):
a11557a
update app.py
Browse files
app.py
CHANGED
@@ -8,13 +8,19 @@ model = SentenceTransformer("Omartificial-Intelligence-Space/Arabic-Nli-Matryosh
|
|
8 |
# Define the labels for NLI
|
9 |
labels = ["contradiction", "entailment", "neutral"]
|
10 |
|
|
|
|
|
|
|
11 |
# Function to compute similarity and classify relationship
|
12 |
def predict(sentence1, sentence2):
|
13 |
sentences = [sentence1, sentence2]
|
14 |
embeddings = model.encode(sentences)
|
15 |
|
|
|
|
|
|
|
16 |
# Compute cosine similarity between the two sentences
|
17 |
-
similarity_score = util.
|
18 |
|
19 |
# Placeholder logic for NLI (needs to be replaced with actual model inference)
|
20 |
# This is just an example; in reality, you need a classifier trained for NLI
|
@@ -45,10 +51,10 @@ examples = [
|
|
45 |
gr.Interface(
|
46 |
fn=predict,
|
47 |
title="Arabic Sentence Similarity and NLI Classification",
|
48 |
-
description="Compute the semantic similarity and classify the relationship between two Arabic sentences using
|
49 |
inputs=inputs,
|
50 |
examples=examples,
|
51 |
outputs=outputs,
|
52 |
cache_examples=False,
|
53 |
-
article="Author:
|
54 |
).launch(debug=True, share=True)
|
|
|
8 |
# Define the labels for NLI
|
9 |
labels = ["contradiction", "entailment", "neutral"]
|
10 |
|
11 |
+
# Define the Matryoshka dimension
|
12 |
+
matryoshka_dim = 64
|
13 |
+
|
14 |
# Function to compute similarity and classify relationship
|
15 |
def predict(sentence1, sentence2):
|
16 |
sentences = [sentence1, sentence2]
|
17 |
embeddings = model.encode(sentences)
|
18 |
|
19 |
+
# Shrink the embedding dimensions
|
20 |
+
embeddings = embeddings[..., :matryoshka_dim]
|
21 |
+
|
22 |
# Compute cosine similarity between the two sentences
|
23 |
+
similarity_score = util.cos_sim(embeddings[0], embeddings[1])
|
24 |
|
25 |
# Placeholder logic for NLI (needs to be replaced with actual model inference)
|
26 |
# This is just an example; in reality, you need a classifier trained for NLI
|
|
|
51 |
gr.Interface(
|
52 |
fn=predict,
|
53 |
title="Arabic Sentence Similarity and NLI Classification",
|
54 |
+
description="Compute the semantic similarity and classify the relationship between two Arabic sentences using a SentenceTransformer model.",
|
55 |
inputs=inputs,
|
56 |
examples=examples,
|
57 |
outputs=outputs,
|
58 |
cache_examples=False,
|
59 |
+
article="Author: Your Name. Model from Hugging Face Hub: Omartificial-Intelligence-Space/Arabic-Nli-Matryoshka",
|
60 |
).launch(debug=True, share=True)
|