VytasM commited on
Commit
d5ed54a
·
verified ·
1 Parent(s): dbea5f8

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +317 -113
README.md CHANGED
@@ -3,207 +3,411 @@ base_model: google/gemma-3-12b-it
3
  library_name: peft
4
  pipeline_tag: text-generation
5
  tags:
6
- - base_model:adapter:google/gemma-3-12b-it
7
- - lora
8
- - sft
9
- - transformers
10
- - trl
11
  ---
12
 
13
- # Model Card for Model ID
14
 
15
- <!-- Provide a quick summary of what the model is/does. -->
16
 
 
17
 
 
18
 
19
- ## Model Details
20
-
21
- ### Model Description
22
-
23
- <!-- Provide a longer summary of what this model is. -->
24
-
25
-
26
-
27
- - **Developed by:** [More Information Needed]
28
- - **Funded by [optional]:** [More Information Needed]
29
- - **Shared by [optional]:** [More Information Needed]
30
- - **Model type:** [More Information Needed]
31
- - **Language(s) (NLP):** [More Information Needed]
32
- - **License:** [More Information Needed]
33
- - **Finetuned from model [optional]:** [More Information Needed]
34
-
35
- ### Model Sources [optional]
36
-
37
- <!-- Provide the basic links for the model. -->
38
 
39
- - **Repository:** [More Information Needed]
40
- - **Paper [optional]:** [More Information Needed]
41
- - **Demo [optional]:** [More Information Needed]
42
 
43
- ## Uses
44
 
45
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
 
 
 
 
46
 
47
- ### Direct Use
48
 
49
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
50
 
51
- [More Information Needed]
 
 
 
 
 
 
 
 
 
52
 
53
- ### Downstream Use [optional]
54
 
55
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
56
 
57
- [More Information Needed]
58
 
59
- ### Out-of-Scope Use
60
 
61
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
 
62
 
63
- [More Information Needed]
64
 
65
- ## Bias, Risks, and Limitations
66
 
67
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
 
 
 
68
 
69
- [More Information Needed]
70
 
71
- ### Recommendations
72
 
73
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
 
 
 
 
 
 
 
 
 
 
74
 
75
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
76
 
77
- ## How to Get Started with the Model
78
 
79
- Use the code below to get started with the model.
80
 
81
- [More Information Needed]
82
 
83
- ## Training Details
 
 
84
 
85
- ### Training Data
86
 
87
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
88
 
89
- [More Information Needed]
90
 
91
- ### Training Procedure
92
 
93
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
 
 
94
 
95
- #### Preprocessing [optional]
96
 
97
- [More Information Needed]
 
 
 
 
 
98
 
 
99
 
100
- #### Training Hyperparameters
 
 
 
 
101
 
102
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
103
 
104
- #### Speeds, Sizes, Times [optional]
105
 
106
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
107
 
108
- [More Information Needed]
 
 
109
 
110
- ## Evaluation
111
 
112
- <!-- This section describes the evaluation protocols and provides the results. -->
 
 
113
 
114
- ### Testing Data, Factors & Metrics
115
 
116
- #### Testing Data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
- <!-- This should link to a Dataset Card if possible. -->
119
 
120
- [More Information Needed]
121
 
122
- #### Factors
123
 
124
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
125
 
126
- [More Information Needed]
127
 
128
- #### Metrics
 
 
 
 
129
 
130
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
131
 
132
- [More Information Needed]
133
 
134
- ### Results
 
 
 
 
 
 
 
 
 
135
 
136
- [More Information Needed]
137
 
138
- #### Summary
139
 
 
140
 
 
141
 
142
- ## Model Examination [optional]
 
 
143
 
144
- <!-- Relevant interpretability work for the model goes here -->
145
 
146
- [More Information Needed]
147
 
148
- ## Environmental Impact
 
 
 
 
149
 
150
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
151
 
152
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
153
 
154
- - **Hardware Type:** [More Information Needed]
155
- - **Hours used:** [More Information Needed]
156
- - **Cloud Provider:** [More Information Needed]
157
- - **Compute Region:** [More Information Needed]
158
- - **Carbon Emitted:** [More Information Needed]
 
 
 
 
 
 
159
 
160
- ## Technical Specifications [optional]
161
 
162
- ### Model Architecture and Objective
163
 
164
- [More Information Needed]
165
 
166
- ### Compute Infrastructure
167
 
168
- [More Information Needed]
 
 
169
 
170
- #### Hardware
171
 
172
- [More Information Needed]
173
 
174
- #### Software
175
 
176
- [More Information Needed]
177
 
178
- ## Citation [optional]
 
 
 
 
179
 
180
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
181
 
182
- **BibTeX:**
 
 
 
 
 
183
 
184
- [More Information Needed]
185
 
186
- **APA:**
 
 
 
 
187
 
188
- [More Information Needed]
189
 
190
- ## Glossary [optional]
191
 
192
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
193
 
194
- [More Information Needed]
 
 
195
 
196
- ## More Information [optional]
197
 
198
- [More Information Needed]
 
 
199
 
200
- ## Model Card Authors [optional]
201
 
202
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
- ## Model Card Contact
205
 
206
- [More Information Needed]
207
  ### Framework versions
208
 
209
- - PEFT 0.18.1
 
3
  library_name: peft
4
  pipeline_tag: text-generation
5
  tags:
6
+ - base_model:adapter:google/gemma-3-12b-it
7
+ - lora
8
+ - sft
9
+ - transformers
10
+ - trl
11
  ---
12
 
13
+ # Gemma3-MIAITS-Adapter
14
 
15
+ **EN** | [LT](#lt-lietuvių)
16
 
17
+ ---
18
 
19
+ ## EN: English
20
 
21
+ ### Overview
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ **Gemma3-MIAITS-Adapter** is a LoRA adapter fine-tuned on top of [`google/gemma-3-12b-it`](https://huggingface.co/google/gemma-3-12b-it) for Lithuanian-language misinformation classification, developed as part of the **MIAITS** project (_Melagingos informacijos automatinio identifikavimo tekstyno sukūrimas_ - Lithuanian Misinformation Automatic Identification Text Corpus).
 
 
24
 
25
+ The model classifies Lithuanian news articles and statements into three categories:
26
 
27
+ | Label | Meaning |
28
+ | --------------- | --------------------------------- |
29
+ | `Klaidinga` | False / Fake information |
30
+ | `Manipuliatyvu` | Manipulative / Misleading content |
31
+ | `Teisinga` | True / Correct information |
32
 
33
+ ---
34
 
35
+ ### Architecture
36
 
37
+ - **Base model**: [`google/gemma-3-12b-it`](https://huggingface.co/google/gemma-3-12b-it) - Gemma 3 12B instruction-tuned
38
+ - **Adapter type**: LoRA (PEFT) via QLoRA (4-bit NF4)
39
+ - **Task**: Causal language modelling (text generation) - classification via generated JSON response
40
+ - **LoRA rank (r)**: 32
41
+ - **LoRA alpha**: 64
42
+ - **LoRA dropout**: 0.1
43
+ - **Target modules**: `q_proj`, `v_proj` (attention only)
44
+ - **Bias**: none
45
+ - **Quantization**: 4-bit NF4, compute dtype bfloat16, double quantization enabled
46
+ - **PEFT version**: 0.18.1
47
 
48
+ ---
49
 
50
+ ### Training Data
51
 
52
+ **Source**: Lithuanian misinformation classification dataset.
53
 
54
+ **Labels** (3-class):
55
 
56
+ - `Klaidinga` - False
57
+ - `Manipuliatyvu` - Manipulative
58
+ - `Teisinga` - True
59
 
60
+ **Text columns**: Each original row was expanded into 3 rows using `7-Statement`, `8-Statement_Context`, and `9-Full_text`. Validation and test sets use `9-Full_text` only.
61
 
62
+ **Splits**: Stratified 80/10/10.
63
 
64
+ | Split | Rows |
65
+ | ----- | ------ |
66
+ | Train | 11,976 |
67
+ | Val | 499 |
68
+ | Test | 499 |
69
 
70
+ ---
71
 
72
+ ### Training Hyperparameters
73
 
74
+ | Parameter | Value |
75
+ | --------------------- | --------------------------- |
76
+ | Learning rate | 2e-5 |
77
+ | Scheduler | Cosine (10% warmup) |
78
+ | Weight decay | 0.05 |
79
+ | Epochs | 3 (early stopping patience 2) |
80
+ | Batch size | 1 |
81
+ | Gradient accumulation | 32 (effective batch = 32) |
82
+ | Max sequence length | 4,096 |
83
+ | Precision | BF16 |
84
+ | Max new tokens (eval) | 512 |
85
 
86
+ **Selected checkpoint**: epoch 1 (best eval_loss). Runtime: ~11.6h.
87
 
88
+ ---
89
 
90
+ ### Prompt Format
91
 
92
+ The system prompt instructs the model (in Lithuanian) to classify the text and respond in JSON:
93
 
94
+ ```json
95
+ {"label": "<label>", "justification": "<1-sentence explanation>"}
96
+ ```
97
 
98
+ Ground truth justifications from the `17-Justification` column of the source data were used as assistant responses during training.
99
 
100
+ ---
101
 
102
+ ### Performance
103
 
104
+ Evaluated on the MIAITS test set (499 rows, 3 classes). Best checkpoint: epoch 1 (by eval_loss).
105
 
106
+ | Metric | Val | Test |
107
+ | ------------------ | ------ | ------ |
108
+ | Accuracy | 67.1% | 68.0% |
109
+ | Macro F1 | 0.647 | 0.662 |
110
+ | JSON parse failures | 2.4% | 1.8% |
111
 
112
+ **Epoch progression**:
113
 
114
+ | Epoch | Val Acc | Val Macro F1 | Test Acc | Test Macro F1 |
115
+ | -------- | ------- | ------------ | -------- | ------------- |
116
+ | 0 (base) | 42.3% | 0.384 | 41.6% | 0.399 |
117
+ | 1 | 65.3% | 0.610 | 66.0% | 0.641 |
118
+ | 2 | 66.7% | 0.643 | 68.2% | 0.668 |
119
+ | 3 | 66.9% | 0.642 | 68.2% | 0.667 |
120
 
121
+ **Per-class metrics (Test)**:
122
 
123
+ | Class | Precision | Recall | F1 |
124
+ | ------------- | --------- | ------ | ----- |
125
+ | Klaidinga | 0.637 | 0.717 | 0.675 |
126
+ | Manipuliatyvu | 0.514 | 0.400 | 0.450 |
127
+ | Teisinga | 0.843 | 0.881 | 0.862 |
128
 
129
+ > **Note:** `Manipuliatyvu` is the hardest class (F1 0.450). `Teisinga` is the easiest (F1 0.862). ~2% of outputs failed JSON parsing.
130
 
131
+ ---
132
 
133
+ ### Intended Use
134
 
135
+ - Secondary signal in an ensemble alongside ModernBERT
136
+ - Text normalization pre-processing (restoring perturbed Lithuanian text before classification)
137
+ - Research on generative LLMs for Baltic/Eastern European misinformation detection
138
 
139
+ ### Limitations
140
 
141
+ - Trained exclusively on Lithuanian-language data; not suitable for other languages
142
+ - `Manipuliatyvu` class has notably low recall (0.400)
143
+ - Produces occasional JSON parse failures (~2%)
144
 
145
+ ---
146
 
147
+ ### Usage
148
+
149
+ **Hardware requirements:**
150
+
151
+ - bfloat16 (default): ~24 GB VRAM
152
+ - 4-bit quantization (`--load-in-4bit`): ~8-10 GB VRAM (recommended for consumer GPUs)
153
+
154
+ ```python
155
+ import torch
156
+ from peft import PeftModel
157
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
158
+
159
+ BASE_MODEL = "google/gemma-3-12b-it"
160
+ ADAPTER_PATH = "VSSA-SDSA/LT_AI_FakeNews_LLM"
161
+
162
+ # Optional: 4-bit quantization to reduce VRAM usage
163
+ quantization_config = BitsAndBytesConfig(
164
+ load_in_4bit=True,
165
+ bnb_4bit_compute_dtype=torch.bfloat16,
166
+ bnb_4bit_use_double_quant=True,
167
+ bnb_4bit_quant_type="nf4",
168
+ )
169
+
170
+ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
171
+
172
+ base_model = AutoModelForCausalLM.from_pretrained(
173
+ BASE_MODEL,
174
+ quantization_config=quantization_config, # remove for full bfloat16
175
+ device_map="auto",
176
+ )
177
+
178
+ model = PeftModel.from_pretrained(base_model, ADAPTER_PATH)
179
+ model.eval()
180
+
181
+
182
+ def classify(text: str, max_new_tokens: int = 512) -> dict:
183
+ messages = [
184
+ {
185
+ "role": "system",
186
+ "content": (
187
+ "Esi lietuviškos žiniasklaidos analizės įrankis. "
188
+ "Klasifikuok pateiktą tekstą į vieną iš trijų kategorijų: "
189
+ "Klaidinga, Manipuliatyvu, Teisinga. "
190
+ 'Atsakyk JSON formatu: {"label": "<kategorija>", "justification": "<vienas sakinys>"}'
191
+ ),
192
+ },
193
+ {"role": "user", "content": text},
194
+ ]
195
+ inputs = tokenizer.apply_chat_template(
196
+ messages, return_tensors="pt", add_generation_prompt=True
197
+ ).to(model.device)
198
+ with torch.inference_mode():
199
+ output_ids = model.generate(
200
+ inputs,
201
+ max_new_tokens=max_new_tokens,
202
+ do_sample=False,
203
+ repetition_penalty=1.1,
204
+ )
205
+ new_tokens = output_ids[0][inputs.shape[1]:]
206
+ return tokenizer.decode(new_tokens, skip_special_tokens=True)
207
+
208
+
209
+ text = "Mokslininkai įrodė, kad žemė yra plokščia ir NASA slepia tiesą."
210
+ print(classify(text))
211
+ ```
212
 
213
+ ---
214
 
215
+ ## LT: Lietuvių
216
 
217
+ ### Apžvalga
218
 
219
+ **Gemma3-MIAITS-Adapter** - tai LoRA adapteris, suderintas ant [`google/gemma-3-12b-it`](https://huggingface.co/google/gemma-3-12b-it) pagrindu lietuviškos dezinformacijos klasifikavimui, sukurtas **MIAITS** projekto (_Melagingos informacijos automatinio identifikavimo tekstyno sukūrimas_) rėmuose.
220
 
221
+ Modelis klasifikuoja lietuviškus naujienų straipsnius ir teiginius į tris kategorijas:
222
 
223
+ | Žyma | Reikšmė |
224
+ | --------------- | --------------------------------------- |
225
+ | `Klaidinga` | Klaidinga / melaginga informacija |
226
+ | `Manipuliatyvu` | Manipuliatyvi / klaidinanti informacija |
227
+ | `Teisinga` | Teisinga informacija |
228
 
229
+ ---
230
 
231
+ ### Architektūra
232
 
233
+ - **Bazinis modelis**: [`google/gemma-3-12b-it`](https://huggingface.co/google/gemma-3-12b-it) - Gemma 3 12B instrukcinė versija
234
+ - **Adapterio tipas**: LoRA (PEFT) per QLoRA (4 bitų NF4)
235
+ - **Užduotis**: Priežastinis kalbos modeliavimas (teksto generavimas) - klasifikavimas per sugeneruotą JSON atsakymą
236
+ - **LoRA rangas (r)**: 32
237
+ - **LoRA alpha**: 64
238
+ - **LoRA dropout**: 0,1
239
+ - **Tiksliniai moduliai**: `q_proj`, `v_proj` (tik dėmesio sluoksniai)
240
+ - **Bias**: nėra
241
+ - **Kvantizacija**: 4 bitų NF4, skaičiavimo tipas bfloat16, dviguba kvantizacija įjungta
242
+ - **PEFT versija**: 0.18.1
243
 
244
+ ---
245
 
246
+ ### Mokymo duomenys
247
 
248
+ **Šaltinis**: Lietuviškos dezinformacijos klasifikavimo duomenų rinkinys.
249
 
250
+ **Žymos** (3 klasės):
251
 
252
+ - `Klaidinga` - Klaidinga
253
+ - `Manipuliatyvu` - Manipuliatyvu
254
+ - `Teisinga` - Teisinga
255
 
256
+ **Teksto stulpeliai**: Kiekviena originali eilutė buvo išplėsta į 3 eilutes naudojant `7-Statement`, `8-Statement_Context` ir `9-Full_text`. Validavimo ir testavimo rinkiniai naudoja tik `9-Full_text`.
257
 
258
+ **Padalijimas**: Stratifikuotas 80/10/10.
259
 
260
+ | Rinkinys | Eilutės |
261
+ | ----------- | ------- |
262
+ | Mokymas | 11 976 |
263
+ | Validavimas | 499 |
264
+ | Testavimas | 499 |
265
 
266
+ ---
267
 
268
+ ### Mokymo hiperparametrai
269
 
270
+ | Parametras | Reikšmė |
271
+ | --------------------- | --------------------------------- |
272
+ | Mokymosi greitis | 2e-5 |
273
+ | Planuoklis | Kosinusinis (10 % apšilimas) |
274
+ | Svorių atitolimas | 0,05 |
275
+ | Epochos | 3 (ankstyvas stabdymas, kantryb. 2) |
276
+ | Paketų dydis | 1 |
277
+ | Gradiento kaupimas | 32 (efektyvus paketas = 32) |
278
+ | Maks. sekos ilgis | 4 096 |
279
+ | Tikslumas | BF16 |
280
+ | Maks. naujų žetonų (eval) | 512 |
281
 
282
+ **Pasirinktas kontrolinis taškas**: 1 epocha (geriausias eval_loss). Trukmė: ~11,6 val.
283
 
284
+ ---
285
 
286
+ ### Užklausos formatas
287
 
288
+ Sistemos užklausa nurodo modeliui (lietuvių kalba) klasifikuoti tekstą ir atsakyti JSON formatu:
289
 
290
+ ```json
291
+ {"label": "<žyma>", "justification": "<vienas sakinys>"}
292
+ ```
293
 
294
+ Mokymo metu kaip asistentu atsakymai naudoti tikrojo šaltinio pagrindinimai iš `17-Justification` stulpelio.
295
 
296
+ ---
297
 
298
+ ### Rezultatai
299
 
300
+ Įvertinta su MIAITS testavimo rinkiniu (499 eilutės, 3 klasės). Geriausias kontrolinis taškas: 1 epocha (pagal eval_loss).
301
 
302
+ | Metrika | Validavimas | Testavimas |
303
+ | ---------------------- | ----------- | ---------- |
304
+ | Tikslumas | 67,1 % | 68,0 % |
305
+ | Makro F1 | 0,647 | 0,662 |
306
+ | JSON apdorojimo klaidos | 2,4 % | 1,8 % |
307
 
308
+ **Epochų progresija**:
309
 
310
+ | Epocha | Val. tiksl. | Val. makro F1 | Test. tiksl. | Test. makro F1 |
311
+ | ----------- | ----------- | ------------- | ------------ | -------------- |
312
+ | 0 (bazinis) | 42,3 % | 0,384 | 41,6 % | 0,399 |
313
+ | 1 | 65,3 % | 0,610 | 66,0 % | 0,641 |
314
+ | 2 | 66,7 % | 0,643 | 68,2 % | 0,668 |
315
+ | 3 | 66,9 % | 0,642 | 68,2 % | 0,667 |
316
 
317
+ **Tikslumas pagal klasę (testavimas)**:
318
 
319
+ | Klasė | Tikslumas | Atkūrimas | F1 |
320
+ | ------------- | --------- | --------- | ----- |
321
+ | Klaidinga | 0,637 | 0,717 | 0,675 |
322
+ | Manipuliatyvu | 0,514 | 0,400 | 0,450 |
323
+ | Teisinga | 0,843 | 0,881 | 0,862 |
324
 
325
+ > **Pastaba:** `Manipuliatyvu` yra sunkiausia klasė (F1 0,450). `Teisinga` lengviausia (F1 0,862). ~2 % išvesties nepavyko apdoroti JSON formatu.
326
 
327
+ ---
328
 
329
+ ### Numatytas naudojimas
330
 
331
+ - Papildomas signalas ansamblyje kartu su ModernBERT
332
+ - Teksto normalizavimo išankstinis apdorojimas (sugadintų lietuviškų tekstų atstatymas prieš klasifikavimą)
333
+ - Generatyviųjų kalbos modelių dezinformacijos aptikimo tyrimai Baltijos ir Rytų Europos regione
334
 
335
+ ### Apribojimai
336
 
337
+ - Modelis apmokytas išimtinai lietuviškais duomenimis; kitoms kalboms netinka
338
+ - `Manipuliatyvu` klasės atkūrimas ypač žemas (0,400)
339
+ - Kartais nepavyksta apdoroti JSON išvesties (~2 %)
340
 
341
+ ---
342
 
343
+ ### Naudojimas
344
+
345
+ **Aparatūros reikalavimai:**
346
+
347
+ - bfloat16 (numatytasis): ~24 GB VRAM
348
+ - 4 bitų kvantizacija: ~8-10 GB VRAM (rekomenduojama vartotojų GPU)
349
+
350
+ ```python
351
+ import torch
352
+ from peft import PeftModel
353
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
354
+
355
+ BASE_MODEL = "google/gemma-3-12b-it"
356
+ ADAPTER_PATH = "VSSA-SDSA/LT_AI_FakeNews_LLM"
357
+
358
+ # Neprivaloma: 4 bitų kvantizacija, siekiant sumažinti VRAM naudojimą
359
+ quantization_config = BitsAndBytesConfig(
360
+ load_in_4bit=True,
361
+ bnb_4bit_compute_dtype=torch.bfloat16,
362
+ bnb_4bit_use_double_quant=True,
363
+ bnb_4bit_quant_type="nf4",
364
+ )
365
+
366
+ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
367
+
368
+ base_model = AutoModelForCausalLM.from_pretrained(
369
+ BASE_MODEL,
370
+ quantization_config=quantization_config, # pašalinti norint naudoti visą bfloat16
371
+ device_map="auto",
372
+ )
373
+
374
+ model = PeftModel.from_pretrained(base_model, ADAPTER_PATH)
375
+ model.eval()
376
+
377
+
378
+ def classify(text: str, max_new_tokens: int = 512) -> str:
379
+ messages = [
380
+ {
381
+ "role": "system",
382
+ "content": (
383
+ "Esi lietuviškos žiniasklaidos analizės įrankis. "
384
+ "Klasifikuok pateiktą tekstą į vieną iš trijų kategorijų: "
385
+ "Klaidinga, Manipuliatyvu, Teisinga. "
386
+ 'Atsakyk JSON formatu: {"label": "<kategorija>", "justification": "<vienas sakinys>"}'
387
+ ),
388
+ },
389
+ {"role": "user", "content": text},
390
+ ]
391
+ inputs = tokenizer.apply_chat_template(
392
+ messages, return_tensors="pt", add_generation_prompt=True
393
+ ).to(model.device)
394
+ with torch.inference_mode():
395
+ output_ids = model.generate(
396
+ inputs,
397
+ max_new_tokens=max_new_tokens,
398
+ do_sample=False,
399
+ repetition_penalty=1.1,
400
+ )
401
+ new_tokens = output_ids[0][inputs.shape[1]:]
402
+ return tokenizer.decode(new_tokens, skip_special_tokens=True)
403
+
404
+
405
+ text = "Mokslininkai įrodė, kad žemė yra plokščia ir NASA slepia tiesą."
406
+ print(classify(text))
407
+ ```
408
 
409
+ ---
410
 
 
411
  ### Framework versions
412
 
413
+ - PEFT 0.18.1