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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language: en
|
3 |
+
tags:
|
4 |
+
- Clsssification
|
5 |
license: apache-2.0
|
6 |
+
datasets:
|
7 |
+
- Opinosis
|
8 |
+
- ...
|
9 |
+
- MCTI_data
|
10 |
+
thumbnail: https://github.com/Marcosdib/S2Query/Classification_Architecture_model.png
|
11 |
---
|
12 |
+
|
13 |
+

|
14 |
+
|
15 |
+
|
16 |
+
# MCTI Text Classification Task (uncased) DRAFT
|
17 |
+
|
18 |
+
Disclaimer:
|
19 |
+
|
20 |
+
## According to the abstract,
|
21 |
+
|
22 |
+
Text classification is a traditional problem in Natural Language Processing (NLP). Most of the state-of-the-art implementations
|
23 |
+
require high-quality, voluminous, labeled data. Pre- trained models on large corpora have shown beneficial for text classification
|
24 |
+
and other NLP tasks, but they can only take a limited amount of symbols as input. This is a real case study that explores
|
25 |
+
different machine learning strategies to classify a small amount of long, unstructured, and uneven data to find a proper method
|
26 |
+
with good performance. The collected data includes texts of financing opportunities the international R&D funding organizations
|
27 |
+
provided on theirwebsites. The main goal is to find international R&D funding eligible for Brazilian researchers, sponsored by
|
28 |
+
the Ministry of Science, Technology and Innovation. We use pre-training and word embedding solutions to learn the relationship
|
29 |
+
of the words from other datasets with considerable similarity and larger scale. Then, using the acquired features, based on the
|
30 |
+
available dataset from MCTI, we apply transfer learning plus deep learning models to improve the comprehension of each sentence.
|
31 |
+
Compared to the baseline accuracy rate of 81%, based on the available datasets, and the 85% accuracy rate achieved through a
|
32 |
+
Transformer-based approach, the Word2Vec-based approach improved the accuracy rate to 88%. The research results serve as
|
33 |
+
asuccessful case of artificial intelligence in a federal government application.
|
34 |
+
|
35 |
+
This model focus on a more specific problem, creating a Research Financing Products Portfolio (FPP) outside ofthe Union budget,
|
36 |
+
supported by the Brazilian Ministry of Science, Technology, and Innovation (MCTI). It was introduced in ["Using transfer learning to classify long unstructured texts with small amounts of labeled data"](https://www.scitepress.org/Link.aspx?doi=10.5220/0011527700003318) and first released in
|
37 |
+
[this repository](https://huggingface.co/unb-lamfo-nlp-mcti). This model is uncased: it does not make a difference between english
|
38 |
+
and English.
|
39 |
+
|
40 |
+
## Model description
|
41 |
+
|
42 |
+
Nullam congue hendrerit turpis et facilisis. Cras accumsan ante mi, eu hendrerit nulla finibus at. Donec imperdiet,
|
43 |
+
nisi nec pulvinar suscipit, dolor nulla sagittis massa, et vehicula ante felis quis nibh. Lorem ipsum dolor sit amet,
|
44 |
+
consectetur adipiscing elit. Maecenas viverra tempus risus non ornare. Donec in vehicula est. Pellentesque vulputate
|
45 |
+
bibendum cursus. Nunc volutpat vitae neque ut bibendum:
|
46 |
+
|
47 |
+
- Nullam congue hendrerit turpis et facilisis. Cras accumsan ante mi, eu hendrerit nulla finibus at. Donec imperdiet,
|
48 |
+
nisi nec pulvinar suscipit, dolor nulla sagittis massa, et vehicula ante felis quis nibh. Lorem ipsum dolor sit amet,
|
49 |
+
consectetur adipiscing elit.
|
50 |
+
- Nullam congue hendrerit turpis et facilisis. Cras accumsan ante mi, eu hendrerit nulla finibus at. Donec imperdiet,
|
51 |
+
nisi nec pulvinar suscipit, dolor nulla sagittis massa, et vehicula ante felis quis nibh. Lorem ipsum dolor sit amet,
|
52 |
+
consectetur adipiscing elit.
|
53 |
+
|
54 |
+
Nullam congue hendrerit turpis et facilisis. Cras accumsan ante mi, eu hendrerit nulla finibus at. Donec imperdiet,
|
55 |
+
nisi nec pulvinar suscipit, dolor nulla sagittis massa, et vehicula ante felis quis nibh. Lorem ipsum dolor sit amet,
|
56 |
+
consectetur adipiscing elit. Maecenas viverra tempus risus non ornare. Donec in vehicula est. Pellentesque vulputate
|
57 |
+
bibendum cursus. Nunc volutpat vitae neque ut bibendum.
|
58 |
+
|
59 |
+

|
60 |
+
|
61 |
+
## Model variations
|
62 |
+
|
63 |
+
With the motivation to increase accuracy obtained with baseline implementation, we implemented a transfer learning
|
64 |
+
strategy under the assumption that small data available for training was insufficient for adequate embedding training.
|
65 |
+
In this context, we considered two approaches:
|
66 |
+
|
67 |
+
i) pre-training wordembeddings using similar datasets for text classification;
|
68 |
+
ii) using transformers and attention mechanisms (Longformer) to create contextualized embeddings.
|
69 |
+
|
70 |
+
XXXX has originally been released in base and large variations, for cased and uncased input text. The uncased models
|
71 |
+
also strips out an accent markers. Chinese and multilingual uncased and cased versions followed shortly after.
|
72 |
+
Modified preprocessing with whole word masking has replaced subpiece masking in a following work, with the release of
|
73 |
+
two models.
|
74 |
+
|
75 |
+
Other 24 smaller models are released afterward.
|
76 |
+
|
77 |
+
The detailed release history can be found on the [here](https://huggingface.co/unb-lamfo-nlp-mcti) on github.
|
78 |
+
|
79 |
+
| Model | #params | Language |
|
80 |
+
|------------------------------|--------------------|-------|
|
81 |
+
| [`mcti-base-uncased`] | 110M | English |
|
82 |
+
| [`mcti-large-uncased`] | 340M | English | sub
|
83 |
+
| [`mcti-base-cased`] | 110M | English |
|
84 |
+
| [`mcti-large-cased`] | 110M | Chinese |
|
85 |
+
| [`-base-multilingual-cased`] | 110M | Multiple |
|
86 |
+
|
87 |
+
| Dataset | Compatibility to base* |
|
88 |
+
|----------------------------|------------------------|
|
89 |
+
| Labeled MCTI | 100% |
|
90 |
+
| Full MCTI | 100% |
|
91 |
+
| BBC News Articles | 56.77% |
|
92 |
+
| New unlabeled MCTI | 75.26% |
|
93 |
+
|
94 |
+
|
95 |
+
## Intended uses
|
96 |
+
|
97 |
+
You can use the raw model for either masked language modeling or next sentence prediction, but it's mostly intended to
|
98 |
+
be fine-tuned on a downstream task. See the [model hub](https://www.google.com) to look for
|
99 |
+
fine-tuned versions of a task that interests you.
|
100 |
+
|
101 |
+
Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
|
102 |
+
to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
|
103 |
+
generation you should look at model like XXX.
|
104 |
+
|
105 |
+
### How to use
|
106 |
+
|
107 |
+
You can use this model directly with a pipeline for masked language modeling:
|
108 |
+
|
109 |
+
```python
|
110 |
+
>>> from transformers import pipeline
|
111 |
+
>>> unmasker = pipeline('fill-mask', model='bert-base-uncased')
|
112 |
+
>>> unmasker("Hello I'm a [MASK] model.")
|
113 |
+
|
114 |
+
[{'sequence': "[CLS] hello i'm a fashion model. [SEP]",
|
115 |
+
'score': 0.1073106899857521,
|
116 |
+
'token': 4827,
|
117 |
+
'token_str': 'fashion'},
|
118 |
+
{'sequence': "[CLS] hello i'm a role model. [SEP]",
|
119 |
+
'score': 0.08774490654468536,
|
120 |
+
'token': 2535,
|
121 |
+
'token_str': 'role'},
|
122 |
+
{'sequence': "[CLS] hello i'm a new model. [SEP]",
|
123 |
+
'score': 0.05338378623127937,
|
124 |
+
'token': 2047,
|
125 |
+
'token_str': 'new'},
|
126 |
+
{'sequence': "[CLS] hello i'm a super model. [SEP]",
|
127 |
+
'score': 0.04667217284440994,
|
128 |
+
'token': 3565,
|
129 |
+
'token_str': 'super'},
|
130 |
+
{'sequence': "[CLS] hello i'm a fine model. [SEP]",
|
131 |
+
'score': 0.027095865458250046,
|
132 |
+
'token': 2986,
|
133 |
+
'token_str': 'fine'}]
|
134 |
+
```
|
135 |
+
|
136 |
+
Here is how to use this model to get the features of a given text in PyTorch:
|
137 |
+
|
138 |
+
```python
|
139 |
+
from transformers import BertTokenizer, BertModel
|
140 |
+
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
141 |
+
model = BertModel.from_pretrained("bert-base-uncased")
|
142 |
+
text = "Replace me by any text you'd like."
|
143 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
144 |
+
output = model(**encoded_input)
|
145 |
+
```
|
146 |
+
|
147 |
+
and in TensorFlow:
|
148 |
+
|
149 |
+
```python
|
150 |
+
from transformers import BertTokenizer, TFBertModel
|
151 |
+
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
152 |
+
model = TFBertModel.from_pretrained("bert-base-uncased")
|
153 |
+
text = "Replace me by any text you'd like."
|
154 |
+
encoded_input = tokenizer(text, return_tensors='tf')
|
155 |
+
output = model(encoded_input)
|
156 |
+
```
|
157 |
+
|
158 |
+
### Limitations and bias
|
159 |
+
|
160 |
+
Even if the training data used for this model could be characterized as fairly neutral, this model can have biased
|
161 |
+
predictions:
|
162 |
+
|
163 |
+
```python
|
164 |
+
>>> from transformers import pipeline
|
165 |
+
>>> unmasker = pipeline('fill-mask', model='bert-base-uncased')
|
166 |
+
>>> unmasker("The man worked as a [MASK].")
|
167 |
+
|
168 |
+
[{'sequence': '[CLS] the man worked as a carpenter. [SEP]',
|
169 |
+
'score': 0.09747550636529922,
|
170 |
+
'token': 10533,
|
171 |
+
'token_str': 'carpenter'},
|
172 |
+
{'sequence': '[CLS] the man worked as a waiter. [SEP]',
|
173 |
+
'score': 0.0523831807076931,
|
174 |
+
'token': 15610,
|
175 |
+
'token_str': 'waiter'},
|
176 |
+
{'sequence': '[CLS] the man worked as a barber. [SEP]',
|
177 |
+
'score': 0.04962705448269844,
|
178 |
+
'token': 13362,
|
179 |
+
'token_str': 'barber'},
|
180 |
+
{'sequence': '[CLS] the man worked as a mechanic. [SEP]',
|
181 |
+
'score': 0.03788609802722931,
|
182 |
+
'token': 15893,
|
183 |
+
'token_str': 'mechanic'},
|
184 |
+
{'sequence': '[CLS] the man worked as a salesman. [SEP]',
|
185 |
+
'score': 0.037680890411138535,
|
186 |
+
'token': 18968,
|
187 |
+
'token_str': 'salesman'}]
|
188 |
+
|
189 |
+
>>> unmasker("The woman worked as a [MASK].")
|
190 |
+
|
191 |
+
[{'sequence': '[CLS] the woman worked as a nurse. [SEP]',
|
192 |
+
'score': 0.21981462836265564,
|
193 |
+
'token': 6821,
|
194 |
+
'token_str': 'nurse'},
|
195 |
+
{'sequence': '[CLS] the woman worked as a waitress. [SEP]',
|
196 |
+
'score': 0.1597415804862976,
|
197 |
+
'token': 13877,
|
198 |
+
'token_str': 'waitress'},
|
199 |
+
{'sequence': '[CLS] the woman worked as a maid. [SEP]',
|
200 |
+
'score': 0.1154729500412941,
|
201 |
+
'token': 10850,
|
202 |
+
'token_str': 'maid'},
|
203 |
+
{'sequence': '[CLS] the woman worked as a prostitute. [SEP]',
|
204 |
+
'score': 0.037968918681144714,
|
205 |
+
'token': 19215,
|
206 |
+
'token_str': 'prostitute'},
|
207 |
+
{'sequence': '[CLS] the woman worked as a cook. [SEP]',
|
208 |
+
'score': 0.03042375110089779,
|
209 |
+
'token': 5660,
|
210 |
+
'token_str': 'cook'}]
|
211 |
+
```
|
212 |
+
|
213 |
+
This bias will also affect all fine-tuned versions of this model.
|
214 |
+
|
215 |
+
## Training data
|
216 |
+
|
217 |
+
The BERT model was pretrained on [BookCorpus](https://yknzhu.wixsite.com/mbweb), a dataset consisting of 11,038
|
218 |
+
unpublished books and [English Wikipedia](https://en.wikipedia.org/wiki/English_Wikipedia) (excluding lists, tables and
|
219 |
+
headers).
|
220 |
+
|
221 |
+
|
222 |
+
## Training procedure
|
223 |
+
|
224 |
+
### Preprocessing
|
225 |
+
|
226 |
+
The texts are lowercased and tokenized using WordPiece and a vocabulary size of 30,000. The inputs of the model are
|
227 |
+
then of the form:
|
228 |
+
|
229 |
+
```
|
230 |
+
[CLS] Sentence A [SEP] Sentence B [SEP]
|
231 |
+
```
|
232 |
+
|
233 |
+
With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus, and in
|
234 |
+
the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
|
235 |
+
consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
|
236 |
+
"sentences" has a combined length of less than 512 tokens.
|
237 |
+
|
238 |
+
The details of the masking procedure for each sentence are the following:
|
239 |
+
- 15% of the tokens are masked.
|
240 |
+
- In 80% of the cases, the masked tokens are replaced by `[MASK]`.
|
241 |
+
- In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
|
242 |
+
- In the 10% remaining cases, the masked tokens are left as is.
|
243 |
+
|
244 |
+
### Pretraining
|
245 |
+
|
246 |
+
The model was trained on 4 cloud TPUs in Pod configuration (16 TPU chips total) for one million steps with a batch size
|
247 |
+
of 256. The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%. The optimizer
|
248 |
+
used is Adam with a learning rate of 1e-4, \\(\beta_{1} = 0.9\\) and \\(\beta_{2} = 0.999\\), a weight decay of 0.01,
|
249 |
+
learning rate warmup for 10,000 steps and linear decay of the learning rate after.
|
250 |
+
|
251 |
+
## Evaluation results
|
252 |
+
|
253 |
+
### Model training with Word2Vec embeddings
|
254 |
+
|
255 |
+
Now we have a pre-trained model of word2vec embeddings that has already learned relevant meaningsfor our classification problem.
|
256 |
+
We can couple it to our classification models (Fig. 4), realizing transferlearning and then training the model with the labeled
|
257 |
+
data in a supervised manner. The new coupled model can be seen in Figure 5 under word2vec model training. The Table 3 shows the
|
258 |
+
obtained results with related metrics. With this implementation, we achieved new levels of accuracy with 86% for the CNN
|
259 |
+
architecture and 88% for the LSTM architecture.
|
260 |
+
|
261 |
+
|
262 |
+
Table 1: Results from Pre-trained WE + ML models.
|
263 |
+
|
264 |
+
| ML Model | Accuracy | F1 Score | Precision | Recall |
|
265 |
+
|:--------:|:---------:|:---------:|:---------:|:---------:|
|
266 |
+
| NN | 0.8269 | 0.8545 | 0.8392 | 0.8712 |
|
267 |
+
| DNN | 0.7115 | 0.7794 | 0.7255 | 0.8485 |
|
268 |
+
| CNN | 0.8654 | 0.9083 | 0.8486 | 0.9773 |
|
269 |
+
| LSTM | 0.8846 | 0.9139 | 0.9056 | 0.9318 |
|
270 |
+
|
271 |
+
### Transformer-based implementation
|
272 |
+
|
273 |
+
Another way we used pre-trained vector representations was by use of a Longformer (Beltagy et al., 2020). We chose it because
|
274 |
+
of the limitation of the first generation of transformers and BERT-based architectures involving the size of the sentences:
|
275 |
+
the maximum of 512 tokens. The reason behind that limitation is that the self-attention mechanism scale quadratically with the
|
276 |
+
input sequence length O(n2) (Beltagy et al., 2020). The Longformer allowed the processing sequences of a thousand characters
|
277 |
+
without facing the memory bottleneck of BERT-like architectures and achieved SOTA in several benchmarks.
|
278 |
+
|
279 |
+
For our text length distribution in Figure 3, if we used a Bert-based architecture with a maximum length of 512, 99 sentences
|
280 |
+
would have to be truncated and probably miss some critical information. By comparison, with the Longformer, with a maximum
|
281 |
+
length of 4096, only eight sentences will have their information shortened.
|
282 |
+
|
283 |
+
To apply the Longformer, we used the pre-trained base (available on the link) that was previously trained with a combination
|
284 |
+
of vast datasets as input to the model, as shown in figure 5 under Longformer model training. After coupling to our classification
|
285 |
+
models, we realized supervised training of the whole model. At this point, only transfer learning was applied since more
|
286 |
+
computational power was needed to realize the fine-tuning of the weights. The results with related metrics can be viewed in table 4.
|
287 |
+
This approach achieved adequate accuracy scores, above 82% in all implementation architectures.
|
288 |
+
|
289 |
+
|
290 |
+
Table 2: Results from Pre-trained Longformer + ML models.
|
291 |
+
|
292 |
+
| ML Model | Accuracy | F1 Score | Precision | Recall |
|
293 |
+
|:--------:|:---------:|:---------:|:---------:|:---------:|
|
294 |
+
| NN | 0.8269 | 0.8754 |0.7950 | 0.9773 |
|
295 |
+
| DNN | 0.8462 | 0.8776 |0.8474 | 0.9123 |
|
296 |
+
| CNN | 0.8462 | 0.8776 |0.8474 | 0.9123 |
|
297 |
+
| LSTM | 0.8269 | 0.8801 |0.8571 | 0.9091 |
|
298 |
+
|
299 |
+
|
300 |
+
## Checkpoints
|
301 |
+
- Examples
|
302 |
+
- Implementation Notes
|
303 |
+
- Usage Example
|
304 |
+
- >>>
|
305 |
+
- >>> ...
|
306 |
+
|
307 |
+
|
308 |
+
## Config
|
309 |
+
|
310 |
+
## Tokenizer
|
311 |
+
|
312 |
+
## Training data
|
313 |
+
|
314 |
+
## Training procedure
|
315 |
+
|
316 |
+
## Preprocessing
|
317 |
+
|
318 |
+
## Pretraining
|
319 |
+
|
320 |
+
## Evaluation results
|
321 |
+
## Benchmarks
|
322 |
+
|
323 |
+
### BibTeX entry and citation info
|
324 |
+
|
325 |
+
```bibtex
|
326 |
+
@conference{webist22,
|
327 |
+
author ={Carlos Rocha. and Marcos Dib. and Li Weigang. and Andrea Nunes. and Allan Faria. and Daniel Cajueiro.
|
328 |
+
and Maísa {Kely de Melo}. and Victor Celestino.},
|
329 |
+
title ={Using Transfer Learning To Classify Long Unstructured Texts with Small Amounts of Labeled Data},
|
330 |
+
booktitle ={Proceedings of the 18th International Conference on Web Information Systems and Technologies - WEBIST,},
|
331 |
+
year ={2022},
|
332 |
+
pages ={201-213},
|
333 |
+
publisher ={SciTePress},
|
334 |
+
organization ={INSTICC},
|
335 |
+
doi ={10.5220/0011527700003318},
|
336 |
+
isbn ={978-989-758-613-2},
|
337 |
+
issn ={2184-3252},
|
338 |
+
}
|
339 |
+
```
|
340 |
+
|
341 |
+
<a href="https://huggingface.co/exbert/?model=bert-base-uncased">
|
342 |
+
<img width="300px" src="https://cdn-media.huggingface.co/exbert/button.png">
|
343 |
+
</a>
|