nemanjaPetrovic
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
license:
|
3 |
language:
|
4 |
- sr
|
5 |
library_name: sentence-transformers
|
@@ -8,4 +8,80 @@ tags:
|
|
8 |
- Legal
|
9 |
- SBERT
|
10 |
- Jerteh
|
11 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
license: mit
|
3 |
language:
|
4 |
- sr
|
5 |
library_name: sentence-transformers
|
|
|
8 |
- Legal
|
9 |
- SBERT
|
10 |
- Jerteh
|
11 |
+
---
|
12 |
+
|
13 |
+
|
14 |
+
## Semantic Search of Legal Data Using SBERT
|
15 |
+
|
16 |
+
This repository contains a proof-of-concept model for semantic search of legal data, based on Sentence-BERT (SBERT) and fine-tuned using triplets. The model is designed to provide efficient and accurate semantic search capabilities for legal documents.
|
17 |
+
|
18 |
+
### Model Overview
|
19 |
+
|
20 |
+
- **Base Model**: Jerteh-125
|
21 |
+
- **Fine-tuning Technique**: Triplet loss
|
22 |
+
- **Purpose**: To enable semantic search within legal data
|
23 |
+
|
24 |
+
### Installation
|
25 |
+
|
26 |
+
To use the model, you need to have Python 3.6 or higher installed. Additionally, install the necessary dependencies:
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
`pip install transformers
|
31 |
+
pip install sentence-transformers`
|
32 |
+
|
33 |
+
### Usage
|
34 |
+
|
35 |
+
Here's how you can use the model for semantic search:
|
36 |
+
|
37 |
+
1. **Load the Model**
|
38 |
+
|
39 |
+
`from sentence_transformers import SentenceTransformer
|
40 |
+
model = SentenceTransformer('nemanjaPetrovic/legal-jerteh-125-sbert')`
|
41 |
+
|
42 |
+
2. **Encode Sentences**
|
43 |
+
|
44 |
+
`sentences = ["Sankcije se propisuju u granicama zakonom utvrđenog minimuma i maksimuma.", "Vrste krivičnih sankcija određuju se samo krivičnim zakonom."]`
|
45 |
+
|
46 |
+
`sentence_embeddings = model.encode(sentences)`
|
47 |
+
|
48 |
+
3. **Perform Semantic Search**
|
49 |
+
|
50 |
+
To perform a semantic search, you need to encode both your query and the documents you want to search through. You can then use cosine similarity to find the most relevant documents. **You should use vector database for this**, but for quick test, you can try code bellow
|
51 |
+
|
52 |
+
|
53 |
+
`from sklearn.metrics.pairwise import cosine_similarity
|
54 |
+
import numpy as np`
|
55 |
+
|
56 |
+
|
57 |
+
`query = "Objasni mi pojam sankcija."`
|
58 |
+
|
59 |
+
|
60 |
+
`query_embedding = model.encode([query])`
|
61 |
+
|
62 |
+
|
63 |
+
`cosine_similarities = cosine_similarity(query_embedding, sentence_embeddings)`
|
64 |
+
|
65 |
+
|
66 |
+
`most_similar_idx = np.argmax(cosine_similarities)`
|
67 |
+
`most_similar_document = sentences[most_similar_idx]`
|
68 |
+
|
69 |
+
`print(f"The most similar document to the query is: {most_similar_document}")`
|
70 |
+
|
71 |
+
### Fine-tuning Details
|
72 |
+
|
73 |
+
The model was fine-tuned using triplet loss, a common technique for training embedding models to understand semantic similarity. The fine-tuning dataset consisted of triplets (anchor, positive, negative) to teach the model to distinguish between similar and dissimilar legal documents.
|
74 |
+
|
75 |
+
### License
|
76 |
+
|
77 |
+
This project is licensed under the MIT License - see the [LICENSE](https://en.wikipedia.org/wiki/MIT_License) file for details.
|
78 |
+
|
79 |
+
### Acknowledgments
|
80 |
+
|
81 |
+
I would like to acknowledge the author of Jerteh-125 model Mihailo Skoric and the creators of Sentence-BERT for their foundational work, which made this project possible.
|
82 |
+
|
83 |
+
### Contact
|
84 |
+
|
85 |
+
For any questions or issues, please contact [email protected].
|
86 |
+
|
87 |
+
|