示例#1
0
    def __init__(self, hparams):
        super(T5FineTuner, self).__init__()
        self.hparams = hparams

        self.model = MT5ForConditionalGeneration.from_pretrained(
            hparams.model_name_or_path)
        self.tokenizer = MT5TokenizerFast.from_pretrained(
            hparams.tokenizer_name_or_path)
        self.model.get_output_embeddings().weight.requires_grad = False
        self.model.get_input_embeddings().weight.requires_grad = False
示例#2
0
import torch
from torch.utils.data import DataLoader
from tqdm.auto import tqdm
from sklearn import metrics
import pytorch_lightning as pl
from transformers import MT5TokenizerFast,MT5ForConditionalGeneration
from trainudp import PostagDataset,T5FineTuner,args


tokenizer = MT5TokenizerFast.from_pretrained('mt5tokenizer')
dataset = PostagDataset(tokenizer, 'udp', 'test',  max_len=200)
loader = DataLoader(dataset, batch_size=8, num_workers=1)
model = T5FineTuner(args)
model.model=model.model.from_pretrained('udp/result')
model.model.eval()
outputs = []
targets = []
f1_list=[]

if __name__ == '__main__':
    torch.multiprocessing.freeze_support()
    device = "cuda"
    model = model.to(device)
    truep, ref, pred = 0, 0, 0
    for batch in tqdm(loader):
        outs = model.model.generate(input_ids=batch['source_ids'].cuda(),
                                    attention_mask=batch['source_mask'].cuda(),
                                    max_length=140)

        '''pred = [tokenizer.decode(ids) for ids in outs]