antoinelouis
commited on
Commit
•
66e75c5
1
Parent(s):
44c5810
Upload folder using huggingface_hub
Browse files- 1_Pooling/config.json +9 -0
- README.md +110 -0
- config.json +28 -0
- config_sentence_transformers.json +7 -0
- dev_scores.csv +2 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- sentencepiece.bpe.model +3 -0
- special_tokens_map.json +19 -0
- tokenizer.json +0 -0
- tokenizer_config.json +23 -0
1_Pooling/config.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 768,
|
3 |
+
"pooling_mode_cls_token": false,
|
4 |
+
"pooling_mode_mean_tokens": true,
|
5 |
+
"pooling_mode_max_tokens": false,
|
6 |
+
"pooling_mode_mean_sqrt_len_tokens": false,
|
7 |
+
"pooling_mode_weightedmean_tokens": false,
|
8 |
+
"pooling_mode_lasttoken": false
|
9 |
+
}
|
README.md
CHANGED
@@ -1,3 +1,113 @@
|
|
1 |
---
|
|
|
|
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
pipeline_tag: sentence-similarity
|
3 |
+
language: fr
|
4 |
license: apache-2.0
|
5 |
+
datasets:
|
6 |
+
- maastrichtlawtech/lleqa
|
7 |
+
metrics:
|
8 |
+
- recall
|
9 |
+
tags:
|
10 |
+
- feature-extraction
|
11 |
+
- sentence-similarity
|
12 |
+
library_name: sentence-transformers
|
13 |
---
|
14 |
+
|
15 |
+
# camembert-base-lleqa
|
16 |
+
|
17 |
+
This is a [sentence-transformers](https://www.SBERT.net) model: it maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search. The model was trained on the [LLeQA](https://huggingface.co/datasets/maastrichtlawtech/lleqa) dataset for legal information retrieval in **French**.
|
18 |
+
|
19 |
+
## Usage
|
20 |
+
***
|
21 |
+
|
22 |
+
#### Sentence-Transformers
|
23 |
+
|
24 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
25 |
+
|
26 |
+
```
|
27 |
+
pip install -U sentence-transformers
|
28 |
+
```
|
29 |
+
|
30 |
+
Then you can use the model like this:
|
31 |
+
|
32 |
+
```python
|
33 |
+
from sentence_transformers import SentenceTransformer
|
34 |
+
sentences = ["This is an example sentence", "Each sentence is converted"]
|
35 |
+
|
36 |
+
model = SentenceTransformer('maastrichtlawtech/camembert-base-lleqa')
|
37 |
+
embeddings = model.encode(sentences)
|
38 |
+
print(embeddings)
|
39 |
+
```
|
40 |
+
|
41 |
+
#### 🤗 Transformers
|
42 |
+
|
43 |
+
Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
|
44 |
+
|
45 |
+
```python
|
46 |
+
from transformers import AutoTokenizer, AutoModel
|
47 |
+
import torch
|
48 |
+
|
49 |
+
|
50 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
51 |
+
def mean_pooling(model_output, attention_mask):
|
52 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
53 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
54 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
55 |
+
|
56 |
+
# Sentences we want sentence embeddings for
|
57 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
58 |
+
|
59 |
+
# Load model from HuggingFace Hub
|
60 |
+
tokenizer = AutoTokenizer.from_pretrained('antoinelouis/biencoder-antoinelouis-biencoder-camembert-base-mmarcoFRFR-bsard')
|
61 |
+
model = AutoModel.from_pretrained('antoinelouis/biencoder-antoinelouis-biencoder-camembert-base-mmarcoFRFR-bsard')
|
62 |
+
|
63 |
+
# Tokenize sentences
|
64 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
65 |
+
|
66 |
+
# Compute token embeddings
|
67 |
+
with torch.no_grad():
|
68 |
+
model_output = model(**encoded_input)
|
69 |
+
|
70 |
+
# Perform pooling. In this case, mean pooling.
|
71 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
72 |
+
print(sentence_embeddings)
|
73 |
+
```
|
74 |
+
|
75 |
+
## Evaluation
|
76 |
+
***
|
77 |
+
|
78 |
+
We evaluate the model on the test set of LLeQA, which consists of 195 legal questions with a knowlegde corpus of 27.9K candidate articles. We report the mean reciprocal rank (MRR), normalized discounted cumulative gainand (NDCG), mean average precision (MAP), and recall at various cut-offs (R@k).
|
79 |
+
|
80 |
+
| MRR@10 | NDCG@10 | MAP@10 | R@10 | R@100 | R@500 |
|
81 |
+
|---------:|----------:|---------:|-------:|--------:|--------:|
|
82 |
+
| 19.03 | 14.36 | 10.77 | 15.95 | 34.12 | 52.26 |
|
83 |
+
|
84 |
+
## Training
|
85 |
+
***
|
86 |
+
|
87 |
+
#### Background
|
88 |
+
|
89 |
+
We utilize the [camembert-base](https://huggingface.co/camembert-base) model and fine-tuned it on 9.3K question-article pairs in French. We used a contrastive learning objective: given a short legal question, the model should predict which out of a set of sampled legal articles, was actually paired with it in the dataset. Formally, we compute the cosine similarity from each possible pairs from the batch. We then apply the cross entropy loss with a temperature of 0.05 by comparing with true pairs.
|
90 |
+
|
91 |
+
#### Hyperparameters
|
92 |
+
|
93 |
+
We trained the model on a single Tesla V100 GPU with 32GBs of memory during 20 epochs (i.e., 5.4k steps) using a batch size of 32. We used the AdamW optimizer with an initial learning rate of 2e-05, weight decay of 0.01, learning rate warmup over the first 50 steps, and linear decay of the learning rate. The sequence length was limited to 384 tokens.
|
94 |
+
|
95 |
+
#### Data
|
96 |
+
|
97 |
+
We use the [Long-form Legal Question Answering (LLeQA)](https://huggingface.co/datasets/maastrichtlawtech/lleqa) dataset to fine-tune the model. LLeQA is a French native dataset for studying legal information retrieval and question answering. It consists of a knowledge corpus of 27,941 statutory articles collected from the Belgian legislation, and 1,868 legal questions posed by Belgian citizens and labeled by experienced jurists with a comprehensive answer rooted in relevant articles from the corpus.
|
98 |
+
|
99 |
+
## Citation
|
100 |
+
|
101 |
+
```bibtex
|
102 |
+
@article{louis2023interpretable,
|
103 |
+
author = {Louis, Antoine and van Dijck, Gijs and Spanakis, Gerasimos},
|
104 |
+
title = {Interpretable Long-Form Legal Question Answering with Retrieval-Augmented Large Language Models},
|
105 |
+
journal = {CoRR},
|
106 |
+
volume = {abs/2309.xxxxx},
|
107 |
+
year = {2023},
|
108 |
+
url = {https://doi.org/},
|
109 |
+
doi = {},
|
110 |
+
eprinttype = {arXiv},
|
111 |
+
eprint = {2309.xxxxx},
|
112 |
+
}
|
113 |
+
```
|
config.json
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "antoinelouis/biencoder-camembert-base-mmarcoFR",
|
3 |
+
"architectures": [
|
4 |
+
"CamembertModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"bos_token_id": 5,
|
8 |
+
"classifier_dropout": null,
|
9 |
+
"eos_token_id": 6,
|
10 |
+
"hidden_act": "gelu",
|
11 |
+
"hidden_dropout_prob": 0.1,
|
12 |
+
"hidden_size": 768,
|
13 |
+
"initializer_range": 0.02,
|
14 |
+
"intermediate_size": 3072,
|
15 |
+
"layer_norm_eps": 1e-05,
|
16 |
+
"max_position_embeddings": 514,
|
17 |
+
"model_type": "camembert",
|
18 |
+
"num_attention_heads": 12,
|
19 |
+
"num_hidden_layers": 12,
|
20 |
+
"output_past": true,
|
21 |
+
"pad_token_id": 1,
|
22 |
+
"position_embedding_type": "absolute",
|
23 |
+
"torch_dtype": "float32",
|
24 |
+
"transformers_version": "4.30.0.dev0",
|
25 |
+
"type_vocab_size": 1,
|
26 |
+
"use_cache": true,
|
27 |
+
"vocab_size": 32005
|
28 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.2.2",
|
4 |
+
"transformers": "4.30.0.dev0",
|
5 |
+
"pytorch": "2.1.0.dev20230321+cu117"
|
6 |
+
}
|
7 |
+
}
|
dev_scores.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
MRR@10,NDCG@10,MAP@10,Recall@10,Recall@100,Recall@500,model
|
2 |
+
19.03,14.36,10.77,15.95,34.12,52.26,biencoder-antoinelouis-biencoder-camembert-base-mmarcoFRFR-bsard
|
modules.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "sentence_transformers.models.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
+
}
|
14 |
+
]
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a227e4814fdf69df50c64449646d5e8367c1454f2f256b4034e43674cf642c6e
|
3 |
+
size 442559021
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 384,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|
sentencepiece.bpe.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:988bc5a00281c6d210a5d34bd143d0363741a432fefe741bf71e61b1869d4314
|
3 |
+
size 810912
|
special_tokens_map.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<s>NOTUSED",
|
4 |
+
"</s>NOTUSED"
|
5 |
+
],
|
6 |
+
"bos_token": "<s>",
|
7 |
+
"cls_token": "<s>",
|
8 |
+
"eos_token": "</s>",
|
9 |
+
"mask_token": {
|
10 |
+
"content": "<mask>",
|
11 |
+
"lstrip": true,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"pad_token": "<pad>",
|
17 |
+
"sep_token": "</s>",
|
18 |
+
"unk_token": "<unk>"
|
19 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<s>NOTUSED",
|
4 |
+
"</s>NOTUSED"
|
5 |
+
],
|
6 |
+
"bos_token": "<s>",
|
7 |
+
"clean_up_tokenization_spaces": true,
|
8 |
+
"cls_token": "<s>",
|
9 |
+
"eos_token": "</s>",
|
10 |
+
"mask_token": {
|
11 |
+
"__type": "AddedToken",
|
12 |
+
"content": "<mask>",
|
13 |
+
"lstrip": true,
|
14 |
+
"normalized": true,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": false
|
17 |
+
},
|
18 |
+
"model_max_length": 384,
|
19 |
+
"pad_token": "<pad>",
|
20 |
+
"sep_token": "</s>",
|
21 |
+
"tokenizer_class": "CamembertTokenizer",
|
22 |
+
"unk_token": "<unk>"
|
23 |
+
}
|