Datasets:

Modalities:
Text
Languages:
English
ArXiv:
Libraries:
Datasets
License:
Files changed (6) hide show
  1. .gitignore +0 -4
  2. README.md +25 -98
  3. get_model_list.py +0 -47
  4. lm_finetuning.py +0 -226
  5. readme.py +0 -89
  6. tweet_topic_single.py +20 -31
.gitignore DELETED
@@ -1,4 +0,0 @@
1
- wandb
2
- ray_result*
3
- ckpt
4
-
 
 
 
 
 
README.md CHANGED
@@ -14,99 +14,18 @@ task_ids:
14
  pretty_name: TweetTopicSingle
15
  ---
16
 
17
- # Dataset Card for "cardiffnlp/tweet_topic_single"
18
 
19
  ## Dataset Description
20
 
21
- - **Paper:** [https://arxiv.org/abs/2209.09824](https://arxiv.org/abs/2209.09824)
22
  - **Dataset:** Tweet Topic Dataset
23
  - **Domain:** Twitter
24
  - **Number of Class:** 6
25
 
26
 
27
  ### Dataset Summary
28
- This is the official repository of TweetTopic (["Twitter Topic Classification
29
- , COLING main conference 2022"](https://arxiv.org/abs/2209.09824)), a topic classification dataset on Twitter with 6 labels.
30
- Each instance of TweetTopic comes with a timestamp which distributes from September 2019 to August 2021.
31
- See [cardiffnlp/tweet_topic_multi](https://huggingface.co/datasets/cardiffnlp/tweet_topic_multi) for multi label version of TweetTopic.
32
- The tweet collection used in TweetTopic is same as what used in [TweetNER7](https://huggingface.co/datasets/tner/tweetner7).
33
- The dataset is integrated in [TweetNLP](https://tweetnlp.org/) too.
34
-
35
- ### Preprocessing
36
- We pre-process tweets before the annotation to normalize some artifacts, converting URLs into a special token `{{URL}}` and non-verified usernames into `{{USERNAME}}`.
37
- For verified usernames, we replace its display name (or account name) with symbols `{@}`.
38
- For example, a tweet
39
- ```
40
- Get the all-analog Classic Vinyl Edition
41
- of "Takin' Off" Album from @herbiehancock
42
- via @bluenoterecords link below:
43
- http://bluenote.lnk.to/AlbumOfTheWeek
44
- ```
45
- is transformed into the following text.
46
- ```
47
- Get the all-analog Classic Vinyl Edition
48
- of "Takin' Off" Album from {@herbiehancock@}
49
- via {@bluenoterecords@} link below: {{URL}}
50
- ```
51
- A simple function to format tweet follows below.
52
- ```python
53
- import re
54
- from urlextract import URLExtract
55
- extractor = URLExtract()
56
- def format_tweet(tweet):
57
- # mask web urls
58
- urls = extractor.find_urls(tweet)
59
- for url in urls:
60
- tweet = tweet.replace(url, "{{URL}}")
61
- # format twitter account
62
- tweet = re.sub(r"\b(\s*)(@[\S]+)\b", r'\1{\2@}', tweet)
63
- return tweet
64
- target = """Get the all-analog Classic Vinyl Edition of "Takin' Off" Album from @herbiehancock via @bluenoterecords link below: http://bluenote.lnk.to/AlbumOfTheWeek"""
65
- target_format = format_tweet(target)
66
- print(target_format)
67
- 'Get the all-analog Classic Vinyl Edition of "Takin\' Off" Album from {@herbiehancock@} via {@bluenoterecords@} link below: {{URL}}'
68
- ```
69
-
70
-
71
- ### Data Splits
72
-
73
- | split | number of texts | description |
74
- |:------------------------|-----:|------:|
75
- | test_2020 | 376 | test dataset from September 2019 to August 2020 |
76
- | test_2021 | 1693 | test dataset from September 2020 to August 2021 |
77
- | train_2020 | 2858 | training dataset from September 2019 to August 2020 |
78
- | train_2021 | 1516 | training dataset from September 2020 to August 2021 |
79
- | train_all | 4374 | combined training dataset of `train_2020` and `train_2021` |
80
- | validation_2020 | 352 | validation dataset from September 2019 to August 2020 |
81
- | validation_2021 | 189 | validation dataset from September 2020 to August 2021 |
82
- | train_random | 2830 | randomly sampled training dataset with the same size as `train_2020` from `train_all` |
83
- | validation_random | 354 | randomly sampled training dataset with the same size as `validation_2020` from `validation_all` |
84
- | test_coling2022_random | 3399 | random split used in the COLING 2022 paper |
85
- | train_coling2022_random | 3598 | random split used in the COLING 2022 paper |
86
- | test_coling2022 | 3399 | temporal split used in the COLING 2022 paper |
87
- | train_coling2022 | 3598 | temporal split used in the COLING 2022 paper |
88
-
89
- For the temporal-shift setting, model should be trained on `train_2020` with `validation_2020` and evaluate on `test_2021`.
90
- In general, model would be trained on `train_all`, the most representative training set with `validation_2021` and evaluate on `test_2021`.
91
-
92
- **IMPORTANT NOTE:** To get a result that is comparable with the results of the COLING 2022 Tweet Topic paper, please use `train_coling2022` and `test_coling2022` for temporal-shift, and `train_coling2022_random` and `test_coling2022_random` fir random split (the coling2022 split does not have validation set).
93
-
94
- ### Models
95
-
96
- | model | training data | F1 | F1 (macro) | Accuracy |
97
- |:------------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------|---------:|-------------:|-----------:|
98
- | [cardiffnlp/roberta-large-tweet-topic-single-all](https://huggingface.co/cardiffnlp/roberta-large-tweet-topic-single-all) | all (2020 + 2021) | 0.896043 | 0.800061 | 0.896043 |
99
- | [cardiffnlp/roberta-base-tweet-topic-single-all](https://huggingface.co/cardiffnlp/roberta-base-tweet-topic-single-all) | all (2020 + 2021) | 0.887773 | 0.79793 | 0.887773 |
100
- | [cardiffnlp/twitter-roberta-base-2019-90m-tweet-topic-single-all](https://huggingface.co/cardiffnlp/twitter-roberta-base-2019-90m-tweet-topic-single-all) | all (2020 + 2021) | 0.892499 | 0.774494 | 0.892499 |
101
- | [cardiffnlp/twitter-roberta-base-dec2020-tweet-topic-single-all](https://huggingface.co/cardiffnlp/twitter-roberta-base-dec2020-tweet-topic-single-all) | all (2020 + 2021) | 0.890136 | 0.776025 | 0.890136 |
102
- | [cardiffnlp/twitter-roberta-base-dec2021-tweet-topic-single-all](https://huggingface.co/cardiffnlp/twitter-roberta-base-dec2021-tweet-topic-single-all) | all (2020 + 2021) | 0.894861 | 0.800952 | 0.894861 |
103
- | [cardiffnlp/roberta-large-tweet-topic-single-2020](https://huggingface.co/cardiffnlp/roberta-large-tweet-topic-single-2020) | 2020 only | 0.878913 | 0.70565 | 0.878913 |
104
- | [cardiffnlp/roberta-base-tweet-topic-single-2020](https://huggingface.co/cardiffnlp/roberta-base-tweet-topic-single-2020) | 2020 only | 0.868281 | 0.729667 | 0.868281 |
105
- | [cardiffnlp/twitter-roberta-base-2019-90m-tweet-topic-single-2020](https://huggingface.co/cardiffnlp/twitter-roberta-base-2019-90m-tweet-topic-single-2020) | 2020 only | 0.882457 | 0.740187 | 0.882457 |
106
- | [cardiffnlp/twitter-roberta-base-dec2020-tweet-topic-single-2020](https://huggingface.co/cardiffnlp/twitter-roberta-base-dec2020-tweet-topic-single-2020) | 2020 only | 0.87596 | 0.746275 | 0.87596 |
107
- | [cardiffnlp/twitter-roberta-base-dec2021-tweet-topic-single-2020](https://huggingface.co/cardiffnlp/twitter-roberta-base-dec2021-tweet-topic-single-2020) | 2020 only | 0.877732 | 0.746119 | 0.877732 |
108
-
109
- Model fine-tuning script can be found [here](https://huggingface.co/datasets/cardiffnlp/tweet_topic_single/blob/main/lm_finetuning.py).
110
 
111
  ## Dataset Structure
112
 
@@ -136,21 +55,29 @@ The label2id dictionary can be found at [here](https://huggingface.co/datasets/t
136
  }
137
  ```
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  ### Citation Information
140
 
141
  ```
142
- @inproceedings{dimosthenis-etal-2022-twitter,
143
- title = "{T}witter {T}opic {C}lassification",
144
- author = "Antypas, Dimosthenis and
145
- Ushio, Asahi and
146
- Camacho-Collados, Jose and
147
- Neves, Leonardo and
148
- Silva, Vitor and
149
- Barbieri, Francesco",
150
- booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
151
- month = oct,
152
- year = "2022",
153
- address = "Gyeongju, Republic of Korea",
154
- publisher = "International Committee on Computational Linguistics"
155
- }
156
  ```
 
14
  pretty_name: TweetTopicSingle
15
  ---
16
 
17
+ # Dataset Card for "cardiff_nlp/tweet_topic_single"
18
 
19
  ## Dataset Description
20
 
21
+ - **Paper:** TBA
22
  - **Dataset:** Tweet Topic Dataset
23
  - **Domain:** Twitter
24
  - **Number of Class:** 6
25
 
26
 
27
  ### Dataset Summary
28
+ Topic classification dataset on Twitter with single label per tweet.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  ## Dataset Structure
31
 
 
55
  }
56
  ```
57
 
58
+ ### Data Splits
59
+
60
+ | split | number of texts |
61
+ |:--------------------------|-----:|
62
+ | test | 1679 |
63
+ | train | 1505 |
64
+ | validation | 188 |
65
+ | temporal_2020_test | 573 |
66
+ | temporal_2021_test | 1679 |
67
+ | temporal_2020_train | 4585 |
68
+ | temporal_2021_train | 1505 |
69
+ | temporal_2020_validation | 573 |
70
+ | temporal_2021_validation | 188 |
71
+ | random_train | 4564 |
72
+ | random_validation | 573 |
73
+ | coling2022_random_test | 5536 |
74
+ | coling2022_random_train | 5731 |
75
+ | coling2022_temporal_test | 5536 |
76
+ | coling2022_temporal_train | 5731 |
77
+
78
+
79
  ### Citation Information
80
 
81
  ```
82
+ TBA
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  ```
get_model_list.py DELETED
@@ -1,47 +0,0 @@
1
- import json
2
- import os
3
- import requests
4
-
5
- import pandas as pd
6
-
7
-
8
- def download(filename, url):
9
- try:
10
- with open(filename) as f:
11
- json.load(f)
12
- except Exception:
13
- os.makedirs(os.path.dirname(filename), exist_ok=True)
14
- with open(filename, "wb") as f:
15
- r = requests.get(url)
16
- f.write(r.content)
17
- with open(filename) as f:
18
- tmp = json.load(f)
19
- return tmp
20
-
21
-
22
-
23
- models = [
24
- "cardiffnlp/roberta-large-tweet-topic-single-all",
25
- "cardiffnlp/roberta-base-tweet-topic-single-all",
26
- "cardiffnlp/twitter-roberta-base-2019-90m-tweet-topic-single-all",
27
- "cardiffnlp/twitter-roberta-base-dec2020-tweet-topic-single-all",
28
- "cardiffnlp/twitter-roberta-base-dec2021-tweet-topic-single-all",
29
- "cardiffnlp/roberta-large-tweet-topic-single-2020",
30
- "cardiffnlp/roberta-base-tweet-topic-single-2020",
31
- "cardiffnlp/twitter-roberta-base-2019-90m-tweet-topic-single-2020",
32
- "cardiffnlp/twitter-roberta-base-dec2020-tweet-topic-single-2020",
33
- "cardiffnlp/twitter-roberta-base-dec2021-tweet-topic-single-2020"
34
- ]
35
-
36
- os.makedirs("metric_files", exist_ok=True)
37
-
38
- metrics = []
39
- for i in models:
40
- model_type = "all (2020 + 2021)" if i.endswith("all") else "2020 only"
41
- url = f"https://huggingface.co/{i}/raw/main/metric_summary.json"
42
- model_url = f"https://huggingface.co/{i}"
43
- metric = download(f"metric_files/{os.path.basename(i)}.json", url)
44
- metrics.append({"model": f"[{i}]({model_url})", "training data": model_type, "F1": metric["test/eval_f1"], "F1 (macro)": metric["test/eval_f1_macro"], "Accuracy": metric["test/eval_accuracy"]})
45
-
46
- df = pd.DataFrame(metrics)
47
- print(df.to_markdown(index=False))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lm_finetuning.py DELETED
@@ -1,226 +0,0 @@
1
- '''
2
- wandb offline
3
- export WANDB_DISABLED='true'
4
- export RAY_RESULTS='ray_results'
5
-
6
- python lm_finetuning.py -m "roberta-large" -o "ckpt/2021/roberta-large" --push-to-hub --hf-organization "cardiffnlp" -a "roberta-large-tweet-topic-single-all" --split-train "train_all" --split-valid "validation_2021" --split-test "test_2021"
7
- python lm_finetuning.py -m "roberta-large" -o "ckpt/2020/roberta-large" --push-to-hub --hf-organization "cardiffnlp" -a "roberta-large-tweet-topic-single-2020" --split-train "train_2020" --split-valid "validation_2020" --split-test "test_2021"
8
-
9
- python lm_finetuning.py -m "roberta-base" -o "ckpt/2021/roberta_base" --push-to-hub --hf-organization "cardiffnlp" -a "roberta-base-tweet-topic-single-all" --split-train "train_all" --split-valid "validation_2021" --split-test "test_2021"
10
- python lm_finetuning.py -m "roberta-base" -o "ckpt/2020/roberta_base" --push-to-hub --hf-organization "cardiffnlp" -a "roberta-base-tweet-topic-single-2020" --split-train "train_2020" --split-valid "validation_2020" --split-test "test_2021"
11
-
12
- python lm_finetuning.py -m "cardiffnlp/twitter-roberta-base-2019-90m" -o "ckpt/2021/twitter-roberta-base-2019-90m" --push-to-hub --hf-organization "cardiffnlp" -a "twitter-roberta-base-2019-90m-tweet-topic-single-all" --split-train "train_all" --split-valid "validation_2021" --split-test "test_2021"
13
- python lm_finetuning.py -m "cardiffnlp/twitter-roberta-base-2019-90m" -o "ckpt/2020/twitter-roberta-base-2019-90m" --push-to-hub --hf-organization "cardiffnlp" -a "twitter-roberta-base-2019-90m-tweet-topic-single-2020" --split-train "train_2020" --split-valid "validation_2020" --split-test "test_2021"
14
-
15
- python lm_finetuning.py -m "cardiffnlp/twitter-roberta-base-dec2020" -o "ckpt/2021/twitter-roberta-base-dec2020" --push-to-hub --hf-organization "cardiffnlp" -a "twitter-roberta-base-dec2020-tweet-topic-single-all" --split-train "train_all" --split-valid "validation_2021" --split-test "test_2021"
16
- python lm_finetuning.py -m "cardiffnlp/twitter-roberta-base-dec2020" -o "ckpt/2020/twitter-roberta-base-dec2020" --push-to-hub --hf-organization "cardiffnlp" -a "twitter-roberta-base-dec2020-tweet-topic-single-2020" --split-train "train_2020" --split-valid "validation_2020" --split-test "test_2021"
17
-
18
- python lm_finetuning.py -m "cardiffnlp/twitter-roberta-base-dec2021" -o "ckpt/2021/twitter-roberta-base-dec2021" --push-to-hub --hf-organization "cardiffnlp" -a "twitter-roberta-base-dec2021-tweet-topic-single-all" --split-train "train_all" --split-valid "validation_2021" --split-test "test_2021"
19
- python lm_finetuning.py -m "cardiffnlp/twitter-roberta-base-dec2021" -o "ckpt/2020/twitter-roberta-base-dec2021" --push-to-hub --hf-organization "cardiffnlp" -a "twitter-roberta-base-dec2021-tweet-topic-single-2020" --split-train "train_2020" --split-valid "validation_2020" --split-test "test_2021"
20
- '''
21
-
22
- import argparse
23
- import json
24
- import logging
25
- import os
26
- import shutil
27
- import urllib.request
28
- import multiprocessing
29
- from os.path import join as pj
30
-
31
- import torch
32
- import numpy as np
33
- from huggingface_hub import create_repo
34
- from datasets import load_dataset, load_metric
35
- from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
36
- from ray import tune
37
-
38
- from readme import get_readme
39
-
40
- logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S')
41
-
42
- PARALLEL = bool(int(os.getenv("PARALLEL", 1)))
43
- RAY_RESULTS = os.getenv("RAY_RESULTS", "ray_results")
44
- LABEL2ID = {
45
- "arts_&_culture": 0,
46
- "business_&_entrepreneurs": 1,
47
- "pop_culture": 2,
48
- "daily_life": 3,
49
- "sports_&_gaming": 4,
50
- "science_&_technology": 5
51
- }
52
- ID2LABEL = {v: k for k, v in LABEL2ID.items()}
53
-
54
-
55
- def internet_connection(host='http://google.com'):
56
- try:
57
- urllib.request.urlopen(host)
58
- return True
59
- except:
60
- return False
61
-
62
-
63
- def get_metrics():
64
- metric_accuracy = load_metric("accuracy")
65
- metric_f1 = load_metric("f1")
66
-
67
- def compute_metric_search(eval_pred):
68
- logits, labels = eval_pred
69
- predictions = np.argmax(logits, axis=-1)
70
- return metric_f1.compute(predictions=predictions, references=labels, average='micro')
71
-
72
- def compute_metric_all(eval_pred):
73
- logits, labels = eval_pred
74
- predictions = np.argmax(logits, axis=-1)
75
- return {
76
- 'f1': metric_f1.compute(predictions=predictions, references=labels, average='micro')['f1'],
77
- 'f1_macro': metric_f1.compute(predictions=predictions, references=labels, average='macro')['f1'],
78
- 'accuracy': metric_accuracy.compute(predictions=predictions, references=labels)['accuracy']
79
- }
80
- return compute_metric_search, compute_metric_all
81
-
82
-
83
- def main():
84
- parser = argparse.ArgumentParser(description='Fine-tuning language model.')
85
- parser.add_argument('-m', '--model', help='transformer LM', default='roberta-base', type=str)
86
- parser.add_argument('-d', '--dataset', help='', default='cardiffnlp/tweet_topic_single', type=str)
87
- parser.add_argument('--split-train', help='', required=True, type=str)
88
- parser.add_argument('--split-validation', help='', required=True, type=str)
89
- parser.add_argument('--split-test', help='', required=True, type=str)
90
- parser.add_argument('-l', '--seq-length', help='', default=128, type=int)
91
- parser.add_argument('--random-seed', help='', default=42, type=int)
92
- parser.add_argument('--eval-step', help='', default=50, type=int)
93
- parser.add_argument('-o', '--output-dir', help='Directory to output', default='ckpt_tmp', type=str)
94
- parser.add_argument('-t', '--n-trials', default=10, type=int)
95
- parser.add_argument('--push-to-hub', action='store_true')
96
- parser.add_argument('--use-auth-token', action='store_true')
97
- parser.add_argument('--hf-organization', default=None, type=str)
98
- parser.add_argument('-a', '--model-alias', help='', default=None, type=str)
99
- parser.add_argument('--summary-file', default='metric_summary.json', type=str)
100
- parser.add_argument('--skip-train', action='store_true')
101
- parser.add_argument('--skip-eval', action='store_true')
102
- opt = parser.parse_args()
103
- assert opt.summary_file.endswith('.json'), f'`--summary-file` should be a json file {opt.summary_file}'
104
- # setup data
105
- dataset = load_dataset(opt.dataset)
106
- network = internet_connection()
107
- # setup model
108
- tokenizer = AutoTokenizer.from_pretrained(opt.model, local_files_only=not network)
109
- model = AutoModelForSequenceClassification.from_pretrained(
110
- opt.model,
111
- num_labels=6,
112
- local_files_only=not network,
113
- id2label=ID2LABEL,
114
- label2id=LABEL2ID
115
- )
116
- tokenized_datasets = dataset.map(
117
- lambda x: tokenizer(x["text"], padding="max_length", truncation=True, max_length=opt.seq_length),
118
- batched=True)
119
- # setup metrics
120
- compute_metric_search, compute_metric_all = get_metrics()
121
-
122
- if not opt.skip_train:
123
- # setup trainer
124
- trainer = Trainer(
125
- model=model,
126
- args=TrainingArguments(
127
- output_dir=opt.output_dir,
128
- evaluation_strategy="steps",
129
- eval_steps=opt.eval_step,
130
- seed=opt.random_seed
131
- ),
132
- train_dataset=tokenized_datasets[opt.split_train],
133
- eval_dataset=tokenized_datasets[opt.split_validation],
134
- compute_metrics=compute_metric_search,
135
- model_init=lambda x: AutoModelForSequenceClassification.from_pretrained(
136
- opt.model,
137
- num_labels=6,
138
- local_files_only=not network,
139
- return_dict=True,
140
- id2label=ID2LABEL,
141
- label2id=LABEL2ID
142
- )
143
- )
144
- # parameter search
145
- if PARALLEL:
146
- best_run = trainer.hyperparameter_search(
147
- hp_space=lambda x: {
148
- "learning_rate": tune.loguniform(1e-6, 1e-4),
149
- "num_train_epochs": tune.choice(list(range(1, 6))),
150
- "per_device_train_batch_size": tune.choice([4, 8, 16, 32, 64]),
151
- },
152
- local_dir=RAY_RESULTS, direction="maximize", backend="ray", n_trials=opt.n_trials,
153
- resources_per_trial={'cpu': multiprocessing.cpu_count(), "gpu": torch.cuda.device_count()},
154
-
155
- )
156
- else:
157
- best_run = trainer.hyperparameter_search(
158
- hp_space=lambda x: {
159
- "learning_rate": tune.loguniform(1e-6, 1e-4),
160
- "num_train_epochs": tune.choice(list(range(1, 6))),
161
- "per_device_train_batch_size": tune.choice([4, 8, 16, 32, 64]),
162
- },
163
- local_dir=RAY_RESULTS, direction="maximize", backend="ray", n_trials=opt.n_trials
164
- )
165
- # finetuning
166
- for n, v in best_run.hyperparameters.items():
167
- setattr(trainer.args, n, v)
168
- trainer.train()
169
- trainer.save_model(pj(opt.output_dir, 'best_model'))
170
- best_model_path = pj(opt.output_dir, 'best_model')
171
- else:
172
- best_model_path = pj(opt.output_dir, 'best_model')
173
-
174
- # evaluation
175
- model = AutoModelForSequenceClassification.from_pretrained(
176
- best_model_path,
177
- num_labels=6,
178
- local_files_only=not network,
179
- id2label=ID2LABEL,
180
- label2id=LABEL2ID
181
- )
182
- trainer = Trainer(
183
- model=model,
184
- args=TrainingArguments(
185
- output_dir=opt.output_dir,
186
- evaluation_strategy="no",
187
- seed=opt.random_seed
188
- ),
189
- train_dataset=tokenized_datasets[opt.split_train],
190
- eval_dataset=tokenized_datasets[opt.split_test],
191
- compute_metrics=compute_metric_all,
192
- )
193
- summary_file = pj(opt.output_dir, opt.summary_file)
194
- if not opt.skip_eval:
195
- result = {f'test/{k}': v for k, v in trainer.evaluate().items()}
196
- logging.info(json.dumps(result, indent=4))
197
- with open(summary_file, 'w') as f:
198
- json.dump(result, f)
199
-
200
- if opt.push_to_hub:
201
- assert opt.hf_organization is not None, f'specify hf organization `--hf-organization`'
202
- assert opt.model_alias is not None, f'specify hf organization `--model-alias`'
203
- url = create_repo(opt.model_alias, organization=opt.hf_organization, exist_ok=True)
204
- # if not opt.skip_train:
205
- args = {"use_auth_token": opt.use_auth_token, "repo_url": url, "organization": opt.hf_organization}
206
- trainer.model.push_to_hub(opt.model_alias, **args)
207
- tokenizer.push_to_hub(opt.model_alias, **args)
208
- if os.path.exists(summary_file):
209
- shutil.copy2(summary_file, opt.model_alias)
210
- extra_desc = f"This model is fine-tuned on `{opt.split_train}` split and validated on `{opt.split_test}` split of tweet_topic."
211
- readme = get_readme(
212
- model_name=f"{opt.hf_organization}/{opt.model_alias}",
213
- metric=summary_file,
214
- language_model=opt.model,
215
- extra_desc= extra_desc
216
- )
217
- with open(f"{opt.model_alias}/README.md", "w") as f:
218
- f.write(readme)
219
- os.system(
220
- f"cd {opt.model_alias} && git lfs install && git add . && git commit -m 'model update' && git push && cd ../")
221
- shutil.rmtree(f"{opt.model_alias}") # clean up the cloned repo
222
-
223
-
224
- if __name__ == '__main__':
225
- main()
226
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.py DELETED
@@ -1,89 +0,0 @@
1
- import os
2
- import json
3
- from typing import Dict
4
-
5
-
6
- sample = "#NewVideo Cray Dollas- Water- Ft. Charlie Rose- (Official Music Video)- {{URL}} via {@YouTube@} #watchandlearn {{USERNAME}}"
7
- bib = """
8
- @inproceedings{dimosthenis-etal-2022-twitter,
9
- title = "{T}witter {T}opic {C}lassification",
10
- author = "Antypas, Dimosthenis and
11
- Ushio, Asahi and
12
- Camacho-Collados, Jose and
13
- Neves, Leonardo and
14
- Silva, Vitor and
15
- Barbieri, Francesco",
16
- booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
17
- month = oct,
18
- year = "2022",
19
- address = "Gyeongju, Republic of Korea",
20
- publisher = "International Committee on Computational Linguistics"
21
- }
22
- """
23
-
24
-
25
- def get_readme(model_name: str,
26
- metric: str,
27
- language_model,
28
- extra_desc: str = ''):
29
- with open(metric) as f:
30
- metric = json.load(f)
31
- return f"""---
32
- datasets:
33
- - cardiffnlp/tweet_topic_single
34
- metrics:
35
- - f1
36
- - accuracy
37
- model-index:
38
- - name: {model_name}
39
- results:
40
- - task:
41
- type: text-classification
42
- name: Text Classification
43
- dataset:
44
- name: cardiffnlp/tweet_topic_single
45
- type: cardiffnlp/tweet_topic_single
46
- args: cardiffnlp/tweet_topic_single
47
- split: test_2021
48
- metrics:
49
- - name: F1
50
- type: f1
51
- value: {metric['test/eval_f1']}
52
- - name: F1 (macro)
53
- type: f1_macro
54
- value: {metric['test/eval_f1_macro']}
55
- - name: Accuracy
56
- type: accuracy
57
- value: {metric['test/eval_accuracy']}
58
- pipeline_tag: text-classification
59
- widget:
60
- - text: "I'm sure the {"{@Tampa Bay Lightning@}"} would’ve rather faced the Flyers but man does their experience versus the Blue Jackets this year and last help them a lot versus this Islanders team. Another meat grinder upcoming for the good guys"
61
- example_title: "Example 1"
62
- - text: "Love to take night time bike rides at the jersey shore. Seaside Heights boardwalk. Beautiful weather. Wishing everyone a safe Labor Day weekend in the US."
63
- example_title: "Example 2"
64
- ---
65
- # {model_name}
66
-
67
- This model is a fine-tuned version of [{language_model}](https://huggingface.co/{language_model}) on the [tweet_topic_single](https://huggingface.co/datasets/cardiffnlp/tweet_topic_single). {extra_desc}
68
- Fine-tuning script can be found [here](https://huggingface.co/datasets/cardiffnlp/tweet_topic_single/blob/main/lm_finetuning.py). It achieves the following results on the test_2021 set:
69
-
70
- - F1 (micro): {metric['test/eval_f1']}
71
- - F1 (macro): {metric['test/eval_f1_macro']}
72
- - Accuracy: {metric['test/eval_accuracy']}
73
-
74
-
75
- ### Usage
76
-
77
- ```python
78
- from transformers import pipeline
79
-
80
- pipe = pipeline("text-classification", "{model_name}")
81
- topic = pipe("Love to take night time bike rides at the jersey shore. Seaside Heights boardwalk. Beautiful weather. Wishing everyone a safe Labor Day weekend in the US.")
82
- print(topic)
83
- ```
84
-
85
- ### Reference
86
- ```
87
- {bib}
88
- ```
89
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tweet_topic_single.py CHANGED
@@ -4,45 +4,35 @@ from itertools import chain
4
  import datasets
5
 
6
  logger = datasets.logging.get_logger(__name__)
7
- _DESCRIPTION = """[TweetTopic](https://arxiv.org/abs/2209.09824)"""
8
 
9
- _VERSION = "1.0.4"
10
  _CITATION = """
11
- @inproceedings{dimosthenis-etal-2022-twitter,
12
- title = "{T}witter {T}opic {C}lassification",
13
- author = "Antypas, Dimosthenis and
14
- Ushio, Asahi and
15
- Camacho-Collados, Jose and
16
- Neves, Leonardo and
17
- Silva, Vitor and
18
- Barbieri, Francesco",
19
- booktitle = "Proceedings of the 29th International Conference on Computational Linguistics",
20
- month = oct,
21
- year = "2022",
22
- address = "Gyeongju, Republic of Korea",
23
- publisher = "International Committee on Computational Linguistics"
24
- }
25
  """
26
  _HOME_PAGE = "https://cardiffnlp.github.io"
27
  _LABEL_TYPE = "single"
28
  _NAME = f"tweet_topic_{_LABEL_TYPE}"
29
  _URL = f'https://huggingface.co/datasets/cardiffnlp/{_NAME}/raw/main/dataset'
30
  _URLS = {
31
- f"{str(datasets.Split.TEST)}_2020": [f'{_URL}/split_temporal/test_2020.{_LABEL_TYPE}.json'],
32
- f"{str(datasets.Split.TEST)}_2021": [f'{_URL}/split_temporal/test_2021.{_LABEL_TYPE}.json'],
33
- f"{str(datasets.Split.TRAIN)}_2020": [f'{_URL}/split_temporal/train_2020.{_LABEL_TYPE}.json'],
34
- f"{str(datasets.Split.TRAIN)}_2021": [f'{_URL}/split_temporal/train_2021.{_LABEL_TYPE}.json'],
35
- f"{str(datasets.Split.TRAIN)}_all": [f'{_URL}/split_temporal/train_2020.{_LABEL_TYPE}.json', f'{_URL}/split_temporal/train_2021.{_LABEL_TYPE}.json'],
36
- f"{str(datasets.Split.VALIDATION)}_2020": [f'{_URL}/split_temporal/validation_2020.{_LABEL_TYPE}.json'],
37
- f"{str(datasets.Split.VALIDATION)}_2021": [f'{_URL}/split_temporal/validation_2021.{_LABEL_TYPE}.json'],
38
- f"{str(datasets.Split.TRAIN)}_random": [f'{_URL}/split_random/train_random.{_LABEL_TYPE}.json'],
39
- f"{str(datasets.Split.VALIDATION)}_random": [f'{_URL}/split_random/validation_random.{_LABEL_TYPE}.json'],
40
- f"{str(datasets.Split.TEST)}_coling2022_random": [f'{_URL}/split_coling2022_random/test_random.{_LABEL_TYPE}.json'],
41
- f"{str(datasets.Split.TRAIN)}_coling2022_random": [f'{_URL}/split_coling2022_random/train_random.{_LABEL_TYPE}.json'],
42
- f"{str(datasets.Split.TEST)}_coling2022": [f'{_URL}/split_coling2022_temporal/test_2021.{_LABEL_TYPE}.json'],
43
- f"{str(datasets.Split.TRAIN)}_coling2022": [f'{_URL}/split_coling2022_temporal/train_2020.{_LABEL_TYPE}.json'],
 
 
44
  }
45
 
 
46
  class TweetTopicSingleConfig(datasets.BuilderConfig):
47
  """BuilderConfig"""
48
 
@@ -78,14 +68,13 @@ class TweetTopicSingle(datasets.GeneratorBasedBuilder):
78
  _key += 1
79
 
80
  def _info(self):
81
- names = ["arts_&_culture", "business_&_entrepreneurs", "pop_culture", "daily_life", "sports_&_gaming", "science_&_technology"]
82
  return datasets.DatasetInfo(
83
  description=_DESCRIPTION,
84
  features=datasets.Features(
85
  {
86
  "text": datasets.Value("string"),
87
  "date": datasets.Value("string"),
88
- "label": datasets.features.ClassLabel(names=names),
89
  "label_name": datasets.Value("string"),
90
  "id": datasets.Value("string")
91
  }
 
4
  import datasets
5
 
6
  logger = datasets.logging.get_logger(__name__)
7
+ _DESCRIPTION = """[TweetTopic](TBA)"""
8
 
9
+ _VERSION = "1.0.1"
10
  _CITATION = """
11
+ TBA
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  """
13
  _HOME_PAGE = "https://cardiffnlp.github.io"
14
  _LABEL_TYPE = "single"
15
  _NAME = f"tweet_topic_{_LABEL_TYPE}"
16
  _URL = f'https://huggingface.co/datasets/cardiffnlp/{_NAME}/raw/main/dataset'
17
  _URLS = {
18
+ str(datasets.Split.TEST): [f'{_URL}/split_temporal/test_2021.{_LABEL_TYPE}.json'],
19
+ str(datasets.Split.TRAIN): [f'{_URL}/split_temporal/train_2021.{_LABEL_TYPE}.json'],
20
+ str(datasets.Split.VALIDATION): [f'{_URL}/split_temporal/validation_2021.{_LABEL_TYPE}.json'],
21
+ f"temporal_2020_{str(datasets.Split.TEST)}": [f'{_URL}/split_temporal/test_2020.{_LABEL_TYPE}.json'],
22
+ f"temporal_2021_{str(datasets.Split.TEST)}": [f'{_URL}/split_temporal/test_2021.{_LABEL_TYPE}.json'],
23
+ f"temporal_2020_{str(datasets.Split.TRAIN)}": [f'{_URL}/split_temporal/train_2020.{_LABEL_TYPE}.json'],
24
+ f"temporal_2021_{str(datasets.Split.TRAIN)}": [f'{_URL}/split_temporal/train_2021.{_LABEL_TYPE}.json'],
25
+ f"temporal_2020_{str(datasets.Split.VALIDATION)}": [f'{_URL}/split_temporal/validation_2020.{_LABEL_TYPE}.json'],
26
+ f"temporal_2021_{str(datasets.Split.VALIDATION)}": [f'{_URL}/split_temporal/validation_2021.{_LABEL_TYPE}.json'],
27
+ f"random_{str(datasets.Split.TRAIN)}": [f'{_URL}/split_random/train_random.{_LABEL_TYPE}.json'],
28
+ f"random_{str(datasets.Split.VALIDATION)}": [f'{_URL}/split_random/validation_random.{_LABEL_TYPE}.json'],
29
+ f"coling2022_random_{str(datasets.Split.TEST)}": [f'{_URL}/split_coling2022_random/test_random.{_LABEL_TYPE}.json'],
30
+ f"coling2022_random_{str(datasets.Split.TRAIN)}": [f'{_URL}/split_coling2022_random/train_random.{_LABEL_TYPE}.json'],
31
+ f"coling2022_temporal_{str(datasets.Split.TEST)}": [f'{_URL}/split_coling2022_temporal/test_2021.{_LABEL_TYPE}.json'],
32
+ f"coling2022_temporal_{str(datasets.Split.TRAIN)}": [f'{_URL}/split_coling2022_temporal/train_2020.{_LABEL_TYPE}.json'],
33
  }
34
 
35
+
36
  class TweetTopicSingleConfig(datasets.BuilderConfig):
37
  """BuilderConfig"""
38
 
 
68
  _key += 1
69
 
70
  def _info(self):
 
71
  return datasets.DatasetInfo(
72
  description=_DESCRIPTION,
73
  features=datasets.Features(
74
  {
75
  "text": datasets.Value("string"),
76
  "date": datasets.Value("string"),
77
+ "label": datasets.Value("int32"),
78
  "label_name": datasets.Value("string"),
79
  "id": datasets.Value("string")
80
  }