forked from bigdata-ustc/EduCAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train_dataset.py
36 lines (30 loc) · 1.11 KB
/
train_dataset.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
import torch
from torch.utils import data
try:
# for python module
from .dataset import Dataset
except (ImportError, SystemError): # pragma: no cover
# for python script
from dataset import Dataset
class TrainDataset(Dataset, data.dataset.Dataset):
def __init__(self, data, concept_map,
num_students, num_questions, num_concepts):
"""
Args:
data: list, [(sid, qid, score)]
concept_map: dict, concept map {qid: cid}
num_students: int, total student number
num_questions: int, total question number
num_concepts: int, total concept number
"""
super().__init__(data, concept_map,
num_students, num_questions, num_concepts)
def __getitem__(self, item):
sid, qid, score = self.raw_data[item]
concepts = self.concept_map[qid]
concepts_emb = [0.] * self.num_concepts
for concept in concepts:
concepts_emb[concept] = 1.0
return sid, qid, torch.Tensor(concepts_emb), score
def __len__(self):
return len(self.raw_data)