Ihor commited on
Commit
c67d6cc
1 Parent(s): 4f04909

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +208 -0
README.md CHANGED
@@ -1,3 +1,211 @@
1
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - multilingual
4
+ - af
5
+ - am
6
+ - ar
7
+ - az
8
+ - be
9
+ - bg
10
+ - bn
11
+ - ca
12
+ - ceb
13
+ - co
14
+ - cs
15
+ - cy
16
+ - da
17
+ - de
18
+ - el
19
+ - en
20
+ - eo
21
+ - es
22
+ - et
23
+ - eu
24
+ - fa
25
+ - fi
26
+ - fil
27
+ - fr
28
+ - fy
29
+ - ga
30
+ - gd
31
+ - gl
32
+ - gu
33
+ - ha
34
+ - haw
35
+ - hi
36
+ - hmn
37
+ - ht
38
+ - hu
39
+ - hy
40
+ - ig
41
+ - is
42
+ - it
43
+ - iw
44
+ - ja
45
+ - jv
46
+ - ka
47
+ - kk
48
+ - km
49
+ - kn
50
+ - ko
51
+ - ku
52
+ - ky
53
+ - la
54
+ - lb
55
+ - lo
56
+ - lt
57
+ - lv
58
+ - mg
59
+ - mi
60
+ - mk
61
+ - ml
62
+ - mn
63
+ - mr
64
+ - ms
65
+ - mt
66
+ - my
67
+ - ne
68
+ - nl
69
+ - no
70
+ - ny
71
+ - pa
72
+ - pl
73
+ - ps
74
+ - pt
75
+ - ro
76
+ - ru
77
+ - sd
78
+ - si
79
+ - sk
80
+ - sl
81
+ - sm
82
+ - sn
83
+ - so
84
+ - sq
85
+ - sr
86
+ - st
87
+ - su
88
+ - sv
89
+ - sw
90
+ - ta
91
+ - te
92
+ - tg
93
+ - th
94
+ - tr
95
+ - uk
96
+ - und
97
+ - ur
98
+ - uz
99
+ - vi
100
+ - xh
101
+ - yi
102
+ - yo
103
+ - zh
104
+ - zu
105
  license: apache-2.0
106
+ datasets:
107
+ - multi_nli
108
+ - xnli
109
+ - dbpedia_14
110
+ - SetFit/bbc-news
111
+ - squad_v2
112
+ - race
113
+ - knowledgator/events_classification_biotech
114
+ - facebook/anli
115
+ - SetFit/qnli
116
+ metrics:
117
+ - accuracy
118
+ - f1
119
+ library_name: transformers
120
+ pipeline_tag: zero-shot-classification
121
+ tags:
122
+ - classification
123
+ - information-extraction
124
+ - zero-shot
125
  ---
126
+
127
+ **comprehend-it-multilang-base-base**
128
+
129
+ This is an encoder-decoder model based on [mT5-base](google/mt5-base) that was trained on multi-language natural language inference datasets as well as on multiple text classification datasets.
130
+
131
+ The model demonstrates a better contextual understanding of text and verbalized label because both inputs are encoded by different parts of a model - encoder and decoder respectively.
132
+
133
+ The zero-shot classifier supports nearly 100 languages and can work in both directions, meaning that labels and text can belong to different languages.
134
+
135
+ #### Install the neccessary libraries before using it
136
+ Because of the different model architecture, we can't use transformers' "zero-shot-classification" pipeline. For that, we developed a special library called [LiqFit](https://github.com/Knowledgator/LiqFit/tree/main).
137
+ If you haven't install sentencepiece library you need to install it as well to use T5 tokenizers.
138
+
139
+ ```bash
140
+ pip install liqfit sentencepiece
141
+ ```
142
+
143
+ #### With the LiqFit pipeline
144
+
145
+ The model can be loaded with the `zero-shot-classification` pipeline like so:
146
+
147
+ ```python
148
+ from liqfit.pipeline import ZeroShotClassificationPipeline
149
+ from liqfit.models import T5ForZeroShotClassification
150
+ from transformers import T5Tokenizer
151
+
152
+ model = T5ForZeroShotClassification.from_pretrained('knowledgator/comprehend-it-multilang-base')
153
+ tokenizer = T5Tokenizer.from_pretrained('knowledgator/comprehend-it-multilang-base')
154
+ classifier = ZeroShotClassificationPipeline(model=model, tokenizer=tokenizer,
155
+ hypothesis_template = '{}', encoder_decoder = True)
156
+ ```
157
+
158
+ You can then use this pipeline to classify sequences into any of the class names you specify.
159
+
160
+ ```python
161
+ sequence_to_classify = "one day I will see the world"
162
+ candidate_labels = ['travel', 'cooking', 'dancing']
163
+ classifier(sequence_to_classify, candidate_labels, multi_label=False)
164
+ {'sequence': 'one day I will see the world',
165
+ 'labels': ['travel', 'cooking', 'dancing'],
166
+ 'scores': [0.7350383996963501, 0.1484801471233368, 0.1164814680814743]}
167
+ ```
168
+
169
+ Amoung Enlish you can use the model for many other languages, such as Ukrainian:
170
+
171
+ ```python
172
+ sequence_to_classify = "Одного дня я побачу цей світ."
173
+ candidate_labels = ['подорож', 'кулінарія', 'танці']
174
+ classifier(sequence_to_classify, candidate_labels, multi_label=False)
175
+ {'sequence': 'Одного дня я побачу цей світ.',
176
+ 'labels': ['подорож', 'кулінарія', 'танці'],
177
+ 'scores': [0.6393420696258545, 0.2657214105129242, 0.09493650496006012]}
178
+ ```
179
+
180
+ The model works even if labels and text are different languages:
181
+ ```python
182
+ sequence_to_classify = "Одного дня я побачу цей світ"
183
+ candidate_labels = ['travel', 'cooking', 'dancing']
184
+ classifier(sequence_to_classify, candidate_labels, multi_label=False)
185
+ {'sequence': 'Одного дня я побачу цей світ',
186
+ 'labels': ['travel', 'cooking', 'dancing'],
187
+ 'scores': [0.7676175236701965, 0.15484870970249176, 0.07753374427556992]}
188
+ ```
189
+
190
+ ### Benchmarking
191
+ Below, you can see the F1 score on several text classification datasets. All tested models were not fine-tuned on those datasets and were tested in a zero-shot setting.
192
+ | Model | IMDB | AG_NEWS | Emotions |
193
+ |-----------------------------|------|---------|----------|
194
+ | [Bart-large-mnli (407 M)](https://huggingface.co/facebook/bart-large-mnli) | 0.89 | 0.6887 | 0.3765 |
195
+ | [Deberta-base-v3 (184 M)](https://huggingface.co/cross-encoder/nli-deberta-v3-base) | 0.85 | 0.6455 | 0.5095 |
196
+ | [Comprehendo (184M)](https://huggingface.co/knowledgator/comprehend_it-base) | 0.90 | 0.7982 | 0.5660 |
197
+ | [Comprehendo-multi-lang (390M)](https://huggingface.co/knowledgator/comprehend-it-multilang-base) | 0.88 | 0.8372 | - |
198
+ | SetFit [BAAI/bge-small-en-v1.5 (33.4M)](https://huggingface.co/BAAI/bge-small-en-v1.5) | 0.86 | 0.5636 | 0.5754 |
199
+
200
+ ### Future reading
201
+ Check our blogpost - ["The new milestone in zero-shot capabilities (it’s not Generative AI)."](https://medium.com/p/9b5a081fbf27), where we highlighted possible use-cases of the model and why next-token prediction is not the only way to achive amazing zero-shot capabilites.
202
+ While most of the AI industry is focused on generative AI and decoder-based models, we are committed to developing encoder-based models.
203
+ We aim to achieve the same level of generalization for such models as their decoder brothers. Encoders have several wonderful properties, such as bidirectional attention, and they are the best choice for many information extraction tasks in terms of efficiency and controllability.
204
+
205
+ ### Feedback
206
+ We value your input! Share your feedback and suggestions to help us improve our models.
207
+ Fill out the feedback [form](https://forms.gle/5CPFFuLzNWznjcpL7)
208
+
209
+ ### Join Our Discord
210
+ Connect with our community on Discord for news, support, and discussion about our models.
211
+ Join [Discord](https://discord.gg/dkyeAgs9DG)