VANSHKAKKAR04 commited on
Commit
ef8f2ae
·
1 Parent(s): 9685f7b
.gitignore CHANGED
@@ -15,3 +15,6 @@ eval-results-bk/
15
  logs/
16
 
17
  emissions.csv
 
 
 
 
15
  logs/
16
 
17
  emissions.csv
18
+
19
+ .venv/
20
+ .idea/
config.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/content/drive/My Drive/FrugalAI/bert_fine_tuned_model",
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": "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
+ },
22
+ "initializer_range": 0.02,
23
+ "intermediate_size": 3072,
24
+ "label2id": {
25
+ "LABEL_0": 0,
26
+ "LABEL_1": 1,
27
+ "LABEL_2": 2,
28
+ "LABEL_3": 3,
29
+ "LABEL_4": 4,
30
+ "LABEL_5": 5,
31
+ "LABEL_6": 6,
32
+ "LABEL_7": 7
33
+ },
34
+ "layer_norm_eps": 1e-12,
35
+ "max_position_embeddings": 512,
36
+ "model_type": "bert",
37
+ "num_attention_heads": 12,
38
+ "num_hidden_layers": 12,
39
+ "pad_token_id": 0,
40
+ "position_embedding_type": "absolute",
41
+ "problem_type": "single_label_classification",
42
+ "torch_dtype": "float32",
43
+ "transformers_version": "4.47.1",
44
+ "type_vocab_size": 2,
45
+ "use_cache": true,
46
+ "vocab_size": 30522
47
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f2a203e16bd5abb95a639911210e8b926445771d3bf5714215d9faa0d8b1527
3
+ size 437977104
requirements.txt CHANGED
@@ -7,4 +7,7 @@ pydantic>=1.10.0
7
  python-dotenv>=1.0.0
8
  gradio>=4.0.0
9
  requests>=2.31.0
10
- librosa==0.10.2.post1
 
 
 
 
7
  python-dotenv>=1.0.0
8
  gradio>=4.0.0
9
  requests>=2.31.0
10
+ librosa==0.10.2.post1
11
+ torch~=2.5.1
12
+ numpy~=2.0.2
13
+ transformers>=4.30.0
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tasks/text.py CHANGED
@@ -2,14 +2,16 @@ from fastapi import APIRouter
2
  from datetime import datetime
3
  from datasets import load_dataset
4
  from sklearn.metrics import accuracy_score
5
- import random
 
 
6
 
7
  from .utils.evaluation import TextEvaluationRequest
8
  from .utils.emissions import tracker, clean_emissions_data, get_space_info
9
 
10
  router = APIRouter()
11
 
12
- DESCRIPTION = "Random Baseline"
13
  ROUTE = "/text"
14
 
15
  @router.post(ROUTE, tags=["Text Task"],
@@ -58,7 +60,51 @@ async def evaluate_text(request: TextEvaluationRequest):
58
 
59
  # Make random predictions (placeholder for actual model inference)
60
  true_labels = test_dataset["label"]
61
- predictions = [random.randint(0, 7) for _ in range(len(true_labels))]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  #--------------------------------------------------------------------------------------------
64
  # YOUR MODEL INFERENCE STOPS HERE
 
2
  from datetime import datetime
3
  from datasets import load_dataset
4
  from sklearn.metrics import accuracy_score
5
+ import torch
6
+ from torch.utils.data import Dataset, DataLoader
7
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
8
 
9
  from .utils.evaluation import TextEvaluationRequest
10
  from .utils.emissions import tracker, clean_emissions_data, get_space_info
11
 
12
  router = APIRouter()
13
 
14
+ DESCRIPTION = "BERT Fine tuned"
15
  ROUTE = "/text"
16
 
17
  @router.post(ROUTE, tags=["Text Task"],
 
60
 
61
  # Make random predictions (placeholder for actual model inference)
62
  true_labels = test_dataset["label"]
63
+ texts=test_dataset["quote"]
64
+ labels=test_dataset["label"]
65
+
66
+ model_dir = "./"
67
+
68
+ tokenizer = AutoTokenizer.from_pretrained(model_dir)
69
+ model = AutoModelForSequenceClassification.from_pretrained(model_dir)
70
+
71
+ class TextDataset(Dataset):
72
+ def __init__(self, texts, labels, tokenizer, max_len=128):
73
+ self.texts = texts
74
+ self.labels = labels
75
+ self.tokenizer = tokenizer
76
+ self.max_len = max_len
77
+
78
+ def __len__(self):
79
+ return len(self.texts)
80
+
81
+ def __getitem__(self, idx):
82
+ text = self.texts[idx]
83
+ label = self.labels[idx]
84
+ encodings = self.tokenizer(
85
+ text,
86
+ max_length=self.max_len,
87
+ padding='max_length',
88
+ truncation=True,
89
+ return_tensors="pt"
90
+ )
91
+ return {
92
+ 'input_ids': encodings['input_ids'].squeeze(0),
93
+ 'attention_mask': encodings['attention_mask'].squeeze(0),
94
+ 'labels': torch.tensor(label, dtype=torch.long)
95
+ }
96
+
97
+ test_dataset = TextDataset(texts, labels, tokenizer)
98
+ test_loader = DataLoader(test_dataset, batch_size=16)
99
+
100
+ model.eval()
101
+ predictions = []
102
+ with torch.no_grad():
103
+ for inputs, labels in test_loader:
104
+ inputs, labels = inputs.to('cpu'), labels.to('cpu')
105
+ outputs = model(inputs)
106
+ _, predicted = torch.max(outputs, 1)
107
+ predictions.extend(predicted.cpu().numpy())
108
 
109
  #--------------------------------------------------------------------------------------------
110
  # YOUR MODEL INFERENCE STOPS HERE
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 512,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff