Boris Ustyugov commited on
Commit
509468f
·
1 Parent(s): 760de42

Update app to load model from Hugging Face Hub instead of local files

Browse files
config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "ProsusAI/finbert",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "id2label": {
13
+ "0": "positive",
14
+ "1": "negative",
15
+ "2": "neutral"
16
+ },
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "label2id": {
20
+ "negative": 1,
21
+ "neutral": 2,
22
+ "positive": 0
23
+ },
24
+ "layer_norm_eps": 1e-12,
25
+ "max_position_embeddings": 512,
26
+ "model_type": "bert",
27
+ "num_attention_heads": 12,
28
+ "num_hidden_layers": 12,
29
+ "pad_token_id": 0,
30
+ "position_embedding_type": "absolute",
31
+ "problem_type": "single_label_classification",
32
+ "torch_dtype": "float32",
33
+ "transformers_version": "4.46.3",
34
+ "type_vocab_size": 2,
35
+ "use_cache": true,
36
+ "vocab_size": 30522
37
+ }
config.yaml CHANGED
@@ -1 +1 @@
1
- model_path: "model_checkpoint"
 
1
+ model_path: "utyug1/finbert-finetuned-model"
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_config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "mask_token": "[MASK]",
49
+ "model_max_length": 512,
50
+ "never_split": null,
51
+ "pad_token": "[PAD]",
52
+ "sep_token": "[SEP]",
53
+ "strip_accents": null,
54
+ "tokenize_chinese_chars": true,
55
+ "tokenizer_class": "BertTokenizer",
56
+ "unk_token": "[UNK]"
57
+ }
upload_model.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Script to upload the finetuned FinBERT model to Hugging Face Hub.
4
+ """
5
+
6
+ import os
7
+ from huggingface_hub import HfApi, create_repo, Repository
8
+
9
+ def upload_model():
10
+ """Upload the finetuned model to Hugging Face Hub."""
11
+
12
+ # Repository name (using the same name as the Space)
13
+ repo_name = "utyug1/finbert-finetuned-model"
14
+
15
+ try:
16
+ # Create repository if it doesn't exist
17
+ print(f"Creating repository: {repo_name}")
18
+ create_repo(repo_name, exist_ok=True, private=False)
19
+
20
+ # Clone the repository locally
21
+ print("Cloning repository...")
22
+ repo = Repository(repo_name, clone_from=repo_name)
23
+
24
+ # Copy model files to the repository
25
+ print("Copying model files...")
26
+ model_dir = "model_chekpoint"
27
+
28
+ for filename in os.listdir(model_dir):
29
+ file_path = os.path.join(model_dir, filename)
30
+ if os.path.isfile(file_path):
31
+ print(f"Copying {filename}...")
32
+ import shutil
33
+ shutil.copy2(file_path, filename)
34
+
35
+ # Commit and push
36
+ print("Committing and pushing...")
37
+ repo.git_add()
38
+ repo.git_commit("Upload finetuned FinBERT model")
39
+ repo.git_push()
40
+
41
+ print(f"Model successfully uploaded to: https://huggingface.co/{repo_name}")
42
+
43
+ except Exception as e:
44
+ print(f"Error uploading model: {str(e)}")
45
+ return False
46
+
47
+ return True
48
+
49
+ if __name__ == "__main__":
50
+ upload_model()