Repository navigation
Expand file tree
/
Copy pathinference.py
More file actions
54 lines (40 loc) · 1.45 KB
/
Copy pathinference.py
File metadata and controls
54 lines (40 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import json
import os
# import torch
import pandas as pd
from datasets import Dataset, DatasetDict
# from transformers import BertTokenizer, BertForSequenceClassification, Trainer, TrainingArguments
def read_json(file_path):
if os.path.exists(file_path):
with open(file_path, 'r') as f:
try:
data = json.load(f)
return data
except json.JSONDecodeError:
print("Error: File contains invalid JSON.")
return None
else:
print(f"Error: File {file_path} does not exist.")
return None
def print_json(data):
if data is not None:
print(json.dumps(data, indent=4))
else:
print("No data to print.")
# Example usage
file_path = 'user_employee_feedbacks/user_employee_feedbacks.json'
data = read_json(file_path)
print_json(data['user_responses'][-1])
# Create a Dataset from the JSON data
dataset = Dataset.from_list(data['user_responses'])
# Create a DatasetDict with the dataset as the test set
dataset_dict = DatasetDict({
'test': dataset
})
# Print the DatasetDict to check its structure
print(dataset_dict)
model = 'habibul08/employee-sentiment-tracker'
# Load tokenizer and model
# tokenizer = BertTokenizer.from_pretrained(model)
# model = BertForSequenceClassification.from_pretrained(model, num_labels=2) # 2 classes: negative and positive
# test_encodings = tokenizer(dataset_dict, padding=True, truncation=True, max_length=128)