96abhishekarora commited on
Commit
1b4230e
1 Parent(s): 838beaf

Modified validation and training for 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
+ pytorch_model.bin filter=lfs diff=lfs merge=lfs -text
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
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
+ }
LT_training_config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_save_dir": "models",
3
+ "model_save_name": "linkage_kn_en_familyname",
4
+ "opt_model_description": "This model was trained on a dataset consisting of 8138064 people and their family id \n It was trained for 10 epochs using other defaults that can be found in the repo's LinkTransformer config file - LT_training_config.json \n ",
5
+ "opt_model_lang": [
6
+ "kn",
7
+ "en"
8
+ ],
9
+ "train_batch_size": 64,
10
+ "num_epochs": 10,
11
+ "warm_up_perc": 1,
12
+ "learning_rate": 2e-06,
13
+ "val_perc": 0.01,
14
+ "wandb_names": {
15
+ "project": "linkage",
16
+ "id": "econabhishek",
17
+ "run": "linkage_kn_en_familyname",
18
+ "entity": "econabhishek"
19
+ },
20
+ "add_pooling_layer": false,
21
+ "large_val": false,
22
+ "eval_steps_perc": 0.1,
23
+ "test_at_end": true,
24
+ "save_val_test_pickles": true,
25
+ "val_query_prop": 0.5,
26
+ "eval_type": "retrieval",
27
+ "training_dataset": "dataframe",
28
+ "base_model_path": "bert-base-multilingual-cased",
29
+ "best_model_path": "models/linkage_kn_en_familyname"
30
+ }
README.md ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+ language:
4
+ - kn
5
+ - en
6
+ tags:
7
+ - linktransformer
8
+ - sentence-transformers
9
+ - sentence-similarity
10
+ - tabular-classification
11
+
12
+ ---
13
+
14
+ # 96abhishekarora/lt-kn-en_familyname-linkage
15
+
16
+ This is a [LinkTransformer](https://github.com/dell-research-harvard/linktransformer) 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.
17
+ It is designed for quick and easy record linkage (entity-matching) through the LinkTransformer package. The tasks include clustering, deduplication, linking, aggregation and more.
18
+ Notwithstanding that, it can be used for any sentence similarity task within the sentence-transformers framework as well.
19
+ It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
20
+ 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.
21
+
22
+
23
+ This model has been fine-tuned on the model : bert-base-multilingual-cased. It is pretrained for the language : - kn
24
+ - en.
25
+
26
+
27
+ This model was trained on a dataset consisting of 8138064 people and their family id
28
+ It was trained for 10 epochs using other defaults that can be found in the repo's LinkTransformer config file - LT_training_config.json
29
+
30
+
31
+ ## Usage (LinkTransformer)
32
+
33
+ Using this model becomes easy when you have [LinkTransformer](https://github.com/dell-research-harvard/linktransformer) installed:
34
+
35
+ ```
36
+ pip install -U linktransformer
37
+ ```
38
+
39
+ Then you can use the model like this:
40
+
41
+ ```python
42
+ import linktransformer as lt
43
+ import pandas as pd
44
+
45
+ ##Load the two dataframes that you want to link. For example, 2 dataframes with company names that are written differently
46
+ df1=pd.read_csv("data/df1.csv") ###This is the left dataframe with key CompanyName for instance
47
+ df2=pd.read_csv("data/df2.csv") ###This is the right dataframe with key CompanyName for instance
48
+
49
+ ###Merge the two dataframes on the key column!
50
+ df_merged = lt.merge(df1, df2, on="CompanyName", how="inner")
51
+
52
+ ##Done! The merged dataframe has a column called "score" that contains the similarity score between the two company names
53
+
54
+ ```
55
+
56
+
57
+ ## Training your own LinkTransformer model
58
+ 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
59
+ The model was trained using SupCon loss.
60
+ Usage can be found in the package docs.
61
+ The training config can be found in the repo with the name LT_training_config.json
62
+ 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.
63
+ Here is an example.
64
+
65
+
66
+ ```python
67
+
68
+ ##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.
69
+ saved_model_path = train_model(
70
+ model_path="hiiamsid/sentence_similarity_spanish_es",
71
+ dataset_path=dataset_path,
72
+ left_col_names=["description47"],
73
+ right_col_names=['description48'],
74
+ left_id_name=['tariffcode47'],
75
+ right_id_name=['tariffcode48'],
76
+ log_wandb=False,
77
+ config_path=LINKAGE_CONFIG_PATH,
78
+ training_args={"num_epochs": 1}
79
+ )
80
+
81
+ ```
82
+
83
+
84
+ 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.
85
+ Read our paper and the documentation for more!
86
+
87
+
88
+
89
+ ## Evaluation Results
90
+
91
+ <!--- Describe how your model was evaluated -->
92
+
93
+ You can evaluate the model using the [LinkTransformer](https://github.com/dell-research-harvard/linktransformer) package's inference functions.
94
+ 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.
95
+
96
+
97
+ ## Training
98
+ The model was trained with the parameters:
99
+
100
+ **DataLoader**:
101
+
102
+ `torch.utils.data.dataloader.DataLoader` of length 113924 with parameters:
103
+ ```
104
+ {'batch_size': 64, 'sampler': 'torch.utils.data.dataloader._InfiniteConstantSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
105
+ ```
106
+
107
+ **Loss**:
108
+
109
+ `linktransformer.modified_sbert.losses.SupConLoss_wandb`
110
+
111
+ Parameters of the fit()-Method:
112
+ ```
113
+ {
114
+ "epochs": 10,
115
+ "evaluation_steps": 11393,
116
+ "evaluator": "sentence_transformers.evaluation.SequentialEvaluator.SequentialEvaluator",
117
+ "max_grad_norm": 1,
118
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
119
+ "optimizer_params": {
120
+ "lr": 2e-06
121
+ },
122
+ "scheduler": "WarmupLinear",
123
+ "steps_per_epoch": null,
124
+ "warmup_steps": 1139240,
125
+ "weight_decay": 0.01
126
+ }
127
+ ```
128
+
129
+
130
+
131
+
132
+ LinkTransformer(
133
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
134
+ (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})
135
+ )
136
+ ```
137
+
138
+ ## Citing & Authors
139
+
140
+ <!--- Describe where people can find more information -->
config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "models/linkage_kn_en_familyname/",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "directionality": "bidi",
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 0,
20
+ "pooler_fc_size": 768,
21
+ "pooler_num_attention_heads": 12,
22
+ "pooler_num_fc_layers": 3,
23
+ "pooler_size_per_head": 128,
24
+ "pooler_type": "first_token_transform",
25
+ "position_embedding_type": "absolute",
26
+ "torch_dtype": "float32",
27
+ "transformers_version": "4.31.0",
28
+ "type_vocab_size": 2,
29
+ "use_cache": true,
30
+ "vocab_size": 119547
31
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.2",
4
+ "transformers": "4.31.0",
5
+ "pytorch": "2.0.1+cu117"
6
+ }
7
+ }
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:8af50c97be5450dea1d079b45919e05e992d4d72babaa4c09a7d64793982cd3e
3
+ size 711477737
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "do_lower_case": false,
5
+ "mask_token": "[MASK]",
6
+ "model_max_length": 1000000000000000019884624838656,
7
+ "pad_token": "[PAD]",
8
+ "sep_token": "[SEP]",
9
+ "strip_accents": null,
10
+ "tokenize_chinese_chars": true,
11
+ "tokenizer_class": "BertTokenizer",
12
+ "unk_token": "[UNK]"
13
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff