Views
No views yet
1from transformers import AutoTokenizer, RobertaForSequenceClassification
2import torch
3import numpy as np
4
5device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6model_dir = "kfkas/RoBERTa-large-Detection-G2P"
7tokenizer = AutoTokenizer.from_pretrained('klue/roberta-large')
8model = RobertaForSequenceClassification.from_pretrained(model_dir).to(device)
9
10text = "월드커 파나은행 대표티메 행우늬 이달러 이영영장 선물"
11with torch.no_grad():
12 x = tokenizer(text, padding='max_length', truncation=True, return_tensors='pt', max_length=128)
13 y_pred = model(x["input_ids"].to(device))
14 logits = y_pred.logits
15 y_pred = logits.detach().cpu().numpy()
16 y = np.argmax(y_pred)
17 print(y)
18 #1