ychuai commited on
Commit
cec807d
·
verified ·
1 Parent(s): 2358b2d
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,102 @@
1
  ---
2
  license: cc-by-4.0
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-4.0
3
+ library_name: transformers
4
+ pipeline_tag: text-classification
5
+ base_model: Twitter/twhin-bert-base
6
+ tags:
7
+ - multilingual
8
+ - multi-label-classification
9
+ - community-notes
10
+ - topic-classification
11
+ metrics:
12
+ - f1
13
  ---
14
+
15
+ # Multilingual Community Notes topic classifier
16
+
17
+ TwHIN-BERT fine-tuned to assign zero or more of ten topics to a post and its associated Community Note summaries. The unit of classification is the combined post record, not an individual note.
18
+
19
+ ## Labels
20
+
21
+ Politics and Elections; War and Geopolitics; Health and Medicine; Economy and Finance; Technology and AI; Crime and Public Safety; Sports and Games; Celebrity and Entertainment; Religion and Spirituality; Gender and Identity.
22
+
23
+ ## Inputs and inference
24
+
25
+ Input format:
26
+
27
+ ```text
28
+ Original post:
29
+ The original post text
30
+
31
+ Community Note 1:
32
+ First summary
33
+
34
+ Community Note 2:
35
+ Second summary
36
+ ```
37
+
38
+ Use summaries alone when the original post is unavailable, or post text alone when summaries are unavailable. Duplicate nonempty summary texts are included once. Input order should match the prepared record.
39
+
40
+ Long inputs are split into overlapping windows of 512 tokens with a 64-token stride. For each topic, take the maximum logit over all windows, then apply sigmoid. Scores ≥0.5 are selected independently. All settings are in `topic_config.json`.
41
+
42
+ **A standard text-classification pipeline that truncates to one window does not reproduce this model's full document inference.** Use the included script to preserve pooling:
43
+
44
+ ```bash
45
+ pip install -r requirements.txt
46
+ python predict_topics.py --post "A new vaccine study was published." --note "The study was conducted in adults."
47
+ ```
48
+
49
+ To download from Hugging Face, substitute this repository's ID:
50
+
51
+ ```python
52
+ from huggingface_hub import snapshot_download
53
+ path = snapshot_download("YOUR_USERNAME/YOUR_MODEL_NAME")
54
+ # Run the downloaded predict_topics.py, or import TopicPredictor from it.
55
+ ```
56
+
57
+ The weights also load with `AutoModelForSequenceClassification.from_pretrained(...)`; the tokenizer loads with `AutoTokenizer.from_pretrained(...)`. The included helper takes a local downloaded directory and defaults to CPU. No OpenAI API key is needed for inference.
58
+
59
+ ## Training and evaluation
60
+
61
+ Base model: [Twitter/twhin-bert-base](https://huggingface.co/Twitter/twhin-bert-base).
62
+
63
+ Training inputs combine original post text with all associated nonempty note summaries. The pipeline obtains multi-label annotations from `gpt-5.4-mini`, deduplicates identical combined inputs, and uses an 85%/15% training/validation split. Window logits are max-pooled before a post-level binary cross-entropy loss. The saved evaluation was recorded at epoch 5.
64
+
65
+ | Held-out metric | Value |
66
+ |---|---:|
67
+ | Micro F1 | 0.831219 |
68
+ | Macro F1 | 0.809377 |
69
+ | Samples F1 | 0.761806 |
70
+ | Evaluation loss | 0.187633 |
71
+
72
+ These metrics measure agreement with held-out **GPT-generated labels**, not independently verified human ground truth. The exact original training invocation and sample size are not recorded in this export. Metrics are copied from the saved validation artifact.
73
+
74
+ ## Intended use and limitations
75
+
76
+ Research topic annotation of multilingual posts and summaries. Topic predictions do not determine whether a statement is true or a note is Helpful. Multiple categories or no category can be selected. Language-specific performance has not been established by the saved evaluation. Domain shifts, synthetic-label bias, classification errors, and window max-pooling can affect predictions.
77
+
78
+ Combined summaries can include information added after the original post. These predictions are snapshot labels, not historical annotations. The model package contains weights, configuration, tokenizer, inference code, and aggregate metrics; the source corpus and annotation records are not bundled.
79
+
80
+ ## License
81
+
82
+ This fine-tuned model is released under the Creative Commons Attribution 4.0 International (CC BY 4.0) license.
83
+
84
+ ## Related papers
85
+
86
+ Please cite the following related papers when using this model in research:
87
+
88
+ ```bibtex
89
+ @article{chuai2026community,
90
+ title={Community corrections have divergent downstream effects across corrected accounts},
91
+ author={Chuai, Yuwei and Renault, Thomas and Pr{\"o}llochs, Nicolas and Lenzini, Gabriele and Mosleh, Mohsen},
92
+ journal={arXiv preprint arXiv:2608.27526},
93
+ year={2026}
94
+ }
95
+
96
+ @article{renault2026grok,
97
+ title={@ Grok is this true? LLM-powered fact-checking on social media},
98
+ author={Renault, Thomas and Mosleh, Mohsen and Rand, David},
99
+ year={2026},
100
+ publisher={OSF}
101
+ }
102
+ ```
config.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "dtype": "float32",
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "id2label": {
12
+ "0": "Politics and Elections",
13
+ "1": "War and Geopolitics",
14
+ "2": "Health and Medicine",
15
+ "3": "Economy and Finance",
16
+ "4": "Technology and AI",
17
+ "5": "Crime and Public Safety",
18
+ "6": "Sports and Games",
19
+ "7": "Celebrity and Entertainment",
20
+ "8": "Religion and Spirituality",
21
+ "9": "Gender and Identity"
22
+ },
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 3072,
25
+ "label2id": {
26
+ "Celebrity and Entertainment": 7,
27
+ "Crime and Public Safety": 5,
28
+ "Economy and Finance": 3,
29
+ "Gender and Identity": 9,
30
+ "Health and Medicine": 2,
31
+ "Politics and Elections": 0,
32
+ "Religion and Spirituality": 8,
33
+ "Sports and Games": 6,
34
+ "Technology and AI": 4,
35
+ "War and Geopolitics": 1
36
+ },
37
+ "layer_norm_eps": 1e-12,
38
+ "max_position_embeddings": 512,
39
+ "model_type": "bert",
40
+ "num_attention_heads": 12,
41
+ "num_hidden_layers": 12,
42
+ "pad_token_id": 0,
43
+ "position_embedding_type": "relative_key",
44
+ "problem_type": "multi_label_classification",
45
+ "transformers_version": "4.57.6",
46
+ "type_vocab_size": 2,
47
+ "use_cache": true,
48
+ "vocab_size": 250002
49
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bac14a2d07ed4b6dfe296d5bf4682352f28bdfdd71fb8ac9789891aea0f019be
3
+ size 1115370240
predict_topics.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Predict post-level topics with the training pipeline's overlapping-window pooling."""
2
+ import argparse
3
+ import json
4
+ from pathlib import Path
5
+ import torch
6
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
7
+
8
+
9
+ def combine_text(post_text='', summaries=()):
10
+ post_text = post_text.strip()
11
+ summaries = list(dict.fromkeys(s.strip() for s in summaries if s.strip()))
12
+ sections = ['Original post:\n'+post_text] if post_text else []
13
+ sections += [f'Community Note {i}:\n{s}' for i,s in enumerate(summaries,1)]
14
+ if not sections:
15
+ raise ValueError('Provide post text or at least one nonempty note summary')
16
+ return '\n\n'.join(sections)
17
+
18
+
19
+ class TopicPredictor:
20
+ def __init__(self, model_path, device='cpu'):
21
+ path=Path(model_path)
22
+ self.settings=json.loads((path/'topic_config.json').read_text())
23
+ self.tokenizer=AutoTokenizer.from_pretrained(path,local_files_only=True,use_fast=True)
24
+ self.model=AutoModelForSequenceClassification.from_pretrained(path,local_files_only=True).to(device).eval()
25
+ self.device=device
26
+ if self.settings['pooling']!='max_logits':
27
+ raise ValueError('Unsupported pooling configuration')
28
+
29
+ @torch.inference_mode()
30
+ def predict(self, post_text='', summaries=(), window_batch_size=8):
31
+ if window_batch_size < 1:
32
+ raise ValueError('window_batch_size must be positive')
33
+ text=combine_text(post_text,summaries)
34
+ encoded=self.tokenizer(text,truncation=True,max_length=self.settings['max_length'],
35
+ stride=self.settings['stride'],return_overflowing_tokens=True)
36
+ windows=[{k:encoded[k][i] for k in self.tokenizer.model_input_names if k in encoded}
37
+ for i in range(len(encoded['input_ids']))]
38
+ pooled=None
39
+ for start in range(0,len(windows),window_batch_size):
40
+ batch=self.tokenizer.pad(windows[start:start+window_batch_size],return_tensors='pt').to(self.device)
41
+ logits=self.model(**batch).logits.max(dim=0).values
42
+ pooled=logits if pooled is None else torch.maximum(pooled,logits)
43
+ scores=pooled.sigmoid().cpu().tolist()
44
+ return [{'topic':topic,'score':score,'selected':score>=self.settings['threshold']}
45
+ for topic,score in zip(self.settings['categories'],scores)]
46
+
47
+
48
+ if __name__=='__main__':
49
+ parser=argparse.ArgumentParser(description=__doc__)
50
+ parser.add_argument('--model',default=str(Path(__file__).resolve().parent))
51
+ parser.add_argument('--post',default='')
52
+ parser.add_argument('--note',action='append',default=[])
53
+ parser.add_argument('--device',default='cpu')
54
+ args=parser.parse_args()
55
+ print(json.dumps(TopicPredictor(args.model,args.device).predict(args.post,args.note),indent=2))
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ transformers>=4.41,<5
3
+ huggingface_hub>=0.25
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": true,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "</s>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "<unk>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e33145445182c46ae896d136b317372e86aef9e6e5946ad03d231e4ff335eb2d
3
+ size 17082833
tokenizer_config.json ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "250001": {
36
+ "content": "<mask>",
37
+ "lstrip": true,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "<s>",
45
+ "clean_up_tokenization_spaces": false,
46
+ "cls_token": "<s>",
47
+ "eos_token": "</s>",
48
+ "extra_special_tokens": {},
49
+ "mask_token": "<mask>",
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "pad_token": "<pad>",
52
+ "sep_token": "</s>",
53
+ "tokenizer_class": "XLMRobertaTokenizerFast",
54
+ "unk_token": "<unk>"
55
+ }
topic_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "pipeline_version": "post-with-all-notes-v1",
3
+ "base_model": "Twitter/twhin-bert-base",
4
+ "categories": [
5
+ "Politics and Elections",
6
+ "War and Geopolitics",
7
+ "Health and Medicine",
8
+ "Economy and Finance",
9
+ "Technology and AI",
10
+ "Crime and Public Safety",
11
+ "Sports and Games",
12
+ "Celebrity and Entertainment",
13
+ "Religion and Spirituality",
14
+ "Gender and Identity"
15
+ ],
16
+ "threshold": 0.5,
17
+ "max_length": 512,
18
+ "stride": 64,
19
+ "pooling": "max_logits",
20
+ "gpt_model": "gpt-5.4-mini"
21
+ }
validation_metrics.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "eval_loss": 0.1876334697008133,
3
+ "eval_f1_micro": 0.8312189180960113,
4
+ "eval_f1_macro": 0.8093773315390159,
5
+ "eval_f1_samples": 0.7618056223611779,
6
+ "eval_runtime": 65.3206,
7
+ "eval_samples_per_second": 45.468,
8
+ "eval_steps_per_second": 11.375,
9
+ "epoch": 5.0
10
+ }