alperugurcan commited on
Commit
413c8a1
·
verified ·
1 Parent(s): ee00cfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -23
app.py CHANGED
@@ -5,10 +5,10 @@ from transformers import DistilBertTokenizer, DistilBertModel
5
  class SimilarityPredictor:
6
  def __init__(self):
7
  self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
8
- self.model = DistilBertModel.from_pretrained('patent_similarity_model').to(self.device)
9
- self.tokenizer = DistilBertTokenizer.from_pretrained('patent_similarity_model')
 
10
  self.head = torch.nn.Sequential(torch.nn.Linear(768, 1), torch.nn.Sigmoid()).to(self.device)
11
- self.head.load_state_dict(torch.load('patent_similarity_model/head.pt', map_location=self.device))
12
 
13
  def predict(self, anchor, target):
14
  self.model.eval()
@@ -27,25 +27,18 @@ class SimilarityPredictor:
27
 
28
  predictor = SimilarityPredictor()
29
 
30
- # Örnek seçenekler
31
  example_pairs = [
32
  ["mobile phone", "cellphone"],
33
  ["artificial intelligence", "machine learning"],
34
  ["electric vehicle", "battery powered car"],
35
  ["wireless communication", "radio transmission"],
36
- ["solar panel", "photovoltaic cell"],
37
- ["computer processor", "CPU"],
38
- ["digital storage", "memory device"],
39
- ["touch screen", "interactive display"],
40
- ["biometric authentication", "fingerprint recognition"],
41
- ["cloud computing", "remote server processing"]
42
  ]
43
 
44
  def predict_similarity(anchor, target):
45
  score = predictor.predict(anchor, target)
46
  return round(score, 3)
47
 
48
- # Create Gradio interface with examples
49
  iface = gr.Interface(
50
  fn=predict_similarity,
51
  inputs=[
@@ -54,19 +47,9 @@ iface = gr.Interface(
54
  ],
55
  outputs=gr.Number(label="Similarity Score (0-1)"),
56
  title="Patent Phrase Similarity Checker",
57
- description="""Compare the similarity between two patent phrases.
58
-
59
- Score guide:
60
- - 1.0: Very close match (exact or near-exact)
61
- - 0.75: Close synonyms
62
- - 0.5: Related terms
63
- - 0.25: Somewhat related
64
- - 0.0: Unrelated
65
-
66
- Try the examples below or enter your own phrases!""",
67
  examples=example_pairs,
68
- theme="huggingface",
69
- css="footer {display: none !important;}"
70
  )
71
 
72
  iface.launch()
 
5
  class SimilarityPredictor:
6
  def __init__(self):
7
  self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
8
+ # Use the base model instead of custom model
9
+ self.model = DistilBertModel.from_pretrained('distilbert-base-uncased').to(self.device)
10
+ self.tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
11
  self.head = torch.nn.Sequential(torch.nn.Linear(768, 1), torch.nn.Sigmoid()).to(self.device)
 
12
 
13
  def predict(self, anchor, target):
14
  self.model.eval()
 
27
 
28
  predictor = SimilarityPredictor()
29
 
 
30
  example_pairs = [
31
  ["mobile phone", "cellphone"],
32
  ["artificial intelligence", "machine learning"],
33
  ["electric vehicle", "battery powered car"],
34
  ["wireless communication", "radio transmission"],
35
+ ["solar panel", "photovoltaic cell"]
 
 
 
 
 
36
  ]
37
 
38
  def predict_similarity(anchor, target):
39
  score = predictor.predict(anchor, target)
40
  return round(score, 3)
41
 
 
42
  iface = gr.Interface(
43
  fn=predict_similarity,
44
  inputs=[
 
47
  ],
48
  outputs=gr.Number(label="Similarity Score (0-1)"),
49
  title="Patent Phrase Similarity Checker",
50
+ description="Compare the similarity between two patent phrases (0: Different, 1: Identical)",
 
 
 
 
 
 
 
 
 
51
  examples=example_pairs,
52
+ theme="huggingface"
 
53
  )
54
 
55
  iface.launch()