nishan-chatterjee commited on
Commit
ebf6fa2
·
verified ·
1 Parent(s): 2763765

Add canonical HBS and Slovenian checkpoints

Browse files
README.md CHANGED
@@ -3,20 +3,148 @@ library_name: pytorch
3
  tags:
4
  - aspect-based-sentiment-analysis
5
  - south-slavic
 
6
  license: other
7
  ---
8
 
9
  # AspectBench BERTić / SloBERTa
10
 
11
- Private model-only checkpoints for HBS and Slovenian document-level
12
- aspect-based sentiment analysis. This repository contains 4/4
13
- language-mode checkpoint slots. Missing slots are documented in
14
- `availability.json`; they are not substituted with another model.
15
 
16
- Use the shared scripts from
17
- `nishan-chatterjee/aspect-based-sentiment-analysis`. Input articles must tag
18
- the target as `<aspect>...</aspect>`. Checkpoints contain model tensors only;
19
- optimizer, scheduler, and gradient-scaler state has been removed.
20
 
21
- Keep this repository private until all source-data and data-derived-weight
22
- permissions are confirmed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  tags:
4
  - aspect-based-sentiment-analysis
5
  - south-slavic
6
+ - text-classification
7
  license: other
8
  ---
9
 
10
  # AspectBench BERTić / SloBERTa
11
 
12
+ Model-only checkpoints for HBS and Slovenian document-level aspect-based
13
+ sentiment analysis. This repository contains 4/4 language-mode
14
+ checkpoint slots. It is used with the shared inference toolkit in
15
+ [`nishan-chatterjee/aspect-based-sentiment-analysis`](https://huggingface.co/nishan-chatterjee/aspect-based-sentiment-analysis).
16
 
17
+ ## Input format
 
 
 
18
 
19
+ Every article must mark the target span with literal tags, even when using an
20
+ unmasked checkpoint:
21
+
22
+ ```text
23
+ Kupci su pohvalili <aspect>Primer Grupa</aspect> zbog brze usluge.
24
+ ```
25
+
26
+ - `masked`: the tagged text is replaced with `[ASPECT]`; the model does not see
27
+ the target name.
28
+ - `unmasked`: the tags are removed and the model sees the target name.
29
+ - Gold `sentiment` is optional: `-1` = negative, `0` = neutral, `1` = positive.
30
+ It is reported in the result but never used to produce the prediction.
31
+
32
+ ## Available checkpoints
33
+
34
+ | Language | Mode | Status | Best validation Macro-F1 |
35
+ |---|---|---|---:|
36
+ | hbs | masked | Available | 0.9151 (run 1) |
37
+ | hbs | unmasked | Available | 0.9251 (run 0) |
38
+ | slovenian | masked | Available | 0.8545 (run 2) |
39
+ | slovenian | unmasked | Available | 0.8639 (run 2) |
40
+
41
+ `availability.json` contains the machine-readable selection record. A missing
42
+ checkpoint is never replaced with a checkpoint from another mode or run.
43
+
44
+ ## Getting started
45
+
46
+ Create the portable environment from the toolkit repository:
47
+
48
+ ```bash
49
+ conda env create -f environment.yml
50
+ conda activate aspectbench
51
+ ```
52
+
53
+ Or install the runtime packages in an existing environment:
54
+
55
+ ```bash
56
+ python -m pip install -U torch transformers accelerate huggingface-hub sentencepiece numpy spacy sentence-transformers
57
+ ```
58
+
59
+ Download the toolkit and this model repository into the expected directory
60
+ layout:
61
+
62
+ ```python
63
+ from pathlib import Path
64
+ from huggingface_hub import snapshot_download
65
+
66
+ ROOT = Path("huggingface")
67
+ snapshot_download(
68
+ repo_id="nishan-chatterjee/aspect-based-sentiment-analysis",
69
+ local_dir=ROOT,
70
+ )
71
+ snapshot_download(
72
+ repo_id="nishan-chatterjee/aspectbench-slavic-specific",
73
+ local_dir=ROOT / "models" / "slavic-specific",
74
+ )
75
+ ```
76
+
77
+ The model repository includes the tokenizer and configuration assets required
78
+ to reconstruct the architecture. No separate base-model cache is needed.
79
+
80
+ ## Python / Jupyter prediction
81
+
82
+ ```python
83
+ from pathlib import Path
84
+ import sys
85
+
86
+ ROOT = Path("huggingface").resolve()
87
+ sys.path.insert(0, str(ROOT / "scripts"))
88
+
89
+ from inference import InferenceEngine
90
+
91
+ engine = InferenceEngine(
92
+ model_name="slavic-specific",
93
+ language="hbs",
94
+ mode="masked",
95
+ model_root=ROOT / "models",
96
+ device="cuda", # use "cpu" when no GPU is available
97
+ )
98
+
99
+ prediction = engine.predict(
100
+ {
101
+ "article": "Kupci su pohvalili <aspect>Primer Grupa</aspect> zbog brze usluge.",
102
+ "sentiment": 1,
103
+ },
104
+ mc_passes=10,
105
+ )
106
+ prediction
107
+ ```
108
+
109
+ For a real batch, reuse the loaded engine:
110
+
111
+ ```python
112
+ records = [
113
+ {"article": "Kupci su pohvalili <aspect>Primer Grupa</aspect>.", "sentiment": 1},
114
+ {"article": "Pritužbe na <aspect>Drugi Sistem</aspect> nisu riješene.", "sentiment": -1},
115
+ ]
116
+ predictions = engine.predict_batch(records, batch_size=2, mc_passes=10)
117
+ ```
118
+
119
+ ## Command-line prediction
120
+
121
+ Run from the toolkit directory:
122
+
123
+ ```bash
124
+ python scripts/predict.py \
125
+ --model-name slavic-specific \
126
+ --language hbs \
127
+ --mode masked \
128
+ --model-root models \
129
+ --device cuda \
130
+ --mc-passes 10 \
131
+ --article 'Kupci su pohvalili <aspect>Primer Grupa</aspect> zbog brze usluge.' \
132
+ --sentiment 1
133
+ ```
134
+
135
+ ## Output fields
136
+
137
+ | Field | Meaning |
138
+ |---|---|
139
+ | `input_article` | Original article, including `<aspect>` tags. |
140
+ | `tagged_aspects` | Target strings extracted from the tags. |
141
+ | `aspect_used` | Target representation actually supplied to the model. |
142
+ | `gold_sentiment` | Optional user-supplied reference label. |
143
+ | `predicted_sentiment` | Predicted integer label: `-1`, `0`, or `1`. |
144
+ | `predicted_sentiment_name` | Human-readable class name. |
145
+ | `class_probabilities` | Probability assigned to every sentiment class. |
146
+ | `uncertainty_across_classes` | Entropy, confidence, probability margin, and—when MC dropout is enabled—mutual information and vote statistics. |
147
+ | `inference` | Device, MC-dropout flag, and checkpoint path. |
148
+
149
+ The `.pt` files contain model tensors only. Optimizer, scheduler, and
150
+ gradient-scaler state is excluded.
availability.json CHANGED
@@ -9,9 +9,10 @@
9
  "validation_macro_f1": 0.9151353276491324,
10
  "available": true,
11
  "unavailable_reason": null,
 
12
  "base_model": "classla/bcms-bertic",
13
  "weight_path": "slavic-specific/hbs/masked.pt",
14
- "status": "exported",
15
  "size": 442555219,
16
  "sha256": "09a5ef9aa704535145e35b52db88aa9fa4108ec71c8a669ddbb5575f27417b70",
17
  "tensor_count": 201,
@@ -25,9 +26,10 @@
25
  "validation_macro_f1": 0.9250658853407349,
26
  "available": true,
27
  "unavailable_reason": null,
 
28
  "base_model": "classla/bcms-bertic",
29
  "weight_path": "slavic-specific/hbs/unmasked.pt",
30
- "status": "exported",
31
  "size": 442558893,
32
  "sha256": "918c1fdad79ec5911ebde16b90a00651c9d7b0ab02dbff36005490c95586f3da",
33
  "tensor_count": 201,
@@ -41,9 +43,10 @@
41
  "validation_macro_f1": 0.8545257213567837,
42
  "available": true,
43
  "unavailable_reason": null,
 
44
  "base_model": "EMBEDDIA/sloberta",
45
  "weight_path": "slavic-specific/slovenian/masked.pt",
46
- "status": "exported",
47
  "size": 442573651,
48
  "sha256": "1f0c8b88ac36f4d4dfe34322e37f8c12bbc87ef842ca8142265ba60b6066668b",
49
  "tensor_count": 201,
@@ -57,9 +60,10 @@
57
  "validation_macro_f1": 0.8638678818708625,
58
  "available": true,
59
  "unavailable_reason": null,
 
60
  "base_model": "EMBEDDIA/sloberta",
61
  "weight_path": "slavic-specific/slovenian/unmasked.pt",
62
- "status": "exported",
63
  "size": 442577325,
64
  "sha256": "489572e0225aa8d9c58eb90dfb344c97cd5902b4342cfe1e99a893785651a8d6",
65
  "tensor_count": 201,
 
9
  "validation_macro_f1": 0.9151353276491324,
10
  "available": true,
11
  "unavailable_reason": null,
12
+ "expected_source_checkpoint": null,
13
  "base_model": "classla/bcms-bertic",
14
  "weight_path": "slavic-specific/hbs/masked.pt",
15
+ "status": "existing",
16
  "size": 442555219,
17
  "sha256": "09a5ef9aa704535145e35b52db88aa9fa4108ec71c8a669ddbb5575f27417b70",
18
  "tensor_count": 201,
 
26
  "validation_macro_f1": 0.9250658853407349,
27
  "available": true,
28
  "unavailable_reason": null,
29
+ "expected_source_checkpoint": null,
30
  "base_model": "classla/bcms-bertic",
31
  "weight_path": "slavic-specific/hbs/unmasked.pt",
32
+ "status": "existing",
33
  "size": 442558893,
34
  "sha256": "918c1fdad79ec5911ebde16b90a00651c9d7b0ab02dbff36005490c95586f3da",
35
  "tensor_count": 201,
 
43
  "validation_macro_f1": 0.8545257213567837,
44
  "available": true,
45
  "unavailable_reason": null,
46
+ "expected_source_checkpoint": null,
47
  "base_model": "EMBEDDIA/sloberta",
48
  "weight_path": "slavic-specific/slovenian/masked.pt",
49
+ "status": "existing",
50
  "size": 442573651,
51
  "sha256": "1f0c8b88ac36f4d4dfe34322e37f8c12bbc87ef842ca8142265ba60b6066668b",
52
  "tensor_count": 201,
 
60
  "validation_macro_f1": 0.8638678818708625,
61
  "available": true,
62
  "unavailable_reason": null,
63
+ "expected_source_checkpoint": null,
64
  "base_model": "EMBEDDIA/sloberta",
65
  "weight_path": "slavic-specific/slovenian/unmasked.pt",
66
+ "status": "existing",
67
  "size": 442577325,
68
  "sha256": "489572e0225aa8d9c58eb90dfb344c97cd5902b4342cfe1e99a893785651a8d6",
69
  "tensor_count": 201,
hbs/base_model/config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_cross_attention": false,
3
+ "architectures": [
4
+ "ElectraForPreTraining"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": null,
8
+ "classifier_dropout": null,
9
+ "embedding_size": 768,
10
+ "eos_token_id": null,
11
+ "hidden_act": "gelu",
12
+ "hidden_dropout_prob": 0.1,
13
+ "hidden_size": 768,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 3072,
16
+ "is_decoder": false,
17
+ "layer_norm_eps": 1e-12,
18
+ "max_position_embeddings": 512,
19
+ "model_type": "electra",
20
+ "num_attention_heads": 12,
21
+ "num_hidden_layers": 12,
22
+ "pad_token_id": 0,
23
+ "summary_activation": "gelu",
24
+ "summary_last_dropout": 0.1,
25
+ "summary_type": "first",
26
+ "summary_use_proj": true,
27
+ "tie_word_embeddings": true,
28
+ "transformers_version": "5.8.1",
29
+ "type_vocab_size": 2,
30
+ "use_cache": true,
31
+ "vocab_size": 32000
32
+ }
hbs/base_model/source.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": "slavic-specific",
3
+ "language": "hbs",
4
+ "upstream_base_model": "classla/bcms-bertic",
5
+ "purpose": "Tokenizer and architecture configuration for offline checkpoint reconstruction",
6
+ "contains_upstream_model_weights": false
7
+ }
hbs/base_model/tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"do_lower_case": false, "max_len": 512, "init_inputs": [], "strip_accents":false}
hbs/base_model/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
slovenian/base_model/config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_cross_attention": false,
3
+ "architectures": [
4
+ "CamembertForMaskedLM"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "eos_token_id": 2,
10
+ "gradient_checkpointing": false,
11
+ "hidden_act": "gelu",
12
+ "hidden_dropout_prob": 0.1,
13
+ "hidden_size": 768,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 3072,
16
+ "is_decoder": false,
17
+ "layer_norm_eps": 1e-05,
18
+ "max_position_embeddings": 514,
19
+ "model_type": "camembert",
20
+ "num_attention_heads": 12,
21
+ "num_hidden_layers": 12,
22
+ "pad_token_id": 1,
23
+ "tie_word_embeddings": true,
24
+ "transformers_version": "5.8.1",
25
+ "type_vocab_size": 1,
26
+ "use_cache": true,
27
+ "vocab_size": 32005
28
+ }
slovenian/base_model/source.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": "slavic-specific",
3
+ "language": "slovenian",
4
+ "upstream_base_model": "EMBEDDIA/sloberta",
5
+ "purpose": "Tokenizer and architecture configuration for offline checkpoint reconstruction",
6
+ "contains_upstream_model_weights": false
7
+ }
slovenian/base_model/special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": true}, "additional_special_tokens": ["<s>NOTUSED", "</s>NOTUSED"]}
slovenian/base_model/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
slovenian/base_model/tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": "<s>", "eos_token": "</s>", "sep_token": "</s>", "cls_token": "<s>", "unk_token": "<unk>", "pad_token": "<pad>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "additional_special_tokens": ["<s>NOTUSED", "</s>NOTUSED"], "special_tokens_map_file": null, "name_or_path": "EMBEDDIA/sloberta", "sp_model_kwargs": {}, "tokenizer_class": "CamembertTokenizer", "model_max_length": 512, "do_lower_case": false}