aidanlli commited on
Commit
9a8240c
1 Parent(s): cc4eb1d

Add new LinkTransformer model.

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.safetensors filter=lfs diff=lfs merge=lfs -text
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
+ }
LT_training_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_save_dir": "models",
3
+ "model_save_name": "linkage",
4
+ "opt_model_description": null,
5
+ "opt_model_lang": null,
6
+ "train_batch_size": 64,
7
+ "num_epochs": 1,
8
+ "warm_up_perc": 1,
9
+ "learning_rate": 2e-05,
10
+ "loss_type": "supcon",
11
+ "val_perc": 0.2,
12
+ "wandb_names": {
13
+ "project": "linktransformer",
14
+ "id": "your-id",
15
+ "run": "run-name",
16
+ "entity": "your-id"
17
+ },
18
+ "add_pooling_layer": false,
19
+ "large_val": true,
20
+ "eval_steps_perc": 0.5,
21
+ "test_at_end": true,
22
+ "save_val_test_pickles": true,
23
+ "val_query_prop": 0.5,
24
+ "loss_params": {},
25
+ "eval_type": "retrieval",
26
+ "training_dataset": "/content/drive/My Drive/korea/panel_task/linktransformer_postest.csv",
27
+ "base_model_path": "oshizo/sbert-jsnli-luke-japanese-base-lite",
28
+ "best_model_path": "models/linkage"
29
+ }
README.md ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+
4
+ tags:
5
+ - linktransformer
6
+ - sentence-transformers
7
+ - sentence-similarity
8
+ - tabular-classification
9
+
10
+ ---
11
+
12
+ # aidanlli/posmodel
13
+
14
+ This is a [LinkTransformer](https://linktransformer.github.io/) model. At its core this model this is a sentence transformer model [sentence-transformers](https://www.SBERT.net) model- it just wraps around the class.
15
+ It is designed for quick and easy record linkage (entity-matching) through the LinkTransformer package. The tasks include clustering, deduplication, linking, aggregation and more.
16
+ Notwithstanding that, it can be used for any sentence similarity task within the sentence-transformers framework as well.
17
+ It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
18
+ Take a look at the documentation of [sentence-transformers](https://www.sbert.net/index.html) if you want to use this model for more than what we support in our applications.
19
+
20
+
21
+ This model has been fine-tuned on the model : oshizo/sbert-jsnli-luke-japanese-base-lite.
22
+
23
+
24
+
25
+
26
+ ## Usage (LinkTransformer)
27
+
28
+ Using this model becomes easy when you have [LinkTransformer](https://github.com/dell-research-harvard/linktransformer) installed:
29
+
30
+ ```
31
+ pip install -U linktransformer
32
+ ```
33
+
34
+ Then you can use the model like this:
35
+
36
+ ```python
37
+ import linktransformer as lt
38
+ import pandas as pd
39
+
40
+ ##Load the two dataframes that you want to link. For example, 2 dataframes with company names that are written differently
41
+ df1=pd.read_csv("data/df1.csv") ###This is the left dataframe with key CompanyName for instance
42
+ df2=pd.read_csv("data/df2.csv") ###This is the right dataframe with key CompanyName for instance
43
+
44
+ ###Merge the two dataframes on the key column!
45
+ df_merged = lt.merge(df1, df2, on="CompanyName", how="inner")
46
+
47
+ ##Done! The merged dataframe has a column called "score" that contains the similarity score between the two company names
48
+
49
+ ```
50
+
51
+
52
+ ## Training your own LinkTransformer model
53
+ Any Sentence Transformers can be used as a backbone by simply adding a pooling layer. Any other transformer on HuggingFace can also be used by specifying the option add_pooling_layer==True
54
+ The model was trained using SupCon loss.
55
+ Usage can be found in the package docs.
56
+ The training config can be found in the repo with the name LT_training_config.json
57
+ To replicate the training, you can download the file and specify the path in the config_path argument of the training function. You can also override the config by specifying the training_args argument.
58
+ Here is an example.
59
+
60
+
61
+ ```python
62
+
63
+ ##Consider the example in the paper that has a dataset of Mexican products and their tariff codes from 1947 and 1948 and we want train a model to link the two tariff codes.
64
+ saved_model_path = train_model(
65
+ model_path="hiiamsid/sentence_similarity_spanish_es",
66
+ dataset_path=dataset_path,
67
+ left_col_names=["description47"],
68
+ right_col_names=['description48'],
69
+ left_id_name=['tariffcode47'],
70
+ right_id_name=['tariffcode48'],
71
+ log_wandb=False,
72
+ config_path=LINKAGE_CONFIG_PATH,
73
+ training_args={"num_epochs": 1}
74
+ )
75
+
76
+ ```
77
+
78
+
79
+ You can also use this package for deduplication (clusters a df on the supplied key column). Merging a fine class (like product) to a coarse class (like HS code) is also possible.
80
+ Read our paper and the documentation for more!
81
+
82
+
83
+
84
+ ## Evaluation Results
85
+
86
+ <!--- Describe how your model was evaluated -->
87
+
88
+ You can evaluate the model using the [LinkTransformer](https://github.com/dell-research-harvard/linktransformer) package's inference functions.
89
+ We have provided a few datasets in the package for you to try out. We plan to host more datasets on Huggingface and our website (Coming soon) that you can take a look at.
90
+
91
+
92
+ ## Training
93
+ The model was trained with the parameters:
94
+
95
+ **DataLoader**:
96
+
97
+ `torch.utils.data.dataloader.DataLoader` of length 1 with parameters:
98
+ ```
99
+ {'batch_size': 64, 'sampler': 'torch.utils.data.dataloader._InfiniteConstantSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
100
+ ```
101
+
102
+ **Loss**:
103
+
104
+ `linktransformer.modified_sbert.losses.SupConLoss_wandb`
105
+
106
+ Parameters of the fit()-Method:
107
+ ```
108
+ {
109
+ "epochs": 1,
110
+ "evaluation_steps": 1,
111
+ "evaluator": "sentence_transformers.evaluation.SequentialEvaluator.SequentialEvaluator",
112
+ "max_grad_norm": 1,
113
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
114
+ "optimizer_params": {
115
+ "lr": 2e-05
116
+ },
117
+ "scheduler": "WarmupLinear",
118
+ "steps_per_epoch": null,
119
+ "warmup_steps": 1,
120
+ "weight_decay": 0.01
121
+ }
122
+ ```
123
+
124
+
125
+
126
+
127
+ LinkTransformer(
128
+ (0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: LukeModel
129
+ (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False})
130
+ )
131
+ ```
132
+
133
+ ## Citing & Authors
134
+
135
+ ```
136
+ @misc{arora2023linktransformer,
137
+ title={LinkTransformer: A Unified Package for Record Linkage with Transformer Language Models},
138
+ author={Abhishek Arora and Melissa Dell},
139
+ year={2023},
140
+ eprint={2309.00789},
141
+ archivePrefix={arXiv},
142
+ primaryClass={cs.CL}
143
+ }
144
+
145
+ ```
added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "<ent2>": 32771,
3
+ "<ent>": 32770
4
+ }
config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "models/linkage",
3
+ "architectures": [
4
+ "LukeModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bert_model_name": "models/luke-japanese/hf_xlm_roberta",
8
+ "bos_token_id": 0,
9
+ "classifier_dropout": null,
10
+ "cls_entity_prediction": false,
11
+ "entity_emb_size": 256,
12
+ "entity_vocab_size": 4,
13
+ "eos_token_id": 2,
14
+ "hidden_act": "gelu",
15
+ "hidden_dropout_prob": 0.1,
16
+ "hidden_size": 768,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "layer_norm_eps": 1e-05,
20
+ "max_position_embeddings": 514,
21
+ "model_type": "luke",
22
+ "num_attention_heads": 12,
23
+ "num_hidden_layers": 12,
24
+ "pad_token_id": 1,
25
+ "position_embedding_type": "absolute",
26
+ "torch_dtype": "float32",
27
+ "transformers_version": "4.41.1",
28
+ "type_vocab_size": 1,
29
+ "use_cache": true,
30
+ "use_entity_aware_attention": true,
31
+ "vocab_size": 32772
32
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.2",
4
+ "transformers": "4.25.1",
5
+ "pytorch": "1.13.0+cu116"
6
+ }
7
+ }
entity_vocab.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "[MASK2]": 3,
3
+ "[MASK]": 0,
4
+ "[PAD]": 2,
5
+ "[UNK]": 1
6
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:882195bf57f6178b187ee24446a6091f8842bfeb8984266d2e7f867e2f87ce77
3
+ size 532299592
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
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 128,
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:d8b73a5e054936c920cf5b7d1ec21ce9c281977078269963beb821c6c86fbff7
3
+ size 841889
special_tokens_map.json ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<ent>",
4
+ "<ent2>",
5
+ "<ent>",
6
+ "<ent2>",
7
+ "<ent>",
8
+ "<ent2>",
9
+ "<ent>",
10
+ "<ent2>",
11
+ {
12
+ "content": "<ent>",
13
+ "lstrip": false,
14
+ "normalized": true,
15
+ "rstrip": false,
16
+ "single_word": false
17
+ },
18
+ {
19
+ "content": "<ent2>",
20
+ "lstrip": false,
21
+ "normalized": true,
22
+ "rstrip": false,
23
+ "single_word": false
24
+ }
25
+ ],
26
+ "bos_token": {
27
+ "content": "<s>",
28
+ "lstrip": false,
29
+ "normalized": false,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ },
33
+ "cls_token": {
34
+ "content": "<s>",
35
+ "lstrip": false,
36
+ "normalized": false,
37
+ "rstrip": false,
38
+ "single_word": false
39
+ },
40
+ "eos_token": {
41
+ "content": "</s>",
42
+ "lstrip": false,
43
+ "normalized": false,
44
+ "rstrip": false,
45
+ "single_word": false
46
+ },
47
+ "mask_token": {
48
+ "content": "<mask>",
49
+ "lstrip": true,
50
+ "normalized": true,
51
+ "rstrip": false,
52
+ "single_word": false
53
+ },
54
+ "pad_token": {
55
+ "content": "<pad>",
56
+ "lstrip": false,
57
+ "normalized": false,
58
+ "rstrip": false,
59
+ "single_word": false
60
+ },
61
+ "sep_token": {
62
+ "content": "</s>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false
67
+ },
68
+ "unk_token": {
69
+ "content": "<unk>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false
74
+ }
75
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "32769": {
36
+ "content": "<mask>",
37
+ "lstrip": true,
38
+ "normalized": true,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "32770": {
44
+ "content": "<ent>",
45
+ "lstrip": false,
46
+ "normalized": true,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "32771": {
52
+ "content": "<ent2>",
53
+ "lstrip": false,
54
+ "normalized": true,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ }
59
+ },
60
+ "additional_special_tokens": [
61
+ "<ent>",
62
+ "<ent2>",
63
+ "<ent>",
64
+ "<ent2>",
65
+ "<ent>",
66
+ "<ent2>",
67
+ "<ent>",
68
+ "<ent2>",
69
+ "<ent>",
70
+ "<ent2>"
71
+ ],
72
+ "bos_token": "<s>",
73
+ "clean_up_tokenization_spaces": true,
74
+ "cls_token": "<s>",
75
+ "entity_mask2_token": "[MASK2]",
76
+ "entity_mask_token": "[MASK]",
77
+ "entity_pad_token": "[PAD]",
78
+ "entity_token_1": {
79
+ "__type": "AddedToken",
80
+ "content": "<ent>",
81
+ "lstrip": false,
82
+ "normalized": true,
83
+ "rstrip": false,
84
+ "single_word": false,
85
+ "special": false
86
+ },
87
+ "entity_token_2": {
88
+ "__type": "AddedToken",
89
+ "content": "<ent2>",
90
+ "lstrip": false,
91
+ "normalized": true,
92
+ "rstrip": false,
93
+ "single_word": false,
94
+ "special": false
95
+ },
96
+ "entity_unk_token": "[UNK]",
97
+ "eos_token": "</s>",
98
+ "mask_token": "<mask>",
99
+ "max_entity_length": 32,
100
+ "max_mention_length": 30,
101
+ "model_max_length": 512,
102
+ "pad_token": "<pad>",
103
+ "sep_token": "</s>",
104
+ "sp_model_kwargs": {},
105
+ "task": null,
106
+ "tokenizer_class": "MLukeTokenizer",
107
+ "unk_token": "<unk>"
108
+ }