myml commited on
Commit
0ccd07a
1 Parent(s): d043d05

First model version

Browse files
config.json ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "bert-base-chinese",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "directionality": "bidi",
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "id2label": {
13
+ "0": "LABEL_0",
14
+ "1": "LABEL_1",
15
+ "2": "LABEL_2",
16
+ "3": "LABEL_3",
17
+ "4": "LABEL_4",
18
+ "5": "LABEL_5",
19
+ "6": "LABEL_6",
20
+ "7": "LABEL_7",
21
+ "8": "LABEL_8",
22
+ "9": "LABEL_9",
23
+ "10": "LABEL_10",
24
+ "11": "LABEL_11",
25
+ "12": "LABEL_12",
26
+ "13": "LABEL_13",
27
+ "14": "LABEL_14",
28
+ "15": "LABEL_15",
29
+ "16": "LABEL_16",
30
+ "17": "LABEL_17"
31
+ },
32
+ "initializer_range": 0.02,
33
+ "intermediate_size": 3072,
34
+ "label2id": {
35
+ "LABEL_0": 0,
36
+ "LABEL_1": 1,
37
+ "LABEL_10": 10,
38
+ "LABEL_11": 11,
39
+ "LABEL_12": 12,
40
+ "LABEL_13": 13,
41
+ "LABEL_14": 14,
42
+ "LABEL_15": 15,
43
+ "LABEL_16": 16,
44
+ "LABEL_17": 17,
45
+ "LABEL_2": 2,
46
+ "LABEL_3": 3,
47
+ "LABEL_4": 4,
48
+ "LABEL_5": 5,
49
+ "LABEL_6": 6,
50
+ "LABEL_7": 7,
51
+ "LABEL_8": 8,
52
+ "LABEL_9": 9
53
+ },
54
+ "layer_norm_eps": 1e-12,
55
+ "max_position_embeddings": 512,
56
+ "model_type": "bert",
57
+ "num_attention_heads": 12,
58
+ "num_hidden_layers": 12,
59
+ "pad_token_id": 0,
60
+ "pooler_fc_size": 768,
61
+ "pooler_num_attention_heads": 12,
62
+ "pooler_num_fc_layers": 3,
63
+ "pooler_size_per_head": 128,
64
+ "pooler_type": "first_token_transform",
65
+ "position_embedding_type": "absolute",
66
+ "problem_type": "single_label_classification",
67
+ "torch_dtype": "float32",
68
+ "transformers_version": "4.27.1",
69
+ "type_vocab_size": 2,
70
+ "use_cache": true,
71
+ "vocab_size": 21128
72
+ }
eval_results.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ acc = 0.89
2
+ eval_loss = 0.41998069381713865
3
+ mcc = 0.8806300444725128
main.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ # read dataset
4
+ df = pd.read_csv('toutiao_cat_data.txt',
5
+ sep='_!_', lineterminator='\n',
6
+ encoding='utf8',
7
+ names=["id", "type", "type_text", "text", "keywords"])
8
+ df = df[["text", "type"]]
9
+ df["type"] = df["type"] - 100
10
+
11
+ # split dataset
12
+ df = df.sample(frac=1)
13
+ train_df, test_df = df[:-1000], df[-1000:]
14
+
15
+ # create model
16
+ from simpletransformers.classification import ClassificationModel
17
+ model = ClassificationModel(
18
+ "bert",
19
+ "bert-base-chinese",
20
+ num_labels=18,
21
+ args={"reprocess_input_data": True, "overwrite_output_dir": True},
22
+ )
23
+
24
+ # train
25
+ model.train_model(train_df)
26
+
27
+ # eval
28
+ import sklearn
29
+ result = model.eval_model(test_df, acc=sklearn.metrics.accuracy_score)
30
+ result[0]
31
+
32
+ # predict
33
+ model.predict(["M2处理器IPad mini7值得期待吗?"])
model_args.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"adafactor_beta1": null, "adafactor_clip_threshold": 1.0, "adafactor_decay_rate": -0.8, "adafactor_eps": [1e-30, 0.001], "adafactor_relative_step": true, "adafactor_scale_parameter": true, "adafactor_warmup_init": true, "adam_betas": [0.9, 0.999], "adam_epsilon": 1e-08, "best_model_dir": "outputs/best_model", "cache_dir": "cache_dir/", "config": {}, "cosine_schedule_num_cycles": 0.5, "custom_layer_parameters": [], "custom_parameter_groups": [], "dataloader_num_workers": 0, "do_lower_case": false, "dynamic_quantize": false, "early_stopping_consider_epochs": false, "early_stopping_delta": 0, "early_stopping_metric": "eval_loss", "early_stopping_metric_minimize": true, "early_stopping_patience": 3, "encoding": null, "eval_batch_size": 8, "evaluate_during_training": false, "evaluate_during_training_silent": true, "evaluate_during_training_steps": 2000, "evaluate_during_training_verbose": false, "evaluate_each_epoch": true, "fp16": true, "gradient_accumulation_steps": 1, "learning_rate": 4e-05, "local_rank": -1, "logging_steps": 50, "loss_type": null, "loss_args": {}, "manual_seed": null, "max_grad_norm": 1.0, "max_seq_length": 128, "model_name": "bert-base-chinese", "model_type": "bert", "multiprocessing_chunksize": -1, "n_gpu": 1, "no_cache": false, "no_save": false, "not_saved_args": [], "num_train_epochs": 1, "optimizer": "AdamW", "output_dir": "outputs/", "overwrite_output_dir": true, "polynomial_decay_schedule_lr_end": 1e-07, "polynomial_decay_schedule_power": 1.0, "process_count": 6, "quantized_model": false, "reprocess_input_data": true, "save_best_model": true, "save_eval_checkpoints": true, "save_model_every_epoch": true, "save_optimizer_and_scheduler": true, "save_steps": 2000, "scheduler": "linear_schedule_with_warmup", "silent": false, "skip_special_tokens": true, "tensorboard_dir": null, "thread_count": null, "tokenizer_name": "bert-base-chinese", "tokenizer_type": null, "train_batch_size": 8, "train_custom_parameters_only": false, "use_cached_eval_features": false, "use_early_stopping": false, "use_hf_datasets": false, "use_multiprocessing": true, "use_multiprocessing_for_evaluation": true, "wandb_kwargs": {}, "wandb_project": null, "warmup_ratio": 0.06, "warmup_steps": 2863, "weight_decay": 0.0, "model_class": "ClassificationModel", "labels_list": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], "labels_map": {}, "lazy_delimiter": "\t", "lazy_labels_column": 1, "lazy_loading": false, "lazy_loading_start_line": 1, "lazy_text_a_column": null, "lazy_text_b_column": null, "lazy_text_column": 0, "onnx": false, "regression": false, "sliding_window": false, "special_tokens_list": [], "stride": 0.8, "tie_value": 1}
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59b45bf5c7979172fc5b8e220b8704497e46be1b56c9d8e4737c4d34a659d19f
3
+ size 409198773
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "do_lower_case": false,
4
+ "mask_token": "[MASK]",
5
+ "model_max_length": 512,
6
+ "pad_token": "[PAD]",
7
+ "sep_token": "[SEP]",
8
+ "special_tokens_map_file": null,
9
+ "strip_accents": null,
10
+ "tokenize_chinese_chars": true,
11
+ "tokenizer_class": "BertTokenizer",
12
+ "unk_token": "[UNK]"
13
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0729c4ac6a0769d02a19e8d48cb666dd0a3ebad4c5d9f93b3b5798cdc7c00a2b
3
+ size 3259
vocab.txt ADDED
The diff for this file is too large to render. See raw diff