Hanna Abi Akl commited on
Commit
b0fd1ba
1 Parent(s): 89088f7

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +153 -0
README.md ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+ tags:
4
+ - sentence-transformers
5
+ - feature-extraction
6
+ - sentence-similarity
7
+ - transformers
8
+ ---
9
+
10
+ <div style="clear: both;">
11
+ <div style="float: left; margin-right 1em;">
12
+ <h1><strong>FinISH (Finance-Identifying Sroberta for Hypernyms)</strong></h1>
13
+ </div>
14
+ <div>
15
+ <h2><img src="https://pbs.twimg.com/profile_images/1333760924914753538/fQL4zLUw_400x400.png" alt="" width="25" height="25"></h2>
16
+ </div>
17
+ </div>
18
+
19
+ We present FinISH, a [SRoBERTa](https://huggingface.co/sentence-transformers/nli-roberta-base-v2) base model fine-tuned on the [FIBO ontology](https://spec.edmcouncil.org/fibo/) dataset for domain-specific representation learning on the [**Semantic Search**](https://www.sbert.net/examples/applications/semantic-search/README.html) downstream task.
20
+
21
+ ## SRoBERTa Model Architecture
22
+ Sentence-RoBERTa (SRoBERTa) is a modification of the pretrained RoBERTa network that uses siamese and triplet network structures to derive semantically meaningful sentence embeddings that can be compared using cosine-similarity. This reduces the effort for finding the most similar pair from 65 hours with RoBERTa to about 5 seconds with SRoBERTa, while maintaining the accuracy from RoBERTa. SRoBERTa has been evaluated on common STS tasks and transfer learning tasks, where it outperforms other state-of-the-art sentence embeddings methods.
23
+
24
+ Paper: [Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks](https://arxiv.org/pdf/1908.10084.pdf).
25
+
26
+ Authors: *Nils Reimers and Iryna Gurevych*.
27
+
28
+ ## Details on the downstream task (Semantic Search for Text Classification)
29
+ The objective of this task is to correctly classify a given term in the financial domain according to its prototypical hypernym in a list of available hypernym:
30
+ * Bonds
31
+ * Forward
32
+ * Funds
33
+ * Future
34
+ * MMIs (Money Market Instruments)
35
+ * Option
36
+ * Stocks
37
+ * Swap
38
+ * Equity Index
39
+ * Credit Index
40
+ * Securities restrictions
41
+ * Parametric schedules
42
+ * Debt pricing and yields
43
+ * Credit Events
44
+ * Stock Corporation
45
+ * Central Securities Depository
46
+ * Regulatory Agency
47
+
48
+ This kind-based approach relies on identifying the closest hypernym semantically to the given term (even if they possess common properties with other hypernyms).
49
+
50
+ #### Data Description
51
+ The data is a scraped list of term definitions from the FIBO ontology website where each definition has been mapped to its closest hypernym from the proposed labels.
52
+ For multi-sentence definitions, we applied sentence-splitting by punctuation delimiters. We also applied lowercase transformation on all input data.
53
+
54
+ #### Data Instances
55
+ The dataset contains a label representing the hypernym of the given definition.
56
+ ```json
57
+ {
58
+ 'label': 'bonds',
59
+ 'definition': 'callable convertible bond is a kind of callable bond, convertible bond.'
60
+ }
61
+ ```
62
+
63
+ #### Data Fields
64
+ **label**: Can be one of the 17 predefined hypernyms.
65
+
66
+ **definition**: Financial term definition relating to a concept or object in the financial domain.
67
+
68
+ #### Data Splits
69
+ The data contains training data with **317101** entries.
70
+
71
+ #### Test set metrics
72
+ The representational learning model is evaluated on a representative test set with 20% of the entries. The test set is scored based on the following metrics:
73
+ * Average Accuracy
74
+ * Mean Rank (position of the correct label in a set of 5 model predictions)
75
+
76
+ We evaluate FinISH according to these metrics, where it outperforms other state-of-the-art sentence embeddings methods in this task.
77
+ * Average Accuracy: **0.73**
78
+ * Mean Rank: **1.61**
79
+
80
+ ## Usage (Sentence-Transformers)
81
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
82
+ ```
83
+ git clone https://github.com/huggingface/transformers.git
84
+ pip install -q ./transformers
85
+ pip install -U sentence-transformers
86
+ ```
87
+ Then you can use the model like this:
88
+ ```python
89
+ from sentence_transformers import SentenceTransformer, util
90
+ import torch
91
+ model = SentenceTransformer('yseop/roberta-base-finance-hypernym-identification')
92
+ # Our corpus containing the list of hypernym labels
93
+ hypernyms = ['Bonds',
94
+ 'Forward',
95
+ 'Funds',
96
+ 'Future',
97
+ 'MMIs',
98
+ 'Option',
99
+ 'Stocks',
100
+ 'Swap',
101
+ 'Equity Index',
102
+ 'Credit Index',
103
+ 'Securities restrictions',
104
+ 'Parametric schedules',
105
+ 'Debt pricing and yields',
106
+ 'Credit Events',
107
+ 'Stock Corporation',
108
+ 'Central Securities Depository',
109
+ 'Regulatory Agency']
110
+ hypernym_embeddings = model.encode(hypernyms, convert_to_tensor=True)
111
+ # Query sentences are financial terms to match to the predefined labels
112
+ queries = ['Convertible bond', 'weighted average coupon', 'Restriction 144-A']
113
+ # Find the closest 5 hypernyms of the corpus for each query sentence based on cosine similarity
114
+ top_k = min(5, len(hypernyms))
115
+ for query in queries:
116
+ query_embedding = model.encode(query, convert_to_tensor=True)
117
+ # We use cosine-similarity and torch.topk to find the highest 5 scores
118
+ cos_scores = util.pytorch_cos_sim(query_embedding, hypernym_embeddings)[0]
119
+ top_results = torch.topk(cos_scores, k=top_k)
120
+ print("\n\n======================\n\n")
121
+ print("Query:", query)
122
+ print("\nTop 5 most similar hypernyms:")
123
+ for score, idx in zip(top_results[0], top_results[1]):
124
+ print(hypernyms[idx], "(Score: {:.4f})".format(score))
125
+ ```
126
+
127
+ ## Usage (HuggingFace Transformers)
128
+ 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.
129
+ ```python
130
+ from transformers import AutoTokenizer, AutoModel
131
+ import torch
132
+ #Mean Pooling - Take attention mask into account for correct averaging
133
+ def mean_pooling(model_output, attention_mask):
134
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
135
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
136
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
137
+ # Query sentences are financial terms to match to the predefined labels
138
+ queries = ['Convertible bond', 'weighted average coupon', 'Restriction 144-A']
139
+ # Load model from HuggingFace Hub
140
+ tokenizer = AutoTokenizer.from_pretrained('yseop/roberta-base-finance-hypernym-identification')
141
+ model = AutoModel.from_pretrained('yseop/roberta-base-finance-hypernym-identification')
142
+ # Tokenize sentences
143
+ encoded_input = tokenizer(queries, padding=True, truncation=True, return_tensors='pt')
144
+ # Compute token embeddings
145
+ with torch.no_grad():
146
+ model_output = model(**encoded_input)
147
+ # Perform pooling
148
+ query_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
149
+ print("Query embeddings:")
150
+ print(query_embeddings)
151
+ ```
152
+
153
+ **Created by:** [Yseop](https://www.yseop.com/) | Pioneer in Natural Language Generation (NLG) technology. Scaling human expertise through Natural Language Generation.