-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
55 lines (47 loc) · 1.51 KB
/
utils.py
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
55
import os
import torch
from transformers import AutoModel, AutoTokenizer
def check_path(path):
if not os.path.exists(path):
os.makedirs(path)
def set_device(gpu_id):
if gpu_id == -1:
return torch.device('cpu')
else:
return torch.device(
'cuda:' + str(gpu_id) if torch.cuda.is_available() else 'cpu')
def load_plm(model_name='bert-base-uncased'):
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name)
return tokenizer, model
amazon_dataset2fullname = {
'Beauty': 'All_Beauty',
'Fashion': 'AMAZON_FASHION',
'Appliances': 'Appliances',
'Arts': 'Arts_Crafts_and_Sewing',
'Automotive': 'Automotive',
'Books': 'Books',
'CDs': 'CDs_and_Vinyl',
'Cell': 'Cell_Phones_and_Accessories',
'Clothing': 'Clothing_Shoes_and_Jewelry',
'Music': 'Digital_Music',
'Electronics': 'Electronics',
'Gift': 'Gift_Cards',
'Food': 'Grocery_and_Gourmet_Food',
'Home': 'Home_and_Kitchen',
'Scientific': 'Industrial_and_Scientific',
'Kindle': 'Kindle_Store',
'Luxury': 'Luxury_Beauty',
'Magazine': 'Magazine_Subscriptions',
'Movies': 'Movies_and_TV',
'Instruments': 'Musical_Instruments',
'Office': 'Office_Products',
'Garden': 'Patio_Lawn_and_Garden',
'Pantry': 'Prime_Pantry',
'Pet': 'Pet_Supplies',
'Software': 'Software',
'Sports': 'Sports_and_Outdoors',
'Tools': 'Tools_and_Home_Improvement',
'Toys': 'Toys_and_Games',
'Games': 'Video_Games'
}