(i,idx,model, test_data, args)
| 164 | |
| 165 | |
| 166 | def eval(i,idx,model, test_data, args): |
| 167 | model.eval() |
| 168 | with torch.no_grad(): |
| 169 | text_features = [] |
| 170 | for text in tqdm.tqdm(test_data.raw_texts, desc="Processing texts"): |
| 171 | tokens = model.tokenizer( |
| 172 | text, max_length=256, return_tensors='pt', truncation=True, padding=True).to(args.device) |
| 173 | text_features.append(model.lora_model(**tokens)[0][:, 0, :].cpu()) |
| 174 | |
| 175 | desc = descriptions[args.test_dataset[idx]] |
| 176 | tokens = model.tokenizer( |
| 177 | desc, max_length=256, return_tensors='pt', truncation=True, padding=True).to(args.device) |
| 178 | text_features.append(model.lora_model(**tokens)[0][:, 0, :].cpu()) |
| 179 | |
| 180 | node_embeds = torch.cat(text_features, dim=0).to(args.device) |
| 181 | label_features = [] |
| 182 | for text in tqdm.tqdm(test_data.label_text, desc="Processing label texts"): |
| 183 | tokens = model.tokenizer( |
| 184 | text, max_length=256, return_tensors='pt', truncation=True, padding=True).to(args.device) |
| 185 | label_features.append(model.lora_model(**tokens)[0][:, 0, :].cpu()) |
| 186 | label_embeds = torch.cat(label_features, dim=0).to(args.device) |
| 187 | args.test_data = args.test_dataset[idx] |
| 188 | |
| 189 | |
| 190 | res = model.zero_shot_eval( |
| 191 | node_embeds, label_embeds, test_data.data.to(args.device)) |
| 192 | |
| 193 | # torch.save(node_embeds,f"plot_Cora/node_epoch{i}.pt") |
| 194 | # torch.save(label_embeds,f"plot_Cora/label_epoch{i}.pt") |
| 195 | return res |
| 196 | |
| 197 | |
| 198 | if __name__ == '__main__': |
no test coverage detected